unit: guard TokenObserver against a null observer-registry root

Register/Unregister funnel through FUN_00464890, which dereferences the
client/player-rooted observer registry at [VAR_LOCAL_PLAYER_PTR] (+0x24).
That root is null out of world (login, loading screens, logout teardown),
where the helper null-derefs -> ERROR #132 (ACCESS_VIOLATION reading 0x24).

The nameplate teardown on world-exit fires NAME_PLATE_UNIT_REMOVED for
every plate, each calling Unregister while the root was already null ->
crash. Player::Equipment never hit this because it only registers from the
enter-world hook; focus/nameplate register from Lua / WorldTick, which can
run mid-transition.

Gate both Register and Unregister on RegistryReady() ([VAR_LOCAL_PLAYER_PTR]
!= null). Out of world there are no live objects or observer nodes to touch
anyway - nodes die with their objects on teardown, and in-world callers
re-register / clean up on the next tick.
This commit is contained in:
Brues
2026-07-24 18:10:42 -05:00
parent d7078827fd
commit e7e2fe05dc
+17 -2
View File
@@ -55,6 +55,21 @@ const char *const *EventNames() {
static_cast<uintptr_t>(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<void *const volatile *>(
static_cast<uintptr_t>(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<Register_t>(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<Unregister_t>(Offsets::FUN_DESC_OBSERVER_UNREGISTER);