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)
79 : _file(filename)
80{
81 Adtfilename.append(filename);
82}
std::string Adtfilename
Definition: adtfile.h:57
MPQFile _file
Definition: adtfile.h:56

References Adtfilename.

◆ ~ADTFile()

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

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