refactor(item): name CGItem deref idioms via Item::InstanceBlock / ObjectFields

Add item/CGItem.{h,cpp} with two null-safe accessors for a CGItem's two
descriptor-like pointers:
  InstanceBlock(cgItem) -> CGItem + 0x08 (item GUID @ +0, itemID @ +0x0C)
  ObjectFields(cgItem)  -> CGItem + 0x114 (stack/flags/charges/durability/...)

Replace the 30 hand-written `*reinterpret_cast<const uint8_t *const *>(x +
OFF_ITEM_INSTANCE_BLOCK/OFF_ITEM_DESCRIPTOR)` derefs across 24 files with
these calls. Behavior-preserving: same deref, all reads were already const,
and each site keeps its own null-check and field reads. Helpers add a
cgItem null guard (strictly safer).
This commit is contained in:
Brues
2026-08-08 15:08:34 -05:00
parent 2612118ff6
commit 8fa344a084
26 changed files with 126 additions and 60 deletions
+2 -2
View File
@@ -20,6 +20,7 @@
#include "Game.h"
#include "Offsets.h"
#include "item/CGItem.h"
#include "item/Location.h"
#include <cstdint>
@@ -36,8 +37,7 @@ static int __fastcall Script_GetStackCount(void *L) {
Game::Lua::PushNumber(L, 0.0);
return 1;
}
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
item + Offsets::OFF_ITEM_DESCRIPTOR);
auto *descriptor = Item::ObjectFields(item);
if (descriptor == nullptr) {
Game::Lua::PushNumber(L, 0.0);
return 1;