refactor(item): centralize passive item-cache peek in Item::PeekRecord

Add item/Record.{h,cpp} with Item::PeekRecord(itemID) -- the passive
ItemStats_C cache peek (null callback, no network query). Route the three
duplicate implementations through it:
  - the per-module GetItemRecord_t typedef + fn(cache,id,&zero,nullptr,
    nullptr,0) call in ~25 read-only item accessors
  - Item::StatAccum::FetchRecord (deleted; 7 callers repointed)
  - item/Tooltip.cpp's local PeekItemRecord (deleted)

Behavior-identical: every converted call was already a passive peek with
identical args (dedup flag is a no-op when the callback is null).

item/Data.cpp is deliberately untouched -- it owns the ACTIVE fetch
(CacheFetch passes a real callback to fire SMSG_ITEM_QUERY_SINGLE, the
load-bearing cache-race path in CLAUDE.md) and keeps its own typedef.
This commit is contained in:
Brues
2026-08-08 15:35:07 -05:00
parent 0df8885045
commit 13008ab8aa
34 changed files with 136 additions and 360 deletions
+2 -11
View File
@@ -22,6 +22,7 @@
#include "CGItem.h"
#include "ID.h"
#include "Link.h"
#include "Record.h"
#include <cstring>
@@ -32,9 +33,6 @@ namespace {
using GetItemBySlot_t = void *(__thiscall *)(void *thisInvMgr, int slot);
using PackBagSlot_t = int(__fastcall *)(void *L, void **outInvMgr, int *outLinearSlot,
int *outUnused);
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
const uint64_t *guid, void *callback,
void *userData, int unused);
// Reads `loc.fieldName` and returns it as an int. Returns false via the
// boolean result if the field is missing or non-numeric. Always leaves the
@@ -58,13 +56,6 @@ const uint8_t *ResolveBagSlot(void *L, int bagID, int slotIndex) {
// --- GUID-walk helpers ---------------------------------------------------
const uint8_t *PeekItemRecord(uint32_t itemID) {
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
const uint64_t zeroGuid = 0;
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
}
uint64_t ReadCGItemGUID(const uint8_t *item) {
auto *instance = Item::InstanceBlock(item);
if (instance == nullptr)
@@ -125,7 +116,7 @@ int GetBagSlotCount(int bagID) {
const int bagItemID = Item::ID::FromCGItem(bagItem);
if (bagItemID == 0)
return 0;
auto *record = PeekItemRecord(static_cast<uint32_t>(bagItemID));
auto *record = Item::PeekRecord(static_cast<uint32_t>(bagItemID));
if (record == nullptr)
return 0;
return static_cast<int>(*reinterpret_cast<const uint32_t *>(