TrinityCore
Loading...
Searching...
No Matches
wdtfile.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "vmapexport.h"
19#include "wdtfile.h"
20#include "adtfile.h"
21
22#include "StringFormat.h"
23#include <cstdio>
24
25char * wdtGetPlainName(char * FileName)
26{
27 char * szTemp;
28
29 if((szTemp = strrchr(FileName, '\\')) != nullptr)
30 FileName = szTemp + 1;
31 return FileName;
32}
33
34WDTFile::WDTFile(char const* file_name, char const* file_name1) : _file(file_name)
35{
36 filename.append(file_name1, strlen(file_name1));
37}
38
40{
41 if (_file.isEof())
42 {
43 //printf("Can't find WDT file.\n");
44 return false;
45 }
46
47 char fourcc[5];
48 uint32 size;
49
50 std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
51 FILE *dirfile;
52 dirfile = fopen(dirname.c_str(), "ab");
53 if(!dirfile)
54 {
55 printf("Can't open dirfile!'%s'\n", dirname.c_str());
56 return false;
57 }
58
59 while (!_file.isEof())
60 {
61 _file.read(fourcc,4);
62 _file.read(&size, 4);
63
64 flipcc(fourcc);
65 fourcc[4] = 0;
66
67 size_t nextpos = _file.getPos() + size;
68
69 if (!strcmp(fourcc,"MAIN"))
70 {
71 }
72 if (!strcmp(fourcc,"MWMO"))
73 {
74 // global map objects
75 if (size)
76 {
77 char *buf = new char[size];
78 _file.read(buf, size);
79 char *p = buf;
80 while (p < buf + size)
81 {
82 std::string path(p);
83
84 char* s = wdtGetPlainName(p);
85 FixNameCase(s, strlen(s));
86 FixNameSpaces(s, strlen(s));
87 p = p + strlen(p) + 1;
88 _wmoNames.push_back(s);
89
90 ExtractSingleWmo(path);
91 }
92 delete[] buf;
93 }
94 }
95 else if (!strcmp(fourcc, "MODF"))
96 {
97 // global wmo instance data
98 if (size)
99 {
100 uint32 mapObjectCount = size / sizeof(ADT::MODF);
101 for (uint32 i = 0; i < mapObjectCount; ++i)
102 {
103 ADT::MODF mapObjDef;
104 _file.read(&mapObjDef, sizeof(ADT::MODF));
105 MapObject::Extract(mapObjDef, _wmoNames[mapObjDef.Id].c_str(), mapId, 65, 65, dirfile);
106 Doodad::ExtractSet(WmoDoodads[_wmoNames[mapObjDef.Id]], mapObjDef, mapId, 65, 65, dirfile);
107 }
108 }
109 }
110 _file.seek((int)nextpos);
111 }
112
113 _file.close();
114 fclose(dirfile);
115 return true;
116}
117
119{
120 _file.close();
121}
122
124{
125 if(!(x>=0 && z >= 0 && x<64 && z<64))
126 return nullptr;
127
128 return new ADTFile(Trinity::StringFormat("World\\Maps\\{}\\{}_{}_{}.adt", filename, filename, x, z).c_str());
129}
uint32_t uint32
Definition Define.h:133
void FixNameCase(char *name, size_t len)
Definition adtfile.cpp:43
void FixNameSpaces(char *name, size_t len)
Definition adtfile.cpp:60
size_t read(void *dest, size_t bytes)
bool isEof()
Definition mpq_libmpq.h:91
void close()
size_t getPos()
Definition mpq_libmpq.h:88
void seek(int offset)
~WDTFile(void)
Definition wdtfile.cpp:118
WDTFile(char const *file_name, char const *file_name1)
Definition wdtfile.cpp:34
MPQFile _file
Definition wdtfile.h:38
std::vector< std::string > _wmoNames
Definition wdtfile.h:35
bool init(uint32 mapId)
Definition wdtfile.cpp:39
ADTFile * GetMap(int x, int z)
Definition wdtfile.cpp:123
std::string filename
Definition wdtfile.h:39
void flipcc(char *fcc)
Definition mpq_libmpq.h:97
void ExtractSet(WMODoodadData const &doodadData, ADT::MODF const &wmo, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
Definition model.cpp:184
void Extract(ADT::MODF const &mapObjDef, char const *WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
uint32 Id
Definition adtfile.h:40
std::unordered_map< std::string, WMODoodadData > WmoDoodads
char const * szWorkDirWmo
bool ExtractSingleWmo(std::string &fname)
char * wdtGetPlainName(char *FileName)
Definition wdtfile.cpp:25