mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
6000df8009857e8e137a1f73621412929218db14
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
46cae9d465 |
fix(unitmenu): stop stacking Focus/Cancel when a submenu opens
ClassicAPI_ToggleUnitMenu's initialize closure ran the same level-1 customization at every level. When the mouse crossed a nested entry (Loot Method / Loot Threshold / Raid Target Icon) the menu builds its level-2 submenu and re-invokes initialize; our AddFocusButton / AddCancelButton call UIDropDownMenu_AddButton with no level, which defaults to level 1 (not the current level), appending onto the still- open level-1 list. Level 1 is not reset while a submenu rebuilds, so the list grew every hover until "Too many buttons in UIDropDownMenu: ClassicAPIUnitMenuDropDown", pushing the real entries out of reach. Make initialize level-aware: at level >= 2 hand off to UnitPopup_ShowMenu (it resolves the submenu from UIDROPDOWNMENU_MENU_VALUE and adds its own Cancel); do the scratch-copy + Focus/Cancel append only at level 1 - mirroring how Blizzard's own unit dropdowns init. |
||
|
|
9f640de74b |
fix(addon): use plain info tables in the unit menu (stock 1.12 has no UIDropDownMenu_CreateInfo)
UIDropDownMenu_CreateInfo does not exist in stock 1.12.1 FrameXML, so
building the Focus and Cancel buttons through it errored with "attempt
to call global UIDropDownMenu_CreateInfo (a nil value)". Build the info
tables directly ({}) -- the vanilla idiom UIDropDownMenu_AddButton
expects.
|
||
|
|
67b968c36c |
fix(addon): NPC unit menu + working Cancel on the Focus dropdown
Unify ClassicAPI_ToggleUnitMenu so every menu (players and NPCs) shows the base menu minus its trailing Cancel, then appends Focus + Cancel. An NPC resolves to the RAID_TARGET_ICON menu, whose entries UnitPopup_HideButtons hides entirely unless you are grouped and can place markers -- so solo the menu was empty and never opened. The appended Focus + Cancel now always open it, and the NPC's own name is used as the title. Give the Cancel button a no-op func: UIDropDownMenuButton_OnClick early-returns when a button has no func and never hides the list, so the funcless Cancel did nothing on click. |
||
|
|
f833aad769 |
feat(addon): Set/Clear Focus on the unit right-click menu
Add a contextual Focus / Clear Focus entry to the ClassicAPI unit dropdown (ClassicAPI_ToggleUnitMenu), shown for real non-self units (party / raid / target). pfUI unit frames route their right-click through this dropdown, so it reaches every frame in use. Built entirely inside our own dropdown: no hooksecurefunc and no mutation of Blizzard's shared UnitPopupMenus tables, so default frames and other addons are unaffected. Cancel stays last by showing the base menu minus its trailing Cancel, then appending Focus and Cancel with our own click funcs. "Clear Focus" shows when the unit is the current focus, "Set Focus" otherwise. Labels use localized SET_FOCUS / CLEAR_FOCUS globals, added per locale (enUS/deDE/esES/frFR/ruRU/zhCN/zhTW) from Blizzard's Classic GlobalStrings. |
||
|
|
1da06d4a73 |
frame: attribute backport, modern script args, and SMSG hook consolidation (#13)
* frame: backport Frame:SetAttribute/GetAttribute + unit-frame mouseover/click Adds native SetAttribute / SetAttributeNoHandler / GetAttribute on the base Frame registry: a per-frame, case-insensitive value store with the 3.3.5 prefix/name/suffix getter precedence, stored on the frame's own Lua table. A `unit` attribute makes the frame a mouseover source. A WorldTick poll of the engine's mouse-focus frame (GetMouseFocus's global) calls the real mouseover setter (FUN_00492890) for its unit -- 1:1 with hovering the 3D model: model highlight, mouseover tooltip, UPDATE_MOUSEOVER_UNIT, and the native GUID slot. Stomp-proof (the engine's 3D-hover setter is event-driven) and independent of the frame's scripts, so an addon setting its own OnEnter can't break it. A `type1`/`type2`/`type` attribute installs a chained OnClick on that frame only (PCall-guarded, Button-only) that dispatches target / assist / focus on the unit at click time, then runs any prior handler. No global hooks: mouseover reads the mouse-focus global; clicks use the frame's own OnClick. Deliberately does NOT MinHook the button-click dispatcher (FUN_00779540) -- SuperWoW's click-casting owns that prologue and a second inline hook corrupts the trampoline (ERROR #132). * frame: extend attribute backport (one-verb click dispatcher + OnAttributeChanged) The `type*` click path now mirrors retail's SecureActionButton_OnClick: resolve ONE verb per click from the modifier/button-qualified `type` attribute and perform it, instead of a fixed `type1=target`. - Modifier/button resolution: `[alt-/ctrl-/shift-]type[1..5]` with prefix..name..suffix -> name..suffix -> name precedence, read from the live key state and the click's button. - Verbs: target (with the engine's default-interaction precedence - cast a pending spell / drop a cursor item on the unit instead of switching target), assist, focus, spell, stopcasting, macro, and menu. - Own-the-click: when a verb resolves we perform it and do NOT chain the frame's previous OnClick, so a configured `type1` no longer double- dispatches alongside an addon's own conditional click handler. - Self-healing wire: addons that re-SetScript OnClick (pfUI on every raid relayout) clobber our closure; WireOnClick re-wraps a clobbered Lua handler but skips its own C closure, so re-setting `type*` recovers without double-chaining. Dispatch goes straight to C++ where we own the code - no Lua round-trip through the global table: spell -> Spell::AtUnit::CastByName (a native unit-targeted cast; the unit's GUID is fed to the engine's dispatcher so there's no target juggling, and ground-target spells land at the unit's feet), focus -> Unit::Focus::Set, and the target verb's predicates -> Spell::AtCursor::IsPlacementActive / Cursor::Info::HasItem. Only genuine engine entries (TargetUnit/AssistUnit/SpellTargetUnit/DropItemOnUnit/ SpellStopCasting) and addon-provided functions still go through Lua globals. Spell::AtUnit gains a C++ header sharing its CastCore with the C_Spell.CastAtUnit Lua entry. macro verb: takes the content from the `macrotext`/`macro` attribute and prefers an addon-provided RunMacro (SuperCleveRoidMacros etc. - handles named macros and extended macro text), falling back to running the text natively when no RunMacro global is present. The native path runs each line through the stock FrameXML ChatEdit_ParseText via a throwaway edit-box (GetText closure + no-op __index), so it needs no addon. menu/togglemenu verb: pops the standard unit dropdown at the cursor via the new ClassicAPI_ToggleUnitMenu (Util/SecureUnitMenu.lua), resolving the unit -> menu type with Blizzard's own generic resolver (self->SELF, pet->PET, grouped player->PARTY, other player->PLAYER, NPC->RAID_TARGET_ICON). Keeps the FrameXML dropdown logic in Lua with the C side as a thin call. OnAttributeChanged is now a real SetScript/GetScript/HookScript-able frame script on every frame: SetAttribute fires it, SetAttributeNoHandler suppresses it. Made settable by co-hooking the base-frame script-name resolver FUN_0076a0d0 (the one every frame type delegates through) and handing back an external per-frame {handler, context} cell for that name - frames are immortal in 1.12, so the cell never goes stale. One hook does it (vs the tooltip OnTooltipSet* work's five) because we already own the firing side. 1.12 convention: the handler reads this = frame, arg1 = name, arg2 = value. Recursion-guarded so a handler may itself SetAttribute. * frame: add Frame:ClearAttribute (retail 11.2.0) `cleared = frame:ClearAttribute(name)` removes an attribute and returns whether it was set. Registered on the base Frame method registry next to SetAttribute/GetAttribute, so every frame has it. Routes through DoSet's nil-value path (removes the stored key, drops a `unit` mouseover binding) but does NOT fire OnAttributeChanged — verified against a live retail 11.2 client: SetAttribute fires the handler, ClearAttribute fires nothing, and the return is true for a set attribute / false when there was nothing to clear. * frame: store attributes in the Lua registry, hidden from Lua Attributes were kept as a subtable on the frame's own Lua table under a control-char key ("\1ClassicAPIAttributes"). That key, while collision- safe, is still enumerable via pairs(frame) and readable/writable from Lua. Move the store to registry[frame] in the Lua registry (LUA_REGISTRYINDEX), which has no _G path — so the attribute map is invisible to pairs(frame) and can't be read or tampered with from script, matching how retail keeps attributes C-side. Only PushSub changed (create/fetch now key the registry by the frame table); GetAttribute/DoSet/CopyAttr sit on top unchanged. 1.12 frames are immortal, so the strong registry key never leaks. The dead kAttrKey constant is removed. Verified in-game: SetAttribute/GetAttribute still round-trip, and a pairs(frame) scan no longer finds any ClassicAPI key. * frame: add the `item` click verb (SecureActionButton item action) type*="item" uses the modifier-qualified `item` attribute: - a "bag slot" string (e.g. "0 1") -> UseContainerItem(bag, slot); - otherwise an item name / itemID / link -> C_Item.UseItemByName(item, unit), passing the unit as the use target (self-use items ignore it, targeted ones like scrolls/bandages apply to it); - the deprecated `bag` + `slot` attributes are honored when `item` is unset. Both bag paths go through lua_call (new CallTableFunc2Str / CallGlobalNum2) rather than a direct C++ call: the item-use bag walk does SetTop(L, 0), so it needs its own Lua stack frame — a direct call would wipe the dispatcher's stack. (spell stays direct because Spell::AtUnit is stack-free; the helper comment records the distinction.) Retail's "bag slot" string is the preferred form; the deprecated per-attribute form is supported too. * docs: format the attribute click verbs as a table The verbs were one long paragraph of nested parentheticals - hard to scan. Replace it with a Verb | Extra attributes | Action table so each verb's inputs and behavior are legible at a glance. Content-equivalent; no API change. * frame: clear target on the `target` verb when unit is "none" Retail's SecureActionButton target action treats a "none" unit as "clear target". Match it: the `target` verb calls ClearTarget() when the resolved `unit` is "none" (case-insensitive), before the normal cursor/spell precedence. Mouseover already handles "none" implicitly (it resolves to GUID 0 = no unit). Docs' target-verb row updated. * frame: pass modern positional args to script handlers Vanilla always invokes frame-script handlers with zero Lua args; the handler reads this/arg1/event as globals. Modern addon ports write SetScript("OnMouseWheel", function(self, delta) ...) and get nothing. Co-hook both script runners -- FUN_FRAME_INVOKE_SCRIPT (no-arg scripts) and FUN_FRAME_RUN_SCRIPT_ARGS (scripts with values) -- and reimplement their pcall tail: keep the engine's exact this/argN global save-set- restore and message-handler errfunc, but additionally push self + arg1..argN as real positional arguments and pcall with nargs = 1+N. Purely additive: a zero-param vanilla handler ignores the extras and reads globals; a modern (self, delta) handler binds them. OnEvent gets (self, event, arg1..argN), detected structurally by matching the invoked handler ref against the frame OnEvent slot (frame+0x0C) -- exact, since each SetScript makes a distinct ref. Runtime switch SetModernScriptArgs()/GetModernScriptArgs(), default on; when off both detours are a straight passthrough to the original runner, which matters because FUN_FRAME_RUN_SCRIPT_ARGS is the hottest Lua path in the engine (every OnUpdate frame). Verified in-game across OnMouseWheel/OnClick/OnValueChanged/OnUpdate/OnEnter/OnLeave/OnEvent. * net: consolidate spell SMSG hooks onto one dispatch funnel The spell subsystem's per-opcode SMSG handlers (SpellGo, SpellStart, SpellDelayed, ChannelStart/Update, SpellFailure, SpellFailedOther, SpellCooldown) were each co-hooked directly -- and nampower (hadesmem) plus SuperWoW detour the same prologues. Two inline hookers on one prologue is the documented MinHook collision risk, and a whole-protocol bisect fingered exactly this cluster as the crash-suspect surface. Add Net::PacketDispatch: a receive-side mirror of Net::SendObserver that co-hooks the single incoming-SMSG dispatch funnel FUN_NET_MESSAGE_DISPATCH (0x00537AA0) -- a chokepoint nampower does NOT hook (it detours the leaf handlers) -- and fans each packet out to opcode subscribers with the cursor at the body and centralized save/restore. Migrate all eight handlers to subscribers: aura/Source (SpellGo, which re-decodes the packed guids + spellId the leaf handler used to hand it pre-decoded), spell/Cast (Start/Delayed/Channel*/Failure*), and lossofcontrol (Cooldown). The parse bodies are unchanged; only the hook site moved. Subscribers run before the engine's leaf handler instead of after a co-hook's original -- verified order-independent for all eight (self-contained cache/state updates; SpellGo's aura-application handoff rides a separate SMSG_UPDATE_OBJECT). Cuts the ClassicAPI-nampower shared spell prologues from 10 to 3 (the OnAura* method hooks, which have no packet chokepoint to relocate to). One hook on an uncontended function replaces eight on contended ones. Verified in-game: cast bars, channels (incl. Mind Control cast-then- channel), pushback, remote-cast interrupt eviction, and C_LossOfControl school lockouts all intact. * ScriptArgs is back to opt-in * frame: fix ScriptArgs comments to match opt-in default * frame/net: dedupe packet observers, reuse Lua/token helpers, fix attr edge cases Post-review cleanup of the attribute + SMSG-consolidation work. - net: extract the shared packet-observer plumbing (PacketObserver.h) — the intrusive subscriber list, Subscribe(), and the read-opcode / reset-cursor / fan-out / restore loop — so Net::PacketDispatch (SMSG, u16) and Net::SendObserver (CMSG, u32) each reduce to a one-line hook thunk over FanOutByOpcode<OpcodeT>. Drops the dead per-namespace Callback aliases rather than keeping them as compat shims. - Game::Lua: promote PushGlobalFunction / CallGlobal / CallGlobalString into the shared Lua helpers (a pattern several modules open-code); Frame attributes use them instead of private copies. - frame/Attributes: resolve unit tokens through Unit::Identity::GuidForToken (engine resolver + player fast-path) instead of a duplicate raw-cast wrapper. - frame/Attributes: wire the chained OnClick for every "type" action attribute the click resolver reads (IsTypeAttr: modifier prefixes + type1..type5), not just type/type1/type2 — a middle-click or modifier-only binding now installs. - frame/Attributes: FireAttributeChanged snapshots and restores the caller's arg1/arg2 around the fire, so calling SetAttribute from inside a running script handler no longer clobbers its globals. |