diff options
author | KingPin <none@none> | 2008-11-06 08:20:26 -0600 |
---|---|---|
committer | KingPin <none@none> | 2008-11-06 08:20:26 -0600 |
commit | 5746d0e98d8a5c4af96102835d501c47ed370def (patch) | |
tree | a17851f0bc08626df74b690df53f28754e9e89fe /contrib/extractor/System.cpp | |
parent | c74f9b4a685a899091dc7cb1b5db5c494ed12b9a (diff) |
[svn] * Avoid access to bag item prototype for getting bag size, use related item
update field instead as more fast source. source mangos.
* Further reduce of DB access in guild handlers.
* Multi-locale DBC extracting - source Foks
*** Devs not responsible if all your player items drop to the ground and get eaten by ants or rabbits.. or some kind of wierd ant-rabbits..
--HG--
branch : trunk
Diffstat (limited to 'contrib/extractor/System.cpp')
-rw-r--r-- | contrib/extractor/System.cpp | 154 |
1 files changed, 90 insertions, 64 deletions
diff --git a/contrib/extractor/System.cpp b/contrib/extractor/System.cpp index 090fc557ed7..b7ece7e766e 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<string> files = (*i)->GetFileList(); + vector<string> files; + (*i)->GetFileListTo(files); for (vector<string>::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<string>::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); -} - -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; + printf("Extracted %u DBC files\n\n", count); } -void LoadMPQFiles(int const locale) +void LoadLocaleMPQFiles(int const locale) { char filename[512]; @@ -265,56 +252,95 @@ 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); + if(FileExists(filename)) + new MPQArchive(filename); } +} + +void LoadCommonMPQFiles() +{ + char filename[512]; - //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) { - 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; - new MPQArchive(filename); - } + 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"); + printf("===================\n\n"); HandleArgs(argc, arg); - int const locale = GetLocale(); - if(locale < 0) - return 1; - - LoadMPQFiles(locale); + 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; + } - if(extract & EXTRACT_DBC) - ExtractDBCFiles(); + //Extract DBC files + if(FirstLocale<0) + { + ExtractDBCFiles(i, true); + FirstLocale = i; + } + else + ExtractDBCFiles(i, false); + + //Close MPQs + CloseMPQFiles(); + } + } - if(extract & EXTRACT_MAP) + 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; } |