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

Function LoadSqpBlockTable

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

Loads the SQP Block table and converts it to a MPQ block table

Source from the content-addressed store, hash-verified

235
236// Loads the SQP Block table and converts it to a MPQ block table
237TMPQBlock * LoadSqpBlockTable(TMPQArchive * ha)
238{
239 TMPQHeader * pHeader = ha->pHeader;
240 TSQPBlock * pSqpBlockTable;
241 TSQPBlock * pSqpBlockEnd;
242 TSQPBlock * pSqpBlock;
243 TMPQBlock * pMpqBlock;
244 DWORD dwFlags;
245 int nError = ERROR_SUCCESS;
246
247 // Load the hash table
248 pSqpBlockTable = (TSQPBlock *)LoadSqpTable(ha, pHeader->dwBlockTablePos, pHeader->dwBlockTableSize * sizeof(TSQPBlock), MPQ_KEY_BLOCK_TABLE);
249 if(pSqpBlockTable != NULL)
250 {
251 // Parse the entire hash table and convert it to MPQ hash table
252 pSqpBlockEnd = pSqpBlockTable + pHeader->dwBlockTableSize;
253 pMpqBlock = (TMPQBlock *)pSqpBlockTable;
254 for(pSqpBlock = pSqpBlockTable; pSqpBlock < pSqpBlockEnd; pSqpBlock++, pMpqBlock++)
255 {
256 // Check for valid flags
257 if(pSqpBlock->dwFlags & ~MPQ_FILE_VALID_FLAGS)
258 nError = ERROR_FILE_CORRUPT;
259
260 // Convert SQP block table entry to MPQ block table entry
261 dwFlags = pSqpBlock->dwFlags;
262 pMpqBlock->dwCSize = pSqpBlock->dwCSize;
263 pMpqBlock->dwFSize = pSqpBlock->dwFSize;
264 pMpqBlock->dwFlags = dwFlags;
265 }
266
267 // If an error occured, we need to free the hash table
268 if(nError != ERROR_SUCCESS)
269 {
270 STORM_FREE(pSqpBlockTable);
271 pSqpBlockTable = NULL;
272 }
273 }
274
275 // Return the converted hash table (or NULL on failure)
276 return (TMPQBlock *)pSqpBlockTable;
277}
278
279/*****************************************************************************/
280/* */

Callers 1

LoadBlockTableFunction · 0.85

Calls 1

LoadSqpTableFunction · 0.85

Tested by

no test coverage detected