From 8d5f2bdf51da5feef32fd31c7c3723ce17326f41 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Mon, 3 Jun 2024 11:19:39 -0700 Subject: [PATCH] Disambiguate ObjectId to GameObjectId and EntityId --- .../Game/ClientState/Objects/ObjectTable.cs | 6 ++--- .../ClientState/Objects/Types/GameObject.cs | 25 +++++++++++-------- .../Windows/Data/Widgets/ObjectTableWidget.cs | 2 +- .../Windows/Data/Widgets/PartyListWidget.cs | 2 +- Dalamud/Plugin/Services/IObjectTable.cs | 4 +-- Dalamud/Utility/Util.cs | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Dalamud/Game/ClientState/Objects/ObjectTable.cs b/Dalamud/Game/ClientState/Objects/ObjectTable.cs index b36b3ce92..30bfc5d6f 100644 --- a/Dalamud/Game/ClientState/Objects/ObjectTable.cs +++ b/Dalamud/Game/ClientState/Objects/ObjectTable.cs @@ -83,16 +83,16 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable } /// - public GameObject? SearchById(ulong objectId) + public GameObject? SearchById(ulong gameObjectId) { _ = this.WarnMultithreadedUsage(); - if (objectId is GameObject.InvalidGameObjectId or 0) + if (gameObjectId is 0) return null; foreach (var e in this.cachedObjectTable) { - if (e.Update() is { } o && o.ObjectId == objectId) + if (e.Update() is { } o && o.GameObjectId == gameObjectId) return o; } diff --git a/Dalamud/Game/ClientState/Objects/Types/GameObject.cs b/Dalamud/Game/ClientState/Objects/Types/GameObject.cs index 8e0eae83d..e0cb06789 100644 --- a/Dalamud/Game/ClientState/Objects/Types/GameObject.cs +++ b/Dalamud/Game/ClientState/Objects/Types/GameObject.cs @@ -12,11 +12,6 @@ namespace Dalamud.Game.ClientState.Objects.Types; /// public unsafe partial class GameObject : IEquatable { - /// - /// IDs of non-networked GameObjects. - /// - public const uint InvalidGameObjectId = 0xE0000000; - /// /// Initializes a new instance of the class. /// @@ -79,13 +74,13 @@ public unsafe partial class GameObject : IEquatable public bool IsValid() => IsValid(this); /// - bool IEquatable.Equals(GameObject other) => this.ObjectId == other?.ObjectId; + bool IEquatable.Equals(GameObject other) => this.GameObjectId == other?.GameObjectId; /// public override bool Equals(object obj) => ((IEquatable)this).Equals(obj as GameObject); /// - public override int GetHashCode() => this.ObjectId.GetHashCode(); + public override int GetHashCode() => this.GameObjectId.GetHashCode(); } /// @@ -99,10 +94,20 @@ public unsafe partial class GameObject public SeString Name => MemoryHelper.ReadSeString((nint)Unsafe.AsPointer(ref this.Struct->Name[0]), 64); /// - /// Gets the object ID of this . + /// Gets the GameObjectID for this GameObject. The Game Object ID is a globally unique identifier that points to + /// this specific object. This ID is used to reference specific objects on the local client (e.g. for targeting). + /// + /// Not to be confused with . /// - public uint ObjectId => this.Struct->EntityId; + public ulong GameObjectId => this.Struct->GetObjectId(); + /// + /// Gets the Entity ID for this GameObject. Entity IDs are assigned to networked GameObjects. + /// + /// A value of 0xE000_0000 indicates that this entity is not networked and has specific interactivity rules. + /// + public uint EntityId => this.Struct->EntityId; + /// /// Gets the data ID for linking to other respective game data. /// @@ -185,5 +190,5 @@ public unsafe partial class GameObject protected internal FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)this.Address; /// - public override string ToString() => $"{this.ObjectId:X}({this.Name.TextValue} - {this.ObjectKind}) at {this.Address:X}"; + public override string ToString() => $"{this.GameObjectId:X}({this.Name.TextValue} - {this.ObjectKind}) at {this.Address:X}"; } diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/ObjectTableWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/ObjectTableWidget.cs index b34eef6c8..963138bec 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/ObjectTableWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/ObjectTableWidget.cs @@ -81,7 +81,7 @@ internal class ObjectTableWidget : IDataWindowWidget // So, while WorldToScreen will return false if the point is off of game client screen, to // to avoid performance issues, we have to manually determine if creating a window would // produce a new viewport, and skip rendering it if so - var objectText = $"{obj.Address.ToInt64():X}:{obj.ObjectId:X}[{i}] - {obj.ObjectKind} - {obj.Name}"; + var objectText = $"{obj.Address.ToInt64():X}:{obj.GameObjectId:X}[{i}] - {obj.ObjectKind} - {obj.Name}"; var screenPos = ImGui.GetMainViewport().Pos; var screenSize = ImGui.GetMainViewport().Size; diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/PartyListWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/PartyListWidget.cs index 01c0b74b3..6e4cbcb16 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/PartyListWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/PartyListWidget.cs @@ -48,7 +48,7 @@ internal class PartyListWidget : IDataWindowWidget continue; } - ImGui.Text($"[{i}] {member.Address.ToInt64():X} - {member.Name} - {member.GameObject?.ObjectId}"); + ImGui.Text($"[{i}] {member.Address.ToInt64():X} - {member.Name} - {member.GameObject?.GameObjectId}"); if (this.resolveGameData) { var actor = member.GameObject; diff --git a/Dalamud/Plugin/Services/IObjectTable.cs b/Dalamud/Plugin/Services/IObjectTable.cs index d8d9fdb78..bc6f9f811 100644 --- a/Dalamud/Plugin/Services/IObjectTable.cs +++ b/Dalamud/Plugin/Services/IObjectTable.cs @@ -29,9 +29,9 @@ public interface IObjectTable : IEnumerable /// /// Search for a game object by their Object ID. /// - /// Object ID to find. + /// Object ID to find. /// A game object or null. - public GameObject? SearchById(ulong objectId); + public GameObject? SearchById(ulong gameObjectId); /// /// Gets the address of the game object at the specified index of the object table. diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index a7812bec3..f77edf55a 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -711,7 +711,7 @@ public static class Util internal static void PrintGameObject(GameObject actor, string tag, bool resolveGameData) { var actorString = - $"{actor.Address.ToInt64():X}:{actor.ObjectId:X}[{tag}] - {actor.ObjectKind} - {actor.Name} - X{actor.Position.X} Y{actor.Position.Y} Z{actor.Position.Z} D{actor.YalmDistanceX} R{actor.Rotation} - Target: {actor.TargetObjectId:X}\n"; + $"{actor.Address.ToInt64():X}:{actor.GameObjectId:X}[{tag}] - {actor.ObjectKind} - {actor.Name} - X{actor.Position.X} Y{actor.Position.Y} Z{actor.Position.Z} D{actor.YalmDistanceX} R{actor.Rotation} - Target: {actor.TargetObjectId:X}\n"; if (actor is Npc npc) actorString += $" DataId: {npc.DataId} NameId:{npc.NameId}\n";