Replaced StormLib .lib files with source code.

Some modifications to handle backslashes and forward slashes, along with some optimizations to speed up OTR generation.
This commit is contained in:
Nicholas Estelami 2022-06-01 16:05:05 -04:00
commit fc7da35054
378 changed files with 93684 additions and 29 deletions

90
StormLib/test/Readme.txt Normal file
View file

@ -0,0 +1,90 @@
Testing MPQ set for StormLib test suite
=======================================
The path to the directory could be anywhere. Path to this directory
is set on a command line. If there is no command line argument passed,
one of the hard-coded paths is used.
The testing directory must contain the following files:
Path File Size
------------------------------------------------- -----------
patches\wow-update-13164.MPQ 480 028 668 // Original patch files from WoW
patches\wow-update-13205.MPQ 8 814
patches\wow-update-13287.MPQ 333 363 917
patches\wow-update-13329.MPQ 159 285 434
patches\wow-update-13596.MPQ 148 022 182
patches\wow-update-13623.MPQ 11 561
patches\wow-update-base-13914.MPQ 293 580 556
patches\wow-update-base-14007.MPQ 262 906
patches\wow-update-base-14333.MPQ 368 972 365
patches\wow-update-base-14480.MPQ 75 897
patches\wow-update-base-14545.MPQ 1 224 415
patches\wow-update-base-14946.MPQ 749 246 163
patches\wow-update-base-15005.MPQ 7 121 223
patches\wow-update-base-15050.MPQ 4 497
patches\wow-update-enGB-16016.MPQ 17 117 318
patches\wow-update-enGB-16048.MPQ 78 180
patches\wow-update-enGB-16057.MPQ 4 072
patches\wow-update-enGB-16309.MPQ 28 187 877
patches\wow-update-enGB-16357.MPQ 3 621
patches\wow-update-enGB-16516.MPQ 42 934 402
patches\wow-update-enGB-16650.MPQ 426 683
patches\wow-update-enGB-16844.MPQ 18 366 460
patches\wow-update-enGB-16965.MPQ 305 202
patches\wow-update-oldworld-13154.MPQ 54 068 663
patches\wow-update-oldworld-13286.MPQ 2 328 773
AddFile.bin 0 // Just an empty file
AddFile.exe 432 640 // An arbitraty binary file
AddFile.wav 311 340 // An arbitrary WAVE file
ListFile_Blizzard.txt 3 904 784 // Listfile for Blizzard games (pre-WoW)
ListFile_WarOfTheImmortals.txt 3 904 858 // Listfile for War of the Immortals game
MPQ_1997_v1_Diablo1_DIABDAT.MPQ 517 501 282 // Originally DIABDAT.MPQ from Diablo I
MPQ_1997_v1_Diablo1_DIABDAT.sha 206
MPQ_1997_v1_Diablo1_single_0.sha 201 // Single player savegame from Diablo I
MPQ_1997_v1_Diablo1_single_0.sv 98 980
MPQ_1999_v1_WeakSignature.exe 1 031 826 // War2Patch_202.exe from Warcraft II Bnet Edition
MPQ_1999_v1_WeakSignature.sha 260
MPQ_2002_v1_BlockTableCut.MPQ 27 498 436 // Cut file War3Patch.mpq from Warcraft III
MPQ_2002_v1_BlockTableCut.sha 250
MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.sha 1 067
MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.w3x 1 089 638 // Protected Warcraft III map
MPQ_2002_v1_ProtectedMap_InvalidMpqFormat.sha 507
MPQ_2002_v1_ProtectedMap_InvalidMpqFormat.w3x 2 429 195 // Protected Warcraft III map
MPQ_2002_v1_ProtectedMap_InvalidUserData.sha 293
MPQ_2002_v1_ProtectedMap_InvalidUserData.w3x 596 486 // Protected Warcraft III map
MPQ_2002_v1_StrongSignature.sha 250
MPQ_2002_v1_StrongSignature.w3m 306 818 // (10)DustwallowKeys.w3m from Warcraft III
MPQ_2009_v2_WoW_patch.MPQ.part 31 396 380 // patch.MPQ.part from trial WoW build 10958
MPQ_2009_v2_WoW_patch.MPQ.sha 226
MPQ_2010_v2_HashTableCompressed.MPQ.part 14 546 972 // interface.MPQ.part from WoW build 10958
MPQ_2010_v2_HashTableCompressed.MPQ.sha 277
MPQ_2010_v2_HasUserData.s2ma 1 972 177 // (4) - AI - Kulas Ravine (1x).s2ma from Starcraft II Beta
MPQ_2010_v2_HasUserData.sha 261
MPQ_2010_v3_expansion-locale-frFR.MPQ 2 980 489 // expansion-locale-frFR.MPQ from WoW 12911
MPQ_2010_v3_expansion-locale-frFR.sha 274
MPQ_2011_v2_EncryptedMpq.MPQE 41 631 764 // Installer UI 2 esES.MPQE from Starcraft II Installer (build 15404)
MPQ_2011_v2_EncryptedMpq.sha 255
MPQ_2011_v4_InvalidHetEntryCount.MPQ 206 164 // An invalid MPQ created by a previous Stormlib version
MPQ_2011_v4_InvalidHetEntryCount.sha 312
MPQ_2012_v2_EmptyMpq.MPQ 44 // Empty MPQ (Cache from WoW 11723)
MPQ_2012_v2_EmptyMpq.sha 212
MPQ_2012_v4_OldWorld.MPQ 1 854 547 587 // OldWorld.MPQ from WoW 12911
MPQ_2012_v4_OldWorld.sha 270
MPQ_2013_v4_EmptyMpq.MPQ 208 // Empty MPQ created by StormLib
MPQ_2013_v4_EmptyMpq.sha 183
MPQ_2013_v4_expansion1.MPQ 1 426 926 736 // expansion1.MPQ from WoW build 17538
MPQ_2013_v4_expansion1.sha 221
MPQ_2013_v4_locale-enGB.MPQ 446 491 866 // locale-enGB.MPQ from WoW build 16965
MPQ_2013_v4_locale-enGB.sha 273
MPQ_2013_v4_patch-base-16357.MPQ 249 // patch-base-16357.MPQ from WoW build 17538
MPQ_2013_v4_patch-base-16357.sha 229
MPQ_2013_v4_SC2_EmptyMap.SC2Map 25 058 // Custom Starcraft II Map
MPQ_2013_v4_SC2_EmptyMap.sha 243
MPQ_2013_v4_world.MPQ 2 617 175 835 // world.MPQ from WoW build 12911
MPQ_2013_v4_world.sha 252
MPx_2013_v1_LongwuOnline.mpk 2 146 549 // Scp.mpk from Longwu Online
MPx_2013_v1_LongwuOnline.sha 277
MPx_2013_v1_WarOfTheImmortals.sha 248
MPx_2013_v1_WarOfTheImmortals.sqp 56 775 675 // Modified Other.sqp from War of the Immortals

4580
StormLib/test/StormTest.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,441 @@
/*****************************************************************************/
/* TLogHelper.cpp Copyright (c) Ladislav Zezula 2013 */
/*---------------------------------------------------------------------------*/
/* Helper class for reporting StormLib tests */
/* This file should be included directly from StormTest.cpp using #include */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 26.11.13 1.00 Lad The first version of TLogHelper.cpp */
/*****************************************************************************/
//-----------------------------------------------------------------------------
// Definition of the TLogHelper class
class TLogHelper
{
public:
TLogHelper(const char * szNewMainTitle = NULL, const TCHAR * szNewSubTitle1 = NULL, const TCHAR * szNewSubTitle2 = NULL);
~TLogHelper();
#if defined(UNICODE) || defined(UNICODE)
// TCHAR-based functions. They are only needed on UNICODE builds.
// On ANSI builds is TCHAR = char, so we don't need them at all
int PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine);
void PrintProgress(const TCHAR * szFormat, ...);
void PrintMessage(const TCHAR * szFormat, ...);
int PrintErrorVa(const TCHAR * szFormat, ...);
int PrintError(const TCHAR * szFormat, const TCHAR * szFileName = NULL);
#endif // defined(UNICODE) || defined(UNICODE)
// ANSI functions
DWORD PrintWithClreol(const char * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine);
void PrintProgress(const char * szFormat, ...);
void PrintMessage(const char * szFormat, ...);
DWORD PrintErrorVa(const char * szFormat, ...);
DWORD PrintError(const char * szFormat, const char * szFileName = NULL);
const char * UserString;
unsigned int UserCount;
unsigned int UserTotal;
bool bDontPrintResult;
protected:
#if defined(UNICODE) || defined(UNICODE)
TCHAR * CopyFormatCharacter(TCHAR * szBuffer, const TCHAR *& szFormat);
#endif
char * CopyFormatCharacter(char * szBuffer, const char *& szFormat);
int GetConsoleWidth();
const char * szMainTitle; // Title of the text (usually name)
const TCHAR * szSubTitle1; // Title of the text (can be name of the tested file)
const TCHAR * szSubTitle2; // Title of the text (can be name of the tested file)
size_t nTextLength; // Length of the previous progress message
bool bMessagePrinted;
};
//-----------------------------------------------------------------------------
// String replacements for format strings
#ifdef _MSC_VER
#define I64u_t _T("%I64u")
#define I64u_a "%I64u"
#define I64X_t _T("%I64X")
#define I64X_a "%I64X"
#else
#define I64u_t _T("%llu")
#define I64u_a "%llu"
#define I64X_t _T("%llX")
#define I64X_a "%llX"
#endif
//-----------------------------------------------------------------------------
// Constructor and destructor
TLogHelper::TLogHelper(const char * szNewMainTitle, const TCHAR * szNewSubTitle1, const TCHAR * szNewSubTitle2)
{
TCHAR szMainTitleT[0x80];
UserString = "";
UserCount = 1;
UserTotal = 1;
// Fill the test line structure
szMainTitle = szNewMainTitle;
szSubTitle1 = szNewSubTitle1;
szSubTitle2 = szNewSubTitle2;
nTextLength = 0;
bMessagePrinted = false;
bDontPrintResult = false;
// Copy the UNICODE main title
StringCopy(szMainTitleT, _countof(szMainTitleT), szMainTitle);
// Print the initial information
if(szMainTitle != NULL)
{
if(szSubTitle1 != NULL && szSubTitle2 != NULL)
_tprintf(_T("Running %s (%s+%s) ..."), szMainTitleT, szSubTitle1, szSubTitle2);
else if(szSubTitle1 != NULL)
_tprintf(_T("Running %s (%s) ..."), szMainTitleT, szSubTitle1);
else
_tprintf(_T("Running %s ..."), szMainTitleT);
}
}
TLogHelper::~TLogHelper()
{
const TCHAR * szSaveSubTitle1 = szSubTitle1;
const TCHAR * szSaveSubTitle2 = szSubTitle2;
TCHAR szSaveMainTitle[0x80];
// Set both to NULL so they won't be printed
StringCopy(szSaveMainTitle, _countof(szSaveMainTitle), szMainTitle);
szSubTitle1 = NULL;
szSubTitle2 = NULL;
szMainTitle = NULL;
// Print the final information
if(szSaveMainTitle != NULL && bMessagePrinted == false)
{
if(bDontPrintResult == false)
{
if(szSaveSubTitle1 != NULL && szSaveSubTitle2 != NULL)
PrintMessage(_T("%s (%s+%s) succeeded."), szSaveMainTitle, szSaveSubTitle1, szSaveSubTitle2);
else if(szSaveSubTitle1 != NULL)
PrintMessage(_T("%s (%s) succeeded."), szSaveMainTitle, szSaveSubTitle1);
else
PrintMessage(_T("%s succeeded."), szSaveMainTitle);
}
else
{
PrintProgress(" ");
printf("\r");
}
}
#if defined(_MSC_VER) && defined(_DEBUG)
if(_CrtDumpMemoryLeaks())
{
PrintMessage(_T("Memory leak(s) detected after %s.\n"), szSaveMainTitle);
}
#endif // _MSC_VER
}
//-----------------------------------------------------------------------------
// TCHAR-based functions. They are only needed on UNICODE builds.
// On ANSI builds is TCHAR = char, so we don't need them at all
#if defined(UNICODE) || defined(UNICODE)
int TLogHelper::PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine)
{
TCHAR szFormatBuff[0x200];
TCHAR szMessage[0x200];
TCHAR * szBuffer = szFormatBuff;
int nRemainingWidth;
int nConsoleWidth = GetConsoleWidth();
int nLength = 0;
int nError = GetLastError();
// Always start the buffer with '\r'
*szBuffer++ = '\r';
// Print the prefix, if needed
if(szMainTitle != NULL && bPrintPrefix)
{
while(szMainTitle[nLength] != 0)
*szBuffer++ = szMainTitle[nLength++];
*szBuffer++ = ':';
*szBuffer++ = ' ';
}
// Copy the message format itself. Replace %s with "%s", unless it's (%s)
if(szFormat != NULL)
{
while(szFormat[0] != 0)
{
szBuffer = CopyFormatCharacter(szBuffer, szFormat);
}
}
// Append the last error
if(bPrintLastError)
{
nLength = _stprintf(szBuffer, _T(" (error code: %u)"), nError);
szBuffer += nLength;
}
// Create the result string
szBuffer[0] = 0;
nLength = _vstprintf(szMessage, szFormatBuff, argList);
szBuffer = szMessage + nLength;
// Shall we pad the string?
if(nLength < nConsoleWidth)
{
// Calculate the remaining width
nRemainingWidth = nConsoleWidth - nLength - 1;
// Pad the string with spaces to fill it up to the end of the line
for(int i = 0; i < nRemainingWidth; i++)
*szBuffer++ = 0x20;
}
// Put the newline, if requested
*szBuffer++ = bPrintEndOfLine ? '\n' : 0;
*szBuffer = 0;
// Remember if we printed a message
if(bPrintEndOfLine)
bMessagePrinted = true;
// Spit out the text in one single printf
_tprintf(_T("%s"), szMessage);
return nError;
}
void TLogHelper::PrintProgress(const TCHAR * szFormat, ...)
{
va_list argList;
va_start(argList, szFormat);
PrintWithClreol(szFormat, argList, true, false, false);
va_end(argList);
}
void TLogHelper::PrintMessage(const TCHAR * szFormat, ...)
{
va_list argList;
va_start(argList, szFormat);
PrintWithClreol(szFormat, argList, true, false, true);
va_end(argList);
}
int TLogHelper::PrintErrorVa(const TCHAR * szFormat, ...)
{
va_list argList;
int nResult;
va_start(argList, szFormat);
nResult = PrintWithClreol(szFormat, argList, true, true, true);
va_end(argList);
return nResult;
}
int TLogHelper::PrintError(const TCHAR * szFormat, const TCHAR * szFileName)
{
return PrintErrorVa(szFormat, szFileName);
}
#endif // defined(UNICODE) || defined(UNICODE)
//-----------------------------------------------------------------------------
// ANSI functions
DWORD TLogHelper::PrintWithClreol(const char * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine)
{
char szFormatBuff[0x200];
char szMessage[0x200];
char * szBuffer = szFormatBuff;
int nRemainingWidth;
int nConsoleWidth = GetConsoleWidth();
int nLength = 0;
DWORD dwErrCode = GetLastError();
// Always start the buffer with '\r'
*szBuffer++ = '\r';
// Print the prefix, if needed
if(szMainTitle != NULL && bPrintPrefix)
{
while(szMainTitle[nLength] != 0)
*szBuffer++ = (char)szMainTitle[nLength++];
*szBuffer++ = ':';
*szBuffer++ = ' ';
}
// Copy the message format itself. Replace %s with "%s", unless it's (%s)
if(szFormat != NULL)
{
while(szFormat[0] != 0)
{
szBuffer = CopyFormatCharacter(szBuffer, szFormat);
}
}
// Append the last error
if(bPrintLastError)
{
nLength = sprintf(szBuffer, " (error code: %u)", dwErrCode);
szBuffer += nLength;
}
// Create the result string
szBuffer[0] = 0;
nLength = vsprintf(szMessage, szFormatBuff, argList);
// Shall we pad the string?
szBuffer = szMessage + nLength;
if(nLength < nConsoleWidth)
{
// Calculate the remaining width
nRemainingWidth = nConsoleWidth - nLength - 1;
// Pad the string with spaces to fill it up to the end of the line
for(int i = 0; i < nRemainingWidth; i++)
*szBuffer++ = 0x20;
}
// Put the newline, if requested
*szBuffer++ = bPrintEndOfLine ? '\n' : '\r';
*szBuffer = 0;
// Remember if we printed a message
if(bPrintEndOfLine)
bMessagePrinted = true;
// Spit out the text in one single printf
printf("%s", szMessage);
return dwErrCode;
}
void TLogHelper::PrintProgress(const char * szFormat, ...)
{
va_list argList;
va_start(argList, szFormat);
PrintWithClreol(szFormat, argList, true, false, false);
va_end(argList);
}
void TLogHelper::PrintMessage(const char * szFormat, ...)
{
va_list argList;
va_start(argList, szFormat);
PrintWithClreol(szFormat, argList, true, false, true);
va_end(argList);
}
DWORD TLogHelper::PrintErrorVa(const char * szFormat, ...)
{
va_list argList;
DWORD dwErrCode;
va_start(argList, szFormat);
dwErrCode = PrintWithClreol(szFormat, argList, true, true, true);
va_end(argList);
return dwErrCode;
}
DWORD TLogHelper::PrintError(const char * szFormat, const char * szFileName)
{
return PrintErrorVa(szFormat, szFileName);
}
//-----------------------------------------------------------------------------
// Protected functions
#ifdef _UNICODE
TCHAR * TLogHelper::CopyFormatCharacter(TCHAR * szBuffer, const TCHAR *& szFormat)
{
static const TCHAR * szStringFormat = _T("\"%s\"");
static const TCHAR * szUint64Format = I64u_t;
// String format
if(szFormat[0] == '%')
{
if(szFormat[1] == 's' && szFormat[2] != ')')
{
_tcscpy(szBuffer, szStringFormat);
szFormat += 2;
return szBuffer + _tcslen(szStringFormat);
}
// Replace %I64u with the proper platform-dependent suffix
if(szFormat[1] == 'I' && szFormat[2] == '6' && szFormat[3] == '4' && szFormat[4] == 'u')
{
_tcscpy(szBuffer, szUint64Format);
szFormat += 5;
return szBuffer + _tcslen(szUint64Format);
}
}
// Copy the character as-is
*szBuffer++ = *szFormat++;
return szBuffer;
}
#endif
char * TLogHelper::CopyFormatCharacter(char * szBuffer, const char *& szFormat)
{
static const char * szStringFormat = "\"%s\"";
static const char * szUint64Format = I64u_a;
// String format
if(szFormat[0] == '%')
{
if(szFormat[1] == 's' && szFormat[2] != ')')
{
strcpy(szBuffer, szStringFormat);
szFormat += 2;
return szBuffer + strlen(szStringFormat);
}
// Replace %I64u with the proper platform-dependent suffix
if(szFormat[1] == 'I' && szFormat[2] == '6' && szFormat[3] == '4' && szFormat[4] == 'u')
{
strcpy(szBuffer, szUint64Format);
szFormat += 5;
return szBuffer + strlen(szUint64Format);
}
}
// Copy the character as-is
*szBuffer++ = *szFormat++;
return szBuffer;
}
int TLogHelper::GetConsoleWidth()
{
#ifdef STORMLIB_WINDOWS
CONSOLE_SCREEN_BUFFER_INFO ScreenInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ScreenInfo);
return (int)(ScreenInfo.srWindow.Right - ScreenInfo.srWindow.Left);
#else
// On non-Windows platforms, we assume that width of the console line
// is 80 characters
return 120;
#endif
}