| 2583 | } |
| 2584 | |
| 2585 | static DWORD BuildFileTable_HetBet(TMPQArchive * ha) |
| 2586 | { |
| 2587 | TMPQHetTable * pHetTable = ha->pHetTable; |
| 2588 | TMPQBetTable * pBetTable; |
| 2589 | TFileEntry * pFileEntry = ha->pFileTable; |
| 2590 | TMPQBits * pBitArray; |
| 2591 | DWORD dwBitPosition = 0; |
| 2592 | DWORD i; |
| 2593 | DWORD dwErrCode = ERROR_FILE_CORRUPT; |
| 2594 | |
| 2595 | // Load the BET table from the MPQ |
| 2596 | pBetTable = LoadBetTable(ha); |
| 2597 | if(pBetTable != NULL) |
| 2598 | { |
| 2599 | // Verify the size of NameHash2 in the BET table. |
| 2600 | // It has to be 8 bits less than the information in HET table |
| 2601 | if((pBetTable->dwBitCount_NameHash2 + 8) != pHetTable->dwNameHashBitSize) |
| 2602 | { |
| 2603 | FreeBetTable(pBetTable); |
| 2604 | return ERROR_FILE_CORRUPT; |
| 2605 | } |
| 2606 | |
| 2607 | // Step one: Fill the name indexes |
| 2608 | for(i = 0; i < pHetTable->dwTotalCount; i++) |
| 2609 | { |
| 2610 | DWORD dwFileIndex = 0; |
| 2611 | |
| 2612 | // Is the entry in the HET table occupied? |
| 2613 | if(pHetTable->pNameHashes[i] != HET_ENTRY_FREE) |
| 2614 | { |
| 2615 | // Load the index to the BET table |
| 2616 | pHetTable->pBetIndexes->GetBits(pHetTable->dwIndexSizeTotal * i, |
| 2617 | pHetTable->dwIndexSize, |
| 2618 | &dwFileIndex, |
| 2619 | 4); |
| 2620 | // Overflow test |
| 2621 | if(dwFileIndex < pBetTable->dwEntryCount) |
| 2622 | { |
| 2623 | ULONGLONG NameHash1 = pHetTable->pNameHashes[i]; |
| 2624 | ULONGLONG NameHash2 = 0; |
| 2625 | |
| 2626 | // Load the BET hash |
| 2627 | pBetTable->pNameHashes->GetBits(pBetTable->dwBitTotal_NameHash2 * dwFileIndex, |
| 2628 | pBetTable->dwBitCount_NameHash2, |
| 2629 | &NameHash2, |
| 2630 | 8); |
| 2631 | |
| 2632 | // Combine both part of the name hash and put it to the file table |
| 2633 | pFileEntry = ha->pFileTable + dwFileIndex; |
| 2634 | pFileEntry->FileNameHash = (NameHash1 << pBetTable->dwBitCount_NameHash2) | NameHash2; |
| 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | // Go through the entire BET table and convert it to the file table. |
| 2640 | pFileEntry = ha->pFileTable; |
| 2641 | pBitArray = pBetTable->pFileTable; |
| 2642 | for(i = 0; i < pBetTable->dwEntryCount; i++) |
no test coverage detected