| 2421 | |
| 2422 | #ifdef FULL |
| 2423 | static int BuildFileTable_HetBet(TMPQArchive * ha) |
| 2424 | { |
| 2425 | TMPQHetTable * pHetTable = ha->pHetTable; |
| 2426 | TMPQBetTable * pBetTable; |
| 2427 | TFileEntry * pFileEntry = ha->pFileTable; |
| 2428 | TBitArray * pBitArray; |
| 2429 | DWORD dwBitPosition = 0; |
| 2430 | DWORD i; |
| 2431 | int nError = ERROR_FILE_CORRUPT; |
| 2432 | |
| 2433 | // Load the BET table from the MPQ |
| 2434 | pBetTable = LoadBetTable(ha); |
| 2435 | if(pBetTable != NULL) |
| 2436 | { |
| 2437 | // Verify the size of NameHash2 in the BET table. |
| 2438 | // It has to be 8 bits less than the information in HET table |
| 2439 | if((pBetTable->dwBitCount_NameHash2 + 8) != pHetTable->dwNameHashBitSize) |
| 2440 | { |
| 2441 | FreeBetTable(pBetTable); |
| 2442 | return ERROR_FILE_CORRUPT; |
| 2443 | } |
| 2444 | |
| 2445 | // Step one: Fill the name indexes |
| 2446 | for(i = 0; i < pHetTable->dwTotalCount; i++) |
| 2447 | { |
| 2448 | DWORD dwFileIndex = 0; |
| 2449 | |
| 2450 | // Is the entry in the HET table occupied? |
| 2451 | if(pHetTable->pNameHashes[i] != HET_ENTRY_FREE) |
| 2452 | { |
| 2453 | // Load the index to the BET table |
| 2454 | GetBits(pHetTable->pBetIndexes, pHetTable->dwIndexSizeTotal * i, |
| 2455 | pHetTable->dwIndexSize, |
| 2456 | &dwFileIndex, |
| 2457 | 4); |
| 2458 | // Overflow test |
| 2459 | if(dwFileIndex < pBetTable->dwEntryCount) |
| 2460 | { |
| 2461 | ULONGLONG NameHash1 = pHetTable->pNameHashes[i]; |
| 2462 | ULONGLONG NameHash2 = 0; |
| 2463 | |
| 2464 | // Load the BET hash |
| 2465 | GetBits(pBetTable->pNameHashes, pBetTable->dwBitTotal_NameHash2 * dwFileIndex, |
| 2466 | pBetTable->dwBitCount_NameHash2, |
| 2467 | &NameHash2, |
| 2468 | 8); |
| 2469 | |
| 2470 | // Combine both part of the name hash and put it to the file table |
| 2471 | pFileEntry = ha->pFileTable + dwFileIndex; |
| 2472 | pFileEntry->FileNameHash = (NameHash1 << pBetTable->dwBitCount_NameHash2) | NameHash2; |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | // Go through the entire BET table and convert it to the file table. |
| 2478 | pFileEntry = ha->pFileTable; |
| 2479 | pBitArray = pBetTable->pFileTable; |
| 2480 | for(i = 0; i < pBetTable->dwEntryCount; i++) |
no test coverage detected