Compare commits

...
2 Commits
Author SHA1 Message Date
Brues b497bb7fb0 fix(attributes): run macrotext as text, not through name-based RunMacro
The secure "macro" action read both `macrotext` (raw text) and the
deprecated `macro` (saved-macro name) into one buffer and ran whichever
through the global RunMacro. RunMacro is name-based -- stock resolves an
index, and SuperCleveRoidMacros' RunMacro calls GetMacroIndexByName --
so a macrotext value like "/cast [hp:<90] Holy Light" resolved to no
macro and silently did nothing. Because the global existed, the native
fallback never ran.

Split the two by their real semantics: macrotext runs through the chat
parser (RunMacroTextC), so each line dispatches via SlashCmdList and
picks up addon slash hooks like SuperCleveRoidMacros' conditional /cast;
the name form keeps preferring RunMacro. Fixes click-cast macros with
conditionals.
2026-08-12 00:32:28 -05:00
Brues 4d5fe8d41b feat(spellbook): add C_SpellBook.GetSpellBookItemInfo
Backport C_SpellBook.GetSpellBookItemInfo(slotIndex, spellBank) -> table,
reusing Spell::Info's DBC reader. slotIndex is 1-based across the book;
spellBank is Enum.SpellBookSpellBank (0 = Player, 1 = Pet), resolved via
Spell::Lookup::SpellbookSlotToID. Returns nil for an empty/out-of-range
slot, matching retail.

Fields map from Spell.dbc: itemType is Spell (player) or PetAction (pet)
- vanilla's book holds only real spells, so None/FutureSpell/Flyout never
occur; actionID == spellID (no override system); name/subName from the
localized Name/Rank; isPassive from Attributes; isOffSpec always false.
iconID is the icon PATH string (vanilla has no fileID), the same
deviation as C_Spell.GetSpellInfo.iconID; skillLineIndex is omitted.

Also register the two Enum tables the return contract references
(non-destructively, like the other Enum.* additions) so
info.itemType == Enum.SpellBookItemType.Spell comparisons work:
Enum.SpellBookSpellBank and Enum.SpellBookItemType.

Document in docs/API.md (SpellBook section + both Enum entries) and list
in README.
2026-08-11 01:28:31 -05:00
4 changed files with 153 additions and 9 deletions
+3 -1
View File
@@ -60,7 +60,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
| [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.GetSpellDispelType`, `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.IsNextMeleeSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellInRange`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.ResetsMeleeSwing`, `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` |
| [SpellBook](docs/API.md#spellbook) | `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSkillLineName`, `C_SpellBook.GetSkillLineRank`, `C_SpellBook.GetSpellBookItemInfo`, `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`, `IsIndoors`, `IsInGroup`, `IsInRaid`, `IsLoggedIn`, `IsMounted`, `IsOutdoors`, `IsStealthed`, `IsSwimming` |
| [System](docs/API.md#system) | `CopyToClipboard`, `GetPhysicalScreenSize` |
| [Talent](docs/API.md#talent) | `GetTalentIDByIndex`, `GetTalentSpellID` |
@@ -188,6 +188,8 @@ when launching with `-console`), not as Lua functions. See the
| Inventory type | `Enum.InventoryType.Index*Type` (0–34, e.g. `IndexHeadType`=1 … `IndexRelicType`=28) |
| Item class | `Enum.ItemClass.{Consumable,Container,Weapon,Gem,Armor,Reagent,Projectile,Tradegoods,ItemEnhancement,Recipe,Quiver,Questitem,Key,Miscellaneous,…}` (0–19) |
| Item quality | `Enum.ItemQuality.{Poor,Common,Uncommon,Rare,Epic,Legendary,Artifact}` (0–6) |
| Spellbook bank | `Enum.SpellBookSpellBank.{Player,Pet}` (0–1) |
| Spellbook item type | `Enum.SpellBookItemType.{None,Spell,FutureSpell,PetAction,Flyout}` (0–4; 1.12 only yields `Spell`/`PetAction`) |
### Unit tokens
+63
View File
@@ -217,6 +217,8 @@ build instructions.
- [`Enum.ItemClass`](#enumitemclass)
- [`Enum.ItemQuality`](#enumitemquality)
- [`Enum.PowerType`](#enumpowertype)
- [`Enum.SpellBookSpellBank`](#enumspellbookspellbank)
- [`Enum.SpellBookItemType`](#enumspellbookitemtype)
- [Glue](#glue)
- [`C_Glue.IsFirstLoadThisSession()`](#c_glueisfirstloadthissession)
@@ -467,6 +469,7 @@ build instructions.
- [SpellBook](#spellbook)
- [`FindSpellBookSlotByID(spellID)`](#findspellbookslotbyidspellid)
- [`C_SpellBook.GetSpellBookItemInfo(slotIndex, spellBank)`](#c_spellbookgetspellbookiteminfoslotindex-spellbank)
- [`C_SpellBook.GetSpellLevelLearned(spellID)`](#c_spellbookgetspelllevellearnedspellid)
- [`C_SpellBook.GetCurrentLevelSpells([level])`](#c_spellbookgetcurrentlevelspellslevel)
- [`C_SpellBook.GetSkillLineName(skillLineID)`](#c_spellbookgetskilllinenameskilllineid)
@@ -5333,6 +5336,32 @@ not modern's `ComboPoints` reuse of the same number.
local rage = UnitPower("player", Enum.PowerType.Rage)
```
### `Enum.SpellBookSpellBank`
Selects which spellbook a `C_SpellBook.*` slot query reads. Passed as the
`spellBank` argument to
[`C_SpellBook.GetSpellBookItemInfo`](#c_spellbookgetspellbookiteminfoslotindex-spellbank).
| Value | Field |
|------:|----------|
| `0` | `Player` |
| `1` | `Pet` |
### `Enum.SpellBookItemType`
Categorizes a spellbook slot. Vanilla's spellbook only ever holds real
spells, so `C_SpellBook.GetSpellBookItemInfo` returns `Spell` for a
player-book slot and `PetAction` for a pet-book slot. The other values
exist for signature parity with retail but never occur in 1.12.
| Value | Field | Notes |
|------:|---------------|-------|
| `0` | `None` | Empty slot. Never returned — an empty slot yields `nil` instead. |
| `1` | `Spell` | A player-book spell. |
| `2` | `FutureSpell` | A not-yet-learned trainer spell. Never occurs in 1.12. |
| `3` | `PetAction` | A pet-book spell. |
| `4` | `Flyout` | A flyout group — a later-expansion concept. Never occurs. |
## Glue
Backports of two `C_Glue` session helpers. `C_Glue` is registered on the glue
@@ -11697,6 +11726,40 @@ end
Equivalent to the legacy function of the same name introduced in 3.0
(later renamed to `FindSpellBookSlotBySpellID` in 5.x).
### `C_SpellBook.GetSpellBookItemInfo(slotIndex, spellBank)`
Returns a table describing the spell in a spellbook slot. `slotIndex` is
1-based across the whole book. `spellBank` picks the book —
[`Enum.SpellBookSpellBank.Player`](#enumspellbookspellbank) (`0`) or
`Enum.SpellBookSpellBank.Pet` (`1`).
```lua
local info = C_SpellBook.GetSpellBookItemInfo(1, Enum.SpellBookSpellBank.Player)
-- info.name, info.spellID, info.itemType, info.isPassive, info.iconID, ...
```
Table fields:
| Field | Type | Notes |
|-------|------|-------|
| `itemType` | [`Enum.SpellBookItemType`](#enumspellbookitemtype) | `Spell` (1) for the player book, `PetAction` (3) for the pet book. |
| `actionID` | number | The spellID. Equals `spellID` — vanilla has no spell-override system. |
| `spellID` | number | The spellID in the slot. |
| `name` | string | The localized spell name. |
| `subName` | string | The rank text (e.g. `"Rank 3"`), or `""` when the spell has no rank. |
| `iconID` | string | The icon **path** — feed it straight to `texture:SetTexture(...)`. |
| `isPassive` | boolean | `true` for a passive spell. |
| `isOffSpec` | boolean | Always `false`. |
Returns `nil` for an empty or out-of-range slot, matching the modern API.
> **Deviations from retail, forced by 1.12's data.** `iconID` is a
> texture path, not a `fileID` (vanilla has no fileID system) — the same
> deviation as [`C_Spell.GetSpellInfo`](#c_spellgetspellinfospellid).
> `skillLineIndex` is not returned (`nil`); spellbook tabs aren't
> SkillLines. `isOffSpec` is always `false` — vanilla has no
> specializations.
### `C_SpellBook.GetSpellLevelLearned(spellID)`
Returns the level at which a spell becomes available — the
+18 -8
View File
@@ -647,15 +647,25 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
}
if (Ascii::EqualCI(verb, "macro")) {
char macro[512];
if (!ReadModAttr(L, fi, prefix, "macrotext", suffix, macro, sizeof macro) &&
!ReadModAttr(L, fi, prefix, "macro", suffix, macro, sizeof macro))
return false;
// Prefer an addon-provided RunMacro (SuperCleveRoidMacros, pfUI, …) — it
// handles named macros and extended macro text; fall back to the stock
// ChatEdit_ParseText path when no RunMacro global is present.
if (!Game::Lua::CallGlobalString(L, "RunMacro", macro))
// `macrotext` is raw macro text (the modern default). Run it as text
// through the stock chat parser so each line dispatches via
// SlashCmdList — that routes /cast etc. through any addon slash hooks
// (e.g. SuperCleveRoidMacros' conditional /cast). A name-based RunMacro
// (which is what SuperCleveRoidMacros ships) can't interpret text and
// would silently resolve nothing.
if (ReadModAttr(L, fi, prefix, "macrotext", suffix, macro, sizeof macro)) {
RunMacroTextC(L, macro);
return true;
return true;
}
// Deprecated `macro` form: a saved-macro name/index. Prefer an
// addon-provided RunMacro (SuperCleveRoidMacros, pfUI, …) to run the
// named macro's body; fall back to the stock parser when none exists.
if (ReadModAttr(L, fi, prefix, "macro", suffix, macro, sizeof macro)) {
if (!Game::Lua::CallGlobalString(L, "RunMacro", macro))
RunMacroTextC(L, macro);
return true;
}
return false;
}
if (Ascii::EqualCI(verb, "stop") || Ascii::EqualCI(verb, "stopcasting")) {
Game::Lua::CallGlobal(L, "SpellStopCasting");
+69
View File
@@ -617,6 +617,69 @@ static const Game::HookAutoRegister _hookUnlearnSpell{
Offsets::FUN_UNLEARN_SPELL, reinterpret_cast<void *>(&UnlearnSpell_h),
reinterpret_cast<void **>(&g_origUnlearnSpell)};
// Enum.SpellBookItemType values (retail). Vanilla's spellbook only ever
// produces real spells, so we emit Spell (player book) or PetAction (pet
// book); None/FutureSpell/Flyout don't occur in 1.12.
static constexpr int kSpellBookItemTypeSpell = 1;
static constexpr int kSpellBookItemTypePetAction = 3;
static const Game::Lua::EnumIntegerEntry kSpellBookSpellBankEntries[] = {
{"Player", 0}, {"Pet", 1},
};
static const Game::Lua::EnumIntegerEntry kSpellBookItemTypeEntries[] = {
{"None", 0}, {"Spell", 1}, {"FutureSpell", 2}, {"PetAction", 3},
{"Flyout", 4},
};
// `C_SpellBook.GetSpellBookItemInfo(slotIndex, spellBank)` -> table.
// `slotIndex` is 1-based across the whole book; `spellBank` is
// Enum.SpellBookSpellBank (0 = Player, 1 = Pet). Returns nil for an empty or
// out-of-range slot. Vanilla's spellbook holds only real spells, so `itemType`
// is always Spell (player) or PetAction (pet).
//
// Field deviations from retail, all forced by 1.12 lacking the data:
// - `iconID` is the icon PATH string (vanilla has no fileID), same as
// C_Spell.GetSpellInfo.iconID -- feed it straight to texture:SetTexture.
// - `isOffSpec` is always false (vanilla has no specializations).
// - `skillLineIndex` is omitted (nil) -- spellbook tabs aren't SkillLines.
static int __fastcall Script_C_SpellBook_GetSpellBookItemInfo(void *L) {
if (!Game::Lua::IsNumber(L, 1))
return 0; // modern returns nil (not an error) for a bad index
const int slot = static_cast<int>(Game::Lua::ToNumber(L, 1));
const int bank = Game::Lua::IsNumber(L, 2)
? static_cast<int>(Game::Lua::ToNumber(L, 2))
: 0;
const int bookType = (bank == 1) ? 1 : 0; // 1 = pet book, else player
const int spellID = Spell::Lookup::SpellbookSlotToID(slot, bookType);
if (spellID <= 0)
return 0; // empty slot / out of range -> nil
SpellInfoData info;
if (!ReadSpellInfo(spellID, info))
return 0;
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
const uint32_t attr =
record ? *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES)
: 0u;
Game::Lua::NewTable(L);
SetField(L, "itemType",
static_cast<double>(bookType == 1 ? kSpellBookItemTypePetAction
: kSpellBookItemTypeSpell));
SetField(L, "actionID", static_cast<double>(spellID));
SetField(L, "spellID", static_cast<double>(spellID));
SetField(L, "name", info.name);
// subName carries the rank text ("Rank N"); modern uses "" when absent.
SetField(L, "subName", info.rank ? info.rank : "");
SetField(L, "iconID", info.iconPath); // path string -- see note above
SetFieldBool(L, "isPassive", (attr & Offsets::SPELL_ATTR_PASSIVE) != 0);
SetFieldBool(L, "isOffSpec", false);
return 1;
}
static void RegisterLuaFunctions() {
Game::Lua::RegisterGlobalFunction("GetSpellInfo", &Script_GetSpellInfo);
Game::Lua::RegisterGlobalFunction("GetSpellLink", &Script_GetSpellLink);
@@ -637,6 +700,12 @@ static void RegisterLuaFunctions() {
&Script_C_Spell_IsSpellHarmful);
Game::Lua::RegisterTableFunction("C_Spell", "IsSpellHelpful",
&Script_C_Spell_IsSpellHelpful);
Game::Lua::RegisterTableFunction("C_SpellBook", "GetSpellBookItemInfo",
&Script_C_SpellBook_GetSpellBookItemInfo);
Game::Lua::RegisterIntegerEnum("Enum", "SpellBookSpellBank",
kSpellBookSpellBankEntries, 2);
Game::Lua::RegisterIntegerEnum("Enum", "SpellBookItemType",
kSpellBookItemTypeEntries, 5);
}
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};