AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
vmapexport.h File Reference
#include "loadlib/loadlib.h"
#include <string>
#include <unordered_map>

Go to the source code of this file.

Namespaces

namespace  VMAP
 

Enumerations

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

Functions

uint32 GenerateUniqueObjectId (uint32 clientId, uint16 clientDoodadId)
 
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
 
std::unordered_map< std::string, WMODoodadDataWmoDoodads
 

Enumeration Type Documentation

◆ ModelFlags

enum ModelFlags
Enumerator
MOD_M2 
MOD_WORLDSPAWN 
MOD_HAS_BOUND 
32{
33 MOD_M2 = 1,
34 MOD_WORLDSPAWN = 1 << 1,
35 MOD_HAS_BOUND = 1 << 2
36};
@ MOD_M2
Definition vmapexport.h:33
@ MOD_WORLDSPAWN
Definition vmapexport.h:34
@ MOD_HAS_BOUND
Definition vmapexport.h:35

Function Documentation

◆ ExtractGameobjectModels()

void ExtractGameobjectModels ( )
Todo:
: extract .mdl files, if needed
60{
61 printf("Extracting GameObject models...");
62 DBCFile dbc("DBFilesClient\\GameObjectDisplayInfo.dbc");
63 if (!dbc.open())
64 {
65 printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
66 exit(1);
67 }
68
69 std::string basepath = szWorkDirWmo;
70 basepath += "/";
71 std::string path;
72
73 std::string modelListPath = basepath + "temp_gameobject_models";
74 FILE* model_list = fopen(modelListPath.c_str(), "wb");
75 if (!model_list)
76 {
77 printf("Fatal error: Could not open file %s\n", modelListPath.c_str());
78 return;
79 }
80
81 fwrite(VMAP::RAW_VMAP_MAGIC, 1, 8, model_list);
82
83 for (const auto & it : dbc)
84 {
85 path = it.getString(1);
86
87 if (path.length() < 4)
88 continue;
89
90 fixnamen((char*)path.c_str(), path.size());
91 char* name = GetPlainName((char*)path.c_str());
92 fixname2(name, strlen(name));
93
94 char* ch_ext = GetExtension(name);
95 if (!ch_ext)
96 continue;
97
98 strToLower(ch_ext);
99
100 bool result = false;
101 uint8 isWmo = 0;
102 if (!strcmp(ch_ext, ".wmo"))
103 {
104 isWmo = 1;
105 result = ExtractSingleWmo(path);
106 }
107 else if (!strcmp(ch_ext, ".mdl"))
108 {
110 continue;
111 }
112 else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
113 {
114 result = ExtractSingleModel(path);
115 }
116
117 if (result)
118 {
119 uint32 displayId = it.getUInt(0);
120 uint32 path_length = strlen(name);
121 fwrite(&displayId, sizeof(uint32), 1, model_list);
122 fwrite(&isWmo, sizeof(uint8), 1, model_list);
123 fwrite(&path_length, sizeof(uint32), 1, model_list);
124 fwrite(name, sizeof(char), path_length, model_list);
125 }
126 }
127
128 fclose(model_list);
129
130 printf("Done!\n");
131}
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
ModelList model_list
Definition GameObjectModel.cpp:43
void strToLower(std::string &str)
Definition Util.cpp:384
char const * GetPlainName(char const *FileName)
Definition adtfile.cpp:26
void fixnamen(char *name, std::size_t len)
Definition adtfile.cpp:44
void fixname2(char *name, std::size_t len)
Definition adtfile.cpp:62
char * GetExtension(char *FileName)
Definition adtfile.cpp:72
Definition dbcfile.h:25
bool ExtractSingleModel(std::string &fname)
Definition gameobject_extract.cpp:24
const char RAW_VMAP_MAGIC[]
Definition VMapDefinitions.h:26
char const * szWorkDirWmo
Definition vmapexport.cpp:68
bool ExtractSingleWmo(std::string &fname)
Definition vmapexport.cpp:98

References ExtractSingleModel(), ExtractSingleWmo(), fixname2(), fixnamen(), GetExtension(), GetPlainName(), model_list, DBCFile::open(), VMAP::RAW_VMAP_MAGIC, strToLower(), and szWorkDirWmo.

Referenced by main().

◆ ExtractSingleModel()

bool ExtractSingleModel ( std::string &  fname)
25{
26 if (fname.length() < 4)
27 return false;
28
29 std::string extension = fname.substr(fname.length() - 4, 4);
30 if (extension == ".mdx" || extension == ".MDX" || extension == ".mdl" || extension == ".MDL")
31 {
32 // replace .mdx -> .m2
33 fname.erase(fname.length() - 2, 2);
34 fname.append("2");
35 }
36 // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
37 // nothing do
38
39 std::string originalName = fname;
40
41 char* name = GetPlainName((char*)fname.c_str());
42 fixnamen(name, strlen(name));
43 fixname2(name, strlen(name));
44
45 std::string output(szWorkDirWmo);
46 output += "/";
47 output += name;
48
49 if (FileExists(output.c_str()))
50 return true;
51
52 Model mdl(originalName);
53 if (!mdl.open())
54 return false;
55
56 return mdl.ConvertToVMAPModel(output.c_str());
57}
bool FileExists(const char *FileName)
Definition System.cpp:143
Definition model.h:32

References Model::ConvertToVMAPModel(), FileExists(), fixname2(), fixnamen(), GetPlainName(), Model::open(), and szWorkDirWmo.

Referenced by ExtractGameobjectModels(), ADTFile::init(), and WMORoot::open().

◆ ExtractSingleWmo()

bool ExtractSingleWmo ( std::string &  fname)
99{
100 // Copy files from archive
101 std::string originalName = fname;
102
103 char szLocalFile[1024];
104 char* plain_name = GetPlainName(&fname[0]);
105 fixnamen(plain_name, strlen(plain_name));
106 fixname2(plain_name, strlen(plain_name));
107 sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
108
109 if (FileExists(szLocalFile))
110 return true;
111
112 int p = 0;
113 // Select root wmo files
114 char const* rchr = strrchr(plain_name, '_');
115 if (rchr != nullptr)
116 {
117 char cpy[4];
118 memcpy(cpy, rchr, 4);
119 for (int m : cpy)
120 {
121 if (isdigit(m))
122 p++;
123 }
124 }
125
126 if (p == 3)
127 return true;
128
129 bool file_ok = true;
130 printf("Extracting %s\n", originalName.c_str());
131 WMORoot froot(originalName);
132 if (!froot.open())
133 {
134 printf("Couldn't open RootWmo!!!\n");
135 return false;
136 }
137 FILE* output = fopen(szLocalFile, "wb");
138 if (!output)
139 {
140 printf("couldn't open %s for writing!\n", szLocalFile);
141 return false;
142 }
143 froot.ConvertToVMAPRootWmo(output);
144 WMODoodadData& doodads = WmoDoodads[plain_name];
145 std::swap(doodads, froot.DoodadData);
146 int Wmo_nVertices = 0;
147 //printf("root has %d groups\n", froot->nGroups);
148 if (froot.nGroups != 0)
149 {
150 for (uint32 i = 0; i < froot.nGroups; ++i)
151 {
152 char temp[1024];
153 strncpy(temp, fname.c_str(), 1024);
154 temp[fname.length() - 4] = 0;
155 char groupFileName[1024];
156 int ret = snprintf(groupFileName, 1024, "%s_%03u.wmo", temp, i);
157 if (ret < 0)
158 {
159 printf("Error when formatting string");
160 return false;
161 }
162 //printf("Trying to open groupfile %s\n",groupFileName);
163
164 string s = groupFileName;
165 WMOGroup fgroup(s);
166 if (!fgroup.open(&froot))
167 {
168 printf("Could not open all Group file for: %s\n", plain_name);
169 file_ok = false;
170 break;
171 }
172
173 Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, preciseVectorData);
174 for (uint16 groupReference : fgroup.DoodadReferences)
175 {
176 if (groupReference >= doodads.Spawns.size())
177 continue;
178
179 uint32 doodadNameIndex = doodads.Spawns[groupReference].NameIndex;
180 if (froot.ValidDoodadNames.find(doodadNameIndex) == froot.ValidDoodadNames.end())
181 continue;
182
183 doodads.References.insert(groupReference);
184 }
185 }
186 }
187
188 fseek(output, 8, SEEK_SET); // store the correct no of vertices
189 fwrite(&Wmo_nVertices, sizeof(int), 1, output);
190 fclose(output);
191
192 // Delete the extracted file in the case of an error
193 if (!file_ok)
194 remove(szLocalFile);
195 return true;
196}
std::uint16_t uint16
Definition Define.h:108
Definition wmo.h:118
Definition wmo.h:79
Definition wmo.h:71
std::unordered_set< uint16 > References
Definition wmo.h:75
std::vector< WMO::MODD > Spawns
Definition wmo.h:74
std::unordered_map< std::string, WMODoodadData > WmoDoodads
Definition vmapexport.cpp:64
bool preciseVectorData
Definition vmapexport.cpp:63
bool FileExists(const char *file)
Definition vmapexport.cpp:79

References WMOGroup::ConvertToVMAPGroupWmo(), WMORoot::ConvertToVMAPRootWmo(), WMORoot::DoodadData, WMOGroup::DoodadReferences, FileExists(), fixname2(), fixnamen(), GetPlainName(), WMORoot::nGroups, WMORoot::open(), WMOGroup::open(), preciseVectorData, WMODoodadData::References, WMODoodadData::Spawns, szWorkDirWmo, WMORoot::ValidDoodadNames, and WmoDoodads.

Referenced by ExtractGameobjectModels(), ADTFile::init(), and WDTFile::init().

◆ FileExists()

bool FileExists ( const char *  file)
144{
145 int fp = _open(FileName, OPEN_FLAGS);
146 if (fp != -1)
147 {
148 _close(fp);
149 return true;
150 }
151
152 return false;
153}
#define OPEN_FLAGS
Definition System.cpp:56

References OPEN_FLAGS.

Referenced by ExtractDBCFiles(), ExtractSingleModel(), ExtractSingleWmo(), LoadCommonMPQFiles(), LoadLocaleMPQFiles(), and main().

◆ GenerateUniqueObjectId()

uint32 GenerateUniqueObjectId ( uint32  clientId,
uint16  clientDoodadId 
)
73{
74 return uniqueObjectIds.emplace(std::make_pair(clientId, clientDoodadId), uint32(uniqueObjectIds.size() + 1)).first->second;
75}
std::map< std::pair< uint32, uint16 >, uint32 > uniqueObjectIds
Definition vmapexport.cpp:70

References uniqueObjectIds.

Referenced by Doodad::Extract(), MapObject::Extract(), and Doodad::ExtractSet().

◆ strToLower()

void strToLower ( char *  str)
90{
91 while (*str)
92 {
93 *str = tolower(*str);
94 ++str;
95 }
96}

Variable Documentation

◆ szWorkDirWmo

◆ WmoDoodads

std::unordered_map<std::string, WMODoodadData> WmoDoodads
extern