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

#include "wdtfile.h"

Public Member Functions

 WDTFile (char *file_name, char *file_name1)
 
 ~WDTFile (void)
 
bool init (uint32 mapId)
 
ADTFileGetMap (int x, int z)
 

Public Attributes

std::vector< std::string > _wmoNames
 

Private Attributes

MPQFile _file
 
std::string filename
 

Detailed Description

Constructor & Destructor Documentation

◆ WDTFile()

WDTFile::WDTFile ( char *  file_name,
char *  file_name1 
)
33 : _file(file_name)
34{
35 filename.append(file_name1, strlen(file_name1));
36}
MPQFile _file
Definition: wdtfile.h:40
std::string filename
Definition: wdtfile.h:41

References filename.

◆ ~WDTFile()

WDTFile::~WDTFile ( void  )
118{
119 _file.close();
120}
void close()
Definition: mpq_libmpq.cpp:126

References _file, and MPQFile::close().

Member Function Documentation

◆ GetMap()

ADTFile * WDTFile::GetMap ( int  x,
int  z 
)
123{
124 if (!(x >= 0 && z >= 0 && x < 64 && z < 64))
125 return nullptr;
126
127 char name[512];
128
129 snprintf(name, sizeof(name), R"(World\Maps\%s\%s_%d_%d.adt)", filename.c_str(), filename.c_str(), x, z);
130 return new ADTFile(name);
131}
Definition: adtfile.h:54

References filename.

Referenced by ParsMapFiles().

◆ init()

bool WDTFile::init ( uint32  mapId)
39{
40 if (_file.isEof())
41 {
42 //printf("Can't find WDT file.\n");
43 return false;
44 }
45
46 char fourcc[5];
47 uint32 size;
48
49 std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
50 FILE* dirfile;
51 dirfile = fopen(dirname.c_str(), "ab");
52 if (!dirfile)
53 {
54 printf("Can't open dirfile!'%s'\n", dirname.c_str());
55 return false;
56 }
57
58 while (!_file.isEof())
59 {
60 _file.read(fourcc, 4);
61 _file.read(&size, 4);
62
63 flipcc(fourcc);
64 fourcc[4] = 0;
65
66 size_t nextpos = _file.getPos() + size;
67
68 if (!strcmp(fourcc, "MAIN"))
69 {
70 }
71 if (!strcmp(fourcc, "MWMO"))
72 {
73 // global map objects
74 if (size)
75 {
76 char* buf = new char[size];
77 _file.read(buf, size);
78 char* p = buf;
79 while (p < buf + size)
80 {
81 std::string path(p);
82
83 char* s = wdtGetPlainName(p);
84 fixnamen(s, strlen(s));
85 fixname2(s, strlen(s));
86 p = p + strlen(p) + 1;
87 _wmoNames.push_back(s);
88
89 ExtractSingleWmo(path);
90 }
91 delete[] buf;
92 }
93 }
94 else if (!strcmp(fourcc, "MODF"))
95 {
96 // global wmo instance data
97 if (size)
98 {
99 uint32 mapObjectCount = size / sizeof(ADT::MODF);
100 for (uint32 i = 0; i < mapObjectCount; ++i)
101 {
102 ADT::MODF mapObjDef;
103 _file.read(&mapObjDef, sizeof(ADT::MODF));
104 MapObject::Extract(mapObjDef, _wmoNames[mapObjDef.Id].c_str(), mapId, 65, 65, dirfile);
105 Doodad::ExtractSet(WmoDoodads[_wmoNames[mapObjDef.Id]], mapObjDef, mapId, 65, 65, dirfile);
106 }
107 }
108 }
109 _file.seek((int)nextpos);
110 }
111
112 _file.close();
113 fclose(dirfile);
114 return true;
115}
std::uint32_t uint32
Definition: Define.h:108
void fixnamen(char *name, size_t len)
Definition: adtfile.cpp:45
void fixname2(char *name, size_t len)
Definition: adtfile.cpp:63
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
char * wdtGetPlainName(char *FileName)
Definition: wdtfile.cpp:24
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:39
uint32 Id
Definition: adtfile.h:40
std::vector< std::string > _wmoNames
Definition: wdtfile.h:37
void flipcc(char *fcc)
Definition: mpq_libmpq04.h:99

References _file, _wmoNames, MPQFile::close(), MapObject::Extract(), Doodad::ExtractSet(), ExtractSingleWmo(), fixname2(), fixnamen(), flipcc(), MPQFile::getPos(), ADT::MODF::Id, MPQFile::isEof(), MPQFile::read(), MPQFile::seek(), szWorkDirWmo, wdtGetPlainName(), and WmoDoodads.

Referenced by ParsMapFiles().

Member Data Documentation

◆ _file

MPQFile WDTFile::_file
private

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

◆ _wmoNames

std::vector<std::string> WDTFile::_wmoNames

Referenced by init().

◆ filename

std::string WDTFile::filename
private

Referenced by GetMap(), and WDTFile().