Commit Graph
266 Commits
Author SHA1 Message Date
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
Brues 0ad8df1337 Suppress minhook CMake 3.0 deprecation warning
Lifts the policy floor to 3.10 for the vendored submodule via
CMAKE_POLICY_VERSION_MINIMUM, avoiding a patch to external/minhook.
2026-05-16 17:42:03 -05:00
Brues 04f476e1c4 Switch debug log fopen calls to fopen_s
Silences C4996 deprecation warnings under MSVC without disabling
the warning class globally.
2026-05-16 17:39:36 -05:00
Brues 37a1c46c0a ResolveObject added instead of calling raw assembly 2026-05-16 17:38:11 -05:00
Brues b5bcf7f7d1 utilize ColorMixin for GetAuraDispelTypeColor 2026-05-16 17:27:33 -05:00
Brues dbf66daa73 Tightened GetUsesPerItem to match 3.3.5's negative-charge gate. 2026-05-16 17:13:58 -05:00
Brues 4c880c5ac0 C_Reputation.GetFactionDataByIndex(factionSortIndex) 2026-05-16 16:39:43 -05:00
Brues 4fba5d6f24 cleanup 2026-05-16 16:35:52 -05:00
Brues 76e2e7ac66 Found the correct offset for lua_pushvalue a while ago 2026-05-16 16:32:52 -05:00
brues-code 3751491f93 Update README.md 2026-05-16 15:58:20 -05:00
Brues a7aa28f620 moved GetQuestIDFromLogIndex into the C_QuestLog namespace 2026-05-16 15:57:38 -05:00
Brues b0f7f4a2f0 GameTooltip:HasItem() / GameTooltip:HasSpell() 2026-05-16 14:44:57 -05:00
Brues e0f71d2be1 C_Item.GetItemSellPrice(itemLocation) / C_Item.GetItemSellPriceByID(item) 2026-05-16 14:26:56 -05:00
Brues 9a92089ab7 C_MerchantFrame: GetItemInfo, GetBuybackItemID, junk handling
Six functions matching the retail namespace:

- GetItemInfo(slot) reads the 28-byte merchant entry directly.
- GetBuybackItemID(slot) walks buyback storage → player invMgr →
  CGItem instance block. No GetBuybackItemLink roundtrip.
- GetNumJunkItems / SellAllJunkItems iterate bags via the existing
  ResolveBag helper and read quality from the ItemStats cache.
- IsMerchantItemRefundable / IsSellAllJunkEnabled stub to false /
  true to match retail's API contract in a version that has no
  refund mechanic or sell-junk-disabled setting.

SellAllJunkItems calls the engine's internal MerchantSellItem
dispatcher (CMSG_SELL_ITEM) directly rather than going through
Script_UseContainerItem. The dispatcher uses an irregular fastcall
(count in ECX, four stack args, EDX ignored); a dummy EDX in the
typedef forces MSVC to lay the args out the callee expects.

Sells are deferred one per frame via the shared WorldTick
subscriber. Burst-sending 10 CMSG_SELL_ITEM packets in one frame
consistently dropped the 2nd-to-last sell (verified empirically).
Spreading them across frames matches the cadence of click-by-
click selling.

GetNumJunkItems also returns 0 away from a merchant frame to
match retail's contract — the count is meant as a "what would the
sell button do right now" signal, not a passive inventory query.

Includes a small refactor: factored GUID→CGItem resolution out of
EquipmentSet::Locations into Item::Location::ResolveByGUID so it's
shared cleanly between modules, and renamed VAR_MERCHANT_FLAG_A/B
to VAR_MERCHANT_NPC_GUID_LO/HI now that the semantic is decoded.

Cursor-clearing-when-holding-junk left as TODO #93.
2026-05-16 02:08:02 -05:00
Brues 9edaa6095b EncodingUtil: match retail API surface for compression and base64
CompressString/DecompressString take a CompressionMethod enum
(Deflate / Zlib / Gzip). The streaming zlib API (deflateInit2_,
inflateInit2_) handles all three formats via windowBits — the
one-shot compress2/uncompress only do Zlib. Decode auto-detects
Zlib vs Gzip when no method is passed.

EncodeBase64/DecodeBase64 take a Base64Variant (Standard / UrlSafe).
Standard pads with '='; UrlSafe omits padding per RFC 4648 §5.
Decode is strict when a variant is named, lenient (both alphabets,
optional padding) when omitted.

Enum.CompressionMethod and Enum.Base64Variant exposed as globals.
2026-05-16 00:07:07 -05:00
Brues 2cc6cfda86 EncodingUtil 2026-05-15 23:12:16 -05:00
Brues 52fc53a08c UnitIsInMyGuild: drop pcall(UnitName), prefix-gate the token resolver
Prefix-check known tokens inline instead of going through Lua's
UnitName via pcall to figure out "is this a token?". OOR-token name
resolution now goes through FUN_TOKEN_TO_GUID + the engine's player
NameCache directly. Literal-name input still walks the guild roster
by strcmp, unchanged.
2026-05-15 21:26:09 -05:00
Brues a8a970a41d PlayerCache: Key by name 2026-05-15 16:00:19 -05:00
Brues 5330c46e1d C_PlayerCache.GetPlayerInfoByName 2026-05-15 15:29:36 -05:00
Brues 002c4da38e update comment 2026-05-15 14:34:25 -05:00
Brues addef29adc Bypass Script_GetCVar, return nil for cvars that don't exist
tested on anniversary
2026-05-15 14:30:13 -05:00