From b496568670cfeaeadb19081679b9e52c2e0082c5 Mon Sep 17 00:00:00 2001
From: Brues <5278969+brues-code@users.noreply.github.com>
Date: Sun, 26 Jul 2026 15:42:25 -0500
Subject: [PATCH] Add C_Spell.GetSpellEffectMechanics(spellID)
Returns the spell's three per-effect SpellMechanic ids (Spell.dbc
EffectMechanic[3], +0x13C) as a 1-based array, or nil for an invalid spell.
Complements GetSpellMechanicByID, which reads only the spell-level Mechanic
field (+0x14): vanilla stores some mechanics on an effect instead -- e.g.
Rake's bleed is effect-level (spell-level 0, EffectMechanic[2]=15), so
GetSpellMechanicByID misses it while this returns {0,15,0}.
Add OFF_SPELL_RECORD_EFFECT_MECHANIC offset, API.md section + TOC entry, and
README index entry.
---
README.md | 2 +-
docs/API.md | 36 +++++++++++++++++
src/Offsets.h | 6 +++
src/spell/EffectMechanic.cpp | 76 ++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 1 deletion(-)
create mode 100644 src/spell/EffectMechanic.cpp
diff --git a/README.md b/README.md
index ed993371..7071791b 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
| [NewItems](docs/API.md#newitems) | `C_NewItems.ClearAll`, `C_NewItems.IsNewItem`, `C_NewItems.RemoveNewItem` |
| [PlayerInfo](docs/API.md#playerinfo) | `C_PlayerInfo.CanUseItem`, `C_PlayerInfo.GetClass`, `C_PlayerInfo.GetName`, `C_PlayerInfo.GetRace`, `C_PlayerInfo.GetSex`, `C_PlayerInfo.GUIDIsCreature`, `C_PlayerInfo.GUIDIsGameObject`, `C_PlayerInfo.GUIDIsPet`, `C_PlayerInfo.GUIDIsPlayer`, `C_PlayerInfo.IsConnected` |
| [Quest](docs/API.md#quest) | `C_QuestLog.GetNumQuestObjectives`, `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetHeaderIndexForQuest`, `C_QuestLog.GetLogIndexForQuestID`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
-| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLevelInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellRequiredTargetLevel`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellInRange`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CanDualWield`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellBonusDamage`, `GetSpellBonusHealing`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellRequiredTargetLevel`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
+| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellEffectMechanics`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLevelInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellRequiredTargetLevel`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellInRange`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CanDualWield`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellBonusDamage`, `GetSpellBonusHealing`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellRequiredTargetLevel`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
| [SpellBook](docs/API.md#spellbook) | `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSkillLineName`, `C_SpellBook.GetSkillLineRank`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `C_SpellBook.IsAutoAttackSpellBookItem`, `C_SpellBook.IsRangedAutoAttackSpellBookItem`, `FindSpellBookSlotByID` |
| [State](docs/API.md#state) | `CancelShapeshiftForm`, `Dismount`, `GetMirrorTimerInfo`, `GetMirrorTimerProgress`, `GetShapeshiftFormID`, `IsAssistingRitual`, `IsFalling`, `IsInGroup`, `IsInRaid`, `IsLoggedIn`, `IsMounted`, `IsStealthed`, `IsSwimming` |
| [System](docs/API.md#system) | `CopyToClipboard`, `GetPhysicalScreenSize` |
diff --git a/docs/API.md b/docs/API.md
index 9f639246..bad53442 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -402,6 +402,7 @@ build instructions.
- [`C_Spell.GetSpellLink(spellID)`](#c_spellgetspelllinkspellid)
- [`C_Spell.GetSpellDescription(spellID)`](#c_spellgetspelldescriptionspellid)
- [`C_Spell.GetSpellMechanicByID(spellID)`](#c_spellgetspellmechanicbyidspellid)
+ - [`C_Spell.GetSpellEffectMechanics(spellID)`](#c_spellgetspelleffectmechanicsspellid)
- [`C_Spell.GetSpellRadius(spellID)` / `GetSpellRadius(slot, bookType)`](#c_spellgetspellradiusspellid--getspellradiusslot-booktype)
- [`C_Spell.GetSpellPowerCost(spellIdentifier)`](#c_spellgetspellpowercostspellidentifier)
- [`C_Spell.GetSpellReagents(spellID)`](#c_spellgetspellreagentsspellid)
@@ -9639,6 +9640,41 @@ column is exactly what this function returns):
> `14` (incapacitated) in 1.12 — the `30` ("sapped") value used by some
> addon tables is a later-expansion addition and has no row here.
+### `C_Spell.GetSpellEffectMechanics(spellID)`
+
+Returns the spell's three per-effect `SpellMechanic` ids (`Spell.dbc`
+`EffectMechanic[3]`) as a 1-based array table, or `nil` for an invalid /
+out-of-range spell ID. Each entry uses the same numbering as
+[`GetSpellMechanicByID`](#c_spellgetspellmechanicbyidspellid) (`0` = that
+effect carries no mechanic).
+
+```lua
+C_Spell.GetSpellEffectMechanics(1822) -- Rake → { 0, 15, 0 }
+C_Spell.GetSpellEffectMechanics(703) -- Garrote → { 0, 0, 0 }
+C_Spell.GetSpellEffectMechanics(133) -- Fireball → { 0, 0, 0 }
+```
+
+Complements [`GetSpellMechanicByID`](#c_spellgetspellmechanicbyidspellid),
+which reads only the **spell-level** `Mechanic` field (`+0x14`). Vanilla
+frequently stores a spell's mechanic on an **effect** instead — periodic
+damage such as bleeds is the common case. Garrote/Rupture/Rend/Rip tag
+`bleeding` (15) at the spell level, but **Rake** has spell-level `0` and
+`EffectMechanic[2] = 15`, so effect-mechanic-aware callers (e.g. bleed
+classification for immunity tracking) need this array:
+
+```lua
+local function IsBleed(spellID)
+ if C_Spell.GetSpellMechanicByID(spellID) == 15 then return true end
+ local em = C_Spell.GetSpellEffectMechanics(spellID)
+ if em then for i = 1, 3 do if em[i] == 15 then return true end end end
+ return false
+end
+```
+
+Reads `Spell.dbc` directly (`EffectMechanic[3]` at `+0x13C`), so it covers
+every spell the client knows — not just the player's spellbook — with no
+caching or network round-trip.
+
### `C_Spell.GetSpellRadius(spellID)` / `GetSpellRadius(slot, bookType)`
Returns `(baseRadius, modifiedRadius)` — the spell's AOE radius in yards,
diff --git a/src/Offsets.h b/src/Offsets.h
index 7721a604..5c773a61 100644
--- a/src/Offsets.h
+++ b/src/Offsets.h
@@ -5338,6 +5338,12 @@ enum Offsets {
// (form ID for shapeshift, channel index for periodic, etc.).
OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME = 0x16C, // int32[3]
OFF_SPELL_RECORD_EFFECT_MISC_VALUE = 0x1A8, // int32[3]
+ // Per-effect SpellMechanic ids (EffectMechanic[3]). One int32[3] (0xC)
+ // after EffectBasePoints (0x130); cross-checked against EffectRadiusIndex
+ // (0x160) and EffectApplyAuraName (0x16C). Vanilla often stores a spell's
+ // mechanic on an effect rather than the spell-level Mechanic (0x14), so
+ // bleed / DoT detection needs this array in addition to that field.
+ OFF_SPELL_RECORD_EFFECT_MECHANIC = 0x13C, // int32[3]
SPELL_RECORD_EFFECT_COUNT = 3,
// SPELL_EFFECT_* id array (`Effect[3]`) — five arrays before
diff --git a/src/spell/EffectMechanic.cpp b/src/spell/EffectMechanic.cpp
new file mode 100644
index 00000000..22ad2b8b
--- /dev/null
+++ b/src/spell/EffectMechanic.cpp
@@ -0,0 +1,76 @@
+// This file is part of ClassicAPI.
+//
+// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software Foundation, either
+// version 3 of the License, or (at your option) any later version.
+//
+// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// ClassicAPI. If not, see .
+
+// `C_Spell.GetSpellEffectMechanics(spellID)` -> { m1, m2, m3 }
+//
+// Returns a spell's three per-effect mechanic ids (Spell.dbc
+// `EffectMechanic[3]`) as a 1-based array table, or nil for an invalid /
+// out-of-range spell ID. Each entry is a standard WoW SpellMechanic id
+// (0 = that effect carries no mechanic); the numbering matches
+// C_Spell.GetSpellMechanicByID (1 = Charm, 7 = Root, 12 = Stun,
+// 15 = Bleed, 17 = Polymorph, ...).
+//
+// Complements GetSpellMechanicByID, which reads only the SPELL-level
+// `Mechanic` field (+0x14). Vanilla frequently stores the meaningful
+// mechanic on an *effect* rather than the spell — periodic damage such
+// as bleeds is the common case — so effect-mechanic-aware callers (e.g.
+// bleed classification for immunity tracking) need this array too:
+//
+// local em = C_Spell.GetSpellEffectMechanics(spellID)
+// if em then for i = 1, 3 do if em[i] == 15 then --[[ bleed ]] end end end
+//
+// Reads Spell.dbc directly, so it covers every spell the client knows —
+// not just the player's spellbook — with no caching or network round-trip
+// (Spell.dbc is resident from boot).
+
+#include "Game.h"
+#include "Offsets.h"
+#include "spell/Arg.h"
+#include "spell/Lookup.h"
+
+#include
+
+namespace Spell::EffectMechanic {
+
+namespace {
+
+int __fastcall Script_GetSpellEffectMechanics(void *L) {
+ const int spellID = Spell::Arg::ResolveSpellID(L, 1);
+ const uint8_t *record = Spell::Lookup::RecordForID(spellID);
+ if (record == nullptr)
+ return 0; // nil for invalid / out-of-range spell IDs
+
+ auto *mechanics = reinterpret_cast(
+ record + Offsets::OFF_SPELL_RECORD_EFFECT_MECHANIC);
+
+ // Fixed 1-based array of all three effects (0 = effect has no mechanic),
+ // matching the raw EffectMechanic[3] layout so callers can index by slot.
+ Game::Lua::NewTable(L);
+ for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
+ Game::Lua::PushNumber(L, static_cast(i + 1)); // key
+ Game::Lua::PushNumber(L, static_cast(mechanics[i])); // value
+ Game::Lua::SetTable(L, -3);
+ }
+ return 1;
+}
+
+} // namespace
+
+static void RegisterLuaFunctions() {
+ Game::Lua::RegisterTableFunction("C_Spell", "GetSpellEffectMechanics",
+ &Script_GetSpellEffectMechanics);
+}
+
+static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
+
+} // namespace Spell::EffectMechanic