Skip to content

Commit 07559b3

Browse files
Fixed opening of Warcraft III maps that don't have W3M header
1 parent b62de3c commit 07559b3

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/SFileOpenArchive.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static MTYPE CheckMapType(LPCTSTR szFileName, LPBYTE pbHeaderBuffer, size_t cbHe
5151
{
5252
LPDWORD HeaderInt32 = (LPDWORD)pbHeaderBuffer;
5353
LPCTSTR szExtension;
54+
MTYPE TypeByExtension = MapTypeNotRecognized;
5455

5556
// Don't do any checks if there is not at least 16 bytes
5657
if(cbHeaderBuffer > 0x10)
@@ -65,16 +66,22 @@ static MTYPE CheckMapType(LPCTSTR szFileName, LPBYTE pbHeaderBuffer, size_t cbHe
6566
// fake Warcraft III header into the Starcraft II maps
6667
if((szExtension = _tcsrchr(szFileName, _T('.'))) != NULL)
6768
{
69+
// Check for Starcraft I maps by extension
70+
if(!_tcsicmp(szExtension, _T(".scm")) || !_tcsicmp(szExtension, _T(".scx")))
71+
{
72+
return MapTypeStarcraft;
73+
}
74+
6875
// Check for Starcraft II maps by extension
6976
if(!_tcsicmp(szExtension, _T(".s2ma")) || !_tcsicmp(szExtension, _T(".SC2Map")) || !_tcsicmp(szExtension, _T(".SC2Mod")))
7077
{
7178
return MapTypeStarcraft2;
7279
}
7380

74-
// Check for Starcraft I maps by extension
75-
if(!_tcsicmp(szExtension, _T(".scm")) || !_tcsicmp(szExtension, _T(".scx")))
81+
// Check for Warcraft III maps by extension
82+
if(!_tcsicmp(szExtension, _T(".w3m")) || !_tcsicmp(szExtension, _T(".w3x")))
7683
{
77-
return MapTypeStarcraft;
84+
TypeByExtension = MapTypeWarcraft3;
7885
}
7986
}
8087

@@ -112,7 +119,7 @@ static MTYPE CheckMapType(LPCTSTR szFileName, LPBYTE pbHeaderBuffer, size_t cbHe
112119
}
113120

114121
// No special map type recognized
115-
return MapTypeNotRecognized;
122+
return TypeByExtension;
116123
}
117124

118125
static bool IsStarcraftBetaArchive(TMPQHeader * pHeader)

src/StormLib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************************/
2-
/* StormLib.h Copyright (c) Ladislav Zezula 1999-2017 */
2+
/* StormLib.h Copyright (c) Ladislav Zezula 1999-2025 */
33
/*---------------------------------------------------------------------------*/
44
/* StormLib library v 9.30 */
55
/* */

test/StormTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,14 +3955,14 @@ static DWORD TestUtf8Conversions(const BYTE * szTestString, const TCHAR * szList
39553955

39563956
static void Test_PlayingSpace()
39573957
{
3958-
/*
3958+
39593959
HANDLE hMpq;
39603960
HANDLE hFile;
39613961
LPBYTE pbData;
39623962
DWORD dwFileSize = 529298;
39633963
DWORD dwBytesRead = 0;
39643964

3965-
if(SFileOpenArchive(_T("e:\\2.mpq"), 0, 0, &hMpq))
3965+
if(SFileOpenArchive(_T("e:\\Legion_TD_11_2d-BETA_2_TeamOZE.w3x"), 0, 0, &hMpq))
39663966
{
39673967
if(SFileOpenFileEx(hMpq, "(listfile)", 0, &hFile))
39683968
{
@@ -3975,7 +3975,7 @@ static void Test_PlayingSpace()
39753975
}
39763976
SFileCloseArchive(hMpq);
39773977
}
3978-
*/
3978+
39793979
}
39803980

39813981
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)