Add IObjectTable (#1270)

This commit is contained in:
MidoriKami 2023-06-24 20:59:00 -07:00 committed by GitHub
parent 2f138bb1df
commit aacfe4d679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 28 deletions

View file

@ -7,6 +7,7 @@ using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
using Serilog; using Serilog;
namespace Dalamud.Game.ClientState.Objects; namespace Dalamud.Game.ClientState.Objects;
@ -17,7 +18,10 @@ namespace Dalamud.Game.ClientState.Objects;
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService] [ServiceManager.BlockingEarlyLoadedService]
public sealed partial class ObjectTable : IServiceType #pragma warning disable SA1015
[ResolveVia<IObjectTable>]
#pragma warning restore SA1015
public sealed partial class ObjectTable : IServiceType, IObjectTable
{ {
private const int ObjectTableLength = 596; 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}"); Log.Verbose($"Object table address 0x{this.address.ObjectTable.ToInt64():X}");
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the object table.
/// </summary>
public IntPtr Address => this.address.ObjectTable; public IntPtr Address => this.address.ObjectTable;
/// <summary> /// <inheritdoc/>
/// Gets the length of the object table.
/// </summary>
public int Length => ObjectTableLength; public int Length => ObjectTableLength;
/// <summary> /// <inheritdoc/>
/// Get an object at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>An <see cref="GameObject"/> at the specified spawn index.</returns>
public GameObject? this[int index] public GameObject? this[int index]
{ {
get get
@ -55,11 +51,7 @@ public sealed partial class ObjectTable : IServiceType
} }
} }
/// <summary> /// <inheritdoc/>
/// Search for a game object by their Object ID.
/// </summary>
/// <param name="objectId">Object ID to find.</param>
/// <returns>A game object or null.</returns>
public GameObject? SearchById(ulong objectId) public GameObject? SearchById(ulong objectId)
{ {
if (objectId is GameObject.InvalidGameObjectId or 0) if (objectId is GameObject.InvalidGameObjectId or 0)
@ -77,11 +69,7 @@ public sealed partial class ObjectTable : IServiceType
return null; return null;
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the game object at the specified index of the object table.
/// </summary>
/// <param name="index">The index of the object.</param>
/// <returns>The memory address of the object.</returns>
public unsafe IntPtr GetObjectAddress(int index) public unsafe IntPtr GetObjectAddress(int index)
{ {
if (index < 0 || index >= ObjectTableLength) if (index < 0 || index >= ObjectTableLength)
@ -90,11 +78,7 @@ public sealed partial class ObjectTable : IServiceType
return *(IntPtr*)(this.address.ObjectTable + (8 * index)); return *(IntPtr*)(this.address.ObjectTable + (8 * index));
} }
/// <summary> /// <inheritdoc/>
/// Create a reference to an FFXIV game object.
/// </summary>
/// <param name="address">The address of the object in memory.</param>
/// <returns><see cref="GameObject"/> object or inheritor containing the requested data.</returns>
public unsafe GameObject? CreateObjectReference(IntPtr address) public unsafe GameObject? CreateObjectReference(IntPtr address)
{ {
var clientState = Service<ClientState>.GetNullable(); var clientState = Service<ClientState>.GetNullable();
@ -125,7 +109,7 @@ public sealed partial class ObjectTable : IServiceType
/// <summary> /// <summary>
/// This collection represents the currently spawned FFXIV game objects. /// This collection represents the currently spawned FFXIV game objects.
/// </summary> /// </summary>
public sealed partial class ObjectTable : IReadOnlyCollection<GameObject> public sealed partial class ObjectTable
{ {
/// <inheritdoc/> /// <inheritdoc/>
int IReadOnlyCollection<GameObject>.Count => this.Length; int IReadOnlyCollection<GameObject>.Count => this.Length;

View file

@ -0,0 +1,49 @@
using System.Collections.Generic;
using Dalamud.Game.ClientState.Objects.Types;
namespace Dalamud.Plugin.Services;
/// <summary>
/// This collection represents the currently spawned FFXIV game objects.
/// </summary>
public interface IObjectTable : IReadOnlyCollection<GameObject>
{
/// <summary>
/// Gets the address of the object table.
/// </summary>
public nint Address { get; }
/// <summary>
/// Gets the length of the object table.
/// </summary>
public int Length { get; }
/// <summary>
/// Get an object at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>An <see cref="GameObject"/> at the specified spawn index.</returns>
public GameObject? this[int index] { get; }
/// <summary>
/// Search for a game object by their Object ID.
/// </summary>
/// <param name="objectId">Object ID to find.</param>
/// <returns>A game object or null.</returns>
public GameObject? SearchById(ulong objectId);
/// <summary>
/// Gets the address of the game object at the specified index of the object table.
/// </summary>
/// <param name="index">The index of the object.</param>
/// <returns>The memory address of the object.</returns>
public nint GetObjectAddress(int index);
/// <summary>
/// Create a reference to an FFXIV game object.
/// </summary>
/// <param name="address">The address of the object in memory.</param>
/// <returns><see cref="GameObject"/> object or inheritor containing the requested data.</returns>
public GameObject? CreateObjectReference(nint address);
}