#define _CRT_SECURE_NO_DEPRECATE #include #include #include #ifdef WIN32 #include "direct.h" #else #include #endif #include "dbcfile.h" #include "mpq_libmpq.h" extern unsigned int iRes; extern ArchiveSet gOpenArchives; bool ConvertADT(char*,char*); typedef struct{ char name[64]; unsigned int id; }map_id; typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; map_id * map_ids; uint16 * areas; char output_path[128]="."; char input_path[128]="."; enum Extract { EXTRACT_MAP = 1, EXTRACT_DBC = 2 }; int extract = EXTRACT_MAP | EXTRACT_DBC; static char* const langs[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; #define LANG_COUNT 12 #define ADT_RES 64 void CreateDir( const std::string& Path ) { #ifdef WIN32 _mkdir( Path.c_str()); #else mkdir( Path.c_str(), 0777 ); #endif } bool FileExists( const char* FileName ) { if( FILE* fp = fopen( FileName, "rb" ) ) { fclose( fp ); return true; } return false; } void Usage(char* prg) { 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\"", prg,prg); exit(1); } void HandleArgs(int argc, char * arg[]) { for(int c=1;c 0 && extract < 4)) Usage(arg[0]); } else Usage(arg[0]); break; } } } uint32 ReadMapDBC() { printf("Read Map.dbc file... "); DBCFile dbc("DBFilesClient\\Map.dbc"); dbc.open(); uint32 map_count=dbc.getRecordCount(); map_ids=new map_id[map_count]; for(unsigned int x=0;x dbcfiles; // get DBC file list for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) { vector files; (*i)->GetFileListTo(files); for (vector::iterator iter = files.begin(); iter != files.end(); ++iter) if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) dbcfiles.insert(*iter); } string path = output_path; path += "/dbc/"; CreateDir(path); if(!basicLocale) { path += langs[locale]; path += "/"; CreateDir(path); } // extract DBCs int count = 0; for (set::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) { string filename = path; filename += (iter->c_str() + strlen("DBFilesClient\\")); FILE *output=fopen(filename.c_str(),"wb"); if(!output) { printf("Can't create the output file '%s'\n",filename.c_str()); continue; } MPQFile m(iter->c_str()); if(!m.isEof()) fwrite(m.getPointer(),1,m.getSize(),output); fclose(output); ++count; } printf("Extracted %u DBC files\n\n", count); } void LoadLocaleMPQFiles(int const locale) { char filename[512]; sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]); new MPQArchive(filename); for(int i = 1; i < 5; ++i) { char ext[3] = ""; if(i > 1) sprintf(ext, "-%i", i); sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext); if(FileExists(filename)) new MPQArchive(filename); } } void LoadCommonMPQFiles() { char filename[512]; sprintf(filename,"%s/Data/common.MPQ",input_path); new MPQArchive(filename); sprintf(filename,"%s/Data/expansion.MPQ",input_path); new MPQArchive(filename); for(int i = 1; i < 5; ++i) { char ext[3] = ""; if(i > 1) sprintf(ext, "-%i", i); if(FileExists(filename)) new MPQArchive(filename); } } inline void CloseMPQFiles() { for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close(); gOpenArchives.clear(); } int main(int argc, char * arg[]) { printf("Map & DBC Extractor\n"); printf("===================\n\n"); HandleArgs(argc, arg); int FirstLocale = -1; for (int i = 0; i < LANG_COUNT; i++) { char tmp1[512]; sprintf(tmp1, "%s/Data/%s/locale-%s.MPQ", input_path, langs[i], langs[i]); if (FileExists(tmp1)) { printf("Detected locale: %s\n", langs[i]); //Open MPQs LoadLocaleMPQFiles(i); if((extract & EXTRACT_DBC) == 0) { FirstLocale=i; break; } //Extract DBC files if(FirstLocale<0) { ExtractDBCFiles(i, true); FirstLocale = i; } else ExtractDBCFiles(i, false); //Close MPQs CloseMPQFiles(); } } if(FirstLocale<0) { printf("No locales detected\n"); return 0; } if (extract & EXTRACT_MAP) { printf("Using locale: %s\n", langs[FirstLocale]); // Open MPQs LoadLocaleMPQFiles(FirstLocale); LoadCommonMPQFiles(); // Extract maps ExtractMapsFromMpq(); // Close MPQs CloseMPQFiles(); } return 0; }