aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2020-10-26 08:12:25 +0100
committerGitHub <noreply@github.com>2020-10-26 08:12:25 +0100
commit6e836417806d2ca6944b2565c506590d91f21d5c (patch)
treeb6352136f402f3962d8b56cca5cccd1c7346a29f
parent7e4f377e0b45c737f26309ae602addc05c9b6b30 (diff)
parentf3560fa9af389d9b8be09b4e90f668fc22ed531f (diff)
Merge pull request #190 from ladislav-zezula/TBitArrayChangedToPrivate
Resolved name conflicts with Unreal Engine 4
-rw-r--r--src/FileStream.cpp46
-rw-r--r--src/SBaseCommon.cpp4
-rw-r--r--src/SBaseFileTable.cpp94
-rw-r--r--src/StormLib.h78
-rw-r--r--src/StormPort.h52
5 files changed, 137 insertions, 137 deletions
diff --git a/src/FileStream.cpp b/src/FileStream.cpp
index a462690..06f7627 100644
--- a/src/FileStream.cpp
+++ b/src/FileStream.cpp
@@ -33,7 +33,7 @@
//-----------------------------------------------------------------------------
// Local functions - platform-specific functions
-#ifndef PLATFORM_WINDOWS
+#ifndef STORMLIB_WINDOWS
static DWORD nLastError = ERROR_SUCCESS;
DWORD GetLastError()
@@ -89,7 +89,7 @@ static void BaseNone_Init(TFileStream *)
static bool BaseFile_Create(TFileStream * pStream)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
{
DWORD dwWriteShare = (pStream->dwFlags & STREAM_FLAG_WRITE_SHARE) ? FILE_SHARE_WRITE : 0;
@@ -105,7 +105,7 @@ static bool BaseFile_Create(TFileStream * pStream)
}
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
{
intptr_t handle;
@@ -128,7 +128,7 @@ static bool BaseFile_Create(TFileStream * pStream)
static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
{
ULARGE_INTEGER FileSize;
DWORD dwWriteAccess = (dwStreamFlags & STREAM_FLAG_READ_ONLY) ? 0 : FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES;
@@ -154,7 +154,7 @@ static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD
}
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
{
struct stat64 fileinfo;
int oflag = (dwStreamFlags & STREAM_FLAG_READ_ONLY) ? O_RDONLY : O_RDWR;
@@ -199,7 +199,7 @@ static bool BaseFile_Read(
ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
DWORD dwBytesRead = 0; // Must be set by platform-specific code
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
{
// Note: StormLib no longer supports Windows 9x.
// Thus, we can use the OVERLAPPED structure to specify
@@ -223,7 +223,7 @@ static bool BaseFile_Read(
}
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
{
ssize_t bytes_read;
@@ -270,7 +270,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const
ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.File.FilePos;
DWORD dwBytesWritten = 0; // Must be set by platform-specific code
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
{
// Note: StormLib no longer supports Windows 9x.
// Thus, we can use the OVERLAPPED structure to specify
@@ -294,7 +294,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const
}
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
{
ssize_t bytes_written;
@@ -336,7 +336,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const
*/
static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
{
LONG FileSizeHi = (LONG)(NewFileSize >> 32);
LONG FileSizeLo;
@@ -361,7 +361,7 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize)
}
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
{
if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1)
{
@@ -396,7 +396,7 @@ static bool BaseFile_GetPos(TFileStream * pStream, ULONGLONG * pByteOffset)
// Renames the file pointed by pStream so that it contains data from pNewStream
static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
// Delete the original stream file. Don't check the result value,
// because if the file doesn't exist, it would fail
DeleteFile(pStream->szFileName);
@@ -405,7 +405,7 @@ static bool BaseFile_Replace(TFileStream * pStream, TFileStream * pNewStream)
return (bool)MoveFile(pNewStream->szFileName, pStream->szFileName);
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
// "rename" on Linux also works if the target file exists
if(rename(pNewStream->szFileName, pStream->szFileName) == -1)
{
@@ -421,11 +421,11 @@ static void BaseFile_Close(TFileStream * pStream)
{
if(pStream->Base.File.hFile != INVALID_HANDLE_VALUE)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
CloseHandle(pStream->Base.File.hFile);
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
close((intptr_t)pStream->Base.File.hFile);
#endif
}
@@ -450,7 +450,7 @@ static void BaseFile_Init(TFileStream * pStream)
//-----------------------------------------------------------------------------
// Local functions - base memory-mapped file support
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
typedef struct _SECTION_BASIC_INFORMATION
{
@@ -493,7 +493,7 @@ static bool RetrieveFileMappingSize(HANDLE hSection, ULARGE_INTEGER & RefFileSiz
static bool BaseMap_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStreamFlags)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
ULARGE_INTEGER FileSize = {0};
HANDLE hFile = INVALID_HANDLE_VALUE;
@@ -564,7 +564,7 @@ static bool BaseMap_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStre
return false;
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
struct stat64 fileinfo;
intptr_t handle;
bool bResult = false;
@@ -628,12 +628,12 @@ static bool BaseMap_Read(
static void BaseMap_Close(TFileStream * pStream)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
if(pStream->Base.Map.pbFile != NULL)
UnmapViewOfFile(pStream->Base.Map.pbFile);
#endif
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
if(pStream->Base.Map.pbFile != NULL)
munmap(pStream->Base.Map.pbFile, (size_t )pStream->Base.Map.FileSize);
#endif
@@ -683,7 +683,7 @@ static const TCHAR * BaseHttp_ExtractServerName(const TCHAR * szFileName, TCHAR
static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
HINTERNET hRequest;
DWORD dwTemp = 0;
@@ -795,7 +795,7 @@ static bool BaseHttp_Read(
void * pvBuffer, // Pointer to data to be read
DWORD dwBytesToRead) // Number of bytes to read from the file
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
ULONGLONG ByteOffset = (pByteOffset != NULL) ? *pByteOffset : pStream->Base.Http.FilePos;
DWORD dwTotalBytesRead = 0;
@@ -868,7 +868,7 @@ static bool BaseHttp_Read(
static void BaseHttp_Close(TFileStream * pStream)
{
-#ifdef PLATFORM_WINDOWS
+#ifdef STORMLIB_WINDOWS
if(pStream->Base.Http.hConnect != NULL)
InternetCloseHandle(pStream->Base.Http.hConnect);
pStream->Base.Http.hConnect = NULL;
diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp
index a116625..34a7a25 100644
--- a/src/SBaseCommon.cpp
+++ b/src/SBaseCommon.cpp
@@ -1738,7 +1738,7 @@ void CalculateDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE md5_ha
//-----------------------------------------------------------------------------
// Swapping functions
-#ifndef PLATFORM_LITTLE_ENDIAN
+#ifndef STORMLIB_LITTLE_ENDIAN
//
// Note that those functions are implemented for Mac operating system,
@@ -1863,4 +1863,4 @@ void ConvertTMPQHeader(void *header, uint16_t version)
}
}
-#endif // PLATFORM_LITTLE_ENDIAN
+#endif // STORMLIB_LITTLE_ENDIAN
diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp
index c93920c..4448289 100644
--- a/src/SBaseFileTable.cpp
+++ b/src/SBaseFileTable.cpp
@@ -57,19 +57,33 @@ static DWORD GetNecessaryBitCount(ULONGLONG MaxValue)
}
//-----------------------------------------------------------------------------
-// Support functions for BIT_ARRAY
+// Implementation of the TStormBits struc
-static USHORT SetBitsMask[] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
+struct TStormBits
+{
+ static TStormBits * Create(DWORD NumberOfBits, BYTE FillValue);
+
+ void GetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize);
+ void SetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize);
+
+ static const USHORT SetBitsMask[];
+
+ DWORD NumberOfBytes; // Total number of bytes in "Elements"
+ DWORD NumberOfBits; // Total number of bits that are available
+ BYTE Elements[1]; // Array of elements (variable length)
+};
+
+const USHORT TStormBits::SetBitsMask[] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
-static TBitArray * CreateBitArray(
+TStormBits * TStormBits::Create(
DWORD NumberOfBits,
BYTE FillValue)
{
- TBitArray * pBitArray;
- size_t nSize = sizeof(TBitArray) + (NumberOfBits + 7) / 8;
+ TStormBits * pBitArray;
+ size_t nSize = sizeof(TStormBits) + (NumberOfBits + 7) / 8;
// Allocate the bit array
- pBitArray = (TBitArray *)STORM_ALLOC(BYTE, nSize);
+ pBitArray = (TStormBits *)STORM_ALLOC(BYTE, nSize);
if(pBitArray != NULL)
{
memset(pBitArray, FillValue, nSize);
@@ -80,8 +94,7 @@ static TBitArray * CreateBitArray(
return pBitArray;
}
-void GetBits(
- TBitArray * pArray,
+void TStormBits::GetBits(
unsigned int nBitPosition,
unsigned int nBitLength,
void * pvBuffer,
@@ -103,7 +116,7 @@ void GetBits(
assert(pbBuffer[i] == 0);
#endif
-#ifndef PLATFORM_LITTLE_ENDIAN
+#ifndef STORMLIB_LITTLE_ENDIAN
// Adjust the buffer pointer for big endian platforms
pbBuffer += (nResultByteSize - 1);
#endif
@@ -114,14 +127,14 @@ void GetBits(
// Is the current position in the Elements byte-aligned?
if(nBitOffset != 0)
{
- BitBuffer = (unsigned char)((pArray->Elements[nBytePosition0] >> nBitOffset) | (pArray->Elements[nBytePosition1] << (0x08 - nBitOffset)));
+ BitBuffer = (unsigned char)((Elements[nBytePosition0] >> nBitOffset) | (Elements[nBytePosition1] << (0x08 - nBitOffset)));
}
else
{
- BitBuffer = pArray->Elements[nBytePosition0];
+ BitBuffer = Elements[nBytePosition0];
}
-#ifdef PLATFORM_LITTLE_ENDIAN
+#ifdef STORMLIB_LITTLE_ENDIAN
*pbBuffer++ = BitBuffer;
#else
*pbBuffer-- = BitBuffer;
@@ -137,17 +150,16 @@ void GetBits(
nBitLength = (nBitLength & 0x07);
if(nBitLength != 0)
{
- *pbBuffer = (unsigned char)(pArray->Elements[nBytePosition0] >> nBitOffset);
+ *pbBuffer = (unsigned char)(Elements[nBytePosition0] >> nBitOffset);
if(nBitLength > (8 - nBitOffset))
- *pbBuffer = (unsigned char)((pArray->Elements[nBytePosition1] << (8 - nBitOffset)) | (pArray->Elements[nBytePosition0] >> nBitOffset));
+ *pbBuffer = (unsigned char)((Elements[nBytePosition1] << (8 - nBitOffset)) | (Elements[nBytePosition0] >> nBitOffset));
*pbBuffer &= (0x01 << nBitLength) - 1;
}
}
-void SetBits(
- TBitArray * pArray,
+void TStormBits::SetBits(
unsigned int nBitPosition,
unsigned int nBitLength,
void * pvBuffer,
@@ -163,7 +175,7 @@ void SetBits(
// Keep compiler happy for platforms where nResultByteSize is not used
nResultByteSize = nResultByteSize;
-#ifndef PLATFORM_LITTLE_ENDIAN
+#ifndef STORMLIB_LITTLE_ENDIAN
// Adjust the buffer pointer for big endian platforms
pbBuffer += (nResultByteSize - 1);
#endif
@@ -172,7 +184,7 @@ void SetBits(
while(nBitLength > 8)
{
// Reload the bit buffer
-#ifdef PLATFORM_LITTLE_ENDIAN
+#ifdef STORMLIB_LITTLE_ENDIAN
OneByte = *pbBuffer++;
#else
OneByte = *pbBuffer--;
@@ -182,7 +194,7 @@ void SetBits(
AndMask = (AndMask >> 0x08) | (0x00FF << nBitOffset);
// Update the byte in the array
- pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer);
+ Elements[nBytePosition] = (BYTE)((Elements[nBytePosition] & ~AndMask) | BitBuffer);
// Move byte positions and lengths
nBytePosition++;
@@ -199,7 +211,7 @@ void SetBits(
AndMask = (AndMask >> 0x08) | (SetBitsMask[nBitLength] << nBitOffset);
// Update the byte in the array
- pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer);
+ Elements[nBytePosition] = (BYTE)((Elements[nBytePosition] & ~AndMask) | BitBuffer);
// Update the next byte, if needed
if(AndMask & 0xFF00)
@@ -208,7 +220,7 @@ void SetBits(
BitBuffer >>= 0x08;
AndMask >>= 0x08;
- pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer);
+ Elements[nBytePosition] = (BYTE)((Elements[nBytePosition] & ~AndMask) | BitBuffer);
}
}
}
@@ -1320,7 +1332,7 @@ TMPQHetTable * CreateHetTable(DWORD dwEntryCount, DWORD dwTotalCount, DWORD dwNa
memset(pHetTable->pNameHashes, 0, dwTotalCount);
// Allocate the bit array for file indexes
- pHetTable->pBetIndexes = CreateBitArray(dwTotalCount * pHetTable->dwIndexSizeTotal, 0xFF);
+ pHetTable->pBetIndexes = TStormBits::Create(dwTotalCount * pHetTable->dwIndexSizeTotal, 0xFF);
if(pHetTable->pBetIndexes != NULL)
{
// Initialize the HET table from the source data (if given)
@@ -1368,7 +1380,7 @@ static int InsertHetEntry(TMPQHetTable * pHetTable, ULONGLONG FileNameHash, DWOR
pHetTable->pNameHashes[Index] = NameHash1;
// Set the entry in the file index table
- SetBits(pHetTable->pBetIndexes, pHetTable->dwIndexSizeTotal * Index,
+ pHetTable->pBetIndexes->SetBits(pHetTable->dwIndexSizeTotal * Index,
pHetTable->dwIndexSize,
&dwFileIndex,
4);
@@ -1510,7 +1522,7 @@ static DWORD GetFileIndex_Het(TMPQArchive * ha, const char * szFileName)
DWORD dwFileIndex = 0;
// Get the file index
- GetBits(pHetTable->pBetIndexes, pHetTable->dwIndexSizeTotal * Index,
+ pHetTable->pBetIndexes->GetBits(pHetTable->dwIndexSizeTotal * Index,
pHetTable->dwIndexSize,
&dwFileIndex,
sizeof(DWORD));
@@ -1720,7 +1732,7 @@ static TMPQBetTable * TranslateBetTable(
}
// Load the bit-based file table
- pBetTable->pFileTable = CreateBitArray(pBetTable->dwTableEntrySize * pBetHeader->dwEntryCount, 0);
+ pBetTable->pFileTable = TStormBits::Create(pBetTable->dwTableEntrySize * pBetHeader->dwEntryCount, 0);
if(pBetTable->pFileTable != NULL)
{
LengthInBytes = (pBetTable->pFileTable->NumberOfBits + 7) / 8;
@@ -1734,7 +1746,7 @@ static TMPQBetTable * TranslateBetTable(
pBetTable->dwBitCount_NameHash2 = pBetHeader->dwBitCount_NameHash2;
// Create and load the array of BET hashes
- pBetTable->pNameHashes = CreateBitArray(pBetTable->dwBitTotal_NameHash2 * pBetHeader->dwEntryCount, 0);
+ pBetTable->pNameHashes = TStormBits::Create(pBetTable->dwBitTotal_NameHash2 * pBetHeader->dwEntryCount, 0);
if(pBetTable->pNameHashes != NULL)
{
LengthInBytes = (pBetTable->pNameHashes->NumberOfBits + 7) / 8;
@@ -1759,7 +1771,7 @@ TMPQExtHeader * TranslateBetTable(
TMPQBetHeader BetHeader;
TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize;
TFileEntry * pFileEntry;
- TBitArray * pBitArray = NULL;
+ TStormBits * pBitArray = NULL;
LPBYTE pbLinearTable = NULL;
LPBYTE pbTrgData;
DWORD LengthInBytes;
@@ -1779,7 +1791,7 @@ TMPQExtHeader * TranslateBetTable(
pbTrgData = (LPBYTE)(pBetHeader + 1);
// Save the bit-based block table
- pBitArray = CreateBitArray(BetHeader.dwEntryCount * BetHeader.dwTableEntrySize, 0);
+ pBitArray = TStormBits::Create(BetHeader.dwEntryCount * BetHeader.dwTableEntrySize, 0);
if(pBitArray != NULL)
{
DWORD dwFlagIndex = 0;
@@ -1794,22 +1806,22 @@ TMPQExtHeader * TranslateBetTable(
//
// Save the byte offset
- SetBits(pBitArray, nBitOffset + BetHeader.dwBitIndex_FilePos,
+ pBitArray->SetBits(nBitOffset + BetHeader.dwBitIndex_FilePos,
BetHeader.dwBitCount_FilePos,
&pFileEntry->ByteOffset,
8);
- SetBits(pBitArray, nBitOffset + BetHeader.dwBitIndex_FileSize,
+ pBitArray->SetBits(nBitOffset + BetHeader.dwBitIndex_FileSize,
BetHeader.dwBitCount_FileSize,
&pFileEntry->dwFileSize,
4);
- SetBits(pBitArray, nBitOffset + BetHeader.dwBitIndex_CmpSize,
+ pBitArray->SetBits(nBitOffset + BetHeader.dwBitIndex_CmpSize,
BetHeader.dwBitCount_CmpSize,
&pFileEntry->dwCmpSize,
4);
// Save the flag index
dwFlagIndex = GetFileFlagIndex(FlagArray, pFileEntry->dwFlags);
- SetBits(pBitArray, nBitOffset + BetHeader.dwBitIndex_FlagIndex,
+ pBitArray->SetBits(nBitOffset + BetHeader.dwBitIndex_FlagIndex,
BetHeader.dwBitCount_FlagIndex,
&dwFlagIndex,
4);
@@ -1834,7 +1846,7 @@ TMPQExtHeader * TranslateBetTable(
}
// Create bit array for name hashes
- pBitArray = CreateBitArray(BetHeader.dwBitTotal_NameHash2 * BetHeader.dwEntryCount, 0);
+ pBitArray = TStormBits::Create(BetHeader.dwBitTotal_NameHash2 * BetHeader.dwEntryCount, 0);
if(pBitArray != NULL)
{
DWORD dwFileIndex = 0;
@@ -1842,7 +1854,7 @@ TMPQExtHeader * TranslateBetTable(
for(pFileEntry = ha->pFileTable; pFileEntry < pFileTableEnd; pFileEntry++)
{
// Insert the name hash to the bit array
- SetBits(pBitArray, BetHeader.dwBitTotal_NameHash2 * dwFileIndex,
+ pBitArray->SetBits(BetHeader.dwBitTotal_NameHash2 * dwFileIndex,
BetHeader.dwBitCount_NameHash2,
&pFileEntry->FileNameHash,
8);
@@ -2506,7 +2518,7 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
TMPQHetTable * pHetTable = ha->pHetTable;
TMPQBetTable * pBetTable;
TFileEntry * pFileEntry = ha->pFileTable;
- TBitArray * pBitArray;
+ TStormBits * pBitArray;
DWORD dwBitPosition = 0;
DWORD i;
int nError = ERROR_FILE_CORRUPT;
@@ -2532,7 +2544,7 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
if(pHetTable->pNameHashes[i] != HET_ENTRY_FREE)
{
// Load the index to the BET table
- GetBits(pHetTable->pBetIndexes, pHetTable->dwIndexSizeTotal * i,
+ pHetTable->pBetIndexes->GetBits(pHetTable->dwIndexSizeTotal * i,
pHetTable->dwIndexSize,
&dwFileIndex,
4);
@@ -2543,7 +2555,7 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
ULONGLONG NameHash2 = 0;
// Load the BET hash
- GetBits(pBetTable->pNameHashes, pBetTable->dwBitTotal_NameHash2 * dwFileIndex,
+ pBetTable->pNameHashes->GetBits(pBetTable->dwBitTotal_NameHash2 * dwFileIndex,
pBetTable->dwBitCount_NameHash2,
&NameHash2,
8);
@@ -2563,19 +2575,19 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
DWORD dwFlagIndex = 0;
// Read the file position
- GetBits(pBitArray, dwBitPosition + pBetTable->dwBitIndex_FilePos,
+ pBitArray->GetBits(dwBitPosition + pBetTable->dwBitIndex_FilePos,
pBetTable->dwBitCount_FilePos,
&pFileEntry->ByteOffset,
8);
// Read the file size
- GetBits(pBitArray, dwBitPosition + pBetTable->dwBitIndex_FileSize,
+ pBitArray->GetBits(dwBitPosition + pBetTable->dwBitIndex_FileSize,
pBetTable->dwBitCount_FileSize,
&pFileEntry->dwFileSize,
4);
// Read the compressed size
- GetBits(pBitArray, dwBitPosition + pBetTable->dwBitIndex_CmpSize,
+ pBitArray->GetBits(dwBitPosition + pBetTable->dwBitIndex_CmpSize,
pBetTable->dwBitCount_CmpSize,
&pFileEntry->dwCmpSize,
4);
@@ -2584,7 +2596,7 @@ static int BuildFileTable_HetBet(TMPQArchive * ha)
// Read the flag index
if(pBetTable->dwFlagCount != 0)
{
- GetBits(pBitArray, dwBitPosition + pBetTable->dwBitIndex_FlagIndex,
+ pBitArray->GetBits(dwBitPosition + pBetTable->dwBitIndex_FlagIndex,
pBetTable->dwBitCount_FlagIndex,
&dwFlagIndex,
4);
diff --git a/src/StormLib.h b/src/StormLib.h
index 81f8c59..4f19772 100644
--- a/src/StormLib.h
+++ b/src/StormLib.h
@@ -479,20 +479,8 @@ typedef void (WINAPI * SFILE_DOWNLOAD_CALLBACK)(void * pvUserData, ULONGLONG Byt
typedef void (WINAPI * SFILE_ADDFILE_CALLBACK)(void * pvUserData, DWORD dwBytesWritten, DWORD dwTotalBytes, bool bFinalCall);
typedef void (WINAPI * SFILE_COMPACT_CALLBACK)(void * pvUserData, DWORD dwWorkType, ULONGLONG BytesProcessed, ULONGLONG TotalBytes);
-typedef struct TFileStream TFileStream;
-
-//-----------------------------------------------------------------------------
-// Structure for bit arrays used for HET and BET tables
-
-typedef struct _TBitArray
-{
- DWORD NumberOfBytes; // Total number of bytes in "Elements"
- DWORD NumberOfBits; // Total number of bits that are available
- BYTE Elements[1]; // Array of elements (variable length)
-} TBitArray;
-
-void GetBits(TBitArray * array, unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize);
-void SetBits(TBitArray * array, unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize);
+struct TFileStream;
+struct TStormBits;
//-----------------------------------------------------------------------------
// Structures related to MPQ format
@@ -630,7 +618,7 @@ typedef struct _TMPQHash
// The hash of the file path, using method B.
DWORD dwName2;
-#ifdef PLATFORM_LITTLE_ENDIAN
+#ifdef STORMLIB_LITTLE_ENDIAN
// The language of the file. This is a Windows LANGID data type, and uses the same values.
// 0 indicates the default language (American English), or that the file is language-neutral.
@@ -719,14 +707,14 @@ typedef struct _TMPQHetHeader
{
TMPQExtHeader ExtHdr;
- DWORD dwTableSize; // Size of the entire HET table, including HET_TABLE_HEADER (in bytes)
- DWORD dwEntryCount; // Number of occupied entries in the HET table
- DWORD dwTotalCount; // Total number of entries in the HET table
- DWORD dwNameHashBitSize; // Size of the name hash entry (in bits)
- DWORD dwIndexSizeTotal; // Total size of file index (in bits)
- DWORD dwIndexSizeExtra; // Extra bits in the file index
- DWORD dwIndexSize; // Effective size of the file index (in bits)
- DWORD dwIndexTableSize; // Size of the block index subtable (in bytes)
+ DWORD dwTableSize; // Size of the entire HET table, including HET_TABLE_HEADER (in bytes)
+ DWORD dwEntryCount; // Number of occupied entries in the HET table
+ DWORD dwTotalCount; // Total number of entries in the HET table
+ DWORD dwNameHashBitSize; // Size of the name hash entry (in bits)
+ DWORD dwIndexSizeTotal; // Total size of file index (in bits)
+ DWORD dwIndexSizeExtra; // Extra bits in the file index
+ DWORD dwIndexSize; // Effective size of the file index (in bits)
+ DWORD dwIndexTableSize; // Size of the block index subtable (in bytes)
} TMPQHetHeader;
@@ -735,32 +723,32 @@ typedef struct _TMPQBetHeader
{
TMPQExtHeader ExtHdr;
- DWORD dwTableSize; // Size of the entire BET table, including the header (in bytes)
- DWORD dwEntryCount; // Number of entries in the BET table. Must match HET_TABLE_HEADER::dwEntryCount
+ DWORD dwTableSize; // Size of the entire BET table, including the header (in bytes)
+ DWORD dwEntryCount; // Number of entries in the BET table. Must match HET_TABLE_HEADER::dwEntryCount
DWORD dwUnknown08;
- DWORD dwTableEntrySize; // Size of one table entry (in bits)
- DWORD dwBitIndex_FilePos; // Bit index of the file position (within the entry record)
- DWORD dwBitIndex_FileSize; // Bit index of the file size (within the entry record)
- DWORD dwBitIndex_CmpSize; // Bit index of the compressed size (within the entry record)
- DWORD dwBitIndex_FlagIndex; // Bit index of the flag index (within the entry record)
- DWORD dwBitIndex_Unknown; // Bit index of the ??? (within the entry record)
- DWORD dwBitCount_FilePos; // Bit size of file position (in the entry record)
- DWORD dwBitCount_FileSize; // Bit size of file size (in the entry record)
- DWORD dwBitCount_CmpSize; // Bit size of compressed file size (in the entry record)
- DWORD dwBitCount_FlagIndex; // Bit size of flags index (in the entry record)
- DWORD dwBitCount_Unknown; // Bit size of ??? (in the entry record)
- DWORD dwBitTotal_NameHash2; // Total bit size of the NameHash2
- DWORD dwBitExtra_NameHash2; // Extra bits in the NameHash2
- DWORD dwBitCount_NameHash2; // Effective size of NameHash2 (in bits)
- DWORD dwNameHashArraySize; // Size of NameHash2 table, in bytes
- DWORD dwFlagCount; // Number of flags in the following array
+ DWORD dwTableEntrySize; // Size of one table entry (in bits)
+ DWORD dwBitIndex_FilePos; // Bit index of the file position (within the entry record)
+ DWORD dwBitIndex_FileSize; // Bit index of the file size (within the entry record)
+ DWORD dwBitIndex_CmpSize; // Bit index of the compressed size (within the entry record)
+ DWORD dwBitIndex_FlagIndex; // Bit index of the flag index (within the entry record)
+ DWORD dwBitIndex_Unknown; // Bit index of the ??? (within the entry record)
+ DWORD dwBitCount_FilePos; // Bit size of file position (in the entry record)
+ DWORD dwBitCount_FileSize; // Bit size of file size (in the entry record)
+ DWORD dwBitCount_CmpSize; // Bit size of compressed file size (in the entry record)
+ DWORD dwBitCount_FlagIndex; // Bit size of flags index (in the entry record)
+ DWORD dwBitCount_Unknown; // Bit size of ??? (in the entry record)
+ DWORD dwBitTotal_NameHash2; // Total bit size of the NameHash2
+ DWORD dwBitExtra_NameHash2; // Extra bits in the NameHash2
+ DWORD dwBitCount_NameHash2; // Effective size of NameHash2 (in bits)
+ DWORD dwNameHashArraySize; // Size of NameHash2 table, in bytes
+ DWORD dwFlagCount; // Number of flags in the following array
} TMPQBetHeader;
// Structure for parsed HET table
typedef struct _TMPQHetTable
{
- TBitArray * pBetIndexes; // Bit array of FileIndex values
+ TStormBits * pBetIndexes; // Bit array of FileIndex values
LPBYTE pNameHashes; // Array of NameHash1 values (NameHash1 = upper 8 bits of FileName hashe)
ULONGLONG AndMask64; // AND mask used for calculating file name hash
ULONGLONG OrMask64; // OR mask used for setting the highest bit of the file name hash
@@ -776,8 +764,8 @@ typedef struct _TMPQHetTable
// Structure for parsed BET table
typedef struct _TMPQBetTable
{
- TBitArray * pNameHashes; // Array of NameHash2 entries (lower 24 bits of FileName hash)
- TBitArray * pFileTable; // Bit-based file table
+ TStormBits * pNameHashes; // Array of NameHash2 entries (lower 24 bits of FileName hash)
+ TStormBits * pFileTable; // Bit-based file table
LPDWORD pFileFlags; // Array of file flags
DWORD dwTableEntrySize; // Size of one table entry, in bits
@@ -1104,7 +1092,7 @@ int WINAPI SCompDecompress2(void * pvOutBuffer, int * pcbOutBuffer, void * pv
//-----------------------------------------------------------------------------
// Non-Windows support for SetLastError/GetLastError
-#ifndef PLATFORM_WINDOWS
+#ifndef STORMLIB_WINDOWS
void SetLastError(DWORD dwErrCode);
DWORD GetLastError();
diff --git a/src/StormPort.h b/src/StormPort.h
index 7a1bdb2..6773975 100644
--- a/src/StormPort.h
+++ b/src/StormPort.h
@@ -36,7 +36,7 @@
//-----------------------------------------------------------------------------
// Defines for Windows
-#if !defined(PLATFORM_DEFINED) && defined(_WIN32)
+#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(_WIN32)
// In MSVC 8.0, there are some functions declared as deprecated.
#if _MSC_VER >= 1400
@@ -54,25 +54,25 @@
#include <windows.h>
#include <wininet.h>
- #define PLATFORM_LITTLE_ENDIAN
+ #define STORMLIB_LITTLE_ENDIAN
#ifdef _WIN64
- #define PLATFORM_64BIT
+ #define STORMLIB_64BIT
#else
- #define PLATFORM_32BIT
+ #define STORMLIB_32BIT
#endif
#define STORMLIB_CDECL __cdecl
- #define PLATFORM_WINDOWS
- #define PLATFORM_DEFINED // The platform is known now
+ #define STORMLIB_WINDOWS
+ #define STORMLIB_PLATFORM_DEFINED // The platform is known now
#endif
//-----------------------------------------------------------------------------
// Defines for Mac
-#if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
+#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
// Macintosh
#include <sys/types.h>
@@ -94,15 +94,15 @@
#define __SYS_BZLIB
#ifndef __BIG_ENDIAN__
- #define PLATFORM_LITTLE_ENDIAN
+ #define STORMLIB_LITTLE_ENDIAN
#endif
- #define PLATFORM_MAC
- #define PLATFORM_DEFINED // The platform is known now
+ #define STORMLIB_MAC
+ #define STORMLIB_PLATFORM_DEFINED // The platform is known now
#endif
-#if !defined(PLATFORM_DEFINED) && defined(__HAIKU__)
+#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(__HAIKU__)
#include <sys/types.h>
#include <sys/stat.h>
@@ -119,18 +119,18 @@
#include <errno.h>
#ifndef __BIG_ENDIAN__
- #define PLATFORM_LITTLE_ENDIAN
+ #define STORMLIB_LITTLE_ENDIAN
#endif
- #define PLATFORM_HAIKU
- #define PLATFORM_DEFINED // The platform is known now
+ #define STORMLIB_HAIKU
+ #define STORMLIB_PLATFORM_DEFINED // The platform is known now
#endif
//-----------------------------------------------------------------------------
// Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
-#if !defined(PLATFORM_DEFINED)
+#if !defined(STORMLIB_PLATFORM_DEFINED)
#include <sys/types.h>
#include <sys/stat.h>
@@ -147,20 +147,20 @@
#include <assert.h>
#include <errno.h>
- #define PLATFORM_LITTLE_ENDIAN
- #define PLATFORM_LINUX
- #define PLATFORM_DEFINED
+ #define STORMLIB_LITTLE_ENDIAN
+ #define STORMLIB_LINUX
+ #define STORMLIB_PLATFORM_DEFINED
#endif
//-----------------------------------------------------------------------------
// Definition of Windows-specific types for non-Windows platforms
-#ifndef PLATFORM_WINDOWS
+#ifndef STORMLIB_WINDOWS
#if __LP64__
- #define PLATFORM_64BIT
+ #define STORMLIB_64BIT
#else
- #define PLATFORM_32BIT
+ #define STORMLIB_32BIT
#endif
// __cdecl meand nothing on non-Windows
@@ -188,7 +188,7 @@
typedef char * LPTSTR;
typedef char * LPSTR;
- #ifdef PLATFORM_32BIT
+ #ifdef STORMLIB_32BIT
#define _LZMA_UINT32_IS_ULONG
#endif
@@ -225,10 +225,10 @@
#define _tcsicmp strcasecmp
#define _tcsnicmp strncasecmp
-#endif // !PLATFORM_WINDOWS
+#endif // !STORMLIB_WINDOWS
// 64-bit calls are supplied by "normal" calls on Mac
-#if defined(PLATFORM_MAC) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_HAIKU)
#define stat64 stat
#define fstat64 fstat
#define lseek64 lseek
@@ -238,7 +238,7 @@
#endif
// Platform-specific error codes for UNIX-based platforms
-#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU)
+#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(STORMLIB_HAIKU)
#define ERROR_SUCCESS 0
#define ERROR_FILE_NOT_FOUND ENOENT
#define ERROR_ACCESS_DENIED EPERM
@@ -260,7 +260,7 @@
//-----------------------------------------------------------------------------
// Swapping functions
-#ifdef PLATFORM_LITTLE_ENDIAN
+#ifdef STORMLIB_LITTLE_ENDIAN
#define BSWAP_INT16_UNSIGNED(a) (a)
#define BSWAP_INT16_SIGNED(a) (a)
#define BSWAP_INT32_UNSIGNED(a) (a)