aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav Zezula <E:\Ladik\Mail>2016-03-13 16:17:00 +0100
committerLadislav Zezula <E:\Ladik\Mail>2016-03-13 16:17:00 +0100
commitb5b9acbaf081034e148f41af28a59ca5e29af282 (patch)
tree85789b305a0d3d76088a34febe91e3c6861fb535
parentf764c5a96294514559b17c3561be08cf1d304522 (diff)
+ Updates
-rw-r--r--StormLib_vs15.vcxproj2
-rw-r--r--src/SBaseFileTable.cpp6
-rw-r--r--src/SFileGetFileInfo.cpp11
-rw-r--r--src/StormLib.h1
-rw-r--r--test/StormTest.cpp62
5 files changed, 75 insertions, 7 deletions
diff --git a/StormLib_vs15.vcxproj b/StormLib_vs15.vcxproj
index 1f3b470..75d3b01 100644
--- a/StormLib_vs15.vcxproj
+++ b/StormLib_vs15.vcxproj
@@ -70,7 +70,7 @@
<ProjectName>StormLib</ProjectName>
<ProjectGuid>{78424708-1F6E-4D4B-920C-FB6D26847055}</ProjectGuid>
<RootNamespace>StormLib</RootNamespace>
- <WindowsTargetPlatformVersion>5.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugAS|Win32'" Label="Configuration">
diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp
index d822dc7..47bbf0e 100644
--- a/src/SBaseFileTable.cpp
+++ b/src/SBaseFileTable.cpp
@@ -771,9 +771,6 @@ static int BuildFileTableFromBlockTable(
pHashTableEnd = ha->pHashTable + pHeader->dwHashTableSize;
for(pHash = ha->pHashTable; pHash < pHashTableEnd; pHash++)
{
- DWORD dwBlockIndex = pHash->dwBlockIndex;
- DWORD dwNewIndex = pHash->dwBlockIndex;
-
// We need to mask out the upper 4 bits of the block table index.
// This is because it gets shifted out when calculating block table offset
// BlockTableOffset = pHash->dwBlockIndex * 0x10
@@ -792,6 +789,9 @@ static int BuildFileTableFromBlockTable(
if(IsValidHashEntry1(ha, pHash, pBlockTable))
{
+ DWORD dwBlockIndex = pHash->dwBlockIndex;
+ DWORD dwNewIndex = pHash->dwBlockIndex;
+
// Determine the new block index
if(DefragmentTable != NULL)
{
diff --git a/src/SFileGetFileInfo.cpp b/src/SFileGetFileInfo.cpp
index 9874793..365dce5 100644
--- a/src/SFileGetFileInfo.cpp
+++ b/src/SFileGetFileInfo.cpp
@@ -773,6 +773,17 @@ bool WINAPI SFileGetFileInfo(
}
break;
+ case SFileInfoCRC32:
+ hf = IsValidFileHandle(hMpqOrFile);
+ if(hf != NULL && hf->pFileEntry != NULL)
+ {
+ dwInt32Value = hf->pFileEntry->dwCrc32;
+ pvSrcFileInfo = &dwInt32Value;
+ cbSrcFileInfo = sizeof(DWORD);
+ nInfoType = SFILE_INFO_TYPE_DIRECT_POINTER;
+ }
+ break;
+
default: // Invalid info class
SetLastError(ERROR_INVALID_PARAMETER);
return false;
diff --git a/src/StormLib.h b/src/StormLib.h
index 8c3f6f9..22658bd 100644
--- a/src/StormLib.h
+++ b/src/StormLib.h
@@ -435,6 +435,7 @@ typedef enum _SFileInfoClass
SFileInfoFlags, // File flags from (DWORD)
SFileInfoEncryptionKey, // File encryption key
SFileInfoEncryptionKeyRaw, // Unfixed value of the file key
+ SFileInfoCRC32, // CRC32 of the file
} SFileInfoClass;
//-----------------------------------------------------------------------------
diff --git a/test/StormTest.cpp b/test/StormTest.cpp
index c6908dc..114870c 100644
--- a/test/StormTest.cpp
+++ b/test/StormTest.cpp
@@ -2420,6 +2420,54 @@ static int TestOpenFile_OpenById(const char * szPlainName)
return nError;
}
+static int TestOpenFile_OpenByName(const char * szPlainName, const char * szFileName)
+{
+ TLogHelper Logger("OpenFileById", szPlainName);
+ TFileData * pFileData = NULL;
+ HANDLE hFile;
+ HANDLE hMpq;
+ DWORD dwCrc32_1 = 0;
+ DWORD dwCrc32_2 = 0;
+ int nError;
+
+ // Copy the archive so we won't fuck up the original one
+ nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, NULL, &hMpq);
+
+ // Now try to open the given file
+ if(nError == ERROR_SUCCESS)
+ {
+ // Retrieve the CRC32
+ if(SFileOpenFileEx(hMpq, szFileName, 0, &hFile))
+ {
+ SFileGetFileInfo(hFile, SFileInfoCRC32, &dwCrc32_1, sizeof(dwCrc32_1), NULL);
+ SFileCloseFile(hFile);
+ }
+
+ // Load the entire file
+ pFileData = LoadMpqFile(&Logger, hMpq, szFileName);
+ if(pFileData != NULL)
+ {
+ // Compare the CRC32, if available
+ dwCrc32_2 = crc32(0, (Bytef *)pFileData->FileData, (uInt)pFileData->dwFileSize);
+ STORM_FREE(pFileData);
+ }
+ else
+ nError = Logger.PrintError("Failed to load the file %s", "File00000023.xxx");
+
+ // Compare the CRC32
+ if(nError == ERROR_SUCCESS && dwCrc32_1 && dwCrc32_2)
+ {
+ if(dwCrc32_1 != dwCrc32_2)
+ Logger.PrintError("Warning: CRC32 error on %s", szFileName);
+ }
+ }
+
+ // Close the archive
+ if(hMpq != NULL)
+ SFileCloseArchive(hMpq);
+ return nError;
+}
+
static int TestOpenArchive(const char * szPlainName, const char * szListFile = NULL, bool bDontCopyArchive = false)
{
TLogHelper Logger("OpenMpqTest", szPlainName);
@@ -4192,7 +4240,11 @@ int main(int argc, char * argv[])
// Test working with an archive that has no listfile
if(nError == ERROR_SUCCESS)
nError = TestOpenFile_OpenById("MPQ_1997_v1_Diablo1_DIABDAT.MPQ");
-
+*/
+ // Open the update MPQ from Diablo II (patch 2016)
+ if(nError == ERROR_SUCCESS)
+ nError = TestOpenFile_OpenByName("MPQ_2016_v1_D2XP_IX86_1xx_114a.mpq", "waitingroombkgd.dc6");
+/*
// Open a file whose archive's (signature) file has flags = 0x90000000
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_1997_v1_Diablo1_STANDARD.SNP", "ListFile_Blizzard.txt");
@@ -4288,6 +4340,10 @@ int main(int argc, char * argv[])
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2015_v1_flem1.w3x");
+ // Open another protected map
+ if(nError == ERROR_SUCCESS)
+ nError = TestOpenArchive("MPQ_2016_v1_ProtectedMap_TableSizeOverflow.w3x");
+
// Open the multi-file archive with wrong prefix to see how StormLib deals with it
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_WillFail("flat-file://streaming/model.MPQ.0");
@@ -4303,7 +4359,7 @@ int main(int argc, char * argv[])
// Test on an archive that has been invalidated by extending an old valid MPQ
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_Corrupt("MPQ_2013_vX_Battle.net.MPQ");
-*/
+
// Open a patched archive
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_Patched(PatchList_WoW_OldWorld13286, "OldWorld\\World\\Model.blob", 2);
@@ -4343,7 +4399,7 @@ int main(int argc, char * argv[])
// Open a patched archive
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_Patched(PatchList_HS_6898_enGB, "Hearthstone_Data\\Managed\\Assembly-Csharp.dll", 10);
-/*
+
// Check the opening archive for read-only
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_ReadOnly("MPQ_1997_v1_Diablo1_DIABDAT.MPQ", true);