diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/CreatureEventAI.h | 1 | ||||
-rw-r--r-- | src/game/CreatureEventAIMgr.cpp | 12 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 61 | ||||
-rw-r--r-- | src/game/ObjectMgr.h | 12 |
4 files changed, 56 insertions, 30 deletions
diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 7e67dffefcd..006cd7df08b 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -30,7 +30,6 @@ class WorldObject; #define EVENT_UPDATE_TIME 500 #define SPELL_RUN_AWAY 8225 #define MAX_ACTIONS 3 -#define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available enum EventAI_Type { diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index 48c6082a4d4..01c92ade6db 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -36,7 +36,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() m_CreatureEventAI_TextMap.clear(); // Load EventAI Text - LoadTrinityStrings(WorldDatabase,"creature_ai_texts",-1,1+(TEXT_SOURCE_RANGE)); + objmgr.LoadTrinityStrings(WorldDatabase,"creature_ai_texts",MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID); // Gather Additional data from EventAI Texts QueryResult *result = WorldDatabase.PQuery("SELECT entry, sound, type, language, emote FROM creature_ai_texts"); @@ -59,15 +59,17 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() temp.Language = fields[3].GetInt32(); temp.Emote = fields[4].GetInt32(); - if (i >= 0) + // range negative + if (i > MIN_CREATURE_AI_TEXT_STRING_ID || i <= MAX_CREATURE_AI_TEXT_STRING_ID) { - sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is not a negative value.",i); + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is not in valid range(%d-%d)",i,MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID); continue; } - if (i <= TEXT_SOURCE_RANGE) + // range negative (don't must be happen, loaded from same table) + if (!objmgr.GetTrinityStringLocale(i)) { - sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is out of accepted entry range for table.",i); + sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` not found",i); continue; } diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index a8b45738696..3ed60018ecc 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -6822,10 +6822,35 @@ void ObjectMgr::LoadGameObjectForQuests() bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value) { + int32 start_value = min_value; + int32 end_value = max_value; + // some string can have negative indexes range + if (start_value < 0) + { + if (end_value >= start_value) + { + sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table,min_value,max_value); + return false; + } + + // real range (max+1,min+1) exaple: (-10,-1000) -> -999...-10+1 + std::swap(start_value,end_value); + ++start_value; + ++end_value; + } + else + { + if (start_value >= end_value) + { + sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.",table,min_value,max_value); + return false; + } + } + // cleanup affected map part for reloading case for(TrinityStringLocaleMap::iterator itr = mTrinityStringLocaleMap.begin(); itr != mTrinityStringLocaleMap.end();) { - if(itr->first >= min_value && itr->first <= max_value) + if (itr->first >= start_value && itr->first < end_value) { TrinityStringLocaleMap::iterator itr2 = itr; ++itr; @@ -6837,14 +6862,14 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table); - if(!result) + if (!result) { barGoLink bar(1); bar.step(); sLog.outString(); - if(min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings + if (min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings sLog.outErrorDb(">> Loaded 0 trinity strings. DB table `%s` is empty. Cannot continue.",table); else sLog.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table); @@ -6862,22 +6887,20 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi int32 entry = fields[0].GetInt32(); - if(entry==0) + if (entry==0) { sLog.outErrorDb("Table `%s` contain reserved entry 0, ignored.",table); continue; } - else if(entry < min_value || entry > max_value) + else if (entry < start_value || entry >= end_value) { - int32 start = min_value > 0 ? min_value : max_value; - int32 end = min_value > 0 ? max_value : min_value; - sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,start,end); + sLog.outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.",table,entry,min_value,max_value); continue; } TrinityStringLocale& data = mTrinityStringLocaleMap[entry]; - if(data.Content.size() > 0) + if (data.Content.size() > 0) { sLog.outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.",table,entry); continue; @@ -6892,13 +6915,13 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi for(int i = 1; i < MAX_LOCALE; ++i) { std::string str = fields[i+1].GetCppString(); - if(!str.empty()) + if (!str.empty()) { int idx = GetOrNewIndexForLocale(LocaleConstant(i)); - if(idx >= 0) + if (idx >= 0) { // 0 -> default, idx in to idx+1 - if(data.Content.size() <= idx+1) + if (data.Content.size() <= idx+1) data.Content.resize(idx+2); data.Content[idx+1] = str; @@ -6910,7 +6933,7 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi delete result; sLog.outString(); - if(min_value == MIN_TRINITY_STRING_ID) // internal Trinity strings + if (min_value == MIN_TRINITY_STRING_ID) sLog.outString( ">> Loaded %u Trinity strings from table %s", count,table); else sLog.outString( ">> Loaded %u string templates from %s", count,table); @@ -7907,15 +7930,15 @@ uint32 GetAreaTriggerScriptId(uint32 trigger_id) bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value) { - if(start_value >= 0 || start_value <= end_value) // start/end reversed for negative values + // MAX_DB_SCRIPT_STRING_ID is max allowed negative value for scripts (scrpts can use only more deep negative values + // start/end reversed for negative values + if (start_value > MAX_DB_SCRIPT_STRING_ID || end_value >= start_value) { - sLog.outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), use (%d - %d) instead.",table,start_value,end_value,-1,std::numeric_limits<int32>::min()); - start_value = -1; - end_value = std::numeric_limits<int32>::min(); + sLog.outErrorDb("Table '%s' attempt loaded with reserved by mangos range (%d - %d), strings not loaded.",table,start_value,end_value+1); + return false; } - // for scripting localized strings allowed use _only_ negative entries - return objmgr.LoadTrinityStrings(db,table,end_value,start_value); + return objmgr.LoadTrinityStrings(db,table,start_value,end_value); } uint32 TRINITY_DLL_SPEC GetScriptId(const char *name) diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 3fe373f6a34..33915398c91 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -133,10 +133,12 @@ typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes; // mangos string ranges -#define MIN_TRINITY_STRING_ID 1 -#define MAX_TRINITY_STRING_ID 2000000000 -#define MIN_DB_SCRIPT_STRING_ID MAX_TRINITY_STRING_ID -#define MAX_DB_SCRIPT_STRING_ID 2000010000 +#define MIN_TRINITY_STRING_ID 1 // 'mangos_string' +#define MAX_TRINITY_STRING_ID 2000000000 +#define MIN_DB_SCRIPT_STRING_ID MAX_TRINITY_STRING_ID // 'db_script_string' +#define MAX_DB_SCRIPT_STRING_ID 2000010000 +#define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts' +#define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000) struct TrinityStringLocale { @@ -942,7 +944,7 @@ class ObjectMgr #define objmgr Trinity::Singleton<ObjectMgr>::Instance() // scripting access functions -TRINITY_DLL_SPEC bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min()); +TRINITY_DLL_SPEC bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits<int32>::min()); TRINITY_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id); TRINITY_DLL_SPEC uint32 GetScriptId(const char *name); TRINITY_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames(); |