Support for protected SCX files

This commit is contained in:
Ladislav Zezula
2021-12-17 14:51:35 +01:00
parent 5ced3835f9
commit 4f4f926c1a
15 changed files with 115 additions and 82 deletions

View File

@@ -18,6 +18,7 @@
#include "StormCommon.h"
#define HEADER_SEARCH_BUFFER_SIZE 0x1000
#define MINIMUM_MPQ_SIZE 0x0C
//-----------------------------------------------------------------------------
// Local functions
@@ -35,21 +36,28 @@ static MTYPE CheckMapType(LPCTSTR szFileName, LPBYTE pbHeaderBuffer, size_t cbHe
DWORD DwordValue2 = BSWAP_INT32_UNSIGNED(HeaderInt32[2]);
DWORD DwordValue3 = BSWAP_INT32_UNSIGNED(HeaderInt32[3]);
// Test for AVI files (Warcraft III cinematics) - 'RIFF', 'AVI ' or 'LIST'
if(DwordValue0 == 0x46464952 && DwordValue2 == 0x20495641 && DwordValue3 == 0x5453494C)
return MapTypeAviFile;
// Check for Starcraft II maps
// Check maps by extension (Starcraft, Starcraft II). We must do this before
// checking actual data, because the "NP_Protect" protector places
// fake Warcraft III header into the Starcraft II maps
if((szExtension = _tcsrchr(szFileName, _T('.'))) != NULL)
{
// The "NP_Protect" protector places fake Warcraft III header
// into the Starcraft II maps, whilst SC2 maps have no other header but MPQ v4
// Check for Starcraft II maps by extension
if(!_tcsicmp(szExtension, _T(".s2ma")) || !_tcsicmp(szExtension, _T(".SC2Map")) || !_tcsicmp(szExtension, _T(".SC2Mod")))
{
return MapTypeStarcraft2;
}
// Check for Starcraft I maps by extension
if(!_tcsicmp(szExtension, _T(".scm")) || !_tcsicmp(szExtension, _T(".scx")))
{
return MapTypeStarcraft;
}
}
// Test for AVI files (Warcraft III cinematics) - 'RIFF', 'AVI ' or 'LIST'
if(DwordValue0 == 0x46464952 && DwordValue2 == 0x20495641 && DwordValue3 == 0x5453494C)
return MapTypeAviFile;
// Check for Warcraft III maps
if(DwordValue0 == 0x57334D48 && DwordValue1 == 0x00000000)
return MapTypeWarcraft3;
@@ -271,6 +279,7 @@ bool WINAPI SFileOpenArchive(
bool bSearchComplete = false;
memset(ha, 0, sizeof(TMPQArchive));
ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS;
ha->pfnHashString = HashStringSlash;
ha->pStream = pStream;
pStream = NULL;
@@ -288,6 +297,8 @@ bool WINAPI SFileOpenArchive(
// Limit the header searching to about 130 MB of data
if(EndOfSearch > 0x08000000)
EndOfSearch = 0x08000000;
if(FileSize < HEADER_SEARCH_BUFFER_SIZE)
memset(pbHeaderBuffer, 0, HEADER_SEARCH_BUFFER_SIZE);
// Find the offset of MPQ header within the file
while(bSearchComplete == false && ByteOffset < EndOfSearch)
@@ -438,7 +449,14 @@ bool WINAPI SFileOpenArchive(
// Remember whether whis is a map for Warcraft III
if(MapType == MapTypeWarcraft3)
{
ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_W3X;
ha->dwFlags |= MPQ_FLAG_WAR3_MAP;
}
// If this is starcraft map, set the flag mask
if(MapType == MapTypeStarcraft)
ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_SCX;
// Set the size of file sector
ha->dwSectorSize = (0x200 << ha->pHeader->wSectorSize);