From 6fbcb3cea9ed11296076d965ffd51e4d3532e412 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Wed, 2 May 2007 13:00:44 +0000 Subject: [PATCH] * fixed extractor: works now with 2.0.x ONLY! * extractor asks for locale now and creates needed directories itself. * deleted obsoelete files --- src/dep/src/irrlicht/Irrlicht7.1.vcproj | 2 +- src/shared/tools.cpp | 31 +++++++++---- src/shared/tools.h | 3 +- src/tools/stuffextract.vcproj | 6 +++ src/tools/stuffextract/DBCFieldData.h | 59 +++++++++++++------------ src/tools/stuffextract/Locale.cpp | 13 ++++++ src/tools/stuffextract/Locale.h | 7 +++ src/tools/stuffextract/MPQFile.cpp | 15 ++++++- src/tools/stuffextract/MPQFile.h | 2 + src/tools/stuffextract/MPQHelper.cpp | 54 +++++++++++++++++++--- src/tools/stuffextract/StuffExtract.cpp | 54 +++++++++++++++------- src/tools/stuffextract/dbcfile.cpp | 5 +++ thanks_to.txt | 25 ----------- todo_tofix_someday.txt | 4 -- 14 files changed, 190 insertions(+), 90 deletions(-) create mode 100644 src/tools/stuffextract/Locale.cpp create mode 100644 src/tools/stuffextract/Locale.h delete mode 100644 thanks_to.txt delete mode 100644 todo_tofix_someday.txt diff --git a/src/dep/src/irrlicht/Irrlicht7.1.vcproj b/src/dep/src/irrlicht/Irrlicht7.1.vcproj index 5a3c298..09e3519 100644 --- a/src/dep/src/irrlicht/Irrlicht7.1.vcproj +++ b/src/dep/src/irrlicht/Irrlicht7.1.vcproj @@ -90,7 +90,7 @@ PreprocessorDefinitions="WIN32" StringPooling="TRUE" ExceptionHandling="FALSE" - RuntimeLibrary="4" + RuntimeLibrary="0" BufferSecurityCheck="FALSE" EnableFunctionLevelLinking="FALSE" EnableEnhancedInstructionSet="0" diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index 2dc2835..d7b9526 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -135,16 +135,29 @@ std::deque GetFileList(std::string path) return files; } -bool FileExists(char *fn) +bool FileExists(std::string fn) { - std::fstream f; - f.open(fn,std::ios_base::in); - if (f.is_open()) - { - f.close(); - return true; - } - return false; + std::fstream f; + f.open(fn.c_str(),std::ios_base::in); + if (f.is_open()) + { + f.close(); + return true; + } + return false; +} + +bool CreateDir(const char *dir) +{ + bool result; +# ifdef _WIN32 + result = ::CreateDirectory(dir,NULL); +# else + // NOT tested for Linux!! whats the return value on success? + // TODO: fix me! + result = mkdir(dir); +#endif + return result; } diff --git a/src/shared/tools.h b/src/shared/tools.h index c485c15..0348a34 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -16,6 +16,7 @@ std::string getDateString(void); uint64 toInt(std::string); std::string toHexDump(uint8* array,uint32 size,bool spaces=true); std::deque GetFileList(std::string); -bool FileExists(char*); +bool FileExists(std::string); +bool CreateDir(const char*); #endif \ No newline at end of file diff --git a/src/tools/stuffextract.vcproj b/src/tools/stuffextract.vcproj index 09eebda..34471a1 100644 --- a/src/tools/stuffextract.vcproj +++ b/src/tools/stuffextract.vcproj @@ -163,6 +163,12 @@ + + + + diff --git a/src/tools/stuffextract/DBCFieldData.h b/src/tools/stuffextract/DBCFieldData.h index a790409..e2b4f98 100644 --- a/src/tools/stuffextract/DBCFieldData.h +++ b/src/tools/stuffextract/DBCFieldData.h @@ -1,8 +1,6 @@ #ifndef DBCFIELDDATA_H #define DBCFIELDDATA_H -// NOTE: fields checked for 1.12.2 deDE - // defines fields numbers in EmotesText.dbc // unk fields are always 0, EMOTESTEXT_EMOTE_STRING is string and the rest is uint32. enum EmotesTextEnum @@ -56,7 +54,15 @@ static const char *EmotesTextFieldNames[] = enum EmotesTextDataEnum { EMOTESTEXTDATA_TEXTID = 0, - EMOTESTEXTDATA_STRING = 4 + EMOTESTEXTDATA_STRING1, + EMOTESTEXTDATA_STRING2, + EMOTESTEXTDATA_STRING3, + EMOTESTEXTDATA_STRING4, + EMOTESTEXTDATA_STRING5, + EMOTESTEXTDATA_STRING6, + EMOTESTEXTDATA_STRING7, + EMOTESTEXTDATA_STRING8, + EMOTESTEXTDATA_UNK, // rest of the fields is 0 always }; @@ -129,30 +135,29 @@ enum ChrRacesEnum CHRRACES_NAME_SHORT, // 2 chars name abbrev (Hu,Or,Tr, etc) CHRRACES_UNK_4, CHRRACES_FACTION, // 1=Alliance, 7=Horde - CHRRACES_UNK_5, - CHRRACES_UNK_6, + CHRRACES_UNK_5, // always 7? + CHRRACES_UNK_6, // SpellID? was always 836 in 1.12.x, since 2.0.x its 15007 CHRRACES_UNK_7, - CHRRACES_UNK_8, - CHRRACES_UNK_9, - CHRRACES_UNK_10, CHRRACES_NAME_GENERAL, // always the english(?) name (without spaces). used in texture names etc. + CHRRACES_UNK_9, + // the following 8 fields contain either 0 or the race name, depending on the locale. + CHRRACES_NAME1, // english + CHRRACES_NAME2, // + CHRRACES_NAME3, // + CHRRACES_NAME4, // german + CHRRACES_NAME5, // + CHRRACES_NAME6, // + CHRRACES_NAME7, // + CHRRACES_NAME8, // + CHRRACES_UNK_10, CHRRACES_UNK_11, - CHRRACES_UNK_12, - CHRRACES_UNK_13, - CHRRACES_UNK_14, - CHRRACES_NAME_LOCAL, // localized(?) name (spanish,german or whatever) - CHRRACES_UNK_15, - CHRRACES_UNK_16, - CHRRACES_UNK_17, - CHRRACES_UNK_18, CHRRACES_UNK_19, CHRRACES_UNK_20, - CHRRACES_TRAITS, // string that defines the face decorations on char create CHRRACES_UNK_21, CHARRACES_END }; -static const char *ChrRacesFormat = "ixxxiisxixxxxxxsxxxxsxxxxxxsx"; +static const char *ChrRacesFormat = "ixxxiisxixxxsxssssssssxxxxx"; static const char *ChrRacesFieldNames[] = { @@ -168,24 +173,22 @@ static const char *ChrRacesFieldNames[] = "", "", "", - "", - "", - "", "name_general", "", - "", - "", - "", + "name", + "name", + "name", + "name", + "name", + "name", + "name", "name", "", "", "", "", "", - "", - "traits", - "", - "" + "" }; #endif diff --git a/src/tools/stuffextract/Locale.cpp b/src/tools/stuffextract/Locale.cpp new file mode 100644 index 0000000..6ec1579 --- /dev/null +++ b/src/tools/stuffextract/Locale.cpp @@ -0,0 +1,13 @@ +#include "Locale.h" + +char *my_locale; + +void SetLocale(char *loc) +{ + my_locale = loc; +} + +char *GetLocale(void) +{ + return my_locale; +} \ No newline at end of file diff --git a/src/tools/stuffextract/Locale.h b/src/tools/stuffextract/Locale.h new file mode 100644 index 0000000..d62833d --- /dev/null +++ b/src/tools/stuffextract/Locale.h @@ -0,0 +1,7 @@ +#ifndef STUFFEXTRACT_LOCALE_H +#define STUFFEXTRACT_LOCALE_H + +char *GetLocale(void); +void SetLocale(char*); + +#endif \ No newline at end of file diff --git a/src/tools/stuffextract/MPQFile.cpp b/src/tools/stuffextract/MPQFile.cpp index fd51661..a79b653 100644 --- a/src/tools/stuffextract/MPQFile.cpp +++ b/src/tools/stuffextract/MPQFile.cpp @@ -7,6 +7,11 @@ MPQFile::MPQFile(const char *fn) _isopen = SFileOpenArchive(fn,0,0,&_mpq); } +MPQFile::~MPQFile() +{ + Close(); +} + bool MPQFile::HasFile(char *fn) { return SFileHasFile(_mpq,fn); @@ -22,6 +27,7 @@ ByteBuffer MPQFile::ReadFile(char *fn) uint32 size = SFileGetFileSize(fh); bb.resize(size); SFileReadFile(fh, (void*)bb.contents(), size, NULL, NULL); + SFileCloseFile(fh); return bb; } @@ -33,4 +39,11 @@ uint32 MPQFile::GetFileSize(char *fn) uint32 size = SFileGetFileSize(fh); SFileCloseFile(fh); return size; -} \ No newline at end of file +} + +void MPQFile::Close(void) +{ + if(_isopen) + SFileCloseArchive(_mpq); +} + diff --git a/src/tools/stuffextract/MPQFile.h b/src/tools/stuffextract/MPQFile.h index ed418e0..621f437 100644 --- a/src/tools/stuffextract/MPQFile.h +++ b/src/tools/stuffextract/MPQFile.h @@ -10,10 +10,12 @@ class MPQFile { public: MPQFile(const char*); + ~MPQFile(); inline bool IsOpen(void) { return _isopen; } ByteBuffer ReadFile(char*); uint32 GetFileSize(char*); bool HasFile(char*); + void Close(void); private: HANDLE _mpq; diff --git a/src/tools/stuffextract/MPQHelper.cpp b/src/tools/stuffextract/MPQHelper.cpp index 960bd4d..0f35f95 100644 --- a/src/tools/stuffextract/MPQHelper.cpp +++ b/src/tools/stuffextract/MPQHelper.cpp @@ -1,28 +1,70 @@ +#include #include "common.h" #include "MPQHelper.h" #include "MPQFile.h" +#include "Locale.h" + +#define DATADIR "Data" MPQHelper::MPQHelper() { } -bool MPQHelper::AssignArchive(char *fn) +// supply without ".mpq" !! +bool MPQHelper::AssignArchive(char *archive) { + // old code for 1.12.x and below archives order + /* // first, check which patch files are avalible. // store patches in reversed order, that patch-9.mpq is checked first, and patch.mpq checked last - if(FileExists("Data/patch.MPQ")) + if(FileExists(DATADIR"/patch.MPQ")) _patches.push_front("Data/patch.MPQ"); for(uint32 i=1; i::iterator i = _patches.begin(); i != _patches.end(); i++) { MPQFile mpq((*i).c_str()); - if(mpq.IsOpen() && mpq.HasFile(fn)) + if(mpq.IsOpen() && mpq.HasFile(fn) && mpq.GetFileSize(fn) > 0) { printf("MPQE: Using %s from %s\n",fn,i->c_str()); bb = mpq.ReadFile(fn); diff --git a/src/tools/stuffextract/StuffExtract.cpp b/src/tools/stuffextract/StuffExtract.cpp index 578a151..6a8e5f2 100644 --- a/src/tools/stuffextract/StuffExtract.cpp +++ b/src/tools/stuffextract/StuffExtract.cpp @@ -5,15 +5,31 @@ #include "dbcfile.h" #include "StuffExtract.h" #include "DBCFieldData.h" +#include "Locale.h" + + int main(int argc, char *argv[]) { - printf("StuffExtract [version %u]\n",SE_VERSION); - ConvertDBC(); + char input[200]; + printf("StuffExtract [version %u]\n\n",SE_VERSION); + printf("Enter your locale (enUS, enGB, deDE, ...): "); + fgets(input,sizeof(input),stdin); + char loc[5]; + memcpy(loc,input,4); loc[4]=0; + SetLocale(loc); + if(FileExists(std::string("Data/")+GetLocale()+"/locale-"+GetLocale()+".MPQ")) + { + printf("Locale seems valid, starting conversion...\n"); + ConvertDBC(); + //... + printf("\n -- finished, press enter to exit --\n"); + } + else + { + printf("ERROR: Invalid locale! Press Enter to exit...\n"); + } - - printf("\n -- finished --\n"); - char crap[200]; - fgets(crap,sizeof(crap),stdin); + fgets(input,sizeof(input),stdin); //while(true); return 0; @@ -54,7 +70,6 @@ void OutSCP(char *fn, SCPStorageMap& scp) } } - bool ConvertDBC(void) { std::map racemap; // needed to extract other dbc files correctly @@ -62,7 +77,7 @@ bool ConvertDBC(void) DBCFile EmotesText,EmotesTextData,EmotesTextSound,ChrRaces,SoundEntries; printf("Opening DBC archive...\n"); MPQHelper mpq; - if(!mpq.AssignArchive("Data/dbc.MPQ")) + if(!mpq.AssignArchive("dbc")) { printf("ConvertDBC: Could not open 'Data/dbc.MPQ'\n"); return false; @@ -86,7 +101,8 @@ bool ConvertDBC(void) if(strlen(ChrRacesFieldNames[field])) { std::string value = AutoGetDataString(it,ChrRacesFormat,field); - RaceDataStorage[id].push_back(std::string(ChrRacesFieldNames[field]).append("=").append(value)); + if(!value.empty()) + RaceDataStorage[id].push_back(std::string(ChrRacesFieldNames[field]).append("=").append(value)); } } } @@ -109,11 +125,17 @@ bool ConvertDBC(void) if(textid == (*it).getInt(field)) { fname = EmotesTextFieldNames[field]; - EmoteDataStorage[em].push_back( fname + "=" + (*ix).getString(EMOTESTEXTDATA_STRING) ); - break; + for(uint8 stringpos=EMOTESTEXTDATA_STRING1; stringpos<=EMOTESTEXTDATA_STRING8; stringpos++) // we have 8 locales, so... + { + if((*ix).getInt(stringpos)) // find out which field is used, 0 if not used + { + EmoteDataStorage[em].push_back( fname + "=" + (*ix).getString(stringpos) ); + break; + } + } + break; } } - } } for(DBCFile::Iterator is = EmotesTextSound.begin(); is != EmotesTextSound.end(); ++is) @@ -148,6 +170,9 @@ bool ConvertDBC(void) //... printf("DONE!\n"); //... + CreateDir("stuffextract"); + CreateDir("stuffextract/scp"); + printf("Writing SCP files:\n"); printf("emote.."); OutSCP(SCPDIR "/emote.scp",EmoteDataStorage); printf("race.."); OutSCP(SCPDIR "/race.scp",RaceDataStorage); @@ -155,9 +180,8 @@ bool ConvertDBC(void) //... printf("DONE!\n"); - - - + // wait for all container destructors to finish + printf("DBC files converted, cleaning up...\n"); return true; } \ No newline at end of file diff --git a/src/tools/stuffextract/dbcfile.cpp b/src/tools/stuffextract/dbcfile.cpp index e4b85ea..50d69bd 100644 --- a/src/tools/stuffextract/dbcfile.cpp +++ b/src/tools/stuffextract/dbcfile.cpp @@ -59,6 +59,11 @@ bool DBCFile::open() bool DBCFile::openmem(ByteBuffer bb) { + if(bb.size() < 4+4+4+4+4) + { + printf("DBCFile::openmem(): ByteBuffer too small!"); + return false; + } uint32 hdr; bb >> hdr; diff --git a/thanks_to.txt b/thanks_to.txt deleted file mode 100644 index 86f8706..0000000 --- a/thanks_to.txt +++ /dev/null @@ -1,25 +0,0 @@ -#Coders: -False.Genesis (project starter) -Mini - - -#Testers: -========= -Project-Eden crew: Leito, Michel [Milk Addict], ©haos, Orochi, SoulReaper - - - -#Special thanks to: -=================== - -©haos for the neat icon and many hours that passed by while discussing -about PseuWoW related stuff. - - - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -Want to be named here? Then do something for the Project! diff --git a/todo_tofix_someday.txt b/todo_tofix_someday.txt deleted file mode 100644 index 431138f..0000000 --- a/todo_tofix_someday.txt +++ /dev/null @@ -1,4 +0,0 @@ -realm login: -- use the correct IP in CLIENT_LOGON_CHALLENGE, and not 127.0.0.1 -- use correct timezone, maybe settable via conf file later on -- define the crc_hash as it should be