1 #define _CRT_SECURE_NO_DEPRECATE
14 #include "mpq_libmpq.h"
16 extern unsigned int iRes
;
17 extern ArchiveSet gOpenArchives
;
19 bool ConvertADT(char*,char*);
26 typedef unsigned char uint8
;
27 typedef unsigned short uint16
;
28 typedef unsigned int uint32
;
32 char output_path
[128]=".";
33 char input_path
[128]=".";
40 int extract
= EXTRACT_MAP
| EXTRACT_DBC
;
42 static char* const langs
[]={"deDE", "enGB", "enUS", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
47 void CreateDir( const std::string
& Path
)
50 _mkdir( Path
.c_str());
52 mkdir( Path
.c_str(), 0777 );
56 bool FileExists( const char* FileName
)
58 if( FILE* fp
= fopen( FileName
, "rb" ) )
69 printf("Usage:\n%s -[var] [value]\n-i set input path\n-o set output path\n-r set resolution\n-e extract only MAP(1)/DBC(2) - standard: both(3)\nExample: %s -r 256 -i \"c:\\games\\game\"",
74 void HandleArgs(int argc
, char * arg
[])
76 for(int c
=1;c
<argc
;c
++)
80 //r - resolution, array of (r * r) heights will be created
81 //e - extract only MAP(1)/DBC(2) - standard both(3)
89 strcpy(input_path
,arg
[(c
++) +1]);
95 strcpy(output_path
,arg
[(c
++) +1]);
101 iRes
=atoi(arg
[(c
++) +1]);
108 extract
=atoi(arg
[(c
++) +1]);
109 if(!(extract
> 0 && extract
< 4))
121 printf("Read Map.dbc file... ");
122 DBCFile
dbc("DBFilesClient\\Map.dbc");
125 uint32 map_count
=dbc
.getRecordCount();
126 map_ids
=new map_id
[map_count
];
127 for(unsigned int x
=0;x
<map_count
;x
++)
129 map_ids
[x
].id
=dbc
.getRecord(x
).getUInt(0);
130 strcpy(map_ids
[x
].name
,dbc
.getRecord(x
).getString(1));
132 printf("Done! (%u maps loaded)\n", map_count
);
136 void ReadAreaTableDBC()
138 printf("Read AreaTable.dbc file... ");
139 DBCFile
dbc("DBFilesClient\\AreaTable.dbc");
142 unsigned int area_count
=dbc
.getRecordCount();
143 uint32 maxid
= dbc
.getMaxId();
144 areas
=new uint16
[maxid
+ 1];
145 memset(areas
, 0xff, sizeof(areas
));
146 for(unsigned int x
=0; x
<area_count
;++x
)
147 areas
[dbc
.getRecord(x
).getUInt(0)] = dbc
.getRecord(x
).getUInt(3);
149 printf("Done! (%u areas loaded)\n", area_count
);
152 void ExtractMapsFromMpq()
154 char mpq_filename
[1024];
155 char output_filename
[1024];
157 printf("Extracting maps...\n");
159 uint32 map_count
= ReadMapDBC();
163 unsigned int total
=map_count
*ADT_RES
*ADT_RES
;
166 std::string path
= output_path
;
170 for(int x
= 0; x
< ADT_RES
; ++x
)
172 for(int y
= 0; y
< ADT_RES
; ++y
)
174 for(int z
= 0; z
< map_count
; ++z
)
176 sprintf(mpq_filename
,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids
[z
].name
,map_ids
[z
].name
,x
,y
);
177 sprintf(output_filename
,"%s/maps/%03u%02u%02u.map",output_path
,map_ids
[z
].id
,y
,x
);
178 ConvertADT(mpq_filename
,output_filename
);
182 printf("Processing........................%d%%\r",(100*done
)/total
);
190 //bool WMO(char* filename);
192 void ExtractDBCFiles()
194 printf("Extracting dbc files...\n");
196 set
<string
> dbcfiles
;
199 for(ArchiveSet::iterator i
= gOpenArchives
.begin(); i
!= gOpenArchives
.end();++i
)
201 vector
<string
> files
= (*i
)->GetFileList();
202 for (vector
<string
>::iterator iter
= files
.begin(); iter
!= files
.end(); ++iter
)
203 if (iter
->rfind(".dbc") == iter
->length() - strlen(".dbc"))
204 dbcfiles
.insert(*iter
);
207 std::string path
= output_path
;
213 for (set
<string
>::iterator iter
= dbcfiles
.begin(); iter
!= dbcfiles
.end(); ++iter
)
215 string filename
= output_path
;
217 filename
+= (iter
->c_str() + strlen("DBFilesClient\\"));
219 //cout << filename << endl;
221 FILE *output
=fopen(filename
.c_str(),"wb");
224 printf("Can't create the output file '%s'\n",filename
.c_str());
227 MPQFile
m(iter
->c_str());
229 fwrite(m
.getPointer(),1,m
.getSize(),output
);
234 printf("Extracted %u DBC files\n", count
);
239 for (int i
= 0; i
< LANG_COUNT
; i
++)
242 sprintf(tmp1
, "%s/Data/%s/locale-%s.MPQ", input_path
, langs
[i
], langs
[i
]);
243 if (FileExists(tmp1
))
245 printf("Detected locale: %s\n", langs
[i
]);
250 printf("Could not detect locale.\n");
254 void LoadMPQFiles(int const locale
)
258 sprintf(filename
,"%s/Data/%s/locale-%s.MPQ",input_path
,langs
[locale
],langs
[locale
]);
259 new MPQArchive(filename
);
261 for(int i
= 1; i
< 5; ++i
)
265 sprintf(ext
, "-%i", i
);
267 sprintf(filename
,"%s/Data/%s/patch-%s%s.MPQ",input_path
,langs
[locale
],langs
[locale
],ext
);
268 if(!FileExists(filename
))
270 new MPQArchive(filename
);
273 //need those files only if extract maps
274 if(extract
& EXTRACT_MAP
)
276 sprintf(filename
,"%s/Data/common.MPQ",input_path
);
277 new MPQArchive(filename
);
278 sprintf(filename
,"%s/Data/expansion.MPQ",input_path
);
279 new MPQArchive(filename
);
281 for(int i
= 1; i
< 5; ++i
)
285 sprintf(ext
, "-%i", i
);
287 sprintf(filename
,"%s/Data/patch%s.MPQ",input_path
,ext
);
288 if(!FileExists(filename
))
290 new MPQArchive(filename
);
295 int main(int argc
, char * arg
[])
297 printf("Map & DBC Extractor\n");
298 printf("===================\n");
300 HandleArgs(argc
, arg
);
302 int const locale
= GetLocale();
306 LoadMPQFiles(locale
);
308 if(extract
& EXTRACT_DBC
)
311 if(extract
& EXTRACT_MAP
)
312 ExtractMapsFromMpq();
315 for(ArchiveSet::iterator i
= gOpenArchives
.begin(); i
!= gOpenArchives
.end();++i
)
317 gOpenArchives
.clear();