static int WowHandler_Insert( TRootHandler_WoW6 * pRootHandler, const char * szFileName, LPBYTE pbEncodingKey) { PCASC_FILE_ENTRY pFileEntry; DWORD FileDataId = 0; // Don't let the number of items to overflow if(pRootHandler->FileTable.ItemCount >= pRootHandler->FileTable.ItemCountMax) return ERROR_NOT_ENOUGH_MEMORY; // Insert the item to the linear file list pFileEntry = (PCASC_FILE_ENTRY)Array_Insert(&pRootHandler->FileTable, NULL, 1); if(pFileEntry != NULL) { // Get the file data ID of the previous item (0 if this is the first one) if(pRootHandler->FileTable.ItemCount > 1) FileDataId = pFileEntry[-1].FileDataId; // Fill-in the new entry pFileEntry->EncodingKey = *(PENCODING_KEY)pbEncodingKey; pFileEntry->FileNameHash = CalcFileNameHash(szFileName); pFileEntry->FileDataId = FileDataId + 1; pFileEntry->Locales = CASC_LOCALE_ALL; // Verify collisions (debug version only) assert(Map_FindObject(pRootHandler->pRootMap, &pFileEntry->FileNameHash, NULL) == NULL); // Insert the entry to the map Map_InsertObject(pRootHandler->pRootMap, pFileEntry, &pFileEntry->FileNameHash); } return ERROR_SUCCESS; }
// Search by file name hash // Also used in CascSearchFile PCASC_FILE_ENTRY FindRootEntry(PCASC_MAP pRootMap, const char * szFileName, DWORD * PtrTableIndex) { // Calculate the HASH value of the normalized file name ULONGLONG FileNameHash = CalcFileNameHash(szFileName); // Perform the hash search return (PCASC_FILE_ENTRY)Map_FindObject(pRootMap, &FileNameHash, PtrTableIndex); }
const char * ListFile_FindName(PLISTFILE_MAP pListMap, ULONGLONG FileNameHash) { PLISTFILE_ENTRY pListEntry = NULL; if(pListMap != NULL) pListEntry = (PLISTFILE_ENTRY)Map_FindObject(pListMap->pNameMap, &FileNameHash); return (pListEntry != NULL) ? pListEntry->szFileName : ""; }
PCASC_ENCODING_ENTRY FindEncodingEntry(TCascStorage * hs, PQUERY_KEY pEncodingKey, PDWORD PtrIndex) { PCASC_ENCODING_ENTRY pEncodingEntry = NULL; if(hs->pEncodingMap != NULL) pEncodingEntry = (PCASC_ENCODING_ENTRY)Map_FindObject(hs->pEncodingMap, pEncodingKey->pbData, PtrIndex); return pEncodingEntry; }
PCASC_INDEX_ENTRY FindIndexEntry(TCascStorage * hs, PQUERY_KEY pIndexKey) { PCASC_INDEX_ENTRY pIndexEntry = NULL; if(hs->pIndexEntryMap != NULL) pIndexEntry = (PCASC_INDEX_ENTRY)Map_FindObject(hs->pIndexEntryMap, pIndexKey->pbData, NULL); return pIndexEntry; }
static LPBYTE D3Handler_GetKey(TRootHandler_Diablo3 * pRootHandler, const char * szFileName) { PCASC_FILE_ENTRY pFileEntry; ULONGLONG FileNameHash = CalcFileNameHash(szFileName); // Find the file in the name table pFileEntry = (PCASC_FILE_ENTRY)Map_FindObject(pRootHandler->pRootMap, &FileNameHash, NULL); return (pFileEntry != NULL) ? pFileEntry->EncodingKey.Value : NULL; }
// Insert an entry with file name as-is static int InsertFileEntry( TRootHandler_Diablo3 * pRootHandler, ENCODING_KEY & EncodingKey, const char * szFileName, size_t cchFileName) { PCASC_FILE_ENTRY pFileEntry; // We must not allow the file name array to be reallocated. // Reallocating the array would cause pointers in TRootHandler_Diablo3::pRootMap // become invalid if(pRootHandler->FileTable.ItemCount >= pRootHandler->FileTable.ItemCountMax) { assert(false); return ERROR_NOT_ENOUGH_MEMORY; } // Insert the plain name to the root handler's global name list szFileName = (const char *)Array_Insert(&pRootHandler->FileNames, szFileName, cchFileName); if(szFileName == NULL) return ERROR_NOT_ENOUGH_MEMORY; // Make sure that we don't exceed the file limit at this phase pFileEntry = (PCASC_FILE_ENTRY)Array_Insert(&pRootHandler->FileTable, NULL, 1); assert(pFileEntry != NULL); // Store the info into the file entry pFileEntry->EncodingKey = EncodingKey; pFileEntry->FileNameHash = CalcFileNameHash(szFileName); pFileEntry->dwFileName = (DWORD)Array_IndexOf(&pRootHandler->FileNames, szFileName); pFileEntry->dwFlags = 0; // Verify collisions (debug version only) assert(Map_FindObject(pRootHandler->pRootMap, &pFileEntry->FileNameHash, NULL) == NULL); // Calculate the file name hash Map_InsertObject(pRootHandler->pRootMap, pFileEntry, &pFileEntry->FileNameHash); // Success return ERROR_SUCCESS; }
PCASC_EKEY_ENTRY FindEKeyEntry(TCascStorage * hs, PQUERY_KEY pEKey, PDWORD PtrIndex) { return (PCASC_EKEY_ENTRY)Map_FindObject(hs->pEKeyEntryMap, pEKey->pbData, PtrIndex); }