Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
14bool 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
42extern HANDLE WorldMpq;
43
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}
std::uint32_t uint32
Definition Define.h:77
ModelList model_list
HANDLE WorldMpq
Definition System.cpp:49
bool FileExists(TCHAR const *fileName)
Definition System.cpp:147
char const * GetPlainName(char const *FileName)
Definition adtfile.cpp:16
void FixNameCase(char *name, size_t len)
Definition adtfile.cpp:34
char * GetExtension(char *FileName)
Definition adtfile.cpp:60
void FixNameSpaces(char *name, size_t len)
Definition adtfile.cpp:51
Iterator end()
Get begin iterator over records.
Definition dbcfile.cpp:92
Iterator begin()
Get begin iterator over records.
Definition dbcfile.cpp:86
virtual bool open()
Definition dbcfile.cpp:16
Definition model.h:18
bool open()
Definition model.cpp:21
bool ConvertToVMAPModel(char const *outfilename)
Definition model.cpp:59
bool ExtractSingleModel(std::string &fname)
void ExtractGameobjectModels()
const char * szWorkDirWmo
void strToLower(char *str)
bool ExtractSingleWmo(std::string &fname)