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:
+8
-8
@@ -32,7 +32,7 @@ uint32_t PlayerSpellFamily() {
|
||||
auto *unit = static_cast<const uint8_t *>(resolve("player"));
|
||||
if (unit == nullptr)
|
||||
return 0;
|
||||
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)
|
||||
return 0;
|
||||
const uint8_t classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
|
||||
@@ -40,7 +40,7 @@ uint32_t PlayerSpellFamily() {
|
||||
Offsets::VAR_CHRCLASSES_COUNT, classByte);
|
||||
if (cls == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint32_t *>(cls + Offsets::OFF_CHRCLASSES_SPELL_FAMILY);
|
||||
return Game::Read<uint32_t>(cls, Offsets::OFF_CHRCLASSES_SPELL_FAMILY);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -49,18 +49,18 @@ float Apply(const uint8_t *spellRecord, int op, float base) {
|
||||
if (spellRecord == nullptr)
|
||||
return base;
|
||||
|
||||
const uint32_t familyName = *reinterpret_cast<const uint32_t *>(
|
||||
spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_NAME);
|
||||
const uint32_t attrEx3 = *reinterpret_cast<const uint32_t *>(
|
||||
spellRecord + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3);
|
||||
const uint32_t familyName = Game::Read<uint32_t>(
|
||||
spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_NAME);
|
||||
const uint32_t attrEx3 = Game::Read<uint32_t>(
|
||||
spellRecord, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3);
|
||||
if (familyName == 0 ||
|
||||
(attrEx3 & Offsets::SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS) != 0)
|
||||
return base;
|
||||
if (familyName != PlayerSpellFamily())
|
||||
return base;
|
||||
|
||||
const uint64_t familyFlags = *reinterpret_cast<const uint64_t *>(
|
||||
spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS);
|
||||
const uint64_t familyFlags = Game::Read<uint64_t>(
|
||||
spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS);
|
||||
if (familyFlags == 0)
|
||||
return base;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user