Multi-locale DBC extracting

Signed-off-by: Foks <Foks@mangos.ru>

Small related code fixed and cleanups.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Foks 2008-11-06 06:14:46 +03:00 committed by VladimirMangos
parent ef8e864008
commit cdb2c08e3f
7 changed files with 101 additions and 75 deletions

View file

@ -39,7 +39,7 @@ enum Extract
}; };
int extract = EXTRACT_MAP | EXTRACT_DBC; 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 LANG_COUNT 12
#define ADT_RES 64 #define ADT_RES 64
@ -167,11 +167,11 @@ void ExtractMapsFromMpq()
path += "/maps/"; path += "/maps/";
CreateDir(path); 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(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); 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); //bool WMO(char* filename);
void ExtractDBCFiles() void ExtractDBCFiles(int locale, bool basicLocale)
{ {
printf("Extracting dbc files...\n"); printf("Extracting dbc files...\n");
@ -198,26 +198,30 @@ void ExtractDBCFiles()
// get DBC file list // get DBC file list
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) 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) for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
dbcfiles.insert(*iter); dbcfiles.insert(*iter);
} }
std::string path = output_path; string path = output_path;
path += "/dbc/"; path += "/dbc/";
CreateDir(path); CreateDir(path);
if(!basicLocale)
{
path += langs[locale];
path += "/";
CreateDir(path);
}
// extract DBCs // extract DBCs
int count = 0; int count = 0;
for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter)
{ {
string filename = output_path; string filename = path;
filename += "/dbc/";
filename += (iter->c_str() + strlen("DBFilesClient\\")); filename += (iter->c_str() + strlen("DBFilesClient\\"));
//cout << filename << endl;
FILE *output=fopen(filename.c_str(),"wb"); FILE *output=fopen(filename.c_str(),"wb");
if(!output) if(!output)
{ {
@ -231,27 +235,10 @@ void ExtractDBCFiles()
fclose(output); fclose(output);
++count; ++count;
} }
printf("Extracted %u DBC files\n", count); printf("Extracted %u DBC files\n\n", count);
} }
int GetLocale() void LoadLocaleMPQFiles(int const 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]);
return i;
}
}
printf("Could not detect locale.\n");
return -1;
}
void LoadMPQFiles(int const locale)
{ {
char filename[512]; char filename[512];
@ -265,56 +252,98 @@ void LoadMPQFiles(int const locale)
sprintf(ext, "-%i", i); sprintf(ext, "-%i", i);
sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext); sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext);
if(!FileExists(filename)) 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;
new MPQArchive(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[]) int main(int argc, char * arg[])
{ {
printf("Map & DBC Extractor\n"); printf("Map & DBC Extractor\n");
printf("===================\n"); printf("===================\n\n");
HandleArgs(argc, arg); HandleArgs(argc, arg);
int const locale = GetLocale(); int FirstLocale = -1;
if(locale < 0)
return 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) //Open MPQs
ExtractDBCFiles(); 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(); ExtractMapsFromMpq();
//Close MPQs // Close MPQs
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) CloseMPQFiles();
(*i)->close(); }
gOpenArchives.clear();
return 0; return 0;
} }

Binary file not shown.

View file

@ -199,7 +199,7 @@ int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype) {
/* /*
* This function returns some useful file information. * 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 blockindex = number; //-1;
int i = 0; int i = 0;
mpq_block *mpq_b = NULL; mpq_block *mpq_b = NULL;

View file

@ -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_close(mpq_archive *mpq_a);
extern int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype); 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_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 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_number(mpq_archive *mpq_a, const char *name);
extern int libmpq_file_check(mpq_archive *mpq_a, void *file, int type); extern int libmpq_file_check(mpq_archive *mpq_a, void *file, int type);

View file

@ -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 */ /* 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] == '#') { if (line[i] == '#') {
pos = i - 1; pos = i - 1;
break; break;

View file

@ -71,7 +71,7 @@ MPQFile::MPQFile(const char* filename):
continue; //file not found continue; //file not found
} }
int fileno = blockindex; uint32 fileno = blockindex;
//int fileno = libmpq_file_number(&mpq_a, filename); //int fileno = libmpq_file_number(&mpq_a, filename);
//if(fileno == LIBMPQ_EFILE_NOT_FOUND) //if(fileno == LIBMPQ_EFILE_NOT_FOUND)

View file

@ -51,14 +51,12 @@ public:
return nullhash; return nullhash;
} }
vector<string> GetFileList() { void GetFileListTo(vector<string>& filelist) {
vector<string> filelist;
mpq_hash hash = GetHashEntry("(listfile)"); mpq_hash hash = GetHashEntry("(listfile)");
uint32 blockindex = hash.blockindex; uint32 blockindex = hash.blockindex;
if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) if ((blockindex == 0xFFFFFFFF) || (blockindex == 0))
return filelist; return;
uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex); uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex);
char *buffer = new char[size]; char *buffer = new char[size];
@ -79,8 +77,7 @@ public:
token = strtok(NULL, seps); token = strtok(NULL, seps);
} }
delete buffer; delete[] buffer;
return filelist;
} }
}; };
typedef std::deque<MPQArchive*> ArchiveSet; typedef std::deque<MPQArchive*> ArchiveSet;