From e2d7b0f555fd9ea1502d4e4a9bf1dcedf9391788 Mon Sep 17 00:00:00 2001
From: Brues <5278969+brues-code@users.noreply.github.com>
Date: Tue, 26 May 2026 00:05:43 -0500
Subject: [PATCH] C_Spell.IsSelfBuff
---
README.md | 2 +-
docs/API.md | 18 ++++++++
src/spell/IsSelfBuff.cpp | 94 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 src/spell/IsSelfBuff.cpp
diff --git a/README.md b/README.md
index 0fbd8be8..20b3deee 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
| [MerchantFrame](docs/API.md#merchantframe) | `C_MerchantFrame.GetBuybackItemID`, `C_MerchantFrame.GetItemInfo`, `C_MerchantFrame.GetNumJunkItems`, `C_MerchantFrame.IsMerchantItemRefundable`, `C_MerchantFrame.IsSellAllJunkEnabled`, `C_MerchantFrame.SellAllJunkItems` |
| [NameCache](docs/API.md#namecache) | `C_CreatureInfo.GetCreatureID`, `C_PlayerCache.GetPlayerInfoByName`, `C_PlayerCache.IsEnabled`, `C_PlayerCache.IsScanEnabled`, `C_PlayerCache.RememberPlayer`, `C_PlayerCache.SetEnabled`, `C_PlayerCache.SetScanEnabled`, `C_PlayerInfo.GUIDIsCreature`, `C_PlayerInfo.GUIDIsGameObject`, `C_PlayerInfo.GUIDIsPet`, `C_PlayerInfo.GUIDIsPlayer`, `GetPlayerInfoByGUID` |
| [Quest](docs/API.md#quest) | `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.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellName`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsCurrentSpell`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `CancelSpellByName`, `CastSpellNoToggle`, `FindSpellBookSlotByID`, `GetCraftSpellID`, `GetSpellInfo`, `GetSpellLink`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell` |
+| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellName`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsCurrentSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `CancelSpellByName`, `CastSpellNoToggle`, `FindSpellBookSlotByID`, `GetCraftSpellID`, `GetSpellInfo`, `GetSpellLink`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell` |
| [State](docs/API.md#state) | `CancelShapeshiftForm`, `Dismount`, `GetMirrorTimerInfo`, `GetMirrorTimerProgress`, `GetShapeshiftFormID`, `IsAssistingRitual`, `IsFalling`, `IsInGroup`, `IsInRaid`, `IsMounted`, `IsStealthed`, `IsSwimming` |
| [Table](docs/API.md#table) | `table.wipe` |
| [Talent](docs/API.md#talent) | `GetTalentIDByIndex`, `GetTalentSpellID` |
diff --git a/docs/API.md b/docs/API.md
index efec197d..ace928f1 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -236,6 +236,7 @@ build instructions.
- [`C_Spell.IsSpellUsable(spellID)`](#c_spellisspellusablespellid)
- [`C_Spell.GetSpellCooldown(spellIdentifier)`](#c_spellgetspellcooldownspellidentifier)
- [`C_Spell.IsCurrentSpell(spellIdentifier)`](#c_spelliscurrentspellspellidentifier)
+ - [`C_Spell.IsSelfBuff(spellID)`](#c_spellisselfbuffspellid)
- [`IsHarmfulSpell(spell)` / `IsHelpfulSpell(spell)`](#isharmfulspellspell--ishelpfulspellspell)
- [`C_Spell.IsSpellHarmful(spellID)` / `C_Spell.IsSpellHelpful(spellID)`](#c_spellisspellharmfulspellid--c_spellisspellhelpfulspellid)
- [`C_SpellBook.GetSpellLevelLearned(spellID)`](#c_spellbookgetspelllevellearnedspellid)
@@ -5419,6 +5420,23 @@ on this. Reads three engine slots and returns true on any match:
covers channeled abilities (Fishing, Drain Soul, Ritual of
Summoning, etc.).
+### `C_Spell.IsSelfBuff(spellID)`
+
+Returns `true` if every active effect on the spell targets only the
+caster — every effect's implicit target (A and B) must be either
+`TARGET_NONE` (0) or `TARGET_SELF` (1).
+
+```lua
+C_Spell.IsSelfBuff(1006) -- Inner Fire → true
+C_Spell.IsSelfBuff(7302) -- Frost Armor → true
+C_Spell.IsSelfBuff(1459) -- Arcane Intellect → false (targets friendly)
+C_Spell.IsSelfBuff(133) -- Fireball → false (targets enemy)
+```
+
+Walks `Spell.dbc.EffectImplicitTargetA[3]` and
+`EffectImplicitTargetB[3]`. Spells with no active effects (a
+degenerate case for normal content) return `false`.
+
### `C_Item.GetWeaponEnchantInfo()`
Returns the modern 12-tuple matching WotLK+'s extended
diff --git a/src/spell/IsSelfBuff.cpp b/src/spell/IsSelfBuff.cpp
new file mode 100644
index 00000000..8bc03a4e
--- /dev/null
+++ b/src/spell/IsSelfBuff.cpp
@@ -0,0 +1,94 @@
+// This file is part of ClassicAPI.
+//
+// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
+// of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License along with
+// ClassicAPI. If not, see .
+
+// `C_Spell.IsSelfBuff(spellID)` — true iff every active effect on the
+// spell targets the caster and only the caster. Read directly from
+// `Spell.dbc.EffectImplicitTargetA[3]` and `EffectImplicitTargetB[3]`
+// — an effect is "self-only" when both targets are either
+// `TARGET_NONE` (0) or `TARGET_SELF` (1). Effects with a zero
+// `Effect` code are skipped (unused effect slots).
+
+#include "Game.h"
+#include "Offsets.h"
+#include "dbc/Lookup.h"
+
+#include
+
+namespace Spell::IsSelfBuff {
+
+namespace {
+
+// Spell.dbc per-effect arrays. Each is an int32[3] in the record.
+// Field-index derivation against the known `EffectApplyAuraName` at
+// field 91 / +0x16C — the implicit-target pair sits at field 82/85.
+constexpr int OFF_SPELL_EFFECT = 0xF4; // SPELL_EFFECT_* code
+constexpr int OFF_SPELL_EFFECT_TARGET_A = 0x148;
+constexpr int OFF_SPELL_EFFECT_TARGET_B = 0x154;
+constexpr int EFFECT_COUNT = 3;
+
+// Vanilla 1.12 implicit-target codes (CMaNGOS `Targets` enum).
+constexpr int TARGET_NONE = 0;
+constexpr int TARGET_SELF = 1;
+
+bool IsSelfOnlyTarget(int target) {
+ return target == TARGET_NONE || target == TARGET_SELF;
+}
+
+} // namespace
+
+static int __fastcall Script_IsSelfBuff(void *L) {
+ if (!Game::Lua::IsNumber(L, 1)) {
+ Game::Lua::PushBool(L, false);
+ return 1;
+ }
+ const int spellID = static_cast(Game::Lua::ToNumber(L, 1));
+ if (spellID <= 0) {
+ Game::Lua::PushBool(L, false);
+ return 1;
+ }
+ const uint8_t *rec = DBC::Record(Offsets::VAR_SPELL_RECORDS,
+ Offsets::VAR_SPELL_RECORD_COUNT,
+ static_cast(spellID));
+ if (rec == nullptr) {
+ Game::Lua::PushBool(L, false);
+ return 1;
+ }
+
+ bool sawEffect = false;
+ for (int i = 0; i < EFFECT_COUNT; ++i) {
+ const int effect = *reinterpret_cast(
+ rec + OFF_SPELL_EFFECT + i * 4);
+ if (effect == 0)
+ continue;
+ sawEffect = true;
+ const int targetA = *reinterpret_cast(
+ rec + OFF_SPELL_EFFECT_TARGET_A + i * 4);
+ const int targetB = *reinterpret_cast(
+ rec + OFF_SPELL_EFFECT_TARGET_B + i * 4);
+ if (!IsSelfOnlyTarget(targetA) || !IsSelfOnlyTarget(targetB)) {
+ Game::Lua::PushBool(L, false);
+ return 1;
+ }
+ }
+ Game::Lua::PushBool(L, sawEffect);
+ return 1;
+}
+
+static void RegisterLuaFunctions() {
+ Game::Lua::RegisterTableFunction("C_Spell", "IsSelfBuff",
+ &Script_IsSelfBuff);
+}
+
+static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
+
+} // namespace Spell::IsSelfBuff