Show
Ignore:
Timestamp:
11/19/08 13:43:30 (17 years ago)
Author:
yumileroy
Message:

[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..

Original author: KingPin?
Date: 2008-11-06 08:20:26-06:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/contrib/extractor/System.cpp

    r2 r177  
    4040int extract = EXTRACT_MAP | EXTRACT_DBC; 
    4141 
    42 static char* const langs[]={"deDE", "enGB", "enUS", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; 
     42static char* const langs[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; 
    4343#define LANG_COUNT 12 
    4444 
     
    168168    CreateDir(path); 
    169169 
    170     for(int x = 0; x < ADT_RES; ++x) 
    171     { 
    172         for(int y = 0; y < ADT_RES; ++y) 
    173         { 
    174             for(int z = 0; z < map_count; ++z) 
     170    for(unsigned int x = 0; x < ADT_RES; ++x) 
     171    { 
     172        for(unsigned int y = 0; y < ADT_RES; ++y) 
     173        { 
     174            for(unsigned int z = 0; z < map_count; ++z) 
    175175            { 
    176176                sprintf(mpq_filename,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids[z].name,map_ids[z].name,x,y); 
     
    190190//bool WMO(char* filename); 
    191191 
    192 void ExtractDBCFiles() 
     192void ExtractDBCFiles(int locale, bool basicLocale) 
    193193{ 
    194194    printf("Extracting dbc files...\n"); 
     
    199199    for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) 
    200200    { 
    201         vector<string> files = (*i)->GetFileList(); 
     201        vector<string> files; 
     202        (*i)->GetFileListTo(files); 
    202203        for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter) 
    203204            if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) 
     
    205206    } 
    206207 
    207     std::string path = output_path; 
     208    string path = output_path; 
    208209    path += "/dbc/"; 
    209210    CreateDir(path); 
     211    if(!basicLocale) 
     212    { 
     213        path += langs[locale]; 
     214        path += "/"; 
     215        CreateDir(path); 
     216    } 
    210217 
    211218    // extract DBCs 
     
    213220    for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) 
    214221    { 
    215         string filename = output_path; 
    216         filename += "/dbc/"; 
     222        string filename = path; 
    217223        filename += (iter->c_str() + strlen("DBFilesClient\\")); 
    218  
    219         //cout << filename << endl; 
    220224 
    221225        FILE *output=fopen(filename.c_str(),"wb"); 
     
    232236        ++count; 
    233237    } 
    234     printf("Extracted %u DBC files\n", count); 
    235 } 
    236  
    237 int GetLocale() 
    238 { 
     238    printf("Extracted %u DBC files\n\n", count); 
     239} 
     240 
     241void LoadLocaleMPQFiles(int const locale) 
     242{ 
     243    char filename[512]; 
     244 
     245    sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]); 
     246    new MPQArchive(filename); 
     247 
     248    for(int i = 1; i < 5; ++i) 
     249    { 
     250        char ext[3] = ""; 
     251        if(i > 1) 
     252            sprintf(ext, "-%i", i); 
     253 
     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); 
     257    } 
     258} 
     259     
     260void LoadCommonMPQFiles() 
     261{ 
     262    char filename[512]; 
     263 
     264    sprintf(filename,"%s/Data/common.MPQ",input_path); 
     265    new MPQArchive(filename); 
     266    sprintf(filename,"%s/Data/expansion.MPQ",input_path); 
     267    new MPQArchive(filename); 
     268    for(int i = 1; i < 5; ++i) 
     269    { 
     270        char ext[3] = ""; 
     271        if(i > 1) 
     272            sprintf(ext, "-%i", i); 
     273            if(FileExists(filename)) 
     274                new MPQArchive(filename); 
     275    } 
     276} 
     277 
     278inline void CloseMPQFiles() 
     279{ 
     280    for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close(); 
     281        gOpenArchives.clear(); 
     282} 
     283 
     284int main(int argc, char * arg[]) 
     285{ 
     286    printf("Map & DBC Extractor\n"); 
     287    printf("===================\n\n"); 
     288 
     289    HandleArgs(argc, arg); 
     290 
     291    int FirstLocale = -1; 
     292     
    239293    for (int i = 0; i < LANG_COUNT; i++) 
    240294    { 
     
    244298        { 
    245299            printf("Detected locale: %s\n", langs[i]); 
    246             return i; 
    247         } 
    248     } 
    249  
    250     printf("Could not detect locale.\n"); 
    251     return -1; 
    252 } 
    253  
    254 void LoadMPQFiles(int const locale) 
    255 { 
    256     char filename[512]; 
    257  
    258     sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]); 
    259     new MPQArchive(filename); 
    260  
    261     for(int i = 1; i < 5; ++i) 
    262     { 
    263         char ext[3] = ""; 
    264         if(i > 1) 
    265             sprintf(ext, "-%i", i); 
    266  
    267         sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext); 
    268         if(!FileExists(filename)) 
    269             break; 
    270         new MPQArchive(filename); 
    271     } 
    272  
    273     //need those files only if extract maps 
    274     if(extract & EXTRACT_MAP) 
    275     { 
    276         sprintf(filename,"%s/Data/common.MPQ",input_path); 
    277         new MPQArchive(filename); 
    278         sprintf(filename,"%s/Data/expansion.MPQ",input_path); 
    279         new MPQArchive(filename); 
    280  
    281         for(int i = 1; i < 5; ++i) 
    282         { 
    283             char ext[3] = ""; 
    284             if(i > 1) 
    285                 sprintf(ext, "-%i", i); 
    286  
    287             sprintf(filename,"%s/Data/patch%s.MPQ",input_path,ext); 
    288             if(!FileExists(filename)) 
    289                 break; 
    290             new MPQArchive(filename); 
    291         } 
    292     } 
    293 } 
    294  
    295 int main(int argc, char * arg[]) 
    296 { 
    297     printf("Map & DBC Extractor\n"); 
    298     printf("===================\n"); 
    299  
    300     HandleArgs(argc, arg); 
    301  
    302     int const locale = GetLocale(); 
    303     if(locale < 0) 
    304         return 1; 
    305  
    306     LoadMPQFiles(locale); 
    307  
    308     if(extract & EXTRACT_DBC) 
    309         ExtractDBCFiles(); 
    310  
    311     if(extract & EXTRACT_MAP) 
     300             
     301            //Open MPQs 
     302            LoadLocaleMPQFiles(i); 
     303             
     304            if((extract & EXTRACT_DBC) == 0) 
     305            { 
     306                FirstLocale=i; 
     307                break; 
     308            } 
     309 
     310        //Extract DBC files 
     311        if(FirstLocale<0) 
     312        { 
     313            ExtractDBCFiles(i, true); 
     314            FirstLocale = i; 
     315        } 
     316        else  
     317            ExtractDBCFiles(i, false); 
     318         
     319            //Close MPQs 
     320            CloseMPQFiles(); 
     321        } 
     322    } 
     323 
     324    if(FirstLocale<0) 
     325    { 
     326        printf("No locales detected\n"); 
     327        return 0; 
     328    } 
     329     
     330    if (extract & EXTRACT_MAP) 
     331    { 
     332        printf("Using locale: %s\n", langs[FirstLocale]); 
     333         
     334        // Open MPQs 
     335        LoadLocaleMPQFiles(FirstLocale); 
     336        LoadCommonMPQFiles(); 
     337         
     338        // Extract maps 
    312339        ExtractMapsFromMpq(); 
    313340 
    314     //Close MPQs 
    315     for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) 
    316         (*i)->close(); 
    317     gOpenArchives.clear(); 
     341        // Close MPQs 
     342        CloseMPQFiles(); 
     343    } 
    318344 
    319345    return 0;