Skip to content

Commit

Permalink
Remove all references to dbscript_string table
Browse files Browse the repository at this point in the history
Now dbscripts may directly reference broadcast text ids instead
  • Loading branch information
MantisLord committed Sep 14, 2021
1 parent 21318d3 commit b2d149a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 73 deletions.
1 change: 0 additions & 1 deletion src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ ChatCommand* ChatHandler::getCommandTable()
{ "creature_involvedrelation", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCreatureQuestInvRelationsCommand, "", nullptr },
{ "creature_loot_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLootTemplatesCreatureCommand, "", nullptr },
{ "creature_questrelation", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCreatureQuestRelationsCommand, "", nullptr },
{ "dbscript_string", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadDbScriptStringCommand, "", nullptr },
{ "dbscripts_on_creature_death", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadDBScriptsOnCreatureDeathCommand, "", nullptr },
{ "dbscripts_on_event", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadDBScriptsOnEventCommand, "", nullptr },
{ "dbscripts_on_gossip", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadDBScriptsOnGossipCommand, "", nullptr },
Expand Down
1 change: 0 additions & 1 deletion src/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ class ChatHandler
bool HandleReloadCreaturesStatsCommand(char* args);
bool HandleReloadCreatureQuestRelationsCommand(char* args);
bool HandleReloadCreatureQuestInvRelationsCommand(char* args);
bool HandleReloadDbScriptStringCommand(char* args);
bool HandleReloadDBScriptsOnCreatureDeathCommand(char* args);
bool HandleReloadDBScriptsOnEventCommand(char* args);
bool HandleReloadDBScriptsOnGossipCommand(char* args);
Expand Down
9 changes: 0 additions & 9 deletions src/game/Chat/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ bool ChatHandler::HandleReloadAllScriptsCommand(char* /*args*/)
HandleReloadDBScriptsOnSpellCommand((char*)"a");
HandleReloadDBScriptsOnRelayCommand((char*)"a");
SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
HandleReloadDbScriptStringCommand((char*)"a");
return true;
}

Expand Down Expand Up @@ -825,14 +824,6 @@ bool ChatHandler::HandleReloadEventAIScriptsCommand(char* /*args*/)
return true;
}

bool ChatHandler::HandleReloadDbScriptStringCommand(char* /*args*/)
{
sLog.outString("Re-Loading Script strings from `dbscript_string`...");
sScriptMgr.LoadDbScriptStrings();
SendGlobalSysMessage("DB table `dbscript_string` reloaded.");
return true;
}

bool ChatHandler::HandleReloadDBScriptsOnGossipCommand(char* args)
{
if (sScriptMgr.IsScriptScheduled())
Expand Down
59 changes: 18 additions & 41 deletions src/game/DBScripts/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u", tablename, tmp.textId[0], tmp.id);
continue;
}

for (int i = 0; i < MAX_TEXT_ID; ++i)
{
if (tmp.textId[i] && (tmp.textId[i] < MIN_DB_SCRIPT_STRING_ID || tmp.textId[i] >= MAX_DB_SCRIPT_STRING_ID))
{
sLog.outErrorDb("Table `%s` has out of range text_id%u (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u", tablename, i + 1, tmp.textId[i], MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, tmp.id);
}
}
}

// if (!GetMangosStringLocale(tmp.dataint)) will be checked after dbscript_string loading
break;
}
case SCRIPT_COMMAND_EMOTE: // 1
Expand Down Expand Up @@ -963,31 +953,19 @@ void ScriptMgr::LoadRelayScripts()

void ScriptMgr::LoadDbScriptStrings()
{
// load both dbscript_strings and creature_ai_texts here because either may be referenced by dbscript_random_templates
sObjectMgr.LoadMangosStrings(WorldDatabase, "dbscript_string", MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, true);
// load creature_ai_texts here because it may be referenced by dbscript_random_templates
sObjectMgr.LoadMangosStrings(WorldDatabase, "creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID, true);

std::set<int32> ids;

for (int32 i = MIN_DB_SCRIPT_STRING_ID; i < MAX_DB_SCRIPT_STRING_ID; ++i)
if (sObjectMgr.GetMangosStringLocale(i))
ids.insert(i);

CheckRandomStringTemplates(ids);

CheckScriptTexts(sQuestEndScripts, ids);
CheckScriptTexts(sQuestStartScripts, ids);
CheckScriptTexts(sSpellScripts, ids);
CheckScriptTexts(sGameObjectScripts, ids);
CheckScriptTexts(sGameObjectTemplateScripts, ids);
CheckScriptTexts(sEventScripts, ids);
CheckScriptTexts(sGossipScripts, ids);
CheckScriptTexts(sCreatureDeathScripts, ids);
CheckScriptTexts(sCreatureMovementScripts, ids);
CheckScriptTexts(sRelayScripts, ids);

for (int32 id : ids)
sLog.outErrorDb("Table `dbscript_string` has unused string id %u", id);
CheckScriptTexts(sQuestEndScripts);
CheckScriptTexts(sQuestStartScripts);
CheckScriptTexts(sSpellScripts);
CheckScriptTexts(sGameObjectScripts);
CheckScriptTexts(sGameObjectTemplateScripts);
CheckScriptTexts(sEventScripts);
CheckScriptTexts(sGossipScripts);
CheckScriptTexts(sCreatureDeathScripts);
CheckScriptTexts(sCreatureMovementScripts);
CheckScriptTexts(sRelayScripts);
}

void ScriptMgr::LoadDbScriptRandomTemplates()
Expand Down Expand Up @@ -1037,7 +1015,7 @@ void ScriptMgr::CheckRandomRelayTemplates()
sLog.outErrorDb("Table `dbscript_random_templates` entry (%u) uses nonexistent relay ID (%u).", templateData.first, data.first);
}

void ScriptMgr::CheckScriptTexts(ScriptMapMapName const& scripts, std::set<int32>& ids)
void ScriptMgr::CheckScriptTexts(ScriptMapMapName const& scripts)
{
for (ScriptMapMap::const_iterator itrMM = scripts.second.begin(); itrMM != scripts.second.end(); ++itrMM)
{
Expand All @@ -1047,20 +1025,19 @@ void ScriptMgr::CheckScriptTexts(ScriptMapMapName const& scripts, std::set<int32
{
for (int i : itrM->second.textId)
{
if (i && !sObjectMgr.GetMangosStringLocale(i))
sLog.outErrorDb("Table `dbscript_string` is missing string id %u, used in database script table %s id %u.", i, scripts.first, itrMM->first);

if (ids.find(i) != ids.end())
ids.erase(i);
if (i && !sObjectMgr.GetBroadcastText(i))
sLog.outErrorDb("Table `broadcast_text` is missing string id %u, used in database script table %s id %u.", i, scripts.first, itrMM->first);
}

if (itrM->second.talk.stringTemplateId)
{
auto& vector = m_scriptTemplates[STRING_TEMPLATE][itrM->second.talk.stringTemplateId];
for (auto& data : vector)
{
if (!sObjectMgr.GetMangosStringLocale(data.first))
sLog.outErrorDb("Table `%s` is missing string id %d, used in database script template table dbscript_random_templates id %u.", itrM->second.talk.stringTemplateId > 0 ? "dbscript_string" : "creature_ai_texts", data.first, itrM->second.talk.stringTemplateId);
if (data.first < 0 && !sObjectMgr.GetMangosStringLocale(data.first))
sLog.outErrorDb("Table `creature_ai_texts` is missing string id %d, used in database script template table dbscript_random_templates id %u.", data.first, itrM->second.talk.stringTemplateId);
else if (data.first > 0 && !sObjectMgr.GetBroadcastText(data.first))
sLog.outErrorDb("Table `broadcast_text` is missing string id %d, used in database script template table dbscript_random_templates id %u.", data.first, itrM->second.talk.stringTemplateId);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/DBScripts/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct SpellEntry;
enum ScriptCommand // resSource, resTarget are the resulting Source/ Target after buddy search is done
{
SCRIPT_COMMAND_TALK = 0, // resSource = WorldObject, resTarget = Unit/none
// dataint = text entry from dbscript_string -table. dataint2-4 optional for random selected texts.
// dataint = text id from broadcast_text table. dataint2-4 optional for random selected texts.
SCRIPT_COMMAND_EMOTE = 1, // resSource = Unit, resTarget = Unit/none
// datalong1 = emote_id, dataint1-4 optional for random selected emotes
SCRIPT_COMMAND_FIELD_SET = 2, // source = any, datalong = field_id, datalong2 = value
Expand Down Expand Up @@ -631,7 +631,7 @@ class ScriptMgr

private:
void LoadScripts(ScriptMapMapName& scripts, const char* tablename);
void CheckScriptTexts(ScriptMapMapName const& scripts, std::set<int32>& ids);
void CheckScriptTexts(ScriptMapMapName const& scripts);

typedef std::vector<std::string> ScriptNameMap;
typedef std::unordered_map<uint32, uint32> AreaTriggerScriptMap;
Expand Down
12 changes: 0 additions & 12 deletions src/game/Globals/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7992,10 +7992,6 @@ inline void _DoStringError(int32 entry, char const* text, ...)
sLog.outErrorScriptLib("%s", buf);
else if (entry <= MIN_CREATURE_AI_TEXT_STRING_ID) // eventAI error
sLog.outErrorEventAI("%s", buf);
else if (entry < MIN_DB_SCRIPT_STRING_ID) // mangos string error
sLog.outError("%s", buf);
else // if (entry > MIN_DB_SCRIPT_STRING_ID) // DB script text error
sLog.outErrorDb("DB-SCRIPTS: %s", buf);
}

bool ObjectMgr::LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value, bool extra_content)
Expand Down Expand Up @@ -9426,14 +9422,6 @@ void ObjectMgr::GetAreaTriggerLocales(uint32 entry, int32 loc_idx, std::string*
// Functions for scripting access
bool LoadMangosStrings(DatabaseType& db, char const* table, int32 start_value, int32 end_value, bool extra_content)
{
// 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 reserved by mangos range (%d - %d), strings not loaded.", table, start_value, end_value + 1);
return false;
}

return sObjectMgr.LoadMangosStrings(db, table, start_value, end_value, extra_content);
}

Expand Down
4 changes: 0 additions & 4 deletions src/game/Globals/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,10 @@ typedef std::unordered_map<uint32/*(mapid,spawnMode) pair*/, CellObjectGuidsMap>
// mangos string ranges
#define MIN_MANGOS_STRING_ID 1 // 'mangos_string'
#define MAX_MANGOS_STRING_ID 2000000000
#define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID // 'dbscript_string'
#define MAX_DB_SCRIPT_STRING_ID 2001000000
#define MIN_CREATURE_AI_TEXT_STRING_ID (-1) // 'creature_ai_texts'
#define MAX_CREATURE_AI_TEXT_STRING_ID (-1000000)
// Anything below MAX_CREATURE_AI_TEXT_STRING_ID is handled by the external script lib

static_assert(MAX_DB_SCRIPT_STRING_ID < INT_MAX, "Must scope with int32 range");

struct MangosStringLocale
{
MangosStringLocale() : SoundId(0), Type(0), LanguageId(LANG_UNIVERSAL), Emote(0), broadcastText(nullptr) { }
Expand Down
2 changes: 0 additions & 2 deletions src/game/Tools/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,5 @@ enum MangosStrings
// Use for custom patches 11000-11999

// NOT RESERVED IDS 12000-1999999999
// `dbscript_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID)
// For other tables maybe 2001000000-2147483647 (max index)
};
#endif
2 changes: 1 addition & 1 deletion src/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void World::SetInitialWorldSettings()
sLog.outString("Loading faction_store...");
sObjectMgr.LoadFactions();

// Load before npc_text, gossip_menu_option, script_texts, creature_ai_texts, dbscript_string
// Load before npc_text, gossip_menu_option, script_texts, creature_ai_texts
sLog.outString("Loading broadcast_text...");
sObjectMgr.LoadBroadcastText();

Expand Down

0 comments on commit b2d149a

Please sign in to comment.