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

Function IsValidHashEntry1

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

Hash entry verification when the file table does not exist yet

Source from the content-addressed store, hash-verified

589
590// Hash entry verification when the file table does not exist yet
591static bool IsValidHashEntry1(TMPQArchive * ha, TMPQHash * pHash, TMPQBlock * pBlockTable)
592{
593 ULONGLONG ByteOffset;
594 TMPQBlock * pBlock;
595
596 // The block index is considered valid if it's less than block table size
597 if(MPQ_BLOCK_INDEX(pHash) < ha->pHeader->dwBlockTableSize)
598 {
599 // Calculate the block table position
600 pBlock = pBlockTable + MPQ_BLOCK_INDEX(pHash);
601
602 // Check whether this is an existing file
603 // Also we do not allow to be file size greater than 2GB
604 if((pBlock->dwFlags & MPQ_FILE_EXISTS) && (pBlock->dwFSize & 0x80000000) == 0)
605 {
606 // The begin of the file must be within the archive
607 ByteOffset = FileOffsetFromMpqOffset(ha, pBlock->dwFilePos);
608 return (ByteOffset < ha->FileSize);
609 }
610 }
611
612 return false;
613}
614
615// Returns a hash table entry in the following order:
616// 1) A hash table entry with the preferred locale and platform

Callers 2

DefragmentHashTableFunction · 0.85

Calls 1

FileOffsetFromMpqOffsetFunction · 0.85

Tested by

no test coverage detected