Skip to content

Commit

Permalink
* Updated ZLIB
Browse files Browse the repository at this point in the history
* Added WDK build
* Bugfixes
  • Loading branch information
ladislav-zezula committed Nov 17, 2019
1 parent 8b9d769 commit 97b9e09
Show file tree
Hide file tree
Showing 29 changed files with 1,470 additions and 866 deletions.
43 changes: 43 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@echo off
if not "x%WDKDIR%" == "x" goto SELECT_LIB
echo The WDKDIR environment variable is not set
echo Set this variable to your WDK directory (without ending backslash)
echo Example: set WDKDIR C:\WinDDK\6001
pause
goto:eof

:SELECT_LIB
set PROJECT_DIR=%~dp0
set LIBRARY_NAME=CascLibWDK

:BUILD_LIB_32
echo Building %LIBRARY_NAME%.lib 32-bit (free) ...
set DDKBUILDENV=
call %WDKDIR%\bin\setenv.bat %WDKDIR%\ fre wxp
cd %PROJECT_DIR%
build.exe -czgw
echo.

:COPY_LIB_32
copy /Y .\objfre_wxp_x86\i386\%LIBRARY_NAME%.lib ..\aaa\lib32\%LIBRARY_NAME%.lib >nul
del buildfre_wxp_x86.log
echo.

:BUILD_LIB_64
echo Building %LIBRARY_NAME%.lib 64-bit (free) ...
set DDKBUILDENV=
call %WDKDIR%\bin\setenv.bat %WDKDIR%\ fre x64 WLH
cd %PROJECT_DIR%
build.exe -czgw
echo.

:COPY_LIB_64
copy /Y .\objfre_wlh_amd64\amd64\%LIBRARY_NAME%.lib ..\aaa\lib64\%LIBRARY_NAME%.lib >nul
del buildfre_wlh_amd64.log
echo.

:COPY_HEADER
copy /Y .\src\CascLib.h ..\aaa\inc >nul

rem Clean temporary files ...
if exist build.bat del build.bat
9 changes: 9 additions & 0 deletions sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TARGETNAME=CascLibWDK
TARGETTYPE=LIBRARY
USE_MSVCRT=1

C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE -DWDK_BUILD

SOURCES=sources-c.c \
sources-cpp.cpp

9 changes: 9 additions & 0 deletions sources-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma warning(disable:4005) // warning C4005: 'DO1' : macro redefinition

#include "src\jenkins\lookup3.c"
#include "src\zlib\adler32.c"
#include "src\zlib\crc32.c"
#include "src\zlib\inffast.c"
#include "src\zlib\inflate.c"
#include "src\zlib\inftrees.c"
#include "src\zlib\zutil.c"
24 changes: 24 additions & 0 deletions sources-cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "src\common\Common.cpp"
#include "src\common\Csv.cpp"
#include "src\common\Directory.cpp"
#include "src\common\FileStream.cpp"
#include "src\common\FileTree.cpp"
#include "src\common\ListFile.cpp"
#include "src\common\RootHandler.cpp"
#include "src\md5\md5.cpp"
#include "src\CascDecompress.cpp"
#include "src\CascDecrypt.cpp"
#include "src\CascDumpData.cpp"
#include "src\CascFiles.cpp"
#include "src\CascFindFile.cpp"
#include "src\CascIndexFiles.cpp"
#include "src\CascOpenFile.cpp"
#include "src\CascOpenStorage.cpp"
#include "src\CascReadFile.cpp"
#include "src\CascRootFile_Diablo3.cpp"
#include "src\CascRootFile_Install.cpp"
#include "src\CascRootFile_MNDX.cpp"
#include "src\CascRootFile_OW.cpp"
#include "src\CascRootFile_Text.cpp"
#include "src\CascRootFile_TVFS.cpp"
#include "src\CascRootFile_WoW.cpp"
5 changes: 0 additions & 5 deletions src/CascDecrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ static CASC_ENCRYPTION_KEY CascKeys[] =
//-----------------------------------------------------------------------------
// Local functions

static DWORD Rol32(DWORD dwValue, DWORD dwRolCount)
{
return (dwValue << dwRolCount) | (dwValue >> (32 - dwRolCount));
}

static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
{
const char * szConstants = (cbKeyLength == 32) ? szKeyConstant32 : szKeyConstant16;
Expand Down
1 change: 0 additions & 1 deletion src/CascFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,6 @@ LPBYTE LoadFileToMemory(LPCTSTR szFileName, DWORD * pcbFileData)
DWORD cbFileData = 0;

// Open the stream for read-only access and read the file
// Note that this fails when the game is running (sharing violation).
pStream = FileStream_OpenFile(szFileName, STREAM_FLAG_READ_ONLY | STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE);
if(pStream != NULL)
{
Expand Down
64 changes: 33 additions & 31 deletions src/CascLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,43 @@ extern "C" {
//
// X - D for Debug version, R for Release version
// Y - A for ANSI version, U for Unicode version
// Z - S for static-linked CRT library, D for multithreaded DLL CRT library
// Z - S for static-linked CRT library, D for dynamic CRT library (dll)
//
#if defined(_MSC_VER) && !defined(__CASCLIB_SELF__) && !defined(CASCLIB_NO_AUTO_LINK_LIBRARY)

#ifdef _DEBUG // DEBUG VERSIONS
#ifndef _UNICODE
#ifdef _DLL
#pragma comment(lib, "CascLibDAD.lib") // Debug Ansi CRT-DLL version
#else
#pragma comment(lib, "CascLibDAS.lib") // Debug Ansi CRT-LIB version
#endif
#else
#ifdef _DLL
#pragma comment(lib, "CascLibDUD.lib") // Debug Unicode CRT-DLL version
#else
#pragma comment(lib, "CascLibDUS.lib") // Debug Unicode CRT-LIB version
#endif
#endif
#else // RELEASE VERSIONS
#ifndef _UNICODE
#ifdef _DLL
#pragma comment(lib, "CascLibRAD.lib") // Release Ansi CRT-DLL version
#if defined(_MSC_VER) && !defined(__CASCLIB_SELF__) && !defined(CASCLIB_NO_AUTO_LINK_LIBRARY)
#ifndef WDK_BUILD
#ifdef _DEBUG // DEBUG VERSIONS
#ifndef _UNICODE
#ifdef _DLL
#pragma comment(lib, "CascLibDAD.lib") // Debug Ansi CRT-DLL version
#else
#pragma comment(lib, "CascLibDAS.lib") // Debug Ansi CRT-LIB version
#endif
#else
#pragma comment(lib, "CascLibRAS.lib") // Release Ansi CRT-LIB version
#ifdef _DLL
#pragma comment(lib, "CascLibDUD.lib") // Debug Unicode CRT-DLL version
#else
#pragma comment(lib, "CascLibDUS.lib") // Debug Unicode CRT-LIB version
#endif
#endif
#else
#ifdef _DLL
#pragma comment(lib, "CascLibRUD.lib") // Release Unicode CRT-DLL version
#else // RELEASE VERSIONS
#ifndef _UNICODE
#ifdef _DLL
#pragma comment(lib, "CascLibRAD.lib") // Release Ansi CRT-DLL version
#else
#pragma comment(lib, "CascLibRAS.lib") // Release Ansi CRT-LIB version
#endif
#else
#pragma comment(lib, "CascLibRUS.lib") // Release Unicode CRT-LIB version
#ifdef _DLL
#pragma comment(lib, "CascLibRUD.lib") // Release Unicode CRT-DLL version
#else
#pragma comment(lib, "CascLibRUS.lib") // Release Unicode CRT-LIB version
#endif
#endif
#endif
#endif

#endif

//-----------------------------------------------------------------------------
// Defines

Expand Down Expand Up @@ -159,7 +161,7 @@ typedef enum _CASC_STORAGE_INFO_CLASS
// Returns the total file count, including the offline files
CascStorageTotalFileCount,


CascStorageFeatures, // Returns the features flag
CascStorageInstalledLocales, // Not supported
CascStorageProduct, // Gives CASC_STORAGE_PRODUCT
Expand Down Expand Up @@ -187,15 +189,15 @@ typedef enum _CASC_NAME_TYPE
CascNameDataId, // Name created from file data id (FILE%08X.dat)
CascNameCKey, // Name created as string representation of CKey
CascNameEKey // Name created as string representation of EKey
} CASC_NAME_TYPE, *PCASC_NAME_TYPE;
} CASC_NAME_TYPE, *PCASC_NAME_TYPE;

// Structure for SFileFindFirstFile and SFileFindNextFile
typedef struct _CASC_FIND_DATA
{
// Full name of the found file. In case when this is CKey/EKey,
// this will be just string representation of the key stored in 'FileKey'
char szFileName[MAX_PATH];

// Content key. This is present if the CASC_FEATURE_ROOT_CKEY is present
BYTE CKey[MD5_HASH_SIZE];

Expand All @@ -213,7 +215,7 @@ typedef struct _CASC_FIND_DATA

// File data ID. Only valid if the storage supports file data IDs, otherwise CASC_INVALID_ID
DWORD dwFileDataId;

// Locale flags. Only valid if the storage supports locale flags, otherwise CASC_INVALID_ID
DWORD dwLocaleFlags;

Expand Down Expand Up @@ -246,7 +248,7 @@ typedef struct _CASC_STORAGE_TAGS

CASC_STORAGE_TAG Tags[1]; // Array of CASC tags

} CASC_STORAGE_TAGS, *PCASC_STORAGE_TAGS;
} CASC_STORAGE_TAGS, *PCASC_STORAGE_TAGS;

typedef struct _CASC_STORAGE_PRODUCT
{
Expand Down
6 changes: 3 additions & 3 deletions src/CascOpenStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,14 +1138,14 @@ static DWORD LoadCascStorage(TCascStorage * hs, PCASC_OPEN_STORAGE_ARGS pArgs)
hs->pArgs = pArgs;

// Extract optional arguments
ExtractVersionedArgument(pArgs, offsetof(CASC_OPEN_STORAGE_ARGS, dwLocaleMask), &dwLocaleMask);
ExtractVersionedArgument(pArgs, FIELD_OFFSET(CASC_OPEN_STORAGE_ARGS, dwLocaleMask), &dwLocaleMask);

// Extract the product code name
if(ExtractVersionedArgument(pArgs, offsetof(CASC_OPEN_STORAGE_ARGS, szCodeName), &szCodeName) && szCodeName != NULL)
if(ExtractVersionedArgument(pArgs, FIELD_OFFSET(CASC_OPEN_STORAGE_ARGS, szCodeName), &szCodeName) && szCodeName != NULL)
hs->szCodeName = CascNewStr(szCodeName);

// Extract the region (optional)
if(ExtractVersionedArgument(pArgs, offsetof(CASC_OPEN_STORAGE_ARGS, szRegion), &szRegion) && szRegion != NULL)
if(ExtractVersionedArgument(pArgs, FIELD_OFFSET(CASC_OPEN_STORAGE_ARGS, szRegion), &szRegion) && szRegion != NULL)
{
CascStrCopy(szRegionA, _countof(szRegionA), szRegion);
hs->szRegion = CascNewStr(szRegionA);
Expand Down
79 changes: 56 additions & 23 deletions src/CascPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

#include <tchar.h>
#include <assert.h>
#include <intrin.h> // Support for intrinsic functions
#include <ctype.h>
#include <io.h>
#include <stdio.h>
Expand All @@ -64,20 +63,21 @@
#define URL_SEP_CHAR '/'
#define PATH_SEP_CHAR '\\'
#define PATH_SEP_STRING "\\"

#pragma intrinsic(memcmp, memcpy)

typedef RTL_CRITICAL_SECTION PLATFORM_LOCK;
#define LOCK_INIT(Lock) InitializeCriticalSection(Lock)
#define LOCK(Lock) EnterCriticalSection(Lock)
#define UNLOCK(Lock) LeaveCriticalSection(Lock)
#define LOCK_FREE(Lock) DeleteCriticalSection(Lock)

#define PLATFORM_WINDOWS
#define PLATFORM_DEFINED // The platform is known now

#endif

#if _MSC_VER >= 1500
#include <intrin.h> // Support for intrinsic functions
#pragma intrinsic(memcmp, memcpy)
#endif

#ifndef FIELD_OFFSET
#define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
#endif

//-----------------------------------------------------------------------------
// Defines for Mac

Expand Down Expand Up @@ -119,12 +119,6 @@
#define PATH_SEP_CHAR '/'
#define PATH_SEP_STRING "/"

typedef unsigned int PLATFORM_LOCK;
#define LOCK_INIT(Lock) { /* TODO */ }
#define LOCK(Lock) { /* TODO */ }
#define UNLOCK(Lock) { /* TODO */ }
#define LOCK_FREE(Lock) { /* TODO */ }

#define PLATFORM_MAC
#define PLATFORM_DEFINED // The platform is known now

Expand Down Expand Up @@ -156,12 +150,6 @@
#define PATH_SEP_CHAR '/'
#define PATH_SEP_STRING "/"

typedef unsigned int PLATFORM_LOCK;
#define LOCK_INIT(Lock) { /* TODO */ }
#define LOCK(Lock) { /* TODO */ }
#define UNLOCK(Lock) { /* TODO */ }
#define LOCK_FREE(Lock) { /* TODO */ }

#define PLATFORM_LITTLE_ENDIAN
#define PLATFORM_LINUX
#define PLATFORM_DEFINED
Expand Down Expand Up @@ -289,9 +277,9 @@
#endif

#ifndef _countof
#define _countof(x) (sizeof(x) / sizeof(x[0]))
#define _countof(x) (sizeof(x) / sizeof(x[0]))
#endif

//-----------------------------------------------------------------------------
// Swapping functions

Expand Down Expand Up @@ -354,6 +342,51 @@ inline DWORD CascInterlockedDecrement(PDWORD PtrValue)
#endif
}

//-----------------------------------------------------------------------------
// Lock functions

#ifdef PLATFORM_WINDOWS
typedef RTL_CRITICAL_SECTION CASC_LOCK;
#else
typedef unsigned int CASC_LOCK;
#endif

inline void CascInitLock(CASC_LOCK & Lock)
{
#ifdef PLATFORM_WINDOWS
InitializeCriticalSection(&Lock);
#else
Lock = 0; // TODO
#endif
}

inline void CascFreeLock(CASC_LOCK & Lock)
{
#ifdef PLATFORM_WINDOWS
DeleteCriticalSection(&Lock);
#else
Lock = 0; // TODO
#endif
}

inline void CascLock(CASC_LOCK & Lock)
{
#ifdef PLATFORM_WINDOWS
EnterCriticalSection(&Lock);
#else
Lock = 0; // TODO
#endif
}

inline void CascUnlock(CASC_LOCK & Lock)
{
#ifdef PLATFORM_WINDOWS
LeaveCriticalSection(&Lock);
#else
Lock = 0; // TODO
#endif
}

//-----------------------------------------------------------------------------
// Forbidden functions, do not use

Expand Down
5 changes: 3 additions & 2 deletions src/CascReadFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static DWORD OpenDataStream(TCascFile * hf, PCASC_FILE_SPAN pFileSpan, PCASC_CKE
{
DWORD dwArchiveIndex = pFileSpan->ArchiveIndex;

// If the file is not open yet, do it
// If the data archive is not open yet, open it now.
// TODO: This is not thread safe, we need to implement locking here
if(hs->DataFiles[dwArchiveIndex] == NULL)
{
// Prepare the name of the data file
Expand Down Expand Up @@ -1143,7 +1144,7 @@ bool WINAPI CascSetFilePointer64(HANDLE hFile, LONGLONG DistanceToMove, PULONGLO
}

// Do not allow the file pointer to move to negative values
if((FilePosition = FilePosition + DistanceToMove) < 0)
if((LONGLONG)(FilePosition = FilePosition + DistanceToMove) < 0)
FilePosition = 0;
hf->FilePointer = FilePosition;
}
Expand Down
Loading

0 comments on commit 97b9e09

Please sign in to comment.