TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CascRootFile_WoW6.cpp File Reference
#include "CascLib.h"
#include "CascCommon.h"
+ Include dependency graph for CascRootFile_WoW6.cpp:

Classes

struct  _FILE_LOCALE_BLOCK
 
struct  _FILE_ROOT_ENTRY
 
struct  _CASC_ROOT_BLOCK
 
struct  _CASC_FILE_ENTRY
 
struct  TRootHandler_WoW6
 

Macros

#define __CASCLIB_SELF__
 
#define ROOT_SEARCH_PHASE_INITIALIZING   0
 
#define ROOT_SEARCH_PHASE_LISTFILE   1
 
#define ROOT_SEARCH_PHASE_NAMELESS   2
 
#define ROOT_SEARCH_PHASE_FINISHED   2
 

Typedefs

typedef struct _FILE_LOCALE_BLOCK FILE_LOCALE_BLOCK
 
typedef struct _FILE_LOCALE_BLOCKPFILE_LOCALE_BLOCK
 
typedef struct _FILE_ROOT_ENTRY FILE_ROOT_ENTRY
 
typedef struct _FILE_ROOT_ENTRYPFILE_ROOT_ENTRY
 
typedef struct _CASC_ROOT_BLOCK CASC_ROOT_BLOCK
 
typedef struct _CASC_ROOT_BLOCKPCASC_ROOT_BLOCK
 
typedef struct _CASC_FILE_ENTRY CASC_FILE_ENTRY
 
typedef struct _CASC_FILE_ENTRYPCASC_FILE_ENTRY
 
typedef int(* PARSE_ROOT )(TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pBlockInfo)
 

Functions

static bool IsFileDataIdName (const char *szFileName)
 
PCASC_FILE_ENTRY FindRootEntry (DYNAMIC_ARRAY &FileTable, DWORD FileDataId)
 
PCASC_FILE_ENTRY FindRootEntry (PCASC_MAP pRootMap, const char *szFileName, DWORD *PtrTableIndex)
 
LPBYTE VerifyLocaleBlock (PCASC_ROOT_BLOCK pBlockInfo, LPBYTE pbFilePointer, LPBYTE pbFileEnd)
 
static int ParseRoot_CountFiles (TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pRootBlock)
 
static int ParseRoot_AddRootEntries (TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pRootBlock)
 
static int ParseWowRootFileInternal (TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask, bool bLoadBlocksWithFlags80, BYTE HighestBitValue)
 
static int ParseWowRootFile2 (TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask, BYTE HighestBitValue)
 
static int ParseWowRootFile (TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask)
 
static int WowHandler_Insert (TRootHandler_WoW6 *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
 
static LPBYTE WowHandler_Search (TRootHandler_WoW6 *pRootHandler, TCascSearch *pSearch, PDWORD, PDWORD PtrLocaleFlags)
 
static LPBYTE WowHandler_GetKey (TRootHandler_WoW6 *pRootHandler, const char *szFileName)
 
static void WowHandler_EndSearch (TRootHandler_WoW6 *, TCascSearch *pSearch)
 
static void WowHandler_Close (TRootHandler_WoW6 *pRootHandler)
 
int RootHandler_CreateWoW6 (TCascStorage *hs, LPBYTE pbRootFile, DWORD cbRootFile, DWORD dwLocaleMask)
 

Macro Definition Documentation

#define __CASCLIB_SELF__
#define ROOT_SEARCH_PHASE_FINISHED   2
#define ROOT_SEARCH_PHASE_INITIALIZING   0
#define ROOT_SEARCH_PHASE_LISTFILE   1
#define ROOT_SEARCH_PHASE_NAMELESS   2

Typedef Documentation

typedef int(* PARSE_ROOT)(TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pBlockInfo)

Function Documentation

PCASC_FILE_ENTRY FindRootEntry ( DYNAMIC_ARRAY FileTable,
DWORD  FileDataId 
)
107 {
108  PCASC_FILE_ENTRY pStartEntry = (PCASC_FILE_ENTRY)FileTable.ItemArray;
109  PCASC_FILE_ENTRY pMidlEntry;
110  PCASC_FILE_ENTRY pEndEntry = pStartEntry + FileTable.ItemCount - 1;
111  int nResult;
112 
113  // Perform binary search on the table
114  while(pStartEntry < pEndEntry)
115  {
116  // Calculate the middle of the interval
117  pMidlEntry = pStartEntry + ((pEndEntry - pStartEntry) / 2);
118 
119  // Did we find it?
120  nResult = (int)FileDataId - (int)pMidlEntry->FileDataId;
121  if(nResult == 0)
122  return pMidlEntry;
123 
124  // Move the interval to the left or right
125  (nResult < 0) ? pEndEntry = pMidlEntry : pStartEntry = pMidlEntry + 1;
126  }
127 
128  return NULL;
129 }
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
char * ItemArray
Definition: DynamicArray.h:19
struct _CASC_FILE_ENTRY * PCASC_FILE_ENTRY
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the caller graph for this function:

PCASC_FILE_ENTRY FindRootEntry ( PCASC_MAP  pRootMap,
const char *  szFileName,
DWORD PtrTableIndex 
)
134 {
135  // Calculate the HASH value of the normalized file name
136  ULONGLONG FileNameHash = CalcFileNameHash(szFileName);
137 
138  // Perform the hash search
139  return (PCASC_FILE_ENTRY)Map_FindObject(pRootMap, &FileNameHash, PtrTableIndex);
140 }
void * Map_FindObject(PCASC_MAP pMap, void *pvKey, PDWORD PtrIndex)
Definition: Map.cpp:138
ULONGLONG CalcFileNameHash(const char *szFileName)
Definition: Common.cpp:260
unsigned long long ULONGLONG
Definition: CascPort.h:144
Definition: CascRootFile_Diablo3.cpp:130

+ Here is the call graph for this function:

static bool IsFileDataIdName ( const char *  szFileName)
static
85 {
86  BYTE BinaryValue[4];
87 
88  // File name must begin with "File", case insensitive
89  if(AsciiToUpperTable_BkSlash[szFileName[0]] == 'F' &&
90  AsciiToUpperTable_BkSlash[szFileName[1]] == 'I' &&
91  AsciiToUpperTable_BkSlash[szFileName[2]] == 'L' &&
92  AsciiToUpperTable_BkSlash[szFileName[3]] == 'E')
93  {
94  // Then, 8 hexadecimal digits must follow
95  if(ConvertStringToBinary(szFileName + 4, 8, BinaryValue) == ERROR_SUCCESS)
96  {
97  // Must be followed by an extension or end-of-string
98  return (szFileName[0x0C] == 0 || szFileName[0x0C] == '.');
99  }
100  }
101 
102  return false;
103 }
int ConvertStringToBinary(const char *szString, size_t nMaxDigits, LPBYTE pbBinary)
Definition: Common.cpp:338
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
unsigned char BYTE
Definition: CascPort.h:136
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int ParseRoot_AddRootEntries ( TRootHandler_WoW6 pRootHandler,
PCASC_ROOT_BLOCK  pRootBlock 
)
static
178 {
179  PCASC_FILE_ENTRY pFileEntry;
180 
181  // Sanity checks
182  assert(pRootHandler->FileTable.ItemArray != NULL);
183  assert(pRootHandler->FileTable.ItemCountMax != 0);
184 
185  // WoW.exe (build 19116): Blocks with zero files are skipped
186  for(DWORD i = 0; i < pRootBlock->pLocaleBlockHdr->NumberOfFiles; i++)
187  {
188  // Create new entry, with overflow check
189  if(pRootHandler->FileTable.ItemCount >= pRootHandler->FileTable.ItemCountMax)
191  pFileEntry = (PCASC_FILE_ENTRY)Array_Insert(&pRootHandler->FileTable, NULL, 1);
192 
193  // (004147A3) Prepare the CASC_FILE_ENTRY structure
194  pFileEntry->FileNameHash = pRootBlock->pRootEntries[i].FileNameHash;
195  pFileEntry->FileDataId = pRootHandler->FileDataId + pRootBlock->FileDataIds[i];
196  pFileEntry->Locales = pRootBlock->pLocaleBlockHdr->Locales;
197  pFileEntry->EncodingKey = pRootBlock->pRootEntries[i].EncodingKey;
198 
199  // Also, insert the entry to the map
200  Map_InsertObject(pRootHandler->pRootMap, pFileEntry, &pFileEntry->FileNameHash);
201 
202  // Update the local File Data Id
203  assert((pFileEntry->FileDataId + 1) > pFileEntry->FileDataId);
204  pRootHandler->FileDataId = pFileEntry->FileDataId + 1;
205 
206  // Move to the next root entry
207  pFileEntry++;
208  }
209 
210  return ERROR_SUCCESS;
211 }
DWORD NumberOfFiles
Definition: CascRootFile_WoW6.cpp:28
PDWORD FileDataIds
Definition: CascRootFile_WoW6.cpp:49
#define ERROR_INSUFFICIENT_BUFFER
Definition: CascPort.h:213
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
DWORD Locales
Definition: CascRootFile_WoW6.cpp:61
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
DWORD FileDataId
Definition: CascRootFile_WoW6.cpp:60
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_WoW6.cpp:68
PFILE_LOCALE_BLOCK pLocaleBlockHdr
Definition: CascRootFile_WoW6.cpp:48
ENCODING_KEY EncodingKey
Definition: CascRootFile_WoW6.cpp:40
bool Map_InsertObject(PCASC_MAP pMap, void *pvNewObject, void *pvKey)
Definition: Map.cpp:170
DWORD FileDataId
Definition: CascRootFile_WoW6.cpp:75
void * Array_Insert(PDYNAMIC_ARRAY pArray, const void *NewItems, size_t NewItemCount)
Definition: DynamicArray.cpp:63
ULONGLONG FileNameHash
Definition: CascRootFile_WoW6.cpp:41
unsigned int DWORD
Definition: CascPort.h:139
ULONGLONG FileNameHash
Definition: CascRootFile_Diablo3.cpp:133
DWORD Locales
Definition: CascRootFile_WoW6.cpp:30
char * ItemArray
Definition: DynamicArray.h:19
PFILE_ROOT_ENTRY pRootEntries
Definition: CascRootFile_WoW6.cpp:50
size_t ItemCountMax
Definition: DynamicArray.h:20
struct _CASC_FILE_ENTRY * PCASC_FILE_ENTRY
#define ERROR_SUCCESS
Definition: CascPort.h:204
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int ParseRoot_CountFiles ( TRootHandler_WoW6 pRootHandler,
PCASC_ROOT_BLOCK  pRootBlock 
)
static
169 {
170  // Add the file count to the total file count
171  pRootHandler->dwTotalFileCount += pRootBlock->pLocaleBlockHdr->NumberOfFiles;
172  return ERROR_SUCCESS;
173 }
DWORD NumberOfFiles
Definition: CascRootFile_WoW6.cpp:28
PFILE_LOCALE_BLOCK pLocaleBlockHdr
Definition: CascRootFile_WoW6.cpp:48
DWORD dwTotalFileCount
Definition: CascRootFile_WoW6.cpp:74
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the caller graph for this function:

static int ParseWowRootFile ( TRootHandler_WoW6 pRootHandler,
PARSE_ROOT  pfnParseRoot,
LPBYTE  pbRootFile,
LPBYTE  pbRootFileEnd,
DWORD  dwLocaleMask 
)
static
306 {
307  ParseWowRootFile2(pRootHandler, pfnParseRoot, pbRootFile, pbRootFileEnd, dwLocaleMask, 0);
308  ParseWowRootFile2(pRootHandler, pfnParseRoot, pbRootFile, pbRootFileEnd, dwLocaleMask, 1);
309  return ERROR_SUCCESS;
310 }
static int ParseWowRootFile2(TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask, BYTE HighestBitValue)
Definition: CascRootFile_WoW6.cpp:278
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int ParseWowRootFile2 ( TRootHandler_WoW6 pRootHandler,
PARSE_ROOT  pfnParseRoot,
LPBYTE  pbRootFile,
LPBYTE  pbRootFileEnd,
DWORD  dwLocaleMask,
BYTE  HighestBitValue 
)
static
285 {
286  // Load the locale as-is
287  ParseWowRootFileInternal(pRootHandler, pfnParseRoot, pbRootFile, pbRootFileEnd, dwLocaleMask, false, HighestBitValue);
288 
289  // If we wanted enGB, we also load enUS for the missing files
290  if(dwLocaleMask == CASC_LOCALE_ENGB)
291  ParseWowRootFileInternal(pRootHandler, pfnParseRoot, pbRootFile, pbRootFileEnd, CASC_LOCALE_ENUS, false, HighestBitValue);
292 
293  if(dwLocaleMask == CASC_LOCALE_PTPT)
294  ParseWowRootFileInternal(pRootHandler, pfnParseRoot, pbRootFile, pbRootFileEnd, CASC_LOCALE_PTBR, false, HighestBitValue);
295 
296  return ERROR_SUCCESS;
297 }
#define CASC_LOCALE_ENUS
Definition: CascLib.h:67
static int ParseWowRootFileInternal(TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask, bool bLoadBlocksWithFlags80, BYTE HighestBitValue)
Definition: CascRootFile_WoW6.cpp:213
#define CASC_LOCALE_PTBR
Definition: CascLib.h:80
#define CASC_LOCALE_ENGB
Definition: CascLib.h:75
#define CASC_LOCALE_PTPT
Definition: CascLib.h:82
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int ParseWowRootFileInternal ( TRootHandler_WoW6 pRootHandler,
PARSE_ROOT  pfnParseRoot,
LPBYTE  pbRootFile,
LPBYTE  pbRootFileEnd,
DWORD  dwLocaleMask,
bool  bLoadBlocksWithFlags80,
BYTE  HighestBitValue 
)
static
221 {
222  CASC_ROOT_BLOCK RootBlock;
223 
224  // Now parse the root file
225  while(pbRootFile < pbRootFileEnd)
226  {
227  // Validate the file locale block
228  pbRootFile = VerifyLocaleBlock(&RootBlock, pbRootFile, pbRootFileEnd);
229  if(pbRootFile == NULL)
230  break;
231 
232  // WoW.exe (build 19116): Entries with flag 0x100 set are skipped
233  if(RootBlock.pLocaleBlockHdr->Flags & 0x100)
234  continue;
235 
236  // WoW.exe (build 19116): Entries with flag 0x80 set are skipped if arg_4 is set to FALSE (which is by default)
237  if((RootBlock.pLocaleBlockHdr->Flags & 0x80) && bLoadBlocksWithFlags80 == 0)
238  continue;
239 
240  // WoW.exe (build 19116): Entries with (flags >> 0x1F) not equal to arg_8 are skipped
241  if((RootBlock.pLocaleBlockHdr->Flags >> 0x1F) != HighestBitValue)
242  continue;
243 
244  // WoW.exe (build 19116): Locales other than defined mask are skipped too
245  if((RootBlock.pLocaleBlockHdr->Locales & dwLocaleMask) == 0)
246  continue;
247 
248  // Now call the custom function
249  pfnParseRoot(pRootHandler, &RootBlock);
250  }
251 
252  return ERROR_SUCCESS;
253 }
arena_t NULL
Definition: jemalloc_internal.h:624
PFILE_LOCALE_BLOCK pLocaleBlockHdr
Definition: CascRootFile_WoW6.cpp:48
LPBYTE VerifyLocaleBlock(PCASC_ROOT_BLOCK pBlockInfo, LPBYTE pbFilePointer, LPBYTE pbFileEnd)
Definition: CascRootFile_WoW6.cpp:142
Definition: CascRootFile_WoW6.cpp:46
DWORD Flags
Definition: CascRootFile_WoW6.cpp:29
DWORD Locales
Definition: CascRootFile_WoW6.cpp:30
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int RootHandler_CreateWoW6 ( TCascStorage hs,
LPBYTE  pbRootFile,
DWORD  cbRootFile,
DWORD  dwLocaleMask 
)
488 {
489  TRootHandler_WoW6 * pRootHandler;
490  LPBYTE pbRootFileEnd = pbRootFile + cbRootFile;
491  int nError;
492 
493  // Verify the size
494  if(pbRootFile == NULL || cbRootFile <= sizeof(PFILE_LOCALE_BLOCK))
495  nError = ERROR_FILE_CORRUPT;
496 
497  // Allocate the root handler object
498  hs->pRootHandler = pRootHandler = CASC_ALLOC(TRootHandler_WoW6, 1);
499  if(pRootHandler == NULL)
501 
502  // Fill-in the handler functions
503  memset(pRootHandler, 0, sizeof(TRootHandler_WoW6));
504  pRootHandler->Insert = (ROOT_INSERT)WowHandler_Insert;
505  pRootHandler->Search = (ROOT_SEARCH)WowHandler_Search;
507  pRootHandler->GetKey = (ROOT_GETKEY)WowHandler_GetKey;
508  pRootHandler->Close = (ROOT_CLOSE)WowHandler_Close;
509 
510 #ifdef _DEBUG
511  pRootHandler->Dump = TRootHandlerWoW6_Dump; // Support for ROOT file dump
512 #endif // _DEBUG
513 
514  // Count the files that are going to be loaded
515  ParseWowRootFile(pRootHandler, ParseRoot_CountFiles, pbRootFile, pbRootFileEnd, dwLocaleMask);
516  pRootHandler->dwTotalFileCount += CASC_EXTRA_FILES;
517 
518  // Create linear table that will contain all root items
519  nError = Array_Create(&pRootHandler->FileTable, CASC_FILE_ENTRY, pRootHandler->dwTotalFileCount);
520  if(nError != ERROR_SUCCESS)
521  return nError;
522 
523  // Create the map of FileHash ->FileEntry
524  pRootHandler->pRootMap = Map_Create(pRootHandler->dwTotalFileCount, sizeof(ULONGLONG), FIELD_OFFSET(CASC_FILE_ENTRY, FileNameHash));
525  if(pRootHandler->pRootMap == NULL)
527 
528  // Parse the root file again and insert all files to the map
529  ParseWowRootFile(pRootHandler, ParseRoot_AddRootEntries, pbRootFile, pbRootFileEnd, dwLocaleMask);
530  return ERROR_SUCCESS;
531 }
TRootHandler * pRootHandler
Definition: CascCommon.h:223
Definition: CascRootFile_WoW6.cpp:65
static void WowHandler_Close(TRootHandler_WoW6 *pRootHandler)
Definition: CascRootFile_WoW6.cpp:409
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
unsigned long long ULONGLONG
Definition: CascPort.h:144
PCASC_MAP Map_Create(DWORD dwMaxItems, DWORD dwKeyLength, DWORD dwKeyOffset)
Definition: Map.cpp:93
LPBYTE(* ROOT_SEARCH)(struct TRootHandler *pRootHandler, struct _TCascSearch *pSearch, PDWORD PtrFileSize, PDWORD PtrLocaleFlags)
Definition: RootHandler.h:36
static int WowHandler_Insert(TRootHandler_WoW6 *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: CascRootFile_WoW6.cpp:315
static LPBYTE WowHandler_Search(TRootHandler_WoW6 *pRootHandler, TCascSearch *pSearch, PDWORD, PDWORD PtrLocaleFlags)
Definition: CascRootFile_WoW6.cpp:351
#define Array_Create(pArray, type, ItemCountMax)
Definition: DynamicArray.h:35
#define CASC_EXTRA_FILES
Definition: CascCommon.h:53
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
ROOT_GETKEY GetKey
Definition: RootHandler.h:71
ROOT_DUMP Dump
Definition: RootHandler.h:72
ROOT_INSERT Insert
Definition: RootHandler.h:68
void(* ROOT_ENDSEARCH)(struct TRootHandler *pRootHandler, struct _TCascSearch *pSearch)
Definition: RootHandler.h:43
static void WowHandler_EndSearch(TRootHandler_WoW6 *, TCascSearch *pSearch)
Definition: CascRootFile_WoW6.cpp:402
#define ERROR_FILE_CORRUPT
Definition: CascPort.h:218
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
LPBYTE(* ROOT_GETKEY)(struct TRootHandler *pRootHandler, const char *szFileName)
Definition: RootHandler.h:48
static int ParseRoot_AddRootEntries(TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pRootBlock)
Definition: CascRootFile_WoW6.cpp:175
static LPBYTE WowHandler_GetKey(TRootHandler_WoW6 *pRootHandler, const char *szFileName)
Definition: CascRootFile_WoW6.cpp:377
BYTE * LPBYTE
Definition: CascPort.h:152
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_WoW6.cpp:68
static int ParseRoot_CountFiles(TRootHandler_WoW6 *pRootHandler, PCASC_ROOT_BLOCK pRootBlock)
Definition: CascRootFile_WoW6.cpp:166
ROOT_SEARCH Search
Definition: RootHandler.h:69
#define FIELD_OFFSET(t, f)
Definition: CascPort.h:122
ROOT_ENDSEARCH EndSearch
Definition: RootHandler.h:70
DWORD dwTotalFileCount
Definition: CascRootFile_WoW6.cpp:74
int(* ROOT_INSERT)(struct TRootHandler *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: RootHandler.h:30
void(* ROOT_CLOSE)(struct TRootHandler *pRootHandler)
Definition: RootHandler.h:62
static int ParseWowRootFile(TRootHandler_WoW6 *pRootHandler, PARSE_ROOT pfnParseRoot, LPBYTE pbRootFile, LPBYTE pbRootFileEnd, DWORD dwLocaleMask)
Definition: CascRootFile_WoW6.cpp:300
Definition: CascRootFile_WoW6.cpp:26
ROOT_CLOSE Close
Definition: RootHandler.h:73
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

LPBYTE VerifyLocaleBlock ( PCASC_ROOT_BLOCK  pBlockInfo,
LPBYTE  pbFilePointer,
LPBYTE  pbFileEnd 
)
143 {
144  // Validate the file locale block
145  pBlockInfo->pLocaleBlockHdr = (PFILE_LOCALE_BLOCK)pbFilePointer;
146  pbFilePointer = (LPBYTE)(pBlockInfo->pLocaleBlockHdr + 1);
147  if(pbFilePointer > pbFileEnd)
148  return NULL;
149 
150  // Validate the array of 32-bit integers
151  pBlockInfo->FileDataIds = (PDWORD)pbFilePointer;
152  pbFilePointer = (LPBYTE)(pBlockInfo->FileDataIds + pBlockInfo->pLocaleBlockHdr->NumberOfFiles);
153  if(pbFilePointer > pbFileEnd)
154  return NULL;
155 
156  // Validate the array of root entries
157  pBlockInfo->pRootEntries = (PFILE_ROOT_ENTRY)pbFilePointer;
158  pbFilePointer = (LPBYTE)(pBlockInfo->pRootEntries + pBlockInfo->pLocaleBlockHdr->NumberOfFiles);
159  if(pbFilePointer > pbFileEnd)
160  return NULL;
161 
162  // Return the position of the next block
163  return pbFilePointer;
164 }
DWORD * PDWORD
Definition: CascPort.h:151
DWORD NumberOfFiles
Definition: CascRootFile_WoW6.cpp:28
PDWORD FileDataIds
Definition: CascRootFile_WoW6.cpp:49
arena_t NULL
Definition: jemalloc_internal.h:624
struct _FILE_LOCALE_BLOCK * PFILE_LOCALE_BLOCK
BYTE * LPBYTE
Definition: CascPort.h:152
PFILE_LOCALE_BLOCK pLocaleBlockHdr
Definition: CascRootFile_WoW6.cpp:48
struct _FILE_ROOT_ENTRY * PFILE_ROOT_ENTRY
PFILE_ROOT_ENTRY pRootEntries
Definition: CascRootFile_WoW6.cpp:50

+ Here is the caller graph for this function:

static void WowHandler_Close ( TRootHandler_WoW6 pRootHandler)
static
410 {
411  if(pRootHandler != NULL)
412  {
413  Array_Free(&pRootHandler->FileTable);
414  Map_Free(pRootHandler->pRootMap);
415  CASC_FREE(pRootHandler);
416  }
417 }
void Map_Free(PCASC_MAP pMap)
Definition: Map.cpp:279
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
void Array_Free(PDYNAMIC_ARRAY pArray)
Definition: DynamicArray.cpp:95
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_WoW6.cpp:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void WowHandler_EndSearch ( TRootHandler_WoW6 ,
TCascSearch pSearch 
)
static
403 {
404  if(pSearch->pRootContext != NULL)
405  CASC_FREE(pSearch->pRootContext);
406  pSearch->pRootContext = NULL;
407 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
void * pRootContext
Definition: CascCommon.h:271

+ Here is the caller graph for this function:

static LPBYTE WowHandler_GetKey ( TRootHandler_WoW6 pRootHandler,
const char *  szFileName 
)
static
378 {
379  PCASC_FILE_ENTRY pFileEntry;
380  DWORD FileDataId;
381  BYTE FileDataIdLE[4];
382 
383  // Open by FileDataId. The file name must be as following:
384  // File########.xxx, where '#' are hexa-decimal numbers (case insensitive).
385  // Extension is ignored in that case
386  if(IsFileDataIdName(szFileName))
387  {
388  ConvertStringToBinary(szFileName + 4, 8, FileDataIdLE);
389  FileDataId = ConvertBytesToInteger_4(FileDataIdLE);
390 
391  pFileEntry = FindRootEntry(pRootHandler->FileTable, FileDataId);
392  }
393  else
394  {
395  // Find by the file name hash
396  pFileEntry = FindRootEntry(pRootHandler->pRootMap, szFileName, NULL);
397  }
398 
399  return (pFileEntry != NULL) ? pFileEntry->EncodingKey.Value : NULL;
400 }
PCASC_FILE_ENTRY FindRootEntry(DYNAMIC_ARRAY &FileTable, DWORD FileDataId)
Definition: CascRootFile_WoW6.cpp:106
int ConvertStringToBinary(const char *szString, size_t nMaxDigits, LPBYTE pbBinary)
Definition: Common.cpp:338
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_WoW6.cpp:68
unsigned int DWORD
Definition: CascPort.h:139
BYTE Value[MD5_HASH_SIZE]
Definition: CascCommon.h:98
static bool IsFileDataIdName(const char *szFileName)
Definition: CascRootFile_WoW6.cpp:84
unsigned char BYTE
Definition: CascPort.h:136
DWORD ConvertBytesToInteger_4(LPBYTE ValueAsBytes)
Definition: CascCommon.cpp:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int WowHandler_Insert ( TRootHandler_WoW6 pRootHandler,
const char *  szFileName,
LPBYTE  pbEncodingKey 
)
static
319 {
320  PCASC_FILE_ENTRY pFileEntry;
321  DWORD FileDataId = 0;
322 
323  // Don't let the number of items to overflow
324  if(pRootHandler->FileTable.ItemCount >= pRootHandler->FileTable.ItemCountMax)
326 
327  // Insert the item to the linear file list
328  pFileEntry = (PCASC_FILE_ENTRY)Array_Insert(&pRootHandler->FileTable, NULL, 1);
329  if(pFileEntry != NULL)
330  {
331  // Get the file data ID of the previous item (0 if this is the first one)
332  if(pRootHandler->FileTable.ItemCount > 1)
333  FileDataId = pFileEntry[-1].FileDataId;
334 
335  // Fill-in the new entry
336  pFileEntry->EncodingKey = *(PENCODING_KEY)pbEncodingKey;
337  pFileEntry->FileNameHash = CalcFileNameHash(szFileName);
338  pFileEntry->FileDataId = FileDataId + 1;
339  pFileEntry->Locales = CASC_LOCALE_ALL;
340 
341  // Verify collisions (debug version only)
342  assert(Map_FindObject(pRootHandler->pRootMap, &pFileEntry->FileNameHash, NULL) == NULL);
343 
344  // Insert the entry to the map
345  Map_InsertObject(pRootHandler->pRootMap, pFileEntry, &pFileEntry->FileNameHash);
346  }
347 
348  return ERROR_SUCCESS;
349 }
void * Map_FindObject(PCASC_MAP pMap, void *pvKey, PDWORD PtrIndex)
Definition: Map.cpp:138
ULONGLONG CalcFileNameHash(const char *szFileName)
Definition: Common.cpp:260
#define CASC_LOCALE_ALL
Definition: CascLib.h:64
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
DWORD Locales
Definition: CascRootFile_WoW6.cpp:61
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
DWORD FileDataId
Definition: CascRootFile_WoW6.cpp:60
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_WoW6.cpp:68
bool Map_InsertObject(PCASC_MAP pMap, void *pvNewObject, void *pvKey)
Definition: Map.cpp:170
void * Array_Insert(PDYNAMIC_ARRAY pArray, const void *NewItems, size_t NewItemCount)
Definition: DynamicArray.cpp:63
struct _ENCODING_KEY * PENCODING_KEY
unsigned int DWORD
Definition: CascPort.h:139
ULONGLONG FileNameHash
Definition: CascRootFile_Diablo3.cpp:133
size_t ItemCountMax
Definition: DynamicArray.h:20
struct _CASC_FILE_ENTRY * PCASC_FILE_ENTRY
#define ERROR_SUCCESS
Definition: CascPort.h:204
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LPBYTE WowHandler_Search ( TRootHandler_WoW6 pRootHandler,
TCascSearch pSearch,
PDWORD  ,
PDWORD  PtrLocaleFlags 
)
static
352 {
353  PCASC_FILE_ENTRY pFileEntry;
354 
355  // Only if we have a listfile
356  if(pSearch->pCache != NULL)
357  {
358  // Keep going through the listfile
359  while(ListFile_GetNext(pSearch->pCache, pSearch->szMask, pSearch->szFileName, MAX_PATH))
360  {
361  // Find the root entry
362  pFileEntry = FindRootEntry(pRootHandler->pRootMap, pSearch->szFileName, NULL);
363  if(pFileEntry != NULL)
364  {
365  // Give the caller the locale mask
366  if(PtrLocaleFlags != NULL)
367  PtrLocaleFlags[0] = pFileEntry->Locales;
368  return pFileEntry->EncodingKey.Value;
369  }
370  }
371  }
372 
373  // No more files
374  return NULL;
375 }
PCASC_FILE_ENTRY FindRootEntry(DYNAMIC_ARRAY &FileTable, DWORD FileDataId)
Definition: CascRootFile_WoW6.cpp:106
#define MAX_PATH
Definition: CascPort.h:160
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
PCASC_MAP pRootMap
Definition: CascRootFile_WoW6.cpp:71
DWORD Locales
Definition: CascRootFile_WoW6.cpp:61
void * pCache
Definition: CascCommon.h:266
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
size_t ListFile_GetNext(void *pvListFile, const char *szMask, char *szBuffer, size_t nMaxChars)
Definition: ListFile.cpp:172
char * szMask
Definition: CascCommon.h:267
char szFileName[MAX_PATH]
Definition: CascCommon.h:268
BYTE Value[MD5_HASH_SIZE]
Definition: CascCommon.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function: