diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 56bccc947..771d582ef 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 5961e0995..bd3631a75 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 - LoadMangosStrings(WorldDatabase,"creature_ai_texts",-1,1+(TEXT_SOURCE_RANGE)); + objmgr.LoadMangosStrings(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.GetMangosStringLocale(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 e70902299..5cb337b3e 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -6524,10 +6524,35 @@ void ObjectMgr::LoadGameObjectForQuests() bool ObjectMgr::LoadMangosStrings(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(MangosStringLocaleMap::iterator itr = mMangosStringLocaleMap.begin(); itr != mMangosStringLocaleMap.end();) { - if(itr->first >= min_value && itr->first <= max_value) + if (itr->first >= start_value && itr->first < end_value) { MangosStringLocaleMap::iterator itr2 = itr; ++itr; @@ -6539,14 +6564,14 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min 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_MANGOS_STRING_ID) // error only in case internal strings + if (min_value == MIN_MANGOS_STRING_ID) // error only in case internal strings sLog.outErrorDb(">> Loaded 0 mangos strings. DB table `%s` is empty. Cannot continue.",table); else sLog.outString(">> Loaded 0 string templates. DB table `%s` is empty.",table); @@ -6564,22 +6589,20 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min 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; } MangosStringLocale& data = mMangosStringLocaleMap[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; @@ -6594,13 +6617,13 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min 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; @@ -6612,7 +6635,7 @@ bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min delete result; sLog.outString(); - if(min_value == MIN_MANGOS_STRING_ID) // error only in case internal strings + if (min_value == MIN_MANGOS_STRING_ID) sLog.outString( ">> Loaded %u MaNGOS strings from table %s", count,table); else sLog.outString( ">> Loaded %u string templates from %s", count,table); @@ -7550,15 +7573,15 @@ uint32 GetAreaTriggerScriptId(uint32 trigger_id) bool LoadMangosStrings(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::min()); - start_value = -1; - end_value = std::numeric_limits::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.LoadMangosStrings(db,table,end_value,start_value); + return objmgr.LoadMangosStrings(db,table,start_value,end_value); } uint32 MANGOS_DLL_SPEC GetScriptId(const char *name) diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 037148be6..d2cb1a766 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -136,10 +136,12 @@ typedef UNORDERED_MAP RespawnTimes; // mangos string ranges -#define MIN_MANGOS_STRING_ID 1 -#define MAX_MANGOS_STRING_ID 2000000000 -#define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID -#define MAX_DB_SCRIPT_STRING_ID 2000010000 +#define MIN_MANGOS_STRING_ID 1 // 'mangos_string' +#define MAX_MANGOS_STRING_ID 2000000000 +#define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_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 MangosStringLocale { @@ -885,7 +887,7 @@ class ObjectMgr #define objmgr MaNGOS::Singleton::Instance() // scripting access functions -MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits::min()); +MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits::min()); MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id); MANGOS_DLL_SPEC uint32 GetScriptId(const char *name); MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 821e79162..b7c7183d5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7833" + #define REVISION_NR "7834" #endif // __REVISION_NR_H__