mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-03 02:53:48 +00:00
feat(Core/Hooks): Add OnAfterDatabaseLoadCreatureTemplates hook (#17621)
* Add OnAfterDatabaseLoadCreatureTemplates hook - fix issue where the fast template cache was not updated correctly after a CS reload of a single creature template * Parameter naming tweak to reduce confusion. * Refactor to streamline fastcache creation, remove threading concerns * Remove unneeded resize when loading creature templates * Update fast cache resizing to highest-performing option
This commit is contained in:
@@ -591,7 +591,7 @@ void ObjectMgr::LoadCreatureTemplates()
|
|||||||
"ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, ctm.InteractionPauseTimer, HoverHeight, HealthModifier, ManaModifier, ArmorModifier, ExperienceModifier, "
|
"ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, ctm.InteractionPauseTimer, HoverHeight, HealthModifier, ManaModifier, ArmorModifier, ExperienceModifier, "
|
||||||
// 64 65 66 67 68 69 70
|
// 64 65 66 67 68 69 70
|
||||||
"RacialLeader, movementId, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName "
|
"RacialLeader, movementId, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName "
|
||||||
"FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId;");
|
"FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId ORDER BY entry DESC;");
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -600,6 +600,7 @@ void ObjectMgr::LoadCreatureTemplates()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_creatureTemplateStore.rehash(result->GetRowCount());
|
_creatureTemplateStore.rehash(result->GetRowCount());
|
||||||
|
_creatureTemplateStoreFast.clear();
|
||||||
|
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
do
|
do
|
||||||
@@ -609,20 +610,7 @@ void ObjectMgr::LoadCreatureTemplates()
|
|||||||
++count;
|
++count;
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
|
|
||||||
// pussywizard:
|
sScriptMgr->OnAfterDatabaseLoadCreatureTemplates(_creatureTemplateStoreFast);
|
||||||
{
|
|
||||||
uint32 max = 0;
|
|
||||||
for (CreatureTemplateContainer::const_iterator itr = _creatureTemplateStore.begin(); itr != _creatureTemplateStore.end(); ++itr)
|
|
||||||
if (itr->first > max)
|
|
||||||
max = itr->first;
|
|
||||||
if (max)
|
|
||||||
{
|
|
||||||
_creatureTemplateStoreFast.clear();
|
|
||||||
_creatureTemplateStoreFast.resize(max + 1, nullptr);
|
|
||||||
for (CreatureTemplateContainer::iterator itr = _creatureTemplateStore.begin(); itr != _creatureTemplateStore.end(); ++itr)
|
|
||||||
_creatureTemplateStoreFast[itr->first] = &(itr->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadCreatureTemplateResistances();
|
LoadCreatureTemplateResistances();
|
||||||
LoadCreatureTemplateSpells();
|
LoadCreatureTemplateSpells();
|
||||||
@@ -638,12 +626,28 @@ void ObjectMgr::LoadCreatureTemplates()
|
|||||||
LOG_INFO("server.loading", " ");
|
LOG_INFO("server.loading", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMgr::LoadCreatureTemplate(Field* fields)
|
/**
|
||||||
|
* @brief Loads a creature template from a database result
|
||||||
|
*
|
||||||
|
* @param fields Database result
|
||||||
|
* @param triggerHook If true, will trigger the OnAfterDatabaseLoadCreatureTemplates hook. Useful if you are not calling the hook yourself.
|
||||||
|
*/
|
||||||
|
void ObjectMgr::LoadCreatureTemplate(Field* fields, bool triggerHook)
|
||||||
{
|
{
|
||||||
uint32 entry = fields[0].Get<uint32>();
|
uint32 entry = fields[0].Get<uint32>();
|
||||||
|
|
||||||
CreatureTemplate& creatureTemplate = _creatureTemplateStore[entry];
|
CreatureTemplate& creatureTemplate = _creatureTemplateStore[entry];
|
||||||
|
|
||||||
|
// enlarge the fast cache as necessary
|
||||||
|
if (_creatureTemplateStoreFast.size() < entry + 1)
|
||||||
|
{
|
||||||
|
_creatureTemplateStoreFast.resize(entry + 1, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load a pointer to this creatureTemplate into the fast cache
|
||||||
|
_creatureTemplateStoreFast[entry] = &creatureTemplate;
|
||||||
|
|
||||||
|
// build the creatureTemplate
|
||||||
creatureTemplate.Entry = entry;
|
creatureTemplate.Entry = entry;
|
||||||
|
|
||||||
for (uint8 i = 0; i < MAX_DIFFICULTY - 1; ++i)
|
for (uint8 i = 0; i < MAX_DIFFICULTY - 1; ++i)
|
||||||
@@ -750,6 +754,13 @@ void ObjectMgr::LoadCreatureTemplate(Field* fields)
|
|||||||
creatureTemplate.SpellSchoolImmuneMask = fields[68].Get<uint8>();
|
creatureTemplate.SpellSchoolImmuneMask = fields[68].Get<uint8>();
|
||||||
creatureTemplate.flags_extra = fields[69].Get<uint32>();
|
creatureTemplate.flags_extra = fields[69].Get<uint32>();
|
||||||
creatureTemplate.ScriptID = GetScriptId(fields[70].Get<std::string>());
|
creatureTemplate.ScriptID = GetScriptId(fields[70].Get<std::string>());
|
||||||
|
|
||||||
|
// useful if the creature template load is being triggered from outside this class
|
||||||
|
if (triggerHook)
|
||||||
|
{
|
||||||
|
sScriptMgr->OnAfterDatabaseLoadCreatureTemplates(_creatureTemplateStoreFast);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMgr::LoadCreatureTemplateResistances()
|
void ObjectMgr::LoadCreatureTemplateResistances()
|
||||||
|
|||||||
@@ -1020,7 +1020,7 @@ public:
|
|||||||
void LoadCreatureClassLevelStats();
|
void LoadCreatureClassLevelStats();
|
||||||
void LoadCreatureLocales();
|
void LoadCreatureLocales();
|
||||||
void LoadCreatureTemplates();
|
void LoadCreatureTemplates();
|
||||||
void LoadCreatureTemplate(Field* fields);
|
void LoadCreatureTemplate(Field* fields, bool triggerHook = false);
|
||||||
void LoadCreatureTemplateAddons();
|
void LoadCreatureTemplateAddons();
|
||||||
void LoadCreatureTemplateResistances();
|
void LoadCreatureTemplateResistances();
|
||||||
void LoadCreatureTemplateSpells();
|
void LoadCreatureTemplateSpells();
|
||||||
|
|||||||
@@ -25,3 +25,11 @@ void ScriptMgr::OnAfterDatabasesLoaded(uint32 updateFlags)
|
|||||||
script->OnAfterDatabasesLoaded(updateFlags);
|
script->OnAfterDatabasesLoaded(updateFlags);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptMgr::OnAfterDatabaseLoadCreatureTemplates(std::vector<CreatureTemplate*> creatureTemplates)
|
||||||
|
{
|
||||||
|
ExecuteScript<DatabaseScript>([&](DatabaseScript* script)
|
||||||
|
{
|
||||||
|
script->OnAfterDatabaseLoadCreatureTemplates(creatureTemplates);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -2024,7 +2024,20 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] bool IsDatabaseBound() const override { return false; }
|
[[nodiscard]] bool IsDatabaseBound() const override { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called after all databases are loaded
|
||||||
|
*
|
||||||
|
* @param updateFlags Update flags from the loader
|
||||||
|
*/
|
||||||
virtual void OnAfterDatabasesLoaded(uint32 /*updateFlags*/) { }
|
virtual void OnAfterDatabasesLoaded(uint32 /*updateFlags*/) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called after all creature template data has been loaded from the database. This hook could be called multiple times, not just at server startup.
|
||||||
|
*
|
||||||
|
* @param creatureTemplates Pointer to a modifiable vector of creature templates. Indexed by Entry ID.
|
||||||
|
*/
|
||||||
|
virtual void OnAfterDatabaseLoadCreatureTemplates(std::vector<CreatureTemplate*> /*creatureTemplates*/) { }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WorldObjectScript : public ScriptObject
|
class WorldObjectScript : public ScriptObject
|
||||||
@@ -2671,6 +2684,7 @@ public: /* CommandSC */
|
|||||||
public: /* DatabaseScript */
|
public: /* DatabaseScript */
|
||||||
|
|
||||||
void OnAfterDatabasesLoaded(uint32 updateFlags);
|
void OnAfterDatabasesLoaded(uint32 updateFlags);
|
||||||
|
void OnAfterDatabaseLoadCreatureTemplates(std::vector<CreatureTemplate*> creatureTemplateStore);
|
||||||
|
|
||||||
public: /* WorldObjectScript */
|
public: /* WorldObjectScript */
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ public:
|
|||||||
|
|
||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
sObjectMgr->LoadCreatureTemplate(fields);
|
sObjectMgr->LoadCreatureTemplate(fields, true);
|
||||||
sObjectMgr->CheckCreatureTemplate(cInfo);
|
sObjectMgr->CheckCreatureTemplate(cInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user