From 386828005b02d16f24f5710e9aec9453aa3faae5 Mon Sep 17 00:00:00 2001 From: MidoriKami Date: Sun, 30 Nov 2025 12:37:51 -0800 Subject: [PATCH] Apply breaking changes --- .../Lifecycle/AddonArgTypes/AddonArgs.cs | 38 +++--- .../Lifecycle/AddonArgTypes/AddonDrawArgs.cs | 21 --- .../AddonArgTypes/AddonFinalizeArgs.cs | 21 --- .../AddonArgTypes/AddonGenericArgs.cs | 17 --- .../AddonArgTypes/AddonReceiveEventArgs.cs | 5 +- .../AddonArgTypes/AddonUpdateArgs.cs | 35 ----- Dalamud/Game/Addon/Lifecycle/AddonArgsType.cs | 25 +--- Dalamud/Game/Addon/Lifecycle/AddonEvent.cs | 3 - .../Game/Addon/Lifecycle/AddonLifecycle.cs | 6 +- .../AddonLifecycleAddressResolver.cs | 24 ---- .../Lifecycle/AddonLifecycleEventListener.cs | 9 +- .../Game/Addon/Lifecycle/AddonVirtualTable.cs | 129 +++++++++--------- .../Windows/Data/Widgets/HookWidget.cs | 36 ++--- .../Internal/Windows/TitleScreenMenuWindow.cs | 4 +- Directory.Build.props | 2 +- 15 files changed, 114 insertions(+), 261 deletions(-) delete mode 100644 Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonDrawArgs.cs delete mode 100644 Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonFinalizeArgs.cs delete mode 100644 Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonGenericArgs.cs delete mode 100644 Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonUpdateArgs.cs delete mode 100644 Dalamud/Game/Addon/Lifecycle/AddonLifecycleAddressResolver.cs diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonArgs.cs index 62ca47238..c4a7e8f53 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonArgs.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonArgs.cs @@ -5,19 +5,24 @@ namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; /// /// Base class for AddonLifecycle AddonArgTypes. /// -public abstract class AddonArgs +public class AddonArgs { /// /// Constant string representing the name of an addon that is invalid. /// public const string InvalidAddon = "NullAddon"; - private string? addonName; + /// + /// Initializes a new instance of the class. + /// + internal AddonArgs() + { + } /// /// Gets the name of the addon this args referrers to. /// - public string AddonName => this.GetAddonName(); + public string AddonName { get; private set; } = InvalidAddon; /// /// Gets the pointer to the addons AtkUnitBase. @@ -25,28 +30,17 @@ public abstract class AddonArgs public AtkUnitBasePtr Addon { get; - internal set; + internal set + { + field = value; + + if (!this.Addon.IsNull && !string.IsNullOrEmpty(value.Name)) + this.AddonName = value.Name; + } } /// /// Gets the type of these args. /// - public abstract AddonArgsType Type { get; } - - /// - /// Helper method for ensuring the name of the addon is valid. - /// - /// The name of the addon for this object. when invalid. - private string GetAddonName() - { - if (this.Addon.IsNull) - return InvalidAddon; - - var name = this.Addon.Name; - - if (string.IsNullOrEmpty(name)) - return InvalidAddon; - - return this.addonName ??= name; - } + public virtual AddonArgsType Type => AddonArgsType.Generic; } diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonDrawArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonDrawArgs.cs deleted file mode 100644 index a834d2983..000000000 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonDrawArgs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Dalamud.Utility; - -namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; - -/// -/// Addon argument data for Draw events. -/// -[Obsolete("Use AddonGenericArgs instead.")] -[Api15ToDo("Remove this")] -public class AddonDrawArgs : AddonArgs -{ - /// - /// Initializes a new instance of the class. - /// - internal AddonDrawArgs() - { - } - - /// - public override AddonArgsType Type => AddonArgsType.Draw; -} diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonFinalizeArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonFinalizeArgs.cs deleted file mode 100644 index 11d15a081..000000000 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonFinalizeArgs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Dalamud.Utility; - -namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; - -/// -/// Addon argument data for ReceiveEvent events. -/// -[Obsolete("Use AddonGenericArgs instead.")] -[Api15ToDo("Remove this")] -public class AddonFinalizeArgs : AddonArgs -{ - /// - /// Initializes a new instance of the class. - /// - internal AddonFinalizeArgs() - { - } - - /// - public override AddonArgsType Type => AddonArgsType.Finalize; -} diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonGenericArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonGenericArgs.cs deleted file mode 100644 index a20e9d23b..000000000 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonGenericArgs.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; - -/// -/// Addon argument data for Draw events. -/// -public class AddonGenericArgs : AddonArgs -{ - /// - /// Initializes a new instance of the class. - /// - internal AddonGenericArgs() - { - } - - /// - public override AddonArgsType Type => AddonArgsType.Generic; -} diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonReceiveEventArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonReceiveEventArgs.cs index bb8168075..785cd199f 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonReceiveEventArgs.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonReceiveEventArgs.cs @@ -1,5 +1,3 @@ -using Dalamud.Utility; - namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; /// @@ -35,6 +33,5 @@ public class AddonReceiveEventArgs : AddonArgs /// /// Gets or sets the pointer to an AtkEventData for this event message. /// - [Api14ToDo("Rename to AtkEventData")] - public nint Data { get; set; } + public nint AtkEventData { get; set; } } diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonUpdateArgs.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonUpdateArgs.cs deleted file mode 100644 index e6147d0eb..000000000 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgTypes/AddonUpdateArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Dalamud.Utility; - -namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes; - -/// -/// Addon argument data for Update events. -/// -[Obsolete("Use AddonGenericArgs instead.")] -[Api15ToDo("Remove this")] -public class AddonUpdateArgs : AddonArgs -{ - /// - /// Initializes a new instance of the class. - /// - internal AddonUpdateArgs() - { - } - - /// - public override AddonArgsType Type => AddonArgsType.Update; - - /// - /// Gets or sets the time since the last update. - /// - internal float TimeDeltaInternal { get; set; } - - /// - /// Gets the time since the last update. - /// - private float TimeDelta - { - get => this.TimeDeltaInternal; - init => this.TimeDeltaInternal = value; - } -} diff --git a/Dalamud/Game/Addon/Lifecycle/AddonArgsType.cs b/Dalamud/Game/Addon/Lifecycle/AddonArgsType.cs index de32bd254..9d7815cef 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonArgsType.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonArgsType.cs @@ -5,26 +5,16 @@ /// public enum AddonArgsType { + /// + /// Generic arg type that contains no meaningful data. + /// + Generic, + /// /// Contains argument data for Setup. /// Setup, - /// - /// Contains argument data for Update. - /// - Update, - - /// - /// Contains argument data for Draw. - /// - Draw, - - /// - /// Contains argument data for Finalize. - /// - Finalize, - /// /// Contains argument data for RequestedUpdate. /// @@ -39,9 +29,4 @@ public enum AddonArgsType /// Contains argument data for ReceiveEvent. /// ReceiveEvent, - - /// - /// Generic arg type that contains no meaningful data. - /// - Generic, } diff --git a/Dalamud/Game/Addon/Lifecycle/AddonEvent.cs b/Dalamud/Game/Addon/Lifecycle/AddonEvent.cs index 7738d6c6a..5ec57b5e3 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonEvent.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonEvent.cs @@ -29,7 +29,6 @@ public enum AddonEvent /// An event that is fired before an addon begins its update cycle via . This event /// is fired every frame that an addon is loaded, regardless of visibility. /// - /// PreUpdate, /// @@ -42,7 +41,6 @@ public enum AddonEvent /// An event that is fired before an addon begins drawing to screen via . Unlike /// , this event is only fired if an addon is visible or otherwise drawing to screen. /// - /// PreDraw, /// @@ -62,7 +60,6 @@ public enum AddonEvent ///
/// As this is part of the destruction process for an addon, this event does not have an associated Post event. /// - /// PreFinalize, /// diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs index 5d121bea4..ddcebe718 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs @@ -59,13 +59,15 @@ internal unsafe class AddonLifecycle : IInternalDisposableService { if (!this.EventListeners.ContainsKey(listener.EventType)) { - this.EventListeners.TryAdd(listener.EventType, []); + if (!this.EventListeners.TryAdd(listener.EventType, [])) + return; } // Note: string.Empty is a valid addon name, as that will trigger on any addon for this event type if (!this.EventListeners[listener.EventType].ContainsKey(listener.AddonName)) { - this.EventListeners[listener.EventType].TryAdd(listener.AddonName, []); + if (!this.EventListeners[listener.EventType].TryAdd(listener.AddonName, [])) + return; } this.EventListeners[listener.EventType][listener.AddonName].Add(listener); diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleAddressResolver.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycleAddressResolver.cs deleted file mode 100644 index 2fa3c5b91..000000000 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleAddressResolver.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Dalamud.Utility; - -namespace Dalamud.Game.Addon.Lifecycle; - -/// -/// AddonLifecycleService memory address resolver. -/// -[Api14ToDo("Remove this class entirely, its not used by AddonLifecycle anymore, also need to use something else for HookWidget")] -internal class AddonLifecycleAddressResolver : BaseAddressResolver -{ - /// - /// Gets the address of the addon finalize hook invoked by the AtkUnitManager. - /// - public nint AddonFinalize { get; private set; } - - /// - /// Scan for and setup any configured address pointers. - /// - /// The signature scanner to facilitate setup. - protected override void Setup64Bit(ISigScanner sig) - { - this.AddonFinalize = sig.ScanText("E8 ?? ?? ?? ?? 48 83 EF 01 75 D5"); - } -} diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs index 9d411cdbc..fc82e0582 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs @@ -25,17 +25,12 @@ internal class AddonLifecycleEventListener /// string.Empty if it wants to be called for any addon. /// public string AddonName { get; init; } - - /// - /// Gets or sets a value indicating whether this event has been unregistered. - /// - public bool Removed { get; set; } - + /// /// Gets the event type this listener is looking for. /// public AddonEvent EventType { get; init; } - + /// /// Gets the delegate this listener invokes. /// diff --git a/Dalamud/Game/Addon/Lifecycle/AddonVirtualTable.cs b/Dalamud/Game/Addon/Lifecycle/AddonVirtualTable.cs index 49ffdc7fb..1ce145946 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonVirtualTable.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonVirtualTable.cs @@ -26,14 +26,18 @@ internal unsafe class AddonVirtualTable : IDisposable private readonly AddonLifecycle lifecycleService; - private readonly AddonSetupArgs addonSetupArg = new(); - private readonly AddonFinalizeArgs addonFinalizeArg = new(); - private readonly AddonDrawArgs addonDrawArg = new(); - private readonly AddonUpdateArgs addonUpdateArg = new(); - private readonly AddonRefreshArgs addonRefreshArg = new(); - private readonly AddonRequestedUpdateArgs addonRequestedUpdateArg = new(); - private readonly AddonReceiveEventArgs addonReceiveEventArg = new(); - private readonly AddonGenericArgs addonGenericArg = new(); + // Each addon gets its own set of args that are used to mutate the original call when used in pre-calls + private readonly AddonSetupArgs setupArgs = new(); + private readonly AddonArgs finalizeArgs = new(); + private readonly AddonArgs drawArgs = new(); + private readonly AddonArgs updateArgs = new(); + private readonly AddonRefreshArgs refreshArgs = new(); + private readonly AddonRequestedUpdateArgs requestedUpdateArgs = new(); + private readonly AddonReceiveEventArgs receiveEventArgs = new(); + private readonly AddonArgs openArgs = new(); + private readonly AddonArgs closeArgs = new(); + private readonly AddonArgs showArgs = new(); + private readonly AddonArgs hideArgs = new(); private readonly AtkUnitBase* atkUnitBase; @@ -133,12 +137,13 @@ internal unsafe class AddonVirtualTable : IDisposable { this.LogEvent(EnableLogging); - this.addonSetupArg.Addon = addon; - this.addonSetupArg.AtkValueCount = valueCount; - this.addonSetupArg.AtkValues = (nint)values; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreSetup, this.addonSetupArg); - valueCount = this.addonSetupArg.AtkValueCount; - values = (AtkValue*)this.addonSetupArg.AtkValues; + this.setupArgs.Addon = addon; + this.setupArgs.AtkValueCount = valueCount; + this.setupArgs.AtkValues = (nint)values; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreSetup, this.setupArgs); + + valueCount = this.setupArgs.AtkValueCount; + values = (AtkValue*)this.setupArgs.AtkValues; try { @@ -149,15 +154,15 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonSetup. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostSetup, this.addonSetupArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostSetup, this.setupArgs); } private void OnAddonFinalize(AtkUnitBase* thisPtr) { this.LogEvent(EnableLogging); - this.addonFinalizeArg.Addon = thisPtr; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreFinalize, this.addonFinalizeArg); + this.finalizeArgs.Addon = thisPtr; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreFinalize, this.finalizeArgs); try { @@ -173,8 +178,8 @@ internal unsafe class AddonVirtualTable : IDisposable { this.LogEvent(EnableLogging); - this.addonDrawArg.Addon = addon; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreDraw, this.addonDrawArg); + this.drawArgs.Addon = addon; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreDraw, this.drawArgs); try { @@ -185,16 +190,15 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonDraw. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostDraw, this.addonDrawArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostDraw, this.drawArgs); } private void OnAddonUpdate(AtkUnitBase* addon, float delta) { this.LogEvent(EnableLogging); - this.addonUpdateArg.Addon = addon; - this.addonUpdateArg.TimeDeltaInternal = delta; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreUpdate, this.addonUpdateArg); + this.updateArgs.Addon = addon; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreUpdate, this.updateArgs); try { @@ -205,7 +209,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonUpdate. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostUpdate, this.addonUpdateArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostUpdate, this.updateArgs); } private bool OnAddonRefresh(AtkUnitBase* addon, uint valueCount, AtkValue* values) @@ -214,12 +218,13 @@ internal unsafe class AddonVirtualTable : IDisposable var result = false; - this.addonRefreshArg.Addon = addon; - this.addonRefreshArg.AtkValueCount = valueCount; - this.addonRefreshArg.AtkValues = (nint)values; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreRefresh, this.addonRefreshArg); - valueCount = this.addonRefreshArg.AtkValueCount; - values = (AtkValue*)this.addonRefreshArg.AtkValues; + this.refreshArgs.Addon = addon; + this.refreshArgs.AtkValueCount = valueCount; + this.refreshArgs.AtkValues = (nint)values; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreRefresh, this.refreshArgs); + + valueCount = this.refreshArgs.AtkValueCount; + values = (AtkValue*)this.refreshArgs.AtkValues; try { @@ -230,7 +235,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonRefresh. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostRefresh, this.addonRefreshArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostRefresh, this.refreshArgs); return result; } @@ -238,12 +243,13 @@ internal unsafe class AddonVirtualTable : IDisposable { this.LogEvent(EnableLogging); - this.addonRequestedUpdateArg.Addon = addon; - this.addonRequestedUpdateArg.NumberArrayData = (nint)numberArrayData; - this.addonRequestedUpdateArg.StringArrayData = (nint)stringArrayData; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreRequestedUpdate, this.addonRequestedUpdateArg); - numberArrayData = (NumberArrayData**)this.addonRequestedUpdateArg.NumberArrayData; - stringArrayData = (StringArrayData**)this.addonRequestedUpdateArg.StringArrayData; + this.requestedUpdateArgs.Addon = addon; + this.requestedUpdateArgs.NumberArrayData = (nint)numberArrayData; + this.requestedUpdateArgs.StringArrayData = (nint)stringArrayData; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreRequestedUpdate, this.requestedUpdateArgs); + + numberArrayData = (NumberArrayData**)this.requestedUpdateArgs.NumberArrayData; + stringArrayData = (StringArrayData**)this.requestedUpdateArgs.StringArrayData; try { @@ -254,23 +260,24 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonRequestedUpdate. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostRequestedUpdate, this.addonRequestedUpdateArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostRequestedUpdate, this.requestedUpdateArgs); } private void OnAddonReceiveEvent(AtkUnitBase* addon, AtkEventType eventType, int eventParam, AtkEvent* atkEvent, AtkEventData* atkEventData) { this.LogEvent(EnableLogging); - this.addonReceiveEventArg.Addon = (nint)addon; - this.addonReceiveEventArg.AtkEventType = (byte)eventType; - this.addonReceiveEventArg.EventParam = eventParam; - this.addonReceiveEventArg.AtkEvent = (IntPtr)atkEvent; - this.addonReceiveEventArg.Data = (nint)atkEventData; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreReceiveEvent, this.addonReceiveEventArg); - eventType = (AtkEventType)this.addonReceiveEventArg.AtkEventType; - eventParam = this.addonReceiveEventArg.EventParam; - atkEvent = (AtkEvent*)this.addonReceiveEventArg.AtkEvent; - atkEventData = (AtkEventData*)this.addonReceiveEventArg.Data; + this.receiveEventArgs.Addon = (nint)addon; + this.receiveEventArgs.AtkEventType = (byte)eventType; + this.receiveEventArgs.EventParam = eventParam; + this.receiveEventArgs.AtkEvent = (IntPtr)atkEvent; + this.receiveEventArgs.AtkEventData = (nint)atkEventData; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreReceiveEvent, this.receiveEventArgs); + + eventType = (AtkEventType)this.receiveEventArgs.AtkEventType; + eventParam = this.receiveEventArgs.EventParam; + atkEvent = (AtkEvent*)this.receiveEventArgs.AtkEvent; + atkEventData = (AtkEventData*)this.receiveEventArgs.AtkEventData; try { @@ -281,7 +288,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonReceiveEvent. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostReceiveEvent, this.addonReceiveEventArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostReceiveEvent, this.receiveEventArgs); } private bool OnAddonOpen(AtkUnitBase* thisPtr, uint depthLayer) @@ -290,8 +297,8 @@ internal unsafe class AddonVirtualTable : IDisposable var result = false; - this.addonGenericArg.Addon = thisPtr; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreOpen, this.addonGenericArg); + this.openArgs.Addon = thisPtr; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreOpen, this.openArgs); try { @@ -302,7 +309,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonOpen. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostOpen, this.addonGenericArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostOpen, this.openArgs); return result; } @@ -313,8 +320,8 @@ internal unsafe class AddonVirtualTable : IDisposable var result = false; - this.addonGenericArg.Addon = thisPtr; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreClose, this.addonGenericArg); + this.closeArgs.Addon = thisPtr; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreClose, this.closeArgs); try { @@ -325,7 +332,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonClose. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostClose, this.addonGenericArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostClose, this.closeArgs); return result; } @@ -334,8 +341,8 @@ internal unsafe class AddonVirtualTable : IDisposable { this.LogEvent(EnableLogging); - this.addonGenericArg.Addon = thisPtr; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreShow, this.addonGenericArg); + this.showArgs.Addon = thisPtr; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreShow, this.showArgs); try { @@ -346,15 +353,15 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonShow. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostShow, this.addonGenericArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostShow, this.showArgs); } private void OnAddonHide(AtkUnitBase* thisPtr, bool unkBool, bool callHideCallback, uint setShowHideFlags) { this.LogEvent(EnableLogging); - this.addonGenericArg.Addon = thisPtr; - this.lifecycleService.InvokeListenersSafely(AddonEvent.PreHide, this.addonGenericArg); + this.hideArgs.Addon = thisPtr; + this.lifecycleService.InvokeListenersSafely(AddonEvent.PreHide, this.hideArgs); try { @@ -365,7 +372,7 @@ internal unsafe class AddonVirtualTable : IDisposable Log.Error(e, "Caught exception when calling original AddonHide. This may be a bug in the game or another plugin hooking this method."); } - this.lifecycleService.InvokeListenersSafely(AddonEvent.PostHide, this.addonGenericArg); + this.lifecycleService.InvokeListenersSafely(AddonEvent.PostHide, this.hideArgs); } [Conditional("DEBUG")] diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/HookWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/HookWidget.cs index 3ad8f86c2..c5ae1d8f0 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/HookWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/HookWidget.cs @@ -5,9 +5,8 @@ using System.Threading.Tasks; using Dalamud.Bindings.ImGui; using Dalamud.Game; -using Dalamud.Game.Addon.Lifecycle; +using Dalamud.Game.ClientState; using Dalamud.Hooking; -using FFXIVClientStructs.FFXIV.Component.GUI; using Serilog; using Windows.Win32.Foundation; using Windows.Win32.UI.WindowsAndMessaging; @@ -17,7 +16,7 @@ namespace Dalamud.Interface.Internal.Windows.Data.Widgets; /// /// Widget for displaying hook information. /// -internal unsafe class HookWidget : IDataWindowWidget +internal class HookWidget : IDataWindowWidget { private readonly List hookStressTestList = []; @@ -32,9 +31,9 @@ internal unsafe class HookWidget : IDataWindowWidget private bool hookStressTestRunning = false; private MessageBoxWDelegate? messageBoxWOriginal; - private AddonFinalizeDelegate? addonFinalizeOriginal; + private HandleZoneInitPacketDelegate? zoneInitOriginal; - private AddonLifecycleAddressResolver? address; + private ClientStateAddressResolver? address; private delegate int MessageBoxWDelegate( IntPtr hWnd, @@ -42,12 +41,12 @@ internal unsafe class HookWidget : IDataWindowWidget [MarshalAs(UnmanagedType.LPWStr)] string caption, MESSAGEBOX_STYLE type); - private delegate void AddonFinalizeDelegate(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase); + private delegate void HandleZoneInitPacketDelegate(nint a1, uint localPlayerEntityId, nint packet, byte type); private enum StressTestHookTarget { MessageBoxW, - AddonFinalize, + ZoneInit, Random, } @@ -65,7 +64,7 @@ internal unsafe class HookWidget : IDataWindowWidget { this.Ready = true; - this.address = new AddonLifecycleAddressResolver(); + this.address = new ClientStateAddressResolver(); this.address.Setup(Service.Get()); } @@ -179,7 +178,7 @@ internal unsafe class HookWidget : IDataWindowWidget return target switch { StressTestHookTarget.MessageBoxW => "MessageBoxW (Hook)", - StressTestHookTarget.AddonFinalize => "AddonFinalize (Hook)", + StressTestHookTarget.ZoneInit => "ZoneInit (Hook)", _ => target.ToString(), }; } @@ -198,15 +197,10 @@ internal unsafe class HookWidget : IDataWindowWidget return result; } - private void OnAddonFinalize(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase) + private void OnZoneInit(IntPtr a1, uint localPlayerEntityId, IntPtr packet, byte type) { - Log.Information("OnAddonFinalize"); - this.addonFinalizeOriginal!(unitManager, atkUnitBase); - } - - private void OnAddonUpdate(AtkUnitBase* thisPtr, float delta) - { - Log.Information("OnAddonUpdate"); + Log.Information("OnZoneInit"); + this.zoneInitOriginal!.Invoke(a1, localPlayerEntityId, packet, type); } private IDalamudHook HookMessageBoxW() @@ -222,11 +216,11 @@ internal unsafe class HookWidget : IDataWindowWidget return hook; } - private IDalamudHook HookAddonFinalize() + private IDalamudHook HookZoneInit() { - var hook = Hook.FromAddress(this.address!.AddonFinalize, this.OnAddonFinalize); + var hook = Hook.FromAddress(this.address!.HandleZoneInitPacket, this.OnZoneInit); - this.addonFinalizeOriginal = hook.Original; + this.zoneInitOriginal = hook.Original; hook.Enable(); return hook; } @@ -241,7 +235,7 @@ internal unsafe class HookWidget : IDataWindowWidget return target switch { StressTestHookTarget.MessageBoxW => this.HookMessageBoxW(), - StressTestHookTarget.AddonFinalize => this.HookAddonFinalize(), + StressTestHookTarget.ZoneInit => this.HookZoneInit(), _ => throw new ArgumentOutOfRangeException(nameof(target), target, null), }; } diff --git a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs index e3eb22a04..62f83f82f 100644 --- a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs +++ b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs @@ -471,9 +471,9 @@ internal class TitleScreenMenuWindow : Window, IDisposable private unsafe void OnVersionStringDraw(AddonEvent ev, AddonArgs args) { - if (args is not AddonDrawArgs drawArgs) return; + if (ev is not (AddonEvent.PostDraw or AddonEvent.PreDraw)) return; - var addon = drawArgs.Addon.Struct; + var addon = args.Addon.Struct; var textNode = addon->GetTextNodeById(3); // look and feel init. should be harmless to set. diff --git a/Directory.Build.props b/Directory.Build.props index eabb727e8..3897256bf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ net10.0-windows x64 x64 - 13.0 + 14.0