Core/Spells: Replaced assert with startup error log

This commit is contained in:
Shauren
2024-06-17 18:16:59 +02:00
parent 73c5e3b66d
commit 8043b71708
2 changed files with 32 additions and 1 deletions

View File

@@ -42,6 +42,7 @@
#include "Spell.h"
#include "SpellHistory.h"
#include "SpellMgr.h"
#include "SpellScript.h"
#include "ThreatManager.h"
#include "Unit.h"
#include "Util.h"
@@ -935,6 +936,32 @@ void AuraEffect::CalculateSpellMod()
break;
}
GetBase()->CallScriptEffectCalcSpellModHandlers(this, m_spellmod);
// validate modifier
if (m_spellmod)
{
bool isValid = true;
auto logErrors = [&] { return std::ranges::any_of(GetBase()->m_loadedScripts, [](AuraScript const* script) { return script->DoEffectCalcSpellMod.size() > 0; }); };
if (AsUnderlyingType(m_spellmod->op) >= MAX_SPELLMOD)
{
isValid = false;
if (logErrors())
TC_LOG_ERROR("spells.aura.effect", "Aura script for spell id {} created invalid spell modifier op {}", GetId(), AsUnderlyingType(m_spellmod->op));
}
if (m_spellmod->type >= SPELLMOD_END)
{
isValid = false;
if (logErrors())
TC_LOG_ERROR("spells.aura.effect", "Aura script for spell id {} created invalid spell modifier type {}", GetId(), AsUnderlyingType(m_spellmod->type));
}
if (!isValid)
{
delete m_spellmod;
m_spellmod = nullptr;
}
}
}
void AuraEffect::ChangeAmount(int32 newAmount, bool mark, bool onStackOrReapply, AuraEffect const* triggeredBy /* = nullptr */)

View File

@@ -2523,7 +2523,11 @@ void SpellMgr::LoadSpellInfoStore()
case SPELL_AURA_ADD_PCT_MODIFIER:
case SPELL_AURA_ADD_PCT_MODIFIER_BY_SPELL_LABEL:
case SPELL_AURA_ADD_FLAT_MODIFIER_BY_SPELL_LABEL:
ASSERT(effect->EffectMiscValue[0] < MAX_SPELLMOD, "MAX_SPELLMOD must be at least %d", effect->EffectMiscValue[0] + 1);
if (effect->EffectMiscValue[0] >= MAX_SPELLMOD)
{
TC_LOG_ERROR("server.loading", "Invalid spell modifier type {} found on spell {} effect index {}, consider increasing MAX_SPELLMOD",
effect->EffectMiscValue[0], effect->SpellID, effect->EffectIndex);
}
break;
default:
break;