fix(nameplate): retry CREATED and UNIT_ADDED until they fire

A plate was marked seen before NAME_PLATE_CREATED was sent, and a GUID
entered the tick snapshot before NAME_PLATE_UNIT_ADDED was sent. When a
fire was dropped because its event slot was not claimed yet, the plate
was never announced again until /reload cleared the diff state. pfUI
builds its overlay on CREATED and finds it on ADDED, so such a plate
kept Blizzard's look (brues-code/pfUI#59).

FireWithFrame now reports whether the event went out, and a plate is
marked seen only then. ADDED waits for its slot AND for its frame's
CREATED, so a handler never gets a unit for a plate it was not
introduced to. A deferred GUID gets no token slot and no observers, and
is left out of the snapshot, so the next tick retries it and no REMOVED
fires for an ADDED that never went out.

Not verified in game: the dropped-slot case cannot be forced here, so
only the normal path was built and deployed.
This commit is contained in:
Brues
2026-09-25 10:34:40 -05:00
parent 3467513df9
commit 74b49619ed
+37 -6
View File
@@ -73,6 +73,11 @@ std::unordered_map<uint64_t, const void *> g_lastTickPlates;
// cycle every frame — `clear()` keeps the existing bucket capacity.
std::unordered_map<uint64_t, const void *> g_currentTickPlates;
// GUIDs whose ADDED couldn't go out this tick (see `OnWorldTick`). Dropped
// from the snapshot before the swap so the next tick sees them as new again.
// File-static for the same reuse-the-capacity reason as the maps above.
std::vector<uint64_t> g_deferredAdds;
// Frame pointers we've ever surfaced as nameplate plates. First
// sighting fires NAME_PLATE_CREATED; same pointer reappearing (pool
// reuse) doesn't refire.
@@ -185,20 +190,23 @@ int __fastcall NamePlateFieldCb(uint32_t fieldOffset, uint32_t /*size*/,
// fire so we don't leak our frame into unrelated global state.
//
// Lua-stack-clean: stack depth on entry == stack depth on exit.
//
// Returns whether the event went out. `false` when the slot isn't claimed yet
// or there's no Lua state — the caller must not treat the plate as announced.
using LuaRefRef_t = int(__fastcall *)(void *L, int t);
using LuaRefUnref_t = void(__fastcall *)(void *L, int t, int ref);
using LuaRawGetI_t = void(__fastcall *)(void *L, int t, int n);
void FireWithFrame(const Event::Custom::AutoReserve &event, void *frame) {
bool FireWithFrame(const Event::Custom::AutoReserve &event, void *frame) {
if (frame == nullptr)
return;
return false;
const int slot = event.Slot();
if (slot < 0)
return;
return false;
void *L = Game::Lua::State();
if (L == nullptr)
return;
return false;
auto refRef = reinterpret_cast<LuaRefRef_t>(
static_cast<uintptr_t>(Offsets::LUA_REF_REF));
@@ -225,6 +233,7 @@ void FireWithFrame(const Event::Custom::AutoReserve &event, void *frame) {
rawgeti(L, Game::Lua::REGISTRY_INDEX, savedRef);
Game::Lua::SetTable(L, Game::Lua::GLOBALS_INDEX);
refUnref(L, Game::Lua::REGISTRY_INDEX, savedRef);
return true;
}
void OnWorldTick() {
@@ -244,10 +253,27 @@ void OnWorldTick() {
// GUIDs not in last tick's snapshot. The slot is assigned *before*
// firing so the token resolves to the newly-added plate during the
// event handler.
//
// Neither event is recorded as sent until it actually goes out. A fire
// dropped because its slot isn't claimed yet retries next tick; otherwise
// the plate stays unannounced until /reload clears the diff state. ADDED
// also waits for its frame's CREATED, so a handler never gets a unit for a
// plate it hasn't been introduced to. A deferred GUID gets no token slot
// and no observers, and is kept out of the snapshot, so it produces no
// REMOVED for an ADDED that never fired.
g_deferredAdds.clear();
for (const auto &kv : g_currentTickPlates) {
if (g_seenPlates.insert(kv.second).second)
FireWithFrame(_evtCreated, const_cast<void *>(kv.second));
bool announced = g_seenPlates.find(kv.second) != g_seenPlates.end();
if (!announced &&
FireWithFrame(_evtCreated, const_cast<void *>(kv.second))) {
g_seenPlates.insert(kv.second);
announced = true;
}
if (g_lastTickPlates.find(kv.first) == g_lastTickPlates.end()) {
if (!announced || _evtUnitAdded.Slot() < 0) {
g_deferredAdds.push_back(kv.first);
continue;
}
const int slot = AssignSlot(kv.first);
// Watch this unit's fields so UNIT_HEALTH/UNIT_AURA/… fire with
// its "nameplateN" token (the engine only watches its own
@@ -289,6 +315,11 @@ void OnWorldTick() {
}
}
// After the REMOVED pass, which needs every bound frame for
// `PlateReassigned`.
for (uint64_t guid : g_deferredAdds)
g_currentTickPlates.erase(guid);
g_lastTickPlates.swap(g_currentTickPlates);
}