mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +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:
@@ -79,13 +79,13 @@ int __fastcall Script_UnitClassBase(void *L) {
|
||||
// tokens go through the unit descriptor.
|
||||
uint8_t classByte = 0;
|
||||
if (Unit::Identity::IsPlayerToken(token)) {
|
||||
classByte = *reinterpret_cast<const uint8_t *>(Offsets::VAR_PLAYER_CLASS_BYTE);
|
||||
classByte = Game::Read<uint8_t>(Offsets::VAR_PLAYER_CLASS_BYTE);
|
||||
} else {
|
||||
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
|
||||
auto *unit = static_cast<const uint8_t *>(resolve(token));
|
||||
if (unit != nullptr) {
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
unit + Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
auto *desc =
|
||||
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
if (desc != nullptr)
|
||||
classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
|
||||
}
|
||||
@@ -98,8 +98,8 @@ int __fastcall Script_UnitClassBase(void *L) {
|
||||
const uint8_t *rec = Unit::Identity::PlayerInfoRecord(
|
||||
Unit::Identity::GuidForToken(token));
|
||||
if (rec != nullptr)
|
||||
classByte = static_cast<uint8_t>(*reinterpret_cast<const uint32_t *>(
|
||||
rec + Offsets::OFF_PLAYER_INFO_CLASS));
|
||||
classByte = static_cast<uint8_t>(
|
||||
Game::Read<uint32_t>(rec, Offsets::OFF_PLAYER_INFO_CLASS));
|
||||
}
|
||||
}
|
||||
if (classByte == 0) {
|
||||
|
||||
Reference in New Issue
Block a user