From d966e5338a7ea11495f972fcc80e587f34686ae7 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Tue, 16 Jul 2024 14:31:03 -0400
Subject: [PATCH] Add SearchByEntityId (#1935)
---
Dalamud/Game/ClientState/Objects/ObjectTable.cs | 17 +++++++++++++++++
Dalamud/Plugin/Services/IObjectTable.cs | 7 +++++++
2 files changed, 24 insertions(+)
diff --git a/Dalamud/Game/ClientState/Objects/ObjectTable.cs b/Dalamud/Game/ClientState/Objects/ObjectTable.cs
index a9bf057c5..d88383c22 100644
--- a/Dalamud/Game/ClientState/Objects/ObjectTable.cs
+++ b/Dalamud/Game/ClientState/Objects/ObjectTable.cs
@@ -98,6 +98,23 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
return null;
}
+ ///
+ public IGameObject? SearchByEntityId(uint entityId)
+ {
+ _ = this.WarnMultithreadedUsage();
+
+ if (entityId is 0 or 0xE0000000)
+ return null;
+
+ foreach (var e in this.cachedObjectTable)
+ {
+ if (e.Update() is { } o && o.EntityId == entityId)
+ return o;
+ }
+
+ return null;
+ }
+
///
public unsafe nint GetObjectAddress(int index)
{
diff --git a/Dalamud/Plugin/Services/IObjectTable.cs b/Dalamud/Plugin/Services/IObjectTable.cs
index a74e6db7a..ad2c4d6dc 100644
--- a/Dalamud/Plugin/Services/IObjectTable.cs
+++ b/Dalamud/Plugin/Services/IObjectTable.cs
@@ -33,6 +33,13 @@ public interface IObjectTable : IEnumerable
/// A game object or null.
public IGameObject? SearchById(ulong gameObjectId);
+ ///
+ /// Search for a game object by the Entity ID.
+ ///
+ /// Entity ID to find.
+ /// A game object or null.
+ public IGameObject? SearchByEntityId(uint entityId);
+
///
/// Gets the address of the game object at the specified index of the object table.
///