Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
wdtfile.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 "vmapexport.h"
7#include "wdtfile.h"
8#include "adtfile.h"
9#include <cstdio>
10
11char * wdtGetPlainName(char * FileName)
12{
13 char * szTemp;
14
15 if((szTemp = strrchr(FileName, '\\')) != NULL)
16 FileName = szTemp + 1;
17 return FileName;
18}
19
20extern HANDLE WorldMpq;
21
22WDTFile::WDTFile(char* file_name, char* file_name1):WDT(WorldMpq, file_name), gnWMO(0)
23{
24 filename.append(file_name1,strlen(file_name1));
25}
26
27bool WDTFile::init(char* /*map_id*/, unsigned int mapID)
28{
29 if (WDT.isEof())
30 {
31 //printf("Can't find WDT file.\n");
32 return false;
33 }
34
35 char fourcc[5];
36 uint32 size;
37
38 std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
39 FILE *dirfile;
40 dirfile = fopen(dirname.c_str(), "ab");
41 if(!dirfile)
42 {
43 printf("Can't open dirfile!'%s'\n", dirname.c_str());
44 return false;
45 }
46
47 while (!WDT.isEof())
48 {
49 WDT.read(fourcc,4);
50 WDT.read(&size, 4);
51
52 flipcc(fourcc);
53 fourcc[4] = 0;
54
55 size_t nextpos = WDT.getPos() + size;
56
57 if (!strcmp(fourcc,"MAIN"))
58 {
59 }
60 if (!strcmp(fourcc,"MWMO"))
61 {
62 // global map objects
63 if (size)
64 {
65 char *buf = new char[size];
66 WDT.read(buf, size);
67 char *p = buf;
68 while (p < buf + size)
69 {
70 char* s=wdtGetPlainName(p);
71 FixNameCase(s,strlen(s));
72 p=p+strlen(p)+1;
73 gWmoInstansName.push_back(s);
74 }
75 delete[] buf;
76 }
77 }
78 else if (!strcmp(fourcc, "MODF"))
79 {
80 // global wmo instance data
81 if (size)
82 {
83 gnWMO = (int)size / 64;
84
85 for (int i = 0; i < gnWMO; ++i)
86 {
87 int id;
88 WDT.read(&id, 4);
89 WMOInstance inst(WDT,gWmoInstansName[id].c_str(), mapID, 65, 65, dirfile);
90 }
91 }
92 }
93 WDT.seek((int)nextpos);
94 }
95
96 WDT.close();
97 fclose(dirfile);
98 return true;
99}
100
102{
103 WDT.close();
104}
105
107{
108 if(!(x>=0 && z >= 0 && x<64 && z<64))
109 return NULL;
110
111 char name[512];
112
113 snprintf(name, sizeof(name), "World\\Maps\\%s\\%s_%d_%d_obj0.adt", filename.c_str(), filename.c_str(), x, z);
114 return new ADTFile(name);
115}
std::uint32_t uint32
Definition Define.h:77
HANDLE WorldMpq
Definition System.cpp:49
void FixNameCase(char *name, size_t len)
Definition adtfile.cpp:34
std::vector< std::string > gWmoInstansName
Definition wdtfile.h:27
WDTFile(char *file_name, char *file_name1)
Definition wdtfile.cpp:22
~WDTFile(void)
Definition wdtfile.cpp:101
int gnWMO
Definition wdtfile.h:28
bool init(char *map_id, unsigned int mapID)
Definition wdtfile.cpp:27
ADTFile * GetMap(int x, int z)
Definition wdtfile.cpp:106
std::string filename
Definition wdtfile.h:21
MPQFile WDT
Definition wdtfile.h:20
void flipcc(char *fcc)
Definition mpqfile.h:75
const char * szWorkDirWmo
char * wdtGetPlainName(char *FileName)
Definition wdtfile.cpp:11