From bcf9476e9600af1abe1558c85463483c8ff8f8ea Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Fri, 19 Feb 2021 18:31:45 +0100 Subject: [PATCH] Core/Spells: restored accidentally dropped spell cast target limit to fix client crashes when hitting more than 255 targets with a single spell --- src/server/game/Server/Packets/SpellPackets.cpp | 14 ++++++++++++++ src/server/game/Server/Packets/SpellPackets.h | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/server/game/Server/Packets/SpellPackets.cpp b/src/server/game/Server/Packets/SpellPackets.cpp index c4570565662..b57ef1d2580 100644 --- a/src/server/game/Server/Packets/SpellPackets.cpp +++ b/src/server/game/Server/Packets/SpellPackets.cpp @@ -121,7 +121,21 @@ ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellCastData con data << uint32(spellCastData.CastTime); if (spellCastData.HitInfo) + { + // Hit and miss target counts are both uint8, that limits us to 255 targets for each + // sending more than 255 targets crashes the client (since count sent would be wrong) + // Spells like 40647 (with a huge radius) can easily reach this limit (spell might need + // target conditions but we still need to limit the number of targets sent and keeping + // correct count for both hit and miss). + static std::size_t const PACKET_TARGET_LIMIT = std::numeric_limits::max(); + if (spellCastData.HitInfo->HitTargets.size() > PACKET_TARGET_LIMIT) + spellCastData.HitInfo->HitTargets.resize(PACKET_TARGET_LIMIT); + + if (spellCastData.HitInfo->MissStatus.size() > PACKET_TARGET_LIMIT) + spellCastData.HitInfo->MissStatus.resize(PACKET_TARGET_LIMIT); + data << *spellCastData.HitInfo; + } data << spellCastData.Target; diff --git a/src/server/game/Server/Packets/SpellPackets.h b/src/server/game/Server/Packets/SpellPackets.h index 56d65be4eca..178f2643c73 100644 --- a/src/server/game/Server/Packets/SpellPackets.h +++ b/src/server/game/Server/Packets/SpellPackets.h @@ -109,7 +109,7 @@ namespace WorldPackets uint32 CastFlagsEx = 0; uint32 CastTime = 0; SpellTargetData Target; - Optional HitInfo; + mutable Optional HitInfo; Optional DestLocSpellCastIndex; Optional Predict; Optional Immunities;