TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gameobject_extract.cpp File Reference
#include "model.h"
#include "dbcfile.h"
#include "adtfile.h"
#include "vmapexport.h"
#include <algorithm>
#include <stdio.h>
+ Include dependency graph for gameobject_extract.cpp:

Functions

bool ExtractSingleModel (std::string &fname)
 
void ExtractGameobjectModels ()
 

Variables

HANDLE CascStorage
 

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:

Variable Documentation

HANDLE CascStorage