mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
GameObject analog of C_CreatureInfo, reading the gameobject cache
(gameobjectcache.wdb, SMSG_GAMEOBJECT_QUERY_RESPONSE):
- GetGameObjectInfoByID -> { gameObjectID, name, type, displayID } | nil
(synchronous peek)
- RequestLoadGameObjectByID -> bool, fires GAMEOBJECT_DATA_LOAD_RESULT
when an uncached GO arrives.
The GO cache is a sibling class of the creature cache: same hash-map
shape but a different vtable and a larger entry (loaded flag at
entry+0x98 vs +0x50), so it has its own _GetRecord (FUN_00558560) and
response parser (FUN_005588E0). Generalized Cache::QueryLoad to take a
per-cache _GetRecord via Register and to hook BOTH parsers (creature +
gameobject), dispatching completion by cache instance. Renamed the
creature offsets FUN_CACHE_* -> FUN_CREATURE_* now that "generic" was a
misnomer.
GO field offsets: name@+0x08 verified (FUN_0062dc10 reads [block+0x08]),
type@+0x00 / displayID@+0x04 from the wire/WDB order. Verified in-game:
Mesa Elevator 47297 type 11 displayID 360, Windrunner 176250 type 15
displayID 7087, and RequestLoadGameObjectByID populated an uncached GO
("Lighting Impact Large", type 5). Creature path re-verified after the
refactor (GetCreatureInfoByID + the load event still work).
66 lines
3.2 KiB
C++
66 lines
3.2 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU Lesser General Public License as published by the Free Software Foundation, either
|
|
// version 3 of the License, or (at your option) any later version.
|
|
//
|
|
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
// Shared async-load machinery for the client query caches that aren't
|
|
// item/quest — creature, gameobject, and (potentially) the other
|
|
// SMSG_*_QUERY caches. Modeled on `Item::Data`'s pending/timeout/event
|
|
// logic, generalized so several caches share one set of code.
|
|
//
|
|
// These caches are sibling classes: they share the record/entry hash-map
|
|
// shape but differ in `_GetRecord` and response-parser per class (the
|
|
// creature class reads its loaded flag at entry+0x50, the gameobject
|
|
// class at +0x98, etc.). So a module registers BOTH its cache's
|
|
// `_GetRecord` address and the dispatcher routes completion by cache
|
|
// instance. The dispatcher hooks each class's response parser (MinHook
|
|
// allows only one hook per target, but the parsers are distinct
|
|
// functions, so hooking creature's and gameobject's separately is fine);
|
|
// item/quest have their own parsers and aren't touched.
|
|
//
|
|
// static const char *kEvent = "CREATURE_DATA_LOAD_RESULT";
|
|
// static const Event::Custom::AutoReserve _r{kEvent}; // reserve the event
|
|
// ...
|
|
// Cache::QueryLoad::Register(cacheInstance, kEvent,
|
|
// Offsets::FUN_CREATURE_GET_RECORD); // at init
|
|
// Cache::QueryLoad::RequestLoad(cacheInstance, id); // fire a load
|
|
//
|
|
// The completion event fires as `(id: number, success: bool)` — success
|
|
// when the cache fills, failure on timeout.
|
|
|
|
namespace Cache::QueryLoad {
|
|
|
|
// Register a query cache for async-load tracking. `cacheInstance` is the
|
|
// cache global (e.g. `Offsets::VAR_CREATURE_CACHE` cast to void*);
|
|
// `eventName` is a Custom event the caller has reserved via
|
|
// `Event::Custom::AutoReserve`, fired `(id, success)` on completion;
|
|
// `getRecordAddr` is the cache class's `_GetRecord` (e.g.
|
|
// `Offsets::FUN_CREATURE_GET_RECORD`). `cacheInstance`/`eventName` must
|
|
// outlive the process (pass static values). Idempotent — calling again
|
|
// for the same cache is a no-op (safe across /reload).
|
|
void Register(void *cacheInstance, const char *eventName, uintptr_t getRecordAddr);
|
|
|
|
// True if `id` is already in the cache (pure peek, no network query).
|
|
bool IsCached(void *cacheInstance, uint32_t id);
|
|
|
|
// Issue an async load for `id`. If already cached, fires the completion
|
|
// event with success synchronously. Otherwise sends the query and tracks
|
|
// the id until the response lands (or it times out). Returns false only
|
|
// if the cache isn't registered or its pending set is full; true
|
|
// otherwise (already-cached, already-pending, or newly-tracked).
|
|
bool RequestLoad(void *cacheInstance, uint32_t id);
|
|
|
|
} // namespace Cache::QueryLoad
|