TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vmapexport.h File Reference
#include <string>
+ Include dependency graph for vmapexport.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ModelFlags { MOD_M2 = 1, MOD_WORLDSPAWN = 1<<1, MOD_HAS_BOUND = 1<<2 }
 

Functions

bool FileExists (const char *file)
 
void strToLower (char *str)
 
bool ExtractSingleWmo (std::string &fname)
 
bool ExtractSingleModel (std::string &fname)
 
void ExtractGameobjectModels ()
 

Variables

const char * szWorkDirWmo
 
const char * szRawVMAPMagic
 

Enumeration Type Documentation

enum ModelFlags
Enumerator
MOD_M2 
MOD_WORLDSPAWN 
MOD_HAS_BOUND 
25 {
26  MOD_M2 = 1,
27  MOD_WORLDSPAWN = 1<<1,
28  MOD_HAS_BOUND = 1<<2
29 };
Definition: vmapexport.h:26
Definition: vmapexport.h:28
Definition: vmapexport.h:27

Function Documentation

void ExtractGameobjectModels ( )
58 {
59  printf("Extracting GameObject models...");
60  DBCFile dbc(CascStorage, "DBFilesClient\\GameObjectDisplayInfo.dbc");
61  if(!dbc.open())
62  {
63  printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
64  exit(1);
65  }
66 
67  DBCFile fileData(CascStorage, "DBFilesClient\\FileData.dbc");
68  if (!fileData.open())
69  {
70  printf("Fatal error: Invalid FileData.dbc file format!\n");
71  exit(1);
72  }
73 
74  std::string basepath = szWorkDirWmo;
75  basepath += "/";
76  std::string path;
77 
78  std::string modelListPath = basepath + "temp_gameobject_models";
79  FILE* model_list = fopen(modelListPath.c_str(), "wb");
80  if (!model_list)
81  {
82  printf("Fatal error: Could not open file %s\n", modelListPath.c_str());
83  return;
84  }
85 
86  size_t maxFileId = fileData.getMaxId() + 1;
87  uint32* fileDataIndex = new uint32[maxFileId];
88  memset(fileDataIndex, 0, maxFileId * sizeof(uint32));
89  size_t files = fileData.getRecordCount();
90  for (uint32 i = 0; i < files; ++i)
91  fileDataIndex[fileData.getRecord(i).getUInt(0)] = i;
92 
93  for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
94  {
95  uint32 fileId = it->getUInt(1);
96  if (!fileId)
97  continue;
98 
99  uint32 fileIndex = fileDataIndex[fileId];
100  if (!fileIndex)
101  continue;
102 
103  std::string filename = fileData.getRecord(fileIndex).getString(1);
104  std::string filepath = fileData.getRecord(fileIndex).getString(2);
105 
106  path = filepath + filename;
107 
108  if (path.length() < 4)
109  continue;
110 
111  FixNameCase((char*)path.c_str(), path.size());
112  char * name = GetPlainName((char*)path.c_str());
113  FixNameSpaces(name, strlen(name));
114 
115  char * ch_ext = GetExtension(name);
116  if (!ch_ext)
117  continue;
118 
119  strToLower(ch_ext);
120 
121  bool result = false;
122  if (!strcmp(ch_ext, ".wmo"))
123  result = ExtractSingleWmo(path);
124  else if (!strcmp(ch_ext, ".mdl")) // TODO: extract .mdl files, if needed
125  continue;
126  else if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
127  result = ExtractSingleModel(path);
128 
129  if (result)
130  {
131  uint32 displayId = it->getUInt(0);
132  uint32 path_length = strlen(name);
133  fwrite(&displayId, sizeof(uint32), 1, model_list);
134  fwrite(&path_length, sizeof(uint32), 1, model_list);
135  fwrite(name, sizeof(char), path_length, model_list);
136  }
137  }
138 
139  fclose(model_list);
140 
141  delete[] fileDataIndex;
142 
143  printf("Done!\n");
144 }
bool ExtractSingleWmo(std::string &fname)
Definition: vmapexport.cpp:281
Definition: dbcfile.h:25
HANDLE CascStorage
Definition: System.cpp:69
bool ExtractSingleModel(std::string &fname)
Definition: gameobject_extract.cpp:27
ModelList model_list
Definition: GameObjectModel.cpp:41
void FixNameCase(char *name, size_t len)
Definition: adtfile.cpp:47
void strToLower(char *str)
Definition: vmapexport.cpp:218
void FixNameSpaces(char *name, size_t len)
Definition: adtfile.cpp:64
uint32_t uint32
Definition: Define.h:150
char * GetExtension(char *FileName)
Definition: adtfile.cpp:73
char const * GetPlainName(char const *FileName)
Definition: adtfile.cpp:29
const char * szWorkDirWmo
Definition: vmapexport.cpp:81
Definition: dbcfile.h:94
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ExtractSingleModel ( std::string &  fname)
28 {
29  if (fname.substr(fname.length() - 4, 4) == ".mdx")
30  {
31  fname.erase(fname.length() - 2, 2);
32  fname.append("2");
33  }
34 
35  std::string originalName = fname;
36 
37  char* name = GetPlainName((char*)fname.c_str());
38  FixNameCase(name, strlen(name));
39  FixNameSpaces(name, strlen(name));
40 
41  std::string output(szWorkDirWmo);
42  output += "/";
43  output += name;
44 
45  if (FileExists(output.c_str()))
46  return true;
47 
48  Model mdl(originalName);
49  if (!mdl.open())
50  return false;
51 
52  return mdl.ConvertToVMAPModel(output.c_str());
53 }
#define output
Definition: wire_format_lite.h:381
void FixNameCase(char *name, size_t len)
Definition: adtfile.cpp:47
void FixNameSpaces(char *name, size_t len)
Definition: adtfile.cpp:64
Definition: model.h:30
bool FileExists(const char *file)
Definition: vmapexport.cpp:208
char const * GetPlainName(char const *FileName)
Definition: adtfile.cpp:29
const char * szWorkDirWmo
Definition: vmapexport.cpp:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ExtractSingleWmo ( std::string &  fname)
282 {
283  // Copy files from archive
284 
285  char szLocalFile[1024];
286  const char * plain_name = GetPlainName(fname.c_str());
287  sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
288  FixNameCase(szLocalFile,strlen(szLocalFile));
289 
290  if (FileExists(szLocalFile))
291  return true;
292 
293  int p = 0;
294  // Select root wmo files
295  char const* rchr = strrchr(plain_name, '_');
296  if (rchr != NULL)
297  {
298  char cpy[4];
299  memcpy(cpy, rchr, 4);
300  for (int i = 0; i < 4; ++i)
301  {
302  int m = cpy[i];
303  if (isdigit(m))
304  p++;
305  }
306  }
307 
308  if (p == 3)
309  return true;
310 
311  bool file_ok = true;
312  std::cout << "Extracting " << fname << std::endl;
313  WMORoot froot(fname);
314  if(!froot.open())
315  {
316  printf("Couldn't open RootWmo!!!\n");
317  return true;
318  }
319  FILE *output = fopen(szLocalFile,"wb");
320  if(!output)
321  {
322  printf("couldn't open %s for writing!\n", szLocalFile);
323  return false;
324  }
325  froot.ConvertToVMAPRootWmo(output);
326  int Wmo_nVertices = 0;
327  //printf("root has %d groups\n", froot->nGroups);
328  if (froot.nGroups !=0)
329  {
330  for (uint32 i = 0; i < froot.nGroups; ++i)
331  {
332  char temp[1024];
333  strncpy(temp, fname.c_str(), 1024);
334  temp[fname.length()-4] = 0;
335  char groupFileName[1024];
336  sprintf(groupFileName, "%s_%03u.wmo", temp, i);
337  //printf("Trying to open groupfile %s\n",groupFileName);
338 
339  std::string s = groupFileName;
340  WMOGroup fgroup(s);
341  if(!fgroup.open())
342  {
343  printf("Could not open all Group file for: %s\n", plain_name);
344  file_ok = false;
345  break;
346  }
347 
348  Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
349  }
350  }
351 
352  fseek(output, 8, SEEK_SET); // store the correct no of vertices
353  fwrite(&Wmo_nVertices,sizeof(int),1,output);
354  fclose(output);
355 
356  // Delete the extracted file in the case of an error
357  if (!file_ok)
358  remove(szLocalFile);
359  return true;
360 }
Definition: wmo.h:81
arena_t NULL
Definition: jemalloc_internal.h:624
#define output
Definition: wire_format_lite.h:381
void FixNameCase(char *name, size_t len)
Definition: adtfile.cpp:47
std::string sprintf(CStringRef format, ArgList args)
Definition: format.h:3096
uint32_t uint32
Definition: Define.h:150
#define SEEK_SET
Definition: zconf.h:475
Definition: wmo.h:45
bool FileExists(const char *file)
Definition: vmapexport.cpp:208
char const * GetPlainName(char const *FileName)
Definition: adtfile.cpp:29
const char * szWorkDirWmo
Definition: vmapexport.cpp:81
bool preciseVectorData
Definition: vmapexport.cpp:76
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool FileExists ( const char *  file)
209 {
210  if (FILE* n = fopen(file, "rb"))
211  {
212  fclose(n);
213  return true;
214  }
215  return false;
216 }

+ Here is the caller graph for this function:

void strToLower ( char *  str)
219 {
220  while(*str)
221  {
222  *str=tolower(*str);
223  ++str;
224  }
225 }

+ Here is the caller graph for this function:

Variable Documentation

const char* szRawVMAPMagic
const char* szWorkDirWmo