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]=".";
41 int extract
= EXTRACT_MAP
| EXTRACT_DBC
;
43 static char* const langs
[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
48 void CreateDir( const std::string
& Path
)
51 _mkdir( Path
.c_str());
53 mkdir( Path
.c_str(), 0777 );
57 bool FileExists( const char* FileName
)
59 if( FILE* fp
= fopen( FileName
, "rb" ) )
70 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\"",
75 void HandleArgs(int argc
, char * arg
[])
77 for(int c
=1;c
<argc
;c
++)
81 //r - resolution, array of (r * r) heights will be created
82 //e - extract only MAP(1)/DBC(2) - standard both(3)
90 strcpy(input_path
,arg
[(c
++) +1]);
96 strcpy(output_path
,arg
[(c
++) +1]);
102 iRes
=atoi(arg
[(c
++) +1]);
109 extract
=atoi(arg
[(c
++) +1]);
110 if(!(extract
> 0 && extract
< 4))
122 printf("Read Map.dbc file... ");
123 DBCFile
dbc("DBFilesClient\\Map.dbc");
126 uint32 map_count
=dbc
.getRecordCount();
127 map_ids
=new map_id
[map_count
];
128 for(unsigned int x
=0;x
<map_count
;x
++)
130 map_ids
[x
].id
=dbc
.getRecord(x
).getUInt(0);
131 strcpy(map_ids
[x
].name
,dbc
.getRecord(x
).getString(1));
133 printf("Done! (%u maps loaded)\n", map_count
);
137 void ReadAreaTableDBC()
139 printf("Read AreaTable.dbc file... ");
140 DBCFile
dbc("DBFilesClient\\AreaTable.dbc");
143 unsigned int area_count
=dbc
.getRecordCount();
144 uint32 maxid
= dbc
.getMaxId();
145 areas
=new uint16
[maxid
+ 1];
146 memset(areas
, 0xff, sizeof(areas
));
147 for(unsigned int x
=0; x
<area_count
;++x
)
148 areas
[dbc
.getRecord(x
).getUInt(0)] = dbc
.getRecord(x
).getUInt(3);
150 maxAreaId
= dbc
.getMaxId();
152 printf("Done! (%u areas loaded)\n", area_count
);
155 void ExtractMapsFromMpq()
157 char mpq_filename
[1024];
158 char output_filename
[1024];
160 printf("Extracting maps...\n");
162 uint32 map_count
= ReadMapDBC();
166 unsigned int total
=map_count
*ADT_RES
*ADT_RES
;
169 std::string path
= output_path
;
173 for(unsigned int x
= 0; x
< ADT_RES
; ++x
)
175 for(unsigned int y
= 0; y
< ADT_RES
; ++y
)
177 for(unsigned int z
= 0; z
< map_count
; ++z
)
179 sprintf(mpq_filename
,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids
[z
].name
,map_ids
[z
].name
,x
,y
);
180 sprintf(output_filename
,"%s/maps/%03u%02u%02u.map",output_path
,map_ids
[z
].id
,y
,x
);
181 ConvertADT(mpq_filename
,output_filename
);
185 printf("Processing........................%d%%\r",(100*done
)/total
);
193 //bool WMO(char* filename);
195 void ExtractDBCFiles(int locale
, bool basicLocale
)
197 printf("Extracting dbc files...\n");
199 set
<string
> dbcfiles
;
202 for(ArchiveSet::iterator i
= gOpenArchives
.begin(); i
!= gOpenArchives
.end();++i
)
204 vector
<string
> files
;
205 (*i
)->GetFileListTo(files
);
206 for (vector
<string
>::iterator iter
= files
.begin(); iter
!= files
.end(); ++iter
)
207 if (iter
->rfind(".dbc") == iter
->length() - strlen(".dbc"))
208 dbcfiles
.insert(*iter
);
211 string path
= output_path
;
216 path
+= langs
[locale
];
223 for (set
<string
>::iterator iter
= dbcfiles
.begin(); iter
!= dbcfiles
.end(); ++iter
)
225 string filename
= path
;
226 filename
+= (iter
->c_str() + strlen("DBFilesClient\\"));
228 FILE *output
=fopen(filename
.c_str(),"wb");
231 printf("Can't create the output file '%s'\n",filename
.c_str());
234 MPQFile
m(iter
->c_str());
236 fwrite(m
.getPointer(),1,m
.getSize(),output
);
241 printf("Extracted %u DBC files\n\n", count
);
244 void LoadLocaleMPQFiles(int const locale
)
248 sprintf(filename
,"%s/Data/%s/locale-%s.MPQ",input_path
,langs
[locale
],langs
[locale
]);
249 new MPQArchive(filename
);
251 for(int i
= 1; i
< 5; ++i
)
255 sprintf(ext
, "-%i", i
);
257 sprintf(filename
,"%s/Data/%s/patch-%s%s.MPQ",input_path
,langs
[locale
],langs
[locale
],ext
);
258 if(FileExists(filename
))
259 new MPQArchive(filename
);
263 void LoadCommonMPQFiles()
267 sprintf(filename
,"%s/Data/common-2.MPQ",input_path
);
268 new MPQArchive(filename
);
269 sprintf(filename
,"%s/Data/lichking.MPQ",input_path
);
270 new MPQArchive(filename
);
271 sprintf(filename
,"%s/Data/expansion.MPQ",input_path
);
272 new MPQArchive(filename
);
274 for(int i
= 1; i
< 5; ++i
)
278 sprintf(ext
, "-%i", i
);
280 sprintf(filename
,"%s/Data/patch%s.MPQ",input_path
,ext
);
281 if(FileExists(filename
))
282 new MPQArchive(filename
);
286 inline void CloseMPQFiles()
288 for(ArchiveSet::iterator j
= gOpenArchives
.begin(); j
!= gOpenArchives
.end();++j
) (*j
)->close();
289 gOpenArchives
.clear();
292 int main(int argc
, char * arg
[])
294 printf("Map & DBC Extractor\n");
295 printf("===================\n\n");
297 HandleArgs(argc
, arg
);
299 int FirstLocale
= -1;
301 for (int i
= 0; i
< LANG_COUNT
; i
++)
304 sprintf(tmp1
, "%s/Data/%s/locale-%s.MPQ", input_path
, langs
[i
], langs
[i
]);
305 if (FileExists(tmp1
))
307 printf("Detected locale: %s\n", langs
[i
]);
310 LoadLocaleMPQFiles(i
);
312 if((extract
& EXTRACT_DBC
) == 0)
321 ExtractDBCFiles(i
, true);
325 ExtractDBCFiles(i
, false);
334 printf("No locales detected\n");
338 if (extract
& EXTRACT_MAP
)
340 printf("Using locale: %s\n", langs
[FirstLocale
]);
343 LoadLocaleMPQFiles(FirstLocale
);
344 LoadCommonMPQFiles();
347 ExtractMapsFromMpq();