From 01b1b4f29638917ca90ebafadf9eba0ad0cd0393 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 18 Feb 2022 13:19:50 -0500 Subject: [PATCH] Core/Spells: Fix assertion triggered Port From (https://github.com/TrinityCore/TrinityCore/commit/e71352db6f50d33de54b757a6af3cbe077136d65) --- Source/Game/Spells/SpellEffects.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 846c5945b..0174a852b 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -3763,10 +3763,21 @@ namespace Game.Spells // This is a blizzlike mistake: this should be 2D distance according to projectile motion formulas, but Blizzard erroneously used 3D distance. float distXY = unitTarget.GetExactDist(pos); + + // Avoid division by 0 + if (distXY < 0.001) + return; + float distZ = pos.GetPositionZ() - unitTarget.GetPositionZ(); float speedXY = effectInfo.MiscValue != 0 ? effectInfo.MiscValue / 10.0f : 30.0f; float speedZ = (float)((2 * speedXY * speedXY * distZ + MotionMaster.gravity * distXY * distXY) / (2 * speedXY * distXY)); + if (!float.IsFinite(speedZ)) + { + Log.outError(LogFilter.Spells, $"Spell {m_spellInfo.Id} with SPELL_EFFECT_PULL_TOWARDS called with invalid speedZ. {GetDebugInfo()}"); + return; + } + unitTarget.JumpTo(speedXY, speedZ, true, pos); } @@ -3788,11 +3799,22 @@ namespace Game.Spells Position pos = m_targets.GetDstPos(); // This is a blizzlike mistake: this should be 2D distance according to projectile motion formulas, but Blizzard erroneously used 3D distance float distXY = unitTarget.GetExactDist(pos); + + // Avoid division by 0 + if (distXY < 0.001) + return; + float distZ = pos.GetPositionZ() - unitTarget.GetPositionZ(); float speedXY = effectInfo.MiscValue != 0 ? effectInfo.MiscValue / 10.0f : 30.0f; float speedZ = (float)((2 * speedXY * speedXY * distZ + MotionMaster.gravity * distXY * distXY) / (2 * speedXY * distXY)); + if (!float.IsFinite(speedZ)) + { + Log.outError(LogFilter.Spells, $"Spell {m_spellInfo.Id} with SPELL_EFFECT_PULL_TOWARDS_DEST called with invalid speedZ. {GetDebugInfo()}"); + return; + } + unitTarget.JumpTo(speedXY, speedZ, true, pos); }