mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Use abstract class instead of interface
This commit is contained in:
parent
bd81d23097
commit
fd3bd6dc5b
14 changed files with 95 additions and 76 deletions
|
|
@ -160,7 +160,7 @@ internal unsafe class AddonEventManager : IDisposable, IServiceType
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="eventType">Event type that triggered this call.</param>
|
/// <param name="eventType">Event type that triggered this call.</param>
|
||||||
/// <param name="addonInfo">Addon that triggered this call.</param>
|
/// <param name="addonInfo">Addon that triggered this call.</param>
|
||||||
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.
|
// It shouldn't be possible for this event to be anything other than PreFinalize.
|
||||||
if (eventType != AddonEvent.PreFinalize) return;
|
if (eventType != AddonEvent.PreFinalize) return;
|
||||||
|
|
|
||||||
46
Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs
Normal file
46
Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonArgs.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
using Dalamud.Memory;
|
||||||
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for AddonLifecycle AddonArgTypes.
|
||||||
|
/// </summary>
|
||||||
|
public abstract unsafe class AddonArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constant string representing the name of an addon that is invalid.
|
||||||
|
/// </summary>
|
||||||
|
public const string InvalidAddon = "NullAddon";
|
||||||
|
|
||||||
|
private string? addonName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the addon this args referrers to.
|
||||||
|
/// </summary>
|
||||||
|
public string AddonName => this.GetAddonName();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the pointer to the addons AtkUnitBase.
|
||||||
|
/// </summary>
|
||||||
|
public nint Addon { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type of these args.
|
||||||
|
/// </summary>
|
||||||
|
public abstract AddonArgsType Type { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method for ensuring the name of the addon is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The name of the addon for this object. <see cref="InvalidAddon"/> when invalid.</returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Finalize events.
|
/// Addon argument data for Finalize events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonDrawArgs : IAddonArgs
|
public class AddonDrawArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.Draw;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.Draw;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Finalize events.
|
/// Addon argument data for Finalize events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonFinalizeArgs : IAddonArgs
|
public class AddonFinalizeArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.Finalize;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.Finalize;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
using System;
|
||||||
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Finalize events.
|
/// Addon argument data for Finalize events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonRefreshArgs : IAddonArgs
|
public class AddonRefreshArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.Refresh;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.Refresh;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of AtkValues.
|
/// Gets the number of AtkValues.
|
||||||
|
|
@ -20,4 +20,9 @@ public class AddonRefreshArgs : IAddonArgs
|
||||||
/// Gets the address of the AtkValue array.
|
/// Gets the address of the AtkValue array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public nint AtkValues { get; init; }
|
public nint AtkValues { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the AtkValues in the form of a span.
|
||||||
|
/// </summary>
|
||||||
|
public unsafe Span<AtkValue> AtkValueSpan => new(this.AtkValues.ToPointer(), (int)this.AtkValueCount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Finalize events.
|
/// Addon argument data for Finalize events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonRequestedUpdateArgs : IAddonArgs
|
public class AddonRequestedUpdateArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.RequestedUpdate;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.RequestedUpdate;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the NumberArrayData** for this event.
|
/// Gets the NumberArrayData** for this event.
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
using System;
|
||||||
|
|
||||||
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Setup events.
|
/// Addon argument data for Setup events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonSetupArgs : IAddonArgs
|
public class AddonSetupArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.Setup;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.Setup;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of AtkValues.
|
/// Gets the number of AtkValues.
|
||||||
|
|
@ -20,4 +21,9 @@ public class AddonSetupArgs : IAddonArgs
|
||||||
/// Gets the address of the AtkValue array.
|
/// Gets the address of the AtkValue array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public nint AtkValues { get; init; }
|
public nint AtkValues { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the AtkValues in the form of a span.
|
||||||
|
/// </summary>
|
||||||
|
public unsafe Span<AtkValue> AtkValueSpan => new(this.AtkValues.ToPointer(), (int)this.AtkValueCount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
namespace Dalamud.Game.Addon.AddonArgTypes;
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Addon argument data for Finalize events.
|
/// Addon argument data for Finalize events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddonUpdateArgs : IAddonArgs
|
public class AddonUpdateArgs : AddonArgs
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public nint Addon { get; init; }
|
public override AddonArgsType Type => AddonArgsType.Update;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public AddonArgsType Type => AddonArgsType.Update;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the time since the last update.
|
/// Gets the time since the last update.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
namespace Dalamud.Game.Addon;
|
namespace Dalamud.Game.Addon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumeration for available AddonLifecycle arg data
|
/// Enumeration for available AddonLifecycle arg data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum AddonArgsType
|
public enum AddonArgsType
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Dalamud.Game.Addon.AddonArgTypes;
|
|
||||||
using Dalamud.Hooking;
|
using Dalamud.Hooking;
|
||||||
using Dalamud.Hooking.Internal;
|
using Dalamud.Hooking.Internal;
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
|
|
@ -128,7 +127,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
||||||
this.onAddonRequestedUpdateHook.Enable();
|
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.
|
// 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)))
|
foreach (var listener in this.eventListeners.Where(listener => listener.EventType == eventType && (listener.AddonName == args.AddonName || listener.AddonName == string.Empty)))
|
||||||
|
|
@ -141,7 +140,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs()
|
this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs
|
||||||
{
|
{
|
||||||
Addon = (nint)addon,
|
Addon = (nint)addon,
|
||||||
AtkValueCount = valueCount,
|
AtkValueCount = valueCount,
|
||||||
|
|
@ -157,7 +156,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs()
|
this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs
|
||||||
{
|
{
|
||||||
Addon = (nint)addon,
|
Addon = (nint)addon,
|
||||||
AtkValueCount = valueCount,
|
AtkValueCount = valueCount,
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
using Dalamud.Memory;
|
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
||||||
|
|
||||||
namespace Dalamud.Game.Addon;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Interface representing the argument data for AddonLifecycle events.
|
|
||||||
/// </summary>
|
|
||||||
public unsafe interface IAddonArgs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name of the addon this args referrers to.
|
|
||||||
/// </summary>
|
|
||||||
string AddonName => this.Addon == nint.Zero ? "NullAddon" : MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the pointer to the addons AtkUnitBase.
|
|
||||||
/// </summary>
|
|
||||||
nint Addon { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the type of these args.
|
|
||||||
/// </summary>
|
|
||||||
AddonArgsType Type { get; }
|
|
||||||
}
|
|
||||||
|
|
@ -255,7 +255,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDtrPostDraw(AddonEvent eventType, IAddonArgs addonInfo)
|
private void OnDtrPostDraw(AddonEvent eventType, AddonArgs addonInfo)
|
||||||
{
|
{
|
||||||
var addon = (AtkUnitBase*)addonInfo.Addon;
|
var addon = (AtkUnitBase*)addonInfo.Addon;
|
||||||
|
|
||||||
|
|
@ -300,7 +300,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAddonRequestedUpdateDetour(AddonEvent eventType, IAddonArgs addonInfo)
|
private void OnAddonRequestedUpdateDetour(AddonEvent eventType, AddonArgs addonInfo)
|
||||||
{
|
{
|
||||||
var addon = (AtkUnitBase*)addonInfo.Addon;
|
var addon = (AtkUnitBase*)addonInfo.Addon;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,32 +100,32 @@ internal class AddonLifecycleAgingStep : IAgingStep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PostSetup(AddonEvent eventType, IAddonArgs addonInfo)
|
private void PostSetup(AddonEvent eventType, AddonArgs addonInfo)
|
||||||
{
|
{
|
||||||
if (this.currentStep is TestStep.CharacterSetup) this.currentStep++;
|
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++;
|
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++;
|
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++;
|
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++;
|
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++;
|
if (this.currentStep is TestStep.CharacterFinalize) this.currentStep++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public interface IAddonLifecycle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="eventType">The event type that triggered the message.</param>
|
/// <param name="eventType">The event type that triggered the message.</param>
|
||||||
/// <param name="args">Information about what addon triggered the message.</param>
|
/// <param name="args">Information about what addon triggered the message.</param>
|
||||||
public delegate void AddonEventDelegate(AddonEvent eventType, IAddonArgs args);
|
public delegate void AddonEventDelegate(AddonEvent eventType, AddonArgs args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register a listener that will trigger on the specified event and any of the specified addons.
|
/// Register a listener that will trigger on the specified event and any of the specified addons.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue