aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SCompression.cpp48
-rw-r--r--src/SFileOpenArchive.cpp19
-rw-r--r--src/StormLib.h20
3 files changed, 50 insertions, 37 deletions
diff --git a/src/SCompression.cpp b/src/SCompression.cpp
index 659c9a8..b689063 100644
--- a/src/SCompression.cpp
+++ b/src/SCompression.cpp
@@ -895,6 +895,16 @@ int WINAPI SCompCompress(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuff
/* */
/*****************************************************************************/
+// Decompression table specific for Starcraft I BETA
+// WAVE files are compressed by different ADPCM compression
+static TDecompressTable dcmp_table_sc_beta[] =
+{
+ {MPQ_COMPRESSION_PKWARE, Decompress_PKLIB}, // Decompression with Pkware Data Compression Library
+ {MPQ_COMPRESSION_HUFFMANN, Decompress_huff}, // Huffmann decompression
+ {0x10, Decompress_ADPCM1_sc1b}, // IMA ADPCM mono decompression
+ {0x20, Decompress_ADPCM2_sc1b}, // IMA ADPCM stereo decompression
+};
+
// This table contains decompress functions which can be applied to
// uncompressed data. The compression mask is stored in the first byte
// of compressed data
@@ -909,25 +919,22 @@ static TDecompressTable dcmp_table[] =
{MPQ_COMPRESSION_SPARSE, Decompress_SPARSE} // Sparse decompression
};
-// Decompression table specific for Starcraft I BETA
-// WAVE files are compressed by different ADPCM compression
-static TDecompressTable dcmp_table_sc1b[] =
-{
- {MPQ_COMPRESSION_PKWARE, Decompress_PKLIB}, // Decompression with Pkware Data Compression Library
- {MPQ_COMPRESSION_HUFFMANN, Decompress_huff}, // Huffmann decompression
- {0x10, Decompress_ADPCM1_sc1b}, // IMA ADPCM mono decompression
- {0x20, Decompress_ADPCM2_sc1b}, // IMA ADPCM stereo decompression
-};
-
-static int SCompDecompressInternal(TDecompressTable * table, size_t table_length, void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer)
+static int SCompDecompressInternal(
+ TDecompressTable * table,
+ size_t table_length,
+ void * pvOutBuffer,
+ int * pcbOutBuffer,
+ void * pvInBuffer,
+ int cbInBuffer,
+ unsigned uValidMask = 0xFF)
{
unsigned char * pbWorkBuffer = NULL;
unsigned char * pbOutBuffer = (unsigned char *)pvOutBuffer;
unsigned char * pbInBuffer = (unsigned char *)pvInBuffer;
unsigned char * pbOutput = (unsigned char *)pvOutBuffer;
unsigned char * pbInput;
- unsigned uCompressionMask; // Decompressions applied to the data
- unsigned uCompressionCopy; // Decompressions applied to the data
+ unsigned uCompressionMask1; // Decompressions applied to the data
+ unsigned uCompressionMask2; // Decompressions applied to the data
int cbOutBuffer = *pcbOutBuffer; // Current size of the output buffer
int cbInLength; // Current size of the input buffer
int nCompressCount = 0; // Number of compressions to be applied
@@ -948,7 +955,8 @@ static int SCompDecompressInternal(TDecompressTable * table, size_t table_length
}
// Get applied compression types and decrement data length
- uCompressionMask = uCompressionCopy = (unsigned char)(*pbInBuffer++);
+ uCompressionMask1 = ((unsigned char)(*pbInBuffer++) & (uValidMask));
+ uCompressionMask2 = uCompressionMask1;
cbInBuffer--;
// Get current compressed data and length of it
@@ -956,21 +964,21 @@ static int SCompDecompressInternal(TDecompressTable * table, size_t table_length
cbInLength = cbInBuffer;
// This compression function doesn't support LZMA
- assert(uCompressionMask != MPQ_COMPRESSION_LZMA);
+ assert(uCompressionMask1 != MPQ_COMPRESSION_LZMA);
// Parse the compression mask
for(size_t i = 0; i < table_length; i++)
{
// If the mask agrees, insert the compression function to the array
- if(uCompressionMask & table[i].uMask)
+ if(uCompressionMask1 & table[i].uMask)
{
- uCompressionCopy &= ~table[i].uMask;
+ uCompressionMask2 &= ~table[i].uMask;
nCompressCount++;
}
}
// If at least one of the compressions remaing unknown, return an error
- if(nCompressCount == 0 || uCompressionCopy != 0)
+ if(nCompressCount == 0 || uCompressionMask2 != 0)
{
SetLastError(ERROR_NOT_SUPPORTED);
return 0;
@@ -994,7 +1002,7 @@ static int SCompDecompressInternal(TDecompressTable * table, size_t table_length
for(size_t i = 0; i < table_length; i++)
{
// Perform the (next) decompression
- if(uCompressionMask & table[i].uMask)
+ if(uCompressionMask1 & table[i].uMask)
{
// Get the correct output buffer
pbOutput = (nCompressIndex & 1) ? pbWorkBuffer : pbOutBuffer;
@@ -1032,7 +1040,7 @@ int WINAPI SCompDecompress(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBu
int WINAPI SCompDecompress_SC1B(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer)
{
- return SCompDecompressInternal(dcmp_table_sc1b, _countof(dcmp_table_sc1b), pvOutBuffer, pcbOutBuffer, pvInBuffer, cbInBuffer);
+ return SCompDecompressInternal(dcmp_table_sc_beta, _countof(dcmp_table_sc_beta), pvOutBuffer, pcbOutBuffer, pvInBuffer, cbInBuffer);
}
int WINAPI SCompDecompress2(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer)
diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp
index 16e2491..f19a6e7 100644
--- a/src/SFileOpenArchive.cpp
+++ b/src/SFileOpenArchive.cpp
@@ -463,16 +463,19 @@ bool WINAPI SFileOpenArchive(
if(IsStarcraftBetaArchive(ha->pHeader))
ha->dwFlags |= MPQ_FLAG_STARCRAFT_BETA;
- // Remember whether whis is a map for Warcraft III
- if(MapType == MapTypeWarcraft3)
+ // Maps from StarCraft and Warcraft III need special treatment
+ switch(MapType)
{
- ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_W3X;
- ha->dwFlags |= MPQ_FLAG_WAR3_MAP;
- }
+ case MapTypeStarcraft:
+ ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_SCX;
+ ha->dwFlags |= MPQ_FLAG_STARCRAFT;
+ break;
- // If this is starcraft map, set the flag mask
- if(MapType == MapTypeStarcraft)
- ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_SCX;
+ case MapTypeWarcraft3:
+ ha->dwValidFileFlags = MPQ_FILE_VALID_FLAGS_W3X;
+ ha->dwFlags |= MPQ_FLAG_WAR3_MAP;
+ break;
+ }
// Set the size of file sector
ha->dwSectorSize = (0x200 << ha->pHeader->wSectorSize);
diff --git a/src/StormLib.h b/src/StormLib.h
index 07408b2..5142868 100644
--- a/src/StormLib.h
+++ b/src/StormLib.h
@@ -194,15 +194,16 @@ extern "C" {
#define MPQ_FLAG_CHECK_SECTOR_CRC 0x00000020 // Checking sector CRC when reading files
#define MPQ_FLAG_SAVING_TABLES 0x00000040 // If set, we are saving MPQ internal files and MPQ tables
#define MPQ_FLAG_PATCH 0x00000080 // If set, this MPQ is a patch archive
-#define MPQ_FLAG_WAR3_MAP 0x00000100 // If set, this MPQ is a Warcraft III map
-#define MPQ_FLAG_STARCRAFT_BETA 0x00000200 // If set, this MPQ is StarDat.mpq from Starcraft I BETA
-#define MPQ_FLAG_LISTFILE_NONE 0x00000400 // Set when no (listfile) was found in InvalidateInternalFiles
-#define MPQ_FLAG_LISTFILE_NEW 0x00000800 // Set when (listfile) invalidated by InvalidateInternalFiles
-#define MPQ_FLAG_LISTFILE_FORCE 0x00001000 // Save updated listfile on exit
-#define MPQ_FLAG_ATTRIBUTES_NONE 0x00002000 // Set when no (attributes) was found in InvalidateInternalFiles
-#define MPQ_FLAG_ATTRIBUTES_NEW 0x00004000 // Set when (attributes) invalidated by InvalidateInternalFiles
-#define MPQ_FLAG_SIGNATURE_NONE 0x00008000 // Set when no (signature) was found in InvalidateInternalFiles
-#define MPQ_FLAG_SIGNATURE_NEW 0x00010000 // Set when (signature) invalidated by InvalidateInternalFiles
+#define MPQ_FLAG_STARCRAFT_BETA 0x00000100 // If set, this MPQ is from Starcraft I BETA
+#define MPQ_FLAG_STARCRAFT 0x00000200 // If set, this MPQ is from Starcraft I
+#define MPQ_FLAG_WAR3_MAP 0x00000400 // If set, this MPQ is a Warcraft III map
+#define MPQ_FLAG_LISTFILE_NONE 0x00000800 // Set when no (listfile) was found in InvalidateInternalFiles
+#define MPQ_FLAG_LISTFILE_NEW 0x00001000 // Set when (listfile) invalidated by InvalidateInternalFiles
+#define MPQ_FLAG_LISTFILE_FORCE 0x00002000 // Save updated listfile on exit
+#define MPQ_FLAG_ATTRIBUTES_NONE 0x00004000 // Set when no (attributes) was found in InvalidateInternalFiles
+#define MPQ_FLAG_ATTRIBUTES_NEW 0x00008000 // Set when (attributes) invalidated by InvalidateInternalFiles
+#define MPQ_FLAG_SIGNATURE_NONE 0x00010000 // Set when no (signature) was found in InvalidateInternalFiles
+#define MPQ_FLAG_SIGNATURE_NEW 0x00020000 // Set when (signature) invalidated by InvalidateInternalFiles
// Values for TMPQArchive::dwSubType
#define MPQ_SUBTYPE_MPQ 0x00000000 // The file is a MPQ file (Blizzard games)
@@ -1122,6 +1123,7 @@ int WINAPI SCompCompress (void * pvOutBuffer, int * pcbOutBuffer, void * pv
int WINAPI SCompDecompress (void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer);
int WINAPI SCompDecompress2(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer);
int WINAPI SCompDecompress_SC1B(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer);
+//int WINAPI SCompDecompress_SCBW(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer);
//-----------------------------------------------------------------------------
// Non-Windows support for SetLastError/GetLastError