From 0df8885045da15ddcbcabc77572313cfca66261b Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 8 Aug 2026 15:12:55 -0500 Subject: [PATCH] refactor(offsets): collapse duplicate object type-mask enum (OBJ_TYPE_* -> TYPEMASK_*) OBJ_TYPE_* was a partial second naming of the same object-type bits as the complete TYPEMASK_* set (OBJ_TYPE_ITEM=2=TYPEMASK_ITEM, ... GAMEOBJECT =0x20 both) -- a single-source-of-truth violation. Repoint all ~18 references to TYPEMASK_* (identical values, behavior-preserving) and delete the OBJ_TYPE_* definitions, folding their derivation notes (bitmask semantics, FUN_004F8DB0 for PLAYER, FUN_0052AA20 for GAMEOBJECT, FUN_00529FE0 SetUnit) into the surviving TYPEMASK_* comment. --- src/Offsets.h | 21 +++++++++------------ src/equipmentset/Locations.cpp | 2 +- src/gameobject/Tooltip.cpp | 2 +- src/item/AverageLevel.cpp | 4 ++-- src/item/Count.cpp | 4 ++-- src/item/Location.cpp | 4 ++-- src/item/Location.h | 2 +- src/item/NewItems.cpp | 2 +- src/item/Tooltip.cpp | 2 +- src/nameplate/Info.cpp | 2 +- src/object/Resolve.h | 2 +- src/player/Equipment.cpp | 2 +- src/player/LocationInfo.cpp | 2 +- src/unit/Focus.cpp | 2 +- src/unit/Identity.cpp | 2 +- src/unit/RaidTarget.cpp | 2 +- src/unit/TokenExtensions.cpp | 2 +- src/unit/Tooltip.cpp | 2 +- 18 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/Offsets.h b/src/Offsets.h index 1d7c6b05..ccbdc9a8 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -198,7 +198,7 @@ enum Offsets { // Returns an int the caller (Script_GameTooltip_SetUnit) tests, so the // co-hook must forward the original's return value. // - GameObject (0x0052aa20, __thiscall(self, guid*), RET 4) — the GO - // hover populator; resolves the GO (OBJ_TYPE_GAMEOBJECT) and writes the + // hover populator; resolves the GO (TYPEMASK_GAMEOBJECT) and writes the // GO field at +0x370. FUN_GAMETOOLTIP_BUILD_UNIT = 0x00529FE0, FUN_GAMETOOLTIP_BUILD_GAMEOBJECT = 0x0052AA20, @@ -1895,7 +1895,7 @@ enum Offsets { // gated on the bank-open globals). Returns the CGContainer GUID of the bag // equipped in that slot, or 0 if none. This is the internal PackBagSlot // uses to resolve bags 1..4: get the bag GUID here, resolve the container - // via FUN_OBJECT_RESOLVE_BY_GUID(OBJ_TYPE_CONTAINER, guid), then call the + // via FUN_OBJECT_RESOLVE_BY_GUID(TYPEMASK_CONTAINER, guid), then call the // container's vtable[+OFF_CONTAINER_GET_INVENTORY] to get the inventory // object GetItemBySlot indexes. Lets us enumerate bag contents in pure C++ // without PackBagSlot's Lua-stack coupling. (Reads GUID arrays at @@ -1957,14 +1957,8 @@ enum Offsets { // guidLo/guidHi). All our callers go through `Object::ByGuid` // (object/Resolve.h), which wraps this single address. FUN_OBJECT_RESOLVE_BY_GUID = 0x00468460, - // The type arg is a bitmask of object-type bits, not an enum - // index — `1<<1` for items, `1<<2` for containers, `1<<3` for - // units, matching what `FUN_00529FE0` passes for SetUnit (`ECX=8`). - OBJ_TYPE_ITEM = 2, - OBJ_TYPE_CONTAINER = 4, - OBJ_TYPE_UNIT = 8, - OBJ_TYPE_PLAYER = 0x10, // what the engine's bag observer FUN_004F8DB0 passes - OBJ_TYPE_GAMEOBJECT = 0x20, // 1<<5; passed by FUN_0052AA20 (hover-tooltip populator). + // The type arg is a bitmask of object-type bits (see the TYPEMASK_* + // block below), not an enum index. // `CGObject::GetName` — returns the display-name `const char *` for // a resolved CGObject (CGUnit / CGPlayer / CGCreature). Internally @@ -2850,8 +2844,11 @@ enum Offsets { // each callback invocation, guidLo/guidHi pushed as 8 stack bytes. FUN_CLNT_OBJ_MGR_ENUM_VISIBLE_OBJECTS = 0x00468380, - // Type-mask flags accepted by FUN_OBJECT_RESOLVE_BY_GUID. Single-bit - // flags can be OR'd together. + // Type-mask flags accepted by FUN_OBJECT_RESOLVE_BY_GUID (and the SetUnit + // path FUN_00529FE0, which passes ECX=8 for UNIT). A bitmask of + // object-type bits, not an enum index — single-bit flags OR together. + // PLAYER (0x10) is what the bag observer FUN_004F8DB0 passes; GAMEOBJECT + // (0x20) what the hover-tooltip populator FUN_0052AA20 passes. TYPEMASK_OBJECT = 0x01, TYPEMASK_ITEM = 0x02, TYPEMASK_CONTAINER = 0x04, diff --git a/src/equipmentset/Locations.cpp b/src/equipmentset/Locations.cpp index eaf79a27..8bade53e 100644 --- a/src/equipmentset/Locations.cpp +++ b/src/equipmentset/Locations.cpp @@ -68,7 +68,7 @@ uint8_t *ResolveByGUID(int type, uint64_t guid) { // bank bags (linear 63..68) — the only differences are the source of // the bag's GUID and how the result encodes back into a location. int WalkBagContents(uint64_t bagGuid, uint64_t targetGuid) { - auto *bag = ResolveByGUID(Offsets::OBJ_TYPE_CONTAINER, bagGuid); + auto *bag = ResolveByGUID(Offsets::TYPEMASK_CONTAINER, bagGuid); if (bag == nullptr) return 0; auto *bagInvMgr = diff --git a/src/gameobject/Tooltip.cpp b/src/gameobject/Tooltip.cpp index 10108460..7ec7ec5c 100644 --- a/src/gameobject/Tooltip.cpp +++ b/src/gameobject/Tooltip.cpp @@ -70,7 +70,7 @@ static int __fastcall Script_GameTooltipGetGameObject(void *L) { if (guidLo == 0 && guidHi == 0) return 0; - void *obj = Object::ByGuid(Offsets::OBJ_TYPE_GAMEOBJECT, + void *obj = Object::ByGuid(Offsets::TYPEMASK_GAMEOBJECT, (static_cast(guidHi) << 32) | guidLo, "GameTooltip:GetGameObject", 0x172); if (obj == nullptr) diff --git a/src/item/AverageLevel.cpp b/src/item/AverageLevel.cpp index adfd3faa..cb25519c 100644 --- a/src/item/AverageLevel.cpp +++ b/src/item/AverageLevel.cpp @@ -199,7 +199,7 @@ void WalkGuidArrayRange(const uint8_t *invMgr, int firstSlot, int lastSlot, if (guidArray == nullptr) return; for (int slot = firstSlot; slot <= lastSlot; ++slot) { - const uint8_t *item = ResolveByGuid(Offsets::OBJ_TYPE_ITEM, guidArray[slot]); + const uint8_t *item = ResolveByGuid(Offsets::TYPEMASK_ITEM, guidArray[slot]); if (item == nullptr) continue; CollectBagOrBankItem(item, candidates); @@ -219,7 +219,7 @@ void WalkBankBags(std::vector &candidates) { return; for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT; slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; ++slot) { - const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER, + const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER, playerGuidArray[slot]); if (bag == nullptr) continue; diff --git a/src/item/Count.cpp b/src/item/Count.cpp index b1faef03..293e826c 100644 --- a/src/item/Count.cpp +++ b/src/item/Count.cpp @@ -119,7 +119,7 @@ int CountInGuidArray(const uint8_t *invMgr, int firstSlot, int lastSlot, return 0; int total = 0; for (int slot = firstSlot; slot <= lastSlot; slot++) { - const uint8_t *item = ResolveByGuid(Offsets::OBJ_TYPE_ITEM, guidArray[slot]); + const uint8_t *item = ResolveByGuid(Offsets::TYPEMASK_ITEM, guidArray[slot]); if (item == nullptr) continue; if (Item::ID::FromCGItem(item) != targetItemID) @@ -148,7 +148,7 @@ int CountInBankBags(int targetItemID, bool includeUses) { int total = 0; for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT; slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; slot++) { - const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER, + const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER, playerGuidArray[slot]); if (bag == nullptr) continue; diff --git a/src/item/Location.cpp b/src/item/Location.cpp index c629dc3e..d2e19a25 100644 --- a/src/item/Location.cpp +++ b/src/item/Location.cpp @@ -107,7 +107,7 @@ void *EquippedBagInventory(int bagID) { if (bagGuid == 0) return nullptr; // no bag equipped in that slot auto *container = static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_CONTAINER, bagGuid, "ItemMgr", 0x172)); + Object::ByGuid(Offsets::TYPEMASK_CONTAINER, bagGuid, "ItemMgr", 0x172)); return ContainerInventory(container); } @@ -168,7 +168,7 @@ const uint8_t *ResolveByGUID(uint64_t guid) { if (guid == 0) return nullptr; return static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_ITEM, guid, "ItemMgr", 0x172)); + Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, "ItemMgr", 0x172)); } bool FindByItemID(void *L, int itemID, ByGUIDResult *out) { diff --git a/src/item/Location.h b/src/item/Location.h index cfcb5c9b..a46423d5 100644 --- a/src/item/Location.h +++ b/src/item/Location.h @@ -70,7 +70,7 @@ const uint8_t *ResolveEquipmentSlot(int slot1Based); int GetBagSlotCount(int bagID); // Given a `CGContainer*` (an equipped bag or bank bag, resolved by GUID via -// `FUN_OBJECT_RESOLVE_BY_GUID` with `OBJ_TYPE_CONTAINER`), returns its own +// `FUN_OBJECT_RESOLVE_BY_GUID` with `TYPEMASK_CONTAINER`), returns its own // inventory-manager object via the container's vtable method at // `+OFF_CONTAINER_GET_INVENTORY`. The returned object has the same layout as // the player inventory manager: slot count at `+0x00`, flat GUID array at diff --git a/src/item/NewItems.cpp b/src/item/NewItems.cpp index 740c9f27..9a1ac1bd 100644 --- a/src/item/NewItems.cpp +++ b/src/item/NewItems.cpp @@ -304,7 +304,7 @@ void AppendNonBagOwned(uint64_t *out, int *count) { return; for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT; slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; ++slot) { - const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER, playerArr[slot]); + const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER, playerArr[slot]); if (bag == nullptr) continue; auto *bagInvMgr = diff --git a/src/item/Tooltip.cpp b/src/item/Tooltip.cpp index 02d27857..b16903c7 100644 --- a/src/item/Tooltip.cpp +++ b/src/item/Tooltip.cpp @@ -158,7 +158,7 @@ static const uint8_t *PeekItemRecord(uint32_t itemID) { static void *ResolveItemByGuid(uint32_t guidLo, uint32_t guidHi) { if (guidLo == 0 && guidHi == 0) return nullptr; - return Object::ByGuid(Offsets::OBJ_TYPE_ITEM, + return Object::ByGuid(Offsets::TYPEMASK_ITEM, (static_cast(guidHi) << 32) | guidLo, "GameTooltip:GetItem", 0x172); } diff --git a/src/nameplate/Info.cpp b/src/nameplate/Info.cpp index b8ee406b..d779fe0d 100644 --- a/src/nameplate/Info.cpp +++ b/src/nameplate/Info.cpp @@ -129,7 +129,7 @@ static void PushNamePlateForGUID(void *L, uint64_t guid) { return; } auto *unit = static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_UNIT, guid, "NamePlate", 0x172)); + Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "NamePlate", 0x172)); if (unit == nullptr) { Game::Lua::PushNil(L); return; diff --git a/src/object/Resolve.h b/src/object/Resolve.h index c985032e..d717456a 100644 --- a/src/object/Resolve.h +++ b/src/object/Resolve.h @@ -23,7 +23,7 @@ namespace Object { // Resolve `guid` to its live client object. `typeMask` is a bitmask of -// `Offsets::OBJ_TYPE_*` (e.g. `OBJ_TYPE_UNIT | OBJ_TYPE_PLAYER`, or +// `Offsets::TYPEMASK_*` (e.g. `TYPEMASK_UNIT | TYPEMASK_PLAYER`, or // `TYPEMASK_UNIT` / `TYPEMASK_OBJECT`). Returns nullptr when the GUID isn't // currently in the object table (out of range, despawned, pre-world). // Non-throwing — safe from any context (Lua callback, world tick, packet diff --git a/src/player/Equipment.cpp b/src/player/Equipment.cpp index 9dce0613..89bcddf8 100644 --- a/src/player/Equipment.cpp +++ b/src/player/Equipment.cpp @@ -82,7 +82,7 @@ const Event::Custom::AutoReserve _r2{kEvtDurability}; // error thrown from there unwinds through raw engine code. bool SlotHasItem(uint32_t guidLo, uint32_t guidHi, int slot0Based) { auto *player = static_cast(Object::ByGuid( - Offsets::OBJ_TYPE_PLAYER, + Offsets::TYPEMASK_PLAYER, (static_cast(guidHi) << 32) | guidLo, "ClassicAPI", 0x172)); if (player == nullptr) return false; diff --git a/src/player/LocationInfo.cpp b/src/player/LocationInfo.cpp index 15d38668..b3083118 100644 --- a/src/player/LocationInfo.cpp +++ b/src/player/LocationInfo.cpp @@ -105,7 +105,7 @@ bool LocationGuid(void *L, int locIdx, uint64_t *out) { // Resolves a GUID to its currently-synced CGUnit, or null if not resident. const uint8_t *ResolveUnit(uint64_t guid) { return static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_UNIT, guid, "ClassicAPI", 0)); + Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "ClassicAPI", 0)); } // Reads a UNIT_FIELD_BYTES_0 byte: the login-time mirror global when `guid` is diff --git a/src/unit/Focus.cpp b/src/unit/Focus.cpp index 10e42195..77f2e0ad 100644 --- a/src/unit/Focus.cpp +++ b/src/unit/Focus.cpp @@ -125,7 +125,7 @@ const uint8_t *ResolveObject(uint64_t guid) { if (guid == 0) return nullptr; return static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_UNIT, guid, "Focus", 0x172)); + Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "Focus", 0x172)); } // True if `guid` is a current party or raid member. Reads the roster GUID diff --git a/src/unit/Identity.cpp b/src/unit/Identity.cpp index fc7c745b..79fa2cca 100644 --- a/src/unit/Identity.cpp +++ b/src/unit/Identity.cpp @@ -109,7 +109,7 @@ const uint8_t *PlayerObject() { if (guid == 0) return nullptr; return static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_PLAYER, guid, "ClassicAPI", 0)); + Object::ByGuid(Offsets::TYPEMASK_PLAYER, guid, "ClassicAPI", 0)); } const uint8_t *PlayerInventoryManager() { diff --git a/src/unit/RaidTarget.cpp b/src/unit/RaidTarget.cpp index ec77d55a..90ec6bda 100644 --- a/src/unit/RaidTarget.cpp +++ b/src/unit/RaidTarget.cpp @@ -79,7 +79,7 @@ const uint8_t *ResolveObject(uint64_t guid) { if (guid == 0) return nullptr; return static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_UNIT, guid, "RaidTarget", 0x172)); + Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "RaidTarget", 0x172)); } // Descriptor-field observer callback for marker slot `Idx` (0-based). diff --git a/src/unit/TokenExtensions.cpp b/src/unit/TokenExtensions.cpp index 265e6787..1bb9fa98 100644 --- a/src/unit/TokenExtensions.cpp +++ b/src/unit/TokenExtensions.cpp @@ -122,7 +122,7 @@ uint64_t WalkSuffix(uint64_t guid, const char *suffix) { return 0; // unknown suffix component — modern returns nil suffix += kSuffixTargetLen; auto *obj = static_cast( - Object::ByGuid(Offsets::OBJ_TYPE_UNIT, guid, "ClassicAPI", + Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "ClassicAPI", kResolvePriority)); if (obj == nullptr) return 0; diff --git a/src/unit/Tooltip.cpp b/src/unit/Tooltip.cpp index 93648009..5320aa23 100644 --- a/src/unit/Tooltip.cpp +++ b/src/unit/Tooltip.cpp @@ -81,7 +81,7 @@ static int __fastcall Script_GameTooltipSetUnitAura(void *L) { using ObjectGetName_t = const char *(__fastcall *)(void *obj, void *edx_unused, int *outFlags); static const char *ResolveUnitName(uint32_t guidLo, uint32_t guidHi) { - void *obj = Object::ByGuid(Offsets::OBJ_TYPE_UNIT, + void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, (static_cast(guidHi) << 32) | guidLo, "GameTooltip:GetUnitGUID", 0x172); if (obj == nullptr)