aboutsummaryrefslogtreecommitdiff
path: root/src/SBaseFileTable.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2023-12-30 08:59:09 +0100
committerLadislav Zezula <zezula@volny.cz>2023-12-30 08:59:09 +0100
commit909ff807e78b0b92afffaf0d5ed7149982d8ac33 (patch)
tree0b819048623265303dc22374831cc1f84be6f328 /src/SBaseFileTable.cpp
parent2e3882409954eb1a3a7830df7d117cd16773fda7 (diff)
Regression tests passed
Diffstat (limited to 'src/SBaseFileTable.cpp')
-rw-r--r--src/SBaseFileTable.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp
index a53d6a6..ca14693 100644
--- a/src/SBaseFileTable.cpp
+++ b/src/SBaseFileTable.cpp
@@ -385,20 +385,39 @@ static ULONGLONG DetermineArchiveSize_V4(
return ArchiveSize;
}
-ULONGLONG FileOffsetFromMpqOffset(TMPQArchive * ha, ULONGLONG MpqOffset)
+ULONGLONG GetFileOffsetMask(TMPQArchive * ha)
{
+ ULONGLONG FileOffsetMask = (ULONGLONG)(-1);
+
+ // Sanity checks
+ assert(ha != NULL);
+ assert(ha->pHeader != NULL);
+
+ // MPQs of format 1 are 32-bit only
if(ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1)
- {
- // For MPQ archive v1, any file offset is only 32-bit
- return (ULONGLONG)((DWORD)ha->MpqPos + (DWORD)MpqOffset);
- }
- else
- {
- // For MPQ archive v2+, file offsets are full 64-bit
- return ha->MpqPos + MpqOffset;
- }
+ FileOffsetMask = (ULONGLONG)(DWORD)(-1);
+ return FileOffsetMask;
}
+ULONGLONG FileOffsetFromMpqOffset(TMPQArchive * ha, ULONGLONG MpqOffset)
+{
+ return (ha->MpqPos + MpqOffset) & ha->FileOffsetMask;
+}
+
+//ULONGLONG FileOffsetFromMpqOffset(TMPQArchive * ha, ULONGLONG MpqOffset)
+//{
+// if(ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1)
+// {
+// // For MPQ archive v1, any file offset is only 32-bit
+// return (ULONGLONG)((DWORD)ha->MpqPos + (DWORD)MpqOffset);
+// }
+// else
+// {
+// // For MPQ archive v2+, file offsets are full 64-bit
+// return ha->MpqPos + MpqOffset;
+// }
+//}
+
ULONGLONG CalculateRawSectorOffset(
TMPQFile * hf,
DWORD dwSectorOffset)
@@ -418,9 +437,7 @@ ULONGLONG CalculateRawSectorOffset(
// For MPQs version 1.0, the offset is purely 32-bit
//
- RawFilePos = hf->RawFilePos + dwSectorOffset;
- if(hf->ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1)
- RawFilePos = (DWORD)hf->ha->MpqPos + (DWORD)hf->pFileEntry->ByteOffset + dwSectorOffset;
+ RawFilePos = (hf->RawFilePos + dwSectorOffset) & hf->ha->FileOffsetMask;
// We also have to add patch header size, if patch header is present
if(hf->pPatchInfo != NULL)