From bf5fcaaf0079602ea7763adf0cdf41121924cdba Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Mon, 4 Aug 2025 15:47:39 -0700 Subject: [PATCH] IObjectTable Helpful Enumerables (#2328) * Add ObjectTable Enumerables * Put kind check on the correct function --- .../Game/ClientState/Objects/ObjectTable.cs | 40 +++++++++++++++++++ Dalamud/Plugin/Services/IObjectTable.cs | 32 +++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Dalamud/Game/ClientState/Objects/ObjectTable.cs b/Dalamud/Game/ClientState/Objects/ObjectTable.cs index f97385fce..84c1b5693 100644 --- a/Dalamud/Game/ClientState/Objects/ObjectTable.cs +++ b/Dalamud/Game/ClientState/Objects/ObjectTable.cs @@ -66,6 +66,24 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable /// public int Length => objectTableLength; + /// + public IEnumerable PlayerObjects => this.GetPlayerObjects(); + + /// + public IEnumerable CharacterManagerObjects => this.GetObjectsInRange(..199); + + /// + public IEnumerable ClientObjects => this.GetObjectsInRange(200..448); + + /// + public IEnumerable EventObjects => this.GetObjectsInRange(449..488); + + /// + public IEnumerable StandObjects => this.GetObjectsInRange(489..628); + + /// + public IEnumerable ReactionEventObjects => this.GetObjectsInRange(629..728); + /// public IGameObject? this[int index] { @@ -146,6 +164,28 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable }; } + private IEnumerable GetPlayerObjects() + { + for (var index = 0; index < 200; index += 2) + { + if (this[index] is IBattleChara { ObjectKind: ObjectKind.Player } gameObject) + { + yield return gameObject; + } + } + } + + private IEnumerable GetObjectsInRange(Range range) + { + for (var index = range.Start.Value; index <= range.End.Value; index++) + { + if (this[index] is { } gameObject) + { + yield return gameObject; + } + } + } + /// Stores an object table entry, with preallocated concrete types. /// Initializes a new instance of the struct. /// A pointer to the object table entry this entry should be pointing to. diff --git a/Dalamud/Plugin/Services/IObjectTable.cs b/Dalamud/Plugin/Services/IObjectTable.cs index ad2c4d6dc..4c5305513 100644 --- a/Dalamud/Plugin/Services/IObjectTable.cs +++ b/Dalamud/Plugin/Services/IObjectTable.cs @@ -19,6 +19,38 @@ public interface IObjectTable : IEnumerable /// public int Length { get; } + /// + /// Gets an enumerator for accessing player objects. This will only contain BattleChara objects. + /// Does not contain any mounts, minions, or accessories. + /// + public IEnumerable PlayerObjects { get; } + + /// + /// Gets an enumerator for accessing character manager objects. Contains all objects in indexes [0, 199]. + /// Includes mounts, minions, accessories, and players. + /// + public IEnumerable CharacterManagerObjects { get; } + + /// + /// Gets an enumerator for accessing client objects. Contains all objects in indexes [200, 448]. + /// + public IEnumerable ClientObjects { get; } + + /// + /// Gets an enumerator for accessing event objects. Contains all objects in indexes [449, 488]. + /// + public IEnumerable EventObjects { get; } + + /// + /// Gets an enumerator for accessing stand objects. Contains all objects in indexes [489, 628]. + /// + public IEnumerable StandObjects { get; } + + /// + /// Gets an enumerator for accessing reaction event objects. Contains all objects in indexes [629, 728]. + /// + public IEnumerable ReactionEventObjects { get; } + /// /// Get an object at the specified spawn index. ///