diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/FileStream.cpp | 10 | ||||
-rw-r--r-- | src/SBaseCommon.cpp | 5 | ||||
-rw-r--r-- | src/SBaseFileTable.cpp | 9 | ||||
-rw-r--r-- | src/SFileAddFile.cpp | 2 | ||||
-rw-r--r-- | src/SFileCompactArchive.cpp | 5 | ||||
-rw-r--r-- | src/SFileGetFileInfo.cpp | 9 | ||||
-rw-r--r-- | src/SFileListFile.cpp | 20 | ||||
-rw-r--r-- | src/SFilePatchArchives.cpp | 1 | ||||
-rw-r--r-- | src/SFileReadFile.cpp | 2 | ||||
-rw-r--r-- | src/StormPort.h | 1 |
10 files changed, 33 insertions, 31 deletions
diff --git a/src/FileStream.cpp b/src/FileStream.cpp index a081bd7..eaf85de 100644 --- a/src/FileStream.cpp +++ b/src/FileStream.cpp @@ -182,7 +182,7 @@ static bool BaseFile_Read( // we have to update the file position if(ByteOffset != pStream->Base.File.FilePos) { - lseek64((intptr_t)pStream->Base.File.hFile, (__off64_t)(ByteOffset), SEEK_SET); + lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET); pStream->Base.File.FilePos = ByteOffset; } @@ -271,7 +271,7 @@ static bool BaseFile_Write(TFileStream * pStream, ULONGLONG * pByteOffset, const // we have to update the file position if(ByteOffset != pStream->Base.File.FilePos) { - lseek64((intptr_t)pStream->Base.File.hFile, (__off64_t)(ByteOffset), SEEK_SET); + lseek64((intptr_t)pStream->Base.File.hFile, (off64_t)(ByteOffset), SEEK_SET); pStream->Base.File.FilePos = ByteOffset; } @@ -346,7 +346,7 @@ static bool BaseFile_SetSize(TFileStream * pStream, ULONGLONG NewFileSize) #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) { - if(ftruncate64((intptr_t)pStream->Base.File.hFile, (__off64_t)NewFileSize) == -1) + if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1) { nLastError = errno; return false; @@ -1134,7 +1134,6 @@ static bool PartialStream_Read( DWORD dwPartIndex; DWORD dwBytesRead = 0; DWORD dwBlockSize = pStream->BlockSize; - bool bResult = false; int nFailReason = ERROR_HANDLE_EOF; // Why it failed if not enough bytes was read // If the byte offset is not entered, use the current position @@ -1172,7 +1171,6 @@ static bool PartialStream_Read( if((PartMap->Flags & 3) == 0) { nFailReason = ERROR_FILE_CORRUPT; - bResult = false; break; } @@ -1188,7 +1186,6 @@ static bool PartialStream_Read( if(RawByteOffset == 0) { nFailReason = ERROR_FILE_CORRUPT; - bResult = false; break; } @@ -1201,7 +1198,6 @@ static bool PartialStream_Read( if(!pStream->BaseRead(pStream, &RawByteOffset, pbBuffer, dwBytesInPart)) { nFailReason = ERROR_FILE_CORRUPT; - bResult = false; break; } diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index a0e789b..bb580b5 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -371,6 +371,7 @@ DWORD DetectFileKeyByKnownContent(void * pvFileContent, DWORD nDwords, ...) // We need at least two DWORDS to detect the file key if(nDwords < 0x02 || nDwords > 0x10) return 0; + memset(dwDecrypted, 0, sizeof(dwDecrypted)); va_start(argList, nDwords); for(i = 0; i < nDwords; i++) @@ -639,7 +640,7 @@ ULONGLONG FindFreeMpqSpace(TMPQArchive * ha) { TMPQHeader * pHeader = ha->pHeader; TFileEntry * pFileTableEnd = ha->pFileTable + ha->dwFileTableSize; - TFileEntry * pFileEntry = ha->pFileTable; + TFileEntry * pFileEntry; ULONGLONG FreeSpacePos = ha->pHeader->dwHeaderSize; DWORD dwChunkCount; @@ -952,7 +953,7 @@ int AllocateSectorOffsets(TMPQFile * hf, bool bLoadFromFile) __LoadSectorOffsets: // Allocate the sector offset table - hf->SectorOffsets = (DWORD *)STORM_ALLOC(BYTE, dwSectorOffsLen); + hf->SectorOffsets = STORM_ALLOC(DWORD, (dwSectorOffsLen / sizeof(DWORD))); if(hf->SectorOffsets == NULL) return ERROR_NOT_ENOUGH_MEMORY; diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index d4155bd..d88c5f9 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -499,7 +499,7 @@ int ConvertMpqHeaderToFormat4( if(pHeader->HetTablePos64) { pHeader->HetTableSize64 = ByteOffset - pHeader->HetTablePos64; - ByteOffset = pHeader->HetTablePos64; +// ByteOffset = pHeader->HetTablePos64; } break; @@ -1479,7 +1479,7 @@ static TMPQBetTable * TranslateBetTable( LengthInBytes = (pBetTable->pNameHashes->NumberOfBits + 7) / 8; if(pBetTable->pNameHashes != NULL) memcpy(pBetTable->pNameHashes->Elements, pbSrcData, LengthInBytes); - pbSrcData += pBetHeader->dwNameHashArraySize; +// pbSrcData += pBetHeader->dwNameHashArraySize; // Dump both tables // DumpHetAndBetTable(ha->pHetTable, pBetTable); @@ -1592,7 +1592,7 @@ TMPQExtHeader * TranslateBetTable( // Write the array of BET hashes LengthInBytes = (pBitArray->NumberOfBits + 7) / 8; memcpy(pbTrgData, pBitArray->Elements, LengthInBytes); - pbTrgData += LengthInBytes; +// pbTrgData += LengthInBytes; // Free the bit array STORM_FREE(pBitArray); @@ -2726,6 +2726,7 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize, DWORD dwNewMaxF // Set the new tables to the MPQ archive ha->pFileTable = pFileTable; ha->pHashTable = pHashTable; + pFileTable = NULL; // Set the new limits to the MPQ archive ha->pHeader->dwHashTableSize = dwNewHashTableSize; @@ -2763,6 +2764,8 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize, DWORD dwNewMaxF STORM_FREE(pOldFileTable); if(pOldHashTable != NULL) STORM_FREE(pOldHashTable); + if(pFileTable != NULL) + STORM_FREE(pFileTable); return nError; } diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index bb8f4f1..5246f89 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -276,7 +276,7 @@ static int RecryptFileData( if(hf->SectorOffsets != NULL) { // Allocate secondary buffer for sectors copy - DWORD * SectorOffsetsCopy = (DWORD *)STORM_ALLOC(BYTE, hf->SectorOffsets[0]); + DWORD * SectorOffsetsCopy = STORM_ALLOC(DWORD, hf->SectorOffsets[0] / sizeof(DWORD)); DWORD dwSectorOffsLen = hf->SectorOffsets[0]; if(SectorOffsetsCopy == NULL) diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp index ad9801b..5ca4065 100644 --- a/src/SFileCompactArchive.cpp +++ b/src/SFileCompactArchive.cpp @@ -118,7 +118,7 @@ static int CopyNonMpqData( DataSize -= dwToRead; } - return ERROR_SUCCESS; + return nError; } // Copies all file sectors into another archive. @@ -167,7 +167,7 @@ static int CopyMpqFileSectors( // If we have to save sector offset table, do it. if(nError == ERROR_SUCCESS && hf->SectorOffsets != NULL) { - DWORD * SectorOffsetsCopy = (DWORD *)STORM_ALLOC(BYTE, hf->SectorOffsets[0]); + DWORD * SectorOffsetsCopy = STORM_ALLOC(DWORD, hf->SectorOffsets[0] / sizeof(DWORD)); DWORD dwSectorOffsLen = hf->SectorOffsets[0]; assert((pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT) == 0); @@ -311,7 +311,6 @@ static int CopyMpqFileSectors( // Include these extra data in the compressed size dwCmpSize += dwBytesToCopy; - dwBytesToCopy = 0; STORM_FREE(pbExtraData); } else diff --git a/src/SFileGetFileInfo.cpp b/src/SFileGetFileInfo.cpp index 07b7722..da47fc9 100644 --- a/src/SFileGetFileInfo.cpp +++ b/src/SFileGetFileInfo.cpp @@ -143,6 +143,7 @@ bool WINAPI SFileGetFileInfo( TFileEntry * pFileEntry = NULL; ULONGLONG Int64Value = 0; ULONGLONG ByteOffset = 0; + TMPQHash * pHash; TMPQFile * hf = NULL; void * pvSrcFileInfo = NULL; DWORD cbSrcFileInfo = 0; @@ -691,7 +692,8 @@ bool WINAPI SFileGetFileInfo( hf = IsValidFileHandle(hMpqOrFile); if(hf != NULL && hf->ha != NULL && hf->ha->pHashTable != NULL) { - pvSrcFileInfo = &ha->pHashTable[hf->pFileEntry->dwHashIndex].dwName1; + pHash = hf->ha->pHashTable + hf->pFileEntry->dwHashIndex; + pvSrcFileInfo = &pHash->dwName1; cbSrcFileInfo = sizeof(DWORD); nInfoType = SFILE_INFO_TYPE_DIRECT_POINTER; } @@ -701,7 +703,8 @@ bool WINAPI SFileGetFileInfo( hf = IsValidFileHandle(hMpqOrFile); if(hf != NULL && hf->ha != NULL && hf->ha->pHashTable != NULL) { - pvSrcFileInfo = &ha->pHashTable[hf->pFileEntry->dwHashIndex].dwName2; + pHash = hf->ha->pHashTable + hf->pFileEntry->dwHashIndex; + pvSrcFileInfo = &pHash->dwName2; cbSrcFileInfo = sizeof(DWORD); nInfoType = SFILE_INFO_TYPE_DIRECT_POINTER; } @@ -825,7 +828,7 @@ bool WINAPI SFileGetFileInfo( pcbLengthNeeded[0] = cbSrcFileInfo; // If the caller entered an output buffer, the output size must also be entered - if(pvFileInfo != NULL && cbFileInfo != 0) + if(pvSrcFileInfo != NULL && pvFileInfo != NULL && cbFileInfo != 0) { // Check if there is enough space in the output buffer if(cbSrcFileInfo <= cbFileInfo) diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp index 896b341..c1197c9 100644 --- a/src/SFileListFile.cpp +++ b/src/SFileListFile.cpp @@ -138,7 +138,7 @@ static DWORD ReloadListFileCache(TListFileCache * pCache) // Load the next data chunk to the cache SFileSetFilePointer(pCache->hFile, pCache->dwFilePos, NULL, FILE_BEGIN); - SFileReadFile(pCache->hFile, pCache->Buffer, CACHE_BUFFER_SIZE, &dwBytesRead, NULL); + SFileReadFile(pCache->hFile, pCache->Buffer, dwBytesToRead, &dwBytesRead, NULL); // If we didn't read anything, it might mean that the block // of the file is not available (in case of partial MPQs). @@ -327,7 +327,6 @@ static int SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFil TFileEntry * pFileEntry; TMPQHash * pFirstHash; TMPQHash * pHash; - bool bNameEntryCreated = false; // If we have HET table, use that one if(ha->pHetTable != NULL) @@ -337,14 +336,13 @@ static int SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFil { // Allocate file name for the file entry AllocateFileName(ha, pFileEntry, szFileName); - bNameEntryCreated = true; } return ERROR_SUCCESS; } // If we have hash table, we use it - if(bNameEntryCreated == false && ha->pHashTable != NULL) + if(ha->pHashTable != NULL) { // Look for the first hash table entry for the file pFirstHash = pHash = GetFirstHashEntry(ha, szFileName); @@ -357,7 +355,6 @@ static int SListFileCreateNodeForAllLocales(TMPQArchive * ha, const char * szFil { // Allocate file name for the file entry AllocateFileName(ha, ha->pFileTable + pHash->dwBlockIndex, szFileName); - bNameEntryCreated = true; } // Now find the next language version of the file @@ -599,17 +596,20 @@ HANDLE WINAPI SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const } } + // Close the listfile + if(hListFile != NULL) + SFileCloseFile(hListFile); + // Cleanup & exit if(nError != ERROR_SUCCESS) { + if(pCache != NULL) + FreeListFileCache(pCache); + pCache = NULL; + memset(lpFindFileData, 0, sizeof(SFILE_FIND_DATA)); SetLastError(nError); } - - if(pCache != NULL) - FreeListFileCache(pCache); - if(hListFile != NULL) - SFileCloseFile(hListFile); return (HANDLE)pCache; } diff --git a/src/SFilePatchArchives.cpp b/src/SFilePatchArchives.cpp index 7f67749..cc10726 100644 --- a/src/SFilePatchArchives.cpp +++ b/src/SFilePatchArchives.cpp @@ -65,7 +65,6 @@ static void Decompress_RLE(LPBYTE pbDecompressed, DWORD cbDecompressed, LPBYTE p // Cut the initial DWORD from the compressed chunk pbCompressed += sizeof(DWORD); - cbCompressed -= sizeof(DWORD); // Pre-fill decompressed buffer with zeros memset(pbDecompressed, 0, cbDecompressed); diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp index ff4783c..1e1ae56 100644 --- a/src/SFileReadFile.cpp +++ b/src/SFileReadFile.cpp @@ -301,7 +301,7 @@ static int ReadMpqFileSingleUnit(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos } else { - if(pbRawData != hf->pbFileSector) + if(hf->pbFileSector != NULL && pbRawData != hf->pbFileSector) memcpy(hf->pbFileSector, pbRawData, hf->dwDataSize); } diff --git a/src/StormPort.h b/src/StormPort.h index 83d8624..38726ab 100644 --- a/src/StormPort.h +++ b/src/StormPort.h @@ -186,6 +186,7 @@ #define stat64 stat #define fstat64 fstat #define lseek64 lseek + #define ftruncate64 ftruncate #define off64_t off_t #define O_LARGEFILE 0 #endif |