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

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

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:109
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
Definition: wmo.h:71
std::unordered_set< uint16 > References
Definition: wmo.h:75
std::vector< WMO::MODD > Spawns
Definition: wmo.h:74
Definition: wmo.h:79
Definition: wmo.h:118

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