MCPcopy Create free account
hub / github.com/diasurgical/devilution / CalculateRawSectorOffset

Function CalculateRawSectorOffset

3rdParty/StormLib/src/SBaseFileTable.cpp:305–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305ULONGLONG CalculateRawSectorOffset(
306 TMPQFile * hf,
307 DWORD dwSectorOffset)
308{
309 ULONGLONG RawFilePos;
310
311 // Must be used for files within a MPQ
312 assert(hf->ha != NULL);
313 assert(hf->ha->pHeader != NULL);
314
315 //
316 // Some MPQ protectors place the sector offset table after the actual file data.
317 // Sector offsets in the sector offset table are negative. When added
318 // to MPQ file offset from the block table entry, the result is a correct
319 // position of the file data in the MPQ.
320 //
321 // For MPQs version 1.0, the offset is purely 32-bit
322 //
323
324 RawFilePos = hf->RawFilePos + dwSectorOffset;
325 if(hf->ha->pHeader->wFormatVersion == MPQ_FORMAT_VERSION_1)
326 RawFilePos = (DWORD)hf->ha->MpqPos + (DWORD)hf->pFileEntry->ByteOffset + dwSectorOffset;
327
328 // We also have to add patch header size, if patch header is present
329 if(hf->pPatchInfo != NULL)
330 RawFilePos += hf->pPatchInfo->dwLength;
331
332 // Return the result offset
333 return RawFilePos;
334}
335
336// This function converts the MPQ header so it always looks like version 4
337int ConvertMpqHeaderToFormat4(

Callers 2

AllocateSectorChecksumsFunction · 0.85
ReadMpqSectorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected