165 Commits
Author SHA1 Message Date
Brues 54e503d1dd InCombatLockdown just returns false now 2026-05-25 14:59:00 -05:00
Brues 0d5c392c20 C_Map.GetBestMapForUnit 2026-05-25 00:20:53 -05:00
Brues da183c3f9a Update API.md 2026-05-24 19:38:27 -05:00
Brues f61c014973 GetInstanceInfo 2026-05-24 19:33:54 -05:00
Brues b066aec1e9 LockItem/UnlockItem 2026-05-24 16:38:13 -05:00
Brues 9fd85287fa C_Container.MoveItem 2026-05-24 15:51:37 -05:00
Brues 08494b1a48 C_Container.SwapItems 2026-05-24 15:26:54 -05:00
Brues 38f1be96ff GameTooltip:GetOwner() 2026-05-24 01:38:28 -05:00
Brues 49b2bd8829 UnitPower / UnitPowerMax / UnitPowerType + Enum.PowerType 2026-05-22 21:26:47 -05:00
Brues 74aa23480b GetAverageItemLevel 2026-05-22 20:38:21 -05:00
Brues 2b19de518b C_UnitAuras.GetAuraDataBySpellName 2026-05-22 19:14:17 -05:00
Brues 889116c6b0 QUEST_TURNED_IN 2026-05-22 16:41:06 -05:00
Brues 8734030ebe C_QuestLog.IsQuestDataCachedByID 2026-05-22 01:40:03 -05:00
Brues dabb65a220 HEARTHSTONE_BOUND event 2026-05-22 01:20:31 -05:00
Brues 07aaf283e3 GetQuestLogLeaderBoardID 2026-05-22 01:17:56 -05:00
Brues 85f5023f3d GameTooltip:GetGameObject / HasGameObject 2026-05-22 00:12:38 -05:00
Brues 6feb62f884 GetInventoryItemsForSlot
Modern accessor for "all items in inventory that can equip in
slot N". Walks equipment 1..19 + bags 0..4; for each item whose
m_inventoryType passes the slot-compatibility check, inserts
returnTable[packedLocation] = itemLink. Uses the same packed
ItemLocation encoding as C_EquipmentSet.GetItemLocations.

Compatibility check is a single bitwise AND against a static
invType → slotMask table — same shape and values as 3.3.5's at
DAT_00A2D288 (decoded from its Script_GetInventoryItemsForSlot
chain via FUN_007082B0). Two adjustments for vanilla:

  INVTYPE_2HWEAPON       → mainhand only (no titanic grip)
  INVTYPE_WEAPONMAINHAND → mainhand only
  INVTYPE_WEAPONOFFHAND  → offhand only

3.3.5's table allowed either-hand for those three because of
later-expansion mechanics.

Implementation gotcha: Item::Location::ResolveBag does
SetTop(L, 0) internally (it needs to set up the engine's
PackBagSlot expected stack shape), which clobbers our returnTable
at slot 2. Fix: anchor the table in the Lua registry under a
private key, collect items into a std::vector during the walk,
then rebuild the stack and populate. Registry slot is cleaned up
before return.

Bank items aren't included — vanilla's GetItemBySlot gates bank
slots on a banker GUID that's only set while the bank window is
open; modern WoW behaves the same way.

The transmogrify arg is accepted and ignored. Stock 1.12 has no
transmog system to query, and the modern flag's effect (broader
cross-eligibility for visual swaps) reduces to the regular equip
check. Private servers (Turtle WoW etc.) layer their own transmog
systems on top of vanilla; if any of those exposes its rules
through addon-readable engine state we'd plumb the flag through,
but we don't know of any such hook today.
2026-05-21 22:08:15 -05:00
Brues 8b5c670963 C_Item.GetItemSetID / GetItemSetIDByID / GetItemSetInfo
Three new accessors for the equipment-set system that vanilla
exposes only partially:

  GetItemSetIDByID(itemID)       — modern's 16th GetItemInfo return.
  GetItemSetID(itemLocation)     — same, by ItemLocation table.
  GetItemSetInfo(setID)          — full ItemSet.dbc row as a table.

The "what set is this item in" path reads ItemStats_C::m_itemSet
at +0x1C0 (field position derived from VanillaHelpers's struct +
verified-offset arithmetic against the already-confirmed
m_bagFamily at +0x1D0). Cache-miss-warm pattern matches the other
*ByID readers (RequestLoadItemDataByID + listen for
GET_ITEM_INFO_RECEIVED).

GetItemSetInfo reads ItemSet.dbc directly — record layout decoded
from the per-record loader at FUN_0057BBA0:

  +0x00 ID                      +0x6C  SetSpellID[8]
  +0x04 Name[8]  (8 locales!)   +0x8C  SetThreshold[8]
  +0x24 unknown                 +0xAC  RequiredSkill
  +0x28 ItemID[17]              +0xB0  RequiredSkillRank

180-byte stride, 45 columns. ItemSet has only 8 locale slots (vs
Spell.dbc / ChrRaces.dbc's 9), so the name read clamps the global
VAR_LOCALE_INDEX to [0..7] to avoid reading past the locale array
into the unrelated +0x24 field.

Return table: { setID, name, items[], bonuses[{spellID, threshold}],
requiredSkill, requiredSkillRank }. Verified against Magister's
Regalia (setID 181): 8 items, 4 bonuses at thresholds 2/4/6/8.
2026-05-21 17:47:46 -05:00
Brues 24b0153287 C_Spell.GetSpellReagents + fix Spell.dbc reagent offsets
Returns the spell's reagent list as an array of {itemID, count}
tables, one entry per non-empty reagent slot. Reads directly from
Spell.dbc; stops at the first empty slot, matching the engine's
own tooltip reagent loop.

Discovered while implementing that the reagent offsets we had in
Offsets.h were wrong:

  Old: OFF_SPELL_REAGENT_ID = 0x110, OFF_SPELL_REAGENT_COUNT = 0x130
  New: OFF_SPELL_REAGENT_ID = 0xA8,  OFF_SPELL_REAGENT_COUNT = 0xC8

The old values came from a CMaNGOS-style SpellEntry schema that
doesn't match 1.12.1's actual record layout for reagent fields.
Verified empirically by decompiling BuildSpellTooltip (0x0052E610) —
its reagent loop iterates `localRec + 0x2A` (dword arithmetic =
byte +0xA8) as itemIDs and indexes [+8] (= byte +0xC8) for counts.
We already had a separate OFF_SPELL_RECORD_REAGENTS = 0xA8 entry
used by the tradeskill/craft scrapers (correct value), so it was
silently inconsistent — they were reading the same field by two
different names, one of which was wrong.

Fixed latent IsUsableSpell bug as a side effect: the reagent gate
was reading zeros from +0x110 / +0x130 and concluding "no reagents
required" for every spell. Now correctly returns (false, false) for
spells whose reagent the player doesn't have in their bags.
Verified: GetSpellReagents(23028) = {{itemID=17020, count=1}};
IsUsableSpell(23028)=1 with Arcane Powder in inventory.

Consolidated: removed the now-duplicate OFF_SPELL_RECORD_REAGENTS
alias; tradeskill scraper points at the canonical OFF_SPELL_REAGENT_ID.
2026-05-21 16:12:13 -05:00
Brues bb45d84620 UnitInRange
Returns (inRange, checkedRange) — 40-yard healing-range check
matching modern's shape. Reuses the CGObject::GetPosition vtable
virtual at slot 5 (offset 0x14) that Script_CheckInteractDistance
uses, just with a fixed 1600.0 squared-distance threshold.

Two notable behaviors:

  UnitInRange("player") → (false, false). Documented Blizzard quirk
  carried over from modern — the function is meant for "is *another*
  unit in range" checks, querying yourself is meaningless. Short-
  circuited before the position read so checkedRange=false is
  unambiguous.

  checkedRange=false when the unit's position can't be obtained:
  unresolvable tokens, empty party/raid slots, raid members in a
  different zone, target with nothing targeted, etc. The position
  virtual returns null in those cases.

Vtable shape verified via the bytes at 0x0048BACF / 0x0048BADC
(both unit and player calls pass an out-buffer to vtable[+0x14] —
Ghidra's decomp dropped the player-call buffer push from the
output).
2026-05-21 15:17:02 -05:00
Brues da86cd46e3 GetItemCooldown / C_Container.GetItemCooldown
Direct-by-ID item cooldown query. Returns (startTime, duration,
enable) — the same multi-return shape 1.12's
GetContainerItemCooldown(bag, slot) uses — without requiring a
physical slot reference.

Routes through FUN_ITEM_QUERY_COOLDOWN at 0x006E2ED0, which looks up
the item's ItemStats_C record, finds the slot with trigger=ON_USE
(OFF_ITEMSTATS_SPELL_TRIGGER[i] == 0), and queries that spell's
cooldown via the shared FUN_006E13E0 against the player-spell
cooldown manager. The "ON_USE spell's cooldown" interpretation is
how the engine itself surfaces item cooldowns to addons.

Calling-convention gotcha worth flagging: Ghidra labels the first
arg as uint*, but the ItemStats cache lookup uses the integer both
as a hash key and as the cached-entry field-0 match target (which
is a uint*-typed slot), so the decomp inherits the pointer typing.
The actual fastcall value is the itemID itself — passing &itemID
makes ItemStats interpret the stack address as the lookup key and
the call silently fails. Verified via the Hearthstone (6948) test:
&itemID returned (0, 0, 0); passing itemID directly returns
(732120.014, 3600, 1) after use.

GetItemCooldown(itemInfo) accepts itemID / link / numeric string /
name via the shared Item::Arg helper. C_Container.GetItemCooldown
also accepts links because the shared helper extracts them for
free, even though modern's spec says links aren't accepted.
2026-05-21 15:00:46 -05:00
Brues 478006ab15 taint is a 2.0 concept 2026-05-21 14:34:46 -05:00
Brues 69d0b80f63 C_Spell.IsCurrentSpell
True if the spell is currently being cast, queued mid-GCD, or
channeled by the player. Reads three engine slots and returns true
on any match:

  VAR_CURRENT_CAST_SPELL (0x00CECA88) — cast bar; written by the
    cast-start helper at FUN_006E4AD0, read by FUN_006E3D30's
    is-currently-casting check (which Script_SpellStopCasting
    consults before sending CMSG_CANCEL_CAST).
  VAR_QUEUED_CAST_SPELL (0x00CECAA8) — the spell pushed aside when
    a new cast superseded it mid-GCD; restored to current when the
    new cast ends. Covers the "queued to cast next" half of
    modern's documented semantics.
  UNIT_FIELD_CHANNEL_SPELL (player descriptor +0x228) — channels
    (Fishing, Drain Soul, Ritual of Summoning, etc.).

Accepts the full spellIdentifier shape via Spell::Arg::ResolveSpellID
(number / |Hspell:N|h link / known-spellbook name). Closes TODO #32.
2026-05-21 14:27:31 -05:00
Brues 64a7c71cc6 docs: spellIdentifier acceptance for the C_Spell.* namespace
Adds a section-level callout at the top of Spell documenting that
every C_Spell.* function now takes the full spellIdentifier shape
(number / |Hspell:N|h link / known-spellbook name) and returns nil
permissively on garbage input. Function entries still write
(spellID) in the signature for brevity.

Trimmed the now-duplicated identifier-resolution block in
C_Spell.GetSpellCooldown's docs and reworded the "takes a spellID
only" notes on IsSpellPassive / IsSpellHarmful / IsSpellHelpful to
the truer "doesn't accept the (slot, bookType) shape" — since the
broader identifier shape IS accepted.
2026-05-21 14:15:16 -05:00
Brues d2591b7f59 C_Spell.GetSpellCooldown
Modern table-shape cooldown query. Accepts spellID (number),
spell name (with optional (Rank N) suffix), or |Hspell:N|h
hyperlink. Returns a SpellCooldownInfo table:

  { startTime, duration, isEnabled, modRate }

or nil for spellIDs without a Spell.dbc row. modRate is hard-coded
to 1.0 (vanilla has no haste-on-cooldown mechanic); the
post-vanilla fields (activeCategory, timeUntilEndOfStartRecovery,
isOnGCD) are left unset.

Reads the engine's per-spell cooldown manager via
FUN_SPELL_QUERY_COOLDOWN (0x006E2EA0). Fixed the
(*outDuration, *outStart) argument order while doing this — the
typedef in Spell::Usable had it as (*outStart, *outDuration), which
worked accidentally because both fields are 0 when no cooldown is
active, but produced swapped values when a cooldown was running.
Round-tripped against Blink (1953) to verify the corrected order.
2026-05-21 13:59:13 -05:00
Brues 33897d2347 UnitRaceBase
Sibling to UnitClassBase. Reads byte 0 of UNIT_FIELD_BYTES_0
(descriptor +0x78) and looks up ChrRaces.dbc::Filename for the
locale-independent token. Returns (raceFile, raceID): "Human"/1,
"Orc"/2, "Dwarf"/3, "NightElf"/4, "Scourge"/5, "Tauren"/6,
"Gnome"/7, "Troll"/8.
2026-05-21 13:39:09 -05:00
Brues 16ea961542 docs: drop "vanilla doesn't ship X" filler
Removed two paragraphs that just stated the project premise out loud
("Vanilla 1.12 ships no equivalent...", "Vanilla 1.12 doesn't ship X
(added in later expansions)..."). API.md is the reference for what
ClassicAPI adds — that backport context applies to every entry by
definition.

Kept the substantive nearby context (existing-vanilla-function
contrasts, server constraints, behavioral quirks) — those are
genuinely informative.
2026-05-21 13:18:16 -05:00
Brues f18d0a2387 C_QuestLog.IsUnitOnQuest + extract Unit::Flags::IsPlayerControlled
Modern arg-order shape (unit first, questID second; questID-keyed).
Walks the unit's +0xE68 sub-struct quest list at +0x28 — same data
source as the engine's IsUnitOnQuest(logIndex, unit). Single Lua call
covers both "is the player on it" and "is a party/raid member on it"
without making the caller find a matching log index first.

Crash hazard fix: the +0xE68 sub-struct is uninitialized for NPCs
(CGCreature_C). First attempt gated on `[unit + 0xE4] & 1` (the
engine's own pre-check before +0xE68 derefs in SetUnitBuff etc.) but
that wasn't sufficient — passing an NPC token still AV'd in the
quest-list walk. The engine's Script_IsUnitOnQuest gets away with the
weaker gate because its GUID-type-filtered ObjMgr lookup
(FUN_00468460(0x10, ...)) rejects non-player GUIDs upstream;
FUN_RESOLVE_UNIT_TOKEN doesn't have that filter. Switched to
UNIT_FLAG_PLAYER_CONTROLLED, which is the gate Item::InventoryID and
Unit::Flags already use for the same hazard.

While doing that, extracted IsPlayerControlled to Unit::Flags::
(new Flags.h) as the canonical predicate. Removed the file-static
copy in Item::InventoryID and collapsed two inline copies in
Unit::Flags (TestPlayerFlag, ReadGuildKey) to call the shared helper.
2026-05-21 13:00:20 -05:00
Brues 0625011d13 C_QuestLog.IsOnQuest
Walks VAR_QUEST_LOG_ENTRIES (the same array GetQuestIDForLogIndex
reads) matching each real entry's questID against the input. Skips
header rows via the +8 header-pointer gate. Returns false for invalid
input (non-positive / non-number / not in log) — modern semantics, no
lua_error.

Lighter than the engine's IsUnitOnQuest(logIndex, unit) which forces
the caller to walk the log themselves to find the matching index and
resolves a unit token even when the question is just about the player.
2026-05-21 12:39:43 -05:00
Brues e99bce2984 Dismount
Walks the player's buff range for an aura whose Spell.dbc effects
include SPELL_AURA_MOUNTED (78) and sends CMSG_CANCEL_AURA for that
spellID via the existing direct sender. Early-outs on
UNIT_FIELD_MOUNTDISPLAYID == 0 to skip the aura walk when the player
isn't mounted.

Vanilla 1.12 has no Dismount global; addons had to find the mount
buff via GetPlayerBuff and call CancelPlayerBuff with its 0-based
index. Matches Classic Era's no-arg shape.
2026-05-21 10:39:37 -05:00
Brues d7ecbd38e5 CancelShapeshiftForm: doc no-op for warrior stances
Vanilla treats warriors as always-in-a-stance — the engine has no "no
stance" state, right-clicking the active stance bar slot does nothing,
and the server rejects CMSG_CANCEL_AURA for stance spells regardless
of how the request is formed. Tried both a looser aura-walk (no
visibility gate) and a form-bar fallback before confirming stances
genuinely aren't cancelable from the client.

All other shapeshift forms (druid, shaman ghost wolf, priest
shadowform / spirit of redemption, rogue stealth) are real visible
buffs and cancel cleanly via the original aura-walk path.
2026-05-21 10:27:49 -05:00
Brues 32f6e342c4 CancelShapeshiftForm
No-arg drop-current-form, polyfilling the modern singular. Walks the
player's buff slots, scans each spell's Spell.dbc EffectApplyAuraName[3]
at +0x16C and EffectMiscValue[3] at +0x1A8 for the
SPELL_AURA_MOD_SHAPESHIFT (0x24) effect whose misc-value matches the
current form byte, and sends CMSG_CANCEL_AURA via FUN_006E7040 for the
owning spellID.

Offsets validated against both 1.12's Script_CastShapeshiftForm
(0x004B4810) — which does the same scan when re-toggling an active form
— and 3.3.5's Script_CancelShapeshiftForm inner FUN_00726CE0. Vanilla's
public Lua surface only exposes the index-based toggle via
CastShapeshiftForm, forcing addons to know which bar slot the current
form occupies before they can cancel it; the no-arg shape is a lot
easier.
2026-05-21 10:14:47 -05:00
Brues 8e5c15f019 C_Spell.CancelSpellByID / CancelSpellByName
Modern aura-cancel primitives — `CancelUnitBuff` decomposes to these
internally. Both go direct to the engine's CMSG_CANCEL_AURA sender
(`FUN_006E7040` at 0x006E7040, `__fastcall(spellID)`) and skip
Script_CancelPlayerBuff's client-side gates (the per-entry cancelable
flag at +0x0A bit 0x01 and the fallback AttributesEx & 0x04 check on
the spell record). Server is the authority on what's cancelable —
non-cancelable auras are rejected server-side as no-ops either way.

CancelSpellByName walks the player's unit-aura descriptor slots 0..31
(buff range) and matches Spell.dbc localized name case-insensitively.
Buff-only by design — matches modern semantics where dispels go
through separate UX.

Player-only (vanilla server only accepts CMSG_CANCEL_AURA for the
local player's own auras), so neither function takes a `unit` arg.

Pre-validates spellID via Spell::Lookup::RecordForID — the engine's
sender unconditionally derefs [record + 0x1C] after a NULL-on-OOR
record lookup, so skipping the check would AV on bad input.
2026-05-21 09:46:54 -05:00
Brues 85e4f582e3 UPDATE_SHAPESHIFT_FORM event
Synthesize modern's per-form-change event by hooking the engine's
bonus-action-bar refresh helper at 0x004E4FC0 — fires every relevant
UNIT_BYTES_1 broadcast plus once at post-login. Cached-byte gate on
descriptor[+0x212] filters out the recomputes for non-form bytes
(standstate, etc.) the same helper handles. Sentinel -1 for "player
not resolvable yet" distinguishes early-login transients from real
"left a form" transitions.

Vanilla 1.12 only has UPDATE_SHAPESHIFT_FORMS (plural — list-changed).
2026-05-21 04:19:37 -05:00
Brues dcb00701fd GetShapeshiftFormID 2026-05-21 04:04:01 -05:00
Brues b0f1b9910b GetMacroSpell 2026-05-21 00:25:20 -05:00
Brues 1d05f59261 GetMirrorTimerInfo(index) / GetMirrorTimerProgress(label) 2026-05-20 23:49:20 -05:00
Brues 1b01f3fcc9 Removed patches these functions were introduced 2026-05-20 23:04:26 -05:00
Brues fc2010340e UnitTokenFromGUID 2026-05-20 22:40:19 -05:00
Brues e2a18d196c swapped GetUnitGUID arg return order 2026-05-20 22:16:21 -05:00
Brues 753080e267 GameTooltip:GetUnitGUID() / GameTooltip:HasUnit() 2026-05-20 22:08:50 -05:00
Brues 8e51b56b5b typo 2026-05-20 21:42:54 -05:00
Brues 57c5f7a90b QUEST_ACCEPTED 2026-05-20 17:02:41 -05:00
Brues 9b452823b2 Update API.md 2026-05-20 01:29:22 -05:00
Brues 232eaed1f1 GetClassicExpansionLevel 2026-05-19 18:30:13 -05:00
Brues 12c708b55a GetQuestIDForLogIndex 2026-05-19 17:32:53 -05:00
Brues ba28c4cad5 Populate AuraData duration + expirationTime for player auras
`expirationTime` now reads from the engine's player-buff table at
`0x00BC6040` (same data path `GetPlayerBuffTimeLeft` uses) when the
unit is the local player. Other units still report 0 — the server
only broadcasts cast/duration for the local player's own auras.
Verified that the engine's ms tickcount matches Lua's GetTime() *
1000, so `expirationMs * 0.001` lands directly on the GetTime
timeline with no epoch reconciliation needed.

`duration` looks up `Spell.dbc.m_durationIndex` (+0x78) →
SpellDuration.dbc and applies the `(effLevel - spellBaseLevel) *
perLevel + base` scaling the engine uses internally, capped at max.
Populated for any unit (the base duration is identical regardless of
who's affected); talent / glyph extensions aren't included here since
those are caster-side and already baked into `expirationTime` on the
caster's side.

First attempt had the wrong field offset for spellID in the buff
table — read +0x0C (untalented rank, returned by Script_GetPlayerBuff
as its second result) instead of +0x04 (the actual spellID, used by
Script_GetPlayerBuffTexture to look up Spell.dbc). Fixed before this
commit.

This unblocks `buff.lua` bookkeeping (the bid-tracking ring-buffer
exists only to compensate for the missing time data) — addons can
now use modern UnitAuras semantics directly.
2026-05-18 23:26:40 -05:00
Brues 86047d2fbd Document GameTooltip:SetEquipmentSet
Adds the GameTooltip row entry in the README + a per-method section
in docs/API.md covering the tooltip shape, localization behavior
(Blizzard FrameXML globals with English fallbacks), and the
storage-format change that persists itemID alongside GUID per slot
to support naming missing items.
2026-05-18 15:19:19 -05:00
Brues 084cc81ca8 Sort docs/API.md sections alphabetically
Reorders all 30 top-level sections (and the matching Contents TOC
groups) by case-insensitive name. Done via a one-shot Python script
that sliced the file by ## headers and reassembled in sorted order
— no content edits, every per-section sub-bullet and prose block
preserved verbatim.

Also adds the Hooks TOC group that was missing entirely. The Hooks
section existed in the body but had no TOC bullet pointing at it.

Sub-bullet count is unchanged before/after (188 ### subsections),
confirming nothing was dropped during the reshuffle.
2026-05-18 14:29:52 -05:00
Brues d6ddc0020d Document GetActionInfo and UseItemByName
Adds README + docs/API.md entries for the two new functions, plus a
correction to the UseHearthstone entry — it still described the old
Script_UseContainerItem dispatch after the 30b3d91 refactor that
routed it through FUN_ITEM_USE directly.

The GetActionInfo entry calls out the known gap: the 0x40000000
non-macro branch surfaces type "item" but nil for the id, since
extracting the itemID from the bag-action hash struct needs more
reversing than landed in 509fbfe.
2026-05-18 14:24:50 -05:00