diff --git a/src/unit/TokenObserver.cpp b/src/unit/TokenObserver.cpp index 75f21c4f..660ebaf6 100644 --- a/src/unit/TokenObserver.cpp +++ b/src/unit/TokenObserver.cpp @@ -55,6 +55,21 @@ const char *const *EventNames() { static_cast(Offsets::VAR_EVENT_NAME_TABLE_STATIC)); } +// Both register and unregister funnel through `FUN_00464890`, which +// dereferences the client/player-rooted observer registry at +// `[VAR_LOCAL_PLAYER_PTR]` (reads its `+0x24` mask). That root is NULL out of +// world — login screen, loading screens, logout teardown — where the engine +// helper null-derefs (crash: `MOV EAX,[EDX+0x24]`, EDX=0). Bail when it isn't +// up: there are no live objects or observer nodes to touch anyway (nodes die +// with their objects during teardown), and in-world callers re-register/clean +// up on the next tick. Unlike `Player::Equipment` (which only ever registers +// from the enter-world hook), our consumers register from Lua / WorldTick, +// which can run mid-transition — hence the guard here. +bool RegistryReady() { + return *reinterpret_cast( + static_cast(Offsets::VAR_LOCAL_PLAYER_PTR)) != nullptr; +} + // Bytes the engine watches for the observer on event index `i` — verbatim // from `FUN_0051bbb0`'s size switch. The 8-byte entries are the 64-bit GUID // fields; index 0x29 (`UNIT_FIELD_AURA`) spans the whole 0xD8 aura block. @@ -80,7 +95,7 @@ int SizeForIndex(int i) { } // namespace void Register(uint64_t guid, FieldCallback cb) { - if (guid == 0 || cb == nullptr) + if (guid == 0 || cb == nullptr || !RegistryReady()) return; auto reg = reinterpret_cast(Offsets::FUN_DESC_OBSERVER_REGISTER); const char *const *names = EventNames(); @@ -95,7 +110,7 @@ void Register(uint64_t guid, FieldCallback cb) { } void Unregister(uint64_t guid, FieldCallback cb) { - if (guid == 0 || cb == nullptr) + if (guid == 0 || cb == nullptr || !RegistryReady()) return; auto unreg = reinterpret_cast(Offsets::FUN_DESC_OBSERVER_UNREGISTER);