From 305583053bf2796adf3162cf617020c250d7faf7 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 3 Oct 2022 18:52:31 +0200 Subject: Locale & platform problems fixed, regression tests done --- src/SBaseFileTable.cpp | 17 ++++++++++------- src/SFileAddFile.cpp | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index 6e589a5..b68de51 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -803,27 +803,31 @@ static TMPQHash * GetHashEntryLocale(TMPQArchive * ha, const char * szFileName, } // Returns a hash table entry in the following order: -// 1) A hash table entry with the preferred locale +// 1) A hash table entry with the preferred locale&platform // 2) NULL +// In case there are multiple items with the same locale&platform, +// we need to return the last one. This is because it must correspond to SFileOpenFileEx static TMPQHash * GetHashEntryExact(TMPQArchive * ha, const char * szFileName, LCID lcFileLocale) { TMPQHash * pFirstHash = GetFirstHashEntry(ha, szFileName); + TMPQHash * pBestHash = NULL; TMPQHash * pHash = pFirstHash; USHORT Locale = SFILE_LOCALE(lcFileLocale); + BYTE Platform = SFILE_PLATFORM(lcFileLocale); // Parse the found hashes while(pHash != NULL) { - // If the locales match, return it - if(pHash->Locale == Locale) - return pHash; + // If the locales match, we remember this one as the best one + if(pHash->Locale == Locale && pHash->Platform == Platform) + pBestHash = pHash; // Get the next hash entry for that file pHash = GetNextHashEntry(ha, pFirstHash, pHash); } - // Not found - return NULL; + // Return the best hash or NULL + return pBestHash; } // Defragment the file table so it does not contain any gaps @@ -928,7 +932,6 @@ static DWORD BuildFileTableFromBlockTable( if(ha->dwFlags & (MPQ_FLAG_HASH_TABLE_CUT | MPQ_FLAG_BLOCK_TABLE_CUT)) { // Sanity checks - assert(pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1); assert(pHeader->HiBlockTablePos64 == 0); // Allocate the translation table diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index ce177e6..b1288f1 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -441,7 +441,7 @@ DWORD SFileAddFile_Init( if(dwErrCode == ERROR_SUCCESS) { // Check if the file already exists in the archive - pFileEntry = GetFileEntryLocale(ha, szFileName, lcFileLocale, &dwHashIndex); + pFileEntry = GetFileEntryExact(ha, szFileName, lcFileLocale, &dwHashIndex); if(pFileEntry != NULL) { if(dwFlags & MPQ_FILE_REPLACEEXISTING) -- cgit v1.2.3