mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
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.
This commit is contained in:
+5
-12
@@ -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<Typedef##_t>(Offsets::Offset);
|
||||
@@ -136,18 +136,11 @@ void *State() {
|
||||
return Game::Read<void *>(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<FrameScriptPushObject_t>(
|
||||
Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT);
|
||||
auto GetObject = reinterpret_cast<FrameScriptGetObject_t>(
|
||||
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;
|
||||
}
|
||||
|
||||
+23
-49
@@ -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
|
||||
|
||||
+1
-1
@@ -615,7 +615,7 @@ bool TriggerMatches(const DurationMod &m, uint32_t triggerSpellId,
|
||||
return false;
|
||||
if (m.triggerSchool >= 0 &&
|
||||
static_cast<int32_t>(*reinterpret_cast<const uint32_t *>(
|
||||
triggerRec + Offsets::OFF_SPELL_SCHOOL)) != m.triggerSchool)
|
||||
triggerRec + Offsets::OFF_SPELL_RECORD_SCHOOL)) != m.triggerSchool)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-21
@@ -54,6 +54,7 @@
|
||||
#include "item/ID.h"
|
||||
#include "item/Link.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -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<const uint32_t *>(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<ObjectFromGUID_t>(Offsets::FUN_OBJECT_FROM_GUID);
|
||||
const uint8_t *cgItem = resolver(GUID_TYPE_FILTER_ITEM, lo, hi, 0);
|
||||
const uint8_t *cgItem = static_cast<const uint8_t *>(Object::ByGuid(
|
||||
Offsets::TYPEMASK_ITEM, (static_cast<uint64_t>(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<ObjectFromGUID_t>(Offsets::FUN_OBJECT_FROM_GUID);
|
||||
const uint8_t *cgItem = resolver(GUID_TYPE_FILTER_ITEM, lo, hi, 0);
|
||||
const uint8_t *cgItem = static_cast<const uint8_t *>(Object::ByGuid(
|
||||
Offsets::TYPEMASK_ITEM, (static_cast<uint64_t>(hi) << 32) | lo, nullptr, 0));
|
||||
const int itemID =
|
||||
(cgItem != nullptr) ? Item::ID::FromCGItem(cgItem) : 0;
|
||||
return {UI_ITEM, itemID > 0 ? static_cast<uint32_t>(itemID) : 0u};
|
||||
|
||||
+1
-1
@@ -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 =
|
||||
|
||||
@@ -279,7 +279,7 @@ const uint8_t *ResolveBagSlotNoLua(int bagID, int slotIndex) {
|
||||
if (invMgr == nullptr)
|
||||
return nullptr;
|
||||
return static_cast<const uint8_t *>(
|
||||
GetItemBySlot(invMgr, Offsets::BACKPACK_LINEAR_BASE + slotIndex - 1));
|
||||
GetItemBySlot(invMgr, Offsets::INVMGR_BACKPACK_FIRST_SLOT + slotIndex - 1));
|
||||
}
|
||||
void *bagInv = BagInventory(bagID);
|
||||
if (bagInv == nullptr)
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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<const uint8_t *>(
|
||||
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);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/ID.h"
|
||||
#include "object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -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<GetObjectByGUID_t>(Offsets::FUN_GET_OBJECT_BY_GUID);
|
||||
const uint64_t guid = (static_cast<uint64_t>(guidHi) << 32) | guidLo;
|
||||
auto *item = static_cast<uint8_t *>(
|
||||
lookup(Offsets::OBJECT_TYPE_ITEM, nullptr, guidLo, guidHi, 0));
|
||||
Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, nullptr, 0));
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ int __fastcall Script_GetTradeSkillItemID(void *L) {
|
||||
return 0;
|
||||
|
||||
const int itemID = static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
record + Offsets::OFF_SPELL_RECORD_CREATED_ITEM));
|
||||
record + Offsets::OFF_SPELL_RECORD_EFFECT_ITEM_TYPE));
|
||||
if (itemID == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ const char *SpellIconPath(const uint8_t *rec) {
|
||||
}
|
||||
|
||||
int SpellSchoolIndex(const uint8_t *rec) {
|
||||
return Game::Read<int>(rec, Offsets::OFF_SPELL_SCHOOL);
|
||||
return Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_SCHOOL);
|
||||
}
|
||||
|
||||
// The control-loss classifier lives in `Spell::CrowdControl::Classify` so the
|
||||
|
||||
@@ -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 <cstdint>
|
||||
|
||||
@@ -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<GetObjectByGuid_t>(Offsets::FUN_GET_OBJECT_BY_GUID);
|
||||
const uint64_t guid = (static_cast<uint64_t>(guidHi) << 32) | guidLo;
|
||||
auto *cgItem = static_cast<const uint8_t *>(
|
||||
fn(Offsets::OBJECT_TYPE_ITEM, nullptr, guidLo, guidHi, 0));
|
||||
Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, nullptr, 0));
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
|
||||
|
||||
+2
-2
@@ -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<const uint64_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_PARTY_MEMBER_GUIDS));
|
||||
static_cast<uintptr_t>(Offsets::VAR_PARTY_GUIDS));
|
||||
return guids[slot];
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TriggerTutorial_t>(Offsets::FUN_TRIGGER_TUTORIAL)(id, arg);
|
||||
if (Game::Read<int>(static_cast<uintptr_t>(Offsets::VAR_TAXI_MAP_NODE_COUNT)) <= 1)
|
||||
if (Game::Read<int>(static_cast<uintptr_t>(Offsets::VAR_TAXI_NODE_COUNT)) <= 1)
|
||||
return;
|
||||
const void *player = Unit::Identity::PlayerObject();
|
||||
if (player == nullptr)
|
||||
|
||||
@@ -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<const uint32_t *>(Offsets::VAR_SPELL_PLACEMENT_STATE);
|
||||
return *reinterpret_cast<const uint32_t *>(Offsets::VAR_SPELL_TARGETING_FLAGS);
|
||||
}
|
||||
|
||||
bool InWorld() {
|
||||
@@ -117,7 +117,7 @@ bool CommitAtCursor() {
|
||||
return false;
|
||||
|
||||
void *clickInfo = *reinterpret_cast<void *const *>(
|
||||
Offsets::VAR_WORLDFRAME_CLICK_INFO);
|
||||
Offsets::VAR_GAME_STATE_PTR);
|
||||
if (clickInfo == nullptr)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -58,7 +58,7 @@ int __fastcall Script_GetSpellSchool(void *L) {
|
||||
if (rec == nullptr)
|
||||
return 0;
|
||||
const uint32_t school0 = *reinterpret_cast<const uint32_t *>(
|
||||
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<double>(school0 + 1));
|
||||
|
||||
@@ -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<int>(ownerFrame, Offsets::OFF_COBJECT_LUA_REF);
|
||||
auto rawgeti = reinterpret_cast<LuaRawGetI_t>(
|
||||
Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT);
|
||||
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
|
||||
Game::Lua::RawGetI(L, Game::Lua::REGISTRY_INDEX, refKey);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<LuaRawGetI_t>(
|
||||
Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT);
|
||||
auto scriptRegister = reinterpret_cast<ScriptRegister_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER));
|
||||
|
||||
@@ -66,7 +63,7 @@ void Push(void *L, void *frame) {
|
||||
refKey = Game::Read<int>(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<int>(cobj, Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0;
|
||||
scriptRegister(frame, nullptr, nullptr);
|
||||
refKey = Game::Read<int>(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
|
||||
|
||||
+3
-3
@@ -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<PetMinionClass_t>(
|
||||
Offsets::FUN_UNIT_PET_MINION_CLASS);
|
||||
Offsets::FUN_UNIT_CREATURE_TYPE);
|
||||
pet = (classify(unit) == 1);
|
||||
}
|
||||
Game::Lua::PushBool(L, pet);
|
||||
|
||||
Reference in New Issue
Block a user