diff --git a/Dominos/Bindings_Mainline.xml b/Dominos/Bindings_Mainline.xml index 0f91f3f1..959d14d4 100644 --- a/Dominos/Bindings_Mainline.xml +++ b/Dominos/Bindings_Mainline.xml @@ -4,198 +4,198 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - + - + \ No newline at end of file diff --git a/Dominos/CHANGELOG.md b/Dominos/CHANGELOG.md new file mode 100644 index 00000000..c3a81976 --- /dev/null +++ b/Dominos/CHANGELOG.md @@ -0,0 +1,241 @@ +# Dominos Changelog + +### Midnight extra action button taint isolation + +- Applied Dominos' Midnight action-button safety wrapper to the native `ExtraActionButton1` so Blizzard shared action events cannot call protected `SetAttribute()` / cooldown paths through a Dominos-tainted stack. +- Reused the secure press-and-hold updater for both Dominos action buttons and the native extra-action button, preserving slot-driven Blizzard execution. + +### Midnight extra action bar event relay + +- Restored Blizzard extra-action button visibility on Midnight builds after Dominos disables the native `ActionBarController` event pump. +- Added a narrow Dominos relay for `UPDATE_EXTRA_ACTIONBAR` / `PLAYER_ENTERING_WORLD` that calls Blizzard's native `ExtraActionBar_Update()` instead of replacing extra-action execution. +- Hardened `bars/extraAbilityBar.lua` against missing Retail/Classic extra-bar helpers and preserved secure `ExtraActionButton1` click behavior. + +### Midnight native override action-bar taint isolation + +- Forced Dominos-owned override-bar handling on Midnight builds instead of using Blizzard's native `OverrideActionBar` button frame. +- Detached native `OverrideActionBarButton*` frames from Blizzard shared action button dispatchers so hidden native override buttons cannot call protected `SetCooldown` / `SetAttribute` paths with secret values from a Dominos-tainted stack. +- Stopped wrapping native `OverrideActionBarButton1` show/hide scripts on Midnight; override routing now uses Dominos secure override-page state instead. + +### Midnight native action-bar controller taint isolation + +- Stopped hiding or reparenting protected Blizzard action-bar frames on Midnight builds; Dominos now visually suppresses them with alpha/mouse suppression instead. +- Disabled Blizzard's native ActionBarController event pump on Midnight so hidden `MainActionBar` is not shown, hidden, or repaged by Blizzard after Dominos has taken ownership of the visible action bars. +- Preserved the Classic/TBC/Mists hiding path unchanged. + +### Midnight native button taint isolation + +- Detached hidden Blizzard stock action buttons from Blizzard shared action button dispatcher frames on Midnight builds. +- Avoided Dominos touching `ActionButton1` showgrid attributes on Midnight; Dominos now relies on explicit showgrid events there. +- Prevented hidden native `MultiBar*Button*` frames from reaching Blizzard `UpdatePressAndHoldAction()` / `ActionButton_UpdateCooldown()` after Dominos has hidden the stock bars. + + +## Unreleased - Phase 2: Blizzard-compatible action button frame contract rebase + +* (Midnight) Replaced the Dominos-owned action button cooldown/update dispatch with a Blizzard-compatible duration-object path. This avoids passing secret cooldown `start`/`duration` values through tainted Lua and prevents protected `pressAndHoldAction` attribute writes from Blizzard's shared `ActionButton_Update` path. +* Rebased the Phase 2 action-button frame contract work onto the updated `Dominos-master` base without downgrading the newer 11.3.0-beta1 TOC metadata or Mists loading directives. +* Added `core/bindingCompat.lua` as the centralized binding identity layer for native Blizzard binding commands, Dominos fallback CLICK bindings, and stable action-button binding IDs. +* Updated action-button setup to expose stable binding fields and attributes such as `commandName`, `bindingAction`, `bindingID`, `dominosButtonID`, `nativeCommandName`, and `fallbackCommandName` without deriving stable identity from paged action slots. +* Updated hotkey and quick-binding lookup paths to consume the shared BindingCompat contract while preserving existing Dominos fallback bindings for saved user configurations. +* Hardened action button override-binding refresh paths to tolerate missing or nil binding keys and avoid unsafe binding mutation. +* Refactored override binding handling for Blizzard default override states, vehicle/possess-style action states, pet battle states, native `ACTIONBUTTON1`-`ACTIONBUTTON6` keys, and Dominos fallback CLICK bindings. +* Improved support for external secure action-button overrides by detecting `type`, `clickbutton`, and `gse-button` style override attributes on action buttons. +* Preserved the safe restricted-environment correction: Dominos does not alias `ActionButton1`-`ActionButton12` to Dominos-created frames and does not write Dominos buttons into Blizzard restricted `MainActionBar.actionButtons` tables. +* Added a safe bridge for external addons that attach overrides to Blizzard `ActionButton1`-`ActionButton12`, mirroring supported external override attributes onto the matching visible Dominos action buttons without corrupting Blizzard restricted action-bar controller state. +* Preserved slot-driven secure action behavior; Dominos remains a Blizzard-compatible action-slot orchestrator and does not implement custom spell, item, macro, or GSE casting logic. +* Kept Phase 2 changes Lua 5.1 compatible and guarded against combat-taint-prone protected attribute updates where possible. + +## 11.3.0-beta1 + +* Note: This version won't work on 5.5.3 (hence the beta designation) +* Update TOCs for the 12.0.7 and 5.5.4 PTRs + +## 11.2.21 + +* Update TOCs for 12.0.5 + +## 11.2.20 + +* (Retail) Fixed an issue causing the cast bar to not disappear when canceling a channeled spell. + +## 11.2.19 + +* (Retail) Fixed the reputation bar for major factions (Thanks [fediazgon](https://github.com/fediazgon)) + +## 11.2.18 + +* (Retail) Fix more secret errors with the cast bar by using castBarID when available. + +## 11.2.17 + +* Keyboard nudging now checks your Strafe Left/Right keybindings in addition to Turn Left/Right. (Handles the Modern/Legacy control options in 12.x) +* (TBC) Added latency information to the minimap icon, like in Vanilla (Thanks [PortalPi ](https://github.com/PortalPi)) + +## 11.2.16 + +* (Retail) Better handle secret icons on the cast bar. + +## 11.2.15 + +* (TBC) Fixed the talent button not appearing on the menu bar + +## 11.2.14 + +* (Retail) Fixed an menu bar error when entering/exiting pet battles + +## 11.2.13 + +* Fixed an issue with unregistering the Blizzard stance bar that was causing errors + +## 11.2.12 + +* Added support for Burning Crusade Classic Anniversary Edition +* Added in missing menu bar button names + +## 11.2.11 + +* Refactored the progress bar to use a data provider interface instead of metatable manipulation (which broke with the last Midnight fix) + +## 11.2.10 + +* Added a workaround Dominos frame class inheritance to fix the Invalid 'self' frame handle errors in the latest Midnight build (Thanks, [Tyler Fleckenstein](https://github.com/tpfleck)) + +## 11.2.9 + +* (Midnight) Added a workaround for GetUnitEmpowerHoldAtMaxTime returning + secret values to prevent error messages when casting empowered spells. + Hopefully Blizzard will drop this restriction. + +## 11.2.8 + +* (Classic) Fixed the missing Monk class bar + +## 11.2.7 + +* (Retail, Midnight) Reuse the existing pet bar action buttons and logic. This should make the bar usable in Midnight +* (Classic) Use a custom impelemntation for the class bar. This shold resolve issues with positioning of the bar when playing certain classes +* (Midnight) Partially reimplemented the logic for hiding action button cooldowns on transparent bars. + +## 11.2.6 + +* (Midnight) Enabled the cast bar after resolving some secret value comparison errors + +## 11.2.5 + +* Fixed an issue that would prevent bindings from working when in Edit House mode + +## 11.2.4 + +* Updated TOC files for game versions 5.5.3 and 1.15.8 +* Dropped the specific TOC file for Vanilla as 1.15.8 supports conditional directives +* The artifactBar and azeriteBar lua files should now not load at all on Classic + +## 11.2.3 + +* Updated TOC files for 12.0.0 (Midnight) and 11.2.7 +* Fixed an error caused byt the progress bar trying to call a missing API when attempting to show azerite information. +* (Midnight) Disabled the cast bar and pet bar +* (Midnight) Disabled the ability to open flyouts via keypress + +## 11.2.2 + +* Changed the default paging settings for Warriors in Mists to use Action Bar 1 for battle stance, instead of Action Bar 7 +* Fixed an issue with the progress bars that could cause an Addon Action Blocked message to occur when leveling up in combat +* Reintroduced a workaround for a Blizzard error that could occur when hiding the achievement button in classic version +* Updated TOCs for 11.2.5 and 5.5.1 + +## 11.2.1 + +* Fixed the addon compartment menu icon not showing the options menu when clicked + +## 11.2.0 + +* Excluded the new combat assistant highlights from spell animation filtering + +## 11.1.9 + +* Fixed menu bar errors +* Corrected pkgmeta file so that you'll actually see the right changelog and not just my commit messages + +## 11.1.8 + +* Added support for 11.2.0 +* Updated TOCs to use conditional file loading directives +* Rewrote the bar states configuration formats to handle multiple game versions a bit better +* Updated the menu bar button ordering to hopefully prevent issues when switching to vehicle/pet battle UIs + +## 11.1.7 + +* Added support for Monk stances in MoP Classic + +## 11.1.6 + +* Fixed multiple paging issues with Mists of Pandaria Classic + +## 11.1.5 + +* Updated TOCs for 11.1.7 and 5.5.0 (Mists of Pandaria Classic) +* Refreshed libraries to fix a lua error in MoP Classic + +## 11.1.4 + +* Updated TOCs for 11.1.5 + +## 11.1.3 + +* Updated TOCs for 1.15.7 + +## 11.1.2 + +* Context menu dropdowns now use the standard dropdown menu templates + +## 11.1.1 + +* Fixed renown level text showing %d + +## 11.1.0 + +* Adjusted KeyRingButton test to hopefully avoid some errors + +## 11.0.9 + +* Updated TOCs for 11.1.0, 4.4.2 and 1.15.6 +* (Classic) Added experimental support for the extra ability bar + +## 11.0.8 + +* Updated TOCs for 1.15.5 + +## 11.0.7 + +* (Classic) Fixed tooltip issues when enabling all Blizzard action bars + +## 11.0.6 + +* Updated TOCs for 11.0.7 and 11.0.5 + +## 11.0.5 + +* (Vanilla) Fixed tooltip issues when enabling all Blizzard action bars + +## 11.0.4 + +* Added a new slider for row spacing (contributed by [Xiaoyang-Huang](https://github.com/Xiaoyang-Huang)) +* Added a Hide at Max Level option to the display menu of progress bars + +## 11.0.3 + +* Added support for classic versions 4.4.1 and 1.15.4 + +## 11.0.2 + +* Updated Override UI detection + +## 11.0.1 + +* Fixed an issue that would let spell overlay glows still display, even if disabled + +## 11.0.0 + +* (Classic) Ensured the Encounter Bar always is given a size to prevent issues with repositioning frames +* Dropped WoW 10.x from TOC files diff --git a/Dominos/Dominos.lua b/Dominos/Dominos.lua index 44f9a5fa..2be45da6 100644 --- a/Dominos/Dominos.lua +++ b/Dominos/Dominos.lua @@ -777,6 +777,17 @@ function Addon:SetUseOverrideUI(enable) end function Addon:UsingOverrideUI() + -- Midnight hardens native OverrideActionBar action buttons and cooldown + -- values. Once Dominos has integrated with the action bar system, allowing + -- Blizzard's native override UI to remain the active button owner can route + -- protected SetAttribute/SetCooldown calls through a Dominos-tainted stack. + -- Dominos still supports override, vehicle, possess, and temp-shapeshift + -- action slots through its own secure override bar state controller; only + -- the native OverrideActionBar art/button frame is disabled on Midnight. + if self:IsAfterMidnight() then + return false + end + return self.db.profile.useOverrideUI and not self:IsBuild('vanilla') end diff --git a/Dominos/Dominos.toc b/Dominos/Dominos.toc index 0ac44c02..19319b7f 100644 --- a/Dominos/Dominos.toc +++ b/Dominos/Dominos.toc @@ -19,6 +19,7 @@ core\barStates\[Game].lua core\shadowUIParent.lua core\frame.lua core\buttonBar.lua +core\bindingCompat.lua core\bindableButton.lua core\fadeManager.lua core\overrideController.lua [AllowLoadGameType mainline, mists, cata, wrath, tbc] diff --git a/Dominos/LICENSE b/Dominos/LICENSE new file mode 100644 index 00000000..396bd500 --- /dev/null +++ b/Dominos/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2008-2021 Jason Greer +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/Dominos/README.md b/Dominos/README.md new file mode 100644 index 00000000..609c559c --- /dev/null +++ b/Dominos/README.md @@ -0,0 +1,54 @@ +# Dominos + +Dominos is an addon that replaces your main bar with movable parts that offer +additional customization. Dominos is used primarily for its action bars, +which feature: + +* Customizable layout settings (spacing, vertical bars, opacity, scale, etc) +* Customizable action bar paging (so that you can change what your bars do when shapeshifted, etc) +* Customizable visiblity (so that you can make bars transparent, or show up only when in combat, etc) +* [Masque](https://www.curseforge.com/wow/addons/masque) support for button styling, +with individual settings per bar +* [LibKeyBound](https://www.wowace.com/projects/libkeybound-1-0) is implemented for quickly binding keys +* Any other addon that works on Blizzard UI for action buttons should also work with Dominos, too. +This includes things like [tullaRange](https://www.curseforge.com/wow/addons/tullarange), [AdiButtonAuras](https://www.curseforge.com/wow/addons/adibuttonauras), and [OmniCC](https://www.curseforge.com/wow/addons/omni-cc) + +## Usage + +### General Settings + +The main options menu in Dominos can be found by either right clicking the +minimap icon or via the `/dominos` slashcommand. On the main options menu, +you will find sections for configuring shared bar settings and profiles. + +### Moving Stuff Around + +To move around or hide bars, you will want to enter **configuration mode**. You +can do this by either one of the following ways + +* Left clicking the minimap button +* Clicking **Configure Bars...** from the main options menu (accessible from /dominos) +* Using the slash command /dominos config +* Once in configuration mode, you can drag around bars using your mouse + +### Customizing Individual Bars + +Most per bar settings can be found in context menus. To access these settings, +*right click* or alt left click the bar in configuration mode. + +### Binding Keys + +Dominos implements support for [LibKeyBound](https://www.wowace.com/projects/libkeybound-1-0) +for quickly binding keys. Quick Binding mode can be entered by either the standard keybound shortcut (/kb) +or by clicking the Bind Keys... button in the main options menu. + +### Slash Commands + +Dominos provides a large set of slash commands for usage in macros and bulk +adjustments. [The complete set of slash commands can be found on the wiki](https://github.com/tullamods/Dominos/wiki/Slash-Commands) + +## Contributing + +[Source code for the addon can be found on GitHub](https://github.com/tullamods/Dominos). +Contributions are welcome (though I can be picky 😊). + diff --git a/Dominos/bars/actionBar/bar.lua b/Dominos/bars/actionBar/bar.lua index 012dda7d..2407af6d 100644 --- a/Dominos/bars/actionBar/bar.lua +++ b/Dominos/bars/actionBar/bar.lua @@ -261,7 +261,9 @@ function ActionBar:LoadStateController() local offset = 0 local overridePage = self:GetAttribute('state-overridepage') or 0 - if overridePage > 0 and self:GetAttribute('state-overridebar') then + local overrideActive = overridePage > 0 and self:GetAttribute('state-overridebar') + + if overrideActive then offset = (overridePage - 1) * self:GetAttribute('overrideBarLength') else local page = self:GetAttribute('state-page') or 1 @@ -275,7 +277,16 @@ function ActionBar:LoadStateController() end self:SetAttribute('actionOffset', offset) - control:ChildUpdate('offset', offset) + + -- Keep the visible button's GSE/clickbutton contract untouched. The + -- high offset flag makes every action-slot update self-heal the + -- override proxy state, so a missed/delayed overrideactive child update + -- cannot leave the transparent proxy covering a normal GSE button. + local overrideFlag = overrideActive and 100000 or 0 + local overrideValue = overrideActive and 1 or 0 + + control:ChildUpdate('offset', offset + overrideFlag) + control:ChildUpdate('overrideactive', overrideValue) ]]) self:UpdateOverrideBar() diff --git a/Dominos/bars/actionBar/bindings.lua b/Dominos/bars/actionBar/bindings.lua index 8c6f4725..ea272980 100644 --- a/Dominos/bars/actionBar/bindings.lua +++ b/Dominos/bars/actionBar/bindings.lua @@ -1,74 +1,295 @@ -------------------------------------------------------------------------------- --- Sets priority bindings to the Pet Battle and Override UI when either frame --- is visible +-- Secure binding bridge for Blizzard override/pet-battle action routing. -- --- TODO: --- Load the override bindings from whatever bar we've configured as the Dominos --- override bar. Ensure that the bindings displayed for those frames are sourced --- from those +-- Default action bars route ACTIONBUTTON1-6 through Blizzard's secure action +-- button functions when the Override UI or Pet Battle UI is active. Dominos +-- also has a configurable override bar, so the bridge must preserve both: +-- 1. Blizzard's priority ACTIONBUTTON routing when the default UI owns it. +-- 2. Dominos' configured override-bar buttons when Dominos owns it. -------------------------------------------------------------------------------- local _, Addon = ... if not OverrideActionBar then return end +local afterMidnight = Addon.IsAfterMidnight and Addon:IsAfterMidnight() + local Binder = CreateFrame("Frame", nil, nil, "SecureHandlerAttributeTemplate") -Binder:WrapScript(OverrideActionBarButton1, "OnShow", [[ - control:SetAttribute("overrideui", 1) -]]) +local MAX_OVERRIDE_BINDINGS = NUM_OVERRIDE_BUTTONS or 6 +local MAX_BINDING_SOURCES = 6 +local SOURCE_ATTRIBUTE_TEMPLATE = "ACTIONBUTTON%d_SOURCE%d" +local ENABLED_ATTRIBUTE_TEMPLATE = "ACTIONBUTTON%d_ENABLED" +local TARGET_ATTRIBUTE_TEMPLATE = "ACTIONBUTTON%d_TARGET" +local BUTTON_REF_TEMPLATE = "overrideButton%d" + +Binder:SetAttribute("maxOverrideBindings", MAX_OVERRIDE_BINDINGS) + +local function GetBindingCompat() + return Addon.BindingCompat +end + +local function GetOverrideButton(index) + if not Addon.GetOverrideBar then + return nil + end + + local bar = Addon:GetOverrideBar() + if bar and bar.buttons then + return bar.buttons[index] + end +end + +local function IsValidClickTargetName(name) + return type(name) == "string" and name ~= "" and not name:find(":", 1, true) +end + +local function GetOverrideClickTarget(button) + if button and button.dominosOverrideActionProxy then + return button.dominosOverrideActionProxy + end + + return button +end + +local function SetSourceAttribute(self, buttonIndex, sourceIndex, value) + self:SetAttribute(SOURCE_ATTRIBUTE_TEMPLATE:format(buttonIndex, sourceIndex), value) +end + +local function ClearOverrideButtonSources(self, buttonIndex) + for sourceIndex = 1, MAX_BINDING_SOURCES do + SetSourceAttribute(self, buttonIndex, sourceIndex, nil) + end + + self:SetAttribute(TARGET_ATTRIBUTE_TEMPLATE:format(buttonIndex), nil) + self:SetAttribute(ENABLED_ATTRIBUTE_TEMPLATE:format(buttonIndex), nil) +end + +local function SetOverrideButtonSources(self, buttonIndex, button) + ClearOverrideButtonSources(self, buttonIndex) + + if not button then + return + end + + local targetButton = GetOverrideClickTarget(button) + local targetName = targetButton and targetButton.GetName and targetButton:GetName() + if not IsValidClickTargetName(targetName) then + return + end + + local bindingCompat = GetBindingCompat() + if bindingCompat and bindingCompat.GetActionButtonCommands then + local commands = bindingCompat.GetActionButtonCommands(button:GetAttribute("bindingID"), button) or {} + for sourceIndex = 1, math.min(#commands, MAX_BINDING_SOURCES) do + SetSourceAttribute(self, buttonIndex, sourceIndex, commands[sourceIndex]) + end + else + SetSourceAttribute(self, buttonIndex, 1, button:GetAttribute("commandName")) + end + + self:SetFrameRef(BUTTON_REF_TEMPLATE:format(buttonIndex), targetButton) + self:SetAttribute(TARGET_ATTRIBUTE_TEMPLATE:format(buttonIndex), targetName) + self:SetAttribute(ENABLED_ATTRIBUTE_TEMPLATE:format(buttonIndex), 1) +end + +local function MarkBindingsDirty(self) + if InCombatLockdown() then + self.needsBindingRefresh = true + self:RegisterEvent("PLAYER_REGEN_ENABLED") + return + end + + self:SetAttribute("bindingUpdate", (self:GetAttribute("bindingUpdate") or 0) + 1) +end + +local function SetUseOverrideUI(self, enabled) + if InCombatLockdown() then + self.pendingUseOverrideUI = enabled and true or false + self:RegisterEvent("PLAYER_REGEN_ENABLED") + return + end + + self:SetAttribute("useoverrideui", enabled and 1 or 0) +end + +function Binder:UpdateOverrideBindingSources() + if InCombatLockdown() then + self.needsOverrideBindingSourceUpdate = true + self:RegisterEvent("PLAYER_REGEN_ENABLED") + return + end + + for buttonIndex = 1, MAX_OVERRIDE_BINDINGS do + SetOverrideButtonSources(self, buttonIndex, GetOverrideButton(buttonIndex)) + end + + MarkBindingsDirty(self) +end + +function Binder:PLAYER_REGEN_ENABLED() + self:UnregisterEvent("PLAYER_REGEN_ENABLED") + + if self.pendingUseOverrideUI ~= nil then + self:SetAttribute("useoverrideui", self.pendingUseOverrideUI and 1 or 0) + self.pendingUseOverrideUI = nil + end + + if self.needsOverrideBindingSourceUpdate then + self.needsOverrideBindingSourceUpdate = nil + self:UpdateOverrideBindingSources() + elseif self.needsBindingRefresh then + self.needsBindingRefresh = nil + MarkBindingsDirty(self) + end +end -Binder:WrapScript(OverrideActionBarButton1, "OnHide", [[ - control:SetAttribute("overrideui", 0) +function Binder:UPDATE_BINDINGS() + MarkBindingsDirty(self) +end + +if not afterMidnight then + Binder:WrapScript(OverrideActionBarButton1, "OnShow", [[ + control:SetAttribute("overrideui", 1) + ]]) + + Binder:WrapScript(OverrideActionBarButton1, "OnHide", [[ + control:SetAttribute("overrideui", 0) + ]]) +else + Binder:SetAttributeNoHandler("overrideui", 0) +end + +Binder:SetAttributeNoHandler("SetCommandBindings", [[ + local targetCommand = ... + + for sourceIndex = 2, select("#", ...) do + local sourceCommand = select(sourceIndex, ...) + if sourceCommand then + for keyIndex = 1, select("#", GetBindingKey(sourceCommand)) do + local key = select(keyIndex, GetBindingKey(sourceCommand)) + if key then + self:SetBinding(true, key, targetCommand) + end + end + end + end ]]) -Binder:SetAttributeNoHandler("_onattributechanged", [[ - if name == "bind" then return end - - local bind = ( - (self:GetAttribute("overrideui") == 1 and self:GetAttribute("useoverrideui") == 1) - or self:GetAttribute("petbattleui") == 1 - ) - - if self:GetAttribute("bind") ~= bind then - self:SetAttribute("bind", bind) - self:ClearBindings() - - if bind then - for i = 1, 6 do - local command = "ACTIONBUTTON" .. i - local keyCommand = self:GetAttribute(command) or command - self:RunAttribute("SetBindings", command, GetBindingKey(keyCommand)) +Binder:SetAttributeNoHandler("SetClickBindings", [[ + local targetName = ... + + if type(targetName) ~= "string" or targetName == "" or targetName:match(":") then + return + end + + for sourceIndex = 2, select("#", ...) do + local sourceCommand = select(sourceIndex, ...) + if sourceCommand then + for keyIndex = 1, select("#", GetBindingKey(sourceCommand)) do + local key = select(keyIndex, GetBindingKey(sourceCommand)) + if key then + self:SetBindingClick(true, key, targetName, "LeftButton") + end end end end ]]) -Binder:SetAttributeNoHandler("SetBindings", [[ - local command = ... - for i = 2, select("#", ...) do - self:SetBinding(true, select(i, ...), command) +Binder:SetAttributeNoHandler("UpdateBindings", [[ + local overrideUIValue = self:GetAttribute("overrideui") + local useOverrideUIValue = self:GetAttribute("useoverrideui") + local petBattleValue = self:GetAttribute("petbattleui") + local statePetBattleValue = self:GetAttribute("state-petbattleui") + local overridePage = tonumber(self:GetAttribute("state-overridepage")) or 0 + local maxOverrideBindings = tonumber(self:GetAttribute("maxOverrideBindings")) or 6 + + local overrideUIActive = overrideUIValue == 1 or overrideUIValue == "1" or overrideUIValue == true + local useOverrideUI = useOverrideUIValue == 1 or useOverrideUIValue == "1" or useOverrideUIValue == true + local petBattleActive = petBattleValue == 1 or petBattleValue == "1" or petBattleValue == true + or statePetBattleValue == 1 or statePetBattleValue == "1" or statePetBattleValue == true + local dominosOverrideActive = overridePage > 0 and not useOverrideUI and not petBattleActive + + self:ClearBindings() + + if (overrideUIActive and useOverrideUI) or petBattleActive then + for buttonIndex = 1, maxOverrideBindings do + local targetCommand = "ACTIONBUTTON" .. buttonIndex + self:RunAttribute( + "SetCommandBindings", + targetCommand, + targetCommand, + self:GetAttribute(targetCommand .. "_SOURCE1"), + self:GetAttribute(targetCommand .. "_SOURCE2"), + self:GetAttribute(targetCommand .. "_SOURCE3"), + self:GetAttribute(targetCommand .. "_SOURCE4"), + self:GetAttribute(targetCommand .. "_SOURCE5"), + self:GetAttribute(targetCommand .. "_SOURCE6") + ) + end + elseif dominosOverrideActive then + for buttonIndex = 1, maxOverrideBindings do + if self:GetAttribute("ACTIONBUTTON" .. buttonIndex .. "_ENABLED") == 1 then + local targetCommand = "ACTIONBUTTON" .. buttonIndex + local targetName = self:GetAttribute(targetCommand .. "_TARGET") + if targetName then + self:RunAttribute( + "SetClickBindings", + targetName, + targetCommand, + self:GetAttribute(targetCommand .. "_SOURCE1"), + self:GetAttribute(targetCommand .. "_SOURCE2"), + self:GetAttribute(targetCommand .. "_SOURCE3"), + self:GetAttribute(targetCommand .. "_SOURCE4"), + self:GetAttribute(targetCommand .. "_SOURCE5"), + self:GetAttribute(targetCommand .. "_SOURCE6") + ) + end + end + end end ]]) --- initialize state +Binder:SetAttributeNoHandler("_onattributechanged", [[ + self:RunAttribute("UpdateBindings") +]]) + Binder:SetScript("OnEvent", function(self, event) - self:SetScript("OnEvent", nil) - self:UnregisterEvent(event) + if event == "PLAYER_LOGIN" then + self:UnregisterEvent(event) + + self:SetAttribute("overrideui", afterMidnight and 0 or (OverrideActionBarButton1:IsVisible() and 1 or 0)) + SetUseOverrideUI(self, Addon:UsingOverrideUI()) + RegisterAttributeDriver(self, "petbattleui", "[petbattle]1;0") + + if Addon.OverrideController then + Addon.OverrideController:Add(self) + end + + self:RegisterEvent("UPDATE_BINDINGS") + self:UpdateOverrideBindingSources() + return + end - self:SetAttribute("overrideui", OverrideActionBarButton1:IsVisible() and 1 or 0) - self:SetAttribute("useoverrideui", Addon:UsingOverrideUI() and 1 or 0) - RegisterAttributeDriver(self, "petbattleui", "[petbattle]1;0") + if self[event] then + self[event](self) + end end) Binder:RegisterEvent("PLAYER_LOGIN") function Binder:USE_OVERRRIDE_UI_CHANGED(_, enabled) - self:SetAttribute("useoverrideui", enabled and 1 or 0) + SetUseOverrideUI(self, enabled) end function Binder:LAYOUT_LOADED() - self:SetAttribute("useoverrideui", Addon:UsingOverrideUI() and 1 or 0) + SetUseOverrideUI(self, Addon:UsingOverrideUI()) + self:UpdateOverrideBindingSources() +end + +function Binder:OVERRIDE_BAR_UPDATED() + self:UpdateOverrideBindingSources() end Addon.RegisterCallback(Binder, "USE_OVERRRIDE_UI_CHANGED") Addon.RegisterCallback(Binder, "LAYOUT_LOADED") +Addon.RegisterCallback(Binder, "OVERRIDE_BAR_UPDATED") diff --git a/Dominos/bars/actionBar/button.lua b/Dominos/bars/actionBar/button.lua index cedd6ce4..dfb4c734 100644 --- a/Dominos/bars/actionBar/button.lua +++ b/Dominos/bars/actionBar/button.lua @@ -1,64 +1,193 @@ local _, Addon = ... local ActionButton = {} -local function GetActionButtonCommand(id) - -- 0 - if id <= 0 then - return - -- 1 - elseif id <= 12 then - return "ACTIONBUTTON" .. id - -- 2 - elseif id <= 24 then - return - -- 3 - elseif id <= 36 then - return "MULTIACTIONBAR3BUTTON" .. (id - 24) - -- 4 - elseif id <= 48 then - return "MULTIACTIONBAR4BUTTON" .. (id - 36) - -- 5 - elseif id <= 60 then - return "MULTIACTIONBAR2BUTTON" .. (id - 48) - -- 6 - elseif id <= 72 then - return "MULTIACTIONBAR1BUTTON" .. (id - 60) - -- 7-11 - elseif id <= 132 then +local function GetBindingCompat() + return Addon.BindingCompat +end + +local function GetActionTextureSafe(action) + if C_ActionBar and C_ActionBar.GetActionTexture then + return C_ActionBar.GetActionTexture(action) + end + + return GetActionTexture(action) +end + +local function GetActionButtonCommand(button) + local bindingCompat = GetBindingCompat() + if bindingCompat then + local command = bindingCompat.NormalizeCommandName(button:GetAttribute("commandName")) + if command then + return command + end + + return bindingCompat.GetActionButtonCommand(button:GetAttribute("bindingID"), button) + end + + local name = button:GetName() + if name then + return ("CLICK %s:HOTKEY"):format(name) + end +end + +local function ApplyActionButtonContract(button, id) + local bindingCompat = GetBindingCompat() + if bindingCompat and bindingCompat.ApplyActionButtonContract then + bindingCompat.ApplyActionButtonContract(button, id) return - -- 12 - elseif id <= 144 then - return "MULTIACTIONBAR5BUTTON" .. (id - 132) - -- 13 - elseif id <= 156 then - return "MULTIACTIONBAR6BUTTON" .. (id - 144) - -- 14 - elseif id <= 168 then - return "MULTIACTIONBAR7BUTTON" .. (id - 156) + end + + local name = button:GetName() + local command = name and ("CLICK %s:HOTKEY"):format(name) or nil + button.commandName = command + button.bindingAction = command + button.bindingID = id + button.dominosButtonID = id + + button:SetAttributeNoHandler("commandName", command) + button:SetAttributeNoHandler("bindingID", id) + button:SetAttributeNoHandler("dominosButtonID", id) +end + +local function SetRegionParent(region, parent) + if region and region:GetParent() ~= parent then + region:SetParent(parent) + end +end + +local function IsSecureTruthy(value) + return value == true or value == 1 or value == "1" +end + +local function IsOverrideActionBarActive(button) + return button and IsSecureTruthy(button:GetAttribute("dominos-override-action-active")) +end + +local function IsExternalActionOverrideType(actionType) + return actionType ~= nil and actionType ~= "action" and actionType ~= "actionrelease" +end + +local function HasExternalActionOverride(button) + if not button then + return nil + end + + -- While the configured Dominos override/vehicle/possess bar is active, + -- external clickbutton/GSE attributes on the normal button must not make + -- the swapped action look occupied. Actual clicks are handled by a + -- separate override-only secure proxy, so the normal button can keep its + -- external attributes untouched for instant restoration afterward. + if IsOverrideActionBarActive(button) then + return nil + end + + if button:GetAttribute("gse-button") then + return true + end + + if button:GetAttribute("clickbutton") then + return true + end + + if IsExternalActionOverrideType(button:GetAttribute("type")) then + return true + end + + if IsExternalActionOverrideType(button:GetAttribute("type1")) then + return true + end + + if IsExternalActionOverrideType(button:GetAttribute("*type1")) then + return true + end + + if type(SecureButton_GetModifiedAttribute) == "function" then + return IsExternalActionOverrideType(SecureButton_GetModifiedAttribute(button, "type", "LeftButton")) end end function ActionButton:OnCreate(id) - -- initialize secure state + -- Preserve a Blizzard-compatible public identity before the button is used + -- by binding, tooltip, hotkey, or external hook code. This identity is the + -- stable Dominos/native button id, not the current paged action slot. + ApplyActionButtonContract(self, id) + + -- initialize secure state. Match Blizzard's ActionBarActionButtonMixin + -- public secure-action contract while keeping Dominos execution slot-driven + -- through the explicit secure "action" attribute. + self:SetAttributeNoHandler("type", "action") + self:SetAttributeNoHandler("typerelease", "actionrelease") self:SetAttributeNoHandler("action", 0) - self:SetAttributeNoHandler("commandName", GetActionButtonCommand(id) or ("CLICK %s:HOTKEY"):format(self:GetName())) self:SetAttributeNoHandler("showgrid", 0) + self:SetAttributeNoHandler("statehidden", nil) + self:SetAttributeNoHandler("dominos-override-action-active", nil) + self:SetAttributeNoHandler("checkfocuscast", true) + self:SetAttributeNoHandler("checkmouseovercast", true) + self:SetAttributeNoHandler("checkselfcast", true) self:SetAttributeNoHandler("useparent-checkfocuscast", true) self:SetAttributeNoHandler("useparent-checkmouseovercast", true) self:SetAttributeNoHandler("useparent-checkselfcast", true) + self:SetAttributeNoHandler("useparent-unit", true) - -- register for clicks on all buttons, and enable mousewheel bindings + -- Midnight press-and-hold handling is installed by ActionButtons so the same + -- hardened path can be reused by native extra-action buttons. + + -- register for clicks exactly like Blizzard action buttons: mouse-up for + -- normal actions, plus down-click support for ActionButtonUseKeyDown paths. self:EnableMouseWheel() - self:RegisterForClicks("AnyUp", "AnyDown") + self:RegisterForDrag("LeftButton", "RightButton") + self:RegisterForClicks("AnyUp", "LeftButtonDown", "RightButtonDown") -- secure handlers self:SetAttributeNoHandler('_childupdate-offset', [[ - local offset = message or 0 - local id = self:GetAttribute('index') + offset + local encodedOffset = tonumber(message) or 0 + local active + + if encodedOffset >= 100000 then + encodedOffset = encodedOffset - 100000 + active = 1 + end + + local id = self:GetAttribute('index') + encodedOffset if self:GetAttribute('action') ~= id then self:SetAttribute('action', id) end + + if self:GetAttribute("dominos-override-action-active") ~= active then + self:SetAttribute("dominos-override-action-active", active) + end + + local proxy = self:GetFrameRef("dominos-override-action-proxy") + if proxy then + if active then + proxy:Show(true) + else + proxy:Hide(true) + end + end + ]]) + + self:SetAttributeNoHandler('_childupdate-overrideactive', [[ + local active + if message == true or message == 1 or message == "1" then + active = 1 + end + + if self:GetAttribute("dominos-override-action-active") ~= active then + self:SetAttribute("dominos-override-action-active", active) + end + + local proxy = self:GetFrameRef("dominos-override-action-proxy") + if proxy then + if active then + proxy:Show(true) + else + proxy:Hide(true) + end + end + + self:RunAttribute("UpdateShown") ]]) self:SetAttributeNoHandler("SetShowGrid", [[ @@ -77,7 +206,20 @@ function ActionButton:OnCreate(id) if (prevValue ~= value) or force then self:SetAttribute("showgrid", value) - local show = (value > 0 or HasAction(self:GetAttribute("action"))) + local buttonType = self:GetAttribute("type") + local type1 = self:GetAttribute("type1") or self:GetAttribute("*type1") + local hasExternalActionOverride = self:GetAttribute("gse-button") + or self:GetAttribute("clickbutton") + or (buttonType and buttonType ~= "action" and buttonType ~= "actionrelease") + or (type1 and type1 ~= "action" and type1 ~= "actionrelease") + + if self:GetAttribute("dominos-override-action-active") then + hasExternalActionOverride = nil + end + + local show = (value > 0 + or HasAction(self:GetAttribute("action")) + or hasExternalActionOverride) and not self:GetAttribute("statehidden") if show then @@ -89,7 +231,20 @@ function ActionButton:OnCreate(id) ]]) self:SetAttributeNoHandler("UpdateShown", [[ - local show = (self:GetAttribute("showgrid") > 0 or HasAction(self:GetAttribute("action"))) + local buttonType = self:GetAttribute("type") + local type1 = self:GetAttribute("type1") or self:GetAttribute("*type1") + local hasExternalActionOverride = self:GetAttribute("gse-button") + or self:GetAttribute("clickbutton") + or (buttonType and buttonType ~= "action" and buttonType ~= "actionrelease") + or (type1 and type1 ~= "action" and type1 ~= "actionrelease") + + if self:GetAttribute("dominos-override-action-active") then + hasExternalActionOverride = nil + end + + local show = (self:GetAttribute("showgrid") > 0 + or HasAction(self:GetAttribute("action")) + or hasExternalActionOverride) and not self:GetAttribute("statehidden") if show then @@ -108,30 +263,43 @@ function ActionButton:OnCreate(id) end function ActionButton:UpdateIcon() - local icon = GetActionTexture(self.action) + local icon = GetActionTextureSafe(self.action) if icon then self.icon:SetTexture(icon) self.icon:Show() - else + elseif not HasExternalActionOverride(self) then self.icon:Hide() end end function ActionButton:UpdateOverrideBindings() if InCombatLockdown() then return end + if not self.bind then return end if C_HouseEditor and C_HouseEditor.IsHouseEditorActive() then ClearOverrideBindings(self.bind) - else - self.bind:SetOverrideBindings(GetBindingKey(self:GetAttribute("commandName"))) + return end + + local bindingCompat = GetBindingCompat() + if bindingCompat and bindingCompat.GetActionButtonBindingKeys then + local keys = bindingCompat.GetActionButtonBindingKeys(self:GetAttribute("bindingID"), self) + self.bind:SetOverrideBindings(HasExternalActionOverride(self), unpack(keys)) + return + end + + local command = GetActionButtonCommand(self) + local keys = command and { GetBindingKey(command) } or {} + self.bind:SetOverrideBindings(HasExternalActionOverride(self), unpack(keys)) end function ActionButton:UpdateShown() if InCombatLockdown() then return end self:SetShown( - (self:GetAttribute("showgrid") > 0 or HasAction(self:GetAttribute("action"))) + (self:GetAttribute("showgrid") > 0 + or HasAction(self:GetAttribute("action")) + or HasExternalActionOverride(self)) and not self:GetAttribute("statehidden") ) end @@ -151,10 +319,7 @@ end -- so we simply make our hotkeys transparent when we don't want them shown function ActionButton:SetShowBindingText(show) local parent = (show and self) or Addon.ShadowUIParent - - if self.HotKey:GetParent() ~= parent then - self.HotKey:SetParent(parent) - end + SetRegionParent(self.HotKey, parent) end -- we hide cooldowns when action buttons are transparent @@ -179,10 +344,7 @@ end function ActionButton:SetShowEquippedItemBorders(show) local parent = (show and self) or Addon.ShadowUIParent - - if self.Border:GetParent() ~= parent then - self.Border:SetParent(parent) - end + SetRegionParent(self.Border, parent) end function ActionButton:SetShowEmptyButtons(show, force) diff --git a/Dominos/bars/actionBar/buttons.lua b/Dominos/bars/actionBar/buttons.lua index 603c32a7..b3d8783e 100644 --- a/Dominos/bars/actionBar/buttons.lua +++ b/Dominos/bars/actionBar/buttons.lua @@ -4,6 +4,9 @@ local ActionButtons = CreateFrame('Frame', nil, nil, 'SecureHandlerAttributeTemp -- constants local ACTION_BUTTON_NAME_TEMPLATE = AddonName .. "ActionButton%d" +local function noop() +end + -------------------------------------------------------------------------------- -- State -------------------------------------------------------------------------------- @@ -21,6 +24,9 @@ ActionButtons.ShowGridReasons = { -- states -- [button] = action ActionButtons.buttons = {} +ActionButtons.blizzardActionButtonBridge = {} +ActionButtons.blizzardActionButtonBridgeHooked = {} +ActionButtons.pendingExternalOverrideUpdates = {} ActionButtons:Execute([[ ActionButtons = table.new() @@ -111,15 +117,22 @@ function ActionButtons:Initialize() -- of the reasons only triggered by game events (like ACTIONBAR_SHOWGRID). -- Propagate those changes to all the buttons managed by the controller. -- This allows us to properly show and hide action buttons in combat - -- when the player is attempting to drag and drop abilities - self:WrapScript(ActionButton1, "OnAttributeChanged", [[ - if name ~= "showgrid" then return end - - for reason = 2, 4, 2 do - local show = value % (reason * 2) >= reason - control:RunAttribute("SetShowGrid", show, reason) - end - ]]) + -- when the player is attempting to drag and drop abilities. + -- + -- Midnight hardens native action button attributes and cooldown values. + -- Dominos detaches hidden stock buttons from Blizzard's shared dispatchers + -- there, so avoid wrapping ActionButton1 and rely on the explicit + -- ACTIONBAR_SHOWGRID/ACTIONBAR_HIDEGRID events registered above. + if not Addon:IsAfterMidnight() then + self:WrapScript(ActionButton1, "OnAttributeChanged", [[ + if name ~= "showgrid" then return end + + for reason = 2, 4, 2 do + local show = value % (reason * 2) >= reason + control:RunAttribute("SetShowGrid", show, reason) + end + ]]) + end -- overlay glow hiding if ActionButtonSpellAlertManager then @@ -177,10 +190,51 @@ end -- reset grid state at login. This covers waiting for the game to apply the -- always show buttons state to the main bar function ActionButtons:PLAYER_LOGIN() - ActionButton1:SetAttribute("showgrid", 0) + if not Addon:IsAfterMidnight() then + ActionButton1:SetAttribute("showgrid", 0) + end + self:LAYOUT_LOADED() end +function ActionButtons:PLAYER_REGEN_ENABLED() + self:UnregisterEvent("PLAYER_REGEN_ENABLED") + + for sourceButton, targetButton in pairs(self.blizzardActionButtonBridge) do + self:MirrorBlizzardActionButtonOverride(sourceButton, targetButton) + end + + for button in pairs(self.pendingExternalOverrideUpdates) do + if button.UpdateShown then + button:UpdateShown() + end + + if button.UpdateOverrideBindings then + button:UpdateOverrideBindings() + end + + self.pendingExternalOverrideUpdates[button] = nil + end + + self:ForAll("UpdateShown") + self:ForAll("UpdateOverrideBindings") +end + +function ActionButtons:OnExternalOverrideChanged(buttonName) + local button = _G[buttonName] + if not button or not self.buttons[button] then + return + end + + if InCombatLockdown() then + self:QueueExternalOverrideUpdate(button) + return + end + + button:UpdateShown() + button:UpdateOverrideBindings() +end + -- force a visibility updates when spells changed (typically called when -- switching talents) function ActionButtons:SPELLS_CHANGED() @@ -234,6 +288,19 @@ local ActionButton_AttributeChanged = [[ control:CallMethod("OnActionChanged", self:GetName(), value, prevValue) end + elseif name == "type" + or name == "type1" + or name == "*type1" + or name == "typerelease" + or name == "clickbutton" + or name == "clickbutton1" + or name == "*clickbutton1" + or name == "gse-button" + or name == "gse-eff-action" + then + DirtyButtons[self] = true + control:SetAttribute("commit", 0) + control:CallMethod("OnExternalOverrideChanged", self:GetName(), name) end ]] @@ -261,6 +328,641 @@ local ActionButton_OnShowHide = [[ self:RunAttribute("UpdateShown") ]] + +local MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTES = { + "gse-button", + "gse-eff-action", + "type", + "type1", + "type2", + "*type1", + "*type2", + "typerelease", + "clickbutton", + "clickbutton1", + "clickbutton2", + "*clickbutton1", + "*clickbutton2", + "macro", + "macro1", + "macro2", + "*macro1", + "*macro2", + "macrotext", + "macrotext1", + "macrotext2", + "*macrotext1", + "*macrotext2", + "spell", + "spell1", + "spell2", + "*spell1", + "*spell2", + "item", + "item1", + "item2", + "*item1", + "*item2", + "unit", + "unit1", + "unit2", + "*unit1", + "*unit2", +} + +local MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTE_SET = {} +for _, attributeName in ipairs(MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTES) do + MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTE_SET[attributeName] = true +end + +local function IsMirroredExternalOverrideAttribute(attributeName) + return MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTE_SET[attributeName] == true +end + +local function IsExternalActionOverrideType(actionType) + return actionType ~= nil and actionType ~= "action" and actionType ~= "actionrelease" +end + +local function HasExternalActionOverrideAttributes(button) + if not button or not button.GetAttribute then + return nil + end + + return button:GetAttribute("gse-button") + or button:GetAttribute("clickbutton") + or IsExternalActionOverrideType(button:GetAttribute("type")) + or IsExternalActionOverrideType(button:GetAttribute("type1")) + or IsExternalActionOverrideType(button:GetAttribute("*type1")) +end + +local ACTION_BUTTON_CAST_TYPE_CAST = 1 +local ACTION_BUTTON_CAST_TYPE_CHANNEL = 2 +local ACTION_BUTTON_CAST_TYPE_EMPOWERED = 3 + +local function ClearCooldown(cooldown) + if cooldown and cooldown.Clear then + cooldown:Clear() + end +end + +local function ClearActionButtonCooldownsSafe(button) + ClearCooldown(button and button.cooldown) + ClearCooldown(button and button.chargeCooldown) + ClearCooldown(button and button.lossOfControlCooldown) +end + +local function SetCooldownFromDurationObject(cooldown, duration) + if not cooldown then + return + end + + if duration and cooldown.SetCooldownFromDurationObject then + cooldown:SetCooldownFromDurationObject(duration, true) + else + cooldown:Clear() + end +end + +local function GetActionCooldownDuration(action, ignoreGCD) + if C_ActionBar and C_ActionBar.GetActionCooldownDuration then + return C_ActionBar.GetActionCooldownDuration(action, ignoreGCD and true or false) + end +end + +local function GetActionChargeDuration(action) + if C_ActionBar and C_ActionBar.GetActionChargeDuration then + return C_ActionBar.GetActionChargeDuration(action) + end +end + +local function GetActionLossOfControlCooldownDuration(action) + if C_ActionBar and C_ActionBar.GetActionLossOfControlCooldownDuration then + return C_ActionBar.GetActionLossOfControlCooldownDuration(action) + end +end + +local function HasActionSafe(action) + if action and C_ActionBar and C_ActionBar.HasAction then + return C_ActionBar.HasAction(action) + end + + return action and HasAction(action) +end + +local function GetActionTextureForUpdate(action) + if C_ActionBar and C_ActionBar.GetActionTexture then + return C_ActionBar.GetActionTexture(action) + end + + return GetActionTexture(action) +end + +local function DominosActionButton_UpdateCount(button) + local updateCount = button and button.dominosNativeUpdateCount + if type(updateCount) ~= "function" then + return + end + + local ok = pcall(updateCount, button) + if not ok and button.Count then + button.Count:SetText("") + end +end + +local function DominosActionButton_UpdateCooldown(button) + local action = button and (button.action or button:GetAttribute("action")) + if not action or not HasActionSafe(action) then + ClearActionButtonCooldownsSafe(button) + return + end + + -- Midnight cooldown APIs can return secret start/duration values. The safe + -- public replacement path is to pass Blizzard's duration object directly to + -- the cooldown frame instead of reading start/duration and calling SetCooldown. + SetCooldownFromDurationObject(button.cooldown, GetActionCooldownDuration(action, false)) + SetCooldownFromDurationObject(button.chargeCooldown, GetActionChargeDuration(action)) + + if button.enableLOCCooldown then + SetCooldownFromDurationObject(button.lossOfControlCooldown, GetActionLossOfControlCooldownDuration(action)) + else + ClearCooldown(button.lossOfControlCooldown) + end +end + +local function InstallMidnightPressAndHoldUpdater(button) + if not button or button.dominosMidnightPressAndHoldUpdaterInstalled then + return + end + + if type(button.SetAttributeNoHandler) ~= "function" then + return + end + + button:SetAttributeNoHandler("UpdatePressAndHoldAction", [[ + local pressAndHoldAction = false + local action + + if self.CalculateAction then + action = self:CalculateAction() + end + + if not action then + action = self:GetAttribute("action") + end + + if action and action ~= 0 then + local actionType, id = GetActionInfo(action) + if actionType == "spell" and id then + pressAndHoldAction = IsPressHoldReleaseSpell(id) + end + end + + if self:GetAttribute("pressAndHoldAction") ~= pressAndHoldAction then + self:SetAttribute("pressAndHoldAction", pressAndHoldAction) + end + ]]) + + button.dominosMidnightPressAndHoldUpdaterInstalled = true +end + +local function DominosActionButton_UpdatePressAndHoldAction(button) + if button and button.RunAttribute and button:GetAttribute("UpdatePressAndHoldAction") then + button:RunAttribute("UpdatePressAndHoldAction") + end +end + +local function DominosActionButton_Update(button) + local action = button.action or button:GetAttribute("action") + local icon = button.icon + local texture = GetActionTextureForUpdate(action) + + if icon then + icon:SetDesaturated(false) + end + + if HasActionSafe(action) then + if not button.eventsRegistered and ActionBarActionEventsFrame then + ActionBarActionEventsFrame:RegisterFrame(button) + button.eventsRegistered = true + end + + if button.UpdateState then button:UpdateState() end + if button.UpdateUsable then button:UpdateUsable() end + if button.UpdateProfessionQuality then button:UpdateProfessionQuality() end + if button.UpdateTypeOverlay then button:UpdateTypeOverlay() end + DominosActionButton_UpdateCooldown(button) + if button.UpdateFlash then button:UpdateFlash() end + if button.UpdateHighlightMark then button:UpdateHighlightMark() end + if button.UpdateSpellHighlightMark then button:UpdateSpellHighlightMark() end + else + if button.eventsRegistered and ActionBarActionEventsFrame then + ActionBarActionEventsFrame:UnregisterFrame(button) + button.eventsRegistered = nil + end + + ClearActionButtonCooldownsSafe(button) + if button.ClearFlash then button:ClearFlash() end + button:SetChecked(false) + if button.ClearProfessionQuality then button:ClearProfessionQuality() end + if button.ClearTypeOverlay then button:ClearTypeOverlay() end + + if button.LevelLinkLockIcon then + button.LevelLinkLockIcon:SetShown(false) + end + end + + DominosActionButton_UpdatePressAndHoldAction(button) + + local border = button.Border + if border then + if action and C_ActionBar and C_ActionBar.IsEquippedAction and C_ActionBar.IsEquippedAction(action) then + border:SetVertexColor(0, 1.0, 0, 0.5) + border:Show() + else + border:Hide() + end + end + + local actionName = button.Name + if actionName then + if action and C_ActionBar and C_ActionBar.UsesActionText and C_ActionBar.UsesActionText(action) then + actionName:SetText(C_ActionBar.GetActionText(action)) + else + actionName:SetText("") + end + end + + if texture and icon then + icon:SetTexture(texture) + icon:Show() + if button.UpdateCount then button:UpdateCount() end + else + if button.Count then button.Count:SetText("") end + if icon then icon:Hide() end + ClearActionButtonCooldownsSafe(button) + + local hotkey = button.HotKey + if hotkey then + if hotkey:GetText() == RANGE_INDICATOR then + hotkey:Hide() + elseif ACTIONBAR_HOTKEY_FONT_COLOR then + hotkey:SetVertexColor(ACTIONBAR_HOTKEY_FONT_COLOR:GetRGB()) + end + end + end + + if button.UpdateFlyout then button:UpdateFlyout() end + if button.UpdateSpellAlert then button:UpdateSpellAlert() end + + if GameTooltip:GetOwner() == button and button.SetTooltip then + button:SetTooltip() + end + + button.feedback_action = action +end + +local function DominosActionButton_OnEvent(button, event, ...) + local arg1 = ... + + if ((event == "UNIT_INVENTORY_CHANGED" and arg1 == "player") or event == "LEARNED_SPELL_IN_SKILL_LINE") then + if GameTooltip:GetOwner() == button and button.SetTooltip then + button:SetTooltip() + end + elseif event == "ACTIONBAR_SLOT_CHANGED" then + if arg1 == 0 or arg1 == tonumber(button.action) then + ClearNewActionHighlight(button.action, true) + button:UpdateAction(true) + end + elseif event == "PLAYER_ENTERING_WORLD" then + button:Update() + elseif event == "UPDATE_SHAPESHIFT_FORM" then + local texture = GetActionTextureForUpdate(button.action) + if texture then + button.icon:SetTexture(texture) + end + elseif event == "UPDATE_BINDINGS" or event == "GAME_PAD_ACTIVE_CHANGED" then + button:UpdateHotkeys(button.buttonType) + elseif event == "UNIT_FLAGS" or event == "UNIT_AURA" or event == "PET_BAR_UPDATE" then + button.flashDirty = true + button.stateDirty = true + button:CheckNeedsUpdate() + elseif event == "ACTIONBAR_UPDATE_STATE" + or ((event == "UNIT_ENTERED_VEHICLE" or event == "UNIT_EXITED_VEHICLE") and arg1 == "player") + or (event == "COMPANION_UPDATE" and arg1 == "MOUNT") + then + button:UpdateState() + elseif event == "PLAYER_MOUNT_DISPLAY_CHANGED" then + button:UpdateUsable() + elseif event == "LOSS_OF_CONTROL_UPDATE" then + DominosActionButton_UpdateCooldown(button) + elseif event == "ACTIONBAR_UPDATE_COOLDOWN" or event == "LOSS_OF_CONTROL_ADDED" then + DominosActionButton_UpdateCooldown(button) + if GameTooltip:GetOwner() == button and button.SetTooltip then + button:SetTooltip() + end + elseif event == "TRADE_SKILL_SHOW" or event == "TRADE_SKILL_CLOSE" or event == "ARCHAEOLOGY_CLOSED" then + button:UpdateState() + elseif event == "PLAYER_ENTER_COMBAT" then + if C_ActionBar and C_ActionBar.IsAttackAction and C_ActionBar.IsAttackAction(button.action) then + button:StartFlash() + end + elseif event == "PLAYER_LEAVE_COMBAT" then + if C_ActionBar and C_ActionBar.IsAttackAction and C_ActionBar.IsAttackAction(button.action) then + button:StopFlash() + end + elseif event == "START_AUTOREPEAT_SPELL" then + if C_ActionBar and C_ActionBar.IsAutoRepeatAction and C_ActionBar.IsAutoRepeatAction(button.action) then + button:StartFlash() + end + elseif event == "STOP_AUTOREPEAT_SPELL" then + if button:IsFlashing() and not (C_ActionBar and C_ActionBar.IsAttackAction and C_ActionBar.IsAttackAction(button.action)) then + button:StopFlash() + end + elseif event == "PET_STABLE_UPDATE" or event == "PET_STABLE_SHOW" then + button:Update() + elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then + local actionType, id, subType = GetActionInfo(button.action) + if actionType == "spell" and id == arg1 then + ActionButtonSpellAlertManager:ShowAlert(button) + elseif actionType == "macro" and subType == "spell" and id == arg1 then + ActionButtonSpellAlertManager:ShowAlert(button) + elseif actionType == "flyout" and FlyoutHasSpell(id, arg1) then + ActionButtonSpellAlertManager:ShowAlert(button) + end + elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then + local actionType, id, subType = GetActionInfo(button.action) + if actionType == "spell" and id == arg1 then + ActionButtonSpellAlertManager:HideAlert(button) + elseif actionType == "macro" and subType == "spell" and id == arg1 then + ActionButtonSpellAlertManager:HideAlert(button) + elseif actionType == "flyout" and FlyoutHasSpell(id, arg1) then + ActionButtonSpellAlertManager:HideAlert(button) + end + elseif event == "SPELL_UPDATE_CHARGES" then + button:UpdateCount() + elseif event == "UPDATE_SUMMONPETS_ACTION" then + local actionType = GetActionInfo(button.action) + if actionType == "summonpet" then + local texture = GetActionTextureForUpdate(button.action) + if texture then + button.icon:SetTexture(texture) + end + end + elseif event == "SPELL_UPDATE_ICON" then + button:Update() + elseif event == "ACTION_RANGE_CHECK_UPDATE" then + local inRange, checksRange = select(2, ...) + ActionButton_UpdateRangeIndicator(button, checksRange, inRange) + elseif event == "UNIT_SPELLCAST_INTERRUPTED" then + button:PlaySpellInterruptedAnim() + elseif event == "UNIT_SPELLCAST_START" then + button:PlaySpellCastAnim(ACTION_BUTTON_CAST_TYPE_CAST) + elseif event == "UNIT_SPELLCAST_STOP" then + button:StopSpellCastAnim(true, ACTION_BUTTON_CAST_TYPE_CAST) + button:StopTargettingReticleAnim() + elseif event == "UNIT_SPELLCAST_SUCCEEDED" then + button:StopSpellCastAnim(false, ACTION_BUTTON_CAST_TYPE_CAST) + button:StopTargettingReticleAnim() + elseif event == "UNIT_SPELLCAST_SENT" or event == "UNIT_SPELLCAST_FAILED" then + button:StopTargettingReticleAnim() + elseif event == "UNIT_SPELLCAST_EMPOWER_START" then + button:PlaySpellCastAnim(ACTION_BUTTON_CAST_TYPE_EMPOWERED) + elseif event == "UNIT_SPELLCAST_EMPOWER_STOP" then + local _, _, _, castComplete = ... + local interrupted = not castComplete + if interrupted then + button:PlaySpellInterruptedAnim() + else + button:StopSpellCastAnim(interrupted, ACTION_BUTTON_CAST_TYPE_EMPOWERED) + end + elseif event == "UNIT_SPELLCAST_CHANNEL_START" then + button:PlaySpellCastAnim(ACTION_BUTTON_CAST_TYPE_CHANNEL) + elseif event == "UNIT_SPELLCAST_CHANNEL_STOP" then + button:StopSpellCastAnim(false, ACTION_BUTTON_CAST_TYPE_CHANNEL) + elseif event == "UNIT_SPELLCAST_RETICLE_TARGET" then + button:PlayTargettingReticleAnim() + elseif event == "UNIT_SPELLCAST_RETICLE_CLEAR" then + button:StopTargettingReticleAnim() + elseif event == "AssistedCombatManager.OnSetActionSpell" then + button:UpdateAssistedCombatRotationFrame() + end +end + +local function ApplyMidnightActionButtonSafety(button) + -- Midnight restricts passing action cooldown start/duration secrets through + -- tainted Lua. Dominos buttons are addon-owned ActionButtonTemplate frames, so + -- using Blizzard's shared OnEvent/Update path now pushes protected cooldown and + -- press-and-hold mutations through a tainted stack. Keep the Blizzard frame + -- contract, but replace only the unsafe dispatch methods with duration-object + -- based equivalents. + if not Addon:IsAfterMidnight() then + return + end + + InstallMidnightPressAndHoldUpdater(button) + + if button.dominosMidnightActionButtonSafetyApplied then + return + end + + button.dominosNativeOnEvent = button.OnEvent + button.dominosNativeUpdate = button.Update + button.dominosNativeUpdatePressAndHoldAction = button.UpdatePressAndHoldAction + button.dominosNativeUpdateCount = button.UpdateCount + + button.OnEvent = DominosActionButton_OnEvent + button.Update = DominosActionButton_Update + button.UpdateCount = DominosActionButton_UpdateCount + button.UpdatePressAndHoldAction = DominosActionButton_UpdatePressAndHoldAction + button.dominosMidnightActionButtonSafetyApplied = true +end + +local function SetAttributeIfChanged(button, attributeName, value) + if button:GetAttribute(attributeName) ~= value then + button:SetAttribute(attributeName, value) + end +end + +local function GetButtonIcon(button) + if not button then + return nil + end + + return button.icon or button.Icon or (button.GetName and _G[button:GetName() .. "Icon"]) +end + +local function CopyButtonIcon(sourceButton, targetButton) + local sourceIcon = GetButtonIcon(sourceButton) + local targetIcon = GetButtonIcon(targetButton) + if not sourceIcon or not targetIcon or not sourceIcon.GetTexture then + return + end + + local texture = sourceIcon:GetTexture() + if texture then + targetIcon:SetTexture(texture) + targetIcon:Show() + end +end + +local function ScheduleButtonIconCopy(sourceButton, targetButton) + CopyButtonIcon(sourceButton, targetButton) + + if C_Timer and C_Timer.After then + C_Timer.After(0, function() + if targetButton and targetButton.GetAttribute and targetButton:GetAttribute("gse-button") then + CopyButtonIcon(sourceButton, targetButton) + end + end) + end +end + +local function RestoreNativeActionAttributes(button) + SetAttributeIfChanged(button, "type", "action") + SetAttributeIfChanged(button, "typerelease", "actionrelease") + + for _, attributeName in ipairs(MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTES) do + if attributeName ~= "type" and attributeName ~= "typerelease" then + SetAttributeIfChanged(button, attributeName, nil) + end + end +end + +function ActionButtons:QueueExternalOverrideUpdate(button) + if not button then + return + end + + self.pendingExternalOverrideUpdates[button] = true + self:RegisterEvent("PLAYER_REGEN_ENABLED") +end + +function ActionButtons:MirrorBlizzardActionButtonOverride(sourceButton, targetButton) + if not sourceButton or not targetButton or sourceButton == targetButton then + return + end + + if InCombatLockdown() then + self:QueueExternalOverrideUpdate(targetButton) + return + end + + if HasExternalActionOverrideAttributes(sourceButton) then + targetButton.dominosExternalOverrideBridgeSource = sourceButton + + for _, attributeName in ipairs(MIRRORED_EXTERNAL_OVERRIDE_ATTRIBUTES) do + SetAttributeIfChanged(targetButton, attributeName, sourceButton:GetAttribute(attributeName)) + end + + if sourceButton:GetAttribute("clickbutton") and not targetButton:GetAttribute("type") then + SetAttributeIfChanged(targetButton, "type", "click") + end + + ScheduleButtonIconCopy(sourceButton, targetButton) + elseif targetButton.dominosExternalOverrideBridgeSource == sourceButton then + targetButton.dominosExternalOverrideBridgeSource = nil + RestoreNativeActionAttributes(targetButton) + end + + if targetButton.UpdateShown then + targetButton:UpdateShown() + end + + if targetButton.UpdateOverrideBindings then + targetButton:UpdateOverrideBindings() + end +end + +local function BlizzardActionButton_OnAttributeChanged(sourceButton, attributeName) + if not IsMirroredExternalOverrideAttribute(attributeName) then + return + end + + local targetButton = ActionButtons.blizzardActionButtonBridge[sourceButton] + if targetButton then + ActionButtons:MirrorBlizzardActionButtonOverride(sourceButton, targetButton) + end +end + +local function SuppressHiddenBlizzardActionButtonSource(sourceButton) + if not Addon:IsAfterMidnight() or not sourceButton or sourceButton.dominosBlizzardBridgeSourceSuppressed then + return + end + + -- These source buttons are kept only as Blizzard-compatible external contract + -- anchors. They must not continue running Blizzard's native action update path + -- while Dominos owns the visible action button, because that path can call + -- protected SetAttribute/SetCooldown with Midnight secret values from a + -- Dominos-tainted stack. + sourceButton.dominosNativeOnEvent = sourceButton.OnEvent + sourceButton.dominosNativeOnUpdate = sourceButton.OnUpdate + sourceButton.dominosNativeUpdate = sourceButton.Update + sourceButton.dominosNativeUpdateAction = sourceButton.UpdateAction + sourceButton.dominosNativeUpdatePressAndHoldAction = sourceButton.UpdatePressAndHoldAction + sourceButton.dominosNativeCheckNeedsUpdate = sourceButton.CheckNeedsUpdate + sourceButton.dominosNativeActionButtonOnClick = sourceButton.ActionBarActionButtonDerivedMixin_OnClick + + sourceButton.OnEvent = noop + sourceButton.OnUpdate = noop + sourceButton.Update = noop + sourceButton.UpdateAction = noop + sourceButton.UpdatePressAndHoldAction = noop + sourceButton.CheckNeedsUpdate = noop + sourceButton.ActionBarActionButtonDerivedMixin_OnClick = noop + sourceButton.eventsRegistered = nil + sourceButton.needsUpdate = nil + sourceButton.dominosBlizzardBridgeSourceSuppressed = true +end + +local function GetBlizzardActionButtonName(id) + if id >= 1 and id <= 12 then + return ("ActionButton%d"):format(id) + elseif id >= 25 and id <= 36 then + return ("MultiBarRightButton%d"):format(id - 24) + elseif id >= 37 and id <= 48 then + return ("MultiBarLeftButton%d"):format(id - 36) + elseif id >= 49 and id <= 60 then + return ("MultiBarBottomRightButton%d"):format(id - 48) + elseif id >= 61 and id <= 72 then + return ("MultiBarBottomLeftButton%d"):format(id - 60) + elseif id >= 133 and id <= 144 then + return ("MultiBar5Button%d"):format(id - 132) + elseif id >= 145 and id <= 156 then + return ("MultiBar6Button%d"):format(id - 144) + elseif id >= 157 and id <= 168 then + return ("MultiBar7Button%d"):format(id - 156) + end +end + +function ActionButtons:ApplyMidnightActionButtonSafety(button) + ApplyMidnightActionButtonSafety(button) +end + +function ActionButtons:RegisterBlizzardActionButtonBridge(button, id) + local sourceName = GetBlizzardActionButtonName(id) + if not sourceName then + return + end + + local sourceButton = _G[sourceName] + if not sourceButton or sourceButton == button then + return + end + + SuppressHiddenBlizzardActionButtonSource(sourceButton) + + self.blizzardActionButtonBridge[sourceButton] = button + button.dominosBlizzardActionButtonBridgeSource = sourceButton + button.blizzardActionButtonName = sourceButton:GetName() + + if not self.blizzardActionButtonBridgeHooked[sourceButton] then + sourceButton:HookScript("OnAttributeChanged", BlizzardActionButton_OnAttributeChanged) + self.blizzardActionButtonBridgeHooked[sourceButton] = true + end + + self:MirrorBlizzardActionButtonOverride(sourceButton, button) +end + local function GetActionButtonName(id) if id <= 0 then return @@ -343,6 +1045,9 @@ function ActionButtons:GetOrCreateActionButton(id, parent) end if created then + ApplyMidnightActionButtonSafety(button) + self:AddOverrideActionProxy(button) + -- add secure handlers self:WrapScript(button, "OnAttributeChanged", ActionButton_AttributeChanged) self:WrapScript(button, "PostClick", ActionButton_PostClick) @@ -363,39 +1068,102 @@ function ActionButtons:GetOrCreateActionButton(id, parent) self.buttons[button] = 0 end + self:RegisterBlizzardActionButtonBridge(button, id) + return button end +local function GetOverrideActionProxyName(button) + local name = button and button:GetName() + if name then + return name .. "OverrideActionProxy" + end +end + +function ActionButtons:AddOverrideActionProxy(button) + if button.dominosOverrideActionProxy then + return button.dominosOverrideActionProxy + end + + local proxyName = GetOverrideActionProxyName(button) + if not proxyName then + return nil + end + + -- This transparent child is only shown while Dominos' configured + -- override/vehicle/possess bar is active. It executes the current action + -- slot through Blizzard's native SecureActionButtonTemplate while the + -- visible Dominos button keeps any GSE/clickbutton attributes untouched. + local proxy = CreateFrame("Button", proxyName, button, "SecureActionButtonTemplate") + proxy:SetAllPoints(button) + proxy:SetFrameLevel(button:GetFrameLevel() + 10) + proxy:EnableMouse(true) + proxy:RegisterForClicks("AnyUp", "LeftButtonDown", "RightButtonDown") + + proxy:SetAttributeNoHandler("type", "action") + proxy:SetAttributeNoHandler("typerelease", "actionrelease") + proxy:SetAttributeNoHandler("useparent-action", true) + proxy:SetAttributeNoHandler("useparent-checkfocuscast", true) + proxy:SetAttributeNoHandler("useparent-checkmouseovercast", true) + proxy:SetAttributeNoHandler("useparent-checkselfcast", true) + proxy:SetAttributeNoHandler("useparent-flyoutDirection", true) + proxy:SetAttributeNoHandler("useparent-pressAndHoldAction", true) + proxy:SetAttributeNoHandler("useparent-unit", true) + proxy:Hide() + + SecureHandlerSetFrameRef(button, "dominos-override-action-proxy", proxy) + button.dominosOverrideActionProxy = proxy + + if Addon.SpellFlyout then + Addon.SpellFlyout:Register(proxy) + end + + return proxy +end + -- update the pushed state of our parent button when pressing and releasing --- the button's hotkey +-- the button's hotkey. The hidden secure proxy owns override bindings for normal +-- slot execution. When an external addon replaces the visible button contract +-- with a clickbutton/macro/spell override, bindings are retargeted to the visible +-- button so the external secure override receives the same click as the mouse. local function bindButton_PreClick(self, _, down) local owner = self:GetParent() + if not owner then + return + end if down then if owner:GetButtonState() == "NORMAL" then owner:SetButtonState("PUSHED") end - else - if owner:GetButtonState() == "PUSHED" then - owner:SetButtonState("NORMAL") - end + elseif owner:GetButtonState() == "PUSHED" then + owner:SetButtonState("NORMAL") end end -local function bindButton_SetOverrideBindings(self, ...) +local function bindButton_SetOverrideBindings(self, useVisibleButton, ...) ClearOverrideBindings(self) - local name = self:GetName() + local owner = self:GetParent() + local targetName = useVisibleButton and owner and owner:GetName() or self:GetName() + local targetButton = useVisibleButton and "LeftButton" or "HOTKEY" + if not targetName then + return + end + for i = 1, select("#", ...) do - SetOverrideBindingClick(self, false, select(i, ...), name, "HOTKEY") + local key = select(i, ...) + if key then + SetOverrideBindingClick(self, false, key, targetName, targetButton) + end end end --- cast on keypress support is implemented by using a second hidden button --- that mirrors all ofthe attributes of its parent button. This is to work --- around inconsistent handling of drag and drop if we just use the --- SecureActionButtonTemplate for buttons, as well as the OnClick handler --- for action buttons only triggering actions on key release. +-- Cast-on-keypress support is implemented by using a second hidden button that +-- mirrors the secure action attributes of its parent. Native Blizzard binding +-- keys are captured with override bindings and redirected here for normal action +-- slots so addon-created Dominos buttons are not executed through Blizzard's +-- restricted ACTIONBUTTON binding snippets. function ActionButtons:AddCastOnKeyPressSupport(button) local bind = CreateFrame("Button", "$parentHotkey", button, "SecureActionButtonTemplate") @@ -412,16 +1180,15 @@ function ActionButtons:AddCastOnKeyPressSupport(button) bind:EnableMouseWheel() bind:RegisterForClicks("AnyUp", "AnyDown") - bind:SetScript("PreClick", bindButton_PreClick) - bind.SetOverrideBindings = bindButton_SetOverrideBindings if Addon.SpellFlyout then Addon.SpellFlyout:Register(bind) end - -- translate HOTKEY button "clicks" into LeftButton + -- Translate HOTKEY button clicks into LeftButton. This matches the old + -- Dominos fallback path while preserving flyout safety on Midnight builds. if Addon:IsAfterMidnight() then self:WrapScript(bind, "OnClick", [[ if button == "HOTKEY" then diff --git a/Dominos/bars/extraAbilityBar.lua b/Dominos/bars/extraAbilityBar.lua index 18803293..475a929e 100644 --- a/Dominos/bars/extraAbilityBar.lua +++ b/Dominos/bars/extraAbilityBar.lua @@ -4,9 +4,92 @@ local AddonName, Addon = ... local L = LibStub("AceLocale-3.0"):GetLocale(AddonName) local BAR_ID = 'extra' +local EXTRA_ACTION_EVENTS = { + 'PLAYER_ENTERING_WORLD', + 'UPDATE_EXTRA_ACTIONBAR' +} local ExtraAbilityBar = Addon:CreateClass('Frame', Addon.Frame) +local function hasExtraActionBar() + if C_ActionBar and type(C_ActionBar.HasExtraActionBar) == 'function' then + return C_ActionBar.HasExtraActionBar() + end + + if type(HasExtraActionBar) == 'function' then + return HasExtraActionBar() + end + + return false +end + +local function hasNativeExtraActionRelay() + return Addon.IsAfterMidnight and Addon:IsAfterMidnight() +end + +local function getExtraAbilityContainer() + return ExtraAbilityContainer or ExtraActionBarFrame +end + +local function getExtraActionButton() + return ExtraActionBarFrame and ExtraActionBarFrame.button +end + +local function setFramePoint(frame, point, relativeFrame) + if frame.ClearAllPointsBase and frame.SetPointBase then + frame:ClearAllPointsBase() + frame:SetPointBase(point, relativeFrame) + return + end + + frame:ClearAllPoints() + frame:SetPoint(point, relativeFrame) +end + +local function setFrameShown(frame, show) + if not frame then + return + end + + if frame.SetShown then + frame:SetShown(show and true or false) + elseif show then + frame:Show() + else + frame:Hide() + end +end + +local function applyExtraActionButtonSafety() + if not hasNativeExtraActionRelay() then + return + end + + local actionButtons = Addon.ActionButtons + if not actionButtons or type(actionButtons.ApplyMidnightActionButtonSafety) ~= 'function' then + return + end + + actionButtons:ApplyMidnightActionButtonSafety(getExtraActionButton()) +end + +local function themeButton(button, enable, styleInfo) + if not button then + return + end + + local themer = Addon:GetModule('ButtonThemer', true) + if not themer then + return + end + + if enable then + themer:Register(button, 'Extra Bar', styleInfo) + else + themer:Unregister(button, 'Extra Bar') + end +end + function ExtraAbilityBar:New() return ExtraAbilityBar.proto.New(self, BAR_ID) end @@ -22,31 +105,15 @@ ExtraAbilityBar:Extend('OnAcquire', function(self) end) function ExtraAbilityBar:ThemeBar(enable) - if HasExtraActionBar() then - local button = ExtraActionBarFrame and ExtraActionBarFrame.button - if button then - if enable then - Addon:GetModule('ButtonThemer'):Register(button, 'Extra Bar') - else - Addon:GetModule('ButtonThemer'):Unregister(button, 'Extra Bar') - end - end + if hasExtraActionBar() then + applyExtraActionButtonSafety() + themeButton(getExtraActionButton(), enable) end - local zoneAbilities = C_ZoneAbility and C_ZoneAbility.GetActiveAbilities() - if type(zoneAbilities) == "table" and #zoneAbilities > 0 then + if ZoneAbilityFrame and ZoneAbilityFrame.SpellButtonContainer + and type(ZoneAbilityFrame.SpellButtonContainer.EnumerateActive) == 'function' then for button in ZoneAbilityFrame.SpellButtonContainer:EnumerateActive() do - if button then - if enable then - Addon:GetModule('ButtonThemer'):Register( - button, 'Extra Bar', {Icon = button.Icon} - ) - else - Addon:GetModule('ButtonThemer'):Unregister( - button, 'Extra Bar' - ) - end - end + themeButton(button, enable, { Icon = button.Icon }) end end end @@ -70,19 +137,21 @@ function ExtraAbilityBar:Layout() end function ExtraAbilityBar:RepositionExtraAbilityContainer() - if InCombatLockdown() then return end - - local container = ExtraAbilityContainer or ExtraActionBarFrame + if InCombatLockdown() then + return false + end - container:SetParent(self) + local container = getExtraAbilityContainer() + if not container then + return false + end - if container.ClearAllPointsBase then - container:ClearAllPointsBase() - container:SetPointBase('CENTER', self) - else - container:ClearAllPoints() - container:SetPoint('CENTER', self) + if container:GetParent() ~= self then + container:SetParent(self) end + + setFramePoint(container, 'CENTER', self) + return true end function ExtraAbilityBar:OnCreateMenu(menu) @@ -112,38 +181,40 @@ end function ExtraAbilityBar:ShowBlizzardTexture(show) self.sets.hideBlizzardTeture = not show + self.sets.hideBlizzardTexture = not show self:UpdateShowBlizzardTexture() end function ExtraAbilityBar:ShowingBlizzardTexture() + if self.sets.hideBlizzardTexture ~= nil then + return not self.sets.hideBlizzardTexture + end + return not self.sets.hideBlizzardTeture end function ExtraAbilityBar:UpdateShowBlizzardTexture() - if self:ShowingBlizzardTexture() then - ExtraActionBarFrame.button.style:Show() - - if ZoneAbilityFrame then - ZoneAbilityFrame.Style:Show() - end + local showTexture = self:ShowingBlizzardTexture() + local button = getExtraActionButton() - self:ThemeBar(false) - else - ExtraActionBarFrame.button.style:Hide() - - if ZoneAbilityFrame then - ZoneAbilityFrame.Style:Hide() - end + if button and button.style then + setFrameShown(button.style, showTexture) + end - self:ThemeBar(true) + if ZoneAbilityFrame and ZoneAbilityFrame.Style then + setFrameShown(ZoneAbilityFrame.Style, showTexture) end + + self:ThemeBar(not showTexture) end local ExtraAbilityBarModule = Addon:NewModule('ExtraAbilityBar') function ExtraAbilityBarModule:Load() + applyExtraActionButtonSafety() self.frame = ExtraAbilityBar:New() + self:RefreshNativeExtraActionBar() end function ExtraAbilityBarModule:Unload() @@ -155,43 +226,88 @@ end function ExtraAbilityBarModule:OnFirstLoad() self:ApplyTitanPanelWorkarounds() + self:InstallExtraActionRelay() + applyExtraActionButtonSafety() - -- disable mouse interactions on the extra action bar - -- as it can sometimes block the UI from being interactive - if ExtraActionBarFrame:IsMouseEnabled() then + -- Disable mouse interactions on the container frame only. The actual + -- ExtraActionButton1 child must remain clickable and secure. + if ExtraActionBarFrame and ExtraActionBarFrame:IsMouseEnabled() then ExtraActionBarFrame:EnableMouse(false) end - -- onshow/hide call UpdateManagedFramePositions on the blizzard end so - -- turn that bit off + -- OnShow/OnHide call UpdateManagedFramePositions on the Blizzard end, so + -- turn that bit off while Dominos owns placement. if ExtraAbilityContainer then - ExtraAbilityContainer:SetScript("OnShow", nil) - ExtraAbilityContainer:SetScript("OnHide", nil) - - -- watch for new frames to be added to the container as we will want to - -- possibly theme them later (if they're new buttons) - hooksecurefunc( - ExtraAbilityContainer, 'AddFrame', function() - if self.frame then - self.frame:ThemeBar(not self.frame:ShowingBlizzardTexture()) - end + ExtraAbilityContainer:SetScript('OnShow', nil) + ExtraAbilityContainer:SetScript('OnHide', nil) + + -- Watch for new frames to be added to the container as we will want to + -- possibly theme them later (if they're new buttons). + hooksecurefunc(ExtraAbilityContainer, 'AddFrame', function() + if self.frame then + self.frame:ThemeBar(not self.frame:ShowingBlizzardTexture()) end - ) - - -- also reposition whenever edit mode tries to do so - hooksecurefunc(ExtraAbilityContainer, 'ApplySystemAnchor', function() - self:RepositionExtraAbilityContainer() end) - else + + -- Also reposition whenever Edit Mode tries to do so. + if type(ExtraAbilityContainer.ApplySystemAnchor) == 'function' then + hooksecurefunc(ExtraAbilityContainer, 'ApplySystemAnchor', function() + self:RepositionExtraAbilityContainer() + end) + end + elseif ExtraActionBarFrame then ExtraActionBarFrame.ignoreFramePositionManager = true end end +function ExtraAbilityBarModule:InstallExtraActionRelay() + if self.extraActionRelay or not hasNativeExtraActionRelay() then + return + end + + if type(ExtraActionBar_Update) ~= 'function' then + return + end + + local relay = CreateFrame('Frame') + for _, event in ipairs(EXTRA_ACTION_EVENTS) do + relay:RegisterEvent(event) + end + + relay:SetScript('OnEvent', function() + self:RefreshNativeExtraActionBar() + end) + + self.extraActionRelay = relay +end + +function ExtraAbilityBarModule:RefreshNativeExtraActionBar() + applyExtraActionButtonSafety() + + -- Midnight Dominos intentionally disables Blizzard's ActionBarController to + -- avoid hidden native main-bar taint. That also removes Blizzard's native + -- UPDATE_EXTRA_ACTIONBAR dispatcher, so restore only this safe, narrow path. + if hasNativeExtraActionRelay() and type(ExtraActionBar_Update) == 'function' then + ExtraActionBar_Update() + end + + if self.frame then + self.frame:RepositionExtraAbilityContainer() + self.frame:UpdateShowBlizzardTexture() + end +end + function ExtraAbilityBarModule:RepositionExtraAbilityContainer() - if (not self.frame) then return end + if not self.frame then + return + end - local _, relFrame = ExtraAbilityContainer:GetPoint() + local container = getExtraAbilityContainer() + if not container then + return + end + local _, relFrame = container:GetPoint() if self.frame ~= relFrame then self.frame:RepositionExtraAbilityContainer() end @@ -199,10 +315,10 @@ end -- Titan panel will attempt to take control of the ExtraActionBarFrame and break -- its position and ability to be usable. This is because Titan Panel doesn't --- check to see if another addon has taken control of the bar +-- check to see if another addon has taken control of the bar. -- -- To resolve this, we call TitanMovable_AddonAdjust() for the extra ability bar --- frames to let titan panel know we are handling positions for the extra bar +-- frames to let Titan Panel know we are handling positions for the extra bar. function ExtraAbilityBarModule:ApplyTitanPanelWorkarounds() local adjust = _G.TitanMovable_AddonAdjust if not adjust then return end @@ -211,6 +327,6 @@ function ExtraAbilityBarModule:ApplyTitanPanelWorkarounds() adjust('ExtraAbilityContainer', true) end - adjust("ExtraActionBarFrame", true) + adjust('ExtraActionBarFrame', true) return true end diff --git a/Dominos/core/bindableButton.lua b/Dominos/core/bindableButton.lua index dc27483b..eab291b3 100644 --- a/Dominos/core/bindableButton.lua +++ b/Dominos/core/bindableButton.lua @@ -3,12 +3,23 @@ local AddonName, Addon = ... local KeyBound = LibStub('LibKeyBound-1.0') local COMMAND_TEMPLATE = 'CLICK %s:HOTKEY' +local function getBindingCompat() + return Addon.BindingCompat +end + -- binding method definitions -- returns the binding action associated with the button -- we use a virtual button (arbitrarily named HOTKEY) -- to enable cast on key press support local function getButtonBindingAction(button) + local bindingCompat = getBindingCompat() + if bindingCompat then + return bindingCompat.NormalizeCommandName(button:GetAttribute("commandName")) + or bindingCompat.GetActionButtonCommand(button:GetAttribute("bindingID"), button) + or bindingCompat.GetFallbackClickBinding(button, button:GetAttribute("bindingID")) + end + return button:GetAttribute("commandName") or COMMAND_TEMPLATE:format(button:GetName()) end @@ -20,6 +31,13 @@ local function getButtonBindingActionName(button) end local function getButtonBindings(button) + local bindingID = button:GetAttribute("bindingID") + local bindingCompat = getBindingCompat() + + if bindingID and bindingCompat and bindingCompat.GetActionButtonBindingKeys then + return unpack(bindingCompat.GetActionButtonBindingKeys(bindingID, button)) + end + return GetBindingKey(getButtonBindingAction(button)) end @@ -36,7 +54,12 @@ end -- returns a space separated list of all bindings for the given button local function getButtonBindingsList(button) - return strjoin(' ', getButtonBindings(button)) + local key = getButtonBindings(button) + if key then + return strjoin(' ', getButtonBindings(button)) + end + + return '' end -- set bindings @@ -45,13 +68,28 @@ local function setButtonBinding(button, key) end -- clears all bindings from the button -local function clearButtonBindings(button) - local key = (getButtonBindings(button)) +local function clearButtonBindingCommand(command) + local key = GetBindingKey(command) while key do SetBinding(key, nil) - key = (getButtonBindings(button)) + key = GetBindingKey(command) + end +end + +local function clearButtonBindings(button) + local bindingID = button:GetAttribute("bindingID") + local bindingCompat = getBindingCompat() + + if bindingID and bindingCompat and bindingCompat.GetActionButtonCommands then + local commands = bindingCompat.GetActionButtonCommands(bindingID, button) + for _, command in ipairs(commands) do + clearButtonBindingCommand(command) + end + return end + + clearButtonBindingCommand(getButtonBindingAction(button)) end -- used to implement keybinding support without applying all of the LibKeyBound @@ -108,6 +146,16 @@ function BindableButton:AddQuickBindingSupport(button) end function BindableButton:UpdateHotkeys() + local bindingAction = getButtonBindingAction(self) + + -- Blizzard's ActionBarActionButtonMixin may rebuild bindingAction from + -- GetID(), which Dominos intentionally keeps decoupled from secure paging. + -- Restore the stable binding contract after the native hotkey update path + -- runs so external binding-highlighting hooks see the same command Dominos + -- displays and binds. + self.commandName = bindingAction + self.bindingAction = bindingAction + local key = (self.GetHotkey or getButtonHotkey)(self) or '' local hotkey = self.HotKey diff --git a/Dominos/core/bindingCompat.lua b/Dominos/core/bindingCompat.lua new file mode 100644 index 00000000..f49b1895 --- /dev/null +++ b/Dominos/core/bindingCompat.lua @@ -0,0 +1,288 @@ +-- Centralized binding identity helpers for Dominos action buttons. +-- +-- Dominos buttons should expose Blizzard-native binding commands whenever a +-- stable Dominos button maps to a native Blizzard action button. Dominos CLICK +-- bindings remain available as fallback compatibility bindings for buttons that +-- do not have a Blizzard-native binding command. +local AddonName, Addon = ... + +local BindingCompat = {} +local CLICK_BINDING_TEMPLATE = "CLICK %s:HOTKEY" +local LEGACY_BUTTON_NAME_TEMPLATE = AddonName .. "ActionButton%d" + +local NATIVE_BINDING_RANGES = { + -- Main action bar. + {first = 1, last = 12, prefix = "ACTIONBUTTON", offset = 0}, + + -- Blizzard multi action bars. The Dominos stable button ids intentionally + -- match action slot layout, not paged runtime action attributes. + {first = 25, last = 36, prefix = "MULTIACTIONBAR3BUTTON", offset = 24}, + {first = 37, last = 48, prefix = "MULTIACTIONBAR4BUTTON", offset = 36}, + {first = 49, last = 60, prefix = "MULTIACTIONBAR2BUTTON", offset = 48}, + {first = 61, last = 72, prefix = "MULTIACTIONBAR1BUTTON", offset = 60}, + + -- Retail extra multi action bars. These are capability-checked before use + -- so TBC safely falls back to Dominos CLICK bindings. + {first = 133, last = 144, prefix = "MULTIACTIONBAR5BUTTON", offset = 132, retailOnly = true}, + {first = 145, last = 156, prefix = "MULTIACTIONBAR6BUTTON", offset = 144, retailOnly = true}, + {first = 157, last = 168, prefix = "MULTIACTIONBAR7BUTTON", offset = 156, retailOnly = true}, +} + +local function IsNonEmptyString(value) + return type(value) == "string" and value ~= "" +end + +local function GetBindingNameGlobal(command) + if IsNonEmptyString(command) then + return _G["BINDING_NAME_" .. command] + end +end + +local function IsNativeBindingCommandAvailable(command) + -- Binding name globals are the safest capability probe here: they indicate + -- that the client actually exposes the command through Blizzard's binding + -- system. GetBindingKey() alone cannot distinguish unbound commands from + -- commands that do not exist on a flavor. + return GetBindingNameGlobal(command) ~= nil +end + +local function GetRangeInfo(buttonID) + if type(buttonID) ~= "number" then + return nil + end + + for _, range in ipairs(NATIVE_BINDING_RANGES) do + if buttonID >= range.first and buttonID <= range.last then + return range + end + end +end + + +local function AddUniqueValue(values, seen, value) + if IsNonEmptyString(value) and not seen[value] then + values[#values + 1] = value + seen[value] = true + end +end + +local function AddBindingKeysForCommand(keys, seen, command) + if not IsNonEmptyString(command) then + return + end + + local firstKey, secondKey = GetBindingKey(command) + AddUniqueValue(keys, seen, firstKey) + AddUniqueValue(keys, seen, secondKey) +end + +local function GetButtonName(button) + if type(button) == "string" then + return button + end + + if type(button) == "table" and button.GetName then + return button:GetName() + end +end + +function BindingCompat.NormalizeCommandName(command) + if IsNonEmptyString(command) then + return command + end +end + +function BindingCompat.GetLegacyActionButtonName(buttonID) + if type(buttonID) == "number" and buttonID > 0 then + return LEGACY_BUTTON_NAME_TEMPLATE:format(buttonID) + end +end + +function BindingCompat.GetBlizzardActionButtonAliasName(buttonID) + if type(buttonID) == "number" and buttonID >= 1 and buttonID <= 12 then + return ("ActionButton%d"):format(buttonID) + end +end + +function BindingCompat.CreateLegacyActionButtonAlias(button, buttonID) + local legacyName = BindingCompat.GetLegacyActionButtonName(buttonID) + if not legacyName or not button then + return + end + + -- Keep the historical DominosActionButtonN global as an alias only when it + -- already resolves to this frame or has not been created yet. Do not alias + -- Blizzard-owned ActionButtonN globals to Dominos-created frames; those are + -- used by restricted Blizzard binding scripts and controller tables. + if _G[legacyName] == nil or _G[legacyName] == button then + _G[legacyName] = button + end +end + +function BindingCompat.GetClickBindingForButtonName(buttonName) + if IsNonEmptyString(buttonName) then + return CLICK_BINDING_TEMPLATE:format(buttonName) + end +end + +function BindingCompat.GetActualClickBinding(button) + local name = GetButtonName(button) + return BindingCompat.GetClickBindingForButtonName(name) +end + +function BindingCompat.GetBlizzardAliasClickBinding(buttonID) + return BindingCompat.GetClickBindingForButtonName(BindingCompat.GetBlizzardActionButtonAliasName(buttonID)) +end + +function BindingCompat.GetFallbackClickBinding(button, buttonID) + local legacyName = BindingCompat.GetLegacyActionButtonName(buttonID) + if legacyName then + return CLICK_BINDING_TEMPLATE:format(legacyName) + end + + return BindingCompat.GetActualClickBinding(button) +end + +function BindingCompat.GetNativeActionButtonCommand(buttonID) + local range = GetRangeInfo(buttonID) + if not range then + return nil + end + + local command = range.prefix .. (buttonID - range.offset) + if not range.retailOnly then + return command + end + + -- Retail-only bars must be capability checked because this file also loads + -- on TBC. Prefer the capability probe, with Addon:IsBuild as a fallback in + -- case a client delays binding-name globals. + if IsNativeBindingCommandAvailable(command) then + return command + end + + if Addon.IsBuild and Addon:IsBuild("retail") then + return command + end +end + +function BindingCompat.GetActionButtonCommand(buttonID, button) + return BindingCompat.GetNativeActionButtonCommand(buttonID) + or BindingCompat.GetFallbackClickBinding(button, buttonID) +end + + +function BindingCompat.GetActionButtonCommands(buttonID, button) + local commands = {} + local seen = {} + + AddUniqueValue(commands, seen, BindingCompat.GetNativeActionButtonCommand(buttonID)) + AddUniqueValue(commands, seen, BindingCompat.GetFallbackClickBinding(button, buttonID)) + AddUniqueValue(commands, seen, BindingCompat.GetActualClickBinding(button)) + + return commands +end + +function BindingCompat.GetActionButtonBindingKeys(buttonID, button) + local keys = {} + local seen = {} + local commands = BindingCompat.GetActionButtonCommands(buttonID, button) + + for _, command in ipairs(commands) do + AddBindingKeysForCommand(keys, seen, command) + end + + return keys +end + +function BindingCompat.GetFallbackActionButtonBindingKeys(buttonID, button) + local keys = {} + local seen = {} + + -- Fallback-only binding collection. The full binding collection above is used + -- for Dominos-owned override bindings so native keys can be captured without + -- executing Blizzard's restricted ACTIONBUTTON snippets against addon frames. + AddBindingKeysForCommand(keys, seen, BindingCompat.GetFallbackClickBinding(button, buttonID)) + AddBindingKeysForCommand(keys, seen, BindingCompat.GetActualClickBinding(button)) + + return keys +end + +function BindingCompat.UsesNativeBindingRouting(buttonID) + return BindingCompat.GetNativeActionButtonCommand(buttonID) ~= nil +end + +function BindingCompat.GetOverrideActionButtonCommand(index) + if type(index) == "number" and index > 0 then + return "ACTIONBUTTON" .. index + end +end + +function BindingCompat.GetActionButtonIndex(buttonID) + local range = GetRangeInfo(buttonID) + if range then + return buttonID - range.offset + end + + if type(buttonID) == "number" and buttonID > 0 then + return ((buttonID - 1) % NUM_ACTIONBAR_BUTTONS) + 1 + end +end + +function BindingCompat.GetActionButtonType(buttonID) + local command = BindingCompat.GetNativeActionButtonCommand(buttonID) + if not command then + return nil + end + + return command:match("^(.-)%d+$") +end + +function BindingCompat.ApplyActionButtonContract(button, buttonID) + if not button then + return + end + + local command = BindingCompat.GetActionButtonCommand(buttonID, button) + local nativeCommand = BindingCompat.GetNativeActionButtonCommand(buttonID) + local fallbackCommand = BindingCompat.GetFallbackClickBinding(button, buttonID) + local actualClickCommand = BindingCompat.GetActualClickBinding(button) + local blizzardAliasName = BindingCompat.GetBlizzardActionButtonAliasName(buttonID) + local blizzardAliasClickCommand = BindingCompat.GetBlizzardAliasClickBinding(buttonID) + local buttonType = BindingCompat.GetActionButtonType(buttonID) + local buttonIndex = BindingCompat.GetActionButtonIndex(buttonID) + + -- Mirror Blizzard's public action-button fields where practical. These are + -- intentionally stable button identity values, not the current paged action + -- slot held in the secure "action" attribute. + button.commandName = command + button.bindingAction = command + button.bindingID = buttonID + button.dominosButtonID = buttonID + button.dominosNativeCommandName = nativeCommand + button.dominosFallbackCommandName = fallbackCommand + button.dominosActualClickCommandName = actualClickCommand + button.dominosBlizzardAliasName = blizzardAliasName + button.dominosBlizzardAliasClickCommandName = blizzardAliasClickCommand + + if buttonType then + button.buttonType = buttonType + end + + if buttonIndex then + button.buttonIndex = buttonIndex + end + + button:SetAttributeNoHandler("commandName", command) + button:SetAttributeNoHandler("bindingID", buttonID) + button:SetAttributeNoHandler("nativeCommandName", nativeCommand) + button:SetAttributeNoHandler("fallbackCommandName", fallbackCommand) + button:SetAttributeNoHandler("actualClickCommandName", actualClickCommand) + button:SetAttributeNoHandler("blizzardAliasName", blizzardAliasName) + button:SetAttributeNoHandler("blizzardAliasClickCommandName", blizzardAliasClickCommand) + button:SetAttributeNoHandler("dominosButtonID", buttonID) + + BindingCompat.CreateLegacyActionButtonAlias(button, buttonID) +end + +Addon.BindingCompat = BindingCompat diff --git a/Dominos/core/blizzardHider.lua b/Dominos/core/blizzardHider.lua index 57c1f394..7d827667 100644 --- a/Dominos/core/blizzardHider.lua +++ b/Dominos/core/blizzardHider.lua @@ -1,5 +1,235 @@ local _, Addon = ... +local afterMidnight = Addon.IsAfterMidnight and Addon:IsAfterMidnight() +local detachedNativeActionButtons = setmetatable({}, { __mode = "k" }) + +local function noop() +end + +local nativeActionButtonPrefixes = { + "ActionButton", + "MultiBarBottomLeftButton", + "MultiBarBottomRightButton", + "MultiBarLeftButton", + "MultiBarRightButton", + "MultiBar5Button", + "MultiBar6Button", + "MultiBar7Button" +} + +local function disableNativeActionButtonDispatch(button) + if not afterMidnight or not button or button.dominosNativeDispatchDisabled then + return + end + + -- Hidden native action buttons must not keep executing Blizzard's shared + -- ActionButton_Update/UpdatePressAndHoldAction path once Dominos owns the + -- visible bar. Midnight can mark cooldown and action attributes as secret, + -- and those protected updates are only safe from Blizzard's untainted path. + button.dominosNativeOnEvent = button.OnEvent + button.dominosNativeOnUpdate = button.OnUpdate + button.dominosNativeUpdate = button.Update + button.dominosNativeUpdateAction = button.UpdateAction + button.dominosNativeUpdatePressAndHoldAction = button.UpdatePressAndHoldAction + button.dominosNativeCheckNeedsUpdate = button.CheckNeedsUpdate + button.dominosNativeActionButtonOnClick = button.ActionBarActionButtonDerivedMixin_OnClick + + button.OnEvent = noop + button.OnUpdate = noop + button.Update = noop + button.UpdateAction = noop + button.UpdatePressAndHoldAction = noop + button.CheckNeedsUpdate = noop + button.ActionBarActionButtonDerivedMixin_OnClick = noop + button.eventsRegistered = nil + button.needsUpdate = nil + button.dominosNativeDispatchDisabled = true +end + +local function removeFrameFromArray(frames, frame) + if type(frames) ~= "table" then + return + end + + for i = #frames, 1, -1 do + if frames[i] == frame then + table.remove(frames, i) + end + end +end + +local function unregisterFrame(owner, frame) + if not owner or not frame then + return + end + + if type(owner.UnregisterFrame) == "function" then + pcall(owner.UnregisterFrame, owner, frame) + elseif type(owner.frames) == "table" then + removeFrameFromArray(owner.frames, frame) + owner.frames[frame] = nil + end +end + +local function unregisterActionWatcher(owner, action, frame) + if not owner or not action or not frame or type(owner.UnregisterFrame) ~= "function" then + return + end + + pcall(owner.UnregisterFrame, owner, action, frame) +end + +local function getButtonAction(button) + if not button then + return nil + end + + if button.action then + return button.action + end + + if type(button.GetAttribute) == "function" then + return button:GetAttribute("action") + end +end + +local function suppressFrameInput(frame) + if not frame then + return + end + + -- Do not call Hide(), HideBase(), SetShown(), SetParent(), or protected + -- action-button attributes here on Midnight. Those paths can taint Blizzard's + -- EditMode action-bar visibility controller, which later causes blocked calls + -- such as MainActionBar:SetShownBase(). Alpha/mouse suppression keeps the + -- stock frames visually inert while Dominos owns the visible bars. + if type(frame.SetAlpha) == "function" then + frame:SetAlpha(0) + end + + if type(frame.EnableMouse) == "function" then + frame:EnableMouse(false) + end + + if type(frame.SetMouseClickEnabled) == "function" then + frame:SetMouseClickEnabled(false) + end + + if type(frame.SetMouseMotionEnabled) == "function" then + frame:SetMouseMotionEnabled(false) + end +end + +local function detachNativeActionButton(button) + if not button then + return + end + + local action = getButtonAction(button) + + -- Native action buttons are registered with shared Blizzard dispatcher frames. + -- On Midnight, touching these hidden stock buttons from Dominos can taint them; + -- if they remain registered, Blizzard's native OnEvent path later calls + -- protected SetAttribute/SetCooldown with secret values and the stack blames + -- Dominos. Detach the hidden stock buttons from the shared dispatchers and + -- let Dominos-created buttons own the visible/update path instead. + -- + -- This intentionally runs every time it is requested instead of only once: + -- Blizzard or another addon may re-register a hidden stock button after Dominos + -- has detached it, especially when native ActionButton attributes are changed. + unregisterFrame(ActionBarButtonEventsFrame, button) + unregisterFrame(ActionBarActionEventsFrame, button) + unregisterFrame(ActionBarButtonUpdateFrame, button) + unregisterActionWatcher(ActionBarButtonRangeCheckFrame, action, button) + unregisterActionWatcher(ActionBarButtonUsableWatcherFrame, action, button) + disableNativeActionButtonDispatch(button) + + if not detachedNativeActionButtons[button] then + suppressFrameInput(button) + detachedNativeActionButtons[button] = true + end +end + +local function hideNativeActionButton(button) + if not button then + return + end + + if afterMidnight then + detachNativeActionButton(button) + return + end + + button:UnregisterAllEvents() + button:SetAttributeNoHandler("statehidden", true) + button:Hide() +end + +local function detachNativeActionButtonGlobals() + if not afterMidnight then + return + end + + local maxButtons = NUM_ACTIONBAR_BUTTONS or 12 + for _, prefix in ipairs(nativeActionButtonPrefixes) do + for i = 1, maxButtons do + hideNativeActionButton(_G[prefix .. i]) + end + end +end + +local function detachOverrideActionBarButtons() + if not afterMidnight or not OverrideActionBar then + return + end + + -- The native override buttons are not stored in OverrideActionBar.actionButtons. + -- They are SpellButton1..N parent keys with global names + -- OverrideActionBarButton1..N, and they inherit ActionButtonTemplate. If they + -- remain registered with Blizzard's shared action dispatchers, hidden/tainted + -- native override buttons can still call ActionButton_UpdateCooldown() and + -- UpdatePressAndHoldAction() with secret values from a Dominos-tainted stack. + local maxButtons = NUM_OVERRIDE_BUTTONS or 6 + for i = 1, maxButtons do + local button = OverrideActionBar["SpellButton" .. i] or _G["OverrideActionBarButton" .. i] + hideNativeActionButton(button) + end + + if type(OverrideActionBar.UnregisterAllEvents) == "function" then + OverrideActionBar:UnregisterAllEvents() + end + + suppressFrameInput(OverrideActionBar) +end + +local function disableNativeActionBarController() + if not ActionBarController or type(ActionBarController.UnregisterAllEvents) ~= "function" then + return + end + + -- Dominos provides its own secure paging/override state controller. On + -- Midnight, allowing Blizzard's ActionBarController to continue driving the + -- hidden MainActionBar can re-enter protected EditMode visibility functions + -- from a tainted stack after Dominos suppresses the stock bars. Disabling + -- the controller event pump prevents hidden Blizzard bars from being shown, + -- hidden, or repaged behind Dominos. + ActionBarController:UnregisterAllEvents() +end + +local function suppressNativeActionBarFrame(frame) + if not frame then + return + end + + if afterMidnight then + suppressFrameInput(frame) + return + end + + (frame.HideBase or frame.Hide)(frame) + frame:SetParent(Addon.ShadowUIParent) +end + local framesToHide = { "MainActionBar", "MultiBar5", @@ -30,25 +260,38 @@ local wipeActionButtons = { MultiBarRight = true } +local controllerDisabler +if afterMidnight then + disableNativeActionBarController() + + -- Run once more after login/entering-world in case Blizzard has reloaded or + -- reinitialized the controller after this file was evaluated. + controllerDisabler = CreateFrame("Frame") + controllerDisabler:RegisterEvent("PLAYER_LOGIN") + controllerDisabler:RegisterEvent("PLAYER_ENTERING_WORLD") + controllerDisabler:SetScript("OnEvent", function(self) + disableNativeActionBarController() + detachNativeActionButtonGlobals() + detachOverrideActionBarButtons() + end) +end + for _, frameName in ipairs(framesToHide) do local frame = _G[frameName] if frame then - if not keepEvents[frameName] then + if (not afterMidnight) and (not keepEvents[frameName]) then frame:UnregisterAllEvents() end - (frame.HideBase or frame.Hide)(frame) - frame:SetParent(Addon.ShadowUIParent) + suppressNativeActionBarFrame(frame) if frame.actionButtons and type(frame.actionButtons) == "table" then for _, button in pairs(frame.actionButtons) do - button:UnregisterAllEvents() - button:SetAttributeNoHandler("statehidden", true) - button:Hide() + hideNativeActionButton(button) end - if wipeActionButtons[frameName] then + if (not afterMidnight) and wipeActionButtons[frameName] then table.wipe(frame.actionButtons) end end @@ -56,3 +299,12 @@ for _, frameName in ipairs(framesToHide) do Addon:Printf('Could not find frame %q', frameName) end end + +-- Some stock buttons can be rebuilt or re-registered outside frame.actionButtons. +-- Detach by the Blizzard global button names as well so hidden native buttons do +-- not keep receiving shared ActionButton events. +detachNativeActionButtonGlobals() + +-- OverrideActionBar uses SpellButton parent keys instead of actionButtons, so +-- handle it explicitly after Blizzard's regular action bars are suppressed. +detachOverrideActionBarButtons() diff --git a/Dominos/core/overrideController.lua b/Dominos/core/overrideController.lua index 7a0626b1..4863f725 100644 --- a/Dominos/core/overrideController.lua +++ b/Dominos/core/overrideController.lua @@ -3,21 +3,51 @@ if not Addon:IsBuild('retail', 'mists', 'cata', 'wrath') then return end +if not OverrideActionBar then + return +end + +local afterMidnight = Addon.IsAfterMidnight and Addon:IsAfterMidnight() + local OverrideController = CreateFrame('Frame', nil, OverrideActionBar, 'SecureHandlerAttributeTemplate, SecureHandlerShowHideTemplate') +local overrideDrivers = { + form = '[form]1;0', + overridebar = '[overridebar]1;0', + possessbar = '[possessbar]1;0', + sstemp = '[shapeshift]1;0', + vehicle = '[@vehicle,exists]1;0', + vehicleui = '[vehicleui]1;0', + petbattleui = '[petbattle]1;0', +} + function OverrideController:OnLoad() - self:SetAttributeNoHandler("_onattributechanged", [[ - if name == "overrideui" then + self:Execute([[ + myFrames = newtable() + ]]) + + self:SetAttributeNoHandler('_onattributechanged', [[ + if not myFrames then + myFrames = newtable() + end + + if name == 'overrideui' then for _, frame in pairs(myFrames) do - frame:SetAttribute("state-overrideui", value == 1) + if frame then + frame:SetAttribute('state-overrideui', value == 1) + end end - elseif name == "petbattleui" then + elseif name == 'petbattleui' then for _, frame in pairs(myFrames) do - frame:SetAttribute("state-petbattleui", value == 1) + if frame then + frame:SetAttribute('state-petbattleui', value == 1) + end end - elseif name == "overridepage" then + elseif name == 'overridepage' then for _, frame in pairs(myFrames) do - frame:SetAttribute("state-overridepage", value) + if frame then + frame:SetAttribute('state-overridepage', value) + end end else local page @@ -31,28 +61,23 @@ function OverrideController:OnLoad() page = 0 end - if self:GetAttribute("overridepage") ~= page then - self:SetAttribute("overridepage", page) + if self:GetAttribute('overridepage') ~= page then + self:SetAttribute('overridepage', page) end end ]]) - self:SetAttributeNoHandler("_onshow", [[ self:SetAttribute("overrideui", 1) ]]) - self:SetAttributeNoHandler("_onhide", [[ self:SetAttribute("overrideui", 0) ]]) - self:SetAttributeNoHandler('overrideui', OverrideActionBar:IsVisible()) - - -- init - self:Execute([[ myFrames = table.new() ]]) - - for attribute, driver in pairs { - form = '[form]1;0', - overridebar = '[overridebar]1;0', - possessbar = '[possessbar]1;0', - sstemp = '[shapeshift]1;0', - vehicle = '[@vehicle,exists]1;0', - vehicleui = '[vehicleui]1;0', - petbattleui = '[petbattle]1;0' - } do + if afterMidnight then + self:SetAttributeNoHandler('_onshow', [[ self:SetAttribute('overrideui', 0) ]]) + self:SetAttributeNoHandler('_onhide', [[ self:SetAttribute('overrideui', 0) ]]) + self:SetAttributeNoHandler('overrideui', 0) + else + self:SetAttributeNoHandler('_onshow', [[ self:SetAttribute('overrideui', 1) ]]) + self:SetAttributeNoHandler('_onhide', [[ self:SetAttribute('overrideui', 0) ]]) + self:SetAttributeNoHandler('overrideui', OverrideActionBar:IsVisible() and 1 or 0) + end + + for attribute, driver in pairs(overrideDrivers) do RegisterAttributeDriver(self, attribute, driver) end @@ -70,21 +95,51 @@ function OverrideController:USE_OVERRRIDE_UI_CHANGED(_, show) end function OverrideController:Add(frame) + if not frame then + return + end + self:SetFrameRef('add', frame) - self:Execute([[ table.insert(myFrames, self:GetFrameRef('add')) ]]) + self:Execute([[ + if not myFrames then + myFrames = newtable() + end + + local frame = self:GetFrameRef('add') + if frame then + local exists = false + for _, registeredFrame in pairs(myFrames) do + if registeredFrame == frame then + exists = true + break + end + end + + if not exists then + table.insert(myFrames, frame) + end + end + ]]) - -- initialize state frame:SetAttribute('state-overrideui', tonumber(self:GetAttribute('overrideui')) == 1) frame:SetAttribute('state-petbattleui', tonumber(self:GetAttribute('petbattleui')) == 1) frame:SetAttribute('state-overridepage', self:GetAttribute('overridepage') or 0) end function OverrideController:Remove(frame) - self:SetFrameRef('rem', frame) + if not frame then + return + end + self:SetFrameRef('rem', frame) self:Execute([[ + if not myFrames then + return + end + + local frameToRemove = self:GetFrameRef('rem') for i, frame in pairs(myFrames) do - if frame == self:GetFrameRef('rem') then + if frame == frameToRemove then table.remove(myFrames, i) break end @@ -92,26 +147,34 @@ function OverrideController:Remove(frame) ]]) end -local originalParent = nil +local originalParent function OverrideController:SetShowOverrideUI(show) + if afterMidnight then + -- Do not reparent or show the native OverrideActionBar on Midnight. + -- Its action buttons inherit Blizzard's ActionButtonTemplate and can + -- receive secret cooldown values through protected native dispatchers + -- after Dominos has touched the frame family. Dominos continues to use + -- secure override-page state on its own action buttons instead. + return + end + if show then - if originalParent ~= nil then + if originalParent then OverrideActionBar:SetParent(originalParent) originalParent = nil end - elseif originalParent == nil then + elseif not originalParent then originalParent = OverrideActionBar:GetParent() OverrideActionBar:SetParent(Addon.ShadowUIParent) end end --- returns true if the player is in a state where they should be using actions --- normally found on the override bar +-- Returns true if the player is in a state where they should use actions +-- normally found on the override bar. function OverrideController:OverrideBarActive() - return (self:GetAttribute("overridepage") or 0) > 10 + return (tonumber(self:GetAttribute('overridepage')) or 0) > 10 end OverrideController:OnLoad() --- exports Addon.OverrideController = OverrideController diff --git a/Dominos/libs/AceAddon-3.0/AceAddon-3.0.lua b/Dominos/libs/AceAddon-3.0/AceAddon-3.0.lua new file mode 100644 index 00000000..f392a216 --- /dev/null +++ b/Dominos/libs/AceAddon-3.0/AceAddon-3.0.lua @@ -0,0 +1,649 @@ +--- **AceAddon-3.0** provides a template for creating addon objects. +-- It'll provide you with a set of callback functions that allow you to simplify the loading +-- process of your addon.\\ +-- Callbacks provided are:\\ +-- * **OnInitialize**, which is called directly after the addon is fully loaded. +-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present. +-- * **OnDisable**, which is only called when your addon is manually being disabled. +-- @usage +-- -- A small (but complete) addon, that doesn't do anything, +-- -- but shows usage of the callbacks. +-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- +-- function MyAddon:OnInitialize() +-- -- do init tasks here, like loading the Saved Variables, +-- -- or setting up slash commands. +-- end +-- +-- function MyAddon:OnEnable() +-- -- Do more initialization here, that really enables the use of your addon. +-- -- Register Events, Hook functions, Create Frames, Get information from +-- -- the game that wasn't available in OnInitialize +-- end +-- +-- function MyAddon:OnDisable() +-- -- Unhook, Unregister Events, Hide frames that you created. +-- -- You would probably only use an OnDisable if you want to +-- -- build a "standby" mode, or be able to toggle modules on/off. +-- end +-- @class file +-- @name AceAddon-3.0.lua +-- @release $Id: AceAddon-3.0.lua 1284 2022-09-25 09:15:30Z nevcairiel $ + +local MAJOR, MINOR = "AceAddon-3.0", 13 +local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) + +if not AceAddon then return end -- No Upgrade needed. + +AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame +AceAddon.addons = AceAddon.addons or {} -- addons in general +AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon. +AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized +AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled +AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon + +-- Lua APIs +local tinsert, tconcat, tremove = table.insert, table.concat, table.remove +local fmt, tostring = string.format, tostring +local select, pairs, next, type, unpack = select, pairs, next, type, unpack +local loadstring, assert, error = loadstring, assert, error +local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget + +--[[ + xpcall safecall implementation +]] +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function safecall(func, ...) + -- we check to see if the func is passed is actually a function here and don't error when it isn't + -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not + -- present execution should continue without hinderance + if type(func) == "function" then + return xpcall(func, errorhandler, ...) + end +end + +-- local functions that will be implemented further down +local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype + +-- used in the addon metatable +local function addontostring( self ) return self.name end + +-- Check if the addon is queued for initialization +local function queuedForInitialization(addon) + for i = 1, #AceAddon.initializequeue do + if AceAddon.initializequeue[i] == addon then + return true + end + end + return false +end + +--- Create a new AceAddon-3.0 addon. +-- Any libraries you specified will be embeded, and the addon will be scheduled for +-- its OnInitialize and OnEnable callbacks. +-- The final addon object, with all libraries embeded, will be returned. +-- @paramsig [object ,]name[, lib, ...] +-- @param object Table to use as a base for the addon (optional) +-- @param name Name of the addon object to create +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a simple addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0") +-- +-- -- Create a Addon object based on the table of a frame +-- local MyFrame = CreateFrame("Frame") +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") +function AceAddon:NewAddon(objectorname, ...) + local object,name + local i=1 + if type(objectorname)=="table" then + object=objectorname + name=... + i=2 + else + name=objectorname + end + if type(name)~="string" then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) + end + if self.addons[name] then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2) + end + + object = object or {} + object.name = name + + local addonmeta = {} + local oldmeta = getmetatable(object) + if oldmeta then + for k, v in pairs(oldmeta) do addonmeta[k] = v end + end + addonmeta.__tostring = addontostring + + setmetatable( object, addonmeta ) + self.addons[name] = object + object.modules = {} + object.orderedModules = {} + object.defaultModuleLibraries = {} + Embed( object ) -- embed NewModule, GetModule methods + self:EmbedLibraries(object, select(i,...)) + + -- add to queue of addons to be initialized upon ADDON_LOADED + tinsert(self.initializequeue, object) + return object +end + + +--- Get the addon object by its name from the internal AceAddon registry. +-- Throws an error if the addon object cannot be found (except if silent is set). +-- @param name unique name of the addon object +-- @param silent if true, the addon is optional, silently return nil if its not found +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +function AceAddon:GetAddon(name, silent) + if not silent and not self.addons[name] then + error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2) + end + return self.addons[name] +end + +-- - Embed a list of libraries into the specified addon. +-- This function will try to embed all of the listed libraries into the addon +-- and error if a single one fails. +-- +-- **Note:** This function is for internal use by :NewAddon/:NewModule +-- @paramsig addon, [lib, ...] +-- @param addon addon object to embed the libs in +-- @param lib List of libraries to embed into the addon +function AceAddon:EmbedLibraries(addon, ...) + for i=1,select("#", ... ) do + local libname = select(i, ...) + self:EmbedLibrary(addon, libname, false, 4) + end +end + +-- - Embed a library into the addon object. +-- This function will check if the specified library is registered with LibStub +-- and if it has a :Embed function to call. It'll error if any of those conditions +-- fails. +-- +-- **Note:** This function is for internal use by :EmbedLibraries +-- @paramsig addon, libname[, silent[, offset]] +-- @param addon addon object to embed the library in +-- @param libname name of the library to embed +-- @param silent marks an embed to fail silently if the library doesn't exist (optional) +-- @param offset will push the error messages back to said offset, defaults to 2 (optional) +function AceAddon:EmbedLibrary(addon, libname, silent, offset) + local lib = LibStub:GetLibrary(libname, true) + if not lib and not silent then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2) + elseif lib and type(lib.Embed) == "function" then + lib:Embed(addon) + tinsert(self.embeds[addon], libname) + return true + elseif lib then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2) + end +end + +--- Return the specified module from an addon object. +-- Throws an error if the addon object cannot be found (except if silent is set) +-- @name //addon//:GetModule +-- @paramsig name[, silent] +-- @param name unique name of the module +-- @param silent if true, the module is optional, silently return nil if its not found (optional) +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- -- Get the Module +-- MyModule = MyAddon:GetModule("MyModule") +function GetModule(self, name, silent) + if not self.modules[name] and not silent then + error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2) + end + return self.modules[name] +end + +local function IsModuleTrue(self) return true end + +--- Create a new module for the addon. +-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\ +-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as +-- an addon object. +-- @name //addon//:NewModule +-- @paramsig name[, prototype|lib[, lib, ...]] +-- @param name unique name of the module +-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional) +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a module with some embeded libraries +-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0") +-- +-- -- Create a module with a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") +function NewModule(self, name, prototype, ...) + if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end + if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end + + if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end + + -- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. + -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is. + local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name)) + + module.IsModule = IsModuleTrue + module:SetEnabledState(self.defaultModuleState) + module.moduleName = name + + if type(prototype) == "string" then + AceAddon:EmbedLibraries(module, prototype, ...) + else + AceAddon:EmbedLibraries(module, ...) + end + AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) + + if not prototype or type(prototype) == "string" then + prototype = self.defaultModulePrototype or nil + end + + if type(prototype) == "table" then + local mt = getmetatable(module) + mt.__index = prototype + setmetatable(module, mt) -- More of a Base class type feel. + end + + safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. + self.modules[name] = module + tinsert(self.orderedModules, module) + + return module +end + +--- Returns the real name of the addon or module, without any prefix. +-- @name //addon//:GetName +-- @paramsig +-- @usage +-- print(MyAddon:GetName()) +-- -- prints "MyAddon" +function GetName(self) + return self.moduleName or self.name +end + +--- Enables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback +-- and enabling all modules of the addon (unless explicitly disabled).\\ +-- :Enable() also sets the internal `enableState` variable to true +-- @name //addon//:Enable +-- @paramsig +-- @usage +-- -- Enable MyModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +function Enable(self) + self:SetEnabledState(true) + + -- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still + -- it'll be enabled after the init process + if not queuedForInitialization(self) then + return AceAddon:EnableAddon(self) + end +end + +--- Disables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback +-- and disabling all modules of the addon.\\ +-- :Disable() also sets the internal `enableState` variable to false +-- @name //addon//:Disable +-- @paramsig +-- @usage +-- -- Disable MyAddon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:Disable() +function Disable(self) + self:SetEnabledState(false) + return AceAddon:DisableAddon(self) +end + +--- Enables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object. +-- @name //addon//:EnableModule +-- @paramsig name +-- @usage +-- -- Enable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +-- +-- -- Enable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:EnableModule("MyModule") +function EnableModule(self, name) + local module = self:GetModule( name ) + return module:Enable() +end + +--- Disables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object. +-- @name //addon//:DisableModule +-- @paramsig name +-- @usage +-- -- Disable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Disable() +-- +-- -- Disable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:DisableModule("MyModule") +function DisableModule(self, name) + local module = self:GetModule( name ) + return module:Disable() +end + +--- Set the default libraries to be mixed into all modules created by this object. +-- Note that you can only change the default module libraries before any module is created. +-- @name //addon//:SetDefaultModuleLibraries +-- @paramsig lib[, lib, ...] +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Configure default libraries for modules (all modules need AceEvent-3.0) +-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0") +-- -- Create a module +-- MyModule = MyAddon:NewModule("MyModule") +function SetDefaultModuleLibraries(self, ...) + if next(self.modules) then + error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleLibraries = {...} +end + +--- Set the default state in which new modules are being created. +-- Note that you can only change the default state before any module is created. +-- @name //addon//:SetDefaultModuleState +-- @paramsig state +-- @param state Default state for new modules, true for enabled, false for disabled +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Set the default state to "disabled" +-- MyAddon:SetDefaultModuleState(false) +-- -- Create a module and explicilty enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +function SetDefaultModuleState(self, state) + if next(self.modules) then + error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleState = state +end + +--- Set the default prototype to use for new modules on creation. +-- Note that you can only change the default prototype before any module is created. +-- @name //addon//:SetDefaultModulePrototype +-- @paramsig prototype +-- @param prototype Default prototype for the new modules (table) +-- @usage +-- -- Define a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- -- Set the default prototype +-- MyAddon:SetDefaultModulePrototype(prototype) +-- -- Create a module and explicitly Enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +-- -- should print "OnEnable called!" now +-- @see NewModule +function SetDefaultModulePrototype(self, prototype) + if next(self.modules) then + error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) + end + if type(prototype) ~= "table" then + error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2) + end + self.defaultModulePrototype = prototype +end + +--- Set the state of an addon or module +-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize. +-- @name //addon//:SetEnabledState +-- @paramsig state +-- @param state the state of an addon or module (enabled=true, disabled=false) +function SetEnabledState(self, state) + self.enabledState = state +end + + +--- Return an iterator of all modules associated to the addon. +-- @name //addon//:IterateModules +-- @paramsig +-- @usage +-- -- Enable all modules +-- for name, module in MyAddon:IterateModules() do +-- module:Enable() +-- end +local function IterateModules(self) return pairs(self.modules) end + +-- Returns an iterator of all embeds in the addon +-- @name //addon//:IterateEmbeds +-- @paramsig +local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end + +--- Query the enabledState of an addon. +-- @name //addon//:IsEnabled +-- @paramsig +-- @usage +-- if MyAddon:IsEnabled() then +-- MyAddon:Disable() +-- end +local function IsEnabled(self) return self.enabledState end +local mixins = { + NewModule = NewModule, + GetModule = GetModule, + Enable = Enable, + Disable = Disable, + EnableModule = EnableModule, + DisableModule = DisableModule, + IsEnabled = IsEnabled, + SetDefaultModuleLibraries = SetDefaultModuleLibraries, + SetDefaultModuleState = SetDefaultModuleState, + SetDefaultModulePrototype = SetDefaultModulePrototype, + SetEnabledState = SetEnabledState, + IterateModules = IterateModules, + IterateEmbeds = IterateEmbeds, + GetName = GetName, +} +local function IsModule(self) return false end +local pmixins = { + defaultModuleState = true, + enabledState = true, + IsModule = IsModule, +} +-- Embed( target ) +-- target (object) - target object to embed aceaddon in +-- +-- this is a local function specifically since it's meant to be only called internally +function Embed(target, skipPMixins) + for k, v in pairs(mixins) do + target[k] = v + end + if not skipPMixins then + for k, v in pairs(pmixins) do + target[k] = target[k] or v + end + end +end + + +-- - Initialize the addon after creation. +-- This function is only used internally during the ADDON_LOADED event +-- It will call the **OnInitialize** function on the addon object (if present), +-- and the **OnEmbedInitialize** function on all embeded libraries. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- @param addon addon object to intialize +function AceAddon:InitializeAddon(addon) + safecall(addon.OnInitialize, addon) + + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedInitialize, lib, addon) end + end + + -- we don't call InitializeAddon on modules specifically, this is handled + -- from the event handler and only done _once_ +end + +-- - Enable the addon after creation. +-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED, +-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons. +-- It will call the **OnEnable** function on the addon object (if present), +-- and the **OnEmbedEnable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Enable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:EnableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if self.statuses[addon.name] or not addon.enabledState then return false end + + -- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable. + self.statuses[addon.name] = true + + safecall(addon.OnEnable, addon) + + -- make sure we're still enabled before continueing + if self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedEnable, lib, addon) end + end + + -- enable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:EnableAddon(modules[i]) + end + end + return self.statuses[addon.name] -- return true if we're disabled +end + +-- - Disable the addon +-- Note: This function is only used internally. +-- It will call the **OnDisable** function on the addon object (if present), +-- and the **OnEmbedDisable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Disable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:DisableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if not self.statuses[addon.name] then return false end + + -- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable. + self.statuses[addon.name] = false + + safecall( addon.OnDisable, addon ) + + -- make sure we're still disabling... + if not self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedDisable, lib, addon) end + end + -- disable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:DisableAddon(modules[i]) + end + end + + return not self.statuses[addon.name] -- return true if we're disabled +end + +--- Get an iterator over all registered addons. +-- @usage +-- -- Print a list of all installed AceAddon's +-- for name, addon in AceAddon:IterateAddons() do +-- print("Addon: " .. name) +-- end +function AceAddon:IterateAddons() return pairs(self.addons) end + +--- Get an iterator over the internal status registry. +-- @usage +-- -- Print a list of all enabled addons +-- for name, status in AceAddon:IterateAddonStatus() do +-- if status then +-- print("EnabledAddon: " .. name) +-- end +-- end +function AceAddon:IterateAddonStatus() return pairs(self.statuses) end + +-- Following Iterators are deprecated, and their addon specific versions should be used +-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon) +function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end +function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end + +-- Blizzard AddOns which can load very early in the loading process and mess with Ace3 addon loading +local BlizzardEarlyLoadAddons = { + Blizzard_DebugTools = true, + Blizzard_TimeManager = true, + Blizzard_BattlefieldMap = true, + Blizzard_MapCanvas = true, + Blizzard_SharedMapDataProviders = true, + Blizzard_CombatLog = true, +} + +-- Event Handling +local function onEvent(this, event, arg1) + -- 2020-08-28 nevcairiel - ignore the load event of Blizzard addons which occur early in the loading process + if (event == "ADDON_LOADED" and (arg1 == nil or not BlizzardEarlyLoadAddons[arg1])) or event == "PLAYER_LOGIN" then + -- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration + while(#AceAddon.initializequeue > 0) do + local addon = tremove(AceAddon.initializequeue, 1) + -- this might be an issue with recursion - TODO: validate + if event == "ADDON_LOADED" then addon.baseName = arg1 end + AceAddon:InitializeAddon(addon) + tinsert(AceAddon.enablequeue, addon) + end + + if IsLoggedIn() then + while(#AceAddon.enablequeue > 0) do + local addon = tremove(AceAddon.enablequeue, 1) + AceAddon:EnableAddon(addon) + end + end + end +end + +AceAddon.frame:RegisterEvent("ADDON_LOADED") +AceAddon.frame:RegisterEvent("PLAYER_LOGIN") +AceAddon.frame:SetScript("OnEvent", onEvent) + +-- upgrade embeded +for name, addon in pairs(AceAddon.addons) do + Embed(addon, true) +end + +-- 2010-10-27 nevcairiel - add new "orderedModules" table +if oldminor and oldminor < 10 then + for name, addon in pairs(AceAddon.addons) do + addon.orderedModules = {} + for module_name, module in pairs(addon.modules) do + tinsert(addon.orderedModules, module) + end + end +end diff --git a/Dominos/libs/AceAddon-3.0/AceAddon-3.0.xml b/Dominos/libs/AceAddon-3.0/AceAddon-3.0.xml new file mode 100644 index 00000000..e6ad639f --- /dev/null +++ b/Dominos/libs/AceAddon-3.0/AceAddon-3.0.xml @@ -0,0 +1,4 @@ + +