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
+4 -7
View File
@@ -60,12 +60,10 @@ void Push(void *L, void *frame) {
static_cast<uintptr_t>(Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER));
auto *cobj = static_cast<uint8_t *>(frame);
int refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
int refKey = Game::Read<int>(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
if (refKey <= 0) {
scriptRegister(frame, nullptr, nullptr);
refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
refKey = Game::Read<int>(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<int *>(cobj + Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0;
Game::Ref<int>(cobj, Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0;
scriptRegister(frame, nullptr, nullptr);
refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
refKey = Game::Read<int>(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
}