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

Classes

struct  _CASC_FILE_ENTRY
 
struct  TRootHandler_Ovr
 

Macros

#define __CASCLIB_SELF__
 

Typedefs

typedef struct _CASC_FILE_ENTRY CASC_FILE_ENTRY
 
typedef struct _CASC_FILE_ENTRYPCASC_FILE_ENTRY
 

Functions

static int InsertFileEntry (TRootHandler_Ovr *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
 
static int OvrHandler_Insert (TRootHandler_Ovr *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
 
static LPBYTE OvrHandler_Search (TRootHandler_Ovr *pRootHandler, TCascSearch *pSearch, PDWORD, PDWORD)
 
static void OvrHandler_EndSearch (TRootHandler_Ovr *, TCascSearch *)
 
static LPBYTE OvrHandler_GetKey (TRootHandler_Ovr *pRootHandler, const char *szFileName)
 
static void OvrHandler_Close (TRootHandler_Ovr *pRootHandler)
 
int RootHandler_CreateOverwatch (TCascStorage *hs, LPBYTE pbRootFile, DWORD cbRootFile)
 

Macro Definition Documentation

#define __CASCLIB_SELF__

Typedef Documentation

Function Documentation

static int InsertFileEntry ( TRootHandler_Ovr pRootHandler,
const char *  szFileName,
LPBYTE  pbEncodingKey 
)
static
44 {
45  PCASC_FILE_ENTRY pFileEntry;
46  size_t nLength = strlen(szFileName);
47 
48  // Attempt to insert the file name to the global buffer
49  szFileName = (char *)Array_Insert(&pRootHandler->FileNames, szFileName, nLength + 1);
50  if(szFileName == NULL)
52 
53  // Attempt to insert the entry to the array of file entries
54  pFileEntry = (PCASC_FILE_ENTRY)Array_Insert(&pRootHandler->FileTable, NULL, 1);
55  if(pFileEntry == NULL)
57 
58  // Fill the file entry
59  pFileEntry->EncodingKey = *(PENCODING_KEY)pbEncodingKey;
60  pFileEntry->FileNameHash = CalcFileNameHash(szFileName);
61  pFileEntry->dwFileName = Array_IndexOf(&pRootHandler->FileNames, szFileName);
62 
63  // Insert the file entry to the map
64  assert(Map_FindObject(pRootHandler->pRootMap, &pFileEntry->FileNameHash, NULL) == NULL);
65  Map_InsertObject(pRootHandler->pRootMap, pFileEntry, &pFileEntry->FileNameHash);
66  return ERROR_SUCCESS;
67 }
void * Map_FindObject(PCASC_MAP pMap, void *pvKey, PDWORD PtrIndex)
Definition: Map.cpp:138
ULONGLONG CalcFileNameHash(const char *szFileName)
Definition: Common.cpp:260
struct _CASC_FILE_ENTRY * PCASC_FILE_ENTRY
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
bool Map_InsertObject(PCASC_MAP pMap, void *pvNewObject, void *pvKey)
Definition: Map.cpp:170
PCASC_MAP pRootMap
Definition: CascRootFile_Ovr.cpp:34
DYNAMIC_ARRAY FileNames
Definition: CascRootFile_Ovr.cpp:31
DWORD dwFileName
Definition: CascRootFile_Diablo3.cpp:134
void * Array_Insert(PDYNAMIC_ARRAY pArray, const void *NewItems, size_t NewItemCount)
Definition: DynamicArray.cpp:63
struct _ENCODING_KEY * PENCODING_KEY
size_t Array_IndexOf(PDYNAMIC_ARRAY pArray, const void *ArrayPtr)
Definition: DynamicArray.cpp:87
ULONGLONG FileNameHash
Definition: CascRootFile_Diablo3.cpp:133
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_Ovr.cpp:28
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void OvrHandler_Close ( TRootHandler_Ovr pRootHandler)
static
113 {
114  if(pRootHandler != NULL)
115  {
116  // Free the file map
117  if(pRootHandler->pRootMap)
118  Map_Free(pRootHandler->pRootMap);
119  pRootHandler->pRootMap = NULL;
120 
121  // Free the array of the file names and file items
122  Array_Free(&pRootHandler->FileTable);
123  Array_Free(&pRootHandler->FileNames);
124 
125  // Free the root file itself
126  CASC_FREE(pRootHandler);
127  }
128 }
void Map_Free(PCASC_MAP pMap)
Definition: Map.cpp:279
arena_t NULL
Definition: jemalloc_internal.h:624
void Array_Free(PDYNAMIC_ARRAY pArray)
Definition: DynamicArray.cpp:95
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
PCASC_MAP pRootMap
Definition: CascRootFile_Ovr.cpp:34
DYNAMIC_ARRAY FileNames
Definition: CascRootFile_Ovr.cpp:31
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_Ovr.cpp:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void OvrHandler_EndSearch ( TRootHandler_Ovr ,
TCascSearch  
)
static
101 {
102  // Do nothing
103 }

+ Here is the caller graph for this function:

static LPBYTE OvrHandler_GetKey ( TRootHandler_Ovr pRootHandler,
const char *  szFileName 
)
static
106 {
107  ULONGLONG FileNameHash = CalcFileNameHash(szFileName);
108 
109  return (LPBYTE)Map_FindObject(pRootHandler->pRootMap, &FileNameHash, NULL);
110 }
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
arena_t NULL
Definition: jemalloc_internal.h:624
BYTE * LPBYTE
Definition: CascPort.h:152
PCASC_MAP pRootMap
Definition: CascRootFile_Ovr.cpp:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int OvrHandler_Insert ( TRootHandler_Ovr pRootHandler,
const char *  szFileName,
LPBYTE  pbEncodingKey 
)
static
76 {
77  return InsertFileEntry(pRootHandler, szFileName, pbEncodingKey);
78 }
static int InsertFileEntry(TRootHandler_Ovr *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: CascRootFile_Ovr.cpp:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LPBYTE OvrHandler_Search ( TRootHandler_Ovr pRootHandler,
TCascSearch pSearch,
PDWORD  ,
PDWORD   
)
static
81 {
82  PCASC_FILE_ENTRY pFileEntry;
83 
84  // Are we still inside the root directory range?
85  while(pSearch->IndexLevel1 < pRootHandler->FileTable.ItemCount)
86  {
87  // Retrieve the file item
88  pFileEntry = (PCASC_FILE_ENTRY)Array_ItemAt(&pRootHandler->FileTable, pSearch->IndexLevel1);
89  strcpy(pSearch->szFileName, (char *)Array_ItemAt(&pRootHandler->FileNames, pFileEntry->dwFileName));
90 
91  // Prepare the pointer to the next search
92  pSearch->IndexLevel1++;
93  return pFileEntry->EncodingKey.Value;
94  }
95 
96  // No more entries
97  return NULL;
98 }
struct _CASC_FILE_ENTRY * PCASC_FILE_ENTRY
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
ENCODING_KEY EncodingKey
Definition: CascRootFile_Diablo3.cpp:132
void * Array_ItemAt(PDYNAMIC_ARRAY pArray, size_t ItemIndex)
Definition: DynamicArray.cpp:81
DYNAMIC_ARRAY FileNames
Definition: CascRootFile_Ovr.cpp:31
DWORD dwFileName
Definition: CascRootFile_Diablo3.cpp:134
char szFileName[MAX_PATH]
Definition: CascCommon.h:268
BYTE Value[MD5_HASH_SIZE]
Definition: CascCommon.h:98
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_Ovr.cpp:28
size_t IndexLevel1
Definition: CascCommon.h:272
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int RootHandler_CreateOverwatch ( TCascStorage hs,
LPBYTE  pbRootFile,
DWORD  cbRootFile 
)
134 {
135  TRootHandler_Ovr * pRootHandler;
136  ENCODING_KEY KeyBuffer;
137  QUERY_KEY EncodingKey = {KeyBuffer.Value, MD5_HASH_SIZE};
138  void * pTextFile;
139  size_t nLength;
140  char szOneLine[0x200];
141  char szFileName[MAX_PATH+1];
142  DWORD dwFileCountMax = hs->pEncodingMap->TableSize;
143  int nFileNameIndex;
144  int nError = ERROR_SUCCESS;
145 
146  // Allocate the root handler object
147  hs->pRootHandler = pRootHandler = CASC_ALLOC(TRootHandler_Ovr, 1);
148  if(pRootHandler == NULL)
150 
151  // Fill-in the handler functions
152  memset(pRootHandler, 0, sizeof(TRootHandler_Ovr));
153  pRootHandler->Insert = (ROOT_INSERT)OvrHandler_Insert;
154  pRootHandler->Search = (ROOT_SEARCH)OvrHandler_Search;
156  pRootHandler->GetKey = (ROOT_GETKEY)OvrHandler_GetKey;
157  pRootHandler->Close = (ROOT_CLOSE)OvrHandler_Close;
158 
159  // Fill-in the flags
160  pRootHandler->dwRootFlags |= ROOT_FLAG_HAS_NAMES;
161 
162  // Allocate the linear array of file entries
163  nError = Array_Create(&pRootHandler->FileTable, CASC_FILE_ENTRY, 0x10000);
164  if(nError != ERROR_SUCCESS)
165  return nError;
166 
167  // Allocate the buffer for the file names
168  nError = Array_Create(&pRootHandler->FileNames, char, 0x10000);
169  if(nError != ERROR_SUCCESS)
170  return nError;
171 
172  // Create map of ROOT_ENTRY -> FileEntry
173  pRootHandler->pRootMap = Map_Create(dwFileCountMax, sizeof(ULONGLONG), FIELD_OFFSET(CASC_FILE_ENTRY, FileNameHash));
174  if(pRootHandler->pRootMap == NULL)
176 
177  // Parse the ROOT file
178  pTextFile = ListFile_FromBuffer(pbRootFile, cbRootFile);
179  if(pTextFile != NULL)
180  {
181  // Get the initial line, containing variable names
182  nLength = ListFile_GetNextLine(pTextFile, szOneLine, _maxchars(szOneLine));
183 
184  // Determine the index of the "FILENAME" variable
185  nError = GetRootVariableIndex(szOneLine, szOneLine + nLength, "FILENAME", &nFileNameIndex);
186  if(nError == ERROR_SUCCESS)
187  {
188  // Parse the next lines
189  while((nLength = ListFile_GetNextLine(pTextFile, szOneLine, _maxchars(szOneLine))) > 0)
190  {
191  // Parse the line
192  nError = ParseRootFileLine(szOneLine, szOneLine + nLength, nFileNameIndex, &EncodingKey, szFileName, _maxchars(szFileName));
193  if(nError == ERROR_SUCCESS)
194  {
195  InsertFileEntry(pRootHandler, szFileName, KeyBuffer.Value);
196  }
197  }
198  }
199 
200  // Free the listfile
201  ListFile_Free(pTextFile);
202  }
203 
204  // Succeeded
205  return nError;
206 }
TRootHandler * pRootHandler
Definition: CascCommon.h:223
Definition: CascCommon.h:96
#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
#define Array_Create(pArray, type, ItemCountMax)
Definition: DynamicArray.h:35
DWORD dwRootFlags
Definition: RootHandler.h:75
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
ROOT_GETKEY GetKey
Definition: RootHandler.h:71
ROOT_INSERT Insert
Definition: RootHandler.h:68
void ListFile_Free(void *pvListFile)
Definition: ListFile.cpp:201
void(* ROOT_ENDSEARCH)(struct TRootHandler *pRootHandler, struct _TCascSearch *pSearch)
Definition: RootHandler.h:43
Definition: CascLib.h:138
#define MAX_PATH
Definition: CascPort.h:160
#define ROOT_FLAG_HAS_NAMES
Definition: RootHandler.h:21
Definition: CascRootFile_Diablo3.cpp:130
arena_t NULL
Definition: jemalloc_internal.h:624
static int OvrHandler_Insert(TRootHandler_Ovr *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: CascRootFile_Ovr.cpp:72
LPBYTE(* ROOT_GETKEY)(struct TRootHandler *pRootHandler, const char *szFileName)
Definition: RootHandler.h:48
int ParseRootFileLine(const char *szLinePtr, const char *szLineEnd, int nFileNameIndex, PQUERY_KEY pEncodingKey, char *szFileName, size_t nMaxChars)
Definition: CascFiles.cpp:982
static LPBYTE OvrHandler_GetKey(TRootHandler_Ovr *pRootHandler, const char *szFileName)
Definition: CascRootFile_Ovr.cpp:105
size_t TableSize
Definition: Map.h:21
#define MD5_HASH_SIZE
Definition: CascLib.h:105
#define _maxchars(buff)
Definition: CascCommon.h:80
size_t ListFile_GetNextLine(void *pvListFile, const char **pszLineBegin, const char **pszLineEnd)
Definition: ListFile.cpp:111
PCASC_MAP pRootMap
Definition: CascRootFile_Ovr.cpp:34
DYNAMIC_ARRAY FileNames
Definition: CascRootFile_Ovr.cpp:31
ROOT_SEARCH Search
Definition: RootHandler.h:69
#define FIELD_OFFSET(t, f)
Definition: CascPort.h:122
PCASC_MAP pEncodingMap
Definition: CascCommon.h:220
static void OvrHandler_Close(TRootHandler_Ovr *pRootHandler)
Definition: CascRootFile_Ovr.cpp:112
static LPBYTE OvrHandler_Search(TRootHandler_Ovr *pRootHandler, TCascSearch *pSearch, PDWORD, PDWORD)
Definition: CascRootFile_Ovr.cpp:80
ROOT_ENDSEARCH EndSearch
Definition: RootHandler.h:70
void * ListFile_FromBuffer(LPBYTE pbBuffer, DWORD cbBuffer)
Definition: ListFile.cpp:86
unsigned int DWORD
Definition: CascPort.h:139
static void OvrHandler_EndSearch(TRootHandler_Ovr *, TCascSearch *)
Definition: CascRootFile_Ovr.cpp:100
int(* ROOT_INSERT)(struct TRootHandler *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: RootHandler.h:30
BYTE Value[MD5_HASH_SIZE]
Definition: CascCommon.h:98
Definition: CascRootFile_Ovr.cpp:25
void(* ROOT_CLOSE)(struct TRootHandler *pRootHandler)
Definition: RootHandler.h:62
DYNAMIC_ARRAY FileTable
Definition: CascRootFile_Ovr.cpp:28
int GetRootVariableIndex(const char *szLinePtr, const char *szLineEnd, const char *szVariableName, int *PtrIndex)
Definition: CascFiles.cpp:953
ROOT_CLOSE Close
Definition: RootHandler.h:73
static int InsertFileEntry(TRootHandler_Ovr *pRootHandler, const char *szFileName, LPBYTE pbEncodingKey)
Definition: CascRootFile_Ovr.cpp:40
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function: