Commit Graph
286 Commits
Author SHA1 Message Date
Brues dcb00701fd GetShapeshiftFormID 2026-05-21 04:04:01 -05:00
Brues 5354b78e8f UnitGUID("player"): bypass object-manager gate
FUN_TOKEN_TO_GUID gates "player" on the object-manager lookup, which
drops out transiently during zone transitions / brief CGPlayer rebuilds
even though [VAR_LOCAL_PLAYER_PTR + 0xC0] still holds a valid GUID.
Short-circuit the bare "player" token to read the canonical pointer
directly so we match modern WoW's semantics. Suffixed tokens still go
through the engine so the chained `.target` walk works.

Doesn't help at addon file-load on first login — the GUID isn't
populated anywhere in the engine until SMSG_UPDATE_OBJECT runs in the
main loop after FrameScript_Initialize returns. Addons that need it at
boot have to wait for PLAYER_LOGIN.
2026-05-21 03:06:09 -05:00
Brues 85e036e2ec Prevent CastNoToggle parsing for very long macros 2026-05-21 02:03:23 -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 22d45371ae sort events table 2026-05-20 17:06:36 -05:00
Brues 57c5f7a90b QUEST_ACCEPTED 2026-05-20 17:02:41 -05:00
Brues acf333b2c2 EventTrace: Pressing escape in search no longer clears 2026-05-20 17:02:18 -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 64a621d482 inline textures aren't a thing in 1.12.1 2026-05-19 07:57:37 -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 9dabf9db71 5.0 fixes 2026-05-18 19:53:55 -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 5982b85c75 Add GameTooltip:SetEquipmentSet with localized output
Registers `SetEquipmentSet` on the GameTooltip method registry,
mirroring the 4.3.4 implementation at 0x0046E690. Builds a tooltip
with header + counts (equipped / in inventory / ignored) + one line
per missing item.

Storage format now persists itemID alongside GUID per slot
(`slot N guid=0xHEX item=ID`), so missing items can be looked up by
name in the item cache even when the live CGItem is no longer in the
client's object map. Backward compat: pre-itemID files load fine and
fall back to a `%d missing` summary line for those slots.

Adds `Game::Lua::PushLocalizedString` and `PushLocalizedFormatInt`
helpers — generic lookup of `_G[name]` with a C-string fallback for
servers stripped of standard GlobalStrings. The tooltip uses these
for the four count lines via Blizzard's `ITEMS_VARIABLE_QUANTITY`,
`ITEMS_EQUIPPED`, `ITEMS_IN_INVENTORY`, `ITEM_SLOTS_IGNORED` keys,
and for the per-missing-item line via `ITEM_MISSING`.

AddOn side: a `GlobalStrings.lua` companion provides English defaults
for those five keys plus a `ShowEquipmentSet()` test helper in
Constants.lua.

First implementation passed `nargs=4` to `lua_call` where the stack
needed 5 (self + text + r + g + b for `tooltip:SetText`) — Lua then
treated `self` as the function, surfacing as
`<in C code>: in function 'SetEquipmentSet'` with no Lua frame above.
Fixed before this commit.
2026-05-18 15:13:36 -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
Brues b55e3bae35 Add UseItemByName + route UseHearthstone through the same engine primitive
`C_Item.UseItemByName(itemInfo)` mirrors 3.3.5's function: locate the
item in bags, hand the CGItem pointer to the engine's by-pointer use
primitive `FUN_005D8D00`. That's the same fallback path
`Script_UseContainerItem` ends up in after every cursor-mode branch
(repair, spell-cast targeting, drop-on-bag) is skipped — branches
that don't fire for an addon-issued call from a clean cursor.

`C_Container.UseHearthstone` was doing the same Lua-stack roundtrip
(push bag/slot, call Script_UseContainerItem); now it locates the
hearthstone-equivalent item and calls `FUN_005D8D00` directly,
matching UseItemByName's shape.

First attempt of UseItemByName called `FUN_005E1840` thinking it was
the use primitive — turned out to be the equip/trade path that puts
the item on the cursor in mode 1 and triggers AutoEquip. The
"This item cannot be equipped" error from a hearthstone exposed the
mistake.
2026-05-18 14:11:25 -05:00
Brues c46e4516b0 Add GetActionInfo backport (spell / macro / item)
Mirrors modern WoW's `GetActionInfo(slot)` against the vanilla 1.12.1
action table at `0x00BC6980`. Top-4-bits encode the type tag; the
`0x40000000` tag is ambiguous between macros and bag-items and is
disambiguated by walking the 36-entry macro-slot map at `0x00BDCC60`
(same trick SuperWoWhook's modified `GetActionText` uses).

Returns:
  - empty:      nil
  - spell:      "spell", spellID, "spell"
  - macro:      "macro", macroSlot (1-based)
  - item-by-ID: "item", itemID
  - bag-item:   "item", nil    (itemID extraction from the bag-action
                                 hash struct still needs reversing;
                                 in practice these slots are stale —
                                 the engine's HasAction returns false
                                 for them)
2026-05-18 13:28:11 -05:00
Brues 83f92566b2 Fix FUN_004F8DB0 hook signature: 4 stack args, not 3
Crash repro: moving items in bags faulted at EIP=0x00000777 after a
handful of descriptor updates. Root cause was a calling-convention
mismatch on the keyring hook added in b05ff06.

The Ghidra signature quoted in that commit said three stack args
(__thiscall unsigned(this, guidLo, guidHi, *current)), but the actual
function in the Octo binary at 0x004F8DB0 ends with `RET 0x10` —
four stack args, 16 bytes of callee cleanup. Our hook declared three,
emitted `RET 0xC`, and under-cleaned the caller's stack by 4 bytes per
call. After enough descriptor updates the cumulative drift caused a
later RET to pop a non-return-address value and jump there.

Verified by reading the actual binary at that VA: prologue references
[EBP+8/C/10] and the function epilogue is `RET 0x10` at 0x004F8E9B.
2026-05-18 10:01:05 -05:00
Brues ddd96b587e Expose CVar bindings and RunScript on the glue Lua state
Vanilla 1.12 registers GetCVar/SetCVar/RegisterCVar/GetCVarDefault
and RunScript only on the in-game FrameScript engine; GlueXML had
no way to reach them. Mirroring is pointer-aliasing — same Script_*
C functions registered on glue via RegisterGlueFunction. CVar
storage is process-global so writes from either state are visible
on the other. C_CVar.GetCVarBool (our existing polyfill) gets a
GlueModuleAutoRegister alongside the existing in-game one.
2026-05-17 23:15:23 -05:00
Brues 2a7cbe2e59 Remove C_CharacterList; preserve recovery notes in TODO #95
The single addon driving the C_CharacterList.* bindings moved off
them; keeping the engine-hook surface live for a feature nobody
calls is dead weight. Snapshot record layout, hook target, and the
"why memory-only" rationale all land in TODO #95 so another DLL
can pick it up without re-deriving any of it.
2026-05-17 21:23:09 -05:00
Brues 1c5879e74b Delete TooltipProbe.cpp 2026-05-17 20:50:10 -05:00
Brues 4723a835fe hooksecurefunc: pcall the callback and tighten stack shuffle
A buggy hook was breaking the wrapped path because the callback ran
through lua_call; switching to lua_pcall mirrors 3.3.5's FUN_00817050
and matches the actual safety property of hooksecurefunc — the
original's results always reach the caller. Stack shuffle now sinks
results below the args once instead of duplicating args twice, so the
wrapper uses ~nargs+nresults slots and drops the O(nargs^2) Remove
loop.
2026-05-17 20:47:51 -05:00
Brues 6a9acc420f GetSpell/HasSpell: note the aura-path coverage attempt that didn't land
Tried hooking the inner aura tooltip builder (FUN_0052F880) to mirror
its spellID into a side-table, then surfacing it from
GameTooltip:GetSpell/HasSpell. That consistently crashed in pfUI's
hooksecurefunc-wrapped path with the trampoline executing from
corrupted JIT memory. Reverted; left a note pointing at the next
candidate design (hooking the Script_* setter functions instead of
the inner builder).
2026-05-17 18:00:42 -05:00
Brues ab85a54423 remove debug logging from CastNoToggle 2026-05-17 17:38:23 -05:00
brues-code f63bff005b Update README.md 2026-05-17 03:54:55 -05:00
Brues 0ff233b15e README: split glue calls into their own table
Pulls GetSavedCharacterOrder / SetSavedCharacterOrder out of the
crowded CharacterList row and into a dedicated "GlueXML calls"
table after the in-game Calls table. Makes the in-world / glue
scope distinction visible at a glance and leaves room for future
glue-side additions.
2026-05-17 03:26:00 -05:00
Brues af414cd162 Document GetSavedCharacterOrder / SetSavedCharacterOrder
README CharacterList row gains a GlueXML-only callout for the two new
globals plus their persistence path. docs/API.md gets a dedicated
subsection under CharacterList covering scope (glue Lua state, not
in-world), the API surface, the shared ClassicAPI.txt storage layout,
a usage example, and a brief how-it-works note pointing at
FUN_0046ABB0.
2026-05-17 03:23:36 -05:00
Brues d32d90e662 TODO #94: mark done with as-shipped recipe
Replaces the planning writeup with a short summary of what landed:
final API, storage location, the three infrastructure pieces (glue hook,
GlueModuleAutoRegister, Settings::Account), and the misnamed-offset
note for future callers.
2026-05-17 03:20:50 -05:00
Brues d6c80a18d9 Add Settings::Account registry for shared ClassicAPI.txt
Migrates NameCache's `PersistentNameCacheEnabled` /
`NameCacheScanEnabled` settings and Order's `CharacterOrder.<realm>`
lines onto a single account-scoped settings file. Each module declares
a reset/serialize/parse section at static-init time and the registry
handles the load/save cycle plus account-change detection (re-loads on
autologin switch from the glue screen).

Prior to this, NameCache wholesale-rewrote `ClassicAPI.txt` on every
save and Order owned a separate `CharacterOrder.txt` for the same
account scope. Combining them avoids two files in `WTF\Account\<acct>\`
and lets future per-account modules layer in without coordinating.
2026-05-17 03:18:41 -05:00
Brues 39a972b91e GetSavedCharacterOrder/SetSavedCharacterOrder 2026-05-17 02:51:52 -05:00
Brues cd6da18687 Add GlueModuleAutoRegister + FUN_LOAD_GLUE_SCRIPT_FUNCTIONS hook
Module-self-registration pattern for the glue Lua state, mirroring the
existing in-game ModuleAutoRegister. Modules opt in with a file-scope
GlueModuleAutoRegister; the hook on FUN_0046ABB0 (master glue init,
single caller, 35-byte linear function) fires their callbacks after
the engine finishes registering its own 109 glue functions onto the
freshly-created glue state.

Prior attempt hooked the inner FUN_0046DDF0 60-fn batch trampoline and
crashed on Octo, likely from sibling-DLL collision on a small target.
The linear caller is larger and less obvious; no crash, hook fires
cleanly on initial launch and every world->glue return.
2026-05-17 02:29:27 -05:00
Brues ca4294492e CastSpellNoToggle 2026-05-17 02:03:51 -05:00
Brues b05ff06814 BAG_UPDATE_DELAYED: close keyring gap with FUN_004F8DB0 hook
Pattern-search of .text confirmed exactly three FUN_FIRE_EVENT(0x148,
"%d", ...) call sites in 1.12.1. Two were already covered; the third
lives inside FUN_004F8DB0 — the bag descriptor change callback. Its
keyring branch (slot range 0x51..0x70) fires BAG_UPDATE directly
without going through FUN_004F9370, which was the documented coverage
gap (CLAUDE.md / TODO #67).

Ghidra decompile gave us the calling convention:
  __thiscall unsigned(void *bagDesc, uint, void *, uint *)

Wired as __fastcall with a dummy EDX param — same trampoline trick
used for Frame::RegisterEvent in DllMain. The non-keyring branch of
FUN_004F8DB0 still calls into FUN_004F9370 which is also hooked, but
double-fire is harmless: g_pending is idempotent until the per-frame
drain clears it.
2026-05-17 00:12:32 -05:00
Brues 2397b683f3 GLOBAL_MOUSE_*: switch from polling to WH_GETMESSAGE hook
Mirrors the thread-message-hook pattern in Input::Modifier. The hook
catches WM_*BUTTON{DOWN,UP} on the engine's main thread before
dispatch, which:
  - is event-driven (zero work when idle) vs ~5 GetAsyncKeyState +
    GetWindowThreadProcessId calls per WorldTick
  - scopes naturally to WoW's message queue, so the foreground-window
    check is no longer needed
  - catches sub-frame down+up pairs the poll would miss

XBUTTON side-key distinction now comes from GET_XBUTTON_WPARAM
instead of the separate VK_XBUTTON1/2 codes.
2026-05-16 22:33:14 -05:00
Brues 60147989bb Collapse Event::Custom::Fire_* into one variadic template
The six per-arity helpers (Fire_None / Fire_D / Fire_DD / Fire_DDD /
Fire_SD / Fire_S) all wrapped the same FUN_FIRE_EVENT engine call
with the same eventID<0 early-out — only the format string and arg
list differed. Collapsing into a single template Fire(eventID, fmt,
args...) keeps the printf-style format at the call site and frees us
from adding a new per-arity overload for each new event shape.
2026-05-16 22:05:07 -05:00
Brues 90a580d75d Add Game::Lua::PushBool helper, sweep condition ? 1 : 0 patterns
PushBool(L, bool) wraps lua_pushboolean and centralizes the bool→int
conversion the engine ABI requires. All ~50 sites doing
`PushBoolean(L, condition ? 1 : 0)` collapse to `PushBool(L, condition)`.
Non-PushBoolean callers passing bool→int (Fire_*, FireGetItemInfoReceived,
etc.) switched to `static_cast<int>(...)`. NameCache settings file output
relies on the default ostream bool→"0"/"1" formatting.

Literal `PushBoolean(L, 0)` / `PushBoolean(L, 1)` left alone — they're
already explicit int values.
2026-05-16 21:39:46 -05:00
Brues 24ed233c4f Add Game::Lua::SetGlobalNumber, move CLASSIC_API_VERSION to its own module
Three sites were doing the same 3-call (PushString + PushNumber + SetTable
on GLOBALS_INDEX) to declare integer globals. Promote to a shared helper
that uses RawSet (globals have no __newindex in vanilla 1.12, so the
metatable check SetTable does is dead).

Also lift CLASSIC_API_VERSION out of DllMain.cpp into api/Version.cpp
so it self-registers via ModuleAutoRegister like every other Lua surface,
instead of being a special case wired into FrameScript_Initialize_h.
2026-05-16 20:50:48 -05:00
Brues 7520141108 EquipItemByName auto-slot: call CGPlayer::AutoEquipCursorItem directly
Script_AutoEquipCursorItem is a thin Lua wrapper that just resolves
the local player and __thiscall's the engine helper at 0x005E1480.
Cut out the middleman.

Also drop FUN_SCRIPT_EQUIP_CURSOR_ITEM and FUN_SCRIPT_CURSOR_HAS_ITEM
offsets — no callers remain after recent refactors.
2026-05-16 20:50:37 -05:00
Brues da9c4a729a C_GossipInfo selectors call engine helpers directly
The Script_SelectGossip* Lua wrappers are thin stack-readers around
internal __fastcall(slot0Based, ...) engine helpers at 0x004E2320 /
0x004E24B0 / 0x004E2600. Call those directly instead of stomping the
Lua stack and tail-calling the wrappers. Also fixes SelectOption to
pass the password arg through (previously dropped — boxCoded options
needed it).
2026-05-16 18:11:44 -05:00
Brues f263607ec6 FUN_SCRIPT_GET_ADDON_INFO unused 2026-05-16 18:01:47 -05:00
Brues 844a1f16d0 C_Item.GetItemLink now uses engine link builder directly
Drops the Lua-stack-stomp-and-dispatch pattern for Script_GetContainerItemLink /
Script_GetInventoryItemLink. Promotes the BuildLinkForCGItem helper that
GameTooltip:GetItem already uses into a shared Item::Link::FromCGItem, then
GetItemLink resolves the location to a CGItem and calls it directly.
2026-05-16 18:00:46 -05:00
Brues 14d0494015 Location::GetBagSlotCount 2026-05-16 17:58:07 -05:00