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 -17
View File
@@ -34,6 +34,7 @@
#include "Offsets.h"
#include "item/CGItem.h"
#include "item/Location.h"
#include "item/Record.h"
#include "unit/Identity.h"
#include "tick/WorldTick.h"
@@ -44,10 +45,6 @@ namespace Merchant::Frame {
namespace {
using GetItemRecord_t = const uint8_t *(__thiscall *)(
void *cache, uint32_t itemID, const uint64_t *guid,
void *callback, void *userData, bool requestIfMissing);
// Read the 64-bit merchant NPC GUID. Both halves zero means no
// merchant window is open and the rest of the merchant globals are
// stale.
@@ -82,23 +79,11 @@ uint64_t ItemGUIDFromCGItem(const uint8_t *cgItem) {
instance + Offsets::OFF_INSTANCE_BLOCK_GUID);
}
// Same `PeekItemRecord` pattern Item::Bag / Item::Equipment use —
// inline cache peek with a null callback (no network round-trip on
// miss). Same call shape `Item::Info::FetchItemRecord` uses; not
// shared because each module has its own slightly different needs.
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, false);
}
// Looks up `itemID` in the ItemStats cache and reads quality from
// `+0x1C`. Quality 0 = Poor (grey junk). Returns -1 on cache miss
// so callers can distinguish "not loaded" from "loaded poor-quality".
int ItemQuality(uint32_t itemID) {
auto *record = PeekItemRecord(itemID);
auto *record = Item::PeekRecord(itemID);
if (record == nullptr)
return -1;
return static_cast<int>(*reinterpret_cast<const uint32_t *>(