diff --git a/src/Offsets.h b/src/Offsets.h index e7c94d32..307ce9c6 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -9269,13 +9269,6 @@ enum Offsets { // `RET 0x4` (callee cleans the one stack arg). FUN_WORLD_TICK = 0x0066FD50, - // The world frame counter (`s_frameCounter`): FUN_WORLD_TICK increments it - // once a frame (`inc dword [0xC7B2C8]` at 0x0066FDFC, bytes verified in - // WoW.exe), before the scene draws. The engine's scene code compares a - // per-object stamp against it to do work once per frame (0x00683747); - // use it the same way to reuse a result within one frame. uint32, wraps. - VAR_WORLD_FRAME_COUNTER = 0x00C7B2C8, - // UI render root — the CSimpleTop singleton's (`DAT_00cf0bd8`) per-frame // render callback. Registered at priority 1.0 into the global HLAYER list // (`FUN_00442800`) and drained every frame by the master scene-render pump diff --git a/src/target/SoftInteract.cpp b/src/target/SoftInteract.cpp index 79e836f6..0d1c1372 100644 --- a/src/target/SoftInteract.cpp +++ b/src/target/SoftInteract.cpp @@ -73,10 +73,10 @@ CVar::Factory::Handle g_range = nullptr; CVar::Factory::Handle g_rangeIsHard = nullptr; uint64_t g_soft = 0; -// The frame of the last pick; `g_picked` false forces the next read to pick +// The drain of the last pick; `g_picked` false forces the next read to pick // (a cvar changed). See Refresh. bool g_picked = false; -uint32_t g_pickedFrame = 0; +uint32_t g_pickedDrain = 0; // ── The hover cursor's verdict ─────────────────────────────────────────── @@ -126,16 +126,15 @@ void Set(uint64_t guid) { guid ? Guid::FormatAsString(guid, newBuf, sizeof newBuf) : nullptr); } -// One pick per frame, shared by every read in it (the icon, Lua's token -// reads, the listener tick): the scan reads what the scene drew, which changes -// only when the next frame draws — the counter the engine's scene code keys -// its own per-frame work on. +// One pick per scene drain, shared by every read until the next (the icon, +// Lua's token reads, the listener tick): the scan reads what the last drain +// drew, which changes only when the next one does. void Refresh() { - const uint32_t frame = Game::Read(Offsets::VAR_WORLD_FRAME_COUNTER); - if (g_picked && g_pickedFrame == frame) + const uint32_t drain = SoftTarget::Drains(); + if (g_picked && g_pickedDrain == drain) return; g_picked = true; - g_pickedFrame = frame; + g_pickedDrain = drain; Set(SoftTarget::Enabled(g_enable) ? Pick() : 0); } diff --git a/src/target/SoftTarget.cpp b/src/target/SoftTarget.cpp index 3bd93c31..bdcfe4eb 100644 --- a/src/target/SoftTarget.cpp +++ b/src/target/SoftTarget.cpp @@ -13,8 +13,8 @@ // The soft-target scan, from 1.12's own pieces: // -// - "On screen" is the tab-target collector's IsEntityDrawn on the -// object's world node. +// - "On screen" is the scene's own election: an entity the last drain +// drew in pass 1 (below). // - The arc (SoftTargetArc: 0 = directly in front, 1 = in the front // yaw arc, 2 = anywhere in the targeting area): 1 is the tab collector's // front cone (pi/6 either side, from the engine's own floats); 0 is a @@ -28,18 +28,22 @@ // - The closest candidate wins — Classic Era 1.15 probes for interact, // enemy and friend alike, not the one nearest the forward line. // -// Scan only on the UI frame tick or from Lua, never on the world tick: -// there every world node reads as culled (probe: 3 drawn from Lua, 0 on the -// world tick), while the UI pass — where the engine's own hover -// classification runs, CGWorldFrame::OnUpdate — and Lua see the drawn state. -// // The candidates are the scene's entities in sight, not the whole object // manager. DrawEntityModels (0x683DD0) calls each entity's render callback // WorldObjectRenderCallback (0x481540) once a frame — pass 1 for those in // sight, pass 2 for the rest of the scene's bands, whose models it hides — // so hooking the callback collects the in-sight GUIDs as the scene draws // them, and hooking the drain publishes them when it returns: a scan reads a -// finished drain's list, never one still filling. Stormwind probe, 34 s: +// finished drain's list, never one still filling. Pass 1 is the drawn set +// itself: the cull walk clears bit 0 of an entity's cull state `+0x94` — what +// IsEntityDrawn (0x6704C0) reads — exactly as it moves the entity to the draw +// list the drain calls with pass 1 (benilla-re terrain/scene.md "Entity +// cull", "Object election"). The list is that verdict kept, so it holds until +// the next drain; asking IsEntityDrawn instead is right only between the +// drain and the next paint, which resets every node to culled after the +// world tick. A read in that window — a Lua UnitBuff naming its caster's +// token before the scene draws — found nothing drawn, and the pick it cached +// hid the soft-target icons for that frame. Stormwind probe, 34 s: // ~200 pass-1 and ~360 pass-2 entities a frame, no pass-2 entity ever // IsEntityDrawn, and no IsEntityDrawn object missing from the list (checked // by a full ClntObjMgrEnumObjects walk beside it). That walk is what this @@ -77,7 +81,6 @@ namespace { using Forward_t = void(__thiscall *)(void *camera, float *out); using Heading_t = float(__fastcall *)(const float *from, const float *to); -using IsDrawn_t = uint32_t(__fastcall *)(void *node, void *edx); // `ctx` (the node's callback argument) is unused; the object comes from the // GUID. RET 0xC. using EntityRender_t = int(__fastcall *)(void *ctx, int pass, uint32_t guidLo, uint32_t guidHi, @@ -98,6 +101,7 @@ struct Entity { std::vector g_drawing; std::vector g_entities; bool g_inDrain = false; +uint32_t g_drains = 0; // finished drains, each a new g_entities bool g_inEntity = false; // inside a pass-1 callback, whose entity is g_drawing.back() // The window the objects in `g_entities` are live in: closed by the next // incoming packet, and only under the manager the drain ran with. @@ -129,6 +133,7 @@ void __cdecl DrawEntityModels_h() { g_origDrawEntityModels(); g_inDrain = false; g_entities.swap(g_drawing); + ++g_drains; g_objectsLive = true; g_objectsManager = Game::Read(Offsets::VAR_LOCAL_PLAYER_PTR); } @@ -176,11 +181,6 @@ bool CameraYaw(float &yaw) { return true; } -bool IsDrawn(const void *object) { - void *node = Game::Read(object, Offsets::OFF_CGOBJECT_WORLD_OBJECT); - return reinterpret_cast(Offsets::FUN_WORLD_OBJECT_VISIBLE)(node, nullptr) != 0; -} - bool InArc(const Area &a, const float pos[3]) { if (a.arc >= 2) return true; @@ -197,10 +197,9 @@ bool InArc(const Area &a, const float pos[3]) { return std::cos(angle) > 0.0f && std::fabs(flat * std::sin(angle)) <= kArc0HalfWidth; } -// Drawn, and where: the checks before the arc, which needs the position. +// Where: the checks before the arc, which needs the position. bool Locate(const Area &a, void *object, float pos[3], float &distSq) { - if (object == nullptr || object == a.player || !IsDrawn(object) || - !Unit::Position::Read(object, pos)) + if (object == nullptr || object == a.player || !Unit::Position::Read(object, pos)) return false; const float dx = pos[0] - a.pos[0]; const float dy = pos[1] - a.pos[1]; @@ -270,9 +269,14 @@ bool Begin(Area &area, CVar::Factory::Handle arc, CVar::Factory::Handle range, return true; } -bool InView(const Area &area, void *object, float &distSq) { +uint32_t Drains() { return g_drains; } + +bool InView(const Area &area, uint64_t guid, void *object, float &distSq) { float pos[3]; - return Locate(area, object, pos, distSq) && InArc(area, pos); + for (const Entity &e : g_entities) + if (e.guid == guid) + return Locate(area, object, pos, distSq) && InArc(area, pos); + return false; } uint64_t Nearest(const Area &area, int typeMask, Accept accept, void *ctx) { diff --git a/src/target/SoftTarget.h b/src/target/SoftTarget.h index dc8e9b94..c729aed6 100644 --- a/src/target/SoftTarget.h +++ b/src/target/SoftTarget.h @@ -42,9 +42,14 @@ struct Area { bool Begin(Area &area, CVar::Factory::Handle arc, CVar::Factory::Handle range, float defaultRange); -// True when `object` is drawn and inside the arc; `distSq` is its squared -// distance from the player. The range is the caller's test. -bool InView(const Area &area, void *object, float &distSq); +// Counts the scene's entity drains. What is on screen changes only when it +// does, so a pick holds until then. +uint32_t Drains(); + +// True when `guid`, whose object is `object`, is drawn and inside the arc; +// `distSq` is its squared distance from the player. The range is the +// caller's test. +bool InView(const Area &area, uint64_t guid, void *object, float &distSq); // A kind's test for an object in view. using Accept = bool (*)(const Area &area, void *object, float distSq, void *ctx); diff --git a/src/target/SoftUnit.cpp b/src/target/SoftUnit.cpp index 468a10a6..6800c0da 100644 --- a/src/target/SoftUnit.cpp +++ b/src/target/SoftUnit.cpp @@ -73,10 +73,10 @@ struct State { CVar::Factory::Handle arc; CVar::Factory::Handle range; uint64_t soft; - // The last pick's inputs: the frame it ran in and the locked target it + // The last pick's inputs: the drain it read and the locked target it // saw. `picked` false forces the next read to pick (a cvar changed). bool picked; - uint32_t pickedFrame; + uint32_t pickedDrain; uint64_t pickedTarget; }; @@ -104,7 +104,7 @@ bool Qualifies(const State &st, const SoftTarget::Area &area, uint64_t guid) { return false; void *object = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid); float distSq; - return object != nullptr && SoftTarget::InView(area, object, distSq) && + return object != nullptr && SoftTarget::InView(area, guid, object, distSq) && Accept(area, object, distSq, const_cast(&st)); } @@ -126,18 +126,18 @@ uint64_t Pick(State &st) { bool Watched(const State &st) { return Event::Custom::HasListeners(st.changed->Slot()); } -// One pick per side per frame. The scan reads what the scene drew, which -// changes only when the next frame draws, so every read in a frame — the -// circles, the icons, Lua's token reads — shares the first one's answer, as -// the engine's scene code keys per-frame work on the same counter. The locked -// target and the cvars are the other inputs; changing either repicks at once. +// One pick per side per scene drain. The scan reads what the last drain drew, +// which changes only when the next one does, so every read until then — the +// circles, the icons, Lua's token reads — shares the first one's answer. The +// locked target and the cvars are the other inputs; changing either repicks +// at once. void Refresh(State &st) { - const uint32_t frame = Game::Read(Offsets::VAR_WORLD_FRAME_COUNTER); + const uint32_t drain = SoftTarget::Drains(); const uint64_t target = Loose::Locked(); - if (st.picked && st.pickedFrame == frame && st.pickedTarget == target) + if (st.picked && st.pickedDrain == drain && st.pickedTarget == target) return; st.picked = true; - st.pickedFrame = frame; + st.pickedDrain = drain; st.pickedTarget = target; const uint64_t guid = Pick(st); if (guid == st.soft)