Add SearchByEntityId (#1935)

This commit is contained in:
MidoriKami 2024-07-16 14:31:03 -04:00 committed by GitHub
parent f5ab8d5e98
commit d966e5338a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -98,6 +98,23 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
return null; return null;
} }
/// <inheritdoc/>
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;
}
/// <inheritdoc/> /// <inheritdoc/>
public unsafe nint GetObjectAddress(int index) public unsafe nint GetObjectAddress(int index)
{ {

View file

@ -33,6 +33,13 @@ public interface IObjectTable : IEnumerable<IGameObject>
/// <returns>A game object or null.</returns> /// <returns>A game object or null.</returns>
public IGameObject? SearchById(ulong gameObjectId); public IGameObject? SearchById(ulong gameObjectId);
/// <summary>
/// Search for a game object by the Entity ID.
/// </summary>
/// <param name="entityId">Entity ID to find.</param>
/// <returns>A game object or null.</returns>
public IGameObject? SearchByEntityId(uint entityId);
/// <summary> /// <summary>
/// Gets the address of the game object at the specified index of the object table. /// Gets the address of the game object at the specified index of the object table.
/// </summary> /// </summary>