From 51d49e2e167ecf835040f6bbda41579685d89e94 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Sat, 24 Oct 2020 08:19:07 +0200 Subject: TBitArray made private --- src/SBaseFileTable.cpp | 58 ++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'src/SBaseFileTable.cpp') diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index c93920c..6bcf782 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -57,7 +57,17 @@ static DWORD GetNecessaryBitCount(ULONGLONG MaxValue) } //----------------------------------------------------------------------------- -// Support functions for BIT_ARRAY +// Support functions for TBitArray + +struct TBitArray +{ + void GetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize); + void SetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize); + + 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) +}; static USHORT SetBitsMask[] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}; @@ -80,8 +90,7 @@ static TBitArray * CreateBitArray( return pBitArray; } -void GetBits( - TBitArray * pArray, +void TBitArray::GetBits( unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, @@ -114,11 +123,11 @@ 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 @@ -137,17 +146,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 TBitArray::SetBits( unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, @@ -182,7 +190,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 +207,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 +216,7 @@ void SetBits( BitBuffer >>= 0x08; AndMask >>= 0x08; - pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer); + Elements[nBytePosition] = (BYTE)((Elements[nBytePosition] & ~AndMask) | BitBuffer); } } } @@ -1368,7 +1376,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 +1518,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)); @@ -1794,22 +1802,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); @@ -1842,7 +1850,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); @@ -2532,7 +2540,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 +2551,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 +2571,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 +2592,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); -- cgit v1.2.3 From 738444bddcf49c09744519a44920dde9d1f29359 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Sat, 24 Oct 2020 09:21:20 +0200 Subject: Changed PLATFORM_* to STORMLIB_* --- src/FileStream.cpp | 46 ++++++++++++++++++++++---------------------- src/SBaseCommon.cpp | 4 ++-- src/SBaseFileTable.cpp | 10 +++++----- src/StormLib.h | 4 ++-- src/StormPort.h | 52 +++++++++++++++++++++++++------------------------- 5 files changed, 58 insertions(+), 58 deletions(-) (limited to 'src/SBaseFileTable.cpp') 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 6bcf782..e94e61f 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -57,7 +57,7 @@ static DWORD GetNecessaryBitCount(ULONGLONG MaxValue) } //----------------------------------------------------------------------------- -// Support functions for TBitArray +// Implementation of the TBitArray struc struct TBitArray { @@ -112,7 +112,7 @@ void TBitArray::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 @@ -130,7 +130,7 @@ void TBitArray::GetBits( BitBuffer = Elements[nBytePosition0]; } -#ifdef PLATFORM_LITTLE_ENDIAN +#ifdef STORMLIB_LITTLE_ENDIAN *pbBuffer++ = BitBuffer; #else *pbBuffer-- = BitBuffer; @@ -171,7 +171,7 @@ void TBitArray::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 @@ -180,7 +180,7 @@ void TBitArray::SetBits( while(nBitLength > 8) { // Reload the bit buffer -#ifdef PLATFORM_LITTLE_ENDIAN +#ifdef STORMLIB_LITTLE_ENDIAN OneByte = *pbBuffer++; #else OneByte = *pbBuffer--; diff --git a/src/StormLib.h b/src/StormLib.h index 62a8f37..4ddfee3 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -618,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. @@ -1092,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 #include - #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 @@ -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 #include @@ -119,18 +119,18 @@ #include #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 #include @@ -147,20 +147,20 @@ #include #include - #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) -- cgit v1.2.3 From ece4f1ad6630f339ed02caa859851e66a96b5f33 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Sun, 25 Oct 2020 16:26:18 +0100 Subject: TBitArray: Changed struct to class --- src/SBaseFileTable.cpp | 4 +++- src/StormLib.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/SBaseFileTable.cpp') diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index e94e61f..d78c3a8 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -59,8 +59,10 @@ static DWORD GetNecessaryBitCount(ULONGLONG MaxValue) //----------------------------------------------------------------------------- // Implementation of the TBitArray struc -struct TBitArray +class TBitArray { + public: + void GetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize); void SetBits(unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, int nResultSize); diff --git a/src/StormLib.h b/src/StormLib.h index 4ddfee3..3a52a65 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -480,7 +480,7 @@ typedef void (WINAPI * SFILE_ADDFILE_CALLBACK)(void * pvUserData, DWORD dwBytesW typedef void (WINAPI * SFILE_COMPACT_CALLBACK)(void * pvUserData, DWORD dwWorkType, ULONGLONG BytesProcessed, ULONGLONG TotalBytes); struct TFileStream; -struct TBitArray; +class TBitArray; //----------------------------------------------------------------------------- // Structures related to MPQ format -- cgit v1.2.3 From f3560fa9af389d9b8be09b4e90f668fc22ed531f Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 26 Oct 2020 08:11:00 +0100 Subject: Name conflict with Unreal Engine 4: TBitArray --- src/SBaseFileTable.cpp | 36 +++++++++++++++++++----------------- src/StormLib.h | 8 ++++---- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'src/SBaseFileTable.cpp') diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index d78c3a8..4448289 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -57,31 +57,33 @@ static DWORD GetNecessaryBitCount(ULONGLONG MaxValue) } //----------------------------------------------------------------------------- -// Implementation of the TBitArray struc +// Implementation of the TStormBits struc -class TBitArray +struct TStormBits { - public: + 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) }; -static USHORT SetBitsMask[] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}; +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); @@ -92,7 +94,7 @@ static TBitArray * CreateBitArray( return pBitArray; } -void TBitArray::GetBits( +void TStormBits::GetBits( unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, @@ -157,7 +159,7 @@ void TBitArray::GetBits( } } -void TBitArray::SetBits( +void TStormBits::SetBits( unsigned int nBitPosition, unsigned int nBitLength, void * pvBuffer, @@ -1330,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) @@ -1730,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; @@ -1744,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; @@ -1769,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; @@ -1789,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; @@ -1844,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; @@ -2516,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; diff --git a/src/StormLib.h b/src/StormLib.h index 3a52a65..4f19772 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -480,7 +480,7 @@ typedef void (WINAPI * SFILE_ADDFILE_CALLBACK)(void * pvUserData, DWORD dwBytesW typedef void (WINAPI * SFILE_COMPACT_CALLBACK)(void * pvUserData, DWORD dwWorkType, ULONGLONG BytesProcessed, ULONGLONG TotalBytes); struct TFileStream; -class TBitArray; +struct TStormBits; //----------------------------------------------------------------------------- // Structures related to MPQ format @@ -748,7 +748,7 @@ typedef struct _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 @@ -764,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 -- cgit v1.2.3