mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
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:
+5
-5
@@ -49,14 +49,14 @@ int64_t ComputeCurrentEpoch() {
|
||||
auto *base = reinterpret_cast<const uint8_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_GAMETIME_STRUCT));
|
||||
|
||||
const int year = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_YEAR);
|
||||
const int year = Game::Read<int>(base, Offsets::OFF_GAMETIME_YEAR);
|
||||
if (year <= 0)
|
||||
return 0; // pre-login / not yet sync'd
|
||||
|
||||
const int month = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_MONTH);
|
||||
const int day = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_DAY);
|
||||
const int hour = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_HOUR);
|
||||
const int minute = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_MINUTE);
|
||||
const int month = Game::Read<int>(base, Offsets::OFF_GAMETIME_MONTH);
|
||||
const int day = Game::Read<int>(base, Offsets::OFF_GAMETIME_DAY);
|
||||
const int hour = Game::Read<int>(base, Offsets::OFF_GAMETIME_HOUR);
|
||||
const int minute = Game::Read<int>(base, Offsets::OFF_GAMETIME_MINUTE);
|
||||
|
||||
const DWORD now = GetTickCount();
|
||||
if (year != g_lastYear || month != g_lastMonth || day != g_lastDay ||
|
||||
|
||||
Reference in New Issue
Block a user