diff --git a/contrib/extractor/System.cpp b/contrib/extractor/System.cpp index 090fc557e..39bf1d5b1 100644 --- a/contrib/extractor/System.cpp +++ b/contrib/extractor/System.cpp @@ -39,7 +39,7 @@ enum Extract }; int extract = EXTRACT_MAP | EXTRACT_DBC; -static char* const langs[]={"deDE", "enGB", "enUS", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; +static char* const langs[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; #define LANG_COUNT 12 #define ADT_RES 64 @@ -167,11 +167,11 @@ void ExtractMapsFromMpq() path += "/maps/"; CreateDir(path); - for(int x = 0; x < ADT_RES; ++x) + for(unsigned int x = 0; x < ADT_RES; ++x) { - for(int y = 0; y < ADT_RES; ++y) + for(unsigned int y = 0; y < ADT_RES; ++y) { - for(int z = 0; z < map_count; ++z) + for(unsigned int z = 0; z < map_count; ++z) { sprintf(mpq_filename,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids[z].name,map_ids[z].name,x,y); sprintf(output_filename,"%s/maps/%03u%02u%02u.map",output_path,map_ids[z].id,y,x); @@ -189,7 +189,7 @@ void ExtractMapsFromMpq() //bool WMO(char* filename); -void ExtractDBCFiles() +void ExtractDBCFiles(int locale, bool basicLocale) { printf("Extracting dbc files...\n"); @@ -198,26 +198,30 @@ void ExtractDBCFiles() // get DBC file list for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) { - vector files = (*i)->GetFileList(); + 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); } - std::string path = output_path; + 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 = output_path; - filename += "/dbc/"; + string filename = path; filename += (iter->c_str() + strlen("DBFilesClient\\")); - //cout << filename << endl; - FILE *output=fopen(filename.c_str(),"wb"); if(!output) { @@ -231,27 +235,10 @@ void ExtractDBCFiles() fclose(output); ++count; } - printf("Extracted %u DBC files\n", count); + printf("Extracted %u DBC files\n\n", count); } -int GetLocale() -{ - 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]); - return i; - } - } - - printf("Could not detect locale.\n"); - return -1; -} - -void LoadMPQFiles(int const locale) +void LoadLocaleMPQFiles(int const locale) { char filename[512]; @@ -265,56 +252,98 @@ void LoadMPQFiles(int const locale) sprintf(ext, "-%i", i); sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext); - if(!FileExists(filename)) - break; - new MPQArchive(filename); - } - - //need those files only if extract maps - if(extract & EXTRACT_MAP) - { - 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); - - sprintf(filename,"%s/Data/patch%s.MPQ",input_path,ext); - if(!FileExists(filename)) - break; + 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); + + sprintf(filename,"%s/Data/patch%s.MPQ",input_path,ext); + 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"); + printf("===================\n\n"); HandleArgs(argc, arg); - int const locale = GetLocale(); - if(locale < 0) - return 1; + int FirstLocale = -1; - LoadMPQFiles(locale); + 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]); - if(extract & EXTRACT_DBC) - ExtractDBCFiles(); + //Open MPQs + LoadLocaleMPQFiles(i); - if(extract & EXTRACT_MAP) + 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 - for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) - (*i)->close(); - gOpenArchives.clear(); + // Close MPQs + CloseMPQFiles(); + } return 0; } diff --git a/contrib/extractor/ad.exe b/contrib/extractor/ad.exe index e9606e8e0..1f2c45dfc 100755 Binary files a/contrib/extractor/ad.exe and b/contrib/extractor/ad.exe differ diff --git a/contrib/extractor/libmpq/mpq.cpp b/contrib/extractor/libmpq/mpq.cpp index 9582b72b5..c6a5d7d7b 100644 --- a/contrib/extractor/libmpq/mpq.cpp +++ b/contrib/extractor/libmpq/mpq.cpp @@ -199,7 +199,7 @@ int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype) { /* * This function returns some useful file information. */ -int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number) { +int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const unsigned int number) { int blockindex = number; //-1; int i = 0; mpq_block *mpq_b = NULL; diff --git a/contrib/extractor/libmpq/mpq.h b/contrib/extractor/libmpq/mpq.h index 0a136f95f..55b72ad75 100644 --- a/contrib/extractor/libmpq/mpq.h +++ b/contrib/extractor/libmpq/mpq.h @@ -198,7 +198,7 @@ extern int libmpq_archive_open(mpq_archive *mpq_a, unsigned char *mpq_filename); extern int libmpq_archive_close(mpq_archive *mpq_a); extern int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype); //extern int libmpq_file_extract(mpq_archive *mpq_a, const int number); -extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number); +extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const unsigned int number); extern char *libmpq_file_name(mpq_archive *mpq_a, const int number); extern int libmpq_file_number(mpq_archive *mpq_a, const char *name); extern int libmpq_file_check(mpq_archive *mpq_a, void *file, int type); diff --git a/contrib/extractor/libmpq/parser.cpp b/contrib/extractor/libmpq/parser.cpp index b7a70400f..435395b87 100644 --- a/contrib/extractor/libmpq/parser.cpp +++ b/contrib/extractor/libmpq/parser.cpp @@ -79,7 +79,7 @@ int libmpq_conf_parse_line(char *line, char *search_value, char *return_value, i } /* now search for comment in this line */ - for (i = 0; i < strlen(line); i++) { + for (i = 0; i < int(strlen(line)); i++) { if (line[i] == '#') { pos = i - 1; break; diff --git a/contrib/extractor/mpq_libmpq.cpp b/contrib/extractor/mpq_libmpq.cpp index 98d114c57..41253b242 100644 --- a/contrib/extractor/mpq_libmpq.cpp +++ b/contrib/extractor/mpq_libmpq.cpp @@ -71,7 +71,7 @@ MPQFile::MPQFile(const char* filename): continue; //file not found } - int fileno = blockindex; + uint32 fileno = blockindex; //int fileno = libmpq_file_number(&mpq_a, filename); //if(fileno == LIBMPQ_EFILE_NOT_FOUND) diff --git a/contrib/extractor/mpq_libmpq.h b/contrib/extractor/mpq_libmpq.h index 542e7b21d..9b4984a50 100644 --- a/contrib/extractor/mpq_libmpq.h +++ b/contrib/extractor/mpq_libmpq.h @@ -51,14 +51,12 @@ public: return nullhash; } - vector GetFileList() { - vector filelist; - + void GetFileListTo(vector& filelist) { mpq_hash hash = GetHashEntry("(listfile)"); uint32 blockindex = hash.blockindex; if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) - return filelist; + return; uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex); char *buffer = new char[size]; @@ -79,8 +77,7 @@ public: token = strtok(NULL, seps); } - delete buffer; - return filelist; + delete[] buffer; } }; typedef std::deque ArchiveSet;