From: ShadowFlare Date: Sun, 23 Aug 2009 08:59:27 +0000 (-0600) Subject: Fix a hash table search bug and remove SComp.h X-Git-Url: https://sfsrealm.hopto.org/projects/gitweb.cgi?a=commitdiff_plain;h=46511c53b667ffb988cf1673c3939e9ef3d26dd8;p=SFmpqapi.git Fix a hash table search bug and remove SComp.h - Fixed hash table search for adding/replacing files. It should have finished searching for an existing file before considering free slots. - Removed extra copy of SComp.h and instead references the one from SComp directly. --- diff --git a/SComp.h b/SComp.h deleted file mode 100644 index 37a8e93..0000000 --- a/SComp.h +++ /dev/null @@ -1,25 +0,0 @@ -// SComp.h - Header for main compression/decompression routines -// License information for this code is in license.txt - -#ifndef S_COMP_INCLUDED -#define S_COMP_INCLUDED - -#if (defined(_WIN32) || defined(WIN32)) && !defined(NO_WINDOWS_H) -#include -#else -#include "wintypes.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -BOOL WINAPI SCompCompress(LPVOID lpvDestinationMem, LPDWORD lpdwCompressedSize, LPVOID lpvSourceMem, DWORD dwDecompressedSize, DWORD dwCompressionType, DWORD dwCompressionSubType, DWORD dwCompressLevel); -BOOL WINAPI SCompDecompress(LPVOID lpvDestinationMem, LPDWORD lpdwDecompressedSize, LPVOID lpvSourceMem, DWORD dwCompressedSize); - -#ifdef __cplusplus -}; // extern "C" -#endif - -#endif - diff --git a/SFmpqapi.cpp b/SFmpqapi.cpp index c9a7322..a5b264f 100644 --- a/SFmpqapi.cpp +++ b/SFmpqapi.cpp @@ -12,7 +12,7 @@ #include #endif -#include "SComp.h" +#include "../SComp/SComp.h" #include "SFmpqapi.h" @@ -3227,12 +3227,19 @@ MPQHANDLE GetFreeHashTableEntry(MPQHANDLE hMPQ, LPCSTR lpFileName, LCID FileLoca DWORD dwTablePos = HashString(lpFileName,HASH_POSITION) % mpqOpenArc->MpqHeader.dwHashTableSize; DWORD dwNameHashA = HashString(lpFileName,HASH_NAME_A); DWORD dwNameHashB = HashString(lpFileName,HASH_NAME_B); - DWORD i=dwTablePos; + DWORD i=dwTablePos, nFirstFree = 0xFFFFFFFF; do { - if ((mpqOpenArc->lpHashTable[i].dwBlockTableIndex&0xFFFFFFFE)==0xFFFFFFFE) + if ((mpqOpenArc->lpHashTable[i].dwBlockTableIndex&0xFFFFFFFE)==0xFFFFFFFE && nFirstFree == 0xFFFFFFFF) { - return (MPQHANDLE)&mpqOpenArc->lpHashTable[i]; + if (mpqOpenArc->lpHashTable[i].dwBlockTableIndex == 0xFFFFFFFF) + { + if (nFirstFree == 0xFFFFFFFF) + return (MPQHANDLE)&mpqOpenArc->lpHashTable[i]; + else + return (MPQHANDLE)&mpqOpenArc->lpHashTable[nFirstFree]; + } + else nFirstFree = i; } else if (mpqOpenArc->lpHashTable[i].dwNameHashA==dwNameHashA && mpqOpenArc->lpHashTable[i].dwNameHashB==dwNameHashB && mpqOpenArc->lpHashTable[i].lcLocale==FileLocale) { diff --git a/SFmpqapi.vcproj b/SFmpqapi.vcproj index aedff70..04ec697 100644 --- a/SFmpqapi.vcproj +++ b/SFmpqapi.vcproj @@ -243,6 +243,7 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" + EnableFunctionLevelLinking="true" PrecompiledHeaderFile=".\Debug/SFmpqapi.pch" AssemblerListingLocation=".\Debug/" ObjectFile=".\Debug/" @@ -614,10 +615,6 @@ RelativePath="..\SComp\SComp.h" > - -