From d077c920112861988725cb3b4c0e7cf81958201e Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Tue, 7 Jul 2020 01:56:17 +0200 Subject: [PATCH] Core/Datastores: ported locale related datastore updates in order to load storage locales properly when set in config --- src/common/Common.cpp | 3 +- src/common/Common.h | 1 + src/server/game/DataStores/DB2Stores.cpp | 29 ++++--- src/server/game/DataStores/DB2Stores.h | 2 +- src/server/game/DataStores/DBCStores.cpp | 12 +-- src/server/game/DataStores/DBCStores.h | 2 +- src/server/game/World/World.cpp | 6 +- src/server/scripts/Commands/cs_lookup.cpp | 1 + .../shared/DataStores/DB2StorageLoader.cpp | 22 +++-- src/tools/map_extractor/System.cpp | 86 ++++++++++++------- 10 files changed, 100 insertions(+), 64 deletions(-) diff --git a/src/common/Common.cpp b/src/common/Common.cpp index b10ad2d8d9..b768461e27 100644 --- a/src/common/Common.cpp +++ b/src/common/Common.cpp @@ -29,7 +29,8 @@ char const* localeNames[TOTAL_LOCALES] = "esMX", "ruRU", "none", - "ptBR" + "ptBR", + "itIT" }; LocaleConstant GetLocaleByName(const std::string& name) diff --git a/src/common/Common.h b/src/common/Common.h index a1a0a02cef..3cdb5d0da8 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -92,6 +92,7 @@ enum LocaleConstant : uint8 LOCALE_ruRU = 8, LOCALE_NONE = 9, LOCALE_ptBR = 10, + LOCALE_itIT = 11, TOTAL_LOCALES }; diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index 4eb4cb8997..91c57a3bc3 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -17,6 +17,7 @@ #include "Common.h" #include "DatabaseEnv.h" +#include "DBCStores.h" #include "DB2Stores.h" #include "DB2fmt.h" #include "Errors.h" @@ -43,7 +44,7 @@ DB2Manager& DB2Manager::Instance() uint32 DB2FilesCount = 0; template -inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Manager::StorageMap& stores, DB2Storage* storage, std::string const& db2_path) +inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Manager::StorageMap& stores, DB2Storage* storage, std::string const& db2Path, uint32 defaultLocale) { // compatibility format and C++ structure sizes ASSERT(DB2FileLoader::GetFormatRecordSize(storage->GetFormat()) == sizeof(T), @@ -52,17 +53,21 @@ inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, D ++DB2FilesCount; - if (storage->Load(db2_path, uint32(sWorld->GetDefaultDbcLocale()))) + if (storage->Load(db2Path + localeNames[defaultLocale] + '/', defaultLocale)) { storage->LoadFromDB(); + // LoadFromDB() always loads strings into enUS locale, other locales are expected to have data in corresponding _locale tables + // so we need to make additional call to load that data in case said locale is set as default by worldserver.conf (and we do not want to load all this data from .db2 file again) + if (defaultLocale != LOCALE_enUS) + storage->LoadStringsFromDB(LocaleConstant(defaultLocale)); for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { - if (uint32(sWorld->GetDefaultDbcLocale()) == i) + if (defaultLocale == i) continue; if (availableDb2Locales & (1 << i)) - if (!storage->LoadStringsFrom((db2_path + localeNames[i] + '/'), i)) + if (!storage->LoadStringsFrom((db2Path + localeNames[i] + '/'), i)) availableDb2Locales &= ~(1 << i); // mark as not available for speedup next checks storage->LoadStringsFromDB(LocaleConstant(i)); @@ -71,7 +76,7 @@ inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, D else { // sort problematic db2 to (1) non compatible and (2) nonexistent - if (FILE* f = fopen((db2_path + storage->GetFileName()).c_str(), "rb")) + if (FILE* f = fopen((db2Path + storage->GetFileName()).c_str(), "rb")) { std::ostringstream stream; stream << storage->GetFileName() << " exists, and has " << storage->GetFieldCount() << " field(s) (expected " << strlen(storage->GetFormat()) @@ -87,7 +92,7 @@ inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, D stores[storage->GetHash()] = storage; } -void DB2Manager::LoadStores(std::string const& dataPath) +void DB2Manager::LoadStores(std::string const& dataPath, uint32 defaultLocale) { uint32 oldMSTime = getMSTime(); @@ -96,16 +101,16 @@ void DB2Manager::LoadStores(std::string const& dataPath) DB2StoreProblemList bad_db2_files; uint32 availableDb2Locales = 0xFF; - LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemStore, db2Path); - LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemCurrencyCostStore, db2Path); - LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemSparseStore, db2Path); - LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemExtendedCostStore, db2Path); - LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sKeyChainStore, db2Path); + LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemStore, db2Path, defaultLocale); + LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemCurrencyCostStore, db2Path, defaultLocale); + LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemSparseStore, db2Path, defaultLocale); + LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sItemExtendedCostStore, db2Path, defaultLocale); + LoadDB2(availableDb2Locales, bad_db2_files, _stores, &sKeyChainStore, db2Path, defaultLocale); // error checks if (bad_db2_files.size() >= DB2FilesCount) { - TC_LOG_ERROR("misc", "\nIncorrect DataDir value in worldserver.conf or ALL required *.db2 files (%d) not found by path: %sdb2", DB2FilesCount, dataPath.c_str()); + TC_LOG_ERROR("misc", "\nIncorrect DataDir value in worldserver.conf or ALL required *.db2 files (%d) not found by path: %sdbc/%s/", DB2FilesCount, dataPath.c_str(), localeNames[defaultLocale]); exit(1); } else if (!bad_db2_files.empty()) diff --git a/src/server/game/DataStores/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h index c4a672ebb7..ed8807e6d9 100644 --- a/src/server/game/DataStores/DB2Stores.h +++ b/src/server/game/DataStores/DB2Stores.h @@ -46,7 +46,7 @@ public: static DB2Manager& Instance(); - void LoadStores(std::string const& dataPath); + void LoadStores(std::string const& dataPath, uint32 defaultLocale); DB2StorageBase const* GetStorage(uint32 type) const; void LoadHotfixData(); diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index a63bdf0b56..d7bddd2901 100644 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -283,13 +283,13 @@ static bool LoadDBC_assert_print(uint32 fsize, uint32 rsize, const std::string& } template -inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCStorage& storage, std::string const& dbcPath, std::string const& filename, std::string const& customFormat = std::string(), std::string const& customIndexName = std::string()) +inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCStorage& storage, std::string const& dbcPath, std::string const& filename, uint32 defaultLocale, std::string const& customFormat = std::string(), std::string const& customIndexName = std::string()) { // compatibility format and C++ structure sizes ASSERT(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); ++DBCFileCount; - std::string dbcFilename = dbcPath + filename; + std::string dbcFilename = dbcPath + localeNames[defaultLocale] + '/' + filename; if (storage.Load(dbcFilename)) { @@ -326,7 +326,7 @@ inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCSt } } -void DBCManager::LoadStores(const std::string& dataPath) +void DBCManager::LoadStores(const std::string& dataPath, uint32 defaultLocale) { uint32 oldMSTime = getMSTime(); @@ -343,7 +343,7 @@ void DBCManager::LoadStores(const std::string& dataPath) DBCStorage sPhaseGroupStore(PhaseGroupfmt); DBCStorage sTalentTreePrimarySpellsStore(TalentTreePrimarySpellsfmt); -#define LOAD_DBC(store, file) LoadDBC(availableDbcLocales, bad_dbc_files, store, dbcPath, file) +#define LOAD_DBC(store, file) LoadDBC(availableDbcLocales, bad_dbc_files, store, dbcPath, file, defaultLocale) LOAD_DBC(sAreaTableStore, "AreaTable.dbc"); LOAD_DBC(sAnimKitStore, "AnimKit.dbc");//15595 @@ -513,7 +513,7 @@ void DBCManager::LoadStores(const std::string& dataPath) #undef LOAD_DBC -#define LOAD_DBC_EXT(store, file, dbformat, dbpk) LoadDBC(availableDbcLocales, bad_dbc_files, store, dbcPath, file, dbformat, dbpk) +#define LOAD_DBC_EXT(store, file, dbformat, dbpk) LoadDBC(availableDbcLocales, bad_dbc_files, store, dbcPath, file, defaultLocale, dbformat, dbpk) LOAD_DBC_EXT(sAchievementStore, "Achievement.dbc", CustomAchievementfmt, CustomAchievementIndex);//15595 LOAD_DBC_EXT(sSpellStore, "Spell.dbc", CustomSpellEntryfmt, CustomSpellEntryIndex);// @@ -779,7 +779,7 @@ void DBCManager::LoadStores(const std::string& dataPath) // error checks if (bad_dbc_files.size() >= DBCFileCount) { - TC_LOG_ERROR("misc", "Incorrect DataDir value in worldserver.conf or ALL required *.dbc files (%d) not found by path: %sdbc", DBCFileCount, dataPath.c_str()); + TC_LOG_ERROR("misc", "Incorrect DataDir value in worldserver.conf or ALL required *.dbc files (%d) not found by path: %sdbc/%s", DBCFileCount, dataPath.c_str(), localeNames[defaultLocale]); exit(1); } else if (!bad_dbc_files.empty()) diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index 099eb8fd52..4d4b61b884 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -213,7 +213,7 @@ class TC_GAME_API DBCManager public: static DBCManager& Instance(); - void LoadStores(const std::string& dataPath); + void LoadStores(const std::string& dataPath, uint32 defaultLocale); SimpleFactionsList const* GetFactionTeamList(uint32 faction); static char const* GetPetName(uint32 petfamily, uint32 dbclang); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 0ceaf229bb..826fd5b3fe 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -510,7 +510,7 @@ void World::LoadConfigSettings(bool reload) m_defaultDbcLocale = LocaleConstant(sConfigMgr->GetIntDefault("DBC.Locale", 0)); - if (m_defaultDbcLocale >= TOTAL_LOCALES) + if (m_defaultDbcLocale >= TOTAL_LOCALES || m_defaultDbcLocale < LOCALE_enUS) { TC_LOG_ERROR("server.loading", "Incorrect DBC.Locale! Must be >= 0 and < %d (set to 0)", TOTAL_LOCALES); m_defaultDbcLocale = LOCALE_enUS; @@ -1655,8 +1655,8 @@ void World::SetInitialWorldSettings() ///- Load the DBC/DB2 files TC_LOG_INFO("server.loading", "Initialize data stores..."); - sDBCManager.LoadStores(m_dataPath); - sDB2Manager.LoadStores(m_dataPath); + sDBCManager.LoadStores(m_dataPath, m_defaultDbcLocale); + sDB2Manager.LoadStores(m_dataPath, m_defaultDbcLocale); TC_LOG_INFO("misc", "Loading hotfix info..."); sDB2Manager.LoadHotfixData(); diff --git a/src/server/scripts/Commands/cs_lookup.cpp b/src/server/scripts/Commands/cs_lookup.cpp index f10c3c012a..e7f9838479 100644 --- a/src/server/scripts/Commands/cs_lookup.cpp +++ b/src/server/scripts/Commands/cs_lookup.cpp @@ -374,6 +374,7 @@ public: ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) { + printf("sessionlocale = %u\n", handler->GetSessionDbcLocale()); std::string name = itr->second.GetName(handler->GetSessionDbcLocale()); if (name.empty()) continue; diff --git a/src/server/shared/DataStores/DB2StorageLoader.cpp b/src/server/shared/DataStores/DB2StorageLoader.cpp index 625e207d45..32b889f20d 100644 --- a/src/server/shared/DataStores/DB2StorageLoader.cpp +++ b/src/server/shared/DataStores/DB2StorageLoader.cpp @@ -325,19 +325,21 @@ char* DB2FileLoader::AutoProduceStringsArrayHolders(char const* format, char* da return nullptr; // we store flat holders pool as single memory block - size_t stringFields = GetFormatStringFieldCount(format); + std::size_t stringFields = GetFormatStringFieldCount(format); if (!stringFields) return nullptr; + std::size_t localizedStringFields = GetFormatStringFieldCount(format); + // each string field at load have array of string for each locale - size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; - size_t stringHoldersRecordPoolSize = stringFields * stringHolderSize; - size_t stringHoldersPoolSize = stringHoldersRecordPoolSize * recordCount; + std::size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; + std::size_t stringHoldersRecordPoolSize = localizedStringFields * stringHolderSize + (stringFields - localizedStringFields) * sizeof(char*); + std::size_t stringHoldersPoolSize = stringHoldersRecordPoolSize * recordCount; char* stringHoldersPool = new char[stringHoldersPoolSize]; // DB2 strings expected to have at least empty string - for (size_t i = 0; i < stringHoldersPoolSize / sizeof(char*); ++i) + for (std::size_t i = 0; i < stringHoldersPoolSize / sizeof(char*); ++i) ((char const**)stringHoldersPool)[i] = nullStr; uint32 offset = 0; @@ -345,7 +347,7 @@ char* DB2FileLoader::AutoProduceStringsArrayHolders(char const* format, char* da // assign string holders to string field slots for (uint32 y = 0; y < recordCount; y++) { - uint32 stringFieldNum = 0; + uint32 stringFieldOffset = 0; for (uint32 x = 0; x < fieldCount; x++) { @@ -363,8 +365,12 @@ char* DB2FileLoader::AutoProduceStringsArrayHolders(char const* format, char* da { // init db2 string field slots by pointers to string holders char const*** slot = (char const***)(&dataTable[offset]); - *slot = (char const**)(&stringHoldersPool[stringHoldersRecordPoolSize * y + stringHolderSize * stringFieldNum]); - ++stringFieldNum; + *slot = (char const**)(&stringHoldersPool[stringHoldersRecordPoolSize * y + stringFieldOffset]); + if (format[x] == FT_STRING) + stringFieldOffset += stringHolderSize; + else + ++stringFieldOffset; + offset += sizeof(char*); break; } diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index b6616955b4..b3442e9183 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -27,6 +27,11 @@ #include #include +#include "Common.h" +#ifdef PLATFORM_WINDOWS +#undef PLATFORM_WINDOWS +#endif + #ifdef _WIN32 #include "direct.h" #else @@ -89,8 +94,9 @@ std::vector map_ids; std::unordered_map LiquidMaterials; std::unordered_map LiquidObjects; std::unordered_map LiquidTypes; -char output_path[128] = "."; -char input_path[128] = "."; +#define MAX_PATH_LENGTH 128 +char output_path[MAX_PATH_LENGTH]; +char input_path[MAX_PATH_LENGTH]; // ************************************************** // Extractor options @@ -147,6 +153,25 @@ char const* Locales[LOCALES_COUNT] = "itIT" }; +uint8 const MpqToWowLocale[LOCALES_COUNT] = +{ + LOCALE_enUS, + LOCALE_enUS, + LOCALE_deDE, + LOCALE_esES, + LOCALE_frFR, + LOCALE_koKR, + LOCALE_zhCN, + LOCALE_zhTW, + LOCALE_zhCN, + LOCALE_zhTW, + LOCALE_esMX, + LOCALE_ruRU, + LOCALE_ptBR, + LOCALE_ptBR, + LOCALE_itIT +}; + TCHAR const* LocalesT[LOCALES_COUNT] = { _T("enGB"), _T("enUS"), @@ -163,8 +188,8 @@ void CreateDir(std::string const& path) { if (chdir(path.c_str()) == 0) { - chdir("../"); - return; + chdir("../"); + return; } #ifdef _WIN32 @@ -216,17 +241,22 @@ void HandleArgs(int argc, char* arg[]) switch (arg[c][1]) { case 'i': - if (c + 1 < argc) // all ok - strcpy(input_path, arg[c++ + 1]); + if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok + { + strncpy(input_path, arg[c++ + 1], MAX_PATH_LENGTH); + input_path[MAX_PATH_LENGTH - 1] = '\0'; + } else Usage(arg[0]); break; case 'o': - if (c + 1 < argc) // all ok - strcpy(output_path, arg[c++ + 1]); + if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok + { + strncpy(output_path, arg[c++ + 1], MAX_PATH_LENGTH); + output_path[MAX_PATH_LENGTH - 1] = '\0'; + } else Usage(arg[0]); - break; case 'f': if (c + 1 < argc) // all ok CONF_allow_float_to_int = atoi(arg[c++ + 1])!=0; @@ -1183,7 +1213,7 @@ bool ExtractFile(HANDLE fileInArchive, char const* filename) return true; } -void ExtractDBCFiles(int l, bool basicLocale) +void ExtractDBCFiles(int l) { printf("Extracting dbc files...\n"); @@ -1198,12 +1228,9 @@ void ExtractDBCFiles(int l, bool basicLocale) outputPath += "/dbc/"; CreateDir(outputPath); - if (!basicLocale) - { - outputPath += Locales[l]; - outputPath += "/"; - CreateDir(outputPath); - } + outputPath += localeNames[MpqToWowLocale[l]]; + outputPath += "/"; + CreateDir(outputPath); std::string filename; @@ -1233,7 +1260,7 @@ void ExtractDBCFiles(int l, bool basicLocale) printf("Extracted %u DBC files\n\n", count); } -void ExtractDB2Files(int l, bool basicLocale) +void ExtractDB2Files(int l) { printf("Extracting db2 files...\n"); @@ -1246,11 +1273,8 @@ void ExtractDB2Files(int l, bool basicLocale) { std::string outputPath = output_path; outputPath += "/dbc/"; - if (!basicLocale) - { - outputPath += Locales[l]; - outputPath += "/"; - } + outputPath += localeNames[MpqToWowLocale[l]]; + outputPath += "/"; std::string filename; @@ -1276,7 +1300,7 @@ void ExtractDB2Files(int l, bool basicLocale) printf("Extracted %u DB2 files\n\n", count); } -void ExtractCameraFiles(int locale, bool basicLocale) +void ExtractCameraFiles(int locale) { printf("Extracting camera files...\n"); HANDLE dbcFile; @@ -1311,12 +1335,6 @@ void ExtractCameraFiles(int locale, bool basicLocale) std::string path = output_path; path += "/Cameras/"; CreateDir(path); - if (!basicLocale) - { - path += Locales[locale]; - path += "/"; - CreateDir(path); - } // extract M2s uint32 count = 0; @@ -1463,6 +1481,10 @@ int main(int argc, char * arg[]) { Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr); + boost::filesystem::path current(boost::filesystem::current_path()); + strcpy(input_path, current.string().c_str()); + strcpy(output_path, current.string().c_str()); + HandleArgs(argc, arg); int FirstLocale = -1; @@ -1505,8 +1527,8 @@ int main(int argc, char * arg[]) } printf("\n"); - ExtractDBCFiles(i, FirstLocale < 0); - ExtractDB2Files(i, FirstLocale < 0); + ExtractDBCFiles(i); + ExtractDB2Files(i); if (FirstLocale < 0) { @@ -1533,7 +1555,7 @@ int main(int argc, char * arg[]) LoadCommonMPQFiles(build); // Extract cameras - ExtractCameraFiles(FirstLocale, true); + ExtractCameraFiles(FirstLocale); // Close MPQs SFileCloseArchive(WorldMpq);