From fca967c8278b6d908888f72ef5d204bec95c1eaa Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:29:02 -0600 Subject: [PATCH] refactor(spell): test a spell's auras through one HasAuraEffect Six places asked the same question of a Spell.dbc record: does one of its three effects apply aura N (EffectApplyAuraName, +0x16C, int32[3])? Each had its own loop: the combat log's damage-shield lookup, crowd-control classification and its snare test, tracking-spell detection, C_SpellBook.GetPlayerSpellsByAura, and the aura-source periodic-damage gate (which also hard-coded 3 for the effect count). Spell::Lookup now has FindAuraEffect (the index of the first effect that applies the aura, or -1, for callers that read that effect's other columns) and HasAuraEffect on top of it, next to the existing HasEffect. All six call it. Code that pairs an aura with the same effect's misc value, amount or effect code (Cancel, Interruptible, BonusDamage, StatAccum, EffectInfo) keeps its own per-effect reads. --- src/aura/Source.cpp | 11 ++--------- src/combatlog/Entry.cpp | 11 ----------- src/combatlog/Entry.h | 4 ---- src/combatlog/Packets.cpp | 3 ++- src/spell/CrowdControl.cpp | 16 ++-------------- src/spell/Info.cpp | 14 +++++--------- src/spell/Lookup.cpp | 15 +++++++++++++++ src/spell/Lookup.h | 9 +++++++++ src/spell/Tracking.cpp | 13 +++---------- 9 files changed, 38 insertions(+), 58 deletions(-) diff --git a/src/aura/Source.cpp b/src/aura/Source.cpp index a5b7a576..ea56088e 100644 --- a/src/aura/Source.cpp +++ b/src/aura/Source.cpp @@ -1023,16 +1023,9 @@ CompressState *FindOrClaimCompressState(uint64_t targetGuid, // would compress it, this gate excludes it exactly as the server's does. // (Drain Soul passes via its effect-2 periodic damage: aura=[86,3,0].) bool HasPeriodicDamageOrLeech(const uint8_t *rec) { - if (rec == nullptr) - return false; constexpr int32_t kPeriodicDamage = 3, kPeriodicLeech = 53; - for (int i = 0; i < 3; ++i) { - const int32_t aura = *reinterpret_cast( - rec + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME + i * 4); - if (aura == kPeriodicDamage || aura == kPeriodicLeech) - return true; - } - return false; + return Spell::Lookup::HasAuraEffect(rec, kPeriodicDamage) || + Spell::Lookup::HasAuraEffect(rec, kPeriodicLeech); } // Compression pairs by CASTER, mirroring the server (each warlock's Dark diff --git a/src/combatlog/Entry.cpp b/src/combatlog/Entry.cpp index 75a6e208..e27359db 100644 --- a/src/combatlog/Entry.cpp +++ b/src/combatlog/Entry.cpp @@ -618,17 +618,6 @@ uint32_t SpellSchoolMask(const uint8_t *spell) { : 0; } -bool HasAuraEffect(const uint8_t *spell, int auraName) { - if (spell == nullptr) - return false; - for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { - if (Game::Read(spell, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME + i * 4) == - auraName) - return true; - } - return false; -} - Entry Begin(uint64_t source, uint64_t dest, int event, const uint8_t *spell) { Entry e; e.event = event; diff --git a/src/combatlog/Entry.h b/src/combatlog/Entry.h index 6f2c4933..336d3e08 100644 --- a/src/combatlog/Entry.h +++ b/src/combatlog/Entry.h @@ -167,10 +167,6 @@ uint32_t SchoolMask(uint32_t school); // The spell's school as a mask (4.3.4's SpellRec m_schoolMask), 0 for nullptr. uint32_t SpellSchoolMask(const uint8_t *spell); -// Whether one of the spell's three effects applies the aura `auraName` -// (EffectApplyAuraName). -bool HasAuraEffect(const uint8_t *spell, int auraName); - // GetCombatLogEntry: an entry for `event` from `source` to `dest` (either may // be 0), with the spell prefix when `spell` is a record. Entry Begin(uint64_t source, uint64_t dest, int event, const uint8_t *spell); diff --git a/src/combatlog/Packets.cpp b/src/combatlog/Packets.cpp index e876ff55..b1218635 100644 --- a/src/combatlog/Packets.cpp +++ b/src/combatlog/Packets.cpp @@ -55,6 +55,7 @@ #include "aura/Data.h" #include "net/PacketDispatch.h" #include "object/Resolve.h" +#include "spell/Lookup.h" #include "time/Clock.h" #include @@ -501,7 +502,7 @@ const uint8_t *ShieldSpell(uint64_t owner, uint32_t school) { const uint8_t *spell = SpellRecord(static_cast(spellId)); if (spell == nullptr || Game::Read(spell, Offsets::OFF_SPELL_RECORD_SCHOOL) != school || - !HasAuraEffect(spell, AURA_DAMAGE_SHIELD)) + !Spell::Lookup::HasAuraEffect(spell, AURA_DAMAGE_SHIELD)) continue; if (found != nullptr && found != spell) return nullptr; diff --git a/src/spell/CrowdControl.cpp b/src/spell/CrowdControl.cpp index ca07bfa5..61c42b89 100644 --- a/src/spell/CrowdControl.cpp +++ b/src/spell/CrowdControl.cpp @@ -21,14 +21,7 @@ namespace Spell::CrowdControl { const char *Classify(const uint8_t *rec) { if (rec == nullptr) return nullptr; - const int32_t *aura = reinterpret_cast( - rec + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - auto has = [&](int type) { - for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) - if (aura[i] == type) - return true; - return false; - }; + auto has = [rec](int type) { return Spell::Lookup::HasAuraEffect(rec, type); }; if (has(Offsets::SPELL_AURA_MOD_POSSESS)) return "POSSESS"; if (has(Offsets::SPELL_AURA_MOD_CHARM)) return "CHARM"; if (has(Offsets::SPELL_AURA_MOD_STUN)) return "STUN"; @@ -50,12 +43,7 @@ bool IsCrowdControl(uint32_t spellID) { // slows / snares, which `Classify` (the LoC set) deliberately excludes. if (Classify(rec) != nullptr) return true; - const int32_t *aura = reinterpret_cast( - rec + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) - if (aura[i] == Offsets::SPELL_AURA_MOD_DECREASE_SPEED) - return true; - return false; + return Spell::Lookup::HasAuraEffect(rec, Offsets::SPELL_AURA_MOD_DECREASE_SPEED); } } // namespace Spell::CrowdControl diff --git a/src/spell/Info.cpp b/src/spell/Info.cpp index c3de5515..a95968ba 100644 --- a/src/spell/Info.cpp +++ b/src/spell/Info.cpp @@ -534,15 +534,11 @@ static int __fastcall Script_GetPlayerSpellsByAura(void *L) { int n = 0; ForEachKnownSpell([&](int spellID, const uint8_t *record) { - auto *auras = reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - for (int e = 0; e < Offsets::SPELL_RECORD_EFFECT_COUNT; ++e) { - if (auras[e] == auraName) { - Game::Lua::PushNumber(L, static_cast(++n)); - Game::Lua::PushNumber(L, static_cast(spellID)); - Game::Lua::RawSet(L, -3); - break; // one entry per spell, however many effects match - } + // One entry per spell, however many effects match. + if (Spell::Lookup::HasAuraEffect(record, auraName)) { + Game::Lua::PushNumber(L, static_cast(++n)); + Game::Lua::PushNumber(L, static_cast(spellID)); + Game::Lua::RawSet(L, -3); } return true; }); diff --git a/src/spell/Lookup.cpp b/src/spell/Lookup.cpp index 7db66f0c..4adcb229 100644 --- a/src/spell/Lookup.cpp +++ b/src/spell/Lookup.cpp @@ -62,6 +62,21 @@ bool HasEffect(const uint8_t *spellRecord, int effect) { return false; } +int FindAuraEffect(const uint8_t *spellRecord, int aura) { + if (spellRecord == nullptr) + return -1; + for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { + if (Game::Read(spellRecord, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME + i * 4) == + aura) + return i; + } + return -1; +} + +bool HasAuraEffect(const uint8_t *spellRecord, int aura) { + return FindAuraEffect(spellRecord, aura) >= 0; +} + int SpellbookSlotToID(int slot1Based, int bookType) { const int slot = slot1Based - 1; if (slot < 0 || slot >= Offsets::SPELLBOOK_MAX_SLOTS) diff --git a/src/spell/Lookup.h b/src/spell/Lookup.h index 3faab6ed..656579bd 100644 --- a/src/spell/Lookup.h +++ b/src/spell/Lookup.h @@ -35,6 +35,15 @@ bool IsFitToFamily(const uint8_t *spellRecord, uint32_t family, // SpellHasEffect. False for a null record. bool HasEffect(const uint8_t *spellRecord, int effect); +// The index (0..2) of the first of the spell's three effects that applies +// the aura `aura` (EffectApplyAuraName), or -1 when none does or the record +// is null. For reading that effect's other columns (its misc value, ...). +int FindAuraEffect(const uint8_t *spellRecord, int aura); + +// Whether one of the spell's three effects applies the aura `aura` — +// 4.3.4's SpellHasAuraEffect. False for a null record. +bool HasAuraEffect(const uint8_t *spellRecord, int aura); + // Resolves a 1-based Lua-facing spellbook slot to the spellID stored // there. `bookType` is `0` for the player spellbook, `1` for the pet // spellbook (matches the engine's encoding from `Script_GetSpellName`). diff --git a/src/spell/Tracking.cpp b/src/spell/Tracking.cpp index 87ca29d2..d39236cc 100644 --- a/src/spell/Tracking.cpp +++ b/src/spell/Tracking.cpp @@ -46,16 +46,9 @@ static constexpr int32_t AURA_TRACK_STEALTHED = 151; // True iff `spellID`'s record has any of the three Track* effects. static bool IsTrackingSpell(int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); - if (record == nullptr) - return false; - auto *aura = Game::Ptr( - record, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { - if (aura[i] == AURA_TRACK_CREATURES || aura[i] == AURA_TRACK_RESOURCES || - aura[i] == AURA_TRACK_STEALTHED) - return true; - } - return false; + return Spell::Lookup::HasAuraEffect(record, AURA_TRACK_CREATURES) || + Spell::Lookup::HasAuraEffect(record, AURA_TRACK_RESOURCES) || + Spell::Lookup::HasAuraEffect(record, AURA_TRACK_STEALTHED); } // Walks the player spellbook in slot order counting tracking spells. If