[8423] Fixed typo in mangos.sql.
[getmangos.git] / contrib / vmap_extractor_v2 / vmapextract / wdtfile.cpp
blob697f9b33b5b2fb71c50f94cd6a8777f7b4f29213
1 #define __STORMLIB_SELF__
3 #include "wdtfile.h"
4 #include "adtfile.h"
6 char * wdtGetPlainName(char * FileName)
8 char * szTemp;
10 if((szTemp = strrchr(FileName, '\\')) != NULL)
11 FileName = szTemp + 1;
12 return FileName;
15 WDTFile::WDTFile(char* file_name, char* file_name1):WDT(file_name)
17 filename.append(file_name1,strlen(file_name1));
20 bool WDTFile::init(char *map_id)
22 if (WDT.isEof())
24 //printf("Can't find WDT file.\n");
25 return false;
28 char fourcc[5];
29 size_t size;
31 const char dirname[] = "buildings\\dir";
32 FILE *dirfile;
33 dirfile = fopen(dirname, "ab");
34 if(!dirfile)
36 printf("Can't open dirfile!'%s'\n");
37 return false;
40 while (!WDT.isEof())
42 WDT.read(fourcc,4);
43 WDT.read(&size, 4);
45 flipcc(fourcc);
46 fourcc[4] = 0;
48 size_t nextpos = WDT.getPos() + size;
50 if (!strcmp(fourcc,"MAIN"))
53 if (!strcmp(fourcc,"MWMO"))
55 // global map objects
56 if (size)
58 char *buf = new char[size];
59 WDT.read(buf, size);
60 char *p=buf;
61 int q = 0;
62 gWmoInstansName = new string[size];
63 while (p<buf+size)
65 string path(p);
66 char* s=wdtGetPlainName(p);
67 fixnamen(s,strlen(s));
68 p=p+strlen(p)+1;
69 gWmoInstansName[q++] = s;
71 delete[] buf;
74 else if (!strcmp(fourcc,"MODF"))
76 // global wmo instance data
77 if (size)
79 gnWMO = (int)size / 64;
80 string gWMO_mapname;
81 string fake_mapname;
82 fake_mapname = "65 65 ";
83 //gWMO_mapname = fake_mapname + filename;
84 gWMO_mapname = fake_mapname + std::string(map_id);
85 for (int i=0; i<gnWMO; ++i)
87 int id;
88 WDT.read(&id, 4);
89 WMOInstance inst(WDT,gWmoInstansName[id].c_str(),gWMO_mapname.c_str(), dirfile);
91 delete[] gWmoInstansName;
94 WDT.seek((int)nextpos);
97 WDT.close();
98 fclose(dirfile);
99 return true;
102 WDTFile::~WDTFile(void)
104 WDT.close();
107 ADTFile* WDTFile::GetMap(int x, int z)
109 if(!(x>=0 && z >= 0 && x<64 && z<64))
110 return NULL;
112 char name[512];
114 sprintf(name,"World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z);
115 return new ADTFile(name);