Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
gameobject_extract.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
model.h
"
7
#include "
dbcfile.h
"
8
#include "
adtfile.h
"
9
#include "
vmapexport.h
"
10
11
#include <algorithm>
12
#include <stdio.h>
13
14
bool
ExtractSingleModel
(std::string& fname)
15
{
16
if
(fname.substr(fname.length() - 4, 4) ==
".mdx"
)
17
{
18
fname.erase(fname.length() - 2, 2);
19
fname.append(
"2"
);
20
}
21
22
std::string originalName = fname;
23
24
char
* name =
GetPlainName
((
char
*)fname.c_str());
25
FixNameCase
(name, strlen(name));
26
FixNameSpaces
(name, strlen(name));
27
28
std::string output(
szWorkDirWmo
);
29
output +=
"/"
;
30
output += name;
31
32
if
(
FileExists
(output.c_str()))
33
return
true
;
34
35
Model
mdl(originalName);
36
if
(!mdl.
open
())
37
return
false
;
38
39
return
mdl.
ConvertToVMAPModel
(output.c_str());
40
}
41
42
extern
HANDLE
WorldMpq
;
43
44
void
ExtractGameobjectModels
()
45
{
46
printf(
"Extracting GameObject models..."
);
47
DBCFile
dbc(
WorldMpq
,
"DBFilesClient\\GameObjectDisplayInfo.dbc"
);
48
if
(!dbc.
open
())
49
{
50
printf(
"Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n"
);
51
exit(1);
52
}
53
54
std::string basepath =
szWorkDirWmo
;
55
basepath +=
"/"
;
56
std::string path;
57
58
FILE *
model_list
= fopen((basepath +
"temp_gameobject_models"
).c_str(),
"wb"
);
59
60
for
(
DBCFile::Iterator
it = dbc.
begin
(); it != dbc.
end
(); ++it)
61
{
62
path = it->getString(1);
63
64
if
(path.length() < 4)
65
continue
;
66
67
FixNameCase
((
char
*)path.c_str(), path.size());
68
char
* name =
GetPlainName
((
char
*)path.c_str());
69
FixNameSpaces
(name, strlen(name));
70
71
char
* ch_ext =
GetExtension
(name);
72
if
(!ch_ext)
73
continue
;
74
75
strToLower
(ch_ext);
76
77
bool
result =
false
;
78
if
(!strcmp(ch_ext,
".wmo"
))
79
result =
ExtractSingleWmo
(path);
80
else
if
(!strcmp(ch_ext,
".mdl"
))
// TODO: extract .mdl files, if needed
81
continue
;
82
else
if
(!strcmp(ch_ext,
".mdx"
) || !strcmp(ch_ext,
".m2"
))
83
result =
ExtractSingleModel
(path);
84
85
if
(result)
86
{
87
uint32
displayId = it->getUInt(0);
88
uint32
path_length = strlen(name);
89
fwrite(&displayId,
sizeof
(
uint32
), 1,
model_list
);
90
fwrite(&path_length,
sizeof
(
uint32
), 1,
model_list
);
91
fwrite(name,
sizeof
(
char
), path_length,
model_list
);
92
}
93
}
94
95
fclose(
model_list
);
96
printf(
"Done!\n"
);
97
}
uint32
std::uint32_t uint32
Definition
Define.h:77
model_list
ModelList model_list
Definition
GameObjectModel.cpp:28
WorldMpq
HANDLE WorldMpq
Definition
System.cpp:49
FileExists
bool FileExists(TCHAR const *fileName)
Definition
System.cpp:147
GetPlainName
char const * GetPlainName(char const *FileName)
Definition
adtfile.cpp:16
FixNameCase
void FixNameCase(char *name, size_t len)
Definition
adtfile.cpp:34
GetExtension
char * GetExtension(char *FileName)
Definition
adtfile.cpp:60
FixNameSpaces
void FixNameSpaces(char *name, size_t len)
Definition
adtfile.cpp:51
adtfile.h
DBCFile::Iterator
Definition
dbcfile.h:82
DBCFile
Definition
dbcfile.h:13
DBCFile::end
Iterator end()
Get begin iterator over records.
Definition
dbcfile.cpp:92
DBCFile::begin
Iterator begin()
Get begin iterator over records.
Definition
dbcfile.cpp:86
DBCFile::open
virtual bool open()
Definition
dbcfile.cpp:16
Model
Definition
model.h:18
Model::open
bool open()
Definition
model.cpp:21
Model::ConvertToVMAPModel
bool ConvertToVMAPModel(char const *outfilename)
Definition
model.cpp:59
ExtractSingleModel
bool ExtractSingleModel(std::string &fname)
Definition
gameobject_extract.cpp:14
ExtractGameobjectModels
void ExtractGameobjectModels()
Definition
gameobject_extract.cpp:44
model.h
dbcfile.h
szWorkDirWmo
const char * szWorkDirWmo
Definition
vmapexport.cpp:115
strToLower
void strToLower(char *str)
Definition
vmapexport.cpp:244
ExtractSingleWmo
bool ExtractSingleWmo(std::string &fname)
Definition
vmapexport.cpp:327
vmapexport.h
src
tools
vmap4_extractor
gameobject_extract.cpp
Generated on
for Project SkyFire Core by
1.17.0