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
+6 -8
View File
@@ -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<const uint8_t *>(fs);
if (*reinterpret_cast<const uint32_t *>(f + Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u)
if (Game::Read<uint32_t>(fs, Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u)
return 0xFFu;
const uint8_t *colors =
*reinterpret_cast<const uint8_t *const *>(f + Offsets::OFF_FONTSTRING_COLOR_ARRAY);
const uint8_t *colors = Game::Read<const uint8_t *>(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<uint32_t *>(Offsets::VAR_TEXTURE_BLEND_DEFAULT);
const uint32_t blend = Game::Read<uint32_t>(Offsets::VAR_TEXTURE_BLEND_DEFAULT);
reinterpret_cast<SetTexture_t>(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<float *>(reinterpret_cast<uint8_t *>(r.tex) +
Offsets::OFF_LAYOUT_SCALE);
float sReg = Game::Read<float>(r.tex, Offsets::OFF_LAYOUT_SCALE);
if (!(sReg > 0.01f && sReg < 100.0f))
sReg = *reinterpret_cast<float *>(f + Offsets::OFF_LAYOUT_SCALE);
sReg = Game::Read<float>(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