AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ADTFile Class Reference

#include "adtfile.h"

Public Member Functions

 ADTFile (char *filename)
 
 ~ADTFile ()
 
bool init (uint32 map_num, uint32 tileX, uint32 tileY)
 

Public Attributes

std::vector< std::string > WmoInstanceNames
 
std::vector< std::string > ModelInstanceNames
 

Private Attributes

MPQFile _file
 
std::string Adtfilename
 

Detailed Description

Constructor & Destructor Documentation

◆ ADTFile()

ADTFile::ADTFile ( char *  filename)
80 : _file(filename)
81{
82 Adtfilename.append(filename);
83}
std::string Adtfilename
Definition: adtfile.h:57
MPQFile _file
Definition: adtfile.h:56

References Adtfilename.

◆ ~ADTFile()

ADTFile::~ADTFile ( )
199{
200 _file.close();
201}
void close()
Definition: mpq_libmpq.cpp:126

References _file, and MPQFile::close().

Member Function Documentation

◆ init()

bool ADTFile::init ( uint32  map_num,
uint32  tileX,
uint32  tileY 
)
86{
87 if (_file.isEof())
88 return false;
89
90 uint32 size;
91 std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
92 FILE* dirfile;
93 dirfile = fopen(dirname.c_str(), "ab");
94 if (!dirfile)
95 {
96 printf("Can't open dirfile!'%s'\n", dirname.c_str());
97 return false;
98 }
99
100 while (!_file.isEof())
101 {
102 char fourcc[5];
103 _file.read(&fourcc, 4);
104 _file.read(&size, 4);
105 flipcc(fourcc);
106 fourcc[4] = 0;
107
108 size_t nextpos = _file.getPos() + size;
109
110 if (!strcmp(fourcc, "MCIN"))
111 {
112 }
113 else if (!strcmp(fourcc, "MTEX"))
114 {
115 }
116 else if (!strcmp(fourcc, "MMDX"))
117 {
118 if (size)
119 {
120 char* buf = new char[size];
121 _file.read(buf, size);
122 char* p = buf;
123 while (p < buf + size)
124 {
125 fixnamen(p, strlen(p));
126 char* s = GetPlainName(p);
127 fixname2(s, strlen(s));
128
129 ModelInstanceNames.emplace_back(s);
130
131 string path(p);
132 ExtractSingleModel(path);
133
134 p = p + strlen(p) + 1;
135 }
136 delete[] buf;
137 }
138 }
139 else if (!strcmp(fourcc, "MWMO"))
140 {
141 if (size)
142 {
143 char* buf = new char[size];
144 _file.read(buf, size);
145 char* p = buf;
146 while (p < buf + size)
147 {
148 std::string path(p);
149
150 char* s = GetPlainName(p);
151 fixnamen(s, strlen(s));
152 fixname2(s, strlen(s));
153 WmoInstanceNames.emplace_back(s);
154
155 ExtractSingleWmo(path);
156
157 p += strlen(p) + 1;
158 }
159 delete[] buf;
160 }
161 }
162 //======================
163 else if (!strcmp(fourcc, "MDDF"))
164 {
165 if (size)
166 {
167 uint32 doodadCount = size / sizeof(ADT::MDDF);
168 for (uint32 i = 0; i < doodadCount; ++i)
169 {
170 ADT::MDDF doodadDef;
171 _file.read(&doodadDef, sizeof(ADT::MDDF));
172 Doodad::Extract(doodadDef, ModelInstanceNames[doodadDef.Id].c_str(), map_num, tileX, tileY, dirfile);
173 }
174 }
175 }
176 else if (!strcmp(fourcc, "MODF"))
177 {
178 if (size)
179 {
180 uint32 mapObjectCount = size / sizeof(ADT::MODF);
181 for (uint32 i = 0; i < mapObjectCount; ++i)
182 {
183 ADT::MODF mapObjDef;
184 _file.read(&mapObjDef, sizeof(ADT::MODF));
185 MapObject::Extract(mapObjDef, WmoInstanceNames[mapObjDef.Id].c_str(), map_num, tileX, tileY, dirfile);
186 Doodad::ExtractSet(WmoDoodads[WmoInstanceNames[mapObjDef.Id]], mapObjDef, map_num, tileX, tileY, dirfile);
187 }
188 }
189 }
190 //======================
191 _file.seek(nextpos);
192 }
193 _file.close();
194 fclose(dirfile);
195 return true;
196}
std::uint32_t uint32
Definition: Define.h:108
const char * GetPlainName(const char *FileName)
Definition: adtfile.cpp:27
void fixnamen(char *name, size_t len)
Definition: adtfile.cpp:45
void fixname2(char *name, size_t len)
Definition: adtfile.cpp:63
bool ExtractSingleModel(std::string &fname)
Definition: gameobject_extract.cpp:25
std::unordered_map< std::string, WMODoodadData > WmoDoodads
Definition: vmapexport.cpp:64
char const * szWorkDirWmo
Definition: vmapexport.cpp:68
bool ExtractSingleWmo(std::string &fname)
Definition: vmapexport.cpp:98
void Extract(ADT::MDDF const &doodadDef, char const *ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
Definition: model.cpp:138
void ExtractSet(WMODoodadData const &doodadData, ADT::MODF const &wmo, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
Definition: model.cpp:181
void Extract(ADT::MODF const &mapObjDef, char const *WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
Definition: wmo.cpp:510
size_t read(void *dest, size_t bytes)
Definition: mpq_libmpq.cpp:96
bool isEof()
Definition: mpq_libmpq04.h:93
size_t getPos()
Definition: mpq_libmpq04.h:90
void seek(int offset)
Definition: mpq_libmpq.cpp:114
Definition: adtfile.h:29
uint32 Id
Definition: adtfile.h:30
Definition: adtfile.h:39
uint32 Id
Definition: adtfile.h:40
std::vector< std::string > ModelInstanceNames
Definition: adtfile.h:62
std::vector< std::string > WmoInstanceNames
Definition: adtfile.h:61
void flipcc(char *fcc)
Definition: mpq_libmpq04.h:99

References _file, MPQFile::close(), Doodad::Extract(), MapObject::Extract(), Doodad::ExtractSet(), ExtractSingleModel(), ExtractSingleWmo(), fixname2(), fixnamen(), flipcc(), GetPlainName(), MPQFile::getPos(), ADT::MDDF::Id, ADT::MODF::Id, MPQFile::isEof(), ModelInstanceNames, MPQFile::read(), MPQFile::seek(), szWorkDirWmo, WmoDoodads, and WmoInstanceNames.

Member Data Documentation

◆ _file

MPQFile ADTFile::_file
private

Referenced by init(), and ~ADTFile().

◆ Adtfilename

std::string ADTFile::Adtfilename
private

Referenced by ADTFile().

◆ ModelInstanceNames

std::vector<std::string> ADTFile::ModelInstanceNames

Referenced by init().

◆ WmoInstanceNames

std::vector<std::string> ADTFile::WmoInstanceNames

Referenced by init().