From f1c5ea87ea05fac2102a1464e532e8c7e67c46ab Mon Sep 17 00:00:00 2001 From: Zezula Ladislav Date: Fri, 17 May 2019 13:14:16 +0200 Subject: [PATCH] Linux Build --- src/CascCommon.cpp | 2 +- src/CascCommon.h | 13 -------- src/CascFiles.cpp | 66 ++++++++++++++++++++--------------------- src/CascOpenStorage.cpp | 4 +-- src/CascPort.h | 5 ++++ src/CascReadFile.cpp | 2 +- test/CascTest.cpp | 49 +++++++++++++++--------------- test/TLogHelper.cpp | 10 +++---- 8 files changed, 72 insertions(+), 79 deletions(-) diff --git a/src/CascCommon.cpp b/src/CascCommon.cpp index 0c674e9e..f98287de 100644 --- a/src/CascCommon.cpp +++ b/src/CascCommon.cpp @@ -110,7 +110,7 @@ LPBYTE LoadExternalFileToMemory(const TCHAR * szFileName, DWORD * pcbFileData) { CASC_FREE(pbFileData); pbFileData = NULL; - cbFileData = NULL; + cbFileData = 0; } } else diff --git a/src/CascCommon.h b/src/CascCommon.h index 8356abfc..ba948144 100644 --- a/src/CascCommon.h +++ b/src/CascCommon.h @@ -44,19 +44,6 @@ //----------------------------------------------------------------------------- // CascLib private defines -#define CASC_GAME_HOTS 0x00010000 // Heroes of the Storm -#define CASC_GAME_WOW6 0x00020000 // World of Warcraft - Warlords of Draenor -#define CASC_GAME_DIABLO3 0x00030000 // Diablo 3 since PTR 2.2.0 -#define CASC_GAME_OVERWATCH 0x00040000 // Overwatch since PTR 24919 -#define CASC_GAME_STARCRAFT2 0x00050000 // Starcraft II - Legacy of the Void, since build 38996 -#define CASC_GAME_STARCRAFT1 0x00060000 // Starcraft 1 (remastered) -#define CASC_GAME_WARCRAFT3 0x00070000 // Warcraft III, since version 1.30, build 9655 -#define CASC_GAME_MASK 0xFFFF0000 // Mask for getting game ID - -#define CASC_EXTRA_FILES 0x20 // Number of extra entries to be reserved for additionally inserted files - -#define CASC_PACKAGE_BUFFER 0x1000 - #ifdef _DEBUG #define BREAK_ON_XKEY3(CKey, v0, v1, v2) if(CKey[0] == v0 && CKey[1] == v1 && CKey[2] == v2) { __debugbreak(); } #define BREAKIF(condition) if(condition) { __debugbreak(); } diff --git a/src/CascFiles.cpp b/src/CascFiles.cpp index 4bca1060..aed491f4 100644 --- a/src/CascFiles.cpp +++ b/src/CascFiles.cpp @@ -461,71 +461,71 @@ static int LoadBuildProductId(TCascStorage * hs, const char * /* szVariableName // Product-specific. See https://wowdev.wiki/TACT#Products switch(dwBuildUid) { - case 'd3': - case 'd3b': // Diablo 3 Beta (2013) - case 'd3cn': // Diablo 3 China - case 'd3t': // Diablo 3 Test + case 0x00006433: // 'd3' + case 0x00643364: // 'd3b': Diablo 3 Beta (2013) + case 0x6433636e: // 'd3cn': Diablo 3 China + case 0x00643374: // 'd3t': Diablo 3 Test hs->szProductName = "Diablo 3"; hs->Product = Diablo3; break; - case 'dst2': + case 0x64737432: // 'dst2': hs->szProductName = "Destiny 2"; hs->Product = Destiny2; break; - case 'bnt': // Heroes of the Storm Alpha - case 'hero': // Heroes of the Storm Retail - case 'stor': // Heroes of the Storm (deprecated) + case 0x00626e74: // 'bnt': Heroes of the Storm Alpha + case 0x6865726f: // 'hero': Heroes of the Storm Retail + case 0x73746f72: // 'stor': Heroes of the Storm (deprecated) hs->szProductName = "Heroes Of The Storm"; hs->Product = HeroesOfTheStorm; break; - case 'pro': - case 'proc': - case 'prod': // "prodev": Overwatch Dev - case 'proe': // Not on public CDNs - case 'prot': // Overwatch Test - case 'prov': // Overwatch Vendor - case 'prom': // "proms": Overwatch World Cup Viewer + case 0x0070726f: // 'pro': + case 0x70726f63: // 'proc': + case 0x70726f64: // 'prod': "prodev": Overwatch Dev + case 0x70726f65: // 'proe': Not on public CDNs + case 0x70726f74: // 'prot': Overwatch Test + case 0x70726f76: // 'prov': Overwatch Vendor + case 0x70726f6d: // 'prom': "proms": Overwatch World Cup Viewer hs->szProductName = "Overwatch"; hs->Product = Overwatch; break; - case 's1': // StarCraft 1 - case 's1a': // Starcraft 1 Alpha - case 's1t': // StarCraft 1 Test + case 0x00007331: // 's1': StarCraft 1 + case 0x00733161: // 's1a': Starcraft 1 Alpha + case 0x00733174: // 's1t': StarCraft 1 Test hs->szProductName = "Starcraft 1"; hs->Product = StarCraft1; break; - case 's2': // StarCraft 2 - case 's2b': // Starcraft 2 Beta - case 's2t': // StarCraft 2 Test - case 'sc2': // StarCraft 2 (deprecated) + case 0x00007332: // 's2': StarCraft 2 + case 0x00733262: // 's2b': Starcraft 2 Beta + case 0x00733274: // 's2t': StarCraft 2 Test + case 0x00736332: // 'sc2': StarCraft 2 (deprecated) hs->szProductName = "Starcraft 2"; hs->Product = StarCraft2; break; - case 'vipe': // "viper", "viperdev", "viperv1": Call of Duty Black Ops 4 + case 0x76697065: // "viper", "viperdev", "viperv1": Call of Duty Black Ops 4 hs->szProductName = "Call Of Duty Black Ops 4"; hs->Product = CallOfDutyBlackOps4; break; - case 'w3': // Warcraft III - case 'w3t': // Warcraft III Public Test - case 'war3': // Warcraft III (old) + case 0x00007733: // 'w3': Warcraft III + case 0x00773374: // 'w3t': Warcraft III Public Test + case 0x77617233: // 'war3': Warcraft III (old) hs->szProductName = "WarCraft 3"; hs->Product = WarCraft3; break; - case 'wow': // World of Warcraft - case 'wow_': // "wow_beta", "wow_classic", "wow_classic_beta" - case 'wowd': // "wowdev", "wowdemo" - case 'wowe': // "wowe1", "wowe3", "wowe3", - case 'wowt': // World of Warcraft Test - case 'wowv': // World of Warcraft Vendor - case 'wowz': // World of Warcraft Submission (previously Vendor) + case 0x00776f77: // 'wow': World of Warcraft + case 0x776f775f: // "wow_beta", "wow_classic", "wow_classic_beta" + case 0x776f7764: // "wowdev", "wowdemo" + case 0x776f7765: // "wowe1", "wowe3", "wowe3" + case 0x776f7774: // 'wowt': World of Warcraft Test + case 0x776f7776: // 'wowv': World of Warcraft Vendor + case 0x776f777a: // 'wowz': World of Warcraft Submission (previously Vendor) hs->szProductName = "World Of Warcraft"; hs->Product = WorldOfWarcraft; break; diff --git a/src/CascOpenStorage.cpp b/src/CascOpenStorage.cpp index b921b04e..736832ce 100644 --- a/src/CascOpenStorage.cpp +++ b/src/CascOpenStorage.cpp @@ -567,7 +567,7 @@ static int LoadIndexFile_V2(TCascStorage * hs, CASC_INDEX_HEADER & InHeader, LPB return nError; } -static int LoadIndexFile(TCascStorage * hs, LPBYTE pbFileData, ULONG cbFileData, DWORD BucketIndex) +static int LoadIndexFile(TCascStorage * hs, LPBYTE pbFileData, DWORD cbFileData, DWORD BucketIndex) { CASC_INDEX_HEADER InHeader; @@ -587,7 +587,7 @@ static int LoadIndexFile(TCascStorage * hs, LPBYTE pbFileData, ULONG cbFileData, static int LoadIndexFile(TCascStorage * hs, const TCHAR * szFileName, DWORD BucketIndex) { LPBYTE pbFileData; - ULONG cbFileData; + DWORD cbFileData; int nError = ERROR_SUCCESS; // WoW6 actually reads THE ENTIRE file to memory. Verified on Mac build (x64). diff --git a/src/CascPort.h b/src/CascPort.h index 103a19bc..fa7fdcf3 100644 --- a/src/CascPort.h +++ b/src/CascPort.h @@ -196,6 +196,7 @@ #define _stprintf sprintf #define _tremove remove #define _tmkdir mkdir + #define _access access #define _stricmp strcasecmp #define _strnicmp strncasecmp @@ -242,6 +243,10 @@ #define ERROR_FILE_OFFLINE 1007 // The file is not available in the local storage #endif +#ifndef _countof +#define _countof(x) (sizeof(x) / sizeof(x[0])) +#endif + //----------------------------------------------------------------------------- // Swapping functions diff --git a/src/CascReadFile.cpp b/src/CascReadFile.cpp index 35f3dcda..5b880f54 100644 --- a/src/CascReadFile.cpp +++ b/src/CascReadFile.cpp @@ -37,7 +37,7 @@ static int EnsureDataStreamIsOpen(TCascFile * hf) // Open the data stream with write access and sharing for read+write // to prevent Battle.net Agent detecting a corruption and redownloading the entire package // pStream = FileStream_OpenFile(szDataFile, STREAM_FLAG_READ_ONLY | STREAM_PROVIDER_FLAT | STREAM_FLAG_FILL_MISSING | BASE_PROVIDER_FILE); - pStream = FileStream_OpenFile(szDataFile, STREAM_FLAG_WRITE_SHARE | STREAM_PROVIDER_FLAT | STREAM_FLAG_FILL_MISSING | BASE_PROVIDER_FILE); + pStream = FileStream_OpenFile(szDataFile, STREAM_FLAG_READ_ONLY | STREAM_FLAG_WRITE_SHARE | STREAM_PROVIDER_FLAT | STREAM_FLAG_FILL_MISSING | BASE_PROVIDER_FILE); hs->DataFiles[hf->ArchiveIndex] = pStream; CASC_FREE(szDataFile); } diff --git a/test/CascTest.cpp b/test/CascTest.cpp index ee37566a..e172946e 100644 --- a/test/CascTest.cpp +++ b/test/CascTest.cpp @@ -12,11 +12,11 @@ #define _CRT_SECURE_NO_DEPRECATE #define __INCLUDE_CRYPTOGRAPHY__ #define __CASCLIB_SELF__ // Don't use CascLib.lib -#include #include #include #ifdef _MSC_VER +#include #include #endif @@ -41,7 +41,7 @@ #endif #ifdef PLATFORM_LINUX -#define CASC_PATH_ROOT "/home/ladik/MPQs" +#define CASC_PATH_ROOT "/mnt/casc" #endif #ifdef PLATFORM_MAC @@ -158,35 +158,36 @@ static void MakeShortName(const char * szFileName, DWORD dwOpenFlags, char * szS } } +static TCHAR * CopyPath(TCHAR * szBuffer, TCHAR * szBufferEnd, const char * szSource) +{ + while(szBuffer < szBufferEnd && szSource[0] != 0) + { + if(szSource[0] == '\\' || szSource[0] == '/') + *szBuffer++ = PATH_SEP_CHAR; + else + *szBuffer++ = szSource[0]; + + szSource++; + } + + szBuffer[0] = 0; + return szBuffer; +} + static TCHAR * MakeFullPath(const char * szStorage, TCHAR * szBuffer, size_t ccBuffer) { TCHAR * szBufferEnd = szBuffer + ccBuffer - 1; const char * szPathRoot = CASC_PATH_ROOT; - // If we can access the file directly, use the path as-is - if(_access(szStorage, 0) != -1) + // If we can not access the folder directly, we copy the path root + if(_access(szStorage, 0) == -1) { - while(szStorage[0] != 0 && szBuffer < szBufferEnd) - *szBuffer++ = *szStorage++; + szBuffer = CopyPath(szBuffer, szBufferEnd, szPathRoot); + szBuffer = CopyPath(szBuffer, szBufferEnd, PATH_SEP_STRING); } - else - { - // Copy the path prefix - while(szBuffer < szBufferEnd && szPathRoot[0] != 0) - *szBuffer++ = *szPathRoot++; - - // Append the separator - if(szBuffer < szBufferEnd) - *szBuffer++ = PATH_SEP_CHAR; - - // Append the rest - while(szBuffer < szBufferEnd && szStorage[0] != 0) - *szBuffer++ = *szStorage++; - } - - // Append zero and exit - szBuffer[0] = 0; - return szBuffer; + + // Copy the rest of the path + return CopyPath(szBuffer, szBufferEnd, szStorage); } static int ForceCreatePath(TCHAR * szFullPath) diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp index 483db9ce..c25b8566 100644 --- a/test/TLogHelper.cpp +++ b/test/TLogHelper.cpp @@ -215,7 +215,7 @@ class TLogHelper void PrintTotalTime() { - ULONG TotalTime = SetEndTime(); + DWORD TotalTime = SetEndTime(); if(TotalTime != 0) { @@ -265,10 +265,10 @@ class TLogHelper StartTime = GetCurrentThreadTime(); } - ULONG SetEndTime() + DWORD SetEndTime() { EndTime = GetCurrentThreadTime(); - return (ULONG)(EndTime - StartTime); + return (DWORD)(EndTime - StartTime); } void FormatTotalBytes(char * szBuffer, size_t ccBuffer) @@ -283,12 +283,12 @@ class TLogHelper // Are we already dividing? if(bDividingOn) { - szBuffer += sprintf(szBuffer, " %03u", (ULONG)(Bytes / Divider)); + szBuffer += sprintf(szBuffer, " %03u", (DWORD)(Bytes / Divider)); Bytes = Bytes % Divider; } else if(Bytes > Divider) { - szBuffer += sprintf(szBuffer, "%u", (ULONG)(Bytes / Divider)); + szBuffer += sprintf(szBuffer, "%u", (DWORD)(Bytes / Divider)); Bytes = Bytes % Divider; bDividingOn = true; }