| 2164 | } |
| 2165 | |
| 2166 | static TMPQHash * LoadHashTable(TMPQArchive * ha) |
| 2167 | { |
| 2168 | TMPQHeader * pHeader = ha->pHeader; |
| 2169 | ULONGLONG ByteOffset; |
| 2170 | TMPQHash * pHashTable = NULL; |
| 2171 | DWORD dwTableSize; |
| 2172 | DWORD dwCmpSize; |
| 2173 | bool bHashTableIsCut = false; |
| 2174 | |
| 2175 | // Note: It is allowed to load hash table if it is at offset 0. |
| 2176 | // Example: MPQ_2016_v1_ProtectedMap_HashOffsIsZero.w3x |
| 2177 | // if(pHeader->dwHashTablePos == 0 && pHeader->wHashTablePosHi == 0) |
| 2178 | // return NULL; |
| 2179 | |
| 2180 | // If the hash table size is zero, do nothing |
| 2181 | if(pHeader->dwHashTableSize == 0) |
| 2182 | return NULL; |
| 2183 | |
| 2184 | // Load the hash table for MPQ variations |
| 2185 | switch(ha->dwSubType) |
| 2186 | { |
| 2187 | case MPQ_SUBTYPE_MPQ: |
| 2188 | |
| 2189 | // Calculate the position and size of the hash table |
| 2190 | ByteOffset = FileOffsetFromMpqOffset(ha, MAKE_OFFSET64(pHeader->wHashTablePosHi, pHeader->dwHashTablePos)); |
| 2191 | dwTableSize = pHeader->dwHashTableSize * sizeof(TMPQHash); |
| 2192 | dwCmpSize = (DWORD)pHeader->HashTableSize64; |
| 2193 | |
| 2194 | // Read, decrypt and uncompress the hash table |
| 2195 | pHashTable = (TMPQHash *)LoadMpqTable(ha, ByteOffset, dwCmpSize, dwTableSize, MPQ_KEY_HASH_TABLE, &bHashTableIsCut); |
| 2196 | // DumpHashTable(pHashTable, pHeader->dwHashTableSize); |
| 2197 | |
| 2198 | // If the hash table was cut, we can/have to defragment it |
| 2199 | if(pHashTable != NULL && bHashTableIsCut) |
| 2200 | ha->dwFlags |= (MPQ_FLAG_MALFORMED | MPQ_FLAG_HASH_TABLE_CUT); |
| 2201 | break; |
| 2202 | |
| 2203 | case MPQ_SUBTYPE_SQP: |
| 2204 | pHashTable = LoadSqpHashTable(ha); |
| 2205 | break; |
| 2206 | |
| 2207 | case MPQ_SUBTYPE_MPK: |
| 2208 | pHashTable = LoadMpkHashTable(ha); |
| 2209 | break; |
| 2210 | } |
| 2211 | |
| 2212 | // Remember the size of the hash table |
| 2213 | return pHashTable; |
| 2214 | } |
| 2215 | |
| 2216 | int CreateFileTable(TMPQArchive * ha, DWORD dwFileTableSize) |
| 2217 | { |
no test coverage detected