refactor: centralize engine field/global access via Game::Read/Ref/Ptr

Replace the raw `*reinterpret_cast<const T *>(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<T>(base, offset)  field value read
  Game::Ref<T>(base, offset)   writable field lvalue
  Game::Ptr<T>(base, offset)   pointer to a field (arrays / out-params)
  Game::Read<T>(address) / Ref<T>(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<uint8_t*>(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.
This commit is contained in:
Brues
2026-08-19 11:01:19 -05:00
parent bd14a93a11
commit c54556f6a1
84 changed files with 947 additions and 1032 deletions
+5 -5
View File
@@ -115,8 +115,8 @@ static int ResolveLocationToItemID(void *L, int idx) {
auto *instance = Item::InstanceBlock(item);
if (instance == nullptr)
return 0;
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
instance + Offsets::OFF_INSTANCE_BLOCK_ITEM_ID));
return static_cast<int>(Game::Read<uint32_t>(
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<const uint64_t *const *>(
invMgr + Offsets::OFF_INVMGR_GUID_ARRAY);
auto *guids = Game::Read<const uint64_t *>(
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<int>(
*reinterpret_cast<const uint32_t *>(bagInv + Offsets::OFF_INVMGR_SLOT_COUNT));
Game::Read<uint32_t>(bagInv, Offsets::OFF_INVMGR_SLOT_COUNT));
if (count > 0)
CollectOwnedFrom(bagInv, 0, count - 1);
}