Skip to content

Commit 495b2ab

Browse files
author
Ladislav Zezula
committed
+ Fixed bug in processing HET table
1 parent eec7547 commit 495b2ab

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

doc/History.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
StormLib history
33
================
44

5+
Version 9.11
6+
7+
- Fixed bug in processing HET table.
8+
59
Version 9.10
610

711
- Support for weak-signing

src/SBaseFileTable.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWOR
11151115
BYTE NameHash1;
11161116

11171117
// Get the start index and the high 8 bits of the name hash
1118-
StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwEntryCount);
1118+
StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwTotalCount);
11191119
NameHash1 = (BYTE)(FileNameHash >> (pHetTable->dwNameHashBitSize - 8));
11201120

11211121
// Find a place where to put it
@@ -1137,7 +1137,7 @@ static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWOR
11371137

11381138
// Move to the next entry in the HET table
11391139
// If we came to the start index again, we are done
1140-
Index = (Index + 1) % pHetTable->dwEntryCount;
1140+
Index = (Index + 1) % pHetTable->dwTotalCount;
11411141
if(Index == StartIndex)
11421142
break;
11431143
}
@@ -1257,7 +1257,7 @@ DWORD GetFileIndex_Het(TMPQArchive * ha, const char * szFileName)
12571257
NameHash1 = (BYTE)(FileNameHash >> (pHetTable->dwNameHashBitSize - 8));
12581258

12591259
// Calculate the starting index to the hash table
1260-
StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwEntryCount);
1260+
StartIndex = Index = (DWORD)(FileNameHash % pHetTable->dwTotalCount);
12611261

12621262
// Go through HET table until we find a terminator
12631263
while(pHetTable->pNameHashes[Index] != HET_ENTRY_FREE)
@@ -1286,7 +1286,7 @@ DWORD GetFileIndex_Het(TMPQArchive * ha, const char * szFileName)
12861286

12871287
// Move to the next entry in the HET table
12881288
// If we came to the start index again, we are done
1289-
Index = (Index + 1) % pHetTable->dwEntryCount;
1289+
Index = (Index + 1) % pHetTable->dwTotalCount;
12901290
if(Index == StartIndex)
12911291
break;
12921292
}
@@ -2438,7 +2438,7 @@ int BuildFileTable_HetBet(
24382438
return ERROR_FILE_CORRUPT;
24392439

24402440
// Step one: Fill the name indexes
2441-
for(i = 0; i < pHetTable->dwEntryCount; i++)
2441+
for(i = 0; i < pHetTable->dwTotalCount; i++)
24422442
{
24432443
DWORD dwFileIndex = 0;
24442444

src/StormLib.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
/* 14.01.13 8.21 Lad ADPCM and Huffmann (de)compression refactored */
7070
/* 04.12.13 9.00 Lad Unit tests, bug fixes */
7171
/* 27.08.14 9.10 Lad Signing archives with weak digital signature */
72+
/* 25.11.14 9.11 Lad Fixed bug reading & creating HET table */
7273
/*****************************************************************************/
7374

7475
#ifndef __STORMLIB_H__
@@ -133,8 +134,8 @@ extern "C" {
133134
//-----------------------------------------------------------------------------
134135
// Defines
135136

136-
#define STORMLIB_VERSION 0x090A // Current version of StormLib (9.1)
137-
#define STORMLIB_VERSION_STRING "9.10" // String version of StormLib version
137+
#define STORMLIB_VERSION 0x090B // Current version of StormLib (9.11)
138+
#define STORMLIB_VERSION_STRING "9.11" // String version of StormLib version
138139

139140
#define ID_MPQ 0x1A51504D // MPQ archive header ID ('MPQ\x1A')
140141
#define ID_MPQ_USERDATA 0x1B51504D // MPQ userdata entry ('MPQ\x1B')

test/StormTest.cpp

+49-1
Original file line numberDiff line numberDiff line change
@@ -3754,6 +3754,50 @@ static int TestCreateArchive_BigArchive(const char * szPlainName)
37543754
return nError;
37553755
}
37563756

3757+
// "MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events"
3758+
static int TestModifyArchive_ReplaceFile(const char * szPlainName, const char * szFileName)
3759+
{
3760+
TLogHelper Logger("ModifyTest");
3761+
HANDLE hMpq = NULL;
3762+
HANDLE hFile = NULL;
3763+
const char * szArchivedName;
3764+
char szLocalFileName[MAX_PATH];
3765+
size_t nOffset = 0;
3766+
int nError;
3767+
3768+
// Open an existing archive
3769+
nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq);
3770+
3771+
// Add the given file
3772+
if(nError == ERROR_SUCCESS)
3773+
{
3774+
// Get the name of archived file
3775+
if(!_strnicmp(szFileName, "AddFile-", 8))
3776+
nOffset = 8;
3777+
szArchivedName = szFileName + nOffset;
3778+
3779+
// Just for test - try to open the file in the archive
3780+
if(SFileOpenFileEx(hMpq, szArchivedName, 0, &hFile))
3781+
SFileCloseFile(hFile);
3782+
3783+
// Create the local file name
3784+
CreateFullPathName(szLocalFileName, szMpqSubDir, szFileName);
3785+
3786+
// Add the file to MPQ
3787+
nError = AddLocalFileToMpq(&Logger, hMpq,
3788+
szArchivedName,
3789+
szLocalFileName,
3790+
MPQ_FILE_REPLACEEXISTING | MPQ_FILE_COMPRESS | MPQ_FILE_SINGLE_UNIT,
3791+
MPQ_COMPRESSION_ZLIB,
3792+
true);
3793+
}
3794+
3795+
// Close the MPQ
3796+
if(hMpq != NULL)
3797+
SFileCloseArchive(hMpq);
3798+
return nError;
3799+
}
3800+
37573801
//-----------------------------------------------------------------------------
37583802
// Comparing two directories, creating links
37593803

@@ -4005,7 +4049,7 @@ int main(int argc, char * argv[])
40054049
// Open a patched archive.
40064050
if(nError == ERROR_SUCCESS)
40074051
nError = TestOpenArchive_Patched(PatchList_WoW_16965, "DBFilesClient\\BattlePetNPCTeamMember.db2", 0);
4008-
*/
4052+
40094053
// Open a patched archive.
40104054
if(nError == ERROR_SUCCESS)
40114055
nError = TestOpenArchive_Patched(PatchList_SC2_32283, "TriggerLibs\\natives.galaxy", 6);
@@ -4144,6 +4188,10 @@ int main(int argc, char * argv[])
41444188
// Open a MPQ (add custom user data to it)
41454189
if(nError == ERROR_SUCCESS)
41464190
nError = TestCreateArchive_BigArchive("StormLibTest_BigArchive_v4.mpq");
4191+
*/
4192+
// Test modifying a replay file from Heroes of the Storm
4193+
if(nError == ERROR_SUCCESS)
4194+
nError = TestModifyArchive_ReplaceFile("MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events");
41474195

41484196
return nError;
41494197
}

0 commit comments

Comments
 (0)