TrinityCore
Loading...
Searching...
No Matches
gameobject_extract.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "model.h"
19#include "dbcfile.h"
20#include "adtfile.h"
21#include "vmapexport.h"
22#include "VMapDefinitions.h"
23#include <algorithm>
24#include <stdio.h>
25
26bool ExtractSingleModel(std::string& fname)
27{
28 if (fname.length() < 4)
29 return false;
30
31 std::string extension = fname.substr(fname.length() - 4, 4);
32 if (extension == ".mdx" || extension == ".MDX" || extension == ".mdl" || extension == ".MDL")
33 {
34 fname.erase(fname.length() - 2, 2);
35 fname.append("2");
36 }
37
38 std::string originalName = fname;
39
40 char* name = GetPlainName((char*)fname.c_str());
41 FixNameCase(name, strlen(name));
42 FixNameSpaces(name, strlen(name));
43
44 std::string output(szWorkDirWmo);
45 output += "/";
46 output += name;
47
48 if (FileExists(output.c_str()))
49 return true;
50
51 Model mdl(originalName);
52 if (!mdl.open())
53 return false;
54
55 return mdl.ConvertToVMAPModel(output.c_str());
56}
57
59{
60 printf("Extracting GameObject models...");
61 DBCFile dbc("DBFilesClient\\GameObjectDisplayInfo.dbc");
62 if(!dbc.open())
63 {
64 printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
65 exit(1);
66 }
67
68 std::string basepath = szWorkDirWmo;
69 basepath += "/";
70 std::string path;
71
72 std::string modelListPath = basepath + "temp_gameobject_models";
73 FILE* model_list = fopen(modelListPath.c_str(), "wb");
74 if (!model_list)
75 {
76 printf("Fatal error: Could not open file %s\n", modelListPath.c_str());
77 return;
78 }
79
80 fwrite(VMAP::RAW_VMAP_MAGIC, 1, 8, model_list);
81
82 for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
83 {
84 path = it->getString(1);
85
86 if (path.length() < 4)
87 continue;
88
89 FixNameCase((char*)path.c_str(), path.size());
90 char * name = GetPlainName((char*)path.c_str());
91 FixNameSpaces(name, strlen(name));
92
93 char * ch_ext = GetExtension(name);
94 if (!ch_ext)
95 continue;
96
97 strToLower(ch_ext);
98
99 bool result = false;
100 uint8 isWmo = 0;
101 if (!strcmp(ch_ext, ".wmo"))
102 {
103 isWmo = 1;
104 result = ExtractSingleWmo(path);
105 }
106 else if (!strcmp(ch_ext, ".mdl")) // TODO: extract .mdl files, if needed
107 continue;
108 else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
109 result = ExtractSingleModel(path);
110
111 if (result)
112 {
113 uint32 displayId = it->getUInt(0);
114 uint32 path_length = strlen(name);
115 fwrite(&displayId, sizeof(uint32), 1, model_list);
116 fwrite(&isWmo, sizeof(uint8), 1, model_list);
117 fwrite(&path_length, sizeof(uint32), 1, model_list);
118 fwrite(name, sizeof(char), path_length, model_list);
119 }
120 }
121
122 fclose(model_list);
123
124 printf("Done!\n");
125}
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
ModelList model_list
void strToLower(std::string &str)
Definition Util.cpp:482
char const * GetPlainName(char const *FileName)
Definition adtfile.cpp:25
void FixNameCase(char *name, size_t len)
Definition adtfile.cpp:43
char * GetExtension(char *FileName)
Definition adtfile.cpp:70
void FixNameSpaces(char *name, size_t len)
Definition adtfile.cpp:60
Iterator end()
Get begin iterator over records.
Definition dbcfile.cpp:93
Iterator begin()
Get begin iterator over records.
Definition dbcfile.cpp:88
bool open()
Definition dbcfile.cpp:27
Definition model.h:33
bool open()
Definition model.cpp:35
bool ConvertToVMAPModel(char const *outfilename)
Definition model.cpp:73
bool ExtractSingleModel(std::string &fname)
void ExtractGameobjectModels()
const char RAW_VMAP_MAGIC[]
bool FileExists(char const *file)
char const * szWorkDirWmo
bool ExtractSingleWmo(std::string &fname)