From 0636a03e41bab46300544bfc00f6643648db1ef8 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Thu, 21 Sep 2023 15:26:08 -0700
Subject: [PATCH 1/4] Include argument data in event information.
---
.../AddonEventManager/AddonEventManager.cs | 2 +-
.../AddonArgTypes/AddonDrawArgs.cs | 13 ++++++
.../AddonArgTypes/AddonFinalizeArgs.cs | 13 ++++++
.../AddonArgTypes/AddonRefreshArgs.cs | 23 ++++++++++
.../AddonArgTypes/AddonRequestedUpdateArgs.cs | 23 ++++++++++
.../AddonArgTypes/AddonSetupArgs.cs | 13 ++++++
.../AddonArgTypes/AddonUpdateArgs.cs | 18 ++++++++
Dalamud/Game/AddonLifecycle/AddonArgs.cs | 22 ---------
Dalamud/Game/AddonLifecycle/AddonArgsType.cs | 37 +++++++++++++++
Dalamud/Game/AddonLifecycle/AddonLifecycle.cs | 45 ++++++++++++++-----
Dalamud/Game/AddonLifecycle/IAddonArgs.cs | 25 +++++++++++
Dalamud/Game/Gui/Dtr/DtrBar.cs | 4 +-
.../AgingSteps/AddonLifecycleAgingStep.cs | 12 ++---
Dalamud/Plugin/Services/IAddonLifecycle.cs | 4 +-
14 files changed, 209 insertions(+), 45 deletions(-)
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
delete mode 100644 Dalamud/Game/AddonLifecycle/AddonArgs.cs
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgsType.cs
create mode 100644 Dalamud/Game/AddonLifecycle/IAddonArgs.cs
diff --git a/Dalamud/Game/AddonEventManager/AddonEventManager.cs b/Dalamud/Game/AddonEventManager/AddonEventManager.cs
index 89554074a..730a7a404 100644
--- a/Dalamud/Game/AddonEventManager/AddonEventManager.cs
+++ b/Dalamud/Game/AddonEventManager/AddonEventManager.cs
@@ -160,7 +160,7 @@ private void ContinueConstruction()
///
/// Event type that triggered this call.
/// Addon that triggered this call.
- private void OnAddonFinalize(AddonEvent eventType, AddonArgs addonInfo)
+ private void OnAddonFinalize(AddonEvent eventType, IAddonArgs addonInfo)
{
// It shouldn't be possible for this event to be anything other than PreFinalize.
if (eventType != AddonEvent.PreFinalize) return;
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
new file mode 100644
index 000000000..614a7ac2a
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
@@ -0,0 +1,13 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Finalize events.
+///
+public class AddonDrawArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.Draw;
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
new file mode 100644
index 000000000..aa31fb051
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
@@ -0,0 +1,13 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Finalize events.
+///
+public class AddonFinalizeArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.Finalize;
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
new file mode 100644
index 000000000..ab4f37c3c
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
@@ -0,0 +1,23 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Finalize events.
+///
+public class AddonRefreshArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.Refresh;
+
+ ///
+ /// Gets the number of AtkValues.
+ ///
+ public uint AtkValueCount { get; init; }
+
+ ///
+ /// Gets the address of the AtkValue array.
+ ///
+ public nint AtkValues { get; init; }
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
new file mode 100644
index 000000000..dfd0dac5e
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
@@ -0,0 +1,23 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Finalize events.
+///
+public class AddonRequestedUpdateArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.RequestedUpdate;
+
+ ///
+ /// Gets the NumberArrayData** for this event.
+ ///
+ public nint NumberArrayData { get; init; }
+
+ ///
+ /// Gets the StringArrayData** for this event.
+ ///
+ public nint StringArrayData { get; init; }
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
new file mode 100644
index 000000000..a73d11ae2
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
@@ -0,0 +1,13 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Setup events.
+///
+public class AddonSetupArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.Setup;
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
new file mode 100644
index 000000000..ede588001
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
@@ -0,0 +1,18 @@
+namespace Dalamud.Game.Addon.AddonArgTypes;
+
+///
+/// Addon argument data for Finalize events.
+///
+public class AddonUpdateArgs : IAddonArgs
+{
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ public AddonArgsType Type => AddonArgsType.Update;
+
+ ///
+ /// Gets the time since the last update.
+ ///
+ public float TimeDelta { get; init; }
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgs.cs
deleted file mode 100644
index 4ae306817..000000000
--- a/Dalamud/Game/AddonLifecycle/AddonArgs.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Dalamud.Memory;
-using FFXIVClientStructs.FFXIV.Component.GUI;
-
-namespace Dalamud.Game.Addon;
-
-///
-/// Addon argument data for use in event subscribers.
-///
-public unsafe class AddonArgs
-{
- private string? addonName;
-
- ///
- /// Gets the name of the addon this args referrers to.
- ///
- public string AddonName => this.Addon == nint.Zero ? "NullAddon" : this.addonName ??= MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
-
- ///
- /// Gets the pointer to the addons AtkUnitBase.
- ///
- required public nint Addon { get; init; }
-}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgsType.cs b/Dalamud/Game/AddonLifecycle/AddonArgsType.cs
new file mode 100644
index 000000000..ac325229d
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgsType.cs
@@ -0,0 +1,37 @@
+namespace Dalamud.Game.Addon;
+
+///
+/// Enumeration for available AddonLifecycle arg data
+///
+public enum AddonArgsType
+{
+ ///
+ /// 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.
+ ///
+ RequestedUpdate,
+
+ ///
+ /// Contains argument data for Refresh.
+ ///
+ Refresh,
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
index 68233eeb8..7f4a4de95 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
+using Dalamud.Game.Addon.AddonArgTypes;
using Dalamud.Hooking;
using Dalamud.Hooking.Internal;
using Dalamud.IoC;
@@ -127,7 +128,7 @@ private void ContinueConstruction()
this.onAddonRequestedUpdateHook.Enable();
}
- private void InvokeListeners(AddonEvent eventType, AddonArgs args)
+ private void InvokeListeners(AddonEvent eventType, IAddonArgs args)
{
// Match on string.empty for listeners that want events for all addons.
foreach (var listener in this.eventListeners.Where(listener => listener.EventType == eventType && (listener.AddonName == args.AddonName || listener.AddonName == string.Empty)))
@@ -140,7 +141,7 @@ private nint OnAddonSetup(AtkUnitBase* addon)
{
try
{
- this.InvokeListeners(AddonEvent.PreSetup, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs { Addon = (nint)addon });
}
catch (Exception e)
{
@@ -151,7 +152,7 @@ private nint OnAddonSetup(AtkUnitBase* addon)
try
{
- this.InvokeListeners(AddonEvent.PostSetup, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs { Addon = (nint)addon });
}
catch (Exception e)
{
@@ -165,7 +166,7 @@ private void OnAddonFinalize(AtkUnitManager* unitManager, AtkUnitBase** atkUnitB
{
try
{
- this.InvokeListeners(AddonEvent.PreFinalize, new AddonArgs { Addon = (nint)atkUnitBase[0] });
+ this.InvokeListeners(AddonEvent.PreFinalize, new AddonFinalizeArgs { Addon = (nint)atkUnitBase[0] });
}
catch (Exception e)
{
@@ -179,7 +180,7 @@ private void OnAddonDraw(AtkUnitBase* addon)
{
try
{
- this.InvokeListeners(AddonEvent.PreDraw, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreDraw, new AddonDrawArgs { Addon = (nint)addon });
}
catch (Exception e)
{
@@ -190,7 +191,7 @@ private void OnAddonDraw(AtkUnitBase* addon)
try
{
- this.InvokeListeners(AddonEvent.PostDraw, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostDraw, new AddonDrawArgs { Addon = (nint)addon });
}
catch (Exception e)
{
@@ -202,7 +203,7 @@ private void OnAddonUpdate(AtkUnitBase* addon, float delta)
{
try
{
- this.InvokeListeners(AddonEvent.PreUpdate, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreUpdate, new AddonUpdateArgs { Addon = (nint)addon, TimeDelta = delta });
}
catch (Exception e)
{
@@ -213,7 +214,7 @@ private void OnAddonUpdate(AtkUnitBase* addon, float delta)
try
{
- this.InvokeListeners(AddonEvent.PostUpdate, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostUpdate, new AddonUpdateArgs { Addon = (nint)addon, TimeDelta = delta });
}
catch (Exception e)
{
@@ -225,7 +226,12 @@ private byte OnAddonRefresh(AtkUnitManager* atkUnitManager, AtkUnitBase* addon,
{
try
{
- this.InvokeListeners(AddonEvent.PreRefresh, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreRefresh, new AddonRefreshArgs
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
@@ -236,7 +242,12 @@ private byte OnAddonRefresh(AtkUnitManager* atkUnitManager, AtkUnitBase* addon,
try
{
- this.InvokeListeners(AddonEvent.PostRefresh, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostRefresh, new AddonRefreshArgs
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
@@ -250,7 +261,12 @@ private void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArray
{
try
{
- this.InvokeListeners(AddonEvent.PreRequestedUpdate, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreRequestedUpdate, new AddonRequestedUpdateArgs
+ {
+ Addon = (nint)addon,
+ NumberArrayData = (nint)numberArrayData,
+ StringArrayData = (nint)stringArrayData,
+ });
}
catch (Exception e)
{
@@ -261,7 +277,12 @@ private void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArray
try
{
- this.InvokeListeners(AddonEvent.PostRequestedUpdate, new AddonArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostRequestedUpdate, new AddonRequestedUpdateArgs
+ {
+ Addon = (nint)addon,
+ NumberArrayData = (nint)numberArrayData,
+ StringArrayData = (nint)stringArrayData,
+ });
}
catch (Exception e)
{
diff --git a/Dalamud/Game/AddonLifecycle/IAddonArgs.cs b/Dalamud/Game/AddonLifecycle/IAddonArgs.cs
new file mode 100644
index 000000000..ba77a2c6d
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/IAddonArgs.cs
@@ -0,0 +1,25 @@
+using Dalamud.Memory;
+using FFXIVClientStructs.FFXIV.Component.GUI;
+
+namespace Dalamud.Game.Addon;
+
+///
+/// Interface representing the argument data for AddonLifecycle events.
+///
+public unsafe interface IAddonArgs
+{
+ ///
+ /// Gets the name of the addon this args referrers to.
+ ///
+ string AddonName => this.Addon == nint.Zero ? "NullAddon" : MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
+
+ ///
+ /// Gets the pointer to the addons AtkUnitBase.
+ ///
+ nint Addon { get; init; }
+
+ ///
+ /// Gets the type of these args.
+ ///
+ AddonArgsType Type { get; }
+}
diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs
index 880bc0625..6b74e47cd 100644
--- a/Dalamud/Game/Gui/Dtr/DtrBar.cs
+++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs
@@ -255,7 +255,7 @@ private void HandleAddedNodes()
}
}
- private void OnDtrPostDraw(AddonEvent eventType, AddonArgs addonInfo)
+ private void OnDtrPostDraw(AddonEvent eventType, IAddonArgs addonInfo)
{
var addon = (AtkUnitBase*)addonInfo.Addon;
@@ -300,7 +300,7 @@ private void UpdateNodePositions(AtkUnitBase* addon)
}
}
- private void OnAddonRequestedUpdateDetour(AddonEvent eventType, AddonArgs addonInfo)
+ private void OnAddonRequestedUpdateDetour(AddonEvent eventType, IAddonArgs addonInfo)
{
var addon = (AtkUnitBase*)addonInfo.Addon;
diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
index a9948430f..0821e62de 100644
--- a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
+++ b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
@@ -100,32 +100,32 @@ public void CleanUp()
}
}
- private void PostSetup(AddonEvent eventType, AddonArgs addonInfo)
+ private void PostSetup(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterSetup) this.currentStep++;
}
- private void PostUpdate(AddonEvent eventType, AddonArgs addonInfo)
+ private void PostUpdate(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterUpdate) this.currentStep++;
}
- private void PostDraw(AddonEvent eventType, AddonArgs addonInfo)
+ private void PostDraw(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterDraw) this.currentStep++;
}
- private void PostRefresh(AddonEvent eventType, AddonArgs addonInfo)
+ private void PostRefresh(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRefresh) this.currentStep++;
}
- private void PostRequestedUpdate(AddonEvent eventType, AddonArgs addonInfo)
+ private void PostRequestedUpdate(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRequestedUpdate) this.currentStep++;
}
- private void PreFinalize(AddonEvent eventType, AddonArgs addonInfo)
+ private void PreFinalize(AddonEvent eventType, IAddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterFinalize) this.currentStep++;
}
diff --git a/Dalamud/Plugin/Services/IAddonLifecycle.cs b/Dalamud/Plugin/Services/IAddonLifecycle.cs
index e455754a1..5290395ab 100644
--- a/Dalamud/Plugin/Services/IAddonLifecycle.cs
+++ b/Dalamud/Plugin/Services/IAddonLifecycle.cs
@@ -14,8 +14,8 @@ public interface IAddonLifecycle
/// Delegate for receiving addon lifecycle event messages.
///
/// The event type that triggered the message.
- /// Information about what addon triggered the message.
- public delegate void AddonEventDelegate(AddonEvent eventType, AddonArgs addonInfo);
+ /// Information about what addon triggered the message.
+ public delegate void AddonEventDelegate(AddonEvent eventType, IAddonArgs args);
///
/// Register a listener that will trigger on the specified event and any of the specified addons.
From bd81d230972402d992ced89888aaa5d959ebf700 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Thu, 21 Sep 2023 17:05:27 -0700
Subject: [PATCH 2/4] Use CallHook for AddonSetup
---
.../AddonArgTypes/AddonSetupArgs.cs | 10 +++++++
Dalamud/Game/AddonLifecycle/AddonLifecycle.cs | 26 ++++++++++++-------
.../AddonLifecycleAddressResolver.cs | 2 +-
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
index a73d11ae2..4b467deb8 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
@@ -10,4 +10,14 @@ public class AddonSetupArgs : IAddonArgs
///
public AddonArgsType Type => AddonArgsType.Setup;
+
+ ///
+ /// Gets the number of AtkValues.
+ ///
+ public uint AtkValueCount { get; init; }
+
+ ///
+ /// Gets the address of the AtkValue array.
+ ///
+ public nint AtkValues { get; init; }
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
index 7f4a4de95..75b5b3753 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
@@ -27,7 +27,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
private readonly Framework framework = Service.Get();
private readonly AddonLifecycleAddressResolver address;
- private readonly Hook onAddonSetupHook;
+ private readonly CallHook onAddonSetupHook;
private readonly Hook onAddonFinalizeHook;
private readonly CallHook onAddonDrawHook;
private readonly CallHook onAddonUpdateHook;
@@ -46,7 +46,7 @@ private AddonLifecycle(SigScanner sigScanner)
this.framework.Update += this.OnFrameworkUpdate;
- this.onAddonSetupHook = Hook.FromAddress(this.address.AddonSetup, this.OnAddonSetup);
+ this.onAddonSetupHook = new CallHook(this.address.AddonSetup, this.OnAddonSetup);
this.onAddonFinalizeHook = Hook.FromAddress(this.address.AddonFinalize, this.OnAddonFinalize);
this.onAddonDrawHook = new CallHook(this.address.AddonDraw, this.OnAddonDraw);
this.onAddonUpdateHook = new CallHook(this.address.AddonUpdate, this.OnAddonUpdate);
@@ -54,7 +54,7 @@ private AddonLifecycle(SigScanner sigScanner)
this.onAddonRequestedUpdateHook = new CallHook(this.address.AddonOnRequestedUpdate, this.OnRequestedUpdate);
}
- private delegate nint AddonSetupDelegate(AtkUnitBase* addon);
+ private delegate void AddonSetupDelegate(AtkUnitBase* addon, uint valueCount, AtkValue* values);
private delegate void AddonFinalizeDelegate(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase);
@@ -137,29 +137,37 @@ private void InvokeListeners(AddonEvent eventType, IAddonArgs args)
}
}
- private nint OnAddonSetup(AtkUnitBase* addon)
+ private void OnAddonSetup(AtkUnitBase* addon, uint valueCount, AtkValue* values)
{
try
{
- this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs()
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
Log.Error(e, "Exception in OnAddonSetup pre-setup invoke.");
}
- var result = this.onAddonSetupHook.Original(addon);
+ addon->OnSetup(valueCount, values);
try
{
- this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs()
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
Log.Error(e, "Exception in OnAddonSetup post-setup invoke.");
}
-
- return result;
}
private void OnAddonFinalize(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase)
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
index d68fee9ed..16fd54832 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
@@ -41,7 +41,7 @@ internal class AddonLifecycleAddressResolver : BaseAddressResolver
/// The signature scanner to facilitate setup.
protected override void Setup64Bit(SigScanner sig)
{
- this.AddonSetup = sig.ScanText("E8 ?? ?? ?? ?? 8B 83 ?? ?? ?? ?? C1 E8 14");
+ this.AddonSetup = sig.ScanText("FF 90 ?? ?? ?? ?? 48 8B 93 ?? ?? ?? ?? 80 8B");
this.AddonFinalize = sig.ScanText("E8 ?? ?? ?? ?? 48 8B 7C 24 ?? 41 8B C6");
this.AddonDraw = sig.ScanText("FF 90 ?? ?? ?? ?? 83 EB 01 79 C1");
this.AddonUpdate = sig.ScanText("FF 90 ?? ?? ?? ?? 40 88 AF");
From fd3bd6dc5b9c9db01360016e0b553b50505cb176 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Fri, 22 Sep 2023 12:17:54 -0700
Subject: [PATCH 3/4] Use abstract class instead of interface
---
.../AddonEventManager/AddonEventManager.cs | 2 +-
.../AddonLifecycle/AddonArgTypes/AddonArgs.cs | 46 +++++++++++++++++++
.../AddonArgTypes/AddonDrawArgs.cs | 9 ++--
.../AddonArgTypes/AddonFinalizeArgs.cs | 9 ++--
.../AddonArgTypes/AddonRefreshArgs.cs | 17 ++++---
.../AddonArgTypes/AddonRequestedUpdateArgs.cs | 9 ++--
.../AddonArgTypes/AddonSetupArgs.cs | 18 +++++---
.../AddonArgTypes/AddonUpdateArgs.cs | 9 ++--
Dalamud/Game/AddonLifecycle/AddonArgsType.cs | 2 +-
Dalamud/Game/AddonLifecycle/AddonLifecycle.cs | 7 ++-
Dalamud/Game/AddonLifecycle/IAddonArgs.cs | 25 ----------
Dalamud/Game/Gui/Dtr/DtrBar.cs | 4 +-
.../AgingSteps/AddonLifecycleAgingStep.cs | 12 ++---
Dalamud/Plugin/Services/IAddonLifecycle.cs | 2 +-
14 files changed, 95 insertions(+), 76 deletions(-)
create mode 100644 Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs
delete mode 100644 Dalamud/Game/AddonLifecycle/IAddonArgs.cs
diff --git a/Dalamud/Game/AddonEventManager/AddonEventManager.cs b/Dalamud/Game/AddonEventManager/AddonEventManager.cs
index 730a7a404..89554074a 100644
--- a/Dalamud/Game/AddonEventManager/AddonEventManager.cs
+++ b/Dalamud/Game/AddonEventManager/AddonEventManager.cs
@@ -160,7 +160,7 @@ private void ContinueConstruction()
///
/// Event type that triggered this call.
/// Addon that triggered this call.
- private void OnAddonFinalize(AddonEvent eventType, IAddonArgs addonInfo)
+ private void OnAddonFinalize(AddonEvent eventType, AddonArgs addonInfo)
{
// It shouldn't be possible for this event to be anything other than PreFinalize.
if (eventType != AddonEvent.PreFinalize) return;
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs
new file mode 100644
index 000000000..949d3fde9
--- /dev/null
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs
@@ -0,0 +1,46 @@
+using Dalamud.Memory;
+using FFXIVClientStructs.FFXIV.Component.GUI;
+
+namespace Dalamud.Game.Addon;
+
+///
+/// Base class for AddonLifecycle AddonArgTypes.
+///
+public abstract unsafe class AddonArgs
+{
+ ///
+ /// Constant string representing the name of an addon that is invalid.
+ ///
+ public const string InvalidAddon = "NullAddon";
+
+ private string? addonName;
+
+ ///
+ /// Gets the name of the addon this args referrers to.
+ ///
+ public string AddonName => this.GetAddonName();
+
+ ///
+ /// Gets the pointer to the addons AtkUnitBase.
+ ///
+ public nint Addon { get; init; }
+
+ ///
+ /// 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 == nint.Zero) return InvalidAddon;
+
+ var addonPointer = (AtkUnitBase*)this.Addon;
+ if (addonPointer->Name is null) return InvalidAddon;
+
+ return this.addonName ??= MemoryHelper.ReadString((nint)addonPointer->Name, 0x20);
+ }
+}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
index 614a7ac2a..d93001d1c 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonDrawArgs.cs
@@ -1,13 +1,10 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Finalize events.
///
-public class AddonDrawArgs : IAddonArgs
+public class AddonDrawArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.Draw;
+ public override AddonArgsType Type => AddonArgsType.Draw;
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
index aa31fb051..ed7aa1b3c 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonFinalizeArgs.cs
@@ -1,13 +1,10 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Finalize events.
///
-public class AddonFinalizeArgs : IAddonArgs
+public class AddonFinalizeArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.Finalize;
+ public override AddonArgsType Type => AddonArgsType.Finalize;
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
index ab4f37c3c..60ccaf8ea 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRefreshArgs.cs
@@ -1,15 +1,15 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+using System;
+using FFXIVClientStructs.FFXIV.Component.GUI;
+
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Finalize events.
///
-public class AddonRefreshArgs : IAddonArgs
+public class AddonRefreshArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.Refresh;
+ public override AddonArgsType Type => AddonArgsType.Refresh;
///
/// Gets the number of AtkValues.
@@ -20,4 +20,9 @@ public class AddonRefreshArgs : IAddonArgs
/// Gets the address of the AtkValue array.
///
public nint AtkValues { get; init; }
+
+ ///
+ /// Gets the AtkValues in the form of a span.
+ ///
+ public unsafe Span AtkValueSpan => new(this.AtkValues.ToPointer(), (int)this.AtkValueCount);
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
index dfd0dac5e..a31369aaf 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonRequestedUpdateArgs.cs
@@ -1,15 +1,12 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Finalize events.
///
-public class AddonRequestedUpdateArgs : IAddonArgs
+public class AddonRequestedUpdateArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.RequestedUpdate;
+ public override AddonArgsType Type => AddonArgsType.RequestedUpdate;
///
/// Gets the NumberArrayData** for this event.
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
index 4b467deb8..17c87967a 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
@@ -1,15 +1,16 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+using System;
+
+using FFXIVClientStructs.FFXIV.Component.GUI;
+
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Setup events.
///
-public class AddonSetupArgs : IAddonArgs
+public class AddonSetupArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.Setup;
+ public override AddonArgsType Type => AddonArgsType.Setup;
///
/// Gets the number of AtkValues.
@@ -20,4 +21,9 @@ public class AddonSetupArgs : IAddonArgs
/// Gets the address of the AtkValue array.
///
public nint AtkValues { get; init; }
+
+ ///
+ /// Gets the AtkValues in the form of a span.
+ ///
+ public unsafe Span AtkValueSpan => new(this.AtkValues.ToPointer(), (int)this.AtkValueCount);
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
index ede588001..993883d77 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonUpdateArgs.cs
@@ -1,15 +1,12 @@
-namespace Dalamud.Game.Addon.AddonArgTypes;
+namespace Dalamud.Game.Addon;
///
/// Addon argument data for Finalize events.
///
-public class AddonUpdateArgs : IAddonArgs
+public class AddonUpdateArgs : AddonArgs
{
///
- public nint Addon { get; init; }
-
- ///
- public AddonArgsType Type => AddonArgsType.Update;
+ public override AddonArgsType Type => AddonArgsType.Update;
///
/// Gets the time since the last update.
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgsType.cs b/Dalamud/Game/AddonLifecycle/AddonArgsType.cs
index ac325229d..8a07d445b 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgsType.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgsType.cs
@@ -1,7 +1,7 @@
namespace Dalamud.Game.Addon;
///
-/// Enumeration for available AddonLifecycle arg data
+/// Enumeration for available AddonLifecycle arg data.
///
public enum AddonArgsType
{
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
index 75b5b3753..17afbaeac 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
-using Dalamud.Game.Addon.AddonArgTypes;
using Dalamud.Hooking;
using Dalamud.Hooking.Internal;
using Dalamud.IoC;
@@ -128,7 +127,7 @@ private void ContinueConstruction()
this.onAddonRequestedUpdateHook.Enable();
}
- private void InvokeListeners(AddonEvent eventType, IAddonArgs args)
+ private void InvokeListeners(AddonEvent eventType, AddonArgs args)
{
// Match on string.empty for listeners that want events for all addons.
foreach (var listener in this.eventListeners.Where(listener => listener.EventType == eventType && (listener.AddonName == args.AddonName || listener.AddonName == string.Empty)))
@@ -141,7 +140,7 @@ private void OnAddonSetup(AtkUnitBase* addon, uint valueCount, AtkValue* values)
{
try
{
- this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs()
+ this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs
{
Addon = (nint)addon,
AtkValueCount = valueCount,
@@ -157,7 +156,7 @@ private void OnAddonSetup(AtkUnitBase* addon, uint valueCount, AtkValue* values)
try
{
- this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs()
+ this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs
{
Addon = (nint)addon,
AtkValueCount = valueCount,
diff --git a/Dalamud/Game/AddonLifecycle/IAddonArgs.cs b/Dalamud/Game/AddonLifecycle/IAddonArgs.cs
deleted file mode 100644
index ba77a2c6d..000000000
--- a/Dalamud/Game/AddonLifecycle/IAddonArgs.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Dalamud.Memory;
-using FFXIVClientStructs.FFXIV.Component.GUI;
-
-namespace Dalamud.Game.Addon;
-
-///
-/// Interface representing the argument data for AddonLifecycle events.
-///
-public unsafe interface IAddonArgs
-{
- ///
- /// Gets the name of the addon this args referrers to.
- ///
- string AddonName => this.Addon == nint.Zero ? "NullAddon" : MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
-
- ///
- /// Gets the pointer to the addons AtkUnitBase.
- ///
- nint Addon { get; init; }
-
- ///
- /// Gets the type of these args.
- ///
- AddonArgsType Type { get; }
-}
diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs
index 6b74e47cd..880bc0625 100644
--- a/Dalamud/Game/Gui/Dtr/DtrBar.cs
+++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs
@@ -255,7 +255,7 @@ private void HandleAddedNodes()
}
}
- private void OnDtrPostDraw(AddonEvent eventType, IAddonArgs addonInfo)
+ private void OnDtrPostDraw(AddonEvent eventType, AddonArgs addonInfo)
{
var addon = (AtkUnitBase*)addonInfo.Addon;
@@ -300,7 +300,7 @@ private void UpdateNodePositions(AtkUnitBase* addon)
}
}
- private void OnAddonRequestedUpdateDetour(AddonEvent eventType, IAddonArgs addonInfo)
+ private void OnAddonRequestedUpdateDetour(AddonEvent eventType, AddonArgs addonInfo)
{
var addon = (AtkUnitBase*)addonInfo.Addon;
diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
index 0821e62de..a9948430f 100644
--- a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
+++ b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/AddonLifecycleAgingStep.cs
@@ -100,32 +100,32 @@ public void CleanUp()
}
}
- private void PostSetup(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PostSetup(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterSetup) this.currentStep++;
}
- private void PostUpdate(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PostUpdate(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterUpdate) this.currentStep++;
}
- private void PostDraw(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PostDraw(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterDraw) this.currentStep++;
}
- private void PostRefresh(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PostRefresh(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRefresh) this.currentStep++;
}
- private void PostRequestedUpdate(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PostRequestedUpdate(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRequestedUpdate) this.currentStep++;
}
- private void PreFinalize(AddonEvent eventType, IAddonArgs addonInfo)
+ private void PreFinalize(AddonEvent eventType, AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterFinalize) this.currentStep++;
}
diff --git a/Dalamud/Plugin/Services/IAddonLifecycle.cs b/Dalamud/Plugin/Services/IAddonLifecycle.cs
index 5290395ab..e89c57931 100644
--- a/Dalamud/Plugin/Services/IAddonLifecycle.cs
+++ b/Dalamud/Plugin/Services/IAddonLifecycle.cs
@@ -15,7 +15,7 @@ public interface IAddonLifecycle
///
/// The event type that triggered the message.
/// Information about what addon triggered the message.
- public delegate void AddonEventDelegate(AddonEvent eventType, IAddonArgs args);
+ public delegate void AddonEventDelegate(AddonEvent eventType, AddonArgs args);
///
/// Register a listener that will trigger on the specified event and any of the specified addons.
From c6c28c6e3f8eff1652a2027673907235105ba37d Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Fri, 22 Sep 2023 21:12:44 -0700
Subject: [PATCH 4/4] Change default name so auto generate stops complaining
about improper casing.
---
Dalamud/Plugin/Services/IAddonLifecycle.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Plugin/Services/IAddonLifecycle.cs b/Dalamud/Plugin/Services/IAddonLifecycle.cs
index e89c57931..2bc41a366 100644
--- a/Dalamud/Plugin/Services/IAddonLifecycle.cs
+++ b/Dalamud/Plugin/Services/IAddonLifecycle.cs
@@ -13,9 +13,9 @@ public interface IAddonLifecycle
///
/// Delegate for receiving addon lifecycle event messages.
///
- /// The event type that triggered the message.
+ /// The event type that triggered the message.
/// Information about what addon triggered the message.
- public delegate void AddonEventDelegate(AddonEvent eventType, AddonArgs args);
+ public delegate void AddonEventDelegate(AddonEvent type, AddonArgs args);
///
/// Register a listener that will trigger on the specified event and any of the specified addons.