TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vmapexport.cpp File Reference
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <errno.h>
#include <sys/stat.h>
#include <map>
#include <fstream>
#include "Common.h"
#include "adtfile.h"
#include "wdtfile.h"
#include "dbcfile.h"
#include "wmo.h"
#include "mpqfile.h"
#include "vmapexport.h"
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
+ Include dependency graph for vmapexport.cpp:

Classes

struct  map_id
 

Macros

#define _CRT_SECURE_NO_DEPRECATE
 
#define ERROR_PATH_NOT_FOUND   ERROR_FILE_NOT_FOUND
 
#define MPQ_BLOCK_SIZE   0x1000
 
#define CASC_LOCALES_COUNT   17
 

Functions

uint32 ReadBuild (int locale)
 
bool OpenCascStorage (int locale)
 
bool FileExists (const char *file)
 
void strToLower (char *str)
 
void ReadLiquidTypeTableDBC ()
 
bool ExtractWmo ()
 
bool ExtractSingleWmo (std::string &fname)
 
void ParsMapFiles ()
 
bool processArgv (int argc, char **argv, const char *versionString)
 
int main (int argc, char **argv)
 

Variables

HANDLE CascStorage = NULL
 
map_idmap_ids
 
uint16LiqType = 0
 
uint32 map_count
 
char output_path [128] = "."
 
char input_path [1024] = "."
 
bool preciseVectorData = false
 
const char * szWorkDirWmo = "./Buildings"
 
const char * szRawVMAPMagic = "VMAP043"
 
char constCascLocaleNames [CASC_LOCALES_COUNT]
 
uint32 WowLocaleToCascLocaleFlags [12]
 

Macro Definition Documentation

#define _CRT_SECURE_NO_DEPRECATE
#define CASC_LOCALES_COUNT   17
#define ERROR_PATH_NOT_FOUND   ERROR_FILE_NOT_FOUND
#define MPQ_BLOCK_SIZE   0x1000

Function Documentation

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 ExtractWmo ( )
251 {
252  bool success = true;
253 
254  std::ifstream wmoList("wmo_list.txt");
255  if (!wmoList)
256  {
257  printf("\nUnable to open wmo_list.txt! Nothing extracted.\n");
258  return false;
259  }
260 
261  std::set<std::string> wmos;
262  for (;;)
263  {
264  std::string str;
265  std::getline(wmoList, str);
266  if (str.empty())
267  break;
268 
269  wmos.insert(std::move(str));
270  }
271 
272  for (std::string str : wmos)
273  success &= ExtractSingleWmo(str);
274 
275  if (success)
276  printf("\nExtract wmo complete (No (fatal) errors)\n");
277 
278  return success;
279 }
bool ExtractSingleWmo(std::string &fname)
Definition: vmapexport.cpp:281
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:

int main ( int  argc,
char **  argv 
)
459 {
460  bool success = true;
461  const char *versionString = "V4.03 2015_05";
462 
463  // Use command line arguments, when some
464  if (!processArgv(argc, argv, versionString))
465  return 1;
466 
467  // some simple check if working dir is dirty
468  else
469  {
470  std::string sdir = std::string(szWorkDirWmo) + "/dir";
471  std::string sdir_bin = std::string(szWorkDirWmo) + "/dir_bin";
472  struct stat status;
473  if (!stat(sdir.c_str(), &status) || !stat(sdir_bin.c_str(), &status))
474  {
475  printf("Your output directory seems to be polluted, please use an empty directory!\n");
476  printf("<press return to exit>");
477  char garbage[2];
478  return scanf("%c", garbage);
479  }
480  }
481 
482  printf("Extract %s. Beginning work ....\n\n", versionString);
483  //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
484  // Create the working directory
485  if (mkdir(szWorkDirWmo
486 #if defined(__linux__) || defined(__APPLE__)
487  , 0711
488 #endif
489  ))
490  success = (errno == EEXIST);
491 
492  int FirstLocale = -1;
493  for (int i = 0; i < TOTAL_LOCALES; ++i)
494  {
495  if (i == LOCALE_none)
496  continue;
497 
498  if (!OpenCascStorage(i))
499  continue;
500 
501  FirstLocale = i;
502  uint32 build = ReadBuild(i);
503  if (!build)
504  {
506  continue;
507  }
508 
509  printf("Detected client build: %u\n\n", build);
510  break;
511  }
512 
513  if (!OpenCascStorage(FirstLocale))
514  {
516  printf("Unable to open storage!\n");
517  return 1;
518  }
519 
520  // Extract models, listed in GameObjectDisplayInfo.dbc
522 
524 
525  // extract data
526  if (success)
527  success = ExtractWmo();
528 
529  //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
530  //map.dbc
531  if (success)
532  {
533  DBCFile * dbc = new DBCFile(CascStorage, "DBFilesClient\\Map.dbc");
534  if (!dbc->open())
535  {
536  delete dbc;
537  printf("FATAL ERROR: Map.dbc not found in data file.\n");
538  return 1;
539  }
540 
541  map_count = dbc->getRecordCount();
542  map_ids = new map_id[map_count];
543  for (unsigned int x = 0; x < map_count; ++x)
544  {
545  map_ids[x].id = dbc->getRecord(x).getUInt(0);
546 
547  const char* map_name = dbc->getRecord(x).getString(1);
548  size_t max_map_name_length = sizeof(map_ids[x].name);
549  if (strlen(map_name) >= max_map_name_length)
550  {
551  delete dbc;
552  delete[] map_ids;
553  printf("FATAL ERROR: Map name too long.\n");
554  return 1;
555  }
556 
557  strncpy(map_ids[x].name, map_name, max_map_name_length);
558  map_ids[x].name[max_map_name_length - 1] = '\0';
559  printf("Map - %s\n", map_ids[x].name);
560  }
561 
562  delete dbc;
563  ParsMapFiles();
564  delete [] map_ids;
565  }
566 
568 
569  printf("\n");
570  if (!success)
571  {
572  printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n", versionString, preciseVectorData);
573  getchar();
574  }
575 
576  printf("Extract %s. Work complete. No errors.\n", versionString);
577  delete [] LiqType;
578  return 0;
579 }
Record getRecord(size_t id)
Definition: dbcfile.cpp:81
Definition: dbcfile.h:25
uint32 map_count
Definition: vmapexport.cpp:73
Definition: Common.h:126
char name[64]
Definition: System.cpp:73
bool processArgv(int argc, char **argv, const char *versionString)
Definition: vmapexport.cpp:394
uint32 ReadBuild(int locale)
Definition: vmapexport.cpp:140
bool open()
Definition: dbcfile.cpp:29
char const * getString(size_t field) const
Definition: dbcfile.h:74
uint32 id
Definition: System.cpp:74
Definition: System.cpp:71
HANDLE CascStorage
Definition: vmapexport.cpp:63
bool ExtractWmo()
Definition: vmapexport.cpp:250
bool WINAPI CascCloseStorage(HANDLE hStorage)
Definition: CascOpenStorage.cpp:1133
void ParsMapFiles()
Definition: vmapexport.cpp:362
map_id * map_ids
Definition: vmapexport.cpp:71
uint32_t uint32
Definition: Define.h:150
void ExtractGameobjectModels()
Definition: gameobject_extract.cpp:57
uint16 * LiqType
Definition: vmapexport.cpp:72
int GetLastError()
Definition: Common.cpp:70
void ReadLiquidTypeTableDBC()
Definition: vmapexport.cpp:228
unsigned int getUInt(size_t field) const
Definition: dbcfile.h:62
size_t getRecordCount() const
Trivial.
Definition: dbcfile.h:134
bool OpenCascStorage(int locale)
Definition: vmapexport.cpp:186
G3D::int16 x
Definition: Vector2int16.h:37
const char * szWorkDirWmo
Definition: vmapexport.cpp:81
#define ERROR_PATH_NOT_FOUND
Definition: vmapexport.cpp:34
Definition: Common.h:130
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:

bool OpenCascStorage ( int  locale)
187 {
188  try
189  {
190  boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
191  if (!CascOpenStorage(storage_dir.string().c_str(), WowLocaleToCascLocaleFlags[locale], &CascStorage))
192  {
193  printf("error opening casc storage '%s' locale %s: %s\n", storage_dir.string().c_str(), localeNames[locale], HumanReadableCASCError(GetLastError()));
194  return false;
195  }
196  printf("opened casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
197  return true;
198  }
199  catch (boost::filesystem::filesystem_error& error)
200  {
201  printf("error opening casc storage : %s\n", error.what());
202  return false;
203  }
204 }
char input_path[1024]
Definition: vmapexport.cpp:75
uint32 WowLocaleToCascLocaleFlags[12]
Definition: vmapexport.cpp:98
HANDLE CascStorage
Definition: vmapexport.cpp:63
int GetLastError()
Definition: Common.cpp:70
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
bool WINAPI CascOpenStorage(const TCHAR *szDataPath, DWORD dwLocaleMask, HANDLE *phStorage)
Definition: CascOpenStorage.cpp:1011
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:

void ParsMapFiles ( )
363 {
364  char fn[512];
365  //char id_filename[64];
366  char id[10];
367  for (unsigned int i=0; i<map_count; ++i)
368  {
369  sprintf(id, "%04u", map_ids[i].id);
370  sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
371  WDTFile WDT(fn,map_ids[i].name);
372  if(WDT.init(id, map_ids[i].id))
373  {
374  printf("Processing Map %u\n[", map_ids[i].id);
375  for (int x=0; x<64; ++x)
376  {
377  for (int y=0; y<64; ++y)
378  {
379  if (ADTFile *ADT = WDT.GetMap(x,y))
380  {
381  //sprintf(id_filename,"%02u %02u %03u",x,y,map_ids[i].id);//!!!!!!!!!
382  ADT->init(map_ids[i].id, x, y);
383  delete ADT;
384  }
385  }
386  printf("#");
387  fflush(stdout);
388  }
389  printf("]\n");
390  }
391  }
392 }
uint32 map_count
Definition: vmapexport.cpp:73
Definition: adtfile.h:110
uint32 id
Definition: System.cpp:74
Definition: wdtfile.h:30
std::string sprintf(CStringRef format, ArgList args)
Definition: format.h:3096
map_id * map_ids
Definition: vmapexport.cpp:71
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
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 processArgv ( int  argc,
char **  argv,
const char *  versionString 
)
395 {
396  bool result = true;
397  preciseVectorData = false;
398 
399  for(int i = 1; i < argc; ++i)
400  {
401  if(strcmp("-s",argv[i]) == 0)
402  {
403  preciseVectorData = false;
404  }
405  else if(strcmp("-d",argv[i]) == 0)
406  {
407  if((i+1)<argc)
408  {
409  strncpy(input_path, argv[i + 1], sizeof(input_path));
410  input_path[sizeof(input_path) - 1] = '\0';
411 
412  if (input_path[strlen(input_path) - 1] != '\\' && input_path[strlen(input_path) - 1] != '/')
413  strcat(input_path, "/");
414  ++i;
415  }
416  else
417  {
418  result = false;
419  }
420  }
421  else if(strcmp("-?",argv[1]) == 0)
422  {
423  result = false;
424  }
425  else if(strcmp("-l",argv[i]) == 0)
426  {
427  preciseVectorData = true;
428  }
429  else
430  {
431  result = false;
432  break;
433  }
434  }
435 
436  if (!result)
437  {
438  printf("Extract %s.\n",versionString);
439  printf("%s [-?][-s][-l][-d <path>]\n", argv[0]);
440  printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
441  printf(" -l : large size, ~500MB more vmap data. (might contain more details)\n");
442  printf(" -d <path>: Path to the vector data source folder.\n");
443  printf(" -? : This message.\n");
444  }
445 
446  return result;
447 }
char input_path[1024]
Definition: vmapexport.cpp:75
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:

uint32 ReadBuild ( int  locale)
141 {
142  // include build info file also
143  std::string filename = std::string("component.wow-") + localeNames[locale] + ".txt";
144  //printf("Read %s file... ", filename.c_str());
145 
146  HANDLE dbcFile;
147  if (!CascOpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL, 0, &dbcFile))
148  {
149  printf("Locale %s not installed.\n", localeNames[locale]);
150  return 0;
151  }
152 
153  char buff[512];
154  DWORD readBytes = 0;
155  CascReadFile(dbcFile, buff, 512, &readBytes);
156  if (!readBytes)
157  {
158  printf("Fatal error: Not found %s file!\n", filename.c_str());
159  exit(1);
160  }
161 
162  std::string text = std::string(buff, readBytes);
163  CascCloseFile(dbcFile);
164 
165  size_t pos = text.find("version=\"");
166  size_t pos1 = pos + strlen("version=\"");
167  size_t pos2 = text.find("\"", pos1);
168  if (pos == text.npos || pos2 == text.npos || pos1 >= pos2)
169  {
170  printf("Fatal error: Invalid %s file format!\n", filename.c_str());
171  exit(1);
172  }
173 
174  std::string build_str = text.substr(pos1, pos2 - pos1);
175 
176  int build = atoi(build_str.c_str());
177  if (build <= 0)
178  {
179  printf("Fatal error: Invalid %s file format!\n", filename.c_str());
180  exit(1);
181  }
182 
183  return build;
184 }
#define CASC_LOCALE_ALL
Definition: CascLib.h:64
void * HANDLE
Definition: CascPort.h:146
HANDLE CascStorage
Definition: vmapexport.cpp:63
unsigned int DWORD
Definition: CascPort.h:139
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
bool WINAPI CascReadFile(HANDLE hFile, void *lpBuffer, DWORD dwToRead, PDWORD pdwRead)
Definition: CascReadFile.cpp:459
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196
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:

void ReadLiquidTypeTableDBC ( )
229 {
230  printf("Read LiquidType.dbc file...");
231 
232  DBCFile dbc(CascStorage, "DBFilesClient\\LiquidType.dbc");
233  if(!dbc.open())
234  {
235  printf("Fatal error: Invalid LiquidType.dbc file format!\n");
236  exit(1);
237  }
238 
239  size_t LiqType_count = dbc.getRecordCount();
240  size_t LiqType_maxid = dbc.getRecord(LiqType_count - 1).getUInt(0);
241  LiqType = new uint16[LiqType_maxid + 1];
242  memset(LiqType, 0xff, (LiqType_maxid + 1) * sizeof(uint16));
243 
244  for(uint32 x = 0; x < LiqType_count; ++x)
245  LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
246 
247  printf("Done! (%u LiqTypes loaded)\n", (unsigned int)LiqType_count);
248 }
Definition: dbcfile.h:25
HANDLE CascStorage
Definition: vmapexport.cpp:63
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
uint16 * LiqType
Definition: vmapexport.cpp:72
G3D::int16 x
Definition: Vector2int16.h:37
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:

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

char const* CascLocaleNames[CASC_LOCALES_COUNT]
Initial value:
=
{
"none", "enUS",
"koKR", "unknown",
"frFR", "deDE",
"zhCN", "esES",
"zhTW", "enGB",
"enCN", "enTW",
"esMX", "ruRU",
"ptBR", "itIT",
"ptPT"
}
HANDLE CascStorage = NULL
char input_path[1024] = "."
uint16* LiqType = 0
uint32 map_count
map_id* map_ids
char output_path[128] = "."
bool preciseVectorData = false
const char* szRawVMAPMagic = "VMAP043"
const char* szWorkDirWmo = "./Buildings"
uint32 WowLocaleToCascLocaleFlags[12]
Initial value:
=
{
0,
}
#define CASC_LOCALE_ESES
Definition: CascLib.h:73
#define CASC_LOCALE_DEDE
Definition: CascLib.h:71
#define CASC_LOCALE_KOKR
Definition: CascLib.h:68
#define CASC_LOCALE_FRFR
Definition: CascLib.h:70
#define CASC_LOCALE_ENUS
Definition: CascLib.h:67
#define CASC_LOCALE_ZHCN
Definition: CascLib.h:72
#define CASC_LOCALE_ZHTW
Definition: CascLib.h:74
#define CASC_LOCALE_ESMX
Definition: CascLib.h:78
#define CASC_LOCALE_RURU
Definition: CascLib.h:79
#define CASC_LOCALE_ITIT
Definition: CascLib.h:81
#define CASC_LOCALE_PTBR
Definition: CascLib.h:80
#define CASC_LOCALE_ENGB
Definition: CascLib.h:75
#define CASC_LOCALE_PTPT
Definition: CascLib.h:82