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:
@@ -113,10 +113,10 @@ static int __fastcall Script_GameTooltipGetUnitGUID(void *L) {
|
||||
return 0;
|
||||
|
||||
const auto *base = static_cast<const uint8_t *>(tooltipObj);
|
||||
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
|
||||
base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
|
||||
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
|
||||
base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
|
||||
const uint32_t guidLo =
|
||||
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
|
||||
const uint32_t guidHi =
|
||||
Game::Read<uint32_t>(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<const uint8_t *>(tooltipObj);
|
||||
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
|
||||
base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
|
||||
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
|
||||
base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
|
||||
const uint32_t guidLo =
|
||||
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
|
||||
const uint32_t guidHi =
|
||||
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
|
||||
Game::Lua::PushBool(L, guidLo != 0 || guidHi != 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user