AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
gameobject_extract.cpp File Reference
#include "adtfile.h"
#include "dbcfile.h"
#include "model.h"
#include "vmapexport.h"
#include <cstdio>

Go to the source code of this file.

Functions

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

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}
ModelList model_list
Definition: GameObjectModel.cpp:43
void strToLower(std::string &str)
Definition: Util.cpp:384
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
bool ExtractSingleModel(std::string &fname)
Definition: gameobject_extract.cpp:24
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
char const * szWorkDirWmo
Definition: vmapexport.cpp:68
bool ExtractSingleWmo(std::string &fname)
Definition: vmapexport.cpp:98
const char RAW_VMAP_MAGIC[]
Definition: VMapDefinitions.h:26
Definition: dbcfile.h:25

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().