aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLadislav Zezula <ladislav.zezula@avg.com>2016-07-14 14:15:29 +0200
committerLadislav Zezula <ladislav.zezula@avg.com>2016-07-14 14:15:29 +0200
commitf3112547853a361f9c5419cfb6810b2a54c643e6 (patch)
treeef7998fbd7f3d47e564005dd0b173151275329f3 /src
parent7597fe1702e4f27faf51d201b566139e17ad4342 (diff)
+ Fixed bug in opening SQP archives
+ More efficient version of GetNearestPowerOfTwo
Diffstat (limited to 'src')
-rw-r--r--src/SBaseCommon.cpp28
-rw-r--r--src/SBaseFileTable.cpp2
-rw-r--r--src/SBaseSubTypes.cpp4
-rw-r--r--src/SFileCompactArchive.cpp2
-rw-r--r--src/SFileCreateArchive.cpp2
-rw-r--r--src/StormCommon.h2
6 files changed, 20 insertions, 20 deletions
diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp
index 5483f55..02dc124 100644
--- a/src/SBaseCommon.cpp
+++ b/src/SBaseCommon.cpp
@@ -257,20 +257,20 @@ DWORD HashStringLower(const char * szFileName, DWORD dwHashType)
// Returns the nearest higher power of two.
// If the value is already a power of two, returns the same value
-//static DWORD GetNearestPowerOfTwo(DWORD dwValue)
-//{
-// dwValue --;
-//
-// dwValue |= dwValue >> 1;
-// dwValue |= dwValue >> 2;
-// dwValue |= dwValue >> 4;
-// dwValue |= dwValue >> 8;
-// dwValue |= dwValue >> 16;
-//
-// return dwValue + 1;
-//}
+DWORD GetNearestPowerOfTwo(DWORD dwFileCount)
+{
+ dwFileCount --;
-DWORD GetHashTableSizeForFileCount(DWORD dwFileCount)
+ dwFileCount |= dwFileCount >> 1;
+ dwFileCount |= dwFileCount >> 2;
+ dwFileCount |= dwFileCount >> 4;
+ dwFileCount |= dwFileCount >> 8;
+ dwFileCount |= dwFileCount >> 16;
+
+ return dwFileCount + 1;
+}
+/*
+DWORD GetNearestPowerOfTwo(DWORD dwFileCount)
{
DWORD dwPowerOfTwo = HASH_TABLE_SIZE_MIN;
@@ -284,7 +284,7 @@ DWORD GetHashTableSizeForFileCount(DWORD dwFileCount)
dwPowerOfTwo <<= 1;
return dwPowerOfTwo;
}
-
+*/
//-----------------------------------------------------------------------------
// Calculates a Jenkin's Encrypting and decrypting MPQ file data
diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp
index 981328b..fe5eb78 100644
--- a/src/SBaseFileTable.cpp
+++ b/src/SBaseFileTable.cpp
@@ -701,7 +701,7 @@ static TMPQHash * DefragmentHashTable(
// Calculate how many entries in the hash table we really need
dwFirstFreeEntry = (DWORD)(pTarget - pHashTable);
- dwNewTableSize = GetHashTableSizeForFileCount(dwFirstFreeEntry);
+ dwNewTableSize = GetNearestPowerOfTwo(dwFirstFreeEntry);
// Fill the rest with entries that look like deleted
pHashTableEnd = pHashTable + dwNewTableSize;
diff --git a/src/SBaseSubTypes.cpp b/src/SBaseSubTypes.cpp
index 1f72c17..333b881 100644
--- a/src/SBaseSubTypes.cpp
+++ b/src/SBaseSubTypes.cpp
@@ -202,7 +202,7 @@ TMPQHash * LoadSqpHashTable(TMPQArchive * ha)
if(pSqpHash->dwBlockIndex != HASH_ENTRY_FREE)
{
// Check block index against the size of the block table
- if(pHeader->dwBlockTableSize <= MPQ_BLOCK_INDEX(pSqpHash) && MPQ_BLOCK_INDEX(pSqpHash) < HASH_ENTRY_DELETED)
+ if(pHeader->dwBlockTableSize <= MPQ_BLOCK_INDEX(pSqpHash) && pSqpHash->dwBlockIndex < HASH_ENTRY_DELETED)
nError = ERROR_FILE_CORRUPT;
// We do not support nonzero locale and platform ID
@@ -523,7 +523,7 @@ TMPQHash * LoadMpkHashTable(TMPQArchive * ha)
if(pMpkHash != NULL)
{
// Calculate the hash table size as if it was real MPQ hash table
- pHeader->dwHashTableSize = GetHashTableSizeForFileCount(pHeader->dwHashTableSize);
+ pHeader->dwHashTableSize = GetNearestPowerOfTwo(pHeader->dwHashTableSize);
pHeader->HashTableSize64 = pHeader->dwHashTableSize * sizeof(TMPQHash);
// Now allocate table that will serve like a true MPQ hash table,
diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp
index 57c8839..2895baa 100644
--- a/src/SFileCompactArchive.cpp
+++ b/src/SFileCompactArchive.cpp
@@ -481,7 +481,7 @@ bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount)
if(nError == ERROR_SUCCESS)
{
// Calculate the hash table size for the new file limit
- dwNewHashTableSize = GetHashTableSizeForFileCount(dwMaxFileCount);
+ dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount);
// Rebuild both file tables
nError = RebuildFileTable(ha, dwNewHashTableSize);
diff --git a/src/SFileCreateArchive.cpp b/src/SFileCreateArchive.cpp
index df32759..47354fe 100644
--- a/src/SFileCreateArchive.cpp
+++ b/src/SFileCreateArchive.cpp
@@ -178,7 +178,7 @@ bool WINAPI SFileCreateArchive2(const TCHAR * szMpqName, PSFILE_CREATE_MPQ pCrea
}
// If file count is not zero, initialize the hash table size
- dwHashTableSize = GetHashTableSizeForFileCount(pCreateInfo->dwMaxFileCount + dwReservedFiles);
+ dwHashTableSize = GetNearestPowerOfTwo(pCreateInfo->dwMaxFileCount + dwReservedFiles);
// Retrieve the file size and round it up to 0x200 bytes
FileStream_GetSize(pStream, &MpqPos);
diff --git a/src/StormCommon.h b/src/StormCommon.h
index 3c2148e..27ba45f 100644
--- a/src/StormCommon.h
+++ b/src/StormCommon.h
@@ -154,7 +154,7 @@ DWORD HashStringLower(const char * szFileName, DWORD dwHashType);
void InitializeMpqCryptography();
-DWORD GetHashTableSizeForFileCount(DWORD dwFileCount);
+DWORD GetNearestPowerOfTwo(DWORD dwFileCount);
bool IsPseudoFileName(const char * szFileName, LPDWORD pdwFileIndex);
ULONGLONG HashStringJenkins(const char * szFileName);