From c54556f6a18cea4daf99aeb4e0fc045685cd5959 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Wed, 19 Aug 2026 11:01:19 -0500 Subject: [PATCH] refactor: centralize engine field/global access via Game::Read/Ref/Ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the raw `*reinterpret_cast(base + Offsets::OFF_X)` idiom (and its double-cast variant when base wasn't already a byte pointer) with three typed accessors in Game.h: Game::Read(base, offset) field value read Game::Ref(base, offset) writable field lvalue Game::Ptr(base, offset) pointer to a field (arrays / out-params) Game::Read(address) / Ref(address) fixed-VA globals Pure mechanical refactor, zero behavior change: ~330 cast sites across 84 files collapse to 651 helper calls. Offsets stay in Offsets.h per the single-source-of-truth rule — the helpers only remove the cast noise and fold away the inner `reinterpret_cast(obj)` base casts. Left as raw casts by design: FUN_* function-pointer casts, void*/char* VA handles passed as arguments (caches, method registries), subobject- anchor pointers fed to __thiscall helpers, `void *volatile` player-ptr readiness gates (converting would strip volatile), and VA-as-array-base captures that are subscripted later. --- src/Game.cpp | 2 +- src/Game.h | 40 +++++++++++ src/auctionhouse/PostItem.cpp | 16 ++--- src/bindings/Api.cpp | 4 +- src/container/ItemInfo.cpp | 38 +++++------ src/creature/Info.cpp | 44 ++++++------ src/equipmentset/Storage.cpp | 7 +- src/equipmentset/Tooltip.cpp | 4 +- src/event/Custom.cpp | 58 ++++++++-------- src/event/Registered.cpp | 16 ++--- src/fontstring/Metrics.cpp | 4 +- src/frame/Attributes.cpp | 16 ++--- src/frame/Modern.cpp | 28 +++----- src/frame/MouseFoci.cpp | 18 ++--- src/frame/ScriptArgs.cpp | 11 ++- src/friendlist/Notes.cpp | 7 +- src/friendlist/WhoInfo.cpp | 17 +++-- src/gameobject/Info.cpp | 6 +- src/gameobject/Tooltip.cpp | 16 ++--- src/group/MemberStats.cpp | 19 +++--- src/item/AverageLevel.cpp | 12 ++-- src/item/Cursor.cpp | 6 +- src/item/Data.cpp | 10 +-- src/item/EnchantInfo.cpp | 10 +-- src/item/GetData.cpp | 82 +++++++++++----------- src/item/Info.cpp | 34 +++++----- src/item/Lock.cpp | 8 +-- src/item/StatAccum.cpp | 54 +++++++-------- src/item/Swap.cpp | 8 +-- src/item/Tooltip.cpp | 12 ++-- src/item/TooltipItem.cpp | 11 +-- src/item/scrape/InboxID.cpp | 8 +-- src/item/scrape/LootSlotID.cpp | 6 +- src/item/scrape/MerchantID.cpp | 10 +-- src/loot/History.cpp | 6 +- src/loot/Nearby.cpp | 13 ++-- src/loot/Scan.cpp | 19 ++---- src/loot/UnitItem.cpp | 4 +- src/lossofcontrol/Info.cpp | 8 +-- src/map/Area.cpp | 52 ++++++-------- src/map/AreaTriggers.cpp | 7 +- src/map/Areas.cpp | 10 ++- src/map/Overlays.cpp | 27 ++++---- src/map/WorldSize.cpp | 8 +-- src/model/DisplayInfo.cpp | 44 ++++++------ src/player/CanUseItem.cpp | 74 ++++++++++---------- src/player/InputEvents.cpp | 19 +++--- src/quest/Details.cpp | 2 +- src/spell/BonusDamage.cpp | 54 +++++++-------- src/spell/Cast.cpp | 45 ++++++------- src/spell/CastByID.cpp | 4 +- src/spell/CastEvents.cpp | 10 +-- src/spell/CastNoToggle.cpp | 6 +- src/spell/Info.cpp | 48 ++++++------- src/spell/Level.cpp | 68 +++++++++---------- src/spell/Mechanic.cpp | 4 +- src/spell/Mod.cpp | 16 ++--- src/spell/PowerCost.cpp | 4 +- src/spell/Radius.cpp | 6 +- src/spell/Range.cpp | 3 +- src/spell/SkillLine.cpp | 42 ++++++------ src/spell/Tooltip.cpp | 36 +++++----- src/spell/Usable.cpp | 34 +++++----- src/talent/Info.cpp | 64 +++++++++--------- src/talent/Tooltip.cpp | 17 +++-- src/taxi/Map.cpp | 28 ++++---- src/taxi/Paths.cpp | 4 +- src/text/InlineTexture.cpp | 120 ++++++++++++--------------------- src/text/InlineTexturePool.cpp | 14 ++-- src/texture/Transform.cpp | 33 ++++----- src/time/Server.cpp | 10 +-- src/tooltip/CompareItem.cpp | 39 +++++------ src/tooltip/LinePool.cpp | 23 +++---- src/tooltip/Owner.cpp | 7 +- src/totem/Tracker.cpp | 48 +++++++------ src/tradeskill/Link.cpp | 86 ++++++++++++----------- src/ui/FrameObject.cpp | 11 ++- src/unit/ClassBase.cpp | 10 +-- src/unit/Flags.cpp | 53 +++++++-------- src/unit/Identity.cpp | 27 +++----- src/unit/LineOfSight.cpp | 7 +- src/unit/RaceBase.cpp | 10 +-- src/unit/Tooltip.cpp | 16 ++--- src/xml/Templates.cpp | 37 +++++----- 84 files changed, 947 insertions(+), 1032 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 07c55fe9..211fe904 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -73,7 +73,7 @@ using RegisterFrameMethods_t = void(__fastcall *)(const FrameMethodEntry *table, } // namespace void *State() { - return *reinterpret_cast(static_cast(Offsets::VAR_LUA_STATE)); + return Game::Read(Offsets::VAR_LUA_STATE); } namespace { diff --git a/src/Game.h b/src/Game.h index 5288e843..59d0413a 100644 --- a/src/Game.h +++ b/src/Game.h @@ -17,6 +17,46 @@ namespace Game { +// --- Typed engine-memory access --------------------------------------------- +// +// The canonical way to read/write an engine object field or a fixed-VA global, +// replacing the `*reinterpret_cast(base + Offsets::OFF_X)` idiom +// (and its double-cast variant when `base` isn't a byte pointer). Offsets stay +// in Offsets.h per the single-source-of-truth rule — these only centralize the +// cast noise, they add no checking. +// +// Game::Read(obj, Offsets::OFF_FIELD) field read +// Game::Ref(obj, Offsets::OFF_FIELD) writable field lvalue +// Game::Ptr(obj, Offsets::OFF_FIELD) pointer TO a field (arrays, +// out-params for engine calls) +// Game::Read(Offsets::VAR_GLOBAL) fixed-VA global read +// Game::Ref(Offsets::VAR_GLOBAL) fixed-VA global lvalue + +template +inline const T *Ptr(const void *base, uintptr_t offset) { + return reinterpret_cast(reinterpret_cast(base) + offset); +} +template +inline T *Ptr(void *base, uintptr_t offset) { + return reinterpret_cast(reinterpret_cast(base) + offset); +} +template +inline T Read(const void *base, uintptr_t offset) { + return *Ptr(base, offset); +} +template +inline T &Ref(void *base, uintptr_t offset) { + return *Ptr(base, offset); +} +template +inline T Read(uintptr_t address) { + return *reinterpret_cast(address); +} +template +inline T &Ref(uintptr_t address) { + return *reinterpret_cast(address); +} + using FrameScript_Initialize_t = bool(__fastcall *)(); using LoadScriptFunctions_t = void(__fastcall *)(); diff --git a/src/auctionhouse/PostItem.cpp b/src/auctionhouse/PostItem.cpp index ef4b360e..844b769f 100644 --- a/src/auctionhouse/PostItem.cpp +++ b/src/auctionhouse/PostItem.cpp @@ -103,14 +103,14 @@ int CGItemCount(const uint8_t *item) { auto *desc = Item::ObjectFields(item); if (desc == nullptr) return 0; - return *reinterpret_cast(desc + Offsets::OFF_DESCRIPTOR_STACK_COUNT); + return Game::Read(desc, Offsets::OFF_DESCRIPTOR_STACK_COUNT); } uint64_t CGItemGuid(const uint8_t *item) { auto *inst = Item::InstanceBlock(item); if (inst == nullptr) return 0; - return *reinterpret_cast(inst + Offsets::OFF_INSTANCE_BLOCK_GUID); + return Game::Read(inst, Offsets::OFF_INSTANCE_BLOCK_GUID); } struct SlotInfo { @@ -135,18 +135,18 @@ SlotInfo ReadSlot(void *L, int bag, int slot) { // --- auction-house globals ---------------------------------------------- uint64_t AuctioneerGuid() { - const uint32_t lo = *reinterpret_cast( + const uint32_t lo = Game::Read( Offsets::VAR_AUCTION_AUCTIONEER_GUID_LO); - const uint32_t hi = *reinterpret_cast( + const uint32_t hi = Game::Read( Offsets::VAR_AUCTION_AUCTIONEER_GUID_HI); return (static_cast(hi) << 32) | lo; } bool AHOpen() { return AuctioneerGuid() != 0; } void SetSellGuid(uint64_t guid) { - *reinterpret_cast(Offsets::VAR_AUCTION_SELL_GUID_LO) = + Game::Ref(Offsets::VAR_AUCTION_SELL_GUID_LO) = static_cast(guid); - *reinterpret_cast(Offsets::VAR_AUCTION_SELL_GUID_HI) = + Game::Ref(Offsets::VAR_AUCTION_SELL_GUID_HI) = static_cast(guid >> 32); } @@ -181,8 +181,8 @@ bool BagIsGeneral(int bag) { const uint8_t *rec = Item::PeekRecord(static_cast(id)); if (rec == nullptr) return false; - return *reinterpret_cast( - rec + Offsets::OFF_ITEMSTATS_BAG_FAMILY) == 0; + return Game::Read( + rec, Offsets::OFF_ITEMSTATS_BAG_FAMILY) == 0; } bool FindFreeGeneralSlot(void *L, int *outBag, int *outSlot) { diff --git a/src/bindings/Api.cpp b/src/bindings/Api.cpp index fd096748..df862ec4 100644 --- a/src/bindings/Api.cpp +++ b/src/bindings/Api.cpp @@ -352,8 +352,8 @@ int DispatchOverrideCommand(void *mgr, const char *cmd, int isDown) { reinterpret_cast(Offsets::VAR_FRAMESCRIPT_EXEC_CONTEXT); volatile uint32_t *depth = reinterpret_cast( Offsets::VAR_FRAMESCRIPT_EXEC_CONTEXT_DEPTH); - volatile uint32_t *executing = reinterpret_cast( - reinterpret_cast(mgr) + Offsets::OFF_BINDING_MANAGER_EXECUTING); + volatile uint32_t *executing = + Game::Ptr(mgr, Offsets::OFF_BINDING_MANAGER_EXECUTING); const uint32_t savedContext = *context; *depth = *depth + 1; diff --git a/src/container/ItemInfo.cpp b/src/container/ItemInfo.cpp index 4e028565..586efe5f 100644 --- a/src/container/ItemInfo.cpp +++ b/src/container/ItemInfo.cpp @@ -80,12 +80,12 @@ bool BuildIconPath(uint32_t displayInfoID, char *out, size_t outSize) { // readable-text id is non-zero (letters / server-authored notes). bool ItemReadable(const uint8_t *item, const uint8_t *record) { if (record != nullptr && - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_PAGE_TEXT) != 0) + Game::Read(record, Offsets::OFF_ITEMSTATS_PAGE_TEXT) != 0) return true; const uint8_t *descriptor = Item::ObjectFields(item); return descriptor != nullptr && - *reinterpret_cast( - descriptor + Offsets::OFF_DESCRIPTOR_READABLE_TEXT_ID) != 0; + Game::Read( + descriptor, Offsets::OFF_DESCRIPTOR_READABLE_TEXT_ID) != 0; } int __fastcall Script_C_Container_GetContainerItemInfo(void *L) { @@ -116,14 +116,14 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) { int stackCount = 0; bool isBound = false; if (descriptor != nullptr) { - stackCount = *reinterpret_cast( - descriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT); - isBound = (*reinterpret_cast( - descriptor + Offsets::OFF_DESCRIPTOR_FLAGS) & + stackCount = Game::Read( + descriptor, Offsets::OFF_DESCRIPTOR_STACK_COUNT); + isBound = (Game::Read( + descriptor, Offsets::OFF_DESCRIPTOR_FLAGS) & Offsets::ITEM_FLAG_SOULBOUND) != 0; } - const bool isLocked = (*reinterpret_cast( - item + Offsets::OFF_ITEM_CLIENT_LOCK) & + const bool isLocked = (Game::Read( + item, Offsets::OFF_ITEM_CLIENT_LOCK) & Offsets::ITEM_CLIENT_LOCK_BIT) != 0; const bool isReadable = ItemReadable(item, record); @@ -135,17 +135,17 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) { bool hasLoot = false; bool hasNoValue = false; if (record != nullptr) { - const uint32_t displayInfoID = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); + const uint32_t displayInfoID = Game::Read( + record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); haveIcon = BuildIconPath(displayInfoID, iconPath, sizeof(iconPath)); - quality = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_QUALITY); + quality = Game::Read( + record, Offsets::OFF_ITEMSTATS_QUALITY); haveQuality = true; - const uint32_t flags = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_FLAGS); + const uint32_t flags = Game::Read( + record, Offsets::OFF_ITEMSTATS_FLAGS); hasLoot = (flags & Offsets::ITEM_FLAG_LOOTABLE) != 0; - hasNoValue = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SELL_PRICE) == 0; + hasNoValue = Game::Read( + record, Offsets::OFF_ITEMSTATS_SELL_PRICE) == 0; } const char *hyperlink = Item::Link::FromCGItem(item); @@ -155,8 +155,8 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) { if (Item::Link::NameFromCGItem(item, nameBuf, sizeof(nameBuf))) { itemName = nameBuf; } else if (record != nullptr) { - const char *baseName = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_NAME); + const char *baseName = Game::Read( + record, Offsets::OFF_ITEMSTATS_NAME); if (baseName != nullptr && baseName[0] != '\0') itemName = baseName; } diff --git a/src/creature/Info.cpp b/src/creature/Info.cpp index d5caa84e..81d4f2d8 100644 --- a/src/creature/Info.cpp +++ b/src/creature/Info.cpp @@ -95,14 +95,14 @@ int __fastcall Script_GetCreatureInfoByID(void *L) { if (rec == nullptr) return 0; // not cached -> nil - const char *name = *reinterpret_cast(rec + Offsets::OFF_CREATURE_NAME); + const char *name = Game::Read(rec, Offsets::OFF_CREATURE_NAME); const char *subName = - *reinterpret_cast(rec + Offsets::OFF_CREATURE_SUBNAME); - const uint32_t type = *reinterpret_cast(rec + Offsets::OFF_CREATURE_TYPE); - const uint32_t family = *reinterpret_cast(rec + Offsets::OFF_CREATURE_FAMILY); - const uint32_t rank = *reinterpret_cast(rec + Offsets::OFF_CREATURE_RANK); + Game::Read(rec, Offsets::OFF_CREATURE_SUBNAME); + const uint32_t type = Game::Read(rec, Offsets::OFF_CREATURE_TYPE); + const uint32_t family = Game::Read(rec, Offsets::OFF_CREATURE_FAMILY); + const uint32_t rank = Game::Read(rec, Offsets::OFF_CREATURE_RANK); const uint32_t displayID = - *reinterpret_cast(rec + Offsets::OFF_CREATURE_DISPLAYID); + Game::Read(rec, Offsets::OFF_CREATURE_DISPLAYID); Game::Lua::NewTable(L); Game::Lua::SetFieldNumber(L, "creatureID", creatureID); @@ -213,7 +213,7 @@ int __fastcall Script_GetCreatureFamilyIDs(void *L) { Game::Lua::NewTable(L); const int count = - *reinterpret_cast(Offsets::VAR_CREATUREFAMILY_COUNT); + Game::Read(Offsets::VAR_CREATUREFAMILY_COUNT); int n = 0; for (int id = 1; id <= count; ++id) { const char *name = DBC::LocalizedField(Offsets::VAR_CREATUREFAMILY_RECORDS, @@ -250,8 +250,8 @@ int __fastcall Script_GetFactionInfo(void *L) { static_cast(raceID)); if (crRec == nullptr) return 0; // unknown race - const int ftId = *reinterpret_cast( - crRec + Offsets::OFF_CHRRACES_FACTION_TEMPLATE); + const int ftId = Game::Read( + crRec, Offsets::OFF_CHRRACES_FACTION_TEMPLATE); if (ftId <= 0) return 0; @@ -260,31 +260,31 @@ int __fastcall Script_GetFactionInfo(void *L) { static_cast(ftId)); if (ftRec == nullptr) return 0; - const uint32_t mask = *reinterpret_cast( - ftRec + Offsets::OFF_FACTIONTEMPLATE_GROUP_MASK); + const uint32_t mask = Game::Read( + ftRec, Offsets::OFF_FACTIONTEMPLATE_GROUP_MASK); // FactionGroup is stored contiguously (records-base + i*stride), not as a // pointer array — iterate by hand rather than via DBC::Record. - auto *fgBase = *reinterpret_cast( + auto *fgBase = Game::Read( Offsets::VAR_FACTIONGROUP_RECORDS); const int fgCount = - *reinterpret_cast(Offsets::VAR_FACTIONGROUP_COUNT); - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); + Game::Read(Offsets::VAR_FACTIONGROUP_COUNT); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); if (fgBase == nullptr) return 0; for (int i = 0; i < fgCount; ++i) { const uint8_t *row = fgBase + i * Offsets::FACTIONGROUP_STRIDE; - const int bit = *reinterpret_cast( - row + Offsets::OFF_FACTIONGROUP_BIT); + const int bit = Game::Read( + row, Offsets::OFF_FACTIONGROUP_BIT); if ((mask & (1u << (bit & 0x1F))) == 0) continue; - const char *loc = *reinterpret_cast( - row + Offsets::OFF_FACTIONGROUP_NAMES + locale * 4); + const char *loc = Game::Read( + row, Offsets::OFF_FACTIONGROUP_NAMES + locale * 4); if (loc == nullptr || *loc == '\0') continue; // "Player" / "Monster" have empty localized names - const char *eng = *reinterpret_cast( - row + Offsets::OFF_FACTIONGROUP_ENGLISH); + const char *eng = Game::Read( + row, Offsets::OFF_FACTIONGROUP_ENGLISH); Game::Lua::NewTable(L); Game::Lua::SetFieldString(L, "name", loc); @@ -324,7 +324,7 @@ int __fastcall Script_GetCreatureTypeIDs(void *L) { Game::Lua::NewTable(L); const int count = - *reinterpret_cast(Offsets::VAR_CREATURETYPE_COUNT); + Game::Read(Offsets::VAR_CREATURETYPE_COUNT); int n = 0; for (int id = 1; id <= count; ++id) { const char *name = DBC::LocalizedField(Offsets::VAR_CREATURETYPE_RECORDS, @@ -376,7 +376,7 @@ uint32_t DisplayID(uint32_t creatureID) { const uint8_t *rec = PeekCreature(creatureID); if (rec == nullptr) return 0; - return *reinterpret_cast(rec + Offsets::OFF_CREATURE_DISPLAYID); + return Game::Read(rec, Offsets::OFF_CREATURE_DISPLAYID); } } // namespace Creature::Info diff --git a/src/equipmentset/Storage.cpp b/src/equipmentset/Storage.cpp index 6dc7d507..ab494ab3 100644 --- a/src/equipmentset/Storage.cpp +++ b/src/equipmentset/Storage.cpp @@ -13,6 +13,7 @@ #include "Storage.h" +#include "Game.h" #include "Offsets.h" #include @@ -25,7 +26,7 @@ namespace EquipmentSet::Storage { namespace { const char *ReadAccountName() { - return *reinterpret_cast(Offsets::VAR_ACCOUNT_NAME_PTR); + return Game::Read(Offsets::VAR_ACCOUNT_NAME_PTR); } const char *ReadCharacterName() { @@ -34,10 +35,10 @@ const char *ReadCharacterName() { } const char *ReadRealmName() { - auto *info = *reinterpret_cast(Offsets::VAR_REALM_INFO_PTR); + auto *info = Game::Read(Offsets::VAR_REALM_INFO_PTR); if (info == nullptr) return nullptr; - return *reinterpret_cast(info + Offsets::OFF_REALM_INFO_NAME); + return Game::Read(info, Offsets::OFF_REALM_INFO_NAME); } // Removes trailing CR/LF/whitespace. Names from the engine are ASCII diff --git a/src/equipmentset/Tooltip.cpp b/src/equipmentset/Tooltip.cpp index b0071021..397a11cc 100644 --- a/src/equipmentset/Tooltip.cpp +++ b/src/equipmentset/Tooltip.cpp @@ -210,8 +210,8 @@ int __fastcall Script_GameTooltipSetEquipmentSet(void *L) { unnamedMissing++; continue; } - const char *name = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_NAME); + const char *name = Game::Read( + record, Offsets::OFF_ITEMSTATS_NAME); if (name == nullptr || name[0] == '\0') { unnamedMissing++; continue; diff --git a/src/event/Custom.cpp b/src/event/Custom.cpp index 6bd51548..293260b4 100644 --- a/src/event/Custom.cpp +++ b/src/event/Custom.cpp @@ -112,13 +112,13 @@ void SMemFree(void *ptr) { int TryClaim(const char *eventName) { if (!g_writesEnabled) return -1; - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); if (base == nullptr || count <= 0) return -1; for (int i = 0; i < count; ++i) { - auto **namePtr = reinterpret_cast( - base + i * Offsets::EVENT_ENTRY_STRIDE + + auto **namePtr = Game::Ptr( + base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_NAME); if (*namePtr == nullptr) { char *copy = SStrDup(eventName); @@ -169,15 +169,15 @@ void Grow() { return; g_growLatched = true; // one attempt per build, whether or not it grows - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); if (base == nullptr || count <= 0 || g_reservedCount <= 0) return; int nulls = 0; for (int i = 0; i < count; ++i) - if (*reinterpret_cast( - base + i * Offsets::EVENT_ENTRY_STRIDE + + if (Game::Read( + base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_NAME) == nullptr) ++nulls; @@ -193,8 +193,8 @@ void Grow() { // moving the buffer would corrupt their subscription). Abort if so and // fall back to claim-NULL. for (int i = 0; i < count; ++i) { - const uint32_t head = *reinterpret_cast( - base + i * Offsets::EVENT_ENTRY_STRIDE + Offsets::OFF_EVENT_ENTRY_HEAD); + const uint32_t head = Game::Read( + base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_HEAD); if (head != 0 && (head & 1) == 0) { // populated chain (not 0 / sentinel) Debug::Log::Printf( "[event] grow aborted — chain live at slot %d (not first-reg)", i); @@ -231,9 +231,9 @@ void Grow() { // Publish base BEFORE count so the globals never advertise more entries // than the buffer holds. Then free the OLD buffer only — the name // strings live on in newBuf and are freed by the reload teardown. - *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR) = newBuf; - *reinterpret_cast(Offsets::VAR_EVENT_TABLE_CAP) = newCount; - *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT) = newCount; + Game::Ref(Offsets::VAR_EVENT_TABLE_BASE_PTR) = newBuf; + Game::Ref(Offsets::VAR_EVENT_TABLE_CAP) = newCount; + Game::Ref(Offsets::VAR_EVENT_TABLE_COUNT) = newCount; SMemFree(base); Debug::Log::Printf("[event] grew table %d -> %d (%d NULL, %d reserved%s)", @@ -268,13 +268,13 @@ int Lookup(const char *name) { int LookupByName(const char *name) { if (name == nullptr) return -1; - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); if (base == nullptr || count <= 0) return -1; for (int i = 0; i < count; ++i) { - const char *entryName = *reinterpret_cast( - base + i * Offsets::EVENT_ENTRY_STRIDE + + const char *entryName = Game::Read( + base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_NAME); if (entryName != nullptr && std::strcmp(entryName, name) == 0) return i; @@ -285,16 +285,16 @@ int LookupByName(const char *name) { bool HasListeners(int slot) { if (slot < 0) return false; - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); if (base == nullptr || slot >= count) return false; // The entry's chain head (`+0x0C`): a populated subscriber chain is a // non-zero pointer with the low bit clear; `0` or an odd (tagged) // value is the empty self-sentinel — same test the grow-safety scan // uses. So this is true iff at least one frame registered for the event. - const uint32_t head = *reinterpret_cast( - base + slot * Offsets::EVENT_ENTRY_STRIDE + Offsets::OFF_EVENT_ENTRY_HEAD); + const uint32_t head = Game::Read( + base + slot * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_HEAD); return head != 0 && (head & 1) == 0; } @@ -330,12 +330,12 @@ int __fastcall Script_DumpSlot(void *L) { return 0; } const int slot = static_cast(Game::Lua::ToNumber(L, 1)); - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); const char *name = nullptr; if (base != nullptr && slot >= 0 && slot < count) { - name = *reinterpret_cast( - base + slot * Offsets::EVENT_ENTRY_STRIDE + + name = Game::Read( + base + slot * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_NAME); } Debug::Log::Printf("[dumpslot] base=0x%08X count=%d slot=%d name='%s'", @@ -345,16 +345,16 @@ int __fastcall Script_DumpSlot(void *L) { } int __fastcall Script_DumpAllEvents(void *) { - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); - const int count = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_COUNT); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); + const int count = Game::Read(Offsets::VAR_EVENT_TABLE_COUNT); Debug::Log::Printf("[dumpall] base=0x%08X count=%d", static_cast(reinterpret_cast(base)), count); if (base == nullptr) return 0; for (int i = 0; i < count; ++i) { - const char *name = *reinterpret_cast( - base + i * Offsets::EVENT_ENTRY_STRIDE + + const char *name = Game::Read( + base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_NAME); if (name != nullptr && *name != '\0') Debug::Log::Printf("[%d] %s", i, name); diff --git a/src/event/Registered.cpp b/src/event/Registered.cpp index 3de8c59c..fd427e18 100644 --- a/src/event/Registered.cpp +++ b/src/event/Registered.cpp @@ -50,22 +50,20 @@ int __fastcall Script_GetFramesRegisteredForEvent(void *L) { if (slot < 0) return 0; - auto *base = *reinterpret_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR); + auto *base = Game::Read(Offsets::VAR_EVENT_TABLE_BASE_PTR); if (base == nullptr) return 0; const uint8_t *entry = base + slot * Offsets::EVENT_ENTRY_STRIDE; - const uintptr_t head = *reinterpret_cast( - entry + Offsets::OFF_EVENT_ENTRY_HEAD); + const uintptr_t head = Game::Read(entry, Offsets::OFF_EVENT_ENTRY_HEAD); // First pass: count subscribers so we can reserve stack up front — an // event with many registered frames would otherwise risk overflowing // the default Lua stack slack as we push. int count = 0; for (uintptr_t node = head; (node & 1) == 0 && node != 0; - node = *reinterpret_cast( - node + Offsets::OFF_EVENT_NODE_NEXT)) { - if (*reinterpret_cast(node + Offsets::OFF_EVENT_NODE_FRAME)) + node = Game::Read(node + Offsets::OFF_EVENT_NODE_NEXT)) { + if (Game::Read(node + Offsets::OFF_EVENT_NODE_FRAME)) ++count; } if (count == 0) @@ -74,10 +72,8 @@ int __fastcall Script_GetFramesRegisteredForEvent(void *L) { int pushed = 0; for (uintptr_t node = head; (node & 1) == 0 && node != 0; - node = *reinterpret_cast( - node + Offsets::OFF_EVENT_NODE_NEXT)) { - void *frame = *reinterpret_cast( - node + Offsets::OFF_EVENT_NODE_FRAME); + node = Game::Read(node + Offsets::OFF_EVENT_NODE_NEXT)) { + void *frame = Game::Read(node + Offsets::OFF_EVENT_NODE_FRAME); if (frame != nullptr) { UI::FrameObject::Push(L, frame); ++pushed; diff --git a/src/fontstring/Metrics.cpp b/src/fontstring/Metrics.cpp index b26db50c..166b9977 100644 --- a/src/fontstring/Metrics.cpp +++ b/src/fontstring/Metrics.cpp @@ -40,8 +40,8 @@ using StringHeightInternal_t = float(__fastcall *)(void *fs); // push chain Script_GetStringWidth uses (the inverse of // Tooltip::LinePool::PixelToInternal). double InternalToPixel(float v) { - const float mul = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_MUL); - const float div = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_DIV); + const float mul = Game::Read(Offsets::VAR_UI_COORD_SCALE_MUL); + const float div = Game::Read(Offsets::VAR_UI_COORD_SCALE_DIV); if (mul == 0.0f) return 0.0; return static_cast(v) * div * Offsets::UI_COORD_SCALE_UNIT / mul; diff --git a/src/frame/Attributes.cpp b/src/frame/Attributes.cpp index 135e881c..7af11aae 100644 --- a/src/frame/Attributes.cpp +++ b/src/frame/Attributes.cpp @@ -315,12 +315,11 @@ std::unordered_map g_unitByFrame; uint64_t g_lastSet = 0; const void *CurrentMouseFocus() { - const void *ctx = *reinterpret_cast( + const void *ctx = Game::Read( static_cast(Offsets::VAR_UI_CONTEXT_PTR)); if (ctx == nullptr) return nullptr; - return *reinterpret_cast( - reinterpret_cast(ctx) + Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS); + return Game::Read(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS); } // The engine's real mouseover setter — `__stdcall(guidLo, guidHi, prevLo, @@ -353,7 +352,7 @@ bool GuidHasLiveUnit(uint64_t guid) { // works for an offline member). The engine's setter (FUN_00492890) gates this // call on a live object, so offline members get nothing — we do it here. void BuildRosterUnitTooltip(uint64_t guid) { - void *tooltip = *reinterpret_cast( + void *tooltip = Game::Read( static_cast(Offsets::VAR_GAMETOOLTIP_OBJECT_PTR)); if (tooltip == nullptr) return; @@ -365,9 +364,8 @@ void BuildRosterUnitTooltip(uint64_t guid) { // no owner and never re-appears (only a subsequent live-unit hover, which // takes the engine's own anchor path, would). Use the self-contained // invoker FUN_FRAME_INVOKE_SCRIPT, safe to call from the WorldTick. - const int anchorHandler = *reinterpret_cast( - reinterpret_cast(tooltip) + - Offsets::OFF_TOOLTIP_SET_DEFAULT_ANCHOR_HANDLER); + const int anchorHandler = Game::Read( + tooltip, Offsets::OFF_TOOLTIP_SET_DEFAULT_ANCHOR_HANDLER); if (anchorHandler != 0) reinterpret_cast( static_cast(Offsets::FUN_FRAME_INVOKE_SCRIPT))(anchorHandler, @@ -598,10 +596,10 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix, const bool swapped = unit != nullptr; if (swapped) { prevTarget = - (static_cast(*reinterpret_cast( + (static_cast(Game::Read( Offsets::VAR_CURRENT_SELECTION_GUID_HI)) << 32) | - *reinterpret_cast( + Game::Read( Offsets::VAR_CURRENT_SELECTION_GUID_LO); Game::Lua::CallGlobalString(L, "TargetUnit", unit); } diff --git a/src/frame/Modern.cpp b/src/frame/Modern.cpp index 86902040..b8dfe9ef 100644 --- a/src/frame/Modern.cpp +++ b/src/frame/Modern.cpp @@ -131,8 +131,7 @@ int __fastcall Script_IsMouseOver(void *L) { Game::Lua::PushBool(L, false); return 1; } - const float effScale = *reinterpret_cast( - reinterpret_cast(obj) + Offsets::OFF_REGION_EFFECTIVE_SCALE); + const float effScale = Game::Read(obj, Offsets::OFF_REGION_EFFECTIVE_SCALE); double left, right, top, bottom; if (effScale == 0.0f || @@ -193,13 +192,10 @@ int __fastcall Script_GetRect(void *L) { // there, so it reports false, as it should. int __fastcall Script_IsDragging(void *L) { void *self = Game::Lua::ResolveObject(L, 1); - void *ctx = *reinterpret_cast( - static_cast(Offsets::VAR_UI_CONTEXT_PTR)); + void *ctx = Game::Read(static_cast(Offsets::VAR_UI_CONTEXT_PTR)); void *dragTarget = ctx != nullptr - ? *reinterpret_cast( - reinterpret_cast(ctx) + - Offsets::OFF_UI_CONTEXT_DRAG_TARGET) + ? Game::Read(ctx, Offsets::OFF_UI_CONTEXT_DRAG_TARGET) : nullptr; Game::Lua::PushBool(L, self != nullptr && self == dragTarget); return 1; @@ -348,9 +344,9 @@ int __fastcall Script_HookScript(void *L) { using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n); bool FrameHasEvent(void *frame, const char *eventName) { - const uint32_t count = *reinterpret_cast( + const uint32_t count = Game::Read( static_cast(Offsets::VAR_EVENT_TABLE_COUNT)); - auto *base = *reinterpret_cast( + auto *base = Game::Read( static_cast(Offsets::VAR_EVENT_TABLE_BASE_PTR)); if (count == 0 || base == nullptr) return false; @@ -360,21 +356,19 @@ bool FrameHasEvent(void *frame, const char *eventName) { for (uint32_t i = 0; i < count; ++i) { const uint8_t *entry = base + i * Offsets::EVENT_ENTRY_STRIDE; - const char *name = *reinterpret_cast( - entry + Offsets::OFF_EVENT_ENTRY_NAME); + const char *name = Game::Read( + entry, Offsets::OFF_EVENT_ENTRY_NAME); if (name == nullptr) continue; if (sstrcmpi(name, eventName, 0x7FFFFFFF) != 0) continue; // Names are unique, so this is the one entry — walk its chain. - uintptr_t node = *reinterpret_cast( - entry + Offsets::OFF_EVENT_ENTRY_HEAD); + uintptr_t node = Game::Read( + entry, Offsets::OFF_EVENT_ENTRY_HEAD); while ((node & 1) == 0 && node != 0) { - if (*reinterpret_cast( - node + Offsets::OFF_EVENT_NODE_FRAME) == frame) + if (Game::Read(node + Offsets::OFF_EVENT_NODE_FRAME) == frame) return true; - node = *reinterpret_cast( - node + Offsets::OFF_EVENT_NODE_NEXT); + node = Game::Read(node + Offsets::OFF_EVENT_NODE_NEXT); } return false; } diff --git a/src/frame/MouseFoci.cpp b/src/frame/MouseFoci.cpp index 5b765497..279b594c 100644 --- a/src/frame/MouseFoci.cpp +++ b/src/frame/MouseFoci.cpp @@ -54,8 +54,7 @@ int CallScript(uintptr_t fn, void *L) { // The UI context is a pointer stored at VAR_UI_CONTEXT_PTR (null pre-world). void *UIContext() { - return *reinterpret_cast( - static_cast(Offsets::VAR_UI_CONTEXT_PTR)); + return Game::Read(static_cast(Offsets::VAR_UI_CONTEXT_PTR)); } // Strata name -> draw rank, low (behind) to high (on top). Unknown -> 0. @@ -110,8 +109,7 @@ Cursor ReadCursor(void *L) { // With `self` at Lua idx 1, is the cursor within the frame's rect? bool CursorOverSelf(void *L, void *obj, const Cursor &cur) { - const float effScale = *reinterpret_cast( - reinterpret_cast(obj) + Offsets::OFF_REGION_EFFECTIVE_SCALE); + const float effScale = Game::Read(obj, Offsets::OFF_REGION_EFFECTIVE_SCALE); if (effScale == 0.0f) return false; // unpositioned region — no rect double left, right, top, bottom; @@ -141,19 +139,16 @@ int __fastcall Script_GetMouseFoci(void *L) { // The engine's authoritative topmost focus — the frame GetMouseFocus // returns. Forced to index 1 below. - void *focus = *reinterpret_cast( - reinterpret_cast(ctx) + Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS); + void *focus = Game::Read(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS); const Cursor cur = ReadCursor(L); std::vector hits; - void *node = *reinterpret_cast( - reinterpret_cast(ctx) + Offsets::OFF_UI_CONTEXT_FRAME_LIST_HEAD); + void *node = Game::Read(ctx, Offsets::OFF_UI_CONTEXT_FRAME_LIST_HEAD); while (node != nullptr && (reinterpret_cast(node) & 1) == 0) { // Read the next link before any Lua work (the walk is engine-list // based, independent of the Lua stack, but this keeps it obvious). - void *next = *reinterpret_cast( - reinterpret_cast(node) + Offsets::OFF_FRAME_ENUM_NEXT); + void *next = Game::Read(node, Offsets::OFF_FRAME_ENUM_NEXT); Game::Lua::SetTop(L, 0); UI::FrameObject::Push(L, node); // (self) @@ -164,8 +159,7 @@ int __fastcall Script_GetMouseFoci(void *L) { Game::Lua::SetTop(L, 1); CallScript(Offsets::FUN_SCRIPT_FRAME_GET_STRATA, L); // (self, strata) const int rank = StrataRank(Game::Lua::ToString(L, 2)); - const int level = *reinterpret_cast( - reinterpret_cast(node) + Offsets::OFF_FRAME_LEVEL); + const int level = Game::Read(node, Offsets::OFF_FRAME_LEVEL); hits.push_back(Hit{node, rank, level}); } diff --git a/src/frame/ScriptArgs.cpp b/src/frame/ScriptArgs.cpp index e247804e..ffb49979 100644 --- a/src/frame/ScriptArgs.cpp +++ b/src/frame/ScriptArgs.cpp @@ -77,11 +77,10 @@ const auto RawGetI = reinterpret_cast(Offsets::LUA_RAWGETI); // Returns the frame's Lua object ref (frame+0x08), lazily creating it exactly // as the engine runner does (`if (refcount == 0) ScriptRegister(frame, 0)`). int EnsureLuaRef(void *frame) { - auto *f = reinterpret_cast(frame); - if (*reinterpret_cast(f + Offsets::OFF_COBJECT_LUA_REFCOUNT) == 0) + if (Game::Read(frame, Offsets::OFF_COBJECT_LUA_REFCOUNT) == 0) reinterpret_cast( Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER)(frame, nullptr); - return *reinterpret_cast(f + Offsets::OFF_COBJECT_LUA_REF); + return Game::Read(frame, Offsets::OFF_COBJECT_LUA_REF); } // Writes "arg" + k (k in 1..19) into buf; buf must hold at least 6 bytes. @@ -193,9 +192,7 @@ bool RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr) // as the first positional to mirror retail's (self, event, arg1..argN). const bool isOnEvent = haveThis && - *reinterpret_cast(reinterpret_cast(frame) + - Offsets::OFF_FRAME_ONEVENT_SLOT) == - handlerRef; + Game::Read(frame, Offsets::OFF_FRAME_ONEVENT_SLOT) == handlerRef; const int selfRef = haveThis ? EnsureLuaRef(frame) : 0; Arg args[kMaxArgs]; @@ -230,7 +227,7 @@ bool RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr) // --- call handler(self, [event,] arg1..argN) --------------------------- const int callBase = GetTop(L); // == base + saved-block size - const int errRef = *reinterpret_cast( + const int errRef = Game::Read( static_cast(Offsets::VAR_FRAMESCRIPT_ERROR_HANDLER_REF)); int errIdx = 0; if (errRef > 0) { diff --git a/src/friendlist/Notes.cpp b/src/friendlist/Notes.cpp index f003b66c..2ba2c3c9 100644 --- a/src/friendlist/Notes.cpp +++ b/src/friendlist/Notes.cpp @@ -18,6 +18,7 @@ #include "Notes.h" +#include "Game.h" #include "Offsets.h" #include @@ -41,14 +42,14 @@ std::string g_path; bool g_loaded = false; const char *ReadAccountName() { - return *reinterpret_cast(Offsets::VAR_ACCOUNT_NAME_PTR); + return Game::Read(Offsets::VAR_ACCOUNT_NAME_PTR); } const char *ReadRealmName() { - auto *info = *reinterpret_cast(Offsets::VAR_REALM_INFO_PTR); + auto *info = Game::Read(Offsets::VAR_REALM_INFO_PTR); if (info == nullptr) return nullptr; - return *reinterpret_cast(info + Offsets::OFF_REALM_INFO_NAME); + return Game::Read(info, Offsets::OFF_REALM_INFO_NAME); } const char *ReadCharacterName() { diff --git a/src/friendlist/WhoInfo.cpp b/src/friendlist/WhoInfo.cpp index b4680a1e..9d096ba5 100644 --- a/src/friendlist/WhoInfo.cpp +++ b/src/friendlist/WhoInfo.cpp @@ -34,8 +34,7 @@ namespace FriendList::WhoInfo { namespace { int WhoResultCount() { - return *reinterpret_cast( - static_cast(Offsets::VAR_WHO_RESULT_COUNT)); + return Game::Read(Offsets::VAR_WHO_RESULT_COUNT); } // `C_FriendList.GetNumWhoResults()` → `numWhos, totalCount`. The first is the @@ -44,7 +43,7 @@ int WhoResultCount() { // global's two returns. int __fastcall Script_GetNumWhoResults(void *L) { const int displayed = WhoResultCount(); - const int total = *reinterpret_cast( + const int total = Game::Read( static_cast(Offsets::VAR_WHO_RESULT_COUNT) + 4); Game::Lua::PushNumber(L, static_cast(displayed)); Game::Lua::PushNumber(L, static_cast(total)); @@ -67,15 +66,15 @@ int __fastcall Script_GetWhoInfo(void *L) { static_cast(Offsets::VAR_WHO_RESULTS) + static_cast(index - 1) * Offsets::WHO_RESULT_STRIDE); - const char *name = reinterpret_cast(entry + Offsets::OFF_WHO_NAME); - const char *guild = reinterpret_cast(entry + Offsets::OFF_WHO_GUILD); - const int level = *reinterpret_cast(entry + Offsets::OFF_WHO_LEVEL); + const char *name = Game::Ptr(entry, Offsets::OFF_WHO_NAME); + const char *guild = Game::Ptr(entry, Offsets::OFF_WHO_GUILD); + const int level = Game::Read(entry, Offsets::OFF_WHO_LEVEL); const uint32_t raceID = - *reinterpret_cast(entry + Offsets::OFF_WHO_RACE); + Game::Read(entry, Offsets::OFF_WHO_RACE); const uint32_t classID = - *reinterpret_cast(entry + Offsets::OFF_WHO_CLASS); + Game::Read(entry, Offsets::OFF_WHO_CLASS); const uint32_t zoneID = - *reinterpret_cast(entry + Offsets::OFF_WHO_ZONE); + Game::Read(entry, Offsets::OFF_WHO_ZONE); Game::Lua::NewTable(L); Game::Lua::SetFieldString(L, "fullName", name); // inline; "" if empty diff --git a/src/gameobject/Info.cpp b/src/gameobject/Info.cpp index 28226d1a..d1e0bdda 100644 --- a/src/gameobject/Info.cpp +++ b/src/gameobject/Info.cpp @@ -72,10 +72,10 @@ int __fastcall Script_GetGameObjectInfoByID(void *L) { if (rec == nullptr) return 0; // not cached -> nil - const uint32_t type = *reinterpret_cast(rec + Offsets::OFF_GAMEOBJECT_TYPE); + const uint32_t type = Game::Read(rec, Offsets::OFF_GAMEOBJECT_TYPE); const uint32_t displayID = - *reinterpret_cast(rec + Offsets::OFF_GAMEOBJECT_DISPLAYID); - const char *name = *reinterpret_cast(rec + Offsets::OFF_GAMEOBJECT_NAME); + Game::Read(rec, Offsets::OFF_GAMEOBJECT_DISPLAYID); + const char *name = Game::Read(rec, Offsets::OFF_GAMEOBJECT_NAME); Game::Lua::NewTable(L); Game::Lua::SetFieldNumber(L, "gameObjectID", goID); diff --git a/src/gameobject/Tooltip.cpp b/src/gameobject/Tooltip.cpp index 7ec7ec5c..a99e4cab 100644 --- a/src/gameobject/Tooltip.cpp +++ b/src/gameobject/Tooltip.cpp @@ -63,10 +63,10 @@ static int __fastcall Script_GameTooltipGetGameObject(void *L) { return 0; const auto *base = static_cast(tooltipObj); - const uint32_t guidLo = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO); - const uint32_t guidHi = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI); + const uint32_t guidLo = + Game::Read(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO); + const uint32_t guidHi = + Game::Read(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI); if (guidLo == 0 && guidHi == 0) return 0; @@ -111,10 +111,10 @@ static int __fastcall Script_GameTooltipHasGameObject(void *L) { return 1; } const auto *base = static_cast(tooltipObj); - const uint32_t guidLo = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO); - const uint32_t guidHi = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI); + const uint32_t guidLo = + Game::Read(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO); + const uint32_t guidHi = + Game::Read(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI); Game::Lua::PushBool(L, guidLo != 0 || guidHi != 0); return 1; } diff --git a/src/group/MemberStats.cpp b/src/group/MemberStats.cpp index cbd4f1e2..66cca6bd 100644 --- a/src/group/MemberStats.cpp +++ b/src/group/MemberStats.cpp @@ -13,6 +13,7 @@ #include "group/MemberStats.h" +#include "Game.h" #include "Offsets.h" namespace Group::MemberStats { @@ -23,7 +24,7 @@ namespace { using Lookup_t = const uint8_t *(__fastcall *)(uint64_t *guid); uint16_t U16(const uint8_t *p, int off) { - return *reinterpret_cast(p + off); + return Game::Read(p, off); } } // namespace @@ -67,13 +68,13 @@ Stats Lookup(uint64_t guid) { s.level = U16(e, Offsets::OFF_RAID_SLOT_LEVEL); s.areaId = U16(e, Offsets::OFF_RAID_SLOT_AREA_ID); const uint32_t flags = - *reinterpret_cast(e + Offsets::OFF_RAID_SLOT_FLAGS); + Game::Read(e, Offsets::OFF_RAID_SLOT_FLAGS); s.online = (flags & Offsets::RAID_SLOT_FLAG_ONLINE) != 0; s.dead = (flags & Offsets::RAID_SLOT_FLAG_DEAD) != 0; - s.subgroup = static_cast(*reinterpret_cast( - e + Offsets::OFF_RAID_SLOT_SUBGROUP)) + 1; + s.subgroup = static_cast(Game::Read( + e, Offsets::OFF_RAID_SLOT_SUBGROUP)) + 1; s.rank = static_cast( - *reinterpret_cast(e + Offsets::OFF_RAID_SLOT_RANK)); + Game::Read(e, Offsets::OFF_RAID_SLOT_RANK)); return s; } @@ -93,8 +94,8 @@ const uint16_t *AuraArray(uint64_t guid) { if ((e[Offsets::OFF_GROUP_MEMBER_STATUS_FLAGS] & Offsets::GROUP_MEMBER_STATUS_ONLINE) == 0) return nullptr; - return reinterpret_cast( - e + Offsets::OFF_GROUP_MEMBER_STATS_AURAS); + return Game::Ptr( + e, Offsets::OFF_GROUP_MEMBER_STATS_AURAS); } // Raid slot — auras at +0x64, no online gate (mirrors the engine's raid @@ -102,8 +103,8 @@ const uint16_t *AuraArray(uint64_t guid) { auto slotFn = reinterpret_cast( static_cast(Offsets::FUN_GROUP_MEMBER_SLOT_LOOKUP)); if (const uint8_t *e = slotFn(&guid)) { - return reinterpret_cast( - e + Offsets::OFF_RAID_SLOT_AURAS); + return Game::Ptr( + e, Offsets::OFF_RAID_SLOT_AURAS); } return nullptr; diff --git a/src/item/AverageLevel.cpp b/src/item/AverageLevel.cpp index 2b3bbb45..67136e13 100644 --- a/src/item/AverageLevel.cpp +++ b/src/item/AverageLevel.cpp @@ -138,8 +138,8 @@ ItemInfo ReadItemInfo(const uint8_t *cgItem) { Item::Data::WarmCache(static_cast(itemID)); return {0, 0}; } - return {*reinterpret_cast(record + Offsets::OFF_ITEMSTATS_ITEM_LEVEL), - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)}; + return {Game::Read(record, Offsets::OFF_ITEMSTATS_ITEM_LEVEL), + Game::Read(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)}; } // Bank-walk helpers — bypass the bank-window gate on `GetItemBySlot` @@ -184,8 +184,8 @@ void WalkGuidArrayRange(const uint8_t *invMgr, int firstSlot, int lastSlot, std::vector &candidates) { if (invMgr == nullptr) return; - auto *guidArray = *reinterpret_cast( - invMgr + Offsets::OFF_INVMGR_GUID_ARRAY); + auto *guidArray = Game::Read( + invMgr, Offsets::OFF_INVMGR_GUID_ARRAY); if (guidArray == nullptr) return; for (int slot = firstSlot; slot <= lastSlot; ++slot) { @@ -203,8 +203,8 @@ void WalkBankBags(std::vector &candidates) { auto *playerInvMgr = Unit::Identity::PlayerInventoryManager(); if (playerInvMgr == nullptr) return; - auto *playerGuidArray = *reinterpret_cast( - playerInvMgr + Offsets::OFF_INVMGR_GUID_ARRAY); + auto *playerGuidArray = Game::Read( + playerInvMgr, Offsets::OFF_INVMGR_GUID_ARRAY); if (playerGuidArray == nullptr) return; for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT; diff --git a/src/item/Cursor.cpp b/src/item/Cursor.cpp index 716047c6..abc422f5 100644 --- a/src/item/Cursor.cpp +++ b/src/item/Cursor.cpp @@ -39,7 +39,7 @@ constexpr int OFF_CONTAINER_GUID_LO = 0x08; constexpr int OFF_CONTAINER_GUID_HI = 0x0C; bool ItemLocked(const uint8_t *item) { - return (*reinterpret_cast(item + Offsets::OFF_ITEM_CLIENT_LOCK) & 1) != 0; + return (Game::Read(item, Offsets::OFF_ITEM_CLIENT_LOCK) & 1) != 0; } // Reads a CGItem's 64-bit instance GUID into lo/hi. False if the instance @@ -48,8 +48,8 @@ bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) { auto *instance = Item::InstanceBlock(item); if (instance == nullptr) return false; - *lo = *reinterpret_cast(instance + Offsets::OFF_INSTANCE_BLOCK_GUID); - *hi = *reinterpret_cast(instance + Offsets::OFF_INSTANCE_BLOCK_GUID + 4); + *lo = Game::Read(instance, Offsets::OFF_INSTANCE_BLOCK_GUID); + *hi = Game::Read(instance, Offsets::OFF_INSTANCE_BLOCK_GUID + 4); return true; } diff --git a/src/item/Data.cpp b/src/item/Data.cpp index 348f6fc3..50fd0c1d 100644 --- a/src/item/Data.cpp +++ b/src/item/Data.cpp @@ -115,8 +115,8 @@ static int ResolveLocationToItemID(void *L, int idx) { auto *instance = Item::InstanceBlock(item); if (instance == nullptr) return 0; - return static_cast(*reinterpret_cast( - instance + Offsets::OFF_INSTANCE_BLOCK_ITEM_ID)); + return static_cast(Game::Read( + instance, Offsets::OFF_INSTANCE_BLOCK_ITEM_ID)); } static int __fastcall Script_IsItemDataCachedByID(void *L) { @@ -383,8 +383,8 @@ static void AddOwned(uint32_t itemID) { static void CollectOwnedFrom(const uint8_t *invMgr, int first, int last) { if (invMgr == nullptr) return; - auto *guids = *reinterpret_cast( - invMgr + Offsets::OFF_INVMGR_GUID_ARRAY); + auto *guids = Game::Read( + invMgr, Offsets::OFF_INVMGR_GUID_ARRAY); if (guids == nullptr) return; for (int slot = first; slot <= last; ++slot) { @@ -409,7 +409,7 @@ static void RebuildOwned() { if (bagInv == nullptr) continue; const int count = static_cast( - *reinterpret_cast(bagInv + Offsets::OFF_INVMGR_SLOT_COUNT)); + Game::Read(bagInv, Offsets::OFF_INVMGR_SLOT_COUNT)); if (count > 0) CollectOwnedFrom(bagInv, 0, count - 1); } diff --git a/src/item/EnchantInfo.cpp b/src/item/EnchantInfo.cpp index 58bd73e6..71b3752b 100644 --- a/src/item/EnchantInfo.cpp +++ b/src/item/EnchantInfo.cpp @@ -83,8 +83,8 @@ int __fastcall Script_C_Item_GetEnchantInfo(void *L) { // Localized display name (8-slot locale array at +0x34). Clamp the // locale index to the array bounds — index 8 would read the locale // mask column that follows. enUS (0) fallback for empty slots. - auto names = reinterpret_cast(rec + Offsets::OFF_SPELLITEMENCHANT_NAME); - int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); + auto names = Game::Ptr(rec, Offsets::OFF_SPELLITEMENCHANT_NAME); + int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); if (locale < 0 || locale >= kNumNameLocales) locale = 0; const char *name = names[locale]; @@ -93,9 +93,9 @@ int __fastcall Script_C_Item_GetEnchantInfo(void *L) { if (name == nullptr || name[0] == '\0') return 0; // unnamed record -> nil - auto type = reinterpret_cast(rec + Offsets::OFF_SPELLITEMENCHANT_TYPE); - auto amount = reinterpret_cast(rec + Offsets::OFF_SPELLITEMENCHANT_AMOUNT); - auto arg = reinterpret_cast(rec + Offsets::OFF_SPELLITEMENCHANT_ARG); + auto type = Game::Ptr(rec, Offsets::OFF_SPELLITEMENCHANT_TYPE); + auto amount = Game::Ptr(rec, Offsets::OFF_SPELLITEMENCHANT_AMOUNT); + auto arg = Game::Ptr(rec, Offsets::OFF_SPELLITEMENCHANT_ARG); Game::Lua::NewTable(L); Game::Lua::SetFieldNumber(L, "enchantID", enchantID); diff --git a/src/item/GetData.cpp b/src/item/GetData.cpp index 5cf01344..2ed5c6bf 100644 --- a/src/item/GetData.cpp +++ b/src/item/GetData.cpp @@ -38,7 +38,7 @@ namespace Item::GetData { namespace { int CurrentLocaleIndex() { - return *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); + return Game::Read(Offsets::VAR_LOCALE_INDEX); } // Mirrors the lookup in `Item::Info`. ItemClass.dbc record `+0x0C` is @@ -53,10 +53,10 @@ const char *LookupClassName(uint32_t classID) { // ItemSubClass.dbc walker — same fallback chain as Script_GetItemInfo // (verbose name first, short name on miss). const char *LookupSubClassName(uint32_t classID, uint32_t subClassID) { - const int count = *reinterpret_cast(Offsets::VAR_ITEMSUBCLASS_COUNT); + const int count = Game::Read(Offsets::VAR_ITEMSUBCLASS_COUNT); if (count <= 0) return ""; - auto *records = *reinterpret_cast(Offsets::VAR_ITEMSUBCLASS_RECORDS); + auto *records = Game::Read(Offsets::VAR_ITEMSUBCLASS_RECORDS); if (records == nullptr) return ""; const int locale = CurrentLocaleIndex(); @@ -66,12 +66,12 @@ const char *LookupSubClassName(uint32_t classID, uint32_t subClassID) { continue; if (*reinterpret_cast(record + 0x04) != subClassID) continue; - const char *verbose = *reinterpret_cast( - record + Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4); + const char *verbose = Game::Read( + record, Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4); if (verbose != nullptr && verbose[0] != '\0') return verbose; - const char *shortName = *reinterpret_cast( - record + Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4); + const char *shortName = Game::Read( + record, Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4); return (shortName != nullptr && shortName[0] != '\0') ? shortName : ""; } return ""; @@ -172,10 +172,10 @@ void SetF32Array(void *L, const uint8_t *record, const char *key, void SetStatsMap(void *L, const uint8_t *record) { Game::Lua::PushString(L, "stats"); Game::Lua::NewTable(L); - auto *types = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_STAT_TYPE); - auto *values = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_STAT_VALUE); + auto *types = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_STAT_TYPE); + auto *values = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_STAT_VALUE); for (int i = 0; i < Offsets::ITEMSTATS_STAT_SLOT_COUNT; ++i) { if (types[i] == 0 && values[i] == 0) continue; @@ -193,18 +193,18 @@ void SetStatsMap(void *L, const uint8_t *record) { void SetSpellsArray(void *L, const uint8_t *record) { Game::Lua::PushString(L, "spells"); Game::Lua::NewTable(L); - auto *ids = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_ID); - auto *triggers = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_TRIGGER); - auto *charges = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_CHARGES); - auto *cooldowns = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_COOLDOWN); - auto *categories = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_CATEGORY); - auto *catCooldowns = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_CATEGORY_CD); + auto *ids = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_ID); + auto *triggers = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_TRIGGER); + auto *charges = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_CHARGES); + auto *cooldowns = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_COOLDOWN); + auto *categories = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_CATEGORY); + auto *catCooldowns = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_CATEGORY_CD); int written = 0; for (int i = 0; i < Offsets::ITEMSTATS_SPELL_SLOT_COUNT; ++i) { if (ids[i] == 0) @@ -234,38 +234,38 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) { Game::Lua::SetFieldNumber(L, "itemID", static_cast(itemID)); // Identity strings - const char *name = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_NAME); + const char *name = Game::Read( + record, Offsets::OFF_ITEMSTATS_NAME); Game::Lua::SetFieldString(L, "name", name); - const char *description = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DESCRIPTION); + const char *description = Game::Read( + record, Offsets::OFF_ITEMSTATS_DESCRIPTION); if (description != nullptr && description[0] != '\0') Game::Lua::SetFieldString(L, "description", description); // Display - const uint32_t displayInfoID = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); + const uint32_t displayInfoID = Game::Read( + record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); Game::Lua::SetFieldNumber(L, "displayInfoID", static_cast(displayInfoID)); char iconPath[260]; if (BuildIconPath(displayInfoID, iconPath, sizeof(iconPath))) Game::Lua::SetFieldString(L, "icon", iconPath); // Quality / classification - const uint32_t quality = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_QUALITY); + const uint32_t quality = Game::Read( + record, Offsets::OFF_ITEMSTATS_QUALITY); Game::Lua::SetFieldNumber(L, "quality", static_cast(quality)); - const uint32_t classID = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_CLASS); - const uint32_t subClassID = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SUBCLASS); + const uint32_t classID = Game::Read( + record, Offsets::OFF_ITEMSTATS_CLASS); + const uint32_t subClassID = Game::Read( + record, Offsets::OFF_ITEMSTATS_SUBCLASS); Game::Lua::SetFieldNumber(L, "classID", static_cast(classID)); Game::Lua::SetFieldNumber(L, "subclassID", static_cast(subClassID)); Game::Lua::SetFieldString(L, "className", LookupClassName(classID)); Game::Lua::SetFieldString(L, "subclassName", LookupSubClassName(classID, subClassID)); - const uint32_t invType = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); + const uint32_t invType = Game::Read( + record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); Game::Lua::SetFieldNumber(L, "inventoryType", static_cast(invType)); Game::Lua::SetFieldString(L, "equipLoc", LookupInvType(invType)); @@ -273,8 +273,8 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) { SetU32(L, record, "bindType", Offsets::OFF_ITEMSTATS_BONDING); // Flags: raw + decoded bits. - const uint32_t flags = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_FLAGS); + const uint32_t flags = Game::Read( + record, Offsets::OFF_ITEMSTATS_FLAGS); Game::Lua::SetFieldNumber(L, "flags", static_cast(flags)); Game::Lua::SetFieldBool(L, "isConjured", (flags & Offsets::ITEM_FLAG_CONJURED) != 0); @@ -289,8 +289,8 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) { SetI32(L, record, "maxStackSize", Offsets::OFF_ITEMSTATS_STACKABLE); SetI32(L, record, "maxCount", Offsets::OFF_ITEMSTATS_MAX_COUNT); SetU32(L, record, "containerSlots", Offsets::OFF_ITEMSTATS_CONTAINER_SLOTS); - const uint32_t rawBagFamily = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_BAG_FAMILY); + const uint32_t rawBagFamily = Game::Read( + record, Offsets::OFF_ITEMSTATS_BAG_FAMILY); Game::Lua::SetFieldNumber(L, "bagFamily", static_cast(BagFamilyIdToBitmask(rawBagFamily))); diff --git a/src/item/Info.cpp b/src/item/Info.cpp index 2273c93f..2aa02c4a 100644 --- a/src/item/Info.cpp +++ b/src/item/Info.cpp @@ -30,7 +30,7 @@ namespace Item::Info { static const char *PushedOrEmpty(const char *s) { return (s != nullptr && s[0] != 0) ? s : ""; } -static int CurrentLocaleIndex() { return *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); } +static int CurrentLocaleIndex() { return Game::Read(Offsets::VAR_LOCALE_INDEX); } static const char *LookupItemClassName(uint32_t classID) { return PushedOrEmpty(DBC::LocalizedField( @@ -39,10 +39,10 @@ static const char *LookupItemClassName(uint32_t classID) { } static const char *LookupItemSubClassName(uint32_t classID, uint32_t subClassID) { - const int count = *reinterpret_cast(Offsets::VAR_ITEMSUBCLASS_COUNT); + const int count = Game::Read(Offsets::VAR_ITEMSUBCLASS_COUNT); if (count <= 0) return ""; - auto *records = *reinterpret_cast(Offsets::VAR_ITEMSUBCLASS_RECORDS); + auto *records = Game::Read(Offsets::VAR_ITEMSUBCLASS_RECORDS); if (records == nullptr) return ""; const int locale = CurrentLocaleIndex(); @@ -54,12 +54,12 @@ static const char *LookupItemSubClassName(uint32_t classID, uint32_t subClassID) continue; // Mirror Script_GetItemInfo's fallback chain at 0x48E311..0x48E32C: // try the verbose name first, fall back to the short name. - const char *verbose = *reinterpret_cast( - record + Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4); + const char *verbose = Game::Read( + record, Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4); if (verbose != nullptr && verbose[0] != 0) return verbose; - const char *shortName = *reinterpret_cast( - record + Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4); + const char *shortName = Game::Read( + record, Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4); return PushedOrEmpty(shortName); } return ""; @@ -112,13 +112,13 @@ static int __fastcall Script_GetItemInfoInstant(void *L) { } const uint32_t classID = - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_CLASS); + Game::Read(record, Offsets::OFF_ITEMSTATS_CLASS); const uint32_t subClassID = - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_SUBCLASS); + Game::Read(record, Offsets::OFF_ITEMSTATS_SUBCLASS); const uint32_t displayInfoID = - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); + Game::Read(record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); const uint32_t invType = - *reinterpret_cast(record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); + Game::Read(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); char iconPath[260]; if (!BuildIconPath(displayInfoID, iconPath, sizeof(iconPath))) @@ -143,8 +143,8 @@ static int PushIconForItemID(void *L, int itemID) { const uint8_t *record = Item::PeekRecord(static_cast(itemID)); if (record == nullptr) return 0; - const uint32_t displayInfoID = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); + const uint32_t displayInfoID = Game::Read( + record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID); char iconPath[260]; if (!BuildIconPath(displayInfoID, iconPath, sizeof(iconPath))) return 0; @@ -274,10 +274,10 @@ static int __fastcall Script_C_Item_GetItemInfo(void *L) { const uint32_t sellPrice = u32(Offsets::OFF_ITEMSTATS_SELL_PRICE); const uint32_t bindType = u32(Offsets::OFF_ITEMSTATS_BONDING); const uint32_t setID = u32(Offsets::OFF_ITEMSTATS_ITEM_SET); - const char *name = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_NAME); - const char *description = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DESCRIPTION); + const char *name = Game::Read( + record, Offsets::OFF_ITEMSTATS_NAME); + const char *description = Game::Read( + record, Offsets::OFF_ITEMSTATS_DESCRIPTION); // Apply the link's random suffix ("... of the Owl") to both the name and // the reconstructed link when the input carried one (arg.suffix); with no diff --git a/src/item/Lock.cpp b/src/item/Lock.cpp index e8a5c603..3d36a407 100644 --- a/src/item/Lock.cpp +++ b/src/item/Lock.cpp @@ -58,8 +58,8 @@ bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) { auto *inst = Item::InstanceBlock(item); if (inst == nullptr) return false; - *lo = *reinterpret_cast(inst + Offsets::OFF_INSTANCE_BLOCK_GUID); - *hi = *reinterpret_cast(inst + Offsets::OFF_INSTANCE_BLOCK_GUID + 4); + *lo = Game::Read(inst, Offsets::OFF_INSTANCE_BLOCK_GUID); + *hi = Game::Read(inst, Offsets::OFF_INSTANCE_BLOCK_GUID + 4); return true; } @@ -84,8 +84,8 @@ int __fastcall Script_C_Item_IsLocked(void *L) { Game::Lua::PushBool(L, false); return 1; } - const uint32_t flags = *reinterpret_cast( - item + Offsets::OFF_ITEM_CLIENT_LOCK); + const uint32_t flags = Game::Read( + item, Offsets::OFF_ITEM_CLIENT_LOCK); Game::Lua::PushBool(L, (flags & Offsets::ITEM_CLIENT_LOCK_BIT) != 0); return 1; } diff --git a/src/item/StatAccum.cpp b/src/item/StatAccum.cpp index c5391b90..5c31fb6e 100644 --- a/src/item/StatAccum.cpp +++ b/src/item/StatAccum.cpp @@ -155,14 +155,14 @@ void AddSpellStatAuras(Accum *acc, int spellID, long sign) { static_cast(spellID)); if (sp == nullptr) return; - auto aura = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - auto misc = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE); - auto base = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); - auto dice = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); + auto aura = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); + auto misc = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE); + auto base = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); + auto dice = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); // Vanilla "+N Attack Power" spells carry a melee (99) AND a ranged // (124) aura with the same value; the generic melee key subsumes the @@ -248,10 +248,10 @@ void AddSpellStatAuras(Accum *acc, int spellID, long sign) { // mp5 / defense on base items (vanilla stores them as equip spells, not // stat slots). void AddEquipSpellStats(Accum *acc, const uint8_t *record, long sign) { - auto ids = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_ID); - auto triggers = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SPELL_TRIGGER); + auto ids = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_ID); + auto triggers = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_SPELL_TRIGGER); for (int i = 0; i < Offsets::ITEMSTATS_SPELL_SLOT_COUNT; ++i) if (ids[i] != 0 && triggers[i] == 1) // ON_EQUIP AddSpellStatAuras(acc, static_cast(ids[i]), sign); @@ -288,14 +288,14 @@ long Value(const Accum *acc, const char *key) { double ComputeDPS(const uint8_t *record) { if (record == nullptr) return 0.0; - const uint32_t delayMs = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DELAY); + const uint32_t delayMs = Game::Read( + record, Offsets::OFF_ITEMSTATS_DELAY); if (delayMs == 0) return 0.0; - auto *dmgMin = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DAMAGE_MIN); - auto *dmgMax = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_DAMAGE_MAX); + auto *dmgMin = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_DAMAGE_MIN); + auto *dmgMax = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_DAMAGE_MAX); double avgTotal = 0.0; for (int i = 0; i < Offsets::ITEMSTATS_DAMAGE_SLOT_COUNT; ++i) avgTotal += (static_cast(dmgMin[i]) + @@ -312,9 +312,9 @@ void ApplyEnchant(Accum *acc, uint32_t enchantID, long sign) { Offsets::VAR_SPELLITEMENCHANT_COUNT, enchantID); if (en == nullptr) return; - auto type = reinterpret_cast(en + Offsets::OFF_SPELLITEMENCHANT_TYPE); - auto amount = reinterpret_cast(en + Offsets::OFF_SPELLITEMENCHANT_AMOUNT); - auto arg = reinterpret_cast(en + Offsets::OFF_SPELLITEMENCHANT_ARG); + auto type = Game::Ptr(en, Offsets::OFF_SPELLITEMENCHANT_TYPE); + auto amount = Game::Ptr(en, Offsets::OFF_SPELLITEMENCHANT_AMOUNT); + auto arg = Game::Ptr(en, Offsets::OFF_SPELLITEMENCHANT_ARG); for (int i = 0; i < 3; ++i) { // SpellItemEnchantment has 3 effect slots switch (type[i]) { case 3: // equip spell — stat/resist value lives in the spell @@ -341,8 +341,8 @@ void ApplyRandomSuffix(Accum *acc, int suffixID, long sign) { static_cast(suffixID)); if (rp == nullptr) return; - auto enchants = reinterpret_cast( - rp + Offsets::OFF_ITEMRANDOMPROP_ENCHANT); + auto enchants = Game::Ptr( + rp, Offsets::OFF_ITEMRANDOMPROP_ENCHANT); for (int s = 0; s < Offsets::ITEMRANDOMPROP_ENCHANT_SLOT_COUNT; ++s) ApplyEnchant(acc, enchants[s], sign); } @@ -350,10 +350,10 @@ void ApplyRandomSuffix(Accum *acc, int suffixID, long sign) { void AccumulateRecord(Accum *acc, const uint8_t *record, long sign) { if (record == nullptr) return; - auto *types = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_STAT_TYPE); - auto *values = reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_STAT_VALUE); + auto *types = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_STAT_TYPE); + auto *values = Game::Ptr( + record, Offsets::OFF_ITEMSTATS_STAT_VALUE); for (int i = 0; i < Offsets::ITEMSTATS_STAT_SLOT_COUNT; ++i) AddByKey(acc, StatKeyForItemModType(types[i]), sign * static_cast(values[i])); diff --git a/src/item/Swap.cpp b/src/item/Swap.cpp index e337511f..139aa7f0 100644 --- a/src/item/Swap.cpp +++ b/src/item/Swap.cpp @@ -44,8 +44,8 @@ bool ReadGuid(const void *cgObject, uint32_t *lo, uint32_t *hi) { auto *inst = Item::InstanceBlock(base); if (inst == nullptr) return false; - *lo = *reinterpret_cast(inst + Offsets::OFF_INSTANCE_BLOCK_GUID); - *hi = *reinterpret_cast(inst + Offsets::OFF_INSTANCE_BLOCK_GUID + 4); + *lo = Game::Read(inst, Offsets::OFF_INSTANCE_BLOCK_GUID); + *hi = Game::Read(inst, Offsets::OFF_INSTANCE_BLOCK_GUID + 4); return true; } @@ -259,8 +259,8 @@ bool MoveCount(void *L, int srcBag, int srcSlot, int dstBag, int dstSlot, int co // have to special-case "move everything". auto *srcDescriptor = Item::ObjectFields(srcItem); const int srcStack = srcDescriptor == nullptr ? 0 : - static_cast(*reinterpret_cast( - srcDescriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT)); + static_cast(Game::Read( + srcDescriptor, Offsets::OFF_DESCRIPTOR_STACK_COUNT)); if (count > srcStack) return false; // server would reject anyway; fail fast and locally if (count == srcStack) diff --git a/src/item/Tooltip.cpp b/src/item/Tooltip.cpp index a1e064b3..f5613a38 100644 --- a/src/item/Tooltip.cpp +++ b/src/item/Tooltip.cpp @@ -241,16 +241,16 @@ static int __fastcall Script_GameTooltipGetItem(void *L) { Item::Data::WarmCache(static_cast(itemID)); return 0; } - const char *name = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_NAME); + const char *name = Game::Read( + record, Offsets::OFF_ITEMSTATS_NAME); if (name == nullptr || *name == '\0') return 0; - const uint32_t quality = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_QUALITY); + const uint32_t quality = Game::Read( + record, Offsets::OFF_ITEMSTATS_QUALITY); int suffix = 0; - if (*reinterpret_cast(base + Offsets::OFF_TOOLTIP_COMPARE_FLAG) != 0) - suffix = *reinterpret_cast(base + Offsets::OFF_TOOLTIP_COMPARE_SUFFIX); + if (Game::Read(base, Offsets::OFF_TOOLTIP_COMPARE_FLAG) != 0) + suffix = Game::Read(base, Offsets::OFF_TOOLTIP_COMPARE_SUFFIX); char link[256]; std::snprintf(link, sizeof(link), diff --git a/src/item/TooltipItem.cpp b/src/item/TooltipItem.cpp index 9b9559d0..acc70ace 100644 --- a/src/item/TooltipItem.cpp +++ b/src/item/TooltipItem.cpp @@ -13,6 +13,7 @@ #include "item/TooltipItem.h" +#include "Game.h" #include "Offsets.h" #include "item/ID.h" #include "item/Location.h" @@ -27,10 +28,10 @@ int CurrentID(const void *tooltipObj, uint64_t *outGuid) { auto *c = static_cast(tooltipObj); const uint64_t itemGuid = - *reinterpret_cast(c + Offsets::OFF_TOOLTIP_ITEM_GUID_LO); + Game::Read(c, Offsets::OFF_TOOLTIP_ITEM_GUID_LO); // Link item: the itemID field is authoritative (and reliably cleared). - const int linkItemID = *reinterpret_cast(c + Offsets::OFF_TOOLTIP_ITEM_ID); + const int linkItemID = Game::Read(c, Offsets::OFF_TOOLTIP_ITEM_ID); if (linkItemID > 0) { if (outGuid != nullptr) *outGuid = itemGuid; @@ -44,11 +45,11 @@ int CurrentID(const void *tooltipObj, uint64_t *outGuid) { // it to the itemID (this also yields the dressed link for callers). if (itemGuid == 0) return 0; - if (*reinterpret_cast(c + Offsets::OFF_TOOLTIP_UNIT_GUID_LO) != 0) + if (Game::Read(c, Offsets::OFF_TOOLTIP_UNIT_GUID_LO) != 0) return 0; - if (*reinterpret_cast(c + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO) != 0) + if (Game::Read(c, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO) != 0) return 0; - if (*reinterpret_cast(c + Offsets::OFF_TOOLTIP_SPELL_ID) > 0) + if (Game::Read(c, Offsets::OFF_TOOLTIP_SPELL_ID) > 0) return 0; const uint8_t *cg = Item::Location::ResolveByGUID(itemGuid); diff --git a/src/item/scrape/InboxID.cpp b/src/item/scrape/InboxID.cpp index 372979f4..49254fd8 100644 --- a/src/item/scrape/InboxID.cpp +++ b/src/item/scrape/InboxID.cpp @@ -31,7 +31,7 @@ static int __fastcall Script_GetInboxItemID(void *L) { if (mailID < 0) return 0; - const int count = static_cast(*reinterpret_cast( + const int count = static_cast(Game::Read( Offsets::VAR_INBOX_COUNT)); if (mailID >= count) return 0; @@ -39,15 +39,15 @@ static int __fastcall Script_GetInboxItemID(void *L) { // `VAR_INBOX_ENTRIES` is a pointer slot, not the array — the // engine reads it via `MOV ECX, [imm32]; MOV EDI, [ECX + idx*4]` // (two derefs total before the entry pointer is in hand). - auto **entries = *reinterpret_cast(Offsets::VAR_INBOX_ENTRIES); + auto **entries = Game::Read(Offsets::VAR_INBOX_ENTRIES); if (entries == nullptr) return 0; auto *entry = entries[mailID]; if (entry == nullptr) return 0; - const int itemID = static_cast(*reinterpret_cast( - entry + Offsets::OFF_INBOX_ENTRY_ITEM_ID)); + const int itemID = static_cast(Game::Read( + entry, Offsets::OFF_INBOX_ENTRY_ITEM_ID)); if (itemID == 0) return 0; diff --git a/src/item/scrape/LootSlotID.cpp b/src/item/scrape/LootSlotID.cpp index d19979ee..5374b7fd 100644 --- a/src/item/scrape/LootSlotID.cpp +++ b/src/item/scrape/LootSlotID.cpp @@ -38,13 +38,13 @@ static int __fastcall Script_GetLootSlotItemID(void *L) { } int slot = static_cast(Game::Lua::ToNumber(L, 1)); - const uint32_t guidLo = *reinterpret_cast(Offsets::VAR_LOOT_GUID_LO); - const uint32_t guidHi = *reinterpret_cast(Offsets::VAR_LOOT_GUID_HI); + const uint32_t guidLo = Game::Read(Offsets::VAR_LOOT_GUID_LO); + const uint32_t guidHi = Game::Read(Offsets::VAR_LOOT_GUID_HI); if ((guidLo | guidHi) == 0) return 0; slot -= 1; - if (*reinterpret_cast(Offsets::VAR_LOOT_LOOTABLE) != 0) { + if (Game::Read(Offsets::VAR_LOOT_LOOTABLE) != 0) { if (slot <= 0) return 0; slot -= 1; diff --git a/src/item/scrape/MerchantID.cpp b/src/item/scrape/MerchantID.cpp index 10ec8534..053c7593 100644 --- a/src/item/scrape/MerchantID.cpp +++ b/src/item/scrape/MerchantID.cpp @@ -30,20 +30,20 @@ static int __fastcall Script_GetMerchantItemID(void *L) { if (index < 0) return 0; - const uint32_t guidLo = *reinterpret_cast(Offsets::VAR_MERCHANT_NPC_GUID_LO); - const uint32_t guidHi = *reinterpret_cast(Offsets::VAR_MERCHANT_NPC_GUID_HI); + const uint32_t guidLo = Game::Read(Offsets::VAR_MERCHANT_NPC_GUID_LO); + const uint32_t guidHi = Game::Read(Offsets::VAR_MERCHANT_NPC_GUID_HI); if ((guidLo | guidHi) == 0) return 0; - const int count = static_cast(*reinterpret_cast( + const int count = static_cast(Game::Read( Offsets::VAR_MERCHANT_COUNT)); if (index >= count) return 0; auto *entry = reinterpret_cast( Offsets::VAR_MERCHANT_ITEMS + index * Offsets::MERCHANT_STRIDE); - const int itemID = static_cast(*reinterpret_cast( - entry + Offsets::OFF_MERCHANT_ITEM_ID)); + const int itemID = static_cast(Game::Read( + entry, Offsets::OFF_MERCHANT_ITEM_ID)); if (itemID == 0) return 0; diff --git a/src/loot/History.cpp b/src/loot/History.cpp index 67ae3a3c..8267eb80 100644 --- a/src/loot/History.cpp +++ b/src/loot/History.cpp @@ -92,13 +92,13 @@ const uint8_t *LookupPlayerRecord(uint64_t guid) { const char *NameFromRecord(const uint8_t *rec) { return rec != nullptr - ? reinterpret_cast(rec + Offsets::OFF_PLAYER_INFO_NAME) + ? Game::Ptr(rec, Offsets::OFF_PLAYER_INFO_NAME) : nullptr; } uint32_t ClassIdFromRecord(const uint8_t *rec) { return rec != nullptr - ? *reinterpret_cast(rec + Offsets::OFF_PLAYER_INFO_CLASS) + ? Game::Read(rec, Offsets::OFF_PLAYER_INFO_CLASS) : 0; } @@ -312,7 +312,7 @@ int RecordAllPassed(const void *msg) { // the same field offsets as the message. This is the only place the random // fields are populated, so the result recorders leave them alone. void RecordStart() { - const uint8_t *node = *reinterpret_cast( + const uint8_t *node = Game::Read( static_cast(Offsets::VAR_LOOTROLL_STORE_HEAD)); if (node == nullptr) return; diff --git a/src/loot/Nearby.cpp b/src/loot/Nearby.cpp index 051005e0..a026b7ef 100644 --- a/src/loot/Nearby.cpp +++ b/src/loot/Nearby.cpp @@ -76,10 +76,9 @@ constexpr int VTBL_GET_POSITION_OFFSET = 0x14; // bit of *race* — yields false positives for any Human / Dwarf / // Undead / Gnome player and false negatives for dead mobs. bool IsLootable(const void *unit) { - auto *fields = *reinterpret_cast( - static_cast(unit) + Offsets::OFF_UNIT_DESCRIPTOR); - const uint32_t flags = *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS); + auto *fields = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); + const uint32_t flags = + Game::Read(fields, Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS); return (flags & Offsets::UNIT_DYNFLAG_LOOTABLE) != 0; } @@ -87,10 +86,8 @@ bool IsLootable(const void *unit) { // engine uses this as the contribution from both sides (player + target) // in its interact-range computation. float BoundingRadius(const void *unit) { - auto *fields = *reinterpret_cast( - static_cast(unit) + Offsets::OFF_UNIT_DESCRIPTOR); - return *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS); + auto *fields = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); + return Game::Read(fields, Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS); } // Invokes the unit's virtual `GetPosition` (vtable slot at offset diff --git a/src/loot/Scan.cpp b/src/loot/Scan.cpp index 512ae816..2f3527fe 100644 --- a/src/loot/Scan.cpp +++ b/src/loot/Scan.cpp @@ -143,18 +143,15 @@ constexpr float MIN_INTERACT_RANGE = 5.0f; // === Range / lootability helpers (identical to Loot::Nearby) === bool IsLootableUnit(const void *unit) { - auto *fields = *reinterpret_cast( - static_cast(unit) + Offsets::OFF_UNIT_DESCRIPTOR); - const uint32_t flags = *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS); + auto *fields = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); + const uint32_t flags = + Game::Read(fields, Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS); return (flags & Offsets::UNIT_DYNFLAG_LOOTABLE) != 0; } float BoundingRadius(const void *unit) { - auto *fields = *reinterpret_cast( - static_cast(unit) + Offsets::OFF_UNIT_DESCRIPTOR); - return *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS); + auto *fields = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); + return Game::Read(fields, Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS); } const C3Vector *GetPosition(const void *unit, C3Vector *outBuf) { @@ -190,8 +187,7 @@ bool InInteractRange(const void *player, const void *target) { // `FUN_LOOT_CONTROLLER` run, so the slot table is fully filled in // and the link builder works against it. void ScrapeCurrentLoot(LootEntry *out) { - const uint32_t coinRaw = *reinterpret_cast( - Offsets::VAR_LOOT_LOOTABLE); + const uint32_t coinRaw = Game::Read(Offsets::VAR_LOOT_LOOTABLE); out->coin = (coinRaw == 0xFFFFFFFFu) ? 0u : coinRaw; const bool hasCoin = coinRaw != 0; @@ -239,8 +235,7 @@ void ScrapeCurrentLoot(LootEntry *out) { void LootCurrentWindow() { // Coin present when `VAR_LOOT_LOOTABLE` holds a real amount (0 = none; // 0xFFFFFFFF = already-looted sentinel, never seen on a fresh open). - const uint32_t coinRaw = *reinterpret_cast( - Offsets::VAR_LOOT_LOOTABLE); + const uint32_t coinRaw = Game::Read(Offsets::VAR_LOOT_LOOTABLE); if (coinRaw != 0 && coinRaw != 0xFFFFFFFFu) { auto LootMoney = reinterpret_cast(Offsets::FUN_CMSG_LOOT_MONEY); LootMoney(s_scan.player); diff --git a/src/loot/UnitItem.cpp b/src/loot/UnitItem.cpp index ed423b3f..24c55479 100644 --- a/src/loot/UnitItem.cpp +++ b/src/loot/UnitItem.cpp @@ -57,8 +57,8 @@ uint32_t s_desiredItemID = 0; int s_ticksSinceTransition = 0; uint64_t ReadLootTargetGuid() { - const uint32_t lo = *reinterpret_cast(Offsets::VAR_LOOT_GUID_LO); - const uint32_t hi = *reinterpret_cast(Offsets::VAR_LOOT_GUID_HI); + const uint32_t lo = Game::Read(Offsets::VAR_LOOT_GUID_LO); + const uint32_t hi = Game::Read(Offsets::VAR_LOOT_GUID_HI); return static_cast(hi) << 32 | lo; } diff --git a/src/lossofcontrol/Info.cpp b/src/lossofcontrol/Info.cpp index 8c2e110c..c41eb8a4 100644 --- a/src/lossofcontrol/Info.cpp +++ b/src/lossofcontrol/Info.cpp @@ -61,14 +61,14 @@ using Time::Clock::NowMs; using Time::Clock::Reached; const char *SpellName(const uint8_t *rec) { - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); const char *n = - *reinterpret_cast(rec + Offsets::OFF_SPELL_NAMES + locale * 4); + Game::Read(rec, Offsets::OFF_SPELL_NAMES + locale * 4); return (n != nullptr) ? n : ""; } const char *SpellIconPath(const uint8_t *rec) { - const int iconID = *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ICON_ID); + const int iconID = Game::Read(rec, Offsets::OFF_SPELL_RECORD_ICON_ID); const uint8_t *iconRec = DBC::Record(Offsets::VAR_SPELL_ICON_RECORDS, Offsets::VAR_SPELL_ICON_COUNT, static_cast(iconID)); @@ -79,7 +79,7 @@ const char *SpellIconPath(const uint8_t *rec) { } int SpellSchoolIndex(const uint8_t *rec) { - return *reinterpret_cast(rec + Offsets::OFF_SPELL_SCHOOL); + return Game::Read(rec, Offsets::OFF_SPELL_SCHOOL); } // The control-loss classifier lives in `Spell::CrowdControl::Classify` so the diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 4729eae7..11c1492d 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -13,21 +13,20 @@ #include "map/Area.h" +#include "Game.h" #include "Offsets.h" #include "dbc/Lookup.h" namespace Map::Area { int RowForAreaID(uint32_t areaID) { - const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT); + const int count = Game::Read(Offsets::VAR_WORLDMAP_AREA_COUNT); for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS, Offsets::VAR_WORLDMAP_AREA_COUNT, static_cast(id)); if (rec != nullptr && - *reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID) == - areaID) + Game::Read(rec, Offsets::OFF_WMA_AREA_ID) == areaID) return id; } return -1; @@ -35,17 +34,15 @@ int RowForAreaID(uint32_t areaID) { int CurrentViewRow() { const int continent = - *reinterpret_cast(Offsets::VAR_WORLDMAP_CONTINENT_INDEX); + Game::Read(Offsets::VAR_WORLDMAP_CONTINENT_INDEX); if (continent < 0) - return *reinterpret_cast( - Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW); - const uint8_t *blob = *reinterpret_cast( - Offsets::VAR_WORLDMAP_CONTINENT_DATA); + return Game::Read(Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW); + const uint8_t *blob = + Game::Read(Offsets::VAR_WORLDMAP_CONTINENT_DATA); if (blob == nullptr) return -1; const uint8_t *entry = blob + continent * Offsets::WORLDMAP_CONTINENT_STRIDE; - const int zone = - *reinterpret_cast(Offsets::VAR_WORLDMAP_ZONE_INDEX); + const int zone = Game::Read(Offsets::VAR_WORLDMAP_ZONE_INDEX); if (zone < 0) return *reinterpret_cast(entry + 0x04); const int *zoneRows = *reinterpret_cast(entry + 0x10); @@ -80,20 +77,19 @@ double OverlayMargin(int wmaRow, double mapXpct, double mapYpct) { const double cx = mapXpct / 100.0 * kZoneCanvasW; const double cy = mapYpct / 100.0 * kZoneCanvasH; const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); + Game::Read(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); double best = -1.0; for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_OVERLAY_RECORDS, Offsets::VAR_WORLDMAP_OVERLAY_COUNT, static_cast(id)); if (rec == nullptr || - *reinterpret_cast(rec + Offsets::OFF_WMO_WORLDMAP_AREA) != - wmaRow) + Game::Read(rec, Offsets::OFF_WMO_WORLDMAP_AREA) != wmaRow) continue; - const int hl = *reinterpret_cast(rec + Offsets::OFF_WMO_HITRECT_LEFT); - const int hr = *reinterpret_cast(rec + Offsets::OFF_WMO_HITRECT_RIGHT); - const int ht = *reinterpret_cast(rec + Offsets::OFF_WMO_HITRECT_TOP); - const int hb = *reinterpret_cast(rec + Offsets::OFF_WMO_HITRECT_BOTTOM); + const int hl = Game::Read(rec, Offsets::OFF_WMO_HITRECT_LEFT); + const int hr = Game::Read(rec, Offsets::OFF_WMO_HITRECT_RIGHT); + const int ht = Game::Read(rec, Offsets::OFF_WMO_HITRECT_TOP); + const int hb = Game::Read(rec, Offsets::OFF_WMO_HITRECT_BOTTOM); const double sw = hr - hl, sh = hb - ht; if (sw <= 0.0 || sh <= 0.0) continue; // no / degenerate hit rect @@ -111,8 +107,7 @@ double OverlayMargin(int wmaRow, double mapXpct, double mapYpct) { bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX, double *outMapY) { - const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT); + const int count = Game::Read(Offsets::VAR_WORLDMAP_AREA_COUNT); // Two candidate tracks over the zones whose rect contains the point: // land* — the point is on the zone's drawn landmass (an overlay hit rect // encloses it): authoritative, wins whenever any zone qualifies. @@ -132,10 +127,9 @@ bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX, static_cast(id)); if (rec == nullptr) continue; - if (*reinterpret_cast(rec + Offsets::OFF_WMA_MAP_ID) != mapID) + if (Game::Read(rec, Offsets::OFF_WMA_MAP_ID) != mapID) continue; - const int areaID = - *reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID); + const int areaID = Game::Read(rec, Offsets::OFF_WMA_AREA_ID); if (areaID == 0) continue; // continent-spanning row, not a zone @@ -191,15 +185,14 @@ bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX, } bool PercentInZone(int areaID, float x, float y, double *outMapX, double *outMapY) { - const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT); + const int count = Game::Read(Offsets::VAR_WORLDMAP_AREA_COUNT); for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS, Offsets::VAR_WORLDMAP_AREA_COUNT, static_cast(id)); if (rec == nullptr) continue; - if (*reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID) != areaID) + if (Game::Read(rec, Offsets::OFF_WMA_AREA_ID) != areaID) continue; const double left = FloatField(rec, Offsets::OFF_WMA_LOC_LEFT); const double right = FloatField(rec, Offsets::OFF_WMA_LOC_RIGHT); @@ -219,17 +212,16 @@ bool PercentInZone(int areaID, float x, float y, double *outMapX, double *outMap } bool ContinentPercent(int mapID, float x, float y, double *outPx, double *outPy) { - const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT); + const int count = Game::Read(Offsets::VAR_WORLDMAP_AREA_COUNT); for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS, Offsets::VAR_WORLDMAP_AREA_COUNT, static_cast(id)); if (rec == nullptr) continue; - if (*reinterpret_cast(rec + Offsets::OFF_WMA_MAP_ID) != mapID) + if (Game::Read(rec, Offsets::OFF_WMA_MAP_ID) != mapID) continue; - if (*reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID) != 0) + if (Game::Read(rec, Offsets::OFF_WMA_AREA_ID) != 0) continue; // want the continent-spanning row const double left = FloatField(rec, Offsets::OFF_WMA_LOC_LEFT); diff --git a/src/map/AreaTriggers.cpp b/src/map/AreaTriggers.cpp index ec20b26a..cda123a6 100644 --- a/src/map/AreaTriggers.cpp +++ b/src/map/AreaTriggers.cpp @@ -80,7 +80,7 @@ bool PushTriggerInfo(void *L, int id) { if (rec == nullptr) return false; - const int mapID = *reinterpret_cast(rec + Offsets::OFF_AT_MAP_ID); + const int mapID = Game::Read(rec, Offsets::OFF_AT_MAP_ID); const float x = FloatField(rec, Offsets::OFF_AT_X); const float y = FloatField(rec, Offsets::OFF_AT_Y); const float z = FloatField(rec, Offsets::OFF_AT_Z); @@ -134,8 +134,7 @@ int __fastcall Script_GetAreaTriggers(void *L) { Game::Lua::SetTop(L, 0); Game::Lua::NewTable(L); - const int count = - *reinterpret_cast(Offsets::VAR_AREATRIGGER_COUNT); + const int count = Game::Read(Offsets::VAR_AREATRIGGER_COUNT); int outIdx = 0; for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_AREATRIGGER_RECORDS, @@ -144,7 +143,7 @@ int __fastcall Script_GetAreaTriggers(void *L) { if (rec == nullptr) continue; if (filter && - *reinterpret_cast(rec + Offsets::OFF_AT_MAP_ID) != wantMap) + Game::Read(rec, Offsets::OFF_AT_MAP_ID) != wantMap) continue; outIdx += 1; diff --git a/src/map/Areas.cpp b/src/map/Areas.cpp index b3aa0f57..a890aa5b 100644 --- a/src/map/Areas.cpp +++ b/src/map/Areas.cpp @@ -67,8 +67,7 @@ int __fastcall Script_GetAreas(void *L) { Game::Lua::SetTop(L, 0); Game::Lua::NewTable(L); - const int count = - *reinterpret_cast(Offsets::VAR_AREATABLE_COUNT); + const int count = Game::Read(Offsets::VAR_AREATABLE_COUNT); for (int id = 1; id <= count; ++id) { const char *name = DBC::AreaName(static_cast(id), /*resolveToParent=*/false); @@ -98,18 +97,17 @@ int __fastcall Script_GetMapAreaIDs(void *L) { Game::Lua::SetTop(L, 0); Game::Lua::NewTable(L); - const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT); + const int count = Game::Read(Offsets::VAR_WORLDMAP_AREA_COUNT); for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS, Offsets::VAR_WORLDMAP_AREA_COUNT, static_cast(id)); if (rec == nullptr) continue; - const int areaID = *reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID); + const int areaID = Game::Read(rec, Offsets::OFF_WMA_AREA_ID); if (areaID == 0) continue; // continent-spanning row, no zone id - const char *dir = *reinterpret_cast(rec + Offsets::OFF_WMA_NAME); + const char *dir = Game::Read(rec, Offsets::OFF_WMA_NAME); if (dir == nullptr || dir[0] == '\0') continue; Game::Lua::SetFieldNumber(L, dir, static_cast(areaID)); diff --git a/src/map/Overlays.cpp b/src/map/Overlays.cpp index 00dda941..97ee7b77 100644 --- a/src/map/Overlays.cpp +++ b/src/map/Overlays.cpp @@ -274,7 +274,7 @@ void ResolveTiles(ResolvedOverlay *out, const char *basePath, int dbcW, const ResolvedOverlay *CachedResolve(int overlayId, const char *basePath, int dbcW, int dbcH) { const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); + Game::Read(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); if (g_cache == nullptr || g_cacheSize < count + 1) { auto **fresh = new ResolvedOverlay *[count + 1](); for (int i = 0; i < g_cacheSize; ++i) @@ -388,8 +388,7 @@ const uint8_t *ExplorationBits() { auto *player = static_cast(fn("player")); if (player == nullptr) return nullptr; - auto *sub = *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + auto *sub = Game::Read(player, Offsets::OFF_CGPLAYER_INFO); if (sub == nullptr) return nullptr; return sub + Offsets::OFF_PLAYER_EXPLORED_BITS; @@ -404,8 +403,8 @@ bool IsOverlayExplored(const uint8_t *overlayRec, const uint8_t *bits) { if (bits == nullptr) return false; for (int k = 0; k < 4; ++k) { - const int areaID = *reinterpret_cast( - overlayRec + Offsets::OFF_WMO_AREA_ID + k * 4); + const int areaID = + Game::Read(overlayRec, Offsets::OFF_WMO_AREA_ID + k * 4); if (areaID <= 0) continue; const uint8_t *areaRec = @@ -413,10 +412,10 @@ bool IsOverlayExplored(const uint8_t *overlayRec, const uint8_t *bits) { Offsets::VAR_AREATABLE_COUNT, static_cast(areaID)); if (areaRec == nullptr) continue; - if (*reinterpret_cast(areaRec + Offsets::OFF_AREATABLE_EXPLORE_GATE) < 0) + if (Game::Read(areaRec, Offsets::OFF_AREATABLE_EXPLORE_GATE) < 0) return true; // area needs no exploration → always counts - const int areaBit = *reinterpret_cast( - areaRec + Offsets::OFF_AREATABLE_AREA_BIT); + const int areaBit = + Game::Read(areaRec, Offsets::OFF_AREATABLE_AREA_BIT); if (areaBit < 0) continue; const int byteIdx = areaBit >> 3; @@ -455,8 +454,7 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) { static_cast(wmaRow)); const char *mapDir = (wmaRec != nullptr) - ? *reinterpret_cast(wmaRec + - Offsets::OFF_WMA_NAME) + ? Game::Read(wmaRec, Offsets::OFF_WMA_NAME) : nullptr; // Exploration bitfield only needed for the filtered variants. @@ -464,15 +462,14 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) { (filter == Filter::All) ? nullptr : ExplorationBits(); const int count = - *reinterpret_cast(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); + Game::Read(Offsets::VAR_WORLDMAP_OVERLAY_COUNT); int outIdx = 0; for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_OVERLAY_RECORDS, Offsets::VAR_WORLDMAP_OVERLAY_COUNT, static_cast(id)); if (rec == nullptr || - *reinterpret_cast(rec + Offsets::OFF_WMO_WORLDMAP_AREA) != - wmaRow) + Game::Read(rec, Offsets::OFF_WMO_WORLDMAP_AREA) != wmaRow) continue; if (filter != Filter::All) { @@ -483,8 +480,8 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) { continue; } - const char *texName = *reinterpret_cast( - rec + Offsets::OFF_WMO_TEXTURE_NAME); + const char *texName = + Game::Read(rec, Offsets::OFF_WMO_TEXTURE_NAME); const bool hasTexture = (texName != nullptr && texName[0] != '\0'); const auto fieldInt = [rec](uintptr_t off) { diff --git a/src/map/WorldSize.cpp b/src/map/WorldSize.cpp index 948d6e1e..6c1c3bf1 100644 --- a/src/map/WorldSize.cpp +++ b/src/map/WorldSize.cpp @@ -60,10 +60,10 @@ int __fastcall Script_GetMapWorldSize(void *L) { if (rec == nullptr) return 0; - const float left = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_LEFT); - const float right = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_RIGHT); - const float top = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_TOP); - const float bottom = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_BOTTOM); + const float left = Game::Read(rec, Offsets::OFF_WMA_LOC_LEFT); + const float right = Game::Read(rec, Offsets::OFF_WMA_LOC_RIGHT); + const float top = Game::Read(rec, Offsets::OFF_WMA_LOC_TOP); + const float bottom = Game::Read(rec, Offsets::OFF_WMA_LOC_BOTTOM); Game::Lua::PushNumber(L, static_cast(left) - right); // width (world Y span) Game::Lua::PushNumber(L, static_cast(top) - bottom); // height (world X span) diff --git a/src/model/DisplayInfo.cpp b/src/model/DisplayInfo.cpp index e63f2410..b8f4f105 100644 --- a/src/model/DisplayInfo.cpp +++ b/src/model/DisplayInfo.cpp @@ -69,11 +69,9 @@ Fn Vmethod(void *obj, int byteOffset) { // Model method call; mirror that assignment (FUN_0076d950's prologue) so a // type-check is valid even if no stock Model method has run yet. int ModelTypeId() { - auto &typeId = *reinterpret_cast( - static_cast(Offsets::VAR_MODEL_LUA_TYPE_ID)); + auto &typeId = Game::Ref(Offsets::VAR_MODEL_LUA_TYPE_ID); if (typeId == 0) { - auto &counter = *reinterpret_cast( - static_cast(Offsets::VAR_FRAMESCRIPT_TYPE_ID_COUNTER)); + auto &counter = Game::Ref(Offsets::VAR_FRAMESCRIPT_TYPE_ID_COUNTER); counter += 1; typeId = counter; } @@ -107,8 +105,8 @@ void ApplySkins(void *model, const char *modelPath, const uint8_t *displayRec) { Offsets::FUN_MODEL_SET_REPLACEABLE_TEXTURE); constexpr int kMonsterSlot[3] = {11, 12, 13}; for (int i = 0; i < 3; ++i) { - const char *variation = *reinterpret_cast( - displayRec + Offsets::OFF_CREATUREDISPLAYINFO_TEXTURE_VARIATION + i * 4); + const char *variation = Game::Read( + displayRec, Offsets::OFF_CREATUREDISPLAYINFO_TEXTURE_VARIATION + i * 4); if (variation == nullptr || variation[0] == '\0') continue; const std::string skin = dir + variation; @@ -229,14 +227,14 @@ DressJob *ClaimJob(void *frame) { // engine's own early-out: an Extra record with no bake name gets no // customization at all (FUN_005fb200 returns before creating the builder). void ScheduleDress(void *frame, const uint8_t *extraRec) { - const char *bake = *reinterpret_cast( - extraRec + Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME); + const char *bake = Game::Read( + extraRec, Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME); if (bake == nullptr || bake[0] == '\0') return; DressJob *job = ClaimJob(frame); job->frame = frame; - job->instance = *reinterpret_cast(reinterpret_cast(frame) + - Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE); + job->instance = Game::Read(frame, + Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE); job->extraRec = extraRec; } @@ -244,8 +242,8 @@ void ScheduleDress(void *frame, const uint8_t *extraRec) { // equipment (the engine's order: SetInfo, then the 10 Extra equipment slots), // then pump until done. Field-for-field mirror of FUN_005fb200's NPC branch. void StepJob(DressJob &job) { - void *instance = *reinterpret_cast(reinterpret_cast(job.frame) + - Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE); + void *instance = Game::Read(job.frame, + Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE); if (job.instance == nullptr) job.instance = instance; if (instance == nullptr || instance != job.instance || ++job.ticks > kMaxDressTicks) { @@ -266,7 +264,7 @@ void StepJob(DressJob &job) { const uint8_t *extra = job.extraRec; auto field = [extra](int off) { - return *reinterpret_cast(extra + off); + return Game::Read(extra, off); }; CharCompInfo info = {}; info.race = field(Offsets::OFF_CREATUREDISPLAYINFOEXTRA_RACE); @@ -278,8 +276,8 @@ void StepJob(DressJob &job) { info.hairStyle = field(Offsets::OFF_CREATUREDISPLAYINFOEXTRA_HAIR_STYLE); info.model = instance; info.useBake = 1; - const char *bake = *reinterpret_cast( - extra + Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME); + const char *bake = Game::Read( + extra, Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME); std::snprintf(info.bakePath, sizeof(info.bakePath), "%s%s", "Textures\\BakedNpcTextures\\", bake); std::memcpy(info.geosetDefaults, kGeosetGroupDefaults, sizeof(kGeosetGroupDefaults)); @@ -308,10 +306,10 @@ void StepJob(DressJob &job) { reinterpret_cast(Offsets::FUN_MODEL_INSTANCE_SET_RENDER_CB); const void *lightFogCb = reinterpret_cast(Offsets::FUN_SIMPLEMODELFFX_LIGHT_FOG_CB); - for (auto *child = *reinterpret_cast( - reinterpret_cast(instance) + Offsets::OFF_MODEL_INSTANCE_CHILD_HEAD); - child != nullptr; child = *reinterpret_cast( - child + Offsets::OFF_MODEL_INSTANCE_CHILD_NEXT)) + for (auto *child = Game::Read( + instance, Offsets::OFF_MODEL_INSTANCE_CHILD_HEAD); + child != nullptr; child = Game::Read( + child, Offsets::OFF_MODEL_INSTANCE_CHILD_NEXT)) setRenderCb(child, lightFogCb, job.frame); job.configured = true; @@ -340,8 +338,8 @@ void LoadDisplay(void *model, int displayID) { static_cast(displayID)); if (displayRec == nullptr) return; - const uint32_t modelID = *reinterpret_cast( - displayRec + Offsets::OFF_CREATUREDISPLAYINFO_MODEL_ID); + const uint32_t modelID = Game::Read( + displayRec, Offsets::OFF_CREATUREDISPLAYINFO_MODEL_ID); const char *modelPath = DBC::StringField(Offsets::VAR_CREATUREMODELDATA_RECORDS, Offsets::VAR_CREATUREMODELDATA_COUNT, @@ -360,8 +358,8 @@ void LoadDisplay(void *model, int displayID) { // Character-based display (Character\Race\Sex base): dress it through the // engine compositor, else body and hair render white with every geoset on. - const uint32_t extID = *reinterpret_cast( - displayRec + Offsets::OFF_CREATUREDISPLAYINFO_EXTENDED_ID); + const uint32_t extID = Game::Read( + displayRec, Offsets::OFF_CREATUREDISPLAYINFO_EXTENDED_ID); if (extID != 0) { const uint8_t *extraRec = DBC::Record(Offsets::VAR_CREATUREDISPLAYINFOEXTRA_RECORDS, Offsets::VAR_CREATUREDISPLAYINFOEXTRA_COUNT, extID); diff --git a/src/player/CanUseItem.cpp b/src/player/CanUseItem.cpp index 7b0df76a..a12f66b2 100644 --- a/src/player/CanUseItem.cpp +++ b/src/player/CanUseItem.cpp @@ -86,10 +86,10 @@ bool RestrictedOut(uint32_t mask, uint32_t index1Based) { // item's class *has* a proficiency concept (mask != 0) and the item's // subclass bit is unset. bool ProficiencyMet(const uint8_t *record) { - const uint32_t itemClass = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_CLASS); - const uint32_t subClass = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_SUBCLASS); + const uint32_t itemClass = Game::Read( + record, Offsets::OFF_ITEMSTATS_CLASS); + const uint32_t subClass = Game::Read( + record, Offsets::OFF_ITEMSTATS_SUBCLASS); if (itemClass > 16) // table is 17 entries (m_class 0..16) return true; auto *table = reinterpret_cast( @@ -105,27 +105,26 @@ bool ProficiencyMet(const uint8_t *record) { // item's SkillLine.dbc row to the player's skill slot; the player must // have the line at an effective rank (current + temp bonus) >= required. bool RequiredSkillMet(const uint8_t *player, const uint8_t *record) { - const uint32_t reqSkill = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_SKILL); + const uint32_t reqSkill = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_SKILL); if (reqSkill == 0) return true; // no skill requirement - const uint32_t reqRank = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_SKILL_RANK); + const uint32_t reqRank = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_SKILL_RANK); auto toSlot = reinterpret_cast(Offsets::FUN_SKILL_LINE_TO_SLOT); const int slot = toSlot(const_cast(player), reqSkill); if (slot < 0) return false; // player doesn't have the skill line at all - auto *sub = *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + auto *sub = Game::Read(player, Offsets::OFF_CGPLAYER_INFO); if (sub == nullptr) return false; const uint8_t *rec = sub + Offsets::OFF_SKILL_INFO_TABLE + slot * Offsets::SKILL_INFO_STRIDE; - uint32_t rank = *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_CUR); + uint32_t rank = Game::Read(rec, Offsets::OFF_SKILL_INFO_CUR); if (rank != 0) // add the temp bonus only when there's a base value - rank += *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_BONUS); + rank += Game::Read(rec, Offsets::OFF_SKILL_INFO_BONUS); return rank >= reqRank; } @@ -138,11 +137,11 @@ bool RequiredSkillMet(const uint8_t *player, const uint8_t *record) { bool PlayerKnowsSpell(int spellID) { if (spellID <= 0) return false; - auto *bitmap = *reinterpret_cast( + auto *bitmap = Game::Read( static_cast(Offsets::VAR_PLAYER_SPELL_BITMAP)); if (bitmap == nullptr) return false; - const int spellCount = *reinterpret_cast( + const int spellCount = Game::Read( static_cast(Offsets::VAR_SPELL_RECORD_COUNT)); if (spellID > spellCount) return false; @@ -163,8 +162,8 @@ bool PlayerKnowsSpell(int spellID) { // specialization/proficiency in practice, so the chain walk is // belt-and-suspenders, but it makes the check exact. bool RequiredSpellMet(const uint8_t *player, const uint8_t *record) { - const int reqSpell = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_SPELL); + const int reqSpell = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_SPELL); if (reqSpell <= 0) return true; // no requirement if (::Spell::Lookup::RecordForID(reqSpell) == nullptr) @@ -180,8 +179,8 @@ bool RequiredSpellMet(const uint8_t *player, const uint8_t *record) { // RequiredHonorRank — the player's PvP honor rank must be >= the item's. // `sub` is the CGPlayer +0xE68 sub-struct (may be null pre-world). bool RequiredHonorRankMet(const uint8_t *sub, const uint8_t *record) { - const uint32_t req = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_HONOR_RANK); + const uint32_t req = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_HONOR_RANK); if (req == 0) return true; if (sub == nullptr) @@ -193,14 +192,14 @@ bool RequiredHonorRankMet(const uint8_t *sub, const uint8_t *record) { // RequiredCityRank — a PvP-medal bitmask gate: the item's rank R passes // when the player has earned bit (R-1) in the medal mask. bool RequiredCityRankMet(const uint8_t *sub, const uint8_t *record) { - const uint32_t req = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_CITY_RANK); + const uint32_t req = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_CITY_RANK); if (req == 0) return true; if (sub == nullptr) return false; - const uint32_t medals = *reinterpret_cast( - sub + Offsets::OFF_CGPLAYER_PVP_MEDALS); + const uint32_t medals = Game::Read( + sub, Offsets::OFF_CGPLAYER_PVP_MEDALS); return (medals & (1u << ((req - 1) & 31))) != 0; } @@ -209,17 +208,17 @@ bool RequiredCityRankMet(const uint8_t *sub, const uint8_t *record) { // indexes the engine's reaction-min threshold table; the player's total // rep with the faction must be >= that threshold. bool RequiredReputationMet(const uint8_t *record) { - const int faction = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_FACTION); + const int faction = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_FACTION); if (faction == 0) return true; - const uint32_t band = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_FACTION_RANK); + const uint32_t band = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_FACTION_RANK); if (band > 7) // reaction-min table is 8 bands (0..7); guard OOB return true; auto getStanding = reinterpret_cast(Offsets::FUN_REPUTATION_GET_STANDING); const int current = getStanding(faction); - const int threshold = *reinterpret_cast( + const int threshold = Game::Read( static_cast(Offsets::VAR_REACTION_MIN_TABLE) + band * 4); return current >= threshold; } @@ -233,29 +232,27 @@ bool ComputeCanUse(int itemID) { auto *player = Unit::Identity::PlayerObject(); if (player == nullptr) return false; // pre-login / no player - auto *desc = *reinterpret_cast( - player + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read(player, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return false; if (!ProficiencyMet(record)) return false; - const int playerLevel = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_LEVEL); - const uint32_t reqLevel = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_REQUIRED_LEVEL); + const int playerLevel = Game::Read(desc, Offsets::OFF_UNIT_FIELD_LEVEL); + const uint32_t reqLevel = Game::Read( + record, Offsets::OFF_ITEMSTATS_REQUIRED_LEVEL); if (static_cast(reqLevel) > playerLevel) return false; - const uint32_t allowClass = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_ALLOWABLE_CLASS); + const uint32_t allowClass = Game::Read( + record, Offsets::OFF_ITEMSTATS_ALLOWABLE_CLASS); const uint32_t playerClass = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE); if (RestrictedOut(allowClass, playerClass)) return false; - const uint32_t allowRace = *reinterpret_cast( - record + Offsets::OFF_ITEMSTATS_ALLOWABLE_RACE); + const uint32_t allowRace = Game::Read( + record, Offsets::OFF_ITEMSTATS_ALLOWABLE_RACE); const uint32_t playerRace = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE); if (RestrictedOut(allowRace, playerRace)) return false; @@ -267,8 +264,7 @@ bool ComputeCanUse(int itemID) { return false; // PvP rank + reputation gates read the CGPlayer +0xE68 sub-struct. - auto *sub = *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + auto *sub = Game::Read(player, Offsets::OFF_CGPLAYER_INFO); if (!RequiredHonorRankMet(sub, record)) return false; if (!RequiredCityRankMet(sub, record)) diff --git a/src/player/InputEvents.cpp b/src/player/InputEvents.cpp index 2f9249a3..27887a96 100644 --- a/src/player/InputEvents.cpp +++ b/src/player/InputEvents.cpp @@ -31,6 +31,7 @@ // the free-look bit is held AND the camera yaw changes; STOPPED // fires on LMB release. +#include "Game.h" #include "Offsets.h" #include "event/Custom.h" #include "tick/WorldTick.h" @@ -67,7 +68,7 @@ bool g_havePrevCameraYaw = false; using ResolveUnitToken_t = void *(__fastcall *)(const char *token); const uint8_t *Controller() { - return *reinterpret_cast(Offsets::VAR_UI_INPUT_CONTROLLER); + return Game::Read(Offsets::VAR_UI_INPUT_CONTROLLER); } const uint8_t *Player() { @@ -76,12 +77,12 @@ const uint8_t *Player() { } const uint8_t *Camera() { - const uint8_t *gameState = *reinterpret_cast( + const uint8_t *gameState = Game::Read( Offsets::VAR_GAME_STATE_PTR); if (gameState == nullptr) return nullptr; - return *reinterpret_cast( - gameState + Offsets::OFF_GAME_STATE_CAMERA_PTR); + return Game::Read( + gameState, Offsets::OFF_GAME_STATE_CAMERA_PTR); } void FireTransition(bool now, bool &prev, const char *startedName, @@ -109,8 +110,7 @@ void OnWorldTick() { return; } - const uint32_t flags = *reinterpret_cast( - ctrl + Offsets::OFF_UI_INPUT_FLAGS); + const uint32_t flags = Game::Read(ctrl, Offsets::OFF_UI_INPUT_FLAGS); const bool freeLookHeld = (flags & Offsets::INPUT_FLAG_FREE_LOOK) != 0; const bool mouselookHeld = (flags & Offsets::INPUT_FLAG_MOUSELOOK) != 0; @@ -133,8 +133,7 @@ void OnWorldTick() { // Once STARTED has fired during a hold, the latch stays on // until the bit clears — so a drag-stop-drag motion within // the same RMB hold doesn't flap STARTED/STOPPED. - const float bodyYaw = *reinterpret_cast( - player + Offsets::OFF_PLAYER_BODY_YAW); + const float bodyYaw = Game::Read(player, Offsets::OFF_PLAYER_BODY_YAW); bool turning; if (!mouselookHeld) { turning = false; @@ -159,8 +158,8 @@ void OnWorldTick() { } else if (camera == nullptr) { looking = false; // can't read camera yaw — bail } else { - const float cameraYaw = *reinterpret_cast( - camera + Offsets::OFF_CAMERA_RELATIVE_YAW); + const float cameraYaw = Game::Read( + camera, Offsets::OFF_CAMERA_RELATIVE_YAW); if (g_wasLooking) { looking = true; } else if (g_havePrevCameraYaw && diff --git a/src/quest/Details.cpp b/src/quest/Details.cpp index 26a6db68..ce6d5c89 100644 --- a/src/quest/Details.cpp +++ b/src/quest/Details.cpp @@ -52,7 +52,7 @@ const char *LookupQuestType(uint32_t row) { if (!record) return nullptr; const int localeIdx = - *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); + Game::Read(Offsets::VAR_LOCALE_INDEX); if (localeIdx < 0 || localeIdx > 8) return nullptr; auto *names = reinterpret_cast(record + 4); diff --git a/src/spell/BonusDamage.cpp b/src/spell/BonusDamage.cpp index fee0f039..807ef2a6 100644 --- a/src/spell/BonusDamage.cpp +++ b/src/spell/BonusDamage.cpp @@ -83,8 +83,8 @@ const uint8_t *PlayerFields() { const uint8_t *player = Unit::Identity::PlayerObject(); if (player == nullptr) return nullptr; - return *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + return Game::Read( + player, Offsets::OFF_CGPLAYER_INFO); } // Net spell damage for a 0-based school (0=physical .. 6=arcane). POS is the @@ -94,10 +94,10 @@ long SpellDamageForSchool(int school0) { const uint8_t *pf = PlayerFields(); if (pf == nullptr) return 0; - const int32_t pos = *reinterpret_cast( - pf + Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_POS + school0 * 4); - const int32_t neg = *reinterpret_cast( - pf + Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + school0 * 4); + const int32_t pos = Game::Read( + pf, Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_POS + school0 * 4); + const int32_t neg = Game::Read( + pf, Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + school0 * 4); return static_cast(pos) - static_cast(neg); } @@ -128,12 +128,12 @@ long ItemFlatHealing(const uint8_t *cgItem) { // Random suffix ("… of Restoration") + applied permanent (slot 0) and // temporary (slot 1) enchants (Healing Power, Mana Oil, …). Item::StatAccum::ApplyRandomSuffix( - acc, *reinterpret_cast( - desc + Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY), +1); + acc, Game::Read( + desc, Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY), +1); for (int slot = 0; slot <= 1; ++slot) Item::StatAccum::ApplyEnchant( - acc, *reinterpret_cast( - desc + Offsets::OFF_DESCRIPTOR_ENCHANTMENT_ID + + acc, Game::Read( + desc, Offsets::OFF_DESCRIPTOR_ENCHANTMENT_ID + slot * Offsets::DESCRIPTOR_ENCHANTMENT_SLOT_STRIDE), +1); } return Item::StatAccum::Value(acc, "ITEM_MOD_SPELL_HEALING_DONE_SHORT"); @@ -165,15 +165,15 @@ void AddSpellHealingAuras(long &total, int spellID, int32_t spirit, if (sp == nullptr) return; if (requirePassive && - !(*reinterpret_cast(sp + Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & + !(Game::Read(sp, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & Offsets::SPELL_ATTR_PASSIVE)) return; - auto aura = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); - auto base = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); - auto dice = reinterpret_cast( - sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); + auto aura = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME); + auto base = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); + auto dice = Game::Ptr( + sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { const long amount = static_cast(base[i]) + static_cast(dice[i]); if (aura[i] == kAuraModHealingDone) @@ -194,21 +194,21 @@ long ComputeHealing() { // Player Spirit / Armor for the aura-175 / aura-199 conversions. const uint8_t *desc = Unit::Identity::PlayerDescriptor(); - const int32_t spirit = desc ? *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_STAT_SPIRIT) : 0; - const int32_t armor = desc ? *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_RESISTANCE_ARMOR) : 0; + const int32_t spirit = desc ? Game::Read( + desc, Offsets::OFF_UNIT_FIELD_STAT_SPIRIT) : 0; + const int32_t armor = desc ? Game::Read( + desc, Offsets::OFF_UNIT_FIELD_RESISTANCE_ARMOR) : 0; // Active buffs — flat healing + Spirit/Armor conversions, one pass. auto *table = reinterpret_cast( static_cast(Offsets::VAR_PLAYER_BUFF_TABLE)); for (int i = 0; i < Offsets::PLAYER_BUFF_TABLE_COUNT; ++i) { const uint8_t *entry = table + i * Offsets::PLAYER_BUFF_ENTRY_STRIDE; - if (*reinterpret_cast( - entry + Offsets::OFF_PLAYER_BUFF_SLOT_CODE) < 0) + if (Game::Read( + entry, Offsets::OFF_PLAYER_BUFF_SLOT_CODE) < 0) continue; - AddSpellHealingAuras(total, *reinterpret_cast( - entry + Offsets::OFF_PLAYER_BUFF_SPELL_ID), + AddSpellHealingAuras(total, Game::Read( + entry, Offsets::OFF_PLAYER_BUFF_SPELL_ID), spirit, armor, /*requirePassive=*/false); } @@ -216,9 +216,9 @@ long ComputeHealing() { // and any passive flat healing, via the known-spell bitmap (bounded by // spellCount). The passive gate assumes ranks supersede (only the learned // rank is known), so no per-rank dedup is needed. - auto *bitmap = *reinterpret_cast( + auto *bitmap = Game::Read( static_cast(Offsets::VAR_PLAYER_SPELL_BITMAP)); - const int spellCount = *reinterpret_cast( + const int spellCount = Game::Read( static_cast(Offsets::VAR_SPELL_RECORD_COUNT)); if (bitmap != nullptr && spellCount > 0) { for (int id = 1; id <= spellCount; ++id) diff --git a/src/spell/Cast.cpp b/src/spell/Cast.cpp index 23e1e77c..29754736 100644 --- a/src/spell/Cast.cpp +++ b/src/spell/Cast.cpp @@ -170,8 +170,8 @@ bool MovementInterruptible(int spellID) { const uint8_t *rec = Spell::Lookup::RecordForID(spellID); if (rec == nullptr) return true; - return (*reinterpret_cast( - rec + Offsets::OFF_SPELL_RECORD_INTERRUPT_FLAGS) & + return (Game::Read( + rec, Offsets::OFF_SPELL_RECORD_INTERRUPT_FLAGS) & Offsets::SPELL_INTERRUPT_FLAG_MOVEMENT) != 0; } @@ -190,11 +190,11 @@ bool PlayerMoving() { const uint8_t *player = Unit::Identity::PlayerObject(); if (player == nullptr) return false; - const uint8_t *move = *reinterpret_cast( - player + Offsets::OFF_UNIT_MOVEMENT_INFO_PTR); + const uint8_t *move = Game::Read( + player, Offsets::OFF_UNIT_MOVEMENT_INFO_PTR); if (move == nullptr) return false; - return (*reinterpret_cast(move + Offsets::OFF_MOVEMENT_FLAGS) & + return (Game::Read(move, Offsets::OFF_MOVEMENT_FLAGS) & Offsets::MOVEFLAG_MASK_CAST_DROP) != 0; } @@ -244,9 +244,9 @@ int CastTimeMs(int spellID) { const uint8_t *rec = Spell::Lookup::RecordForID(spellID); if (rec != nullptr) { const uint32_t attr = - *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES); + Game::Read(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES); const uint32_t attrEx2 = - *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2); + Game::Read(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2); if ((attr & SPELL_ATTR_RANGED) && !(attrEx2 & Offsets::SPELL_ATTR_EX2_AUTOREPEAT_FLAG)) ms += 500; } @@ -267,12 +267,12 @@ int ChannelDurationMs(int spellID) { } const char *SpellName(const uint8_t *rec) { - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); - return *reinterpret_cast(rec + Offsets::OFF_SPELL_NAMES + locale * 4); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); + return Game::Read(rec, Offsets::OFF_SPELL_NAMES + locale * 4); } bool IsTradeskill(const uint8_t *rec) { - return (*reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & + return (Game::Read(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & SPELL_ATTR_TRADESPELL) != 0; } @@ -280,13 +280,13 @@ bool IsTradeskill(const uint8_t *rec) { // already stores the full "Interface\Icons\..." path (unlike item icons, // which are bare filenames) — so it's used verbatim, no prefix. const char *SpellIconPath(const uint8_t *rec) { - const int iconID = *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ICON_ID); + const int iconID = Game::Read(rec, Offsets::OFF_SPELL_RECORD_ICON_ID); const uint8_t *iconRec = DBC::Record(Offsets::VAR_SPELL_ICON_RECORDS, Offsets::VAR_SPELL_ICON_COUNT, static_cast(iconID)); if (iconRec == nullptr) return ""; - const char *path = *reinterpret_cast(iconRec + Offsets::OFF_SPELLICON_PATH); + const char *path = Game::Read(iconRec, Offsets::OFF_SPELLICON_PATH); return (path != nullptr) ? path : ""; } @@ -400,7 +400,7 @@ const Game::HookAutoRegister _castStartHook{ // times to `UnitChannelInfo` (validated against the live +0x228 field). bool IsChannelSpell(const uint8_t *rec) { - return (*reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) & + return (Game::Read(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) & Offsets::SPELL_ATTR_EX_CHANNELED) != 0; } @@ -702,8 +702,7 @@ ClearCastingSpell_t g_origClearCastingSpell = nullptr; void __fastcall ClearCastingSpell_h(void *unit, void *edx, int spellID, char notify, char cleanup) { if (unit != nullptr && spellID != 0) { - const int current = *reinterpret_cast( - static_cast(unit) + Offsets::OFF_UNIT_CAST_SPELL); + const int current = Game::Read(unit, Offsets::OFF_UNIT_CAST_SPELL); if (current != 0 && current == spellID) HandleCastAborted(Unit::Identity::GuidForObject(unit), spellID); } @@ -753,7 +752,7 @@ void OnWorldTick() { // so they're exempt — they expire on their computed endMs (self-expiry in // PushCastInfo). if (g_cast.spellID != 0 && !g_castFromServer && - *reinterpret_cast(Offsets::VAR_CURRENT_CAST_SPELL) == 0) + Game::Read(Offsets::VAR_CURRENT_CAST_SPELL) == 0) g_cast.spellID = 0; // End a move-dropped cast (issue #23): the engine cleared its cast-state on @@ -783,9 +782,9 @@ void OnWorldTick() { // SENT castGUID); on cancel it simply stays cleared. Gated on // !g_castFromServer so it can never touch that server re-stamp. if (g_cast.spellID != 0 && !g_castFromServer && - *reinterpret_cast(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0 && + Game::Read(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0 && g_cast.spellID == - *reinterpret_cast(Offsets::VAR_PENDING_CAST_SPELL)) + Game::Read(Offsets::VAR_PENDING_CAST_SPELL)) g_cast.spellID = 0; // Detect a player CHANNEL that ended before its computed endMs — the @@ -806,8 +805,8 @@ void OnWorldTick() { if (g_channel.spellID != 0) { const uint8_t *desc = Unit::Identity::PlayerDescriptor(); if (desc != nullptr) { - const int chan = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL); + const int chan = Game::Read( + desc, Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL); if (chan == g_channel.spellID) g_channelConfirmed = true; else if (chan == 0 && g_channelConfirmed) @@ -894,14 +893,14 @@ static int __fastcall Script_UnitChannelInfo(void *L) { if (u == Resolve("player")) return PushChannelInfo(L, g_channel.spellID, g_channel.startMs, g_channel.endMs, true); - auto *desc = *reinterpret_cast( - static_cast(u) + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read( + u, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return 0; // The live +0x228 field is authoritative for "is this unit channeling // right now"; the SMSG_SPELL_START cache adds real start/end times when // we observed the channel begin (and still matches the current spell). - const int spellID = *reinterpret_cast(desc + Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL); + const int spellID = Game::Read(desc, Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL); if (spellID == 0) return 0; const RemoteCast *rc = FindRemoteCast(Unit::Identity::GuidForObject(u)); diff --git a/src/spell/CastByID.cpp b/src/spell/CastByID.cpp index 4465590e..36cdb24d 100644 --- a/src/spell/CastByID.cpp +++ b/src/spell/CastByID.cpp @@ -44,9 +44,9 @@ static const char *LocaleNameForID(int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return nullptr; - const int locale = *reinterpret_cast( + const int locale = Game::Read( static_cast(Offsets::VAR_LOCALE_INDEX)); - return *reinterpret_cast(record + Offsets::OFF_SPELL_NAMES + locale * 4); + return Game::Read(record, Offsets::OFF_SPELL_NAMES + locale * 4); } // Hook on the single name → spellbook-slot resolver diff --git a/src/spell/CastEvents.cpp b/src/spell/CastEvents.cpp index 48e8761a..b1f4fae5 100644 --- a/src/spell/CastEvents.cpp +++ b/src/spell/CastEvents.cpp @@ -67,8 +67,8 @@ constexpr uint32_t kAutoShotSpellId = 75; constexpr uint16_t kTargetFlagUnit = 0x0002; const char *LocalizedField(const uint8_t *rec, int fieldOffset) { - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); - return *reinterpret_cast(rec + fieldOffset + locale * 4); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); + return Game::Read(rec, fieldOffset + locale * 4); } // Cast UID for a REAL (Type-3) cast — player and remote alike. Per the retail @@ -269,7 +269,7 @@ constexpr int kChanSuccDeferMs = 500; bool IsChanneledSpell(int spellID) { const uint8_t *rec = Spell::Lookup::RecordForID(spellID); return rec != nullptr && - (*reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) & + (Game::Read(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) & Offsets::SPELL_ATTR_EX_CHANNELED) != 0; } @@ -552,14 +552,14 @@ void OnPlayerSucceeded(int spellID) { void PollReticle() { const bool active = - *reinterpret_cast(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0; + Game::Read(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0; if (active) { if (s_reticleSpell == 0) { // Reticle just came up — report the pending spell. Read the spellID // now (it's set by Spell_C_CastSpell before targeting begins); if // it's transiently 0 this frame, retry next tick. const int spellID = - *reinterpret_cast(Offsets::VAR_PENDING_CAST_SPELL); + Game::Read(Offsets::VAR_PENDING_CAST_SPELL); if (spellID != 0) { s_reticleSpell = spellID; s_reticlePlaced = false; diff --git a/src/spell/CastNoToggle.cpp b/src/spell/CastNoToggle.cpp index 8fe998ea..e2625fc5 100644 --- a/src/spell/CastNoToggle.cpp +++ b/src/spell/CastNoToggle.cpp @@ -66,7 +66,7 @@ const CastSpellByName_t Script_CastSpellByName_Engine = reinterpret_cast(Offsets::FUN_SCRIPT_CAST_SPELL_BY_NAME); int ReadActiveSpellID() { - return *reinterpret_cast( + return Game::Read( static_cast(Offsets::VAR_ACTIVE_AUTO_REPEAT_SPELL)); } @@ -74,9 +74,9 @@ const char *LocaleName(int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return nullptr; - const int locale = *reinterpret_cast( + const int locale = Game::Read( static_cast(Offsets::VAR_LOCALE_INDEX)); - return *reinterpret_cast(record + Offsets::OFF_SPELL_NAMES + locale * 4); + return Game::Read(record, Offsets::OFF_SPELL_NAMES + locale * 4); } // Case-insensitive name match for the auto-repeat-name gate. Walks diff --git a/src/spell/Info.cpp b/src/spell/Info.cpp index bae00e39..6f089a93 100644 --- a/src/spell/Info.cpp +++ b/src/spell/Info.cpp @@ -129,26 +129,26 @@ static bool ReadSpellInfo(int spellID, SpellInfoData &out) { const int locale = ReadGlobal(Offsets::VAR_LOCALE_INDEX); out.spellID = spellID; - out.name = *reinterpret_cast(record + Offsets::OFF_SPELL_NAMES + locale * 4); - out.rank = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_RANK + locale * 4); + out.name = Game::Read(record, Offsets::OFF_SPELL_NAMES + locale * 4); + out.rank = Game::Read(record, Offsets::OFF_SPELL_RECORD_RANK + locale * 4); out.iconPath = nullptr; - const int iconID = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_ICON_ID); + const int iconID = Game::Read(record, Offsets::OFF_SPELL_RECORD_ICON_ID); if (auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS, Offsets::VAR_SPELL_ICON_COUNT, iconID)) { - out.iconPath = *reinterpret_cast(iconRec + Offsets::OFF_SPELLICON_PATH); + out.iconPath = Game::Read(iconRec, Offsets::OFF_SPELLICON_PATH); } - out.cost = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_MANA_COST); + out.cost = Game::Read(record, Offsets::OFF_SPELL_RECORD_MANA_COST); - const uint32_t attrEx2 = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2); + const uint32_t attrEx2 = Game::Read( + record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2); out.isFunnel = (attrEx2 & SPELL_ATTR_EX2_HEALTH_FUNNEL) != 0; - out.powerType = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_POWER_TYPE); + out.powerType = Game::Read(record, Offsets::OFF_SPELL_RECORD_POWER_TYPE); out.castTimeMs = 0; - const int castIndex = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_CASTING_TIME_INDEX); + const int castIndex = Game::Read(record, Offsets::OFF_SPELL_RECORD_CASTING_TIME_INDEX); if (auto *castRec = LookupSubRecord(Offsets::VAR_SPELL_CAST_TIMES_RECORDS, Offsets::VAR_SPELL_CAST_TIMES_COUNT, castIndex)) { out.castTimeMs = *reinterpret_cast(castRec + 4); @@ -156,7 +156,7 @@ static bool ReadSpellInfo(int spellID, SpellInfoData &out) { out.minRange = 0.0f; out.maxRange = 0.0f; - const int rangeIndex = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_RANGE_INDEX); + const int rangeIndex = Game::Read(record, Offsets::OFF_SPELL_RECORD_RANGE_INDEX); if (auto *rangeRec = LookupSubRecord(Offsets::VAR_SPELL_RANGE_RECORDS, Offsets::VAR_SPELL_RANGE_COUNT, rangeIndex)) { out.minRange = *reinterpret_cast(rangeRec + 4); @@ -276,7 +276,7 @@ static int __fastcall Script_C_GetSpellName(void *L) { return 0; // nil for unknown spellID const int locale = ReadGlobal(Offsets::VAR_LOCALE_INDEX); - const char *name = *reinterpret_cast(record + Offsets::OFF_SPELL_NAMES + locale * 4); + const char *name = Game::Read(record, Offsets::OFF_SPELL_NAMES + locale * 4); if (name == nullptr || *name == '\0') return 0; // empty / no name in current locale → nil Game::Lua::PushString(L, name); @@ -289,12 +289,12 @@ static int __fastcall Script_C_GetSpellTexture(void *L) { if (record == nullptr) return 0; - const int iconID = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_ICON_ID); + const int iconID = Game::Read(record, Offsets::OFF_SPELL_RECORD_ICON_ID); auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS, Offsets::VAR_SPELL_ICON_COUNT, iconID); if (iconRec == nullptr) return 0; - const char *path = *reinterpret_cast(iconRec + Offsets::OFF_SPELLICON_PATH); + const char *path = Game::Read(iconRec, Offsets::OFF_SPELLICON_PATH); if (path == nullptr || *path == '\0') return 0; Game::Lua::PushString(L, path); @@ -315,7 +315,7 @@ static bool BuildSpellLink(int spellID, char *out, size_t outLen) { if (record == nullptr) return false; const int locale = ReadGlobal(Offsets::VAR_LOCALE_INDEX); - const char *name = *reinterpret_cast(record + Offsets::OFF_SPELL_NAMES + locale * 4); + const char *name = Game::Read(record, Offsets::OFF_SPELL_NAMES + locale * 4); if (name == nullptr || *name == '\0') return false; const int n = std::snprintf(out, outLen, "|cff71d5ff|Hspell:%d:0|h[%s]|h|r", @@ -392,8 +392,8 @@ static int PushIsPassive(void *L, int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return 0; - const uint32_t attr = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES); + const uint32_t attr = Game::Read( + record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES); Game::Lua::PushBool(L, (attr & Offsets::SPELL_ATTR_PASSIVE) != 0); return 1; } @@ -438,11 +438,11 @@ static int __fastcall Script_C_IsSpellPassive(void *L) { static bool PlayerKnowsSpell(int spellID) { if (spellID < 1) return false; - const int spellCount = *reinterpret_cast( + const int spellCount = Game::Read( static_cast(Offsets::VAR_SPELL_RECORD_COUNT)); if (spellID > spellCount) return false; - auto *bitmap = *reinterpret_cast( + auto *bitmap = Game::Read( static_cast(Offsets::VAR_PLAYER_SPELL_BITMAP)); if (bitmap == nullptr) return false; @@ -522,10 +522,10 @@ template static bool AnyEffectTarget(const uint8_t *record, Pred pred) { if (record == nullptr) return false; - auto *targetsA = reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A); - auto *targetsB = reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_B); + auto *targetsA = Game::Ptr( + record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A); + auto *targetsB = Game::Ptr( + record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_B); for (int i = 0; i < 3; ++i) { if (pred(targetsA[i]) || pred(targetsB[i])) return true; @@ -661,8 +661,8 @@ static int __fastcall Script_C_SpellBook_GetSpellBookItemInfo(void *L) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); const uint32_t attr = - record ? *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES) + record ? Game::Read( + record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) : 0u; Game::Lua::NewTable(L); diff --git a/src/spell/Level.cpp b/src/spell/Level.cpp index d36b9dcd..2edb197f 100644 --- a/src/spell/Level.cpp +++ b/src/spell/Level.cpp @@ -33,8 +33,8 @@ const uint8_t *PlayerDescriptor() { auto *player = static_cast(fn("player")); if (player == nullptr) return nullptr; - return *reinterpret_cast( - player + Offsets::OFF_UNIT_DESCRIPTOR); + return Game::Read( + player, Offsets::OFF_UNIT_DESCRIPTOR); } // Builds (or returns the cached) set of every spellID that appears @@ -51,9 +51,9 @@ std::unordered_set &TalentSpellSet() { static std::unordered_set set; if (!set.empty()) return set; - const uint8_t *const *records = *reinterpret_cast( + const uint8_t *const *records = Game::Read( static_cast(Offsets::VAR_TALENT_DBC_RECORDS)); - const int count = *reinterpret_cast( + const int count = Game::Read( static_cast(Offsets::VAR_TALENT_DBC_COUNT)); if (records == nullptr || count <= 0) return set; @@ -63,8 +63,8 @@ std::unordered_set &TalentSpellSet() { const uint8_t *rec = records[i]; if (rec == nullptr) continue; - auto *ranks = reinterpret_cast( - rec + Offsets::OFF_TALENT_SPELL_RANK); + auto *ranks = Game::Ptr( + rec, Offsets::OFF_TALENT_SPELL_RANK); for (int j = 0; j < 9; ++j) { const uint32_t spellID = ranks[j]; if (spellID != 0) @@ -80,8 +80,8 @@ int SpellBaseLevel(int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return 0; - return *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_BASE_LEVEL); + return Game::Read( + record, Offsets::OFF_SPELL_RECORD_BASE_LEVEL); } // Spell.dbc attribute filter for the learnable-spell walk. Only the @@ -110,8 +110,8 @@ bool SpellHiddenFromSpellbook(int spellID) { const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return false; - const uint32_t attributes = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES); + const uint32_t attributes = Game::Read( + record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES); return (attributes & SPELL_ATTR_HIDDEN_CLIENTSIDE) != 0; } @@ -134,7 +134,7 @@ constexpr uint32_t SPELL_EFFECT_APPLY_AURA = 6; constexpr uint32_t SPELL_EFFECT_APPLY_AREA_AURA_PARTY = 35; int LocaleIndex() { - return *reinterpret_cast( + return Game::Read( static_cast(Offsets::VAR_LOCALE_INDEX)); } @@ -169,8 +169,8 @@ bool IsPositiveRankTarget(uint32_t t) { // single-rank buffs (Power Infusion / Innervate / Blessing of Kings, all // empty Rank and un-gated) vs ranked ones (Divine Spirit / Fortitude). bool HasRankString(const uint8_t *record) { - const char *rank = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_RANK + LocaleIndex() * 4); + const char *rank = Game::Read( + record, Offsets::OFF_SPELL_RECORD_RANK + LocaleIndex() * 4); return rank != nullptr && *rank != '\0'; } @@ -178,19 +178,19 @@ bool HasRankString(const uint8_t *record) { // the spell isn't subject to the ranked-positive-aura target-level rule. int RequiredTargetLevel(const uint8_t *record) { const int spellLevel = - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_SPELL_LEVEL); + Game::Read(record, Offsets::OFF_SPELL_RECORD_SPELL_LEVEL); if (spellLevel <= 10) // targetLevel + 10 >= spellLevel holds for any level return 0; const uint32_t attr = - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES); + Game::Read(record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES); if (attr & Offsets::SPELL_ATTR_PASSIVE) return 0; if (!HasRankString(record)) // single-rank spell → not gated return 0; - auto *effect = reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_EFFECT); + auto *effect = Game::Ptr(record, Offsets::OFF_SPELL_RECORD_EFFECT); auto *targetA = - reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A); + Game::Ptr(record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A); bool positiveAura = false; for (int i = 0; i < 3; ++i) { if ((effect[i] == SPELL_EFFECT_APPLY_AURA && @@ -221,13 +221,13 @@ int __fastcall Script_GetSpellLevelInfo(void *L) { return 0; Game::Lua::PushNumber( L, static_cast( - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_SPELL_LEVEL))); + Game::Read(record, Offsets::OFF_SPELL_RECORD_SPELL_LEVEL))); Game::Lua::PushNumber( L, static_cast( - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_BASE_LEVEL))); + Game::Read(record, Offsets::OFF_SPELL_RECORD_BASE_LEVEL))); Game::Lua::PushNumber( L, static_cast( - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_MAX_LEVEL))); + Game::Read(record, Offsets::OFF_SPELL_RECORD_MAX_LEVEL))); return 3; } @@ -308,8 +308,8 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) { const uint8_t classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE); const uint8_t raceByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE); - const int32_t playerLevel = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_LEVEL); + const int32_t playerLevel = Game::Read( + desc, Offsets::OFF_UNIT_FIELD_LEVEL); if (classByte == 0 || raceByte == 0 || playerLevel <= 0) return 1; @@ -337,9 +337,9 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) { (1u << 0) | (1u << 1) | (1u << 2) | (1u << 3) | (1u << 4) | (1u << 6) | (1u << 7) | (1u << 8) | (1u << 10); - const uint8_t *const *records = *reinterpret_cast( + const uint8_t *const *records = Game::Read( static_cast(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS)); - const int count = *reinterpret_cast( + const int count = Game::Read( static_cast(Offsets::VAR_SKILL_LINE_ABILITY_COUNT)); if (records == nullptr || count <= 0) return 1; @@ -357,14 +357,14 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) { if (rec == nullptr) continue; - const uint32_t recClassMask = *reinterpret_cast( - rec + Offsets::OFF_SLA_CLASS_MASK); - const uint32_t recRaceMask = *reinterpret_cast( - rec + Offsets::OFF_SLA_RACE_MASK); - const uint32_t recExcludeClass = *reinterpret_cast( - rec + Offsets::OFF_SLA_EXCLUDE_CLASS); - const uint32_t recExcludeRace = *reinterpret_cast( - rec + Offsets::OFF_SLA_EXCLUDE_RACE); + const uint32_t recClassMask = Game::Read( + rec, Offsets::OFF_SLA_CLASS_MASK); + const uint32_t recRaceMask = Game::Read( + rec, Offsets::OFF_SLA_RACE_MASK); + const uint32_t recExcludeClass = Game::Read( + rec, Offsets::OFF_SLA_EXCLUDE_CLASS); + const uint32_t recExcludeRace = Game::Read( + rec, Offsets::OFF_SLA_EXCLUDE_RACE); // Skip if explicitly excluded. if ((recExcludeClass & playerClassBit) != 0) @@ -406,8 +406,8 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) { if (!isClassSpell && !isRacial) continue; - const int spellID = *reinterpret_cast( - rec + Offsets::OFF_SLA_SPELL_ID); + const int spellID = Game::Read( + rec, Offsets::OFF_SLA_SPELL_ID); if (spellID <= 0) continue; if (SpellBaseLevel(spellID) != queryLevel) diff --git a/src/spell/Mechanic.cpp b/src/spell/Mechanic.cpp index 04bfbc33..4e589b79 100644 --- a/src/spell/Mechanic.cpp +++ b/src/spell/Mechanic.cpp @@ -53,7 +53,7 @@ static const char *MechanicName(uint32_t mechanicID) { Offsets::VAR_SPELLMECHANIC_COUNT, mechanicID); if (rec == nullptr) return nullptr; - auto names = reinterpret_cast(rec + Offsets::OFF_SPELLMECHANIC_NAME); + auto names = Game::Ptr(rec, Offsets::OFF_SPELLMECHANIC_NAME); const char *s = names[0]; // enUS return (s != nullptr && s[0] != '\0') ? s : nullptr; } @@ -65,7 +65,7 @@ static int __fastcall Script_GetSpellMechanicByID(void *L) { return 0; // nil for invalid / out-of-range spell IDs const uint32_t mechanicID = - *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_MECHANIC); + Game::Read(record, Offsets::OFF_SPELL_RECORD_MECHANIC); Game::Lua::PushNumber(L, static_cast(mechanicID)); diff --git a/src/spell/Mod.cpp b/src/spell/Mod.cpp index 3ae2d58a..5c04e7f6 100644 --- a/src/spell/Mod.cpp +++ b/src/spell/Mod.cpp @@ -32,7 +32,7 @@ uint32_t PlayerSpellFamily() { auto *unit = static_cast(resolve("player")); if (unit == nullptr) return 0; - auto *desc = *reinterpret_cast(unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return 0; const uint8_t classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE); @@ -40,7 +40,7 @@ uint32_t PlayerSpellFamily() { Offsets::VAR_CHRCLASSES_COUNT, classByte); if (cls == nullptr) return 0; - return *reinterpret_cast(cls + Offsets::OFF_CHRCLASSES_SPELL_FAMILY); + return Game::Read(cls, Offsets::OFF_CHRCLASSES_SPELL_FAMILY); } } // namespace @@ -49,18 +49,18 @@ float Apply(const uint8_t *spellRecord, int op, float base) { if (spellRecord == nullptr) return base; - const uint32_t familyName = *reinterpret_cast( - spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_NAME); - const uint32_t attrEx3 = *reinterpret_cast( - spellRecord + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3); + const uint32_t familyName = Game::Read( + spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_NAME); + const uint32_t attrEx3 = Game::Read( + spellRecord, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3); if (familyName == 0 || (attrEx3 & Offsets::SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS) != 0) return base; if (familyName != PlayerSpellFamily()) return base; - const uint64_t familyFlags = *reinterpret_cast( - spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS); + const uint64_t familyFlags = Game::Read( + spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS); if (familyFlags == 0) return base; diff --git a/src/spell/PowerCost.cpp b/src/spell/PowerCost.cpp index d7902325..807cdaf4 100644 --- a/src/spell/PowerCost.cpp +++ b/src/spell/PowerCost.cpp @@ -64,8 +64,8 @@ int __fastcall Script_GetSpellPowerCost(void *L) { if (cost == 0xFFFFFFFF) return 0; // engine error (no player context, etc.) - const int powerType = *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_POWER_TYPE); - const int costPercent = *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_MANA_COST_PERCENT); + const int powerType = Game::Read(rec, Offsets::OFF_SPELL_RECORD_POWER_TYPE); + const int costPercent = Game::Read(rec, Offsets::OFF_SPELL_RECORD_MANA_COST_PERCENT); if (cost == 0 && costPercent == 0) return 0; // nil — no resource cost diff --git a/src/spell/Radius.cpp b/src/spell/Radius.cpp index 549e5743..67cdb5e9 100644 --- a/src/spell/Radius.cpp +++ b/src/spell/Radius.cpp @@ -61,14 +61,14 @@ namespace Spell::Radius { static float MaxBaseRadius(const uint8_t *record) { float best = -1.0f; for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { - const int radiusIndex = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_EFFECT_RADIUS_INDEX + i * 4); + const int radiusIndex = Game::Read( + record, Offsets::OFF_SPELL_RECORD_EFFECT_RADIUS_INDEX + i * 4); const uint8_t *rad = DBC::Record(Offsets::VAR_SPELL_RADIUS_RECORDS, Offsets::VAR_SPELL_RADIUS_COUNT, static_cast(radiusIndex)); if (rad == nullptr) continue; - const float r = *reinterpret_cast(rad + Offsets::OFF_SPELL_RADIUS_VALUE); + const float r = Game::Read(rad, Offsets::OFF_SPELL_RADIUS_VALUE); if (r > best) best = r; } diff --git a/src/spell/Range.cpp b/src/spell/Range.cpp index 729ee6d8..465b2166 100644 --- a/src/spell/Range.cpp +++ b/src/spell/Range.cpp @@ -13,6 +13,7 @@ #include "Range.h" +#include "Game.h" #include "Offsets.h" #include "dbc/Lookup.h" #include "unit/Position.h" @@ -41,7 +42,7 @@ bool SpellIDHasRange(int spellID) { if (rec == nullptr) return false; const uint32_t rangeIdx = - *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_RANGE_INDEX); + Game::Read(rec, Offsets::OFF_SPELL_RECORD_RANGE_INDEX); if (rangeIdx == 0) return false; const uint8_t *rangeRec = DBC::Record(Offsets::VAR_SPELL_RANGE_RECORDS, diff --git a/src/spell/SkillLine.cpp b/src/spell/SkillLine.cpp index 529a85f0..13e04bea 100644 --- a/src/spell/SkillLine.cpp +++ b/src/spell/SkillLine.cpp @@ -35,8 +35,8 @@ void ReadPlayerClassRace(uint8_t *outClassByte, uint8_t *outRaceByte) { auto *player = static_cast(fn("player")); if (player == nullptr) return; - auto *desc = *reinterpret_cast( - player + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read( + player, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return; *outClassByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE); @@ -56,9 +56,9 @@ uint32_t FindSkillIDForSpell(int spellID) { if (spellID <= 0) return 0; - auto *const *records = *reinterpret_cast( + auto *const *records = Game::Read( static_cast(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS)); - const int count = *reinterpret_cast( + const int count = Game::Read( static_cast(Offsets::VAR_SKILL_LINE_ABILITY_COUNT)); if (records == nullptr || count <= 0) return 0; @@ -75,13 +75,13 @@ uint32_t FindSkillIDForSpell(int spellID) { const uint8_t *rec = records[i]; if (rec == nullptr) continue; - const int rowSpell = *reinterpret_cast( - rec + Offsets::OFF_SLA_SPELL_ID); + const int rowSpell = Game::Read( + rec, Offsets::OFF_SLA_SPELL_ID); if (rowSpell != spellID) continue; - const uint32_t skill = *reinterpret_cast( - rec + Offsets::OFF_SLA_SKILL_ID); + const uint32_t skill = Game::Read( + rec, Offsets::OFF_SLA_SKILL_ID); if (skill == 0) continue; if (fallback == 0) @@ -92,14 +92,14 @@ uint32_t FindSkillIDForSpell(int spellID) { if (playerClassBit == 0) return skill; - const uint32_t classMask = *reinterpret_cast( - rec + Offsets::OFF_SLA_CLASS_MASK); - const uint32_t raceMask = *reinterpret_cast( - rec + Offsets::OFF_SLA_RACE_MASK); - const uint32_t excludeClass = *reinterpret_cast( - rec + Offsets::OFF_SLA_EXCLUDE_CLASS); - const uint32_t excludeRace = *reinterpret_cast( - rec + Offsets::OFF_SLA_EXCLUDE_RACE); + const uint32_t classMask = Game::Read( + rec, Offsets::OFF_SLA_CLASS_MASK); + const uint32_t raceMask = Game::Read( + rec, Offsets::OFF_SLA_RACE_MASK); + const uint32_t excludeClass = Game::Read( + rec, Offsets::OFF_SLA_EXCLUDE_CLASS); + const uint32_t excludeRace = Game::Read( + rec, Offsets::OFF_SLA_EXCLUDE_RACE); if ((excludeClass & playerClassBit) != 0) continue; if ((excludeRace & playerRaceBit) != 0) @@ -246,8 +246,8 @@ int __fastcall Script_GetSkillLineRank(void *L) { return 1; } - auto *sub = *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + auto *sub = Game::Read( + player, Offsets::OFF_CGPLAYER_INFO); if (sub == nullptr) { Game::Lua::PushNil(L); return 1; @@ -256,11 +256,11 @@ int __fastcall Script_GetSkillLineRank(void *L) { const uint8_t *rec = sub + Offsets::OFF_SKILL_INFO_TABLE + slot * Offsets::SKILL_INFO_STRIDE; const uint32_t cur = - *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_CUR); + Game::Read(rec, Offsets::OFF_SKILL_INFO_CUR); const uint32_t max = - *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_MAX); + Game::Read(rec, Offsets::OFF_SKILL_INFO_MAX); const uint32_t modifier = - *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_BONUS); + Game::Read(rec, Offsets::OFF_SKILL_INFO_BONUS); Game::Lua::PushNumber(L, static_cast(cur)); Game::Lua::PushNumber(L, static_cast(max)); diff --git a/src/spell/Tooltip.cpp b/src/spell/Tooltip.cpp index ac537ed5..b159f671 100644 --- a/src/spell/Tooltip.cpp +++ b/src/spell/Tooltip.cpp @@ -75,30 +75,30 @@ void AppendByID(void *L, int spellID) { return; auto *tt = static_cast(tooltipObj); - const int before = *reinterpret_cast( - tt + Offsets::OFF_GAMETOOLTIP_NUM_LINES); + const int before = Game::Read( + tt, Offsets::OFF_GAMETOOLTIP_NUM_LINES); auto BuildSpellTooltip = reinterpret_cast(Offsets::FUN_GAMETOOLTIP_BUILD_SPELL_TOOLTIP); BuildSpellTooltip(tooltipObj, spellID, 0, 0, 0, 0, 0, /*param_7 (append)=*/1); - const int after = *reinterpret_cast( - tt + Offsets::OFF_GAMETOOLTIP_NUM_LINES); + const int after = Game::Read( + tt, Offsets::OFF_GAMETOOLTIP_NUM_LINES); if (after <= before) return; // nothing appended (bad spellID / missing Spell.dbc record) const uint8_t *record = Spell::Lookup::RecordForID(spellID); if (record == nullptr) return; - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); - const char *name = *reinterpret_cast( - record + Offsets::OFF_SPELL_NAMES + locale * 4); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); + const char *name = Game::Read( + record, Offsets::OFF_SPELL_NAMES + locale * 4); if (name == nullptr || name[0] == '\0') return; // Left-text FontString array: descriptor at +0x324, data ptr at +0x8. - auto **textLeft = *reinterpret_cast( - tt + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8); + auto **textLeft = Game::Read( + tt, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8); if (textLeft == nullptr) return; void *fs = textLeft[before]; @@ -141,8 +141,8 @@ static int __fastcall Script_GameTooltipGetSpell(void *L) { if (tooltipObj == nullptr) return 0; - const int spellID = *reinterpret_cast( - static_cast(tooltipObj) + Offsets::OFF_TOOLTIP_SPELL_ID); + const int spellID = Game::Read( + tooltipObj, Offsets::OFF_TOOLTIP_SPELL_ID); if (spellID <= 0) return 0; @@ -150,11 +150,11 @@ static int __fastcall Script_GameTooltipGetSpell(void *L) { if (record == nullptr) return 0; - const int locale = *reinterpret_cast(Offsets::VAR_LOCALE_INDEX); - const char *name = *reinterpret_cast( - record + Offsets::OFF_SPELL_NAMES + locale * 4); - const char *rank = *reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_RANK + locale * 4); + const int locale = Game::Read(Offsets::VAR_LOCALE_INDEX); + const char *name = Game::Read( + record, Offsets::OFF_SPELL_NAMES + locale * 4); + const char *rank = Game::Read( + record, Offsets::OFF_SPELL_RECORD_RANK + locale * 4); if (name == nullptr) return 0; @@ -181,8 +181,8 @@ static int __fastcall Script_GameTooltipHasSpell(void *L) { Game::Lua::PushBool(L, 0); return 1; } - const int spellID = *reinterpret_cast( - static_cast(tooltipObj) + Offsets::OFF_TOOLTIP_SPELL_ID); + const int spellID = Game::Read( + tooltipObj, Offsets::OFF_TOOLTIP_SPELL_ID); Game::Lua::PushBool(L, spellID > 0); return 1; } diff --git a/src/spell/Usable.cpp b/src/spell/Usable.cpp index 21f4d052..5e79dfbc 100644 --- a/src/spell/Usable.cpp +++ b/src/spell/Usable.cpp @@ -40,11 +40,11 @@ using GetSpellCost_t = uint32_t(__fastcall *)(int spellID, int unit); bool PlayerKnowsSpell(int spellID) { if (spellID <= 0) return false; - auto *bitmap = *reinterpret_cast( + auto *bitmap = Game::Read( static_cast(Offsets::VAR_PLAYER_SPELL_BITMAP)); if (bitmap == nullptr) return false; - const int spellCount = *reinterpret_cast( + const int spellCount = Game::Read( static_cast(Offsets::VAR_SPELL_RECORD_COUNT)); if (spellID > spellCount) return false; @@ -56,8 +56,8 @@ const uint8_t *PlayerDescriptor() { auto *player = static_cast(resolve("player")); if (player == nullptr) return nullptr; - return *reinterpret_cast( - player + Offsets::OFF_UNIT_DESCRIPTOR); + return Game::Read( + player, Offsets::OFF_UNIT_DESCRIPTOR); } // Calls the engine's cooldown helper at `FUN_SPELL_QUERY_COOLDOWN` @@ -101,8 +101,8 @@ int CountItemInBags(void *L, int targetItemID) { auto *itemDesc = Item::ObjectFields(item); if (itemDesc == nullptr) continue; - total += static_cast(*reinterpret_cast( - itemDesc + Offsets::OFF_DESCRIPTOR_STACK_COUNT)); + total += static_cast(Game::Read( + itemDesc, Offsets::OFF_DESCRIPTOR_STACK_COUNT)); } } return total; @@ -113,10 +113,10 @@ int CountItemInBags(void *L, int targetItemID) { // Spells with zero reagents trivially pass. bool HasReagents(void *L, const uint8_t *record) { for (int i = 0; i < Offsets::SPELL_MAX_REAGENTS; i++) { - const int reagentItemID = static_cast(*reinterpret_cast( - record + Offsets::OFF_SPELL_REAGENT_ID + i * 4)); - const int reagentCount = static_cast(*reinterpret_cast( - record + Offsets::OFF_SPELL_REAGENT_COUNT + i * 4)); + const int reagentItemID = static_cast(Game::Read( + record, Offsets::OFF_SPELL_REAGENT_ID + i * 4)); + const int reagentCount = static_cast(Game::Read( + record, Offsets::OFF_SPELL_REAGENT_COUNT + i * 4)); if (reagentItemID <= 0 || reagentCount <= 0) continue; if (CountItemInBags(L, reagentItemID) < reagentCount) @@ -162,8 +162,8 @@ Usability ComputeUsability(void *L, int spellID) { if (desc == nullptr) return r; - const int health = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_HEALTH); + const int health = Game::Read( + desc, Offsets::OFF_UNIT_FIELD_HEALTH); if (health <= 0) return r; @@ -176,16 +176,16 @@ Usability ComputeUsability(void *L, int spellID) { // not just the base ManaCost. Falls back to base if the engine can't // resolve a cost (shouldn't happen here: the player descriptor // resolved above, so it has a player context). - const int powerType = static_cast(*reinterpret_cast( - record + Offsets::OFF_SPELL_RECORD_POWER_TYPE)); + const int powerType = static_cast(Game::Read( + record, Offsets::OFF_SPELL_RECORD_POWER_TYPE)); if (powerType >= 0 && powerType <= 4) { auto getCost = reinterpret_cast(Offsets::FUN_GET_SPELL_COST); uint32_t cost = getCost(spellID, 0 /* local player */); if (cost == 0xFFFFFFFF) - cost = *reinterpret_cast(record + Offsets::OFF_SPELL_RECORD_MANA_COST); + cost = Game::Read(record, Offsets::OFF_SPELL_RECORD_MANA_COST); if (cost > 0) { - const int currentPower = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_POWER1 + powerType * 4); + const int currentPower = Game::Read( + desc, Offsets::OFF_UNIT_FIELD_POWER1 + powerType * 4); if (currentPower < static_cast(cost)) { r.noMana = true; return r; diff --git a/src/talent/Info.cpp b/src/talent/Info.cpp index 76141b52..906713a0 100644 --- a/src/talent/Info.cpp +++ b/src/talent/Info.cpp @@ -77,8 +77,8 @@ static int __fastcall Script_GetTalentSpellID(void *L) { ResolveTalentRecordForClass(classID, tabIndex, talentIndex); if (rec == nullptr) return 0; - const uint32_t spellID = *reinterpret_cast( - rec + Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t)); + const uint32_t spellID = Game::Read( + rec, Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t)); if (spellID == 0) return 0; // rank slot not populated (rank > maxRank for this talent) Game::Lua::PushNumber(L, static_cast(spellID)); @@ -89,21 +89,20 @@ static int __fastcall Script_GetTalentSpellID(void *L) { // engine's `Script_GetTalentInfo` on out-of-range input. The engine // bails to its error path (lua_error) on bad tab, bad talent index, // or NULL player; we want all of those to return nil instead. - const int tabCount = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_COUNT)); + const int tabCount = Game::Read(Offsets::VAR_TALENT_TAB_COUNT); if (tabIndex > tabCount) return 0; - auto *tabs = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_INFO_ARRAY)); + auto *tabs = Game::Read( + Offsets::VAR_TALENT_TAB_INFO_ARRAY); if (tabs == nullptr) return 0; const uint8_t *tabInfo = tabs[tabIndex - 1]; if (tabInfo == nullptr) return 0; - const int numTalents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS); + const int numTalents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS); if (talentIndex > numTalents) return 0; @@ -131,14 +130,14 @@ static int __fastcall Script_GetTalentSpellID(void *L) { rank = 1; // unallocated talent → fall back to rank-1 spellID } - auto *talents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY); + auto *talents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY); if (talents == nullptr) return 0; const uint8_t *entry = talents + (talentIndex - 1) * Offsets::TALENT_ENTRY_STRIDE; - const uint32_t spellID = *reinterpret_cast( - entry + Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t)); + const uint32_t spellID = Game::Read( + entry, Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t)); if (spellID == 0) return 0; // rank slot not populated (rank > maxRank for this talent) @@ -158,22 +157,22 @@ static int __fastcall Script_GetTalentSpellID(void *L) { // never race-restricted — so we apply only the class half of `FUN_004f2e50`. static uint32_t NthClassTalentTabID(int classID, int tabIndex) { const uint32_t classBit = 1u << ((classID - 1) & 0x1F); - auto *base = *reinterpret_cast( - static_cast(Offsets::VAR_TALENTTAB_DBC_FLAT_RECORDS)); - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_TALENTTAB_DBC_FLAT_COUNT)); + auto *base = Game::Read( + Offsets::VAR_TALENTTAB_DBC_FLAT_RECORDS); + const int count = Game::Read( + Offsets::VAR_TALENTTAB_DBC_FLAT_COUNT); if (base == nullptr) return 0; int match = 0; for (int i = 0; i < count; ++i) { const uint8_t *rec = base + i * Offsets::TALENTTAB_ENTRY_STRIDE; - const uint32_t classMask = *reinterpret_cast( - rec + Offsets::OFF_TALENTTAB_CLASS_MASK); + const uint32_t classMask = Game::Read( + rec, Offsets::OFF_TALENTTAB_CLASS_MASK); if (classMask != 0 && (classMask & classBit) == 0) continue; if (++match == tabIndex) - return *reinterpret_cast( - rec + Offsets::OFF_TALENTTAB_ID); + return Game::Read( + rec, Offsets::OFF_TALENTTAB_ID); } return 0; } @@ -182,16 +181,16 @@ static uint32_t NthClassTalentTabID(int classID, int tabIndex) { // `tabID`, in DBC row order — the same order the builder assigns within a tab. // Returns null if there aren't that many. static const uint8_t *NthTabTalentRecord(uint32_t tabID, int talentIndex) { - auto *base = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_DBC_FLAT_RECORDS)); - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_DBC_FLAT_COUNT)); + auto *base = Game::Read( + Offsets::VAR_TALENT_DBC_FLAT_RECORDS); + const int count = Game::Read( + Offsets::VAR_TALENT_DBC_FLAT_COUNT); if (base == nullptr) return nullptr; int match = 0; for (int i = 0; i < count; ++i) { const uint8_t *rec = base + i * Offsets::TALENT_ENTRY_STRIDE; - if (*reinterpret_cast(rec + Offsets::OFF_TALENT_DBC_TAB_ID) != tabID) + if (Game::Read(rec, Offsets::OFF_TALENT_DBC_TAB_ID) != tabID) continue; if (++match == talentIndex) return rec; @@ -259,26 +258,25 @@ static int __fastcall Script_GetTalentIDByIndex(void *L) { return 1; } - const int tabCount = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_COUNT)); + const int tabCount = Game::Read(Offsets::VAR_TALENT_TAB_COUNT); if (tabIndex > tabCount) return 0; - auto *tabs = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_INFO_ARRAY)); + auto *tabs = Game::Read( + Offsets::VAR_TALENT_TAB_INFO_ARRAY); if (tabs == nullptr) return 0; const uint8_t *tabInfo = tabs[tabIndex - 1]; if (tabInfo == nullptr) return 0; - const int numTalents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS); + const int numTalents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS); if (talentIndex > numTalents) return 0; - auto *talents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY); + auto *talents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY); if (talents == nullptr) return 0; diff --git a/src/talent/Tooltip.cpp b/src/talent/Tooltip.cpp index 4662e7a7..6c517900 100644 --- a/src/talent/Tooltip.cpp +++ b/src/talent/Tooltip.cpp @@ -27,10 +27,9 @@ namespace Talent::Tooltip { // classes' talents aren't findable here. Same access pattern as // `Talent::Info::Script_GetTalentIDByIndex` (#42), inverted. static bool FindTalentByID(uint32_t talentID, int *outTab, int *outIdx) { - const int tabCount = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_COUNT)); - auto *tabs = *reinterpret_cast( - static_cast(Offsets::VAR_TALENT_TAB_INFO_ARRAY)); + const int tabCount = Game::Read(Offsets::VAR_TALENT_TAB_COUNT); + auto *tabs = Game::Read( + Offsets::VAR_TALENT_TAB_INFO_ARRAY); if (tabs == nullptr) return false; @@ -38,10 +37,10 @@ static bool FindTalentByID(uint32_t talentID, int *outTab, int *outIdx) { const uint8_t *tabInfo = tabs[t - 1]; if (tabInfo == nullptr) continue; - const int numTalents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS); - auto *talents = *reinterpret_cast( - tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY); + const int numTalents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS); + auto *talents = Game::Read( + tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY); if (talents == nullptr) continue; @@ -70,7 +69,7 @@ static uint32_t LookupTalentRank1Spell(uint32_t talentID) { talentID); if (rec == nullptr) return 0; - return *reinterpret_cast(rec + Offsets::OFF_TALENT_SPELL_RANK); + return Game::Read(rec, Offsets::OFF_TALENT_SPELL_RANK); } // `GameTooltip:SetTalentByID(talentID)` — modern method that renders a diff --git a/src/taxi/Map.cpp b/src/taxi/Map.cpp index 0f865a55..ccf2fe5a 100644 --- a/src/taxi/Map.cpp +++ b/src/taxi/Map.cpp @@ -117,7 +117,7 @@ int ResolveZoneByName(const char *zone) { if (zone == nullptr || *zone == '\0') return 0; const int count = - *reinterpret_cast(Offsets::VAR_AREATABLE_COUNT); + Game::Read(Offsets::VAR_AREATABLE_COUNT); int prefixHit = 0; for (int id = 1; id <= count; ++id) { const char *nm = @@ -154,7 +154,7 @@ void PushPosition(void *L, const char *key, double px, double py) { // is ample). Returns false when the path table isn't loaded. constexpr int kMaxTaxiNodeID = 2048; bool BuildTaxiGraph(bool *endpoint, bool *dest, int size) { - const int count = *reinterpret_cast(Offsets::VAR_TAXIPATH_COUNT); + const int count = Game::Read(Offsets::VAR_TAXIPATH_COUNT); if (count <= 0) return false; for (int i = 1; i <= count; ++i) { @@ -193,7 +193,7 @@ int __fastcall Script_GetTaxiNodesForMap(void *L) { BuildTaxiGraph(endpoint, dest, kMaxTaxiNodeID); const int count = - *reinterpret_cast(Offsets::VAR_TAXINODES_COUNT); + Game::Read(Offsets::VAR_TAXINODES_COUNT); int outIdx = 0; for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_TAXINODES_RECORDS, @@ -316,7 +316,7 @@ int __fastcall Script_GetAllTaxiNodes(void *L) { Game::Lua::NewTable(L); const int count = - *reinterpret_cast(Offsets::VAR_TAXI_NODE_COUNT); + Game::Read(Offsets::VAR_TAXI_NODE_COUNT); if (count <= 0) return 1; // no taxi map open @@ -326,8 +326,8 @@ int __fastcall Script_GetAllTaxiNodes(void *L) { for (int slot = 0; slot < count; ++slot) { const uint8_t *slotRec = arrayBase + slot * Offsets::TAXI_NODE_STRIDE; - const uint8_t *dbcRec = *reinterpret_cast( - slotRec + Offsets::OFF_TAXI_SLOT_RECORD); + const uint8_t *dbcRec = Game::Read( + slotRec, Offsets::OFF_TAXI_SLOT_RECORD); const float x = FloatField(slotRec, Offsets::OFF_TAXI_SLOT_X); const float y = FloatField(slotRec, Offsets::OFF_TAXI_SLOT_Y); @@ -378,7 +378,7 @@ int __fastcall Script_GetTaxiRoute(void *L) { return 0; const int slot1 = static_cast(Game::Lua::ToNumber(L, 1)); const int count = - *reinterpret_cast(Offsets::VAR_TAXI_NODE_COUNT); + Game::Read(Offsets::VAR_TAXI_NODE_COUNT); if (count <= 0 || slot1 < 1 || slot1 > count) return 0; @@ -387,10 +387,10 @@ int __fastcall Script_GetTaxiRoute(void *L) { const uint8_t *slotRec = arrayBase + (slot1 - 1) * Offsets::TAXI_NODE_STRIDE; - const uint8_t *curRec = *reinterpret_cast( + const uint8_t *curRec = Game::Read( Offsets::VAR_TAXI_CURRENT_REC); - const uint8_t *dstRec = *reinterpret_cast( - slotRec + Offsets::OFF_TAXI_SLOT_RECORD); + const uint8_t *dstRec = Game::Read( + slotRec, Offsets::OFF_TAXI_SLOT_RECORD); if (curRec == nullptr || dstRec == nullptr) return 0; const int currentID = IntField(curRec, 0); @@ -405,10 +405,10 @@ int __fastcall Script_GetTaxiRoute(void *L) { ids[n++] = currentID; ids[n++] = destID; } else if (*(slotRec + Offsets::OFF_TAXI_SLOT_MULTIHOP) != 0) { - const int *route = *reinterpret_cast( - slotRec + Offsets::OFF_TAXI_SLOT_ROUTE); - const int rc = *reinterpret_cast( - slotRec + Offsets::OFF_TAXI_SLOT_ROUTE_COUNT); + const int *route = Game::Read( + slotRec, Offsets::OFF_TAXI_SLOT_ROUTE); + const int rc = Game::Read( + slotRec, Offsets::OFF_TAXI_SLOT_ROUTE_COUNT); if (route == nullptr || rc < 2) return 0; const int cap = rc < 64 ? rc : 64; diff --git a/src/taxi/Paths.cpp b/src/taxi/Paths.cpp index 247d4500..37e628cf 100644 --- a/src/taxi/Paths.cpp +++ b/src/taxi/Paths.cpp @@ -49,7 +49,7 @@ int __fastcall Script_GetTaxiPaths(void *L) { Game::Lua::SetTop(L, 0); Game::Lua::NewTable(L); - const int count = *reinterpret_cast(Offsets::VAR_TAXIPATH_COUNT); + const int count = Game::Read(Offsets::VAR_TAXIPATH_COUNT); int outIdx = 0; for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_TAXIPATH_RECORDS, @@ -86,7 +86,7 @@ int __fastcall Script_GetTaxiPathWaypoints(void *L) { int mapID; }; std::vector pts; - const int count = *reinterpret_cast(Offsets::VAR_TAXIPATHNODE_COUNT); + const int count = Game::Read(Offsets::VAR_TAXIPATHNODE_COUNT); for (int id = 1; id <= count; ++id) { const uint8_t *rec = DBC::Record(Offsets::VAR_TAXIPATHNODE_RECORDS, Offsets::VAR_TAXIPATHNODE_COUNT, diff --git a/src/text/InlineTexture.cpp b/src/text/InlineTexture.cpp index 3484a775..0834786d 100644 --- a/src/text/InlineTexture.cpp +++ b/src/text/InlineTexture.cpp @@ -247,12 +247,10 @@ void *OwningFontStringOf(void *node) { auto ow = g_nodeOwner.find(node); if (ow == g_nodeOwner.end() || !LooksReadable(ow->second)) return nullptr; - auto *of = reinterpret_cast(ow->second); - void *block = *reinterpret_cast(of + Offsets::OFF_FONTSTRING_TEXT_BLOCK); + void *block = Game::Read(ow->second, Offsets::OFF_FONTSTRING_TEXT_BLOCK); if (!LooksReadable(block)) return nullptr; - void *cur = *reinterpret_cast(reinterpret_cast(block) + - Offsets::OFF_TEXTBLOCK_NODE); + void *cur = Game::Read(block, Offsets::OFF_TEXTBLOCK_NODE); return (cur == node) ? ow->second : nullptr; } @@ -318,12 +316,10 @@ void __fastcall RebuildString_h(void *fs) { g_rebuildOriginal(fs); if (!LooksReadable(fs)) return; - void *block = *reinterpret_cast(reinterpret_cast(fs) + - Offsets::OFF_FONTSTRING_TEXT_BLOCK); + void *block = Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK); if (!LooksReadable(block)) return; - void *node = *reinterpret_cast(reinterpret_cast(block) + - Offsets::OFF_TEXTBLOCK_NODE); + void *node = Game::Read(block, Offsets::OFF_TEXTBLOCK_NODE); if (LooksReadable(node)) g_nodeOwner[node] = fs; } @@ -343,12 +339,11 @@ static const Game::HookAutoRegister _rebuildHook{Offsets::FUN_FONTSTRING_REBUILD // ±10% (a mid-layout stale-rect read must not poison it). float DeriveK(const uint8_t *n, const uint8_t *f, float originX) { if (LooksReadable(f)) { - const float left = *reinterpret_cast(f + Offsets::OFF_REGION_RECT + 4); - const float right = *reinterpret_cast(f + Offsets::OFF_REGION_RECT + 12); - const float insetX = *reinterpret_cast(f + Offsets::OFF_FONTSTRING_INSET_X); + const float left = Game::Read(f, Offsets::OFF_REGION_RECT + 4); + const float right = Game::Read(f, Offsets::OFF_REGION_RECT + 12); + const float insetX = Game::Read(f, Offsets::OFF_FONTSTRING_INSET_X); if (left < right && std::fabs(insetX) < 1e-6f) { - const int justify = - *reinterpret_cast(n + Offsets::OFF_TEXT_NODE_JUSTIFY); + const int justify = Game::Read(n, Offsets::OFF_TEXT_NODE_JUSTIFY); const float ref = (justify == 1) ? (left + right) * 0.5f : ((justify == 2) ? right : left); if (std::fabs(ref) > 0.02f && originX > 1.0f) { @@ -383,13 +378,12 @@ bool PtrInBuffer(const uint8_t *t, const uint8_t *buf) { // FUN_00772ae0 → … → FUN_005c6940 loops the tokenizer), so the measure tokenizer's // `text` points directly into it. const uint8_t *FocusedEditboxInput() { - const void *fe = *reinterpret_cast(Offsets::VAR_FOCUSED_EDITBOX); + const void *fe = Game::Read(Offsets::VAR_FOCUSED_EDITBOX); if (!LooksReadable(fe)) return nullptr; - auto *f = reinterpret_cast(fe); - const uint8_t sel = f[Offsets::OFF_EDITBOX_BUFFER_SELECT]; - const uint8_t *inBuf = *reinterpret_cast( - f + ((sel & 8u) ? Offsets::OFF_EDITBOX_BUFFER_MASKED : Offsets::OFF_EDITBOX_BUFFER)); + const uint8_t sel = Game::Read(fe, Offsets::OFF_EDITBOX_BUFFER_SELECT); + const uint8_t *inBuf = Game::Read( + fe, (sel & 8u) ? Offsets::OFF_EDITBOX_BUFFER_MASKED : Offsets::OFF_EDITBOX_BUFFER); return LooksReadable(inBuf) ? inBuf : nullptr; } @@ -474,9 +468,7 @@ bool InlineInterceptActive(const uint8_t *text, bool editable) { // global misses (multi-line editors build once, un-focused). This mirrors 4.3.4's // per-render texture-disable flag, adapted to 1.12's layout. inline bool NodeEditable(const void *node) { - return (*reinterpret_cast(reinterpret_cast(node) + - Offsets::OFF_TEXT_NODE_FLAGS) & - 0x40u) != 0; + return (Game::Read(node, Offsets::OFF_TEXT_NODE_FLAGS) & 0x40u) != 0; } // Geometry constants, calibrated in-game during bring-up (via a since-removed @@ -745,14 +737,11 @@ float __fastcall StringWidth_h(void *fs) { const float base = g_stringWidthOriginal(fs); if (!LooksReadable(fs)) return base; - const auto *f = reinterpret_cast(fs); // fs+0x120 bit 0x1000 → gxu editbox bit 0x40: an editbox measures the raw // markup it renders, so its width must stay unadjusted (caret alignment). const bool editable = - (*reinterpret_cast(f + Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & - 0x1000u) != 0; - const uint8_t *text = - *reinterpret_cast(f + Offsets::OFF_FONTSTRING_TEXT); + (Game::Read(fs, Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & 0x1000u) != 0; + const uint8_t *text = Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT); if (!LooksReadable(text) || !InlineInterceptActive(text, editable)) return base; int len = 0; @@ -760,8 +749,8 @@ float __fastcall StringWidth_h(void *fs) { ++len; if (!HasInlineTexture(text, len)) return base; - const float mul = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_MUL); - const float div = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_DIV); + const float mul = Game::Read(Offsets::VAR_UI_COORD_SCALE_MUL); + const float div = Game::Read(Offsets::VAR_UI_COORD_SCALE_DIV); if (!(mul > 0.0f) || !(div > 0.0f)) return base; const float anchorToPx = div * Offsets::UI_COORD_SCALE_UNIT / mul; // ≈1468 (the push K) @@ -810,12 +799,9 @@ float __fastcall StringHeight_h(void *fs) { const float base = g_stringHeightOriginal(fs); if (!LooksReadable(fs)) return base; - const auto *f = reinterpret_cast(fs); const bool editable = - (*reinterpret_cast(f + Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & - 0x1000u) != 0; - const uint8_t *text = - *reinterpret_cast(f + Offsets::OFF_FONTSTRING_TEXT); + (Game::Read(fs, Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & 0x1000u) != 0; + const uint8_t *text = Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT); if (!LooksReadable(text) || !InlineInterceptActive(text, editable)) return base; int len = 0; @@ -823,8 +809,8 @@ float __fastcall StringHeight_h(void *fs) { ++len; if (!HasInlineTexture(text, len)) return base; - const float mul = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_MUL); - const float div = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_DIV); + const float mul = Game::Read(Offsets::VAR_UI_COORD_SCALE_MUL); + const float div = Game::Read(Offsets::VAR_UI_COORD_SCALE_DIV); if (!(mul > 0.0f) || !(div > 0.0f)) return base; const float anchorToPx = div * Offsets::UI_COORD_SCALE_UNIT / mul; @@ -878,10 +864,8 @@ void __fastcall LinkRectAdd_h(void *node, void *edx, float yA, float xLeft, floa if (HasInlineTexture(escStart, len)) { // The line's font pixel height, the emitter's own recipe (ecx = // (nodeFlags>>7)&1, stack = node fontSize). - const uint32_t nodeFlags = *reinterpret_cast( - reinterpret_cast(node) + Offsets::OFF_TEXT_NODE_FLAGS); - const float fontSize = *reinterpret_cast( - reinterpret_cast(node) + Offsets::OFF_TEXT_NODE_FONT_SIZE); + const uint32_t nodeFlags = Game::Read(node, Offsets::OFF_TEXT_NODE_FLAGS); + const float fontSize = Game::Read(node, Offsets::OFF_TEXT_NODE_FONT_SIZE); const float fontH = reinterpret_cast( Offsets::FUN_TEXT_FONT_HEIGHT)(static_cast((nodeFlags >> 7) & 1u), fontSize); const float overflow = MaxIconOverflowPx(escStart, len, fontH); @@ -1168,8 +1152,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_ const bool firstLine = (node == g_buildNode) ? (g_buildEmitSeq++ == 0) - : (text == *reinterpret_cast(reinterpret_cast(node) + - Offsets::OFF_TEXT_NODE_TEXT)); + : (text == Game::Read(node, Offsets::OFF_TEXT_NODE_TEXT)); if (firstLine) g_nodeIcons.erase(node); @@ -1195,8 +1178,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_ // the batch-clear ONCE per build (a len-0 original call with bit 3 still set, // only on the first wrapped line), then clearing bit 3 so our per-segment calls // APPEND. Restore the flags before returning. - uint32_t *const flagsPtr = reinterpret_cast(reinterpret_cast(node) + - Offsets::OFF_TEXT_NODE_FLAGS); + uint32_t *const flagsPtr = Game::Ptr(node, Offsets::OFF_TEXT_NODE_FLAGS); const uint32_t savedFlags = *flagsPtr; const bool batchClearMode = (savedFlags & 8u) != 0; if (batchClearMode) { @@ -1225,17 +1207,14 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_ // near the text top). Mirrors the emitter's own call: ecx = (nodeFlags>>7)&1, // stack = the node's font size [node+0x1c]. const int fontFlag = static_cast((savedFlags >> 7) & 1u); - const float fontSize = - *reinterpret_cast(reinterpret_cast(node) + - Offsets::OFF_TEXT_NODE_FONT_SIZE); + const float fontSize = Game::Read(node, Offsets::OFF_TEXT_NODE_FONT_SIZE); const float fontH = reinterpret_cast( Offsets::FUN_TEXT_FONT_HEIGHT)(fontFlag, fontSize); // Font face + native→pen advance scale, mirroring the emitter's own // `local_10 = fontH / (float)nativeHeight`. Used by drawRun's terminal- // advance correction (glyph-record advances are native-font units). - void *const fontFace = *reinterpret_cast(reinterpret_cast(node) + - Offsets::OFF_TEXT_NODE_FONT_FACE); + void *const fontFace = Game::Read(node, Offsets::OFF_TEXT_NODE_FONT_FACE); using FontNativeHeight_t = int(__fastcall *)(void *font); const int fontNativeH = (fontFace != nullptr) @@ -1260,8 +1239,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_ // (right) so the whole text+icons block is justified as a unit. Left-justify // (chat, justify 0) needs no shift. node+0x54: 1 = centre, 2 = right (verified // in the draw builder FUN_005cdc20's justify branch). - const int justify = *reinterpret_cast( - reinterpret_cast(node) + Offsets::OFF_TEXT_NODE_JUSTIFY); + const int justify = Game::Read(node, Offsets::OFF_TEXT_NODE_JUSTIFY); if (justify == 1 || justify == 2) { // Shared helper so the pre-shift matches the real advances exactly // (including the positive-offsetX term an earlier inline copy omitted). @@ -1447,9 +1425,8 @@ Paint_t g_paintOriginal = nullptr; void FlushLayout(void *layout) { if (!LooksReadable(layout)) return; - auto *L = reinterpret_cast(layout); - const int linkOff = *reinterpret_cast(L + Offsets::OFF_TEXT_LAYOUT_NODE_LINK); - void *node = *reinterpret_cast(L + Offsets::OFF_TEXT_LAYOUT_NODE_HEAD); + const int linkOff = Game::Read(layout, Offsets::OFF_TEXT_LAYOUT_NODE_LINK); + void *node = Game::Read(layout, Offsets::OFF_TEXT_LAYOUT_NODE_HEAD); for (int guard = 0; node != nullptr && (reinterpret_cast(node) & 1) == 0 && guard < 4096; @@ -1457,7 +1434,7 @@ void FlushLayout(void *layout) { if (!LooksReadable(node)) break; auto *n = reinterpret_cast(node); - void *const next = *reinterpret_cast(n + linkOff + 4); + void *const next = Game::Read(n, linkOff + 4); // Resolve the owning fontstring up front: a node with NO icons must // still clear its fontstring's regions — the fs may have just been @@ -1470,12 +1447,9 @@ void FlushLayout(void *layout) { { auto ow = g_nodeOwner.find(node); if (ow != g_nodeOwner.end() && LooksReadable(ow->second)) { - auto *of = reinterpret_cast(ow->second); - void *block = - *reinterpret_cast(of + Offsets::OFF_FONTSTRING_TEXT_BLOCK); + void *block = Game::Read(ow->second, Offsets::OFF_FONTSTRING_TEXT_BLOCK); if (LooksReadable(block) && - *reinterpret_cast(reinterpret_cast(block) + - Offsets::OFF_TEXTBLOCK_NODE) == node) { + Game::Read(block, Offsets::OFF_TEXTBLOCK_NODE) == node) { fs = ow->second; } else if (block == nullptr) { // Stuck-blockless fs: RebuildString released the block (a @@ -1484,8 +1458,7 @@ void FlushLayout(void *layout) { // fs's rebuild-dirty bit so the engine rebuilds next update // and the icon pipeline resumes. Byte write only — safe // from the paint tail (consumed by the fs's own update). - uint8_t *flags = of + Offsets::OFF_FONTSTRING_DIRTY_FLAGS; - *flags |= 1u; + Game::Ref(ow->second, Offsets::OFF_FONTSTRING_DIRTY_FLAGS) |= 1u; } } } @@ -1503,8 +1476,7 @@ void FlushLayout(void *layout) { // check erases good records on every clean paint: the all-icons-gone // regression.) if (it != g_nodeIcons.end() && !it->second.empty() && fs != nullptr) { - const char *ftext = *reinterpret_cast( - reinterpret_cast(fs) + Offsets::OFF_FONTSTRING_TEXT); + const char *ftext = Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT); bool fsHasMarkup = false; if (LooksReadable(ftext)) { for (int k = 1; k < 2048 && ftext[k] != '\0'; ++k) @@ -1550,26 +1522,23 @@ void FlushLayout(void *layout) { // node alpha too). One-frame lag (flush runs post-paint), same as // the icon fade mirror. Chat (bit-3 clear) is excluded: the engine // re-bakes those on colour change itself. - if ((*reinterpret_cast(n + Offsets::OFF_TEXT_NODE_FLAGS) & - 8u) != 0) { - const uint8_t liveA = n[Offsets::OFF_TEXT_NODE_COLOR + 3]; + if ((Game::Read(n, Offsets::OFF_TEXT_NODE_FLAGS) & 8u) != 0) { + const uint8_t liveA = Game::Read(n, Offsets::OFF_TEXT_NODE_COLOR + 3); for (int page = 0; page < Offsets::TEXT_NODE_PAGE_COUNT; ++page) { - auto *buf = *reinterpret_cast( - n + Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4); + auto *buf = + Game::Read(n, Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4); if (buf == nullptr) continue; - const int count = *reinterpret_cast( - buf + Offsets::OFF_TEXT_PAGE_COLOR_COUNT); - auto *colors = - *reinterpret_cast(buf + Offsets::OFF_TEXT_PAGE_COLORS); + const int count = Game::Read(buf, Offsets::OFF_TEXT_PAGE_COLOR_COUNT); + auto *colors = Game::Read(buf, Offsets::OFF_TEXT_PAGE_COLORS); if (colors == nullptr || count <= 0 || colors[3] == liveA) continue; for (int i = 0; i < count; ++i) colors[i * 4 + 3] = liveA; } } - const float ox = *reinterpret_cast(n + Offsets::OFF_TEXT_NODE_ORIGIN_X); - const float oy = *reinterpret_cast(n + Offsets::OFF_TEXT_NODE_ORIGIN_Y); + const float ox = Game::Read(n, Offsets::OFF_TEXT_NODE_ORIGIN_X); + const float oy = Game::Read(n, Offsets::OFF_TEXT_NODE_ORIGIN_Y); // The fs rect, read HERE in the same flush as the icon coords — a // coherent snapshot. Placements are stored FS-RELATIVE: an // apply-time rect read raced the chat relayout (SetText invalidates @@ -1581,8 +1550,7 @@ void FlushLayout(void *layout) { float fsLeft = 0.0f, fsBottom = 0.0f; bool fsRectValid = false; if (fs != nullptr) { - const float *rc = reinterpret_cast( - reinterpret_cast(fs) + Offsets::OFF_REGION_RECT); + const float *rc = Game::Ptr(fs, Offsets::OFF_REGION_RECT); fsBottom = (rc[0] < rc[2]) ? rc[0] : rc[2]; fsLeft = (rc[1] < rc[3]) ? rc[1] : rc[3]; fsRectValid = rc[1] != rc[3]; // unresolved rect reads 0-width diff --git a/src/text/InlineTexturePool.cpp b/src/text/InlineTexturePool.cpp index 1680795a..533c0ff0 100644 --- a/src/text/InlineTexturePool.cpp +++ b/src/text/InlineTexturePool.cpp @@ -22,6 +22,7 @@ #include "text/InlineTexturePool.h" +#include "Game.h" #include "Offsets.h" #include "text/PtrProbe.h" #include "tick/FrameTick.h" @@ -173,11 +174,9 @@ void Hide(void *tex) { // derivation); mirroring the byte onto the line's icon regions makes inline // icons fade with their text. Count 0 = never colored = opaque default. uint8_t FsColorAlpha(const void *fs) { - auto *f = reinterpret_cast(fs); - if (*reinterpret_cast(f + Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u) + if (Game::Read(fs, Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u) return 0xFFu; - const uint8_t *colors = - *reinterpret_cast(f + Offsets::OFF_FONTSTRING_COLOR_ARRAY); + const uint8_t *colors = Game::Read(fs, Offsets::OFF_FONTSTRING_COLOR_ARRAY); if (!LooksReadable(colors)) return 0xFFu; return colors[3]; // slot 0's BGRA dword, alpha byte @@ -216,7 +215,7 @@ void ApplyPlacement(IconRegion &r, void *fs, const Placement &p, uint8_t fsAlpha // then froze them — the scroll-landing "randomly hidden icon" bug. if (r.path != p.path) { - const uint32_t blend = *reinterpret_cast(Offsets::VAR_TEXTURE_BLEND_DEFAULT); + const uint32_t blend = Game::Read(Offsets::VAR_TEXTURE_BLEND_DEFAULT); reinterpret_cast(Offsets::FUN_SIMPLETEXTURE_SET_TEXTURE)(r.tex, p.path.c_str(), 0, blend, 0); r.path = p.path; @@ -236,10 +235,9 @@ void ApplyPlacement(IconRegion &r, void *fs, const Placement &p, uint8_t fsAlpha // the probe: a 50px SetPoint offset stored as 0.0319 internal resolved to a // rect at 0.0290 = 0.0319 × s (s = 0.91). So divide the desired resolved // delta by the region's own scale before storing. - float sReg = *reinterpret_cast(reinterpret_cast(r.tex) + - Offsets::OFF_LAYOUT_SCALE); + float sReg = Game::Read(r.tex, Offsets::OFF_LAYOUT_SCALE); if (!(sReg > 0.01f && sReg < 100.0f)) - sReg = *reinterpret_cast(f + Offsets::OFF_LAYOUT_SCALE); + sReg = Game::Read(f, Offsets::OFF_LAYOUT_SCALE); const float inv = (sReg > 0.01f && sReg < 100.0f) ? 1.0f / sReg : 1.0f; // Single deterministic placement; the resolver's true offset scale is diff --git a/src/texture/Transform.cpp b/src/texture/Transform.cpp index 4e7efd66..8537ab6e 100644 --- a/src/texture/Transform.cpp +++ b/src/texture/Transform.cpp @@ -94,8 +94,8 @@ using Crop_t = void(__fastcall *)(void *region, void *edx, float *rect); // region's LOCAL pixels must be folded through its effective scale (+0x7C) // before this factor applies; WriteCorners does that. float PixelToInternal(float px) { - const float mul = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_MUL); - const float div = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_DIV); + const float mul = Game::Read(Offsets::VAR_UI_COORD_SCALE_MUL); + const float div = Game::Read(Offsets::VAR_UI_COORD_SCALE_DIV); if (div == 0.0f) return 0.0f; return px * mul / (div * Offsets::UI_COORD_SCALE_UNIT); @@ -139,14 +139,12 @@ void WriteCorners(void *region, float left, float right, float top, float bottom const float cy = bottom + xf.cyN * (top - bottom); const float c = std::cos(xf.angle); const float s = std::sin(xf.angle); - float scale = *reinterpret_cast( - reinterpret_cast(region) + Offsets::OFF_REGION_EFFECTIVE_SCALE); + float scale = Game::Read(region, Offsets::OFF_REGION_EFFECTIVE_SCALE); if (!(scale > 0.0f)) scale = 1.0f; const float xs[4] = {left, left, right, right}; const float ys[4] = {bottom, top, bottom, top}; - float *base = reinterpret_cast( - reinterpret_cast(region) + Offsets::OFF_SIMPLETEXTURE_CORNERS); + float *base = Game::Ptr(region, Offsets::OFF_SIMPLETEXTURE_CORNERS); // Compute each corner's TARGET rect-space position first. float tx[4], ty[4]; for (int i = 0; i < 4; ++i) { @@ -204,8 +202,7 @@ bool ApplyFromRect(void *region, const Xf &xf) { // BOTH states, so this immediate apply and the corner-store co-hook below // (which re-derives edges from whatever rect the engine stored) can never // disagree about the base rect. - if (*reinterpret_cast(reinterpret_cast(region) + - Offsets::OFF_REGION_TEXCOORD_MODIFIES_RECT) != 0) + if (Game::Read(region, Offsets::OFF_REGION_TEXCOORD_MODIFIES_RECT) != 0) reinterpret_cast(Offsets::FUN_REGION_TEXCOORD_CROP)(region, nullptr, rect); // rect = {top, left, bottom, right} WriteCorners(region, rect[1], rect[3], rect[0], rect[2], xf); @@ -238,8 +235,7 @@ void __fastcall StoreCorners_h(void *region, void *edx, float *rect) { auto it = g_xf.find(region); if (it == g_xf.end() || !it->second.active()) return; - const float *base = reinterpret_cast( - reinterpret_cast(region) + Offsets::OFF_SIMPLETEXTURE_CORNERS); + const float *base = Game::Ptr(region, Offsets::OFF_SIMPLETEXTURE_CORNERS); const float left = base[0]; // corner0 BL.x const float bottom = base[1]; // corner0 BL.y const float top = base[4]; // corner1 TL.y @@ -297,13 +293,11 @@ template int ForEachVert(uint8_t *n, Fn fn) { int visited = 0; for (int page = 0; page < Offsets::TEXT_NODE_PAGE_COUNT; ++page) { - auto *buf = *reinterpret_cast( - n + Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4); + auto *buf = Game::Read(n, Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4); if (buf == nullptr) continue; - const int count = - *reinterpret_cast(buf + Offsets::OFF_TEXT_PAGE_VERT_COUNT); - auto *verts = *reinterpret_cast(buf + Offsets::OFF_TEXT_PAGE_VERTS); + const int count = Game::Read(buf, Offsets::OFF_TEXT_PAGE_VERT_COUNT); + auto *verts = Game::Read(buf, Offsets::OFF_TEXT_PAGE_VERTS); if (verts == nullptr || count <= 0) continue; for (int i = 0; i < count; ++i) { @@ -382,12 +376,10 @@ bool RestoreBaseline(uint8_t *n, const std::vector &base) { // The CSimpleFontString's current live text node (fs+0xF8 → block, block+8), or // null when the text isn't laid out yet. void *FontStringNode(void *fs) { - void *block = *reinterpret_cast(reinterpret_cast(fs) + - Offsets::OFF_FONTSTRING_TEXT_BLOCK); + void *block = Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK); if (block == nullptr) return nullptr; - return *reinterpret_cast(reinterpret_cast(block) + - Offsets::OFF_TEXTBLOCK_NODE); + return Game::Read(block, Offsets::OFF_TEXTBLOCK_NODE); } // Applies the fontstring's stored rotation to `node`'s verts, starting from an @@ -516,8 +508,7 @@ int __fastcall Script_GetCorners(void *L) { Game::Lua::Error(L, "Usage: texture:GetCorners()"); return 0; } - const float *base = reinterpret_cast( - reinterpret_cast(tex) + Offsets::OFF_SIMPLETEXTURE_CORNERS); + const float *base = Game::Ptr(tex, Offsets::OFF_SIMPLETEXTURE_CORNERS); for (int i = 0; i < 4; ++i) { Game::Lua::PushNumber(L, base[i * 3 + 0]); Game::Lua::PushNumber(L, base[i * 3 + 1]); diff --git a/src/time/Server.cpp b/src/time/Server.cpp index 85a1ef4a..e11c5ff3 100644 --- a/src/time/Server.cpp +++ b/src/time/Server.cpp @@ -49,14 +49,14 @@ int64_t ComputeCurrentEpoch() { auto *base = reinterpret_cast( static_cast(Offsets::VAR_GAMETIME_STRUCT)); - const int year = *reinterpret_cast(base + Offsets::OFF_GAMETIME_YEAR); + const int year = Game::Read(base, Offsets::OFF_GAMETIME_YEAR); if (year <= 0) return 0; // pre-login / not yet sync'd - const int month = *reinterpret_cast(base + Offsets::OFF_GAMETIME_MONTH); - const int day = *reinterpret_cast(base + Offsets::OFF_GAMETIME_DAY); - const int hour = *reinterpret_cast(base + Offsets::OFF_GAMETIME_HOUR); - const int minute = *reinterpret_cast(base + Offsets::OFF_GAMETIME_MINUTE); + const int month = Game::Read(base, Offsets::OFF_GAMETIME_MONTH); + const int day = Game::Read(base, Offsets::OFF_GAMETIME_DAY); + const int hour = Game::Read(base, Offsets::OFF_GAMETIME_HOUR); + const int minute = Game::Read(base, Offsets::OFF_GAMETIME_MINUTE); const DWORD now = GetTickCount(); if (year != g_lastYear || month != g_lastMonth || day != g_lastDay || diff --git a/src/tooltip/CompareItem.cpp b/src/tooltip/CompareItem.cpp index a2e1008c..8f51bd07 100644 --- a/src/tooltip/CompareItem.cpp +++ b/src/tooltip/CompareItem.cpp @@ -374,8 +374,7 @@ void RenderDeltas(void *self, void *L, const Accum *acc, double dpsDelta) { const char *FSText(const void *fs) { if (fs == nullptr) return nullptr; - return *reinterpret_cast( - static_cast(fs) + Offsets::OFF_FONTSTRING_TEXT); + return Game::Read(fs, Offsets::OFF_FONTSTRING_TEXT); } // Whether a line's FontString is actually shown. The tooltip clear hides @@ -384,8 +383,7 @@ const char *FSText(const void *fs) { bool FSVisible(const void *fs) { if (fs == nullptr) return false; - return *reinterpret_cast( - static_cast(fs) + Offsets::OFF_FONTSTRING_VISIBLE) != 0; + return Game::Read(fs, Offsets::OFF_FONTSTRING_VISIBLE) != 0; } // Reads a FontString's current color into `*out` (4-byte {b,g,r,a}). @@ -394,8 +392,7 @@ bool FSVisible(const void *fs) { bool FSColor(const void *fs, uint32_t *out) { if (fs == nullptr) return false; - auto *slot = *reinterpret_cast( - static_cast(fs) + Offsets::OFF_FONTSTRING_COLOR_PTR); + auto *slot = Game::Read(fs, Offsets::OFF_FONTSTRING_COLOR_PTR); if (slot == nullptr) return false; *out = *slot; @@ -421,8 +418,7 @@ using ShowHideFS_t = void(__fastcall *)(void *fs); void FSSetShown(void *fs, bool shown) { if (fs == nullptr) return; - *reinterpret_cast(static_cast(fs) + - Offsets::OFF_FONTSTRING_SHOWN_FLAG) = shown ? 1 : 0; + Game::Ref(fs, Offsets::OFF_FONTSTRING_SHOWN_FLAG) = shown ? 1 : 0; reinterpret_cast( shown ? Offsets::FUN_FONTSTRING_SHOW : Offsets::FUN_FONTSTRING_HIDE)(fs); } @@ -452,19 +448,19 @@ void CopyLineCell(void *dst, const void *src) { void PrependCurrentlyEquipped(void *self, void *L) { auto *t = static_cast(self); - int *numLines = reinterpret_cast(t + Offsets::OFF_GAMETOOLTIP_NUM_LINES); + int *numLines = Game::Ptr(t, Offsets::OFF_GAMETOOLTIP_NUM_LINES); const int allocated = - *reinterpret_cast(t + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); + Game::Read(t, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); const int n = *numLines; if (n <= 0 || n + 1 > allocated) return; // nothing built, or pool full (LinePool keeps 60, so rare) - auto **leftArr = *reinterpret_cast( - t + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8); - auto **rightArr = *reinterpret_cast( - t + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 8); - auto *wrapArr = *reinterpret_cast( - t + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 8); + auto **leftArr = Game::Read( + t, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8); + auto **rightArr = Game::Read( + t, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 8); + auto *wrapArr = Game::Read( + t, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 8); if (leftArr == nullptr || rightArr == nullptr || wrapArr == nullptr) return; @@ -495,16 +491,15 @@ int EquippedSuffix(const uint8_t *item) { auto *desc = Item::ObjectFields(item); if (desc == nullptr) return 0; - return static_cast(*reinterpret_cast( - desc + Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY)); + return static_cast( + Game::Read(desc, Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY)); } uint64_t EquippedGUID(const uint8_t *item) { auto *instance = Item::InstanceBlock(item); if (instance == nullptr) return 0; - return *reinterpret_cast( - instance + Offsets::OFF_INSTANCE_BLOCK_GUID); + return Game::Read(instance, Offsets::OFF_INSTANCE_BLOCK_GUID); } int __fastcall Script_SetHyperlinkCompareItem(void *L) { @@ -545,8 +540,8 @@ int __fastcall Script_SetHyperlinkCompareItem(void *L) { if (hoveredRec == nullptr) return bail(0); // no link and no comparisonTooltip item, or not cached yet - const int invType = static_cast(*reinterpret_cast( - hoveredRec + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)); + const int invType = static_cast( + Game::Read(hoveredRec, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)); int slots[2] = {0, 0}; const int nSlots = SlotsForInvType(invType, slots); if (nSlots == 0) diff --git a/src/tooltip/LinePool.cpp b/src/tooltip/LinePool.cpp index 1d97d084..edb1fb3d 100644 --- a/src/tooltip/LinePool.cpp +++ b/src/tooltip/LinePool.cpp @@ -76,8 +76,8 @@ uint8_t *DescData(uint8_t *tooltip, int descOffset) { // otherwise a -2px gap lands ~1000px off. Returns 0 if the scale globals // aren't populated yet (degrades to a 0-offset anchor, not a wild one). float PixelToInternal(float pixels) { - const float mul = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_MUL); - const float divBase = *reinterpret_cast(Offsets::VAR_UI_COORD_SCALE_DIV); + const float mul = Game::Read(Offsets::VAR_UI_COORD_SCALE_MUL); + const float divBase = Game::Read(Offsets::VAR_UI_COORD_SCALE_DIV); const float denom = divBase * static_cast(Offsets::UI_COORD_SCALE_UNIT); if (denom == 0.0f) return 0.0f; @@ -89,8 +89,7 @@ float PixelToInternal(float pixels) { void *FontObjectOf(void *fontString) { if (fontString == nullptr) return nullptr; - return *reinterpret_cast(reinterpret_cast(fontString) + - Offsets::OFF_FONTSTRING_FONT_OBJECT); + return Game::Read(fontString, Offsets::OFF_FONTSTRING_FONT_OBJECT); } // Builds one CSimpleFontString: alloc → ctor(parent) → name → font (copied @@ -138,30 +137,30 @@ void AppendLine(uint8_t *tooltip, void *left, void *right) { auto reallocPtr = reinterpret_cast(Offsets::FUN_TOOLTIP_REALLOC_PTR_ARRAY); auto reallocInt = reinterpret_cast(Offsets::FUN_TOOLTIP_REALLOC_INT_ARRAY); - const uint32_t index = *reinterpret_cast( - tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); + const uint32_t index = + Game::Read(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); const uint32_t newCount = index + 1; reallocPtr(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC, newCount); - *reinterpret_cast(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 4) = newCount; + Game::Ref(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 4) = newCount; reallocPtr(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC, newCount); - *reinterpret_cast(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 4) = newCount; + Game::Ref(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 4) = newCount; reallocInt(tooltip + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC, newCount); - *reinterpret_cast(tooltip + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 4) = newCount; + Game::Ref(tooltip, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 4) = newCount; reinterpret_cast(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC))[index] = left; reinterpret_cast(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC))[index] = right; reinterpret_cast(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC))[index] = 0; - *reinterpret_cast(tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC) = newCount; + Game::Ref(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC) = newCount; } // Grows `tooltip`'s line pool up to kMaxLines, creating + appending the // missing `TextLeftN`/`TextRightN` pairs. No-op if the pool is empty // (scan didn't populate) or already at/above the target. void GrowPool(uint8_t *tooltip) { - uint32_t count = *reinterpret_cast( - tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); + uint32_t count = + Game::Read(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC); if (count == 0 || count >= kMaxLines) return; diff --git a/src/tooltip/Owner.cpp b/src/tooltip/Owner.cpp index 3fd6a583..421a7776 100644 --- a/src/tooltip/Owner.cpp +++ b/src/tooltip/Owner.cpp @@ -53,15 +53,14 @@ static int __fastcall Script_GameTooltipGetOwner(void *L) { if (tooltip == nullptr) return 0; - auto *layoutFrame = *reinterpret_cast( - static_cast(tooltip) + Offsets::OFF_TOOLTIP_OWNER); + auto *layoutFrame = Game::Read(tooltip, Offsets::OFF_TOOLTIP_OWNER); if (layoutFrame == nullptr) { Game::Lua::PushNil(L); return 1; } auto *ownerFrame = layoutFrame - Offsets::OFF_FRAME_LAYOUT_SUBOBJECT; - const int refKey = *reinterpret_cast( - ownerFrame + Offsets::OFF_COBJECT_LUA_REGISTRY_REF); + const int refKey = + Game::Read(ownerFrame, Offsets::OFF_COBJECT_LUA_REGISTRY_REF); auto rawgeti = reinterpret_cast( Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT); rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); diff --git a/src/totem/Tracker.cpp b/src/totem/Tracker.cpp index 6c4977a1..fb0f2b7a 100644 --- a/src/totem/Tracker.cpp +++ b/src/totem/Tracker.cpp @@ -92,7 +92,7 @@ using Time::Clock::NowMs; // The totem tool item a spell requires (`Totem[0]`), or 0. uint32_t TotemToolItem(const uint8_t *rec) { - const int32_t t = *reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_TOTEM); + const int32_t t = Game::Read(rec, Offsets::OFF_SPELL_RECORD_TOTEM); return t > 0 ? static_cast(t) : 0; } @@ -122,7 +122,7 @@ void ScanTools() { const uint8_t *rec = Spell::Lookup::RecordForID(spellID); if (rec == nullptr) continue; - const auto *eff = reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_EFFECT); + const auto *eff = Game::Ptr(rec, Offsets::OFF_SPELL_RECORD_EFFECT); for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { const int e = eff[i]; if (e < kEffectSummonTotemSlot1 || e > kEffectSummonTotemSlot4) @@ -190,12 +190,12 @@ int __fastcall ScanCallback(ScanCtx *ctx, void * /*unusedEdx*/, uint64_t guid) { void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0); if (obj == nullptr) return 1; - auto *desc = *reinterpret_cast( - static_cast(obj) + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read( + obj, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return 1; - const uint64_t createdBy = *reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_CREATEDBY); + const uint64_t createdBy = Game::Read( + desc, Offsets::OFF_UNIT_FIELD_CREATEDBY); if (createdBy == ctx->playerGuid) ctx->present[match] = true; return 1; // keep scanning — other slots may match other creatures @@ -218,12 +218,12 @@ int __fastcall FindGuidCallback(FindGuidCtx *ctx, void * /*unusedEdx*/, void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0); if (obj == nullptr) return 1; - auto *desc = *reinterpret_cast( - static_cast(obj) + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = Game::Read( + obj, Offsets::OFF_UNIT_DESCRIPTOR); if (desc == nullptr) return 1; - if (*reinterpret_cast( - desc + Offsets::OFF_UNIT_FIELD_CREATEDBY) == ctx->playerGuid) { + if (Game::Read( + desc, Offsets::OFF_UNIT_FIELD_CREATEDBY) == ctx->playerGuid) { ctx->found = guid; return 0; // stop } @@ -233,7 +233,7 @@ int __fastcall FindGuidCallback(FindGuidCtx *ctx, void * /*unusedEdx*/, uint64_t FindTotemGuid(uint32_t entry) { if (entry == 0) return 0; - if (*reinterpret_cast(Offsets::VAR_LOCAL_PLAYER_PTR) == + if (Game::Read(Offsets::VAR_LOCAL_PLAYER_PTR) == nullptr) return 0; const uint64_t player = Unit::Identity::PlayerGuid(); @@ -294,7 +294,7 @@ void OnTick() { // object-manager enumerator derefs the manager unconditionally, so it's // gated on the local player existing. if (anyActive && now - g_lastScanMs >= kScanIntervalMs && - *reinterpret_cast(Offsets::VAR_LOCAL_PLAYER_PTR) != + Game::Read(Offsets::VAR_LOCAL_PLAYER_PTR) != nullptr) { const uint64_t player = Unit::Identity::PlayerGuid(); if (player != 0) { @@ -331,12 +331,11 @@ const Tick::WorldTick::AutoSubscribe _tick{&OnTick}; const char *IconPath(int iconID) { if (iconID <= 0) return nullptr; - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_SPELL_ICON_COUNT)); + const int count = Game::Read(Offsets::VAR_SPELL_ICON_COUNT); if (iconID > count) return nullptr; - auto *const *records = *reinterpret_cast( - static_cast(Offsets::VAR_SPELL_ICON_RECORDS)); + auto *const *records = Game::Read( + Offsets::VAR_SPELL_ICON_RECORDS); if (records == nullptr || records[iconID] == nullptr) return nullptr; return *reinterpret_cast(records[iconID] + 4); @@ -390,13 +389,12 @@ int __fastcall Script_GetTotemInfo(void *L) { const char *icon = nullptr; if (rec != nullptr) { const int locale = - *reinterpret_cast(static_cast( - Offsets::VAR_LOCALE_INDEX)); - const char *n = *reinterpret_cast( - rec + Offsets::OFF_SPELL_NAMES + locale * 4); + Game::Read(Offsets::VAR_LOCALE_INDEX); + const char *n = Game::Read( + rec, Offsets::OFF_SPELL_NAMES + locale * 4); if (n != nullptr) name = n; - icon = IconPath(*reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_ICON_ID)); + icon = IconPath(Game::Read(rec, Offsets::OFF_SPELL_RECORD_ICON_ID)); } Game::Lua::PushBool(L, haveTotem); @@ -540,9 +538,9 @@ int __fastcall Script_GameTooltipSetTotem(void *L) { if (rec == nullptr) return 0; const int locale = - *reinterpret_cast(static_cast(Offsets::VAR_LOCALE_INDEX)); + Game::Read(Offsets::VAR_LOCALE_INDEX); const char *name = - *reinterpret_cast(rec + Offsets::OFF_SPELL_NAMES + locale * 4); + Game::Read(rec, Offsets::OFF_SPELL_NAMES + locale * 4); if (name == nullptr || name[0] == '\0') return 0; @@ -605,8 +603,8 @@ void OnPlayerSpellGo(uint32_t spellID) { if (rec == nullptr) return; - const auto *effects = reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_EFFECT); - const auto *misc = reinterpret_cast(rec + Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE); + const auto *effects = Game::Ptr(rec, Offsets::OFF_SPELL_RECORD_EFFECT); + const auto *misc = Game::Ptr(rec, Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE); for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { const int eff = effects[i]; if (eff < kEffectSummonTotemSlot1 || eff > kEffectSummonTotemSlot4) diff --git a/src/tradeskill/Link.cpp b/src/tradeskill/Link.cpp index a75eb231..cf1d016f 100644 --- a/src/tradeskill/Link.cpp +++ b/src/tradeskill/Link.cpp @@ -87,8 +87,8 @@ bool IsCraftRecipe(int spellID) { const uint8_t *rec = Spell::Lookup::RecordForID(spellID); if (rec == nullptr) return false; - const int32_t *eff = reinterpret_cast( - rec + Offsets::OFF_SPELL_RECORD_EFFECT); + const int32_t *eff = Game::Ptr( + rec, Offsets::OFF_SPELL_RECORD_EFFECT); for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) { const int e = eff[i]; if (e == Offsets::SPELL_EFFECT_CREATE_ITEM || @@ -108,10 +108,10 @@ bool IsCraftRecipe(int spellID) { // use, so the bit-index space is identical. int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey, int *outGreen, int maxOut) { - auto *const *records = *reinterpret_cast( - static_cast(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS)); - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_SKILL_LINE_ABILITY_COUNT)); + auto *const *records = Game::Read( + Offsets::VAR_SKILL_LINE_ABILITY_RECORDS); + const int count = Game::Read( + Offsets::VAR_SKILL_LINE_ABILITY_COUNT); if (records == nullptr || count <= 0) return 0; @@ -120,19 +120,19 @@ int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey, const uint8_t *rec = records[i]; if (rec == nullptr) continue; - if (static_cast(*reinterpret_cast( - rec + Offsets::OFF_SLA_SKILL_ID)) != skillLineID) + if (static_cast(Game::Read( + rec, Offsets::OFF_SLA_SKILL_ID)) != skillLineID) continue; const int spellID = - *reinterpret_cast(rec + Offsets::OFF_SLA_SPELL_ID); + Game::Read(rec, Offsets::OFF_SLA_SPELL_ID); if (!IsCraftRecipe(spellID)) continue; if (outGrey != nullptr) - outGrey[n] = *reinterpret_cast( - rec + Offsets::OFF_SLA_TRIVIAL_SKILL_HIGH); + outGrey[n] = Game::Read( + rec, Offsets::OFF_SLA_TRIVIAL_SKILL_HIGH); if (outGreen != nullptr) - outGreen[n] = *reinterpret_cast( - rec + Offsets::OFF_SLA_TRIVIAL_SKILL_LOW); + outGreen[n] = Game::Read( + rec, Offsets::OFF_SLA_TRIVIAL_SKILL_LOW); outSpell[n++] = spellID; } return n; @@ -143,8 +143,8 @@ int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey, bool IsKnownSpell(int spellID) { if (spellID <= 0) return false; - auto *bitmap = *reinterpret_cast( - static_cast(Offsets::VAR_PLAYER_SPELL_BITMAP)); + auto *bitmap = Game::Read( + Offsets::VAR_PLAYER_SPELL_BITMAP); if (bitmap == nullptr) return false; return (bitmap[static_cast(spellID) >> 5] & @@ -158,19 +158,19 @@ bool IsKnownSpell(int spellID) { uint32_t SkillForSpell(int spellID) { if (spellID <= 0) return 0; - auto *const *records = *reinterpret_cast( - static_cast(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS)); - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_SKILL_LINE_ABILITY_COUNT)); + auto *const *records = Game::Read( + Offsets::VAR_SKILL_LINE_ABILITY_RECORDS); + const int count = Game::Read( + Offsets::VAR_SKILL_LINE_ABILITY_COUNT); if (records == nullptr || count <= 0) return 0; for (int i = 1; i <= count; ++i) { const uint8_t *rec = records[i]; if (rec != nullptr && - *reinterpret_cast(rec + Offsets::OFF_SLA_SPELL_ID) == + Game::Read(rec, Offsets::OFF_SLA_SPELL_ID) == spellID) return static_cast( - *reinterpret_cast(rec + Offsets::OFF_SLA_SKILL_ID)); + Game::Read(rec, Offsets::OFF_SLA_SKILL_ID)); } return 0; } @@ -178,8 +178,7 @@ uint32_t SkillForSpell(int spellID) { // Skill line of the open Craft window (Enchanting, pet training) — derived // from its first real recipe entry, mirroring the engine. 0 if none open. uint32_t CraftSkillLine() { - const int count = *reinterpret_cast( - static_cast(Offsets::VAR_CRAFT_COUNT)); + const int count = Game::Read(Offsets::VAR_CRAFT_COUNT); if (count <= 0) return 0; const int cap = (count < kMaxRecipes) ? count : kMaxRecipes; @@ -238,16 +237,16 @@ void ReadPlayerSkillRank(int skillLine, int *outCur, int *outMax) { Offsets::FUN_SKILL_LINE_TO_SLOT)(player, skillLine); if (slot < 0) return; - const uint8_t *base = *reinterpret_cast( - player + Offsets::OFF_CGPLAYER_INFO); + const uint8_t *base = Game::Read( + player, Offsets::OFF_CGPLAYER_INFO); if (base == nullptr) return; const uint8_t *rec = base + Offsets::OFF_SKILL_INFO_TABLE + slot * Offsets::SKILL_INFO_STRIDE; - uint32_t cur = *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_CUR); - uint32_t mx = *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_MAX); + uint32_t cur = Game::Read(rec, Offsets::OFF_SKILL_INFO_CUR); + uint32_t mx = Game::Read(rec, Offsets::OFF_SKILL_INFO_MAX); const uint32_t bonus = - *reinterpret_cast(rec + Offsets::OFF_SKILL_INFO_BONUS); + Game::Read(rec, Offsets::OFF_SKILL_INFO_BONUS); if (cur != 0) cur += bonus; if (mx != 0) @@ -274,14 +273,13 @@ int BuildLink(void *L, bool useCraft) { int skillLine; if (useCraft) { // Craft-window open-state flag; zeroed by the engine on close. - if (*reinterpret_cast( - static_cast(Offsets::VAR_CRAFT_WINDOW_STATE)) == 0) + if (Game::Read(Offsets::VAR_CRAFT_WINDOW_STATE) == 0) return 0; skillLine = static_cast(CraftSkillLine()); } else { // TradeSkill skill-line global; zeroed by the engine on close. - skillLine = *reinterpret_cast( - static_cast(Offsets::VAR_CURRENT_TRADESKILL_LINE)); + skillLine = Game::Read( + Offsets::VAR_CURRENT_TRADESKILL_LINE); } if (skillLine <= 0) return 0; @@ -373,16 +371,16 @@ int __fastcall Script_GetTradeSkillListRecipes(void *L) { int createdItem = 0; int numMade = 0; if (srec != nullptr) { - createdItem = *reinterpret_cast( - srec + Offsets::OFF_SPELL_RECORD_CREATED_ITEM); + createdItem = Game::Read( + srec, Offsets::OFF_SPELL_RECORD_CREATED_ITEM); // Yield: the CREATE_ITEM effect's magnitude (base points + dice), // mirroring the engine's item-creation math. 0 for enchants. - const int32_t *eff = reinterpret_cast( - srec + Offsets::OFF_SPELL_RECORD_EFFECT); - const int32_t *basePts = reinterpret_cast( - srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); - const int32_t *baseDice = reinterpret_cast( - srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); + const int32_t *eff = Game::Ptr( + srec, Offsets::OFF_SPELL_RECORD_EFFECT); + const int32_t *basePts = Game::Ptr( + srec, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS); + const int32_t *baseDice = Game::Ptr( + srec, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE); for (int e = 0; e < Offsets::SPELL_RECORD_EFFECT_COUNT; ++e) { if (eff[e] == Offsets::SPELL_EFFECT_CREATE_ITEM) { numMade = basePts[e] + baseDice[e]; @@ -408,10 +406,10 @@ int __fastcall Script_GetTradeSkillListRecipes(void *L) { Game::Lua::PushString(L, "reagents"); Game::Lua::NewTable(L); if (srec != nullptr) { - const int32_t *rids = reinterpret_cast( - srec + Offsets::OFF_SPELL_REAGENT_ID); - const int32_t *rcounts = reinterpret_cast( - srec + Offsets::OFF_SPELL_REAGENT_COUNT); + const int32_t *rids = Game::Ptr( + srec, Offsets::OFF_SPELL_REAGENT_ID); + const int32_t *rcounts = Game::Ptr( + srec, Offsets::OFF_SPELL_REAGENT_COUNT); int outIdx = 0; for (int r = 0; r < Offsets::SPELL_MAX_REAGENTS; ++r) { if (rids[r] == 0) diff --git a/src/ui/FrameObject.cpp b/src/ui/FrameObject.cpp index ed821f30..d1830edb 100644 --- a/src/ui/FrameObject.cpp +++ b/src/ui/FrameObject.cpp @@ -60,12 +60,10 @@ void Push(void *L, void *frame) { static_cast(Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER)); auto *cobj = static_cast(frame); - int refKey = *reinterpret_cast( - cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF); + int refKey = Game::Read(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF); if (refKey <= 0) { scriptRegister(frame, nullptr, nullptr); - refKey = *reinterpret_cast( - cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF); + refKey = Game::Read(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF); } rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); @@ -76,10 +74,9 @@ void Push(void *L, void *frame) { // Slot got freed somewhere — re-register to rebuild a fresh wrapper // and slot. Zero the refcount so `ScriptRegister` re-enters its build // branch. - *reinterpret_cast(cobj + Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0; + Game::Ref(cobj, Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0; scriptRegister(frame, nullptr, nullptr); - refKey = *reinterpret_cast( - cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF); + refKey = Game::Read(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF); rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey); } diff --git a/src/unit/ClassBase.cpp b/src/unit/ClassBase.cpp index b4e87ac6..b27f4660 100644 --- a/src/unit/ClassBase.cpp +++ b/src/unit/ClassBase.cpp @@ -79,13 +79,13 @@ int __fastcall Script_UnitClassBase(void *L) { // tokens go through the unit descriptor. uint8_t classByte = 0; if (Unit::Identity::IsPlayerToken(token)) { - classByte = *reinterpret_cast(Offsets::VAR_PLAYER_CLASS_BYTE); + classByte = Game::Read(Offsets::VAR_PLAYER_CLASS_BYTE); } else { auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); auto *unit = static_cast(resolve(token)); if (unit != nullptr) { - auto *desc = *reinterpret_cast( - unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = + Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (desc != nullptr) classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE); } @@ -98,8 +98,8 @@ int __fastcall Script_UnitClassBase(void *L) { const uint8_t *rec = Unit::Identity::PlayerInfoRecord( Unit::Identity::GuidForToken(token)); if (rec != nullptr) - classByte = static_cast(*reinterpret_cast( - rec + Offsets::OFF_PLAYER_INFO_CLASS)); + classByte = static_cast( + Game::Read(rec, Offsets::OFF_PLAYER_INFO_CLASS)); } } if (classByte == 0) { diff --git a/src/unit/Flags.cpp b/src/unit/Flags.cpp index ca51b478..d035ad53 100644 --- a/src/unit/Flags.cpp +++ b/src/unit/Flags.cpp @@ -26,19 +26,19 @@ namespace Unit::Flags { bool IsPlayerControlled(const uint8_t *unit) { if (unit == nullptr) return false; - auto *fields = *reinterpret_cast( - unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *fields = + Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (fields == nullptr) return false; - const uint32_t unitFlags = *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_FLAGS); + const uint32_t unitFlags = + Game::Read(fields, Offsets::OFF_UNIT_FIELD_FLAGS); return (unitFlags & Offsets::UNIT_FLAG_PLAYER_CONTROLLED) != 0; } bool IsPlayerObject(const uint8_t *unit) { if (unit == nullptr) return false; - return *reinterpret_cast(unit + Offsets::OFF_CGOBJECT_TYPE_ID) == + return Game::Read(unit, Offsets::OFF_CGOBJECT_TYPE_ID) == Offsets::OBJECT_TYPE_PLAYER; } @@ -80,12 +80,12 @@ bool TestPlayerFlag(void *L, uint32_t flagMask) { if (!IsPlayerObject(unit)) return false; - auto *playerInfo = *reinterpret_cast( - unit + Offsets::OFF_CGPLAYER_INFO); + auto *playerInfo = + Game::Read(unit, Offsets::OFF_CGPLAYER_INFO); if (playerInfo == nullptr) return false; - const uint32_t flags = *reinterpret_cast( - playerInfo + Offsets::OFF_PLAYER_INFO_FLAGS); + const uint32_t flags = + Game::Read(playerInfo, Offsets::OFF_PLAYER_INFO_FLAGS); return (flags & flagMask) != 0; } @@ -129,14 +129,14 @@ int __fastcall Script_UnitIsFeignDeath(void *L) { Game::Lua::PushBoolean(L, 0); return 1; } - auto *fields = *reinterpret_cast( - unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *fields = + Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (fields == nullptr) { Game::Lua::PushBoolean(L, 0); return 1; } - const uint32_t unitFlags = *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_FLAGS); + const uint32_t unitFlags = + Game::Read(fields, Offsets::OFF_UNIT_FIELD_FLAGS); Game::Lua::PushBoolean(L, (unitFlags & Offsets::UNIT_FLAG_FEIGN_DEATH) != 0); return 1; @@ -154,12 +154,10 @@ uint32_t ReadGuildKey(const uint8_t *unit) { // and crash (issue: UnitIsInMyGuild on a nameplate pet/totem). if (!IsPlayerObject(unit)) return 0; - auto *info = *reinterpret_cast( - unit + Offsets::OFF_CGPLAYER_INFO); + auto *info = Game::Read(unit, Offsets::OFF_CGPLAYER_INFO); if (info == nullptr) return 0; - return *reinterpret_cast( - info + Offsets::OFF_PLAYER_INFO_GUILD_KEY); + return Game::Read(info, Offsets::OFF_PLAYER_INFO_GUILD_KEY); } using TokenToGUID_t = uint64_t(__fastcall *)(const char *token); @@ -212,8 +210,7 @@ const char *NameFromGuid(uint64_t guid, char (&nameBuf)[64]) { return nullptr; std::snprintf(nameBuf, sizeof(nameBuf), "%s", - reinterpret_cast( - entry + Offsets::OFF_PLAYER_INFO_NAME)); + Game::Ptr(entry, Offsets::OFF_PLAYER_INFO_NAME)); return nameBuf; } @@ -323,10 +320,8 @@ int __fastcall Script_UnitIsInMyGuild(void *L) { nameToFind = input; } - auto **roster = *reinterpret_cast( - Offsets::VAR_GUILD_ROSTER_PTR); - const int total = *reinterpret_cast( - Offsets::VAR_GUILD_ROSTER_TOTAL_COUNT); + auto **roster = Game::Read(Offsets::VAR_GUILD_ROSTER_PTR); + const int total = Game::Read(Offsets::VAR_GUILD_ROSTER_TOTAL_COUNT); if (roster == nullptr || total <= 0) { Game::Lua::PushNil(L); return 1; @@ -335,8 +330,8 @@ int __fastcall Script_UnitIsInMyGuild(void *L) { const uint8_t *entry = roster[i]; if (entry == nullptr) continue; - const char *name = reinterpret_cast( - entry + Offsets::OFF_GUILD_MEMBER_NAME); + const char *name = + Game::Ptr(entry, Offsets::OFF_GUILD_MEMBER_NAME); if (std::strcmp(name, nameToFind) == 0) { Game::Lua::PushNumber(L, 1.0); return 1; @@ -368,14 +363,14 @@ int __fastcall Script_UnitIsPossessed(void *L) { Game::Lua::PushBoolean(L, 0); return 1; } - auto *fields = *reinterpret_cast( - unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *fields = + Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (fields == nullptr) { Game::Lua::PushBoolean(L, 0); return 1; } - const uint32_t unitFlags = *reinterpret_cast( - fields + Offsets::OFF_UNIT_FIELD_FLAGS); + const uint32_t unitFlags = + Game::Read(fields, Offsets::OFF_UNIT_FIELD_FLAGS); Game::Lua::PushBoolean(L, (unitFlags & Offsets::UNIT_FLAG_POSSESSED) != 0); return 1; diff --git a/src/unit/Identity.cpp b/src/unit/Identity.cpp index 79fa2cca..8295d2b4 100644 --- a/src/unit/Identity.cpp +++ b/src/unit/Identity.cpp @@ -47,12 +47,11 @@ static void __cdecl EnterWorld_h() { g_origEnterWorld(); // Only on a genuine commit — the rename / char-locked bail paths return // before the worker sets the state code to "entering world". - if (*reinterpret_cast( - static_cast(Offsets::VAR_GLUE_LOGIN_INPROGRESS)) != + if (Game::Read(Offsets::VAR_GLUE_LOGIN_INPROGRESS) != Offsets::GLUE_STATE_ENTERING_WORLD) return; - const uintptr_t charStruct = *reinterpret_cast( - static_cast(Offsets::VAR_GLUE_SELECTED_CHAR)); + const uintptr_t charStruct = + Game::Read(Offsets::VAR_GLUE_SELECTED_CHAR); if (charStruct != 0) g_charSelectGuid = *reinterpret_cast( charStruct + Offsets::OFF_GLUE_CHAR_GUID); @@ -86,11 +85,10 @@ static const Game::HookAutoRegister _enterWorldHook{ // this only makes the GUID *value* available early, for keying SavedVariables, // comparisons, our aura/cast caster checks, etc.) uint64_t PlayerGuid() { - auto *player = *reinterpret_cast( - static_cast(Offsets::VAR_LOCAL_PLAYER_PTR)); + auto *player = Game::Read(Offsets::VAR_LOCAL_PLAYER_PTR); if (player != nullptr) { - const uint64_t guid = *reinterpret_cast( - player + Offsets::OFF_LOCAL_PLAYER_GUID); + const uint64_t guid = + Game::Read(player, Offsets::OFF_LOCAL_PLAYER_GUID); if (guid != 0) return guid; // live engine value — authoritative } @@ -123,16 +121,15 @@ const uint8_t *PlayerDescriptor() { const uint8_t *player = PlayerObject(); if (player == nullptr) return nullptr; - return *reinterpret_cast( - player + Offsets::OFF_UNIT_DESCRIPTOR); + return Game::Read(player, Offsets::OFF_UNIT_DESCRIPTOR); } uint64_t GuidForObject(const void *unitObject) { if (unitObject == nullptr) return 0; const auto *unit = static_cast(unitObject); - const uint8_t *block = *reinterpret_cast( - unit + Offsets::OFF_UNIT_GUID_PTR); + const uint8_t *block = + Game::Read(unit, Offsets::OFF_UNIT_GUID_PTR); if (block == nullptr) return 0; return *reinterpret_cast(block); @@ -179,8 +176,7 @@ const char *NameForGuid(uint64_t guid) { const uint8_t *rec = PlayerInfoRecord(guid); if (rec == nullptr) return nullptr; - const char *name = - reinterpret_cast(rec + Offsets::OFF_PLAYER_INFO_NAME); + const char *name = Game::Ptr(rec, Offsets::OFF_PLAYER_INFO_NAME); return (name != nullptr && *name != '\0') ? name : nullptr; } @@ -287,8 +283,7 @@ const char *TokenFromGUID(uint64_t target, char *buf, size_t bufSize) { if (partyGuids[i] != 0) ++partyCount; } - int raidCount = *reinterpret_cast( - static_cast(Offsets::VAR_RAID_MEMBER_COUNT)); + int raidCount = Game::Read(Offsets::VAR_RAID_MEMBER_COUNT); if (raidCount > Offsets::RAID_MAX_SLOTS) raidCount = Offsets::RAID_MAX_SLOTS; diff --git a/src/unit/LineOfSight.cpp b/src/unit/LineOfSight.cpp index 46ec440a..af206ede 100644 --- a/src/unit/LineOfSight.cpp +++ b/src/unit/LineOfSight.cpp @@ -52,8 +52,7 @@ constexpr float kMaxTraceYards = 150.0f; // guard: raw call can crash beyond constexpr float kSamePointYards = 0.05f; int ObjectType(void *obj) { - return *reinterpret_cast(reinterpret_cast(obj) + - Offsets::OFF_CGOBJECT_TYPE_ID); + return Game::Read(obj, Offsets::OFF_CGOBJECT_TYPE_ID); } bool IsUnitOrPlayer(void *obj) { @@ -65,8 +64,8 @@ bool IsUnitOrPlayer(void *obj) { // CMovement sub-struct. 0 if the movement pointer is absent (degrades to a // foot-level trace rather than crashing). float EyeHeight(void *unit) { - const uint32_t cmov = *reinterpret_cast( - reinterpret_cast(unit) + Offsets::OFF_UNIT_MOVEMENT_INFO_PTR); + const uint32_t cmov = + Game::Read(unit, Offsets::OFF_UNIT_MOVEMENT_INFO_PTR); if (cmov == 0) return 0.0f; return *reinterpret_cast(cmov + diff --git a/src/unit/RaceBase.cpp b/src/unit/RaceBase.cpp index 4b1d1c59..a88462f0 100644 --- a/src/unit/RaceBase.cpp +++ b/src/unit/RaceBase.cpp @@ -59,13 +59,13 @@ int __fastcall Script_UnitRaceBase(void *L) { // tokens go through the unit descriptor. uint8_t raceByte = 0; if (Unit::Identity::IsPlayerToken(token)) { - raceByte = *reinterpret_cast(Offsets::VAR_PLAYER_RACE_BYTE); + raceByte = Game::Read(Offsets::VAR_PLAYER_RACE_BYTE); } else { auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); auto *unit = static_cast(resolve(token)); if (unit != nullptr) { - auto *desc = *reinterpret_cast( - unit + Offsets::OFF_UNIT_DESCRIPTOR); + auto *desc = + Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); if (desc != nullptr) raceByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE); } @@ -78,8 +78,8 @@ int __fastcall Script_UnitRaceBase(void *L) { const uint8_t *rec = Unit::Identity::PlayerInfoRecord( Unit::Identity::GuidForToken(token)); if (rec != nullptr) - raceByte = static_cast(*reinterpret_cast( - rec + Offsets::OFF_PLAYER_INFO_RACE)); + raceByte = static_cast( + Game::Read(rec, Offsets::OFF_PLAYER_INFO_RACE)); } } if (raceByte == 0) { diff --git a/src/unit/Tooltip.cpp b/src/unit/Tooltip.cpp index 5320aa23..260eaca8 100644 --- a/src/unit/Tooltip.cpp +++ b/src/unit/Tooltip.cpp @@ -113,10 +113,10 @@ static int __fastcall Script_GameTooltipGetUnitGUID(void *L) { return 0; const auto *base = static_cast(tooltipObj); - const uint32_t guidLo = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO); - const uint32_t guidHi = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI); + const uint32_t guidLo = + Game::Read(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO); + const uint32_t guidHi = + Game::Read(base, Offsets::OFF_TOOLTIP_UNIT_GUID_HI); if (guidLo == 0 && guidHi == 0) return 0; @@ -147,10 +147,10 @@ static int __fastcall Script_GameTooltipHasUnit(void *L) { return 1; } const auto *base = static_cast(tooltipObj); - const uint32_t guidLo = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO); - const uint32_t guidHi = *reinterpret_cast( - base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI); + const uint32_t guidLo = + Game::Read(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO); + const uint32_t guidHi = + Game::Read(base, Offsets::OFF_TOOLTIP_UNIT_GUID_HI); Game::Lua::PushBool(L, guidLo != 0 || guidHi != 0); return 1; } diff --git a/src/xml/Templates.cpp b/src/xml/Templates.cpp index 6bf3052c..0edfe4b9 100644 --- a/src/xml/Templates.cpp +++ b/src/xml/Templates.cpp @@ -60,19 +60,16 @@ const char *Attr(const uint8_t *node, const char *name) { } const uint8_t *FirstChild(const uint8_t *node) { - return *reinterpret_cast( - node + Offsets::OFF_XML_NODE_CHILD); + return Game::Read(node, Offsets::OFF_XML_NODE_CHILD); } const uint8_t *NextSibling(const uint8_t *node) { - return *reinterpret_cast( - node + Offsets::OFF_XML_NODE_SIBLING); + return Game::Read(node, Offsets::OFF_XML_NODE_SIBLING); } // Case-insensitive tag match, using the engine's own comparator (the same one // FUN_006f1eb0 uses to recognize "AbsDimension" etc.). bool TagEquals(const uint8_t *node, const char *tag) { - const char *t = *reinterpret_cast( - node + Offsets::OFF_XML_NODE_TAG); + const char *t = Game::Read(node, Offsets::OFF_XML_NODE_TAG); if (t == nullptr) return false; return reinterpret_cast(Offsets::FUN_SSTR_CMP_I)( @@ -119,35 +116,32 @@ void ReadSize(const uint8_t *node, double *outW, double *outH) { int __fastcall Script_GetTemplates(void *L) { Game::Lua::NewTable(L); // the result array - const uint32_t mask = - *reinterpret_cast(Offsets::VAR_XML_TEMPLATE_MASK); + const uint32_t mask = Game::Read(Offsets::VAR_XML_TEMPLATE_MASK); if (mask == 0xFFFFFFFFu) return 1; // no template has ever registered — empty array - const uint8_t *base = *reinterpret_cast( - Offsets::VAR_XML_TEMPLATE_TABLE); + const uint8_t *base = Game::Read(Offsets::VAR_XML_TEMPLATE_TABLE); if (base == nullptr) return 1; int outIdx = 0; for (uint32_t b = 0; b <= mask; ++b) { const uint8_t *bucket = base + b * Offsets::XML_TEMPLATE_BUCKET_STRIDE; - const int linkOff = *reinterpret_cast( - bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_LINKOFF); - const uint8_t *node = *reinterpret_cast( - bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_HEAD); + const int linkOff = Game::Read( + bucket, Offsets::OFF_XML_TEMPLATE_BUCKET_LINKOFF); + const uint8_t *node = Game::Read( + bucket, Offsets::OFF_XML_TEMPLATE_BUCKET_HEAD); // Walk the intrusive chain; the tail sentinel has its low bit set // (mirrors the engine's own traversal in FUN_006ee6f0). while (node != nullptr && (reinterpret_cast(node) & 1) == 0) { - const char *name = *reinterpret_cast( - node + Offsets::OFF_XML_TEMPLATE_NODE_NAME); - const uint8_t *def = *reinterpret_cast( - node + Offsets::OFF_XML_TEMPLATE_NODE_DEF); + const char *name = Game::Read( + node, Offsets::OFF_XML_TEMPLATE_NODE_NAME); + const uint8_t *def = Game::Read( + node, Offsets::OFF_XML_TEMPLATE_NODE_DEF); const char *type = (def != nullptr) - ? *reinterpret_cast( - def + Offsets::OFF_XML_NODE_TAG) + ? Game::Read(def, Offsets::OFF_XML_NODE_TAG) : nullptr; ++outIdx; @@ -177,8 +171,7 @@ int __fastcall Script_GetTemplateInfo(void *L) { Game::Lua::NewTable(L); // XMLTemplateInfo - const char *type = *reinterpret_cast( - node + Offsets::OFF_XML_NODE_TAG); + const char *type = Game::Read(node, Offsets::OFF_XML_NODE_TAG); Game::Lua::SetFieldString(L, "type", type != nullptr ? type : ""); double w = 0.0, h = 0.0;