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

Function GetFirstHashEntry

3rdParty/StormLib/src/SBaseCommon.cpp:686–716  ·  view source on GitHub ↗

Retrieves the first hash entry for the given file. Every locale version of a file has its own hash entry

Source from the content-addressed store, hash-verified

684// Retrieves the first hash entry for the given file.
685// Every locale version of a file has its own hash entry
686TMPQHash * GetFirstHashEntry(TMPQArchive * ha, const char * szFileName)
687{
688 DWORD dwHashIndexMask = HASH_INDEX_MASK(ha);
689 DWORD dwStartIndex = ha->pfnHashString(szFileName, MPQ_HASH_TABLE_INDEX);
690 DWORD dwName1 = ha->pfnHashString(szFileName, MPQ_HASH_NAME_A);
691 DWORD dwName2 = ha->pfnHashString(szFileName, MPQ_HASH_NAME_B);
692 DWORD dwIndex;
693
694 // Set the initial index
695 dwStartIndex = dwIndex = (dwStartIndex & dwHashIndexMask);
696
697 // Search the hash table
698 for(;;)
699 {
700 TMPQHash * pHash = ha->pHashTable + dwIndex;
701
702 // If the entry matches, we found it.
703 if(pHash->dwName1 == dwName1 && pHash->dwName2 == dwName2 && MPQ_BLOCK_INDEX(pHash) < ha->dwFileTableSize)
704 return pHash;
705
706 // If that hash entry is a free entry, it means we haven't found the file
707 if(pHash->dwBlockIndex == HASH_ENTRY_FREE)
708 return NULL;
709
710 // Move to the next hash entry. Stop searching
711 // if we got reached the original hash entry
712 dwIndex = (dwIndex + 1) & dwHashIndexMask;
713 if(dwIndex == dwStartIndex)
714 return NULL;
715 }
716}
717
718TMPQHash * GetNextHashEntry(TMPQArchive * ha, TMPQHash * pFirstHash, TMPQHash * pHash)
719{

Callers 3

GetHashEntryLocaleFunction · 0.85
GetHashEntryExactFunction · 0.85
SFileEnumLocalesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected