diff options
author | Ladislav Zezula <zezula@volny.cz> | 2023-12-27 20:25:21 +0100 |
---|---|---|
committer | Ladislav Zezula <zezula@volny.cz> | 2023-12-27 20:25:21 +0100 |
commit | 2e3882409954eb1a3a7830df7d117cd16773fda7 (patch) | |
tree | 827356d0fef16ce8e3e96206ff76b842340e2cc2 /src | |
parent | 61b6665433e8de0e4be68e69ddfb0128421d4057 (diff) |
Improved retrieving the hash entry index
Diffstat (limited to 'src')
-rw-r--r-- | src/SFileOpenFileEx.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/SFileOpenFileEx.cpp b/src/SFileOpenFileEx.cpp index d26e01e..157ad15 100644 --- a/src/SFileOpenFileEx.cpp +++ b/src/SFileOpenFileEx.cpp @@ -16,10 +16,13 @@ /* Local functions */ /*****************************************************************************/ +// Finds hash index of the entry that was open by pseudo-name static DWORD FindHashIndex(TMPQArchive * ha, DWORD dwFileIndex) { TMPQHash * pHashTableEnd; TMPQHash * pHash; + DWORD dwHashIndex = HASH_ENTRY_FREE; + DWORD dwCount = 0; // Should only be called if the archive has hash table assert(ha->pHashTable != NULL); @@ -31,15 +34,18 @@ static DWORD FindHashIndex(TMPQArchive * ha, DWORD dwFileIndex) { if(MPQ_BLOCK_INDEX(pHash) == dwFileIndex) { - // Find the first hash entry that points to it. - // If there are multiple hash entries that point - // to the same file, only the first one is returned. - return (DWORD)(pHash - ha->pHashTable); + // Example: MPQ_2023_v1_Lusin2Rpg1.28.w3x, file index 24483 + // ReplaceableTextures\CommandButtons\BTNHaboss79.blp + // Hash Table Index #1 = 18 + // Hash Table Index #2 = 8446 + if(dwCount++ > 0) + return HASH_ENTRY_FREE; + dwHashIndex = (DWORD)(pHash - ha->pHashTable); } } - // No item was found - return HASH_ENTRY_FREE; + // Return the found hash index, if there are no duplicities + return dwHashIndex; } static const char * GetPatchFileName(TMPQArchive * ha, const char * szFileName, char * szBuffer) |