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
[]={"enGB", "enUS", "deDE", "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(unsigned int x
= 0; x
< ADT_RES
; ++x
)
172 for(unsigned int y
= 0; y
< ADT_RES
; ++y
)
174 for(unsigned 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(int locale
, bool basicLocale
)
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
;
202 (*i
)->GetFileListTo(files
);
203 for (vector
<string
>::iterator iter
= files
.begin(); iter
!= files
.end(); ++iter
)
204 if (iter
->rfind(".dbc") == iter
->length() - strlen(".dbc"))
205 dbcfiles
.insert(*iter
);
208 string path
= output_path
;
213 path
+= langs
[locale
];
220 for (set
<string
>::iterator iter
= dbcfiles
.begin(); iter
!= dbcfiles
.end(); ++iter
)
222 string filename
= path
;
223 filename
+= (iter
->c_str() + strlen("DBFilesClient\\"));
225 FILE *output
=fopen(filename
.c_str(),"wb");
228 printf("Can't create the output file '%s'\n",filename
.c_str());
231 MPQFile
m(iter
->c_str());
233 fwrite(m
.getPointer(),1,m
.getSize(),output
);
238 printf("Extracted %u DBC files\n\n", count
);
241 void LoadLocaleMPQFiles(int const locale
)
245 sprintf(filename
,"%s/Data/%s/locale-%s.MPQ",input_path
,langs
[locale
],langs
[locale
]);
246 new MPQArchive(filename
);
248 for(int i
= 1; i
< 5; ++i
)
252 sprintf(ext
, "-%i", i
);
254 sprintf(filename
,"%s/Data/%s/patch-%s%s.MPQ",input_path
,langs
[locale
],langs
[locale
],ext
);
255 if(FileExists(filename
))
256 new MPQArchive(filename
);
260 void LoadCommonMPQFiles()
264 sprintf(filename
,"%s/Data/common-2.MPQ",input_path
);
265 new MPQArchive(filename
);
266 sprintf(filename
,"%s/Data/lichking.MPQ",input_path
);
267 new MPQArchive(filename
);
268 sprintf(filename
,"%s/Data/expansion.MPQ",input_path
);
269 new MPQArchive(filename
);
271 for(int i
= 1; i
< 5; ++i
)
275 sprintf(ext
, "-%i", i
);
277 sprintf(filename
,"%s/Data/patch%s.MPQ",input_path
,ext
);
278 if(FileExists(filename
))
279 new MPQArchive(filename
);
283 inline void CloseMPQFiles()
285 for(ArchiveSet::iterator j
= gOpenArchives
.begin(); j
!= gOpenArchives
.end();++j
) (*j
)->close();
286 gOpenArchives
.clear();
289 int main(int argc
, char * arg
[])
291 printf("Map & DBC Extractor\n");
292 printf("===================\n\n");
294 HandleArgs(argc
, arg
);
296 int FirstLocale
= -1;
298 for (int i
= 0; i
< LANG_COUNT
; i
++)
301 sprintf(tmp1
, "%s/Data/%s/locale-%s.MPQ", input_path
, langs
[i
], langs
[i
]);
302 if (FileExists(tmp1
))
304 printf("Detected locale: %s\n", langs
[i
]);
307 LoadLocaleMPQFiles(i
);
309 if((extract
& EXTRACT_DBC
) == 0)
318 ExtractDBCFiles(i
, true);
322 ExtractDBCFiles(i
, false);
331 printf("No locales detected\n");
335 if (extract
& EXTRACT_MAP
)
337 printf("Using locale: %s\n", langs
[FirstLocale
]);
340 LoadLocaleMPQFiles(FirstLocale
);
341 LoadCommonMPQFiles();
344 ExtractMapsFromMpq();