diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index 2995e5032..9cfbd18a3 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -2675,6 +2675,8 @@ namespace Game.Spells return aura; } + public List GetLoadedScripts() { return m_loadedScripts; } + #region Fields List m_loadedScripts = new(); SpellInfo m_spellInfo; diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 1c7dcdb3a..c6478c608 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -334,6 +334,29 @@ namespace Game.Spells break; } GetBase().CallScriptEffectCalcSpellModHandlers(this, ref m_spellmod); + + // validate modifier + if (m_spellmod != null) + { + bool isValid = true; + bool logErrors = GetBase().GetLoadedScripts().Any(script => script.DoEffectCalcSpellMod.Count > 0); + if (m_spellmod.op >= SpellModOp.Max) + { + isValid = false; + if (logErrors) + Log.outError(LogFilter.Spells, $"Aura script for spell id {GetId()} created invalid spell modifier op {m_spellmod.op}"); + } + + if (m_spellmod.type >= SpellModType.End) + { + isValid = false; + if (logErrors) + Log.outError(LogFilter.Spells, $"Aura script for spell id {GetId()} created invalid spell modifier type {m_spellmod.type}"); + } + + if (!isValid) + m_spellmod = null; + } } public void ChangeAmount(int newAmount, bool mark = true, bool onStackOrReapply = false, AuraEffect triggeredBy = null) { diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index 8c4437e9f..8de55bda2 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -2222,6 +2222,8 @@ namespace Game.Entities case AuraType.AddPctModifierBySpellLabel: case AuraType.AddFlatModifierBySpellLabel: Cypher.Assert(effect.EffectMiscValue[0] < (int)SpellModOp.Max, $"MAX_SPELLMOD must be at least {effect.EffectMiscValue[0] + 1}"); + if (effect.EffectMiscValue[0] >= (int)SpellModOp.Max) + Log.outError(LogFilter.ServerLoading, $"Invalid spell modifier type {effect.EffectMiscValue[0]} found on spell {effect.SpellID} effect index {effect.EffectIndex}, consider increasing MAX_SPELLMOD"); break; default: break;