From a7202096bf33d2a0f3e80886560f665e71ba72e9 Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 17:11:05 -0700 Subject: [PATCH] Add IFateTable (#1263) --- Dalamud/Game/ClientState/Fates/FateTable.cs | 34 ++++++----------- Dalamud/Plugin/Services/IFateTable.cs | 42 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 Dalamud/Plugin/Services/IFateTable.cs diff --git a/Dalamud/Game/ClientState/Fates/FateTable.cs b/Dalamud/Game/ClientState/Fates/FateTable.cs index dfd4bcaee..8416f0ffb 100644 --- a/Dalamud/Game/ClientState/Fates/FateTable.cs +++ b/Dalamud/Game/ClientState/Fates/FateTable.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Serilog; namespace Dalamud.Game.ClientState.Fates; @@ -14,7 +15,10 @@ namespace Dalamud.Game.ClientState.Fates; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed partial class FateTable : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning enable SA1015 +public sealed partial class FateTable : IServiceType, IFateTable { private readonly ClientStateAddressResolver address; @@ -26,14 +30,10 @@ public sealed partial class FateTable : IServiceType Log.Verbose($"Fate table address 0x{this.address.FateTablePtr.ToInt64():X}"); } - /// - /// Gets the address of the Fate table. - /// + /// public IntPtr Address => this.address.FateTablePtr; - /// - /// Gets the amount of currently active Fates. - /// + /// public unsafe int Length { get @@ -69,11 +69,7 @@ public sealed partial class FateTable : IServiceType private unsafe FFXIVClientStructs.FFXIV.Client.Game.Fate.FateManager* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Fate.FateManager*)this.FateTableAddress; - /// - /// Get an actor at the specified spawn index. - /// - /// Spawn index. - /// A at the specified spawn index. + /// public Fate? this[int index] { get @@ -83,11 +79,7 @@ public sealed partial class FateTable : IServiceType } } - /// - /// Gets the address of the Fate at the specified index of the fate table. - /// - /// The index of the Fate. - /// The memory address of the Fate. + /// public unsafe IntPtr GetFateAddress(int index) { if (index >= this.Length) @@ -100,11 +92,7 @@ public sealed partial class FateTable : IServiceType return (IntPtr)this.Struct->Fates.Get((ulong)index).Value; } - /// - /// Create a reference to a FFXIV actor. - /// - /// The offset of the actor in memory. - /// object containing requested data. + /// public Fate? CreateFateReference(IntPtr offset) { var clientState = Service.Get(); @@ -122,7 +110,7 @@ public sealed partial class FateTable : IServiceType /// /// This collection represents the currently available Fate events. /// -public sealed partial class FateTable : IReadOnlyCollection +public sealed partial class FateTable { /// int IReadOnlyCollection.Count => this.Length; diff --git a/Dalamud/Plugin/Services/IFateTable.cs b/Dalamud/Plugin/Services/IFateTable.cs new file mode 100644 index 000000000..ba243ec04 --- /dev/null +++ b/Dalamud/Plugin/Services/IFateTable.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +using Dalamud.Game.ClientState.Fates; + +namespace Dalamud.Plugin.Services; + +/// +/// This collection represents the currently available Fate events. +/// +public interface IFateTable : IReadOnlyCollection +{ + /// + /// Gets the address of the Fate table. + /// + public nint Address { get; } + + /// + /// Gets the amount of currently active Fates. + /// + public int Length { get; } + + /// + /// Get an actor at the specified spawn index. + /// + /// Spawn index. + /// A at the specified spawn index. + public Fate? this[int index] { get; } + + /// + /// Gets the address of the Fate at the specified index of the fate table. + /// wo + /// The index of the Fate. + /// The memory address of the Fate. + public nint GetFateAddress(int index); + + /// + /// Create a reference to a FFXIV actor. + /// + /// The offset of the actor in memory. + /// object containing requested data. + public Fate? CreateFateReference(nint offset); +}