From 7690f02b49c82c65de3e92307063211a2e9941f5 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Thu, 21 Jan 2021 20:49:05 +0100 Subject: [PATCH] feat(Core/Spell): Implement ValidateSpellInfo * Cherry-pick from https://github.com/TrinityCore/TrinityCore/commit/2b5d7eef3a091e67c27e853d43ac0bebbfa67531 & https://github.com/TrinityCore/TrinityCore/commit/a0a158b5b851db7e2c16819ec89e913d914a3aba --- src/server/game/Spells/SpellScript.cpp | 16 ++++++++++++++++ src/server/game/Spells/SpellScript.h | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index 42128ee611..65588300f0 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -20,6 +20,22 @@ bool _SpellScript::_Validate(SpellInfo const* entry) return true; } +bool _SpellScript::_ValidateSpellInfo(uint32 const* begin, uint32 const* end) +{ + bool allValid = true; + while (begin != end) + { + if (!sSpellMgr->GetSpellInfo(*begin)) + { + sLog->outError("_SpellScript::ValidateSpellInfo: Spell %u does not exist.", *begin); + allValid = false; + } + + ++begin; + } + return allValid; +} + void _SpellScript::_Register() { m_currentScriptState = SPELL_SCRIPT_STATE_REGISTRATION; diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 74245592e1..b856578eab 100644 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -110,6 +110,20 @@ public: // Function called when script is destroyed // use for: deallocating memory allocated by script virtual void Unload() {} + // Helpers + static bool ValidateSpellInfo(std::initializer_list spellIds) + { + return _ValidateSpellInfo(spellIds.begin(), spellIds.end()); + } + + template + static bool ValidateSpellInfo(T const& spellIds) + { + return _ValidateSpellInfo(std::begin(spellIds), std::end(spellIds)); + } + +private: + static bool _ValidateSpellInfo(uint32 const* begin, uint32 const* end); }; // SpellScript interface - enum used for runtime checks of script function calls