From 48c2c83bd3b0d8fafa5dab11bb6289353ef669c3 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:46:43 -0600 Subject: [PATCH] refactor(offsets): one name per engine address and per DBC column Offsets.h named the same address or field twice in ten places, against its own single-source rule. A sweep for equal addresses found nine; the tenth is a column pair. Each now has one name: - 0x468460 (the object resolver) was also FUN_GET_OBJECT_BY_GUID and FUN_OBJECT_FROM_GUID, called through local typedefs (one a __thiscall form) in mail/SendMailItemLink, item/scrape/AuctionSellID and cursor/Info. Those now call Object::ByGuid, which also gates on the registry; OBJECT_TYPE_ITEM goes for TYPEMASK_ITEM. - 0x6F3BC0 was LUA_RAWGETI and FUN_FRAMESCRIPT_PUSH_OBJECT; its three callers use Game::Lua::RawGetI. 0x6F3740 (lua_touserdata) becomes LUA_TO_USERDATA beside the other Lua C API names. - 0x605570: FUN_UNIT_CREATURE_TYPE (was also FUN_UNIT_PET_MINION_CLASS). - 0xB4B2BC: VAR_GAME_STATE_PTR (was also VAR_WORLDFRAME_CLICK_INFO). - 0xBC6F48: VAR_PARTY_GUIDS (was also VAR_PARTY_MEMBER_GUIDS). - 0xBB4AA8: VAR_TAXI_NODE_COUNT (was also VAR_TAXI_MAP_NODE_COUNT). - 0xCECAC0: VAR_SPELL_TARGETING_FLAGS (was also VAR_SPELL_PLACEMENT_STATE). - Backpack linear base 23: INVMGR_BACKPACK_FIRST_SLOT (was also BACKPACK_LINEAR_BASE). - Spell.dbc School (+0x04): OFF_SPELL_RECORD_SCHOOL (was also OFF_SPELL_SCHOOL); EffectItemType (+0x19C): OFF_SPELL_RECORD_EFFECT_ITEM_TYPE (was also OFF_SPELL_RECORD_CREATED_ITEM). The surviving entry keeps both comments. --- src/Game.cpp | 17 +++----- src/Offsets.h | 72 ++++++++++--------------------- src/aura/Source.cpp | 2 +- src/cursor/Info.cpp | 27 +++--------- src/item/Data.cpp | 2 +- src/item/Location.cpp | 2 +- src/item/Location.h | 4 +- src/item/NewItems.cpp | 2 +- src/item/scrape/AuctionSellID.cpp | 8 ++-- src/item/scrape/TradeSkillID.cpp | 2 +- src/lossofcontrol/Info.cpp | 2 +- src/mail/SendMailItemLink.cpp | 10 ++--- src/map/Info.cpp | 4 +- src/spell/AutoPrepare.cpp | 2 +- src/spell/Placement.cpp | 4 +- src/spell/Placement.h | 2 +- src/spell/School.cpp | 2 +- src/tooltip/Owner.cpp | 9 +--- src/ui/FrameObject.cpp | 7 +-- src/unit/Pet.cpp | 6 +-- 20 files changed, 62 insertions(+), 124 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 14ae97c0..ebcffeeb 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -118,7 +118,7 @@ namespace Lua { F(CheckStack, lua_checkstack, LUA_CHECK_STACK) \ F(Concat, lua_concat, LUA_CONCAT) \ F(NewUserdata, lua_newuserdata, LUA_NEW_USERDATA) \ - F(ToUserdata, lua_touserdata, FUN_FRAMESCRIPT_GET_OBJECT) + F(ToUserdata, lua_touserdata, LUA_TO_USERDATA) #define CLASSICAPI_BIND_LUA(Name, Typedef, Offset) \ const Typedef##_t Name = reinterpret_cast(Offsets::Offset); @@ -136,18 +136,11 @@ void *State() { return Game::Read(Offsets::VAR_LUA_STATE); } -namespace { -using FrameScriptPushObject_t = void(__fastcall *)(void *L, int idx, int unused); -using FrameScriptGetObject_t = void *(__fastcall *)(void *L, int idx); -} // namespace - void *ResolveObject(void *L, int idx) { - auto PushObject = reinterpret_cast( - Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT); - auto GetObject = reinterpret_cast( - Offsets::FUN_FRAMESCRIPT_GET_OBJECT); - PushObject(L, idx, 0); - void *result = GetObject(L, -1); + // The Set* method prologue's own path: the frame table's [0] is the + // lightuserdata CFrameScriptObject *. + RawGetI(L, idx, 0); + void *result = ToUserdata(L, -1); SetTop(L, -2); return result; } diff --git a/src/Offsets.h b/src/Offsets.h index 784faf0a..0c676f7e 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -167,20 +167,14 @@ enum Offsets { // " " — the token delimiter LoadBindings splits a `bind` line's key with. VAR_STR_SPACE_DELIM = 0x0082EE00, - // GameTooltip script-method prologue helpers (used to resolve self → CFrameScriptObject*). - // Underlying Lua C API names per [[docs/LuaCAPI.md]] are `lua_rawgeti` - // (0x6F3BC0) and `lua_touserdata` (0x6F3740). The Set* method prologue's - // call sequence - // PushObject(L, idx, 0); // == lua_rawgeti(L, idx, 0) — pushes the - // // lightuserdata at table[0] - // GetObject(L, -1); // == lua_touserdata(L, -1) — extracts - // // the raw CFrameScriptObject * - // is the canonical "Lua frame table → C++ object" path. The reverse - // (`GameTooltip:GetOwner` etc.) is just `lua_rawgeti(L, REGISTRY, - // [cobj+OFF_COBJECT_LUA_REF])` — the engine pre-allocates - // the registry handle when the frame is created from Lua. - FUN_FRAMESCRIPT_PUSH_OBJECT = 0x6F3BC0, - FUN_FRAMESCRIPT_GET_OBJECT = 0x6F3740, + // `lua_touserdata` (per [[docs/LuaCAPI.md]]). With `lua_rawgeti` + // (LUA_RAWGETI) it is the Set* method prologue's "Lua frame table → C++ + // object" path: rawgeti(L, idx, 0) pushes the lightuserdata at table[0], + // touserdata(L, -1) extracts the CFrameScriptObject * (Game::Lua:: + // ResolveObject). The reverse (`GameTooltip:GetOwner` etc.) is + // rawgeti(L, REGISTRY, [cobj+OFF_COBJECT_LUA_REF]) — the engine + // pre-allocates the registry handle when the frame is created from Lua. + LUA_TO_USERDATA = 0x6F3740, // Within a CGFrame, the embedded LayoutFrame sub-object starts here. // Engine code that wants to invoke LayoutFrame methods polymorphically @@ -2491,7 +2485,6 @@ enum Offsets { // pets are Beasts, warlock minions are Demons (type 3) — so `!= 1` // cleanly separates them, which neither the GUID (pets and guardians // share the 0xF14… prefix) nor UNIT_FLAG_PLAYER_CONTROLLED reliably does. - FUN_UNIT_PET_MINION_CLASS = 0x00605570, FUN_UNIT_CREATURE_TYPE = 0x00605570, // Party / raid roster counts and the party GUID array referenced @@ -3587,11 +3580,10 @@ enum Offsets { // The taxi map opener (0x004DB710) ends like 4.3.4's: TAXIMAP_OPENED, // then tutorial 34 through FUN_TRIGGER_TUTORIAL (`void __fastcall(int // id, int)`) at this call; 4.3.4 then stands, dismounts and leaves the - // form when the map has more than one node (VAR_TAXI_MAP_NODE_COUNT, + // form when the map has more than one node (VAR_TAXI_NODE_COUNT, // the count the opener's TaxiNodeSetCurrent loop runs to). CALL_TAXI_MAP_OPENED_TUTORIAL = 0x004DBAA2, FUN_TRIGGER_TUTORIAL = 0x004B5390, - VAR_TAXI_MAP_NODE_COUNT = 0x00BB4AA8, // Effective spell/channel duration (ms): // `__fastcall int(const void *spellRecord, int pet /*0 = player, @@ -5702,10 +5694,6 @@ enum Offsets { // returns the container's inventory object — `void* __thiscall(container)`. // The inventory object's slot count lives at its +0x00 (OFF_INVMGR_SLOT_COUNT). OFF_CONTAINER_GET_INVENTORY = 0x10, - // Backpack (bagID 0) linear-slot base in the player invMgr GUID/item - // arrays: a 1-based backpack slot S maps to linear (S - 1) + 23. Matches - // PackBagSlot's `*param_3 += 0x17` for the backpack branch. - BACKPACK_LINEAR_BASE = 23, // Lua container indices (bagID), as `PackBagSlot` reads them and FrameXML // names them (KEYRING_CONTAINER, BANK_CONTAINER, BACKPACK_CONTAINER, // NUM_BAG_SLOTS, NUM_BANKBAGSLOTS): keyring -2, bank -1, backpack 0, @@ -5741,6 +5729,9 @@ enum Offsets { // it hides data that's present from boot. Reading the GUID array // directly recovers it without ever opening the bank window. OFF_INVMGR_GUID_ARRAY = 0x04, + // A 1-based backpack slot S is linear (S - 1) + INVMGR_BACKPACK_FIRST_SLOT + // in the player invMgr GUID/item arrays: PackBagSlot's `*param_3 += 0x17` + // for the backpack branch. INVMGR_BACKPACK_FIRST_SLOT = 23, INVMGR_BACKPACK_LAST_SLOT = 38, INVMGR_BANK_MAIN_FIRST_SLOT = 39, @@ -9034,8 +9025,8 @@ enum Offsets { // - `0x20` source world location needed // - `0x40` dest world location needed // The `0x60` mask therefore identifies "ground-target placement" - // (vs. unit-target, trade-target, etc.). See `Spell::Placement`. - VAR_SPELL_PLACEMENT_STATE = 0x00CECAC0, + // (vs. unit-target, trade-target, etc.). See `Spell::Placement`. The + // word itself is VAR_SPELL_TARGETING_FLAGS. SPELL_PLACEMENT_GROUND_MASK = 0x60, // `FUN_006E60F0(float *xyz)` — commits the in-flight ground-target @@ -9056,8 +9047,8 @@ enum Offsets { // `Script_SpellStopTargeting`. FUN_STOP_PLACEMENT = 0x006E4900, - // `*VAR_WORLDFRAME_CLICK_INFO` is a pointer to the engine's - // CWorldFrame "click info" struct — the data block where the input + // `*VAR_GAME_STATE_PTR` is also the engine's CWorldFrame "click info" + // struct — the data block where the input // dispatcher stashes "what is the cursor pointed at right now" // after every mouse motion. Allocated at world enter, populated // continuously by the rendering pipeline (viewport bounds and @@ -9068,7 +9059,6 @@ enum Offsets { // `1` = world / terrain hit // `2` = unit / object hit // - `+0x360..+0x368` (3 floats) hit world position (when type == 1) - VAR_WORLDFRAME_CLICK_INFO = 0x00B4B2BC, OFF_CLICK_INFO_TYPE = 0x350, OFF_CLICK_INFO_COORDS = 0x360, @@ -9277,7 +9267,7 @@ enum Offsets { // belongs to exactly one school. Mapping: // 0 = Physical 1 = Holy 2 = Fire 3 = Nature // 4 = Frost 5 = Shadow 6 = Arcane - OFF_SPELL_SCHOOL = 0x04, + OFF_SPELL_RECORD_SCHOOL = 0x04, SPELL_SCHOOL_COUNT = 7, // Spell.dbc DispelType field — u32 at record +0x10, indexes into @@ -9536,13 +9526,12 @@ enum Offsets { // `FUN_RESOLVE_UNIT_TOKEN`, which only resolves to a local CGUnit // and returns NULL for group members in other zones. // - // Party: 4 entries × 8 bytes (lo + hi). `guids[i]` corresponds to - // "partyN" where N = i+1. + // Party: VAR_PARTY_GUIDS, 4 entries × 8 bytes (lo + hi). `guids[i]` + // corresponds to "partyN" where N = i+1. // // Raid: 40 entries × 4 bytes — each is a `RaidMember *`. GUID is // at `*member + 0` (lo) and `*member + 4` (hi). Verified from // `FUN_004bb0f0`. Slot may be NULL (empty / offline raid member). - VAR_PARTY_MEMBER_GUIDS = 0x00BC6F48, VAR_RAID_MEMBER_PTRS = 0x00B712A8, // Raid-target-marker GUID table — 8 contiguous `uint64` slots, one @@ -12511,13 +12500,6 @@ enum Offsets { // modern `duration` arg (1/2/3) indexes this table. VAR_AUCTION_DURATION_TABLE = 0x00807028, AUCTION_DURATION_TABLE_COUNT = 3, - // `__fastcall(ECX = typeCode, EDX = unused, [stack] = guidLo, - // [stack] = guidHi, [stack] = anyInt) → CGObject *`. - // Returns NULL when no object matches or the type doesn't match. - // The third stack arg (originally a `__FILE__/__LINE__` debug - // hint) is read by debug paths only — anything works at runtime. - FUN_GET_OBJECT_BY_GUID = 0x00468460, - OBJECT_TYPE_ITEM = 2, // Melee auto-attack primitives (back StartAttack / StopAttack). 1.12 // exposes only the toggling AttackTarget (0x00489B50 -> FUN_006131A0); @@ -12694,12 +12676,10 @@ enum Offsets { // 3 pet. Script_IsTradeskillTrainer (0x004D8EA0) tests `== 2`. VAR_TRAINER_TYPE = 0x00B73A08, TRAINER_TYPE_TRADESKILLS = 2, - // Spell.dbc "produced item" field for crafting recipes — the - // itemID this spell creates when cast. Reagent itemIDs and - // counts live at `OFF_SPELL_REAGENT_ID` / `OFF_SPELL_REAGENT_COUNT` - // above (shared with all spells that consume reagents, not just - // recipes). - OFF_SPELL_RECORD_CREATED_ITEM = 0x19C, + // A crafting recipe's produced item is its first effect's item, + // OFF_SPELL_RECORD_EFFECT_ITEM_TYPE[0]. Reagent itemIDs and counts live at + // `OFF_SPELL_REAGENT_ID` / `OFF_SPELL_REAGENT_COUNT` above (shared with all + // spells that consume reagents, not just recipes). SPELL_RECIPE_MAX_REAGENTS = 8, // Spell.dbc effect arrays — three effects per spell. Derived @@ -12938,7 +12918,6 @@ enum Offsets { // MASK is `1 << School` (the server's GetSpellSchoolMask). Verified in // Spell.dbc: Kick 0, Fireball 2, Earth Shock 3, Shadow Bolt 5, // Counterspell 6. Read by Spell::Interruptible. - OFF_SPELL_RECORD_SCHOOL = 0x04, // u32 (column 1) OFF_SPELL_RECORD_CASTING_TIME_INDEX = 0x48, // u32 → SpellCastTimes.dbc OFF_SPELL_RECORD_MAX_LEVEL = 0x6C, // u32 (scaling cap level) OFF_SPELL_RECORD_SPELL_LEVEL = 0x74, // u32 (this rank's effective level) @@ -13443,11 +13422,6 @@ enum Offsets { // payload globals, not VAR_CURSOR_TYPE. Disassembled. FUN_WORLD_BUTTON_HOOK = 0x00492B50, - // GUID → CGObject resolver. `__fastcall(type_filter, guid_lo, - // guid_hi) → CGObject *` at `0x00468460`. Type filter 0x2 = item, - // matching what `FUN_00494B60` and the trade-attached paths pass - // when re-resolving the cursor GUID to a `CGItem *`. - FUN_OBJECT_FROM_GUID = 0x00468460, // Virtual XML-template registry (a Storm hash table) — the store that // backs `inherits=` and `C_XMLUtil.GetTemplates`. The XML parser diff --git a/src/aura/Source.cpp b/src/aura/Source.cpp index 0a62b53b..fb55bcae 100644 --- a/src/aura/Source.cpp +++ b/src/aura/Source.cpp @@ -615,7 +615,7 @@ bool TriggerMatches(const DurationMod &m, uint32_t triggerSpellId, return false; if (m.triggerSchool >= 0 && static_cast(*reinterpret_cast( - triggerRec + Offsets::OFF_SPELL_SCHOOL)) != m.triggerSchool) + triggerRec + Offsets::OFF_SPELL_RECORD_SCHOOL)) != m.triggerSchool) return false; return true; } diff --git a/src/cursor/Info.cpp b/src/cursor/Info.cpp index 160c33d6..64ec39a5 100644 --- a/src/cursor/Info.cpp +++ b/src/cursor/Info.cpp @@ -54,6 +54,7 @@ #include "item/ID.h" #include "item/Link.h" #include "spell/Lookup.h" +#include "object/Resolve.h" #include @@ -61,20 +62,6 @@ namespace Cursor::Info { namespace { -// Engine signature is `__thiscall(this = typeFilter, guidLo, guidHi, -// unused)`. The "this" param is just a small integer filter — Ghidra -// shows it cast as `(void *)0x2` at every call site for items. The -// function reads only the first two stack args (`[ebp+8]` and -// `[ebp+0xC]`) but cleans 12 bytes via `ret 0xc`, so the caller must -// push a third dword for stack balance — engine callers push a -// scratch dword (`0x90`, `0x1C13`, etc.) for this. Declaring a 4th -// arg here makes MSVC emit the matching push; without it, stack -// imbalance of -4 bytes silently corrupts the caller's frame and -// (downstream) wedges things like chat input. -using ObjectFromGUID_t = uint8_t *(__thiscall *)(uintptr_t typeFilter, - uint32_t guidLo, uint32_t guidHi, - uint32_t unused); - constexpr uint32_t TYPE_EMPTY = 0; constexpr uint32_t TYPE_BAG_ITEM = 1; constexpr uint32_t TYPE_MONEY = 2; @@ -114,7 +101,6 @@ constexpr int UI_MACRO = 7; constexpr int UI_PET = 9; constexpr int UI_EQUIPMENT_SET = 12; -constexpr uint32_t GUID_TYPE_FILTER_ITEM = 0x2; uint32_t ReadVar(uintptr_t va) { return *reinterpret_cast(va); @@ -151,7 +137,7 @@ int PushItem(void *L, const uint8_t *cgItem) { // (plus a virtual call into the sub-object at `+0x110`, whose // vftable is also untouched while held on the cursor). Earlier // crash repros were the stack-imbalance bug in the GUID resolver - // — see Offsets::FUN_OBJECT_FROM_GUID. + // — Object::ByGuid now owns that call. const char *link = Item::Link::FromCGItem(cgItem); if (link != nullptr && *link != '\0') { Game::Lua::PushString(L, link); @@ -165,8 +151,8 @@ int PushBagItemCursor(void *L) { const uint32_t hi = ReadVar(Offsets::VAR_CURSOR_ITEM_GUID_HI); if (lo == 0 && hi == 0) return 0; - auto resolver = reinterpret_cast(Offsets::FUN_OBJECT_FROM_GUID); - const uint8_t *cgItem = resolver(GUID_TYPE_FILTER_ITEM, lo, hi, 0); + const uint8_t *cgItem = static_cast(Object::ByGuid( + Offsets::TYPEMASK_ITEM, (static_cast(hi) << 32) | lo, nullptr, 0)); return PushItem(L, cgItem); } @@ -335,9 +321,8 @@ State Current() { // FrameXML already calls into it from a CURSOR_UPDATE // handler, so the object manager is queryable at this point // in the dispatch. - auto resolver = - reinterpret_cast(Offsets::FUN_OBJECT_FROM_GUID); - const uint8_t *cgItem = resolver(GUID_TYPE_FILTER_ITEM, lo, hi, 0); + const uint8_t *cgItem = static_cast(Object::ByGuid( + Offsets::TYPEMASK_ITEM, (static_cast(hi) << 32) | lo, nullptr, 0)); const int itemID = (cgItem != nullptr) ? Item::ID::FromCGItem(cgItem) : 0; return {UI_ITEM, itemID > 0 ? static_cast(itemID) : 0u}; diff --git a/src/item/Data.cpp b/src/item/Data.cpp index 72864378..f8165048 100644 --- a/src/item/Data.cpp +++ b/src/item/Data.cpp @@ -451,7 +451,7 @@ static void RebuildOwned() { // Player invMgr linear slots 0..38: equipment + bag-slot items + // backpack (bank starts at INVMGR_BANK_MAIN_FIRST_SLOT = 39). CollectOwnedFrom(invMgr, 0, - Offsets::BACKPACK_LINEAR_BASE + Offsets::BACKPACK_NUM_SLOTS - 1); + Offsets::INVMGR_BACKPACK_FIRST_SLOT + Offsets::BACKPACK_NUM_SLOTS - 1); // Contents of each equipped bag (its own invMgr, slot count at +0). for (int bagID = 1; bagID <= 4; ++bagID) { auto *bagInv = diff --git a/src/item/Location.cpp b/src/item/Location.cpp index 63266fb6..102d65ec 100644 --- a/src/item/Location.cpp +++ b/src/item/Location.cpp @@ -279,7 +279,7 @@ const uint8_t *ResolveBagSlotNoLua(int bagID, int slotIndex) { if (invMgr == nullptr) return nullptr; return static_cast( - GetItemBySlot(invMgr, Offsets::BACKPACK_LINEAR_BASE + slotIndex - 1)); + GetItemBySlot(invMgr, Offsets::INVMGR_BACKPACK_FIRST_SLOT + slotIndex - 1)); } void *bagInv = BagInventory(bagID); if (bagInv == nullptr) diff --git a/src/item/Location.h b/src/item/Location.h index 7700b972..b36dfa95 100644 --- a/src/item/Location.h +++ b/src/item/Location.h @@ -100,7 +100,7 @@ const uint8_t *BagContainer(int bagID); // `+OFF_INVMGR_GUID_ARRAY`) and is what `GetItemBySlot` indexes with a // 0-based slot. Null when `BagContainer` is. Pure C — no Lua stack. (The // backpack, `bagID` 0, has no container object; index it directly off the -// player inventory manager at `BACKPACK_LINEAR_BASE + slot - 1`.) +// player inventory manager at `INVMGR_BACKPACK_FIRST_SLOT + slot - 1`.) void *BagInventory(int bagID); // Where a found item sits. Bank covers the main bank, the bank bags and @@ -251,7 +251,7 @@ bool FindItemArgOrLocation(void *L, int idx, ByGUIDResult *out); // Resolves `(bagID, slotIndex)` to its `CGItem *` WITHOUT the Lua stack: // the backpack (bag 0) is indexed straight off the player inventory manager -// at `BACKPACK_LINEAR_BASE + slot - 1`, bags 1..10 through `BagInventory` +// at `INVMGR_BACKPACK_FIRST_SLOT + slot - 1`, bags 1..10 through `BagInventory` // (bank bags only at a banker) — both via the engine's `GetItemBySlot`. Returns // nullptr for a bad bag, an out-of-range slot, or an empty slot. Safe from // any context (world tick, packet hooks) — the `PackBagSlot`-based diff --git a/src/item/NewItems.cpp b/src/item/NewItems.cpp index 592fda6e..124c8872 100644 --- a/src/item/NewItems.cpp +++ b/src/item/NewItems.cpp @@ -231,7 +231,7 @@ int ScanBags(const uint8_t *player, uint64_t *out) { const int backpackSlots = Item::Location::GetBagSlotCount(0); for (int slot = 1; slot <= backpackSlots; ++slot) { auto *item = static_cast( - getItemBySlot(invMgr, Offsets::BACKPACK_LINEAR_BASE + slot - 1)); + getItemBySlot(invMgr, Offsets::INVMGR_BACKPACK_FIRST_SLOT + slot - 1)); const uint64_t guid = ItemGUID(item); if (guid != 0) AddUnique(out, &count, guid); diff --git a/src/item/scrape/AuctionSellID.cpp b/src/item/scrape/AuctionSellID.cpp index d5dc64fa..4c34f4e8 100644 --- a/src/item/scrape/AuctionSellID.cpp +++ b/src/item/scrape/AuctionSellID.cpp @@ -14,6 +14,7 @@ #include "Game.h" #include "Offsets.h" #include "item/ID.h" +#include "object/Resolve.h" #include @@ -25,9 +26,6 @@ namespace { // 64-bit GUID split into low/high on the stack. The third stack arg // is a `__LINE__`-style debug hint that the function reads only for // asserts — anything works at runtime. -using GetObjectByGUID_t = void *(__fastcall *)(int typeCode, void *unused, - uint32_t guidLo, uint32_t guidHi, - int debugLine); } // namespace @@ -43,9 +41,9 @@ static int __fastcall Script_GetAuctionSellItemID(void *L) { if ((guidLo | guidHi) == 0) return 0; - auto lookup = reinterpret_cast(Offsets::FUN_GET_OBJECT_BY_GUID); + const uint64_t guid = (static_cast(guidHi) << 32) | guidLo; auto *item = static_cast( - lookup(Offsets::OBJECT_TYPE_ITEM, nullptr, guidLo, guidHi, 0)); + Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, nullptr, 0)); if (item == nullptr) return 0; diff --git a/src/item/scrape/TradeSkillID.cpp b/src/item/scrape/TradeSkillID.cpp index 81304234..40bf80cb 100644 --- a/src/item/scrape/TradeSkillID.cpp +++ b/src/item/scrape/TradeSkillID.cpp @@ -39,7 +39,7 @@ int __fastcall Script_GetTradeSkillItemID(void *L) { return 0; const int itemID = static_cast(*reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_CREATED_ITEM)); + record + Offsets::OFF_SPELL_RECORD_EFFECT_ITEM_TYPE)); if (itemID == 0) return 0; diff --git a/src/lossofcontrol/Info.cpp b/src/lossofcontrol/Info.cpp index 00698e06..8e1b36e8 100644 --- a/src/lossofcontrol/Info.cpp +++ b/src/lossofcontrol/Info.cpp @@ -74,7 +74,7 @@ const char *SpellIconPath(const uint8_t *rec) { } int SpellSchoolIndex(const uint8_t *rec) { - return Game::Read(rec, Offsets::OFF_SPELL_SCHOOL); + return Game::Read(rec, Offsets::OFF_SPELL_RECORD_SCHOOL); } // The control-loss classifier lives in `Spell::CrowdControl::Classify` so the diff --git a/src/mail/SendMailItemLink.cpp b/src/mail/SendMailItemLink.cpp index 93a04441..842d25bf 100644 --- a/src/mail/SendMailItemLink.cpp +++ b/src/mail/SendMailItemLink.cpp @@ -26,7 +26,7 @@ // The attached item still exists as a live CGItem in the player's // inventory until the mail is actually sent — the engine stores its // GUID at `VAR_SEND_MAIL_ITEM_GUID_LO/HI`. We resolve the GUID via -// `FUN_GET_OBJECT_BY_GUID(OBJECT_TYPE_ITEM, ...)` and feed the +// `Object::ByGuid(TYPEMASK_ITEM, ...)` and feed the // resulting CGItem to the standard `Item::Link::FromCGItem` builder, // so enchant / random-suffix / unique-ID decoration matches what // `GetContainerItemLink` would return for the same item back in @@ -36,6 +36,7 @@ #include "Offsets.h" #include "item/ID.h" #include "item/Link.h" +#include "object/Resolve.h" #include @@ -43,9 +44,6 @@ namespace Mail::SendMailItemLink { namespace { -using GetObjectByGuid_t = void *(__fastcall *)(uint32_t typeMask, const char *debugMsg, - uint32_t guidLo, uint32_t guidHi, - int debugCode); int __fastcall Script_GetSendMailItemLink(void *L) { // Optional 1-based attachment index. Anything other than 1 is a @@ -63,9 +61,9 @@ int __fastcall Script_GetSendMailItemLink(void *L) { if (guidLo == 0 && guidHi == 0) return 0; - auto fn = reinterpret_cast(Offsets::FUN_GET_OBJECT_BY_GUID); + const uint64_t guid = (static_cast(guidHi) << 32) | guidLo; auto *cgItem = static_cast( - fn(Offsets::OBJECT_TYPE_ITEM, nullptr, guidLo, guidHi, 0)); + Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, nullptr, 0)); if (cgItem == nullptr) return 0; diff --git a/src/map/Info.cpp b/src/map/Info.cpp index 738e3694..cb89f6ac 100644 --- a/src/map/Info.cpp +++ b/src/map/Info.cpp @@ -43,13 +43,13 @@ int ParseSlot(const char *s, int max) { } // Look up the GUID stored in the party member slot directly. Slots are -// 0..3 in the parallel GUID table at `VAR_PARTY_MEMBER_GUIDS` (8-byte +// 0..3 in the parallel GUID table at `VAR_PARTY_GUIDS` (8-byte // stride). Returns 0 if the slot is empty (no party member there). uint64_t PartySlotGUID(int slot) { if (slot < 0 || slot >= 4) return 0; auto *guids = reinterpret_cast( - static_cast(Offsets::VAR_PARTY_MEMBER_GUIDS)); + static_cast(Offsets::VAR_PARTY_GUIDS)); return guids[slot]; } diff --git a/src/spell/AutoPrepare.cpp b/src/spell/AutoPrepare.cpp index b76a9a39..324633bf 100644 --- a/src/spell/AutoPrepare.cpp +++ b/src/spell/AutoPrepare.cpp @@ -504,7 +504,7 @@ __declspec(naked) void StartAttackPassedThunk() { // stand, dismount and form cancel for a map with more than one node. void __fastcall TaxiMapOpenedTutorial(int id, int arg) { reinterpret_cast(Offsets::FUN_TRIGGER_TUTORIAL)(id, arg); - if (Game::Read(static_cast(Offsets::VAR_TAXI_MAP_NODE_COUNT)) <= 1) + if (Game::Read(static_cast(Offsets::VAR_TAXI_NODE_COUNT)) <= 1) return; const void *player = Unit::Identity::PlayerObject(); if (player == nullptr) diff --git a/src/spell/Placement.cpp b/src/spell/Placement.cpp index 6e2741aa..09369abf 100644 --- a/src/spell/Placement.cpp +++ b/src/spell/Placement.cpp @@ -46,7 +46,7 @@ using CastDispatch_t = void(__fastcall *)(unsigned slot, int bookType, using NameToSlot_t = int(__fastcall *)(const char *name, void *out); uint32_t State() { - return *reinterpret_cast(Offsets::VAR_SPELL_PLACEMENT_STATE); + return *reinterpret_cast(Offsets::VAR_SPELL_TARGETING_FLAGS); } bool InWorld() { @@ -117,7 +117,7 @@ bool CommitAtCursor() { return false; void *clickInfo = *reinterpret_cast( - Offsets::VAR_WORLDFRAME_CLICK_INFO); + Offsets::VAR_GAME_STATE_PTR); if (clickInfo == nullptr) return false; diff --git a/src/spell/Placement.h b/src/spell/Placement.h index 9ade4e6d..97e89868 100644 --- a/src/spell/Placement.h +++ b/src/spell/Placement.h @@ -30,7 +30,7 @@ namespace Spell::Placement { // True while the engine has an in-flight targeting placement of any kind -// (ground reticle, unit/item/corpse select). `VAR_SPELL_PLACEMENT_STATE != 0`. +// (ground reticle, unit/item/corpse select). `VAR_SPELL_TARGETING_FLAGS != 0`. bool IsActive(); // Cancels any in-flight placement. No-op when none is active. diff --git a/src/spell/School.cpp b/src/spell/School.cpp index aaf8f56f..47ac02d6 100644 --- a/src/spell/School.cpp +++ b/src/spell/School.cpp @@ -58,7 +58,7 @@ int __fastcall Script_GetSpellSchool(void *L) { if (rec == nullptr) return 0; const uint32_t school0 = *reinterpret_cast( - rec + Offsets::OFF_SPELL_SCHOOL); + rec + Offsets::OFF_SPELL_RECORD_SCHOOL); if (school0 >= Offsets::SPELL_SCHOOL_COUNT) return 0; Game::Lua::PushNumber(L, static_cast(school0 + 1)); diff --git a/src/tooltip/Owner.cpp b/src/tooltip/Owner.cpp index b48d341b..65972f05 100644 --- a/src/tooltip/Owner.cpp +++ b/src/tooltip/Owner.cpp @@ -39,11 +39,6 @@ namespace Tooltip::Owner { -namespace { -// FUN_FRAMESCRIPT_PUSH_OBJECT is `lua_rawgeti` — see Offsets.h comment. -using LuaRawGetI_t = void(__fastcall *)(void *L, int idx, int n); -} // namespace - static int __fastcall Script_GameTooltipGetOwner(void *L) { if (Game::Lua::Type(L, 1) != Game::Lua::TYPE_TABLE) { Game::Lua::Error(L, "Usage: GameTooltip:GetOwner()"); @@ -61,9 +56,7 @@ static int __fastcall Script_GameTooltipGetOwner(void *L) { auto *ownerFrame = layoutFrame - Offsets::OFF_FRAME_LAYOUT_SUBOBJECT; const int refKey = Game::Read(ownerFrame, Offsets::OFF_COBJECT_LUA_REF); - auto rawgeti = reinterpret_cast( - Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT); - rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); + Game::Lua::RawGetI(L, Game::Lua::REGISTRY_INDEX, refKey); return 1; } diff --git a/src/ui/FrameObject.cpp b/src/ui/FrameObject.cpp index 185029bc..12169a87 100644 --- a/src/ui/FrameObject.cpp +++ b/src/ui/FrameObject.cpp @@ -22,7 +22,6 @@ namespace UI::FrameObject { namespace { -using LuaRawGetI_t = void(__fastcall *)(void *L, int idx, int n); using ScriptRegister_t = void(__fastcall *)(void *this_, void *edx_unused, const char *name); @@ -54,8 +53,6 @@ using ScriptRegister_t = void(__fastcall *)(void *this_, void *edx_unused, // more (freed elsewhere), re-register to rebuild a fresh wrapper. This // shouldn't happen in practice — engines only unref on frame destruction. void Push(void *L, void *frame) { - auto rawgeti = reinterpret_cast( - Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT); auto scriptRegister = reinterpret_cast( static_cast(Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER)); @@ -66,7 +63,7 @@ void Push(void *L, void *frame) { refKey = Game::Read(cobj, Offsets::OFF_COBJECT_LUA_REF); } - rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); + Game::Lua::RawGetI(L, Game::Lua::REGISTRY_INDEX, refKey); if (Game::Lua::Type(L, -1) == Game::Lua::TYPE_TABLE) return; Game::Lua::SetTop(L, -2); @@ -77,7 +74,7 @@ void Push(void *L, void *frame) { Game::Ref(cobj, Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0; scriptRegister(frame, nullptr, nullptr); refKey = Game::Read(cobj, Offsets::OFF_COBJECT_LUA_REF); - rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); + Game::Lua::RawGetI(L, Game::Lua::REGISTRY_INDEX, refKey); } } // namespace UI::FrameObject diff --git a/src/unit/Pet.cpp b/src/unit/Pet.cpp index ac8276d3..e0dafed3 100644 --- a/src/unit/Pet.cpp +++ b/src/unit/Pet.cpp @@ -59,7 +59,7 @@ namespace { // `int __fastcall(unit)` → 1 for a controllable pet, non-1 otherwise. // The engine's pet-vs-minion title discriminator. See -// FUN_UNIT_PET_MINION_CLASS. +// FUN_UNIT_CREATURE_TYPE. using PetMinionClass_t = int(__fastcall *)(const void *unit); const uint8_t *ResolveUnit(void *L) { @@ -93,7 +93,7 @@ int __fastcall Script_UnitIsMinion(void *L) { // `UnitIsPet(unit)` — true iff the unit is a **pet** of a player (as // opposed to a guardian/totem "minion"): owned by a player AND the -// engine's pet/minion classifier `FUN_UNIT_PET_MINION_CLASS` returns 1. +// engine's pet/minion classifier `FUN_UNIT_CREATURE_TYPE` returns 1. // That classifier — reading the creature *family*, not the GUID or the // player-controlled flag — is exactly what the engine uses to title a unit // "X's Pet" vs "X's Minion". On 1.12/Turtle the GUID can't be used (pets @@ -116,7 +116,7 @@ int __fastcall Script_UnitIsPet(void *L) { bool pet = false; if (Guid::IsPlayer(Unit::Identity::OwnerGuid(unit))) { auto classify = reinterpret_cast( - Offsets::FUN_UNIT_PET_MINION_CLASS); + Offsets::FUN_UNIT_CREATURE_TYPE); pet = (classify(unit) == 1); } Game::Lua::PushBool(L, pet);