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] 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 @@ internal unsafe class AddonEventManager : IDisposable, IServiceType
///
/// 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.Concurrent;
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
{
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 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
}
}
- private void OnDtrPostDraw(AddonEvent eventType, AddonArgs addonInfo)
+ private void OnDtrPostDraw(AddonEvent eventType, IAddonArgs addonInfo)
{
var addon = (AtkUnitBase*)addonInfo.Addon;
@@ -300,7 +300,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
}
}
- 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 @@ internal class AddonLifecycleAgingStep : IAgingStep
}
}
- 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.