From aacfe4d6799b3c98ede0b6886c93175957c1dfff Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 20:59:00 -0700 Subject: [PATCH] Add IObjectTable (#1270) --- .../Game/ClientState/Objects/ObjectTable.cs | 40 +++++---------- Dalamud/Plugin/Services/IObjectTable.cs | 49 +++++++++++++++++++ 2 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 Dalamud/Plugin/Services/IObjectTable.cs diff --git a/Dalamud/Game/ClientState/Objects/ObjectTable.cs b/Dalamud/Game/ClientState/Objects/ObjectTable.cs index 70c17fd83..16cf7c277 100644 --- a/Dalamud/Game/ClientState/Objects/ObjectTable.cs +++ b/Dalamud/Game/ClientState/Objects/ObjectTable.cs @@ -7,6 +7,7 @@ using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Serilog; namespace Dalamud.Game.ClientState.Objects; @@ -17,7 +18,10 @@ namespace Dalamud.Game.ClientState.Objects; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed partial class ObjectTable : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed partial class ObjectTable : IServiceType, IObjectTable { private const int ObjectTableLength = 596; @@ -31,21 +35,13 @@ public sealed partial class ObjectTable : IServiceType Log.Verbose($"Object table address 0x{this.address.ObjectTable.ToInt64():X}"); } - /// - /// Gets the address of the object table. - /// + /// public IntPtr Address => this.address.ObjectTable; - /// - /// Gets the length of the object table. - /// + /// public int Length => ObjectTableLength; - /// - /// Get an object at the specified spawn index. - /// - /// Spawn index. - /// An at the specified spawn index. + /// public GameObject? this[int index] { get @@ -55,11 +51,7 @@ public sealed partial class ObjectTable : IServiceType } } - /// - /// Search for a game object by their Object ID. - /// - /// Object ID to find. - /// A game object or null. + /// public GameObject? SearchById(ulong objectId) { if (objectId is GameObject.InvalidGameObjectId or 0) @@ -77,11 +69,7 @@ public sealed partial class ObjectTable : IServiceType return null; } - /// - /// Gets the address of the game object at the specified index of the object table. - /// - /// The index of the object. - /// The memory address of the object. + /// public unsafe IntPtr GetObjectAddress(int index) { if (index < 0 || index >= ObjectTableLength) @@ -90,11 +78,7 @@ public sealed partial class ObjectTable : IServiceType return *(IntPtr*)(this.address.ObjectTable + (8 * index)); } - /// - /// Create a reference to an FFXIV game object. - /// - /// The address of the object in memory. - /// object or inheritor containing the requested data. + /// public unsafe GameObject? CreateObjectReference(IntPtr address) { var clientState = Service.GetNullable(); @@ -125,7 +109,7 @@ public sealed partial class ObjectTable : IServiceType /// /// This collection represents the currently spawned FFXIV game objects. /// -public sealed partial class ObjectTable : IReadOnlyCollection +public sealed partial class ObjectTable { /// int IReadOnlyCollection.Count => this.Length; diff --git a/Dalamud/Plugin/Services/IObjectTable.cs b/Dalamud/Plugin/Services/IObjectTable.cs new file mode 100644 index 000000000..d029045fa --- /dev/null +++ b/Dalamud/Plugin/Services/IObjectTable.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; + +using Dalamud.Game.ClientState.Objects.Types; + +namespace Dalamud.Plugin.Services; + +/// +/// This collection represents the currently spawned FFXIV game objects. +/// +public interface IObjectTable : IReadOnlyCollection +{ + /// + /// Gets the address of the object table. + /// + public nint Address { get; } + + /// + /// Gets the length of the object table. + /// + public int Length { get; } + + /// + /// Get an object at the specified spawn index. + /// + /// Spawn index. + /// An at the specified spawn index. + public GameObject? this[int index] { get; } + + /// + /// Search for a game object by their Object ID. + /// + /// Object ID to find. + /// A game object or null. + public GameObject? SearchById(ulong objectId); + + /// + /// Gets the address of the game object at the specified index of the object table. + /// + /// The index of the object. + /// The memory address of the object. + public nint GetObjectAddress(int index); + + /// + /// Create a reference to an FFXIV game object. + /// + /// The address of the object in memory. + /// object or inheritor containing the requested data. + public GameObject? CreateObjectReference(nint address); +}