| 1571 | } |
| 1572 | |
| 1573 | static TMPQBetTable * TranslateBetTable( |
| 1574 | TMPQArchive * ha, |
| 1575 | TMPQBetHeader * pBetHeader) |
| 1576 | { |
| 1577 | TMPQBetTable * pBetTable = NULL; |
| 1578 | LPBYTE pbSrcData = (LPBYTE)(pBetHeader + 1); |
| 1579 | DWORD LengthInBytes = 0; |
| 1580 | |
| 1581 | // Sanity check |
| 1582 | assert(pBetHeader->ExtHdr.dwSignature == BET_TABLE_SIGNATURE); |
| 1583 | assert(pBetHeader->ExtHdr.dwVersion == 1); |
| 1584 | assert(ha->pHetTable != NULL); |
| 1585 | ha = ha; |
| 1586 | |
| 1587 | // Verify size of the HET table |
| 1588 | if(pBetHeader->ExtHdr.dwDataSize >= (sizeof(TMPQBetHeader) - sizeof(TMPQExtHeader))) |
| 1589 | { |
| 1590 | // Verify the size of the table in the header |
| 1591 | if(pBetHeader->dwTableSize == pBetHeader->ExtHdr.dwDataSize) |
| 1592 | { |
| 1593 | // The number of entries in the BET table must be the same like number of entries in the block table |
| 1594 | assert(pBetHeader->dwEntryCount == ha->pHeader->dwBlockTableSize); |
| 1595 | assert(pBetHeader->dwEntryCount <= ha->dwMaxFileCount); |
| 1596 | |
| 1597 | // The number of entries in the BET table must be the same like number of entries in the HET table |
| 1598 | // Note that if it's not, it is not a problem |
| 1599 | //assert(pBetHeader->dwEntryCount == ha->pHetTable->dwEntryCount); |
| 1600 | |
| 1601 | // Create translated table |
| 1602 | pBetTable = CreateBetTable(pBetHeader->dwEntryCount); |
| 1603 | if(pBetTable != NULL) |
| 1604 | { |
| 1605 | // Copy the variables from the header to the BetTable |
| 1606 | pBetTable->dwTableEntrySize = pBetHeader->dwTableEntrySize; |
| 1607 | pBetTable->dwBitIndex_FilePos = pBetHeader->dwBitIndex_FilePos; |
| 1608 | pBetTable->dwBitIndex_FileSize = pBetHeader->dwBitIndex_FileSize; |
| 1609 | pBetTable->dwBitIndex_CmpSize = pBetHeader->dwBitIndex_CmpSize; |
| 1610 | pBetTable->dwBitIndex_FlagIndex = pBetHeader->dwBitIndex_FlagIndex; |
| 1611 | pBetTable->dwBitIndex_Unknown = pBetHeader->dwBitIndex_Unknown; |
| 1612 | pBetTable->dwBitCount_FilePos = pBetHeader->dwBitCount_FilePos; |
| 1613 | pBetTable->dwBitCount_FileSize = pBetHeader->dwBitCount_FileSize; |
| 1614 | pBetTable->dwBitCount_CmpSize = pBetHeader->dwBitCount_CmpSize; |
| 1615 | pBetTable->dwBitCount_FlagIndex = pBetHeader->dwBitCount_FlagIndex; |
| 1616 | pBetTable->dwBitCount_Unknown = pBetHeader->dwBitCount_Unknown; |
| 1617 | |
| 1618 | // Since we don't know what the "unknown" is, we'll assert when it's zero |
| 1619 | assert(pBetTable->dwBitCount_Unknown == 0); |
| 1620 | |
| 1621 | // Allocate array for flags |
| 1622 | if(pBetHeader->dwFlagCount != 0) |
| 1623 | { |
| 1624 | // Allocate array for file flags and load it |
| 1625 | pBetTable->pFileFlags = STORM_ALLOC(DWORD, pBetHeader->dwFlagCount); |
| 1626 | if(pBetTable->pFileFlags != NULL) |
| 1627 | { |
| 1628 | LengthInBytes = pBetHeader->dwFlagCount * sizeof(DWORD); |
| 1629 | memcpy(pBetTable->pFileFlags, pbSrcData, LengthInBytes); |
| 1630 | BSWAP_ARRAY32_UNSIGNED(pBetTable->pFileFlags, LengthInBytes); |
no test coverage detected