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

Function LoadSqpHashTable

3rdParty/StormLib/src/SBaseSubTypes.cpp:183–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183TMPQHash * LoadSqpHashTable(TMPQArchive * ha)
184{
185 TMPQHeader * pHeader = ha->pHeader;
186 TSQPHash * pSqpHashTable;
187 TSQPHash * pSqpHashEnd;
188 TSQPHash * pSqpHash;
189 TMPQHash * pMpqHash;
190 int nError = ERROR_SUCCESS;
191
192 // Load the hash table
193 pSqpHashTable = (TSQPHash *)LoadSqpTable(ha, pHeader->dwHashTablePos, pHeader->dwHashTableSize * sizeof(TSQPHash), MPQ_KEY_HASH_TABLE);
194 if(pSqpHashTable != NULL)
195 {
196 // Parse the entire hash table and convert it to MPQ hash table
197 pSqpHashEnd = pSqpHashTable + pHeader->dwHashTableSize;
198 pMpqHash = (TMPQHash *)pSqpHashTable;
199 for(pSqpHash = pSqpHashTable; pSqpHash < pSqpHashEnd; pSqpHash++, pMpqHash++)
200 {
201 // Ignore free entries
202 if(pSqpHash->dwBlockIndex != HASH_ENTRY_FREE)
203 {
204 // Check block index against the size of the block table
205 if(pHeader->dwBlockTableSize <= MPQ_BLOCK_INDEX(pSqpHash) && pSqpHash->dwBlockIndex < HASH_ENTRY_DELETED)
206 nError = ERROR_FILE_CORRUPT;
207
208 // We do not support nonzero locale and platform ID
209 if(pSqpHash->dwAlwaysZero != 0 && pSqpHash->dwAlwaysZero != HASH_ENTRY_FREE)
210 nError = ERROR_FILE_CORRUPT;
211
212 // Store the file name hash
213 pMpqHash->dwName1 = pSqpHash->dwName1;
214 pMpqHash->dwName2 = pSqpHash->dwName2;
215
216 // Store the rest. Note that this must be done last,
217 // because block index corresponds to pMpqHash->dwName2
218 pMpqHash->dwBlockIndex = MPQ_BLOCK_INDEX(pSqpHash);
219 pMpqHash->Platform = 0;
220 pMpqHash->lcLocale = 0;
221 }
222 }
223
224 // If an error occured, we need to free the hash table
225 if(nError != ERROR_SUCCESS)
226 {
227 STORM_FREE(pSqpHashTable);
228 pSqpHashTable = NULL;
229 }
230 }
231
232 // Return the converted hash table (or NULL on failure)
233 return (TMPQHash *)pSqpHashTable;
234}
235
236// Loads the SQP Block table and converts it to a MPQ block table
237TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha)

Callers 1

LoadHashTableFunction · 0.85

Calls 1

LoadSqpTableFunction · 0.85

Tested by

no test coverage detected