Do not check every identifier.

This commit is contained in:
Ottermandias 2022-11-18 15:53:40 +01:00
parent 03bbba6735
commit f676bd1889
5 changed files with 32 additions and 18 deletions

View file

@ -107,9 +107,9 @@ public partial class ActorManager
} }
/// <summary> /// <summary>
/// Compute an ActorIdentifier from a GameObject. /// Compute an ActorIdentifier from a GameObject. If check is true, the values are checked for validity.
/// </summary> /// </summary>
public unsafe ActorIdentifier FromObject(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* actor) public unsafe ActorIdentifier FromObject(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* actor, bool check = true)
{ {
if (actor == null) if (actor == null)
return ActorIdentifier.Invalid; return ActorIdentifier.Invalid;
@ -119,11 +119,11 @@ public partial class ActorManager
{ {
var parentIdx = _toParentIdx(idx); var parentIdx = _toParentIdx(idx);
if (parentIdx >= 0) if (parentIdx >= 0)
return FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_objects.GetObjectAddress(parentIdx)); return FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)_objects.GetObjectAddress(parentIdx), check);
} }
else if (idx is >= (ushort)SpecialActor.CharacterScreen and <= (ushort)SpecialActor.Portrait) else if (idx is >= (ushort)SpecialActor.CharacterScreen and <= (ushort)SpecialActor.Portrait)
{ {
return CreateSpecial((SpecialActor)idx); return CreateIndividualUnchecked(IdentifierType.Special, ByteString.Empty, idx, ObjectKind.None, uint.MaxValue);
} }
switch ((ObjectKind)actor->ObjectKind) switch ((ObjectKind)actor->ObjectKind)
@ -132,7 +132,9 @@ public partial class ActorManager
{ {
var name = new ByteString(actor->Name); var name = new ByteString(actor->Name);
var homeWorld = ((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->HomeWorld; var homeWorld = ((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->HomeWorld;
return CreatePlayer(name, homeWorld); return check
? CreatePlayer(name, homeWorld)
: CreateIndividualUnchecked(IdentifierType.Player, name, homeWorld, ObjectKind.None, uint.MaxValue);
} }
case ObjectKind.BattleNpc: case ObjectKind.BattleNpc:
{ {
@ -146,14 +148,24 @@ public partial class ActorManager
var name = new ByteString(owner->GameObject.Name); var name = new ByteString(owner->GameObject.Name);
var homeWorld = owner->HomeWorld; var homeWorld = owner->HomeWorld;
return CreateOwned(name, homeWorld, ObjectKind.BattleNpc, return check
((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID); ? CreateOwned(name, homeWorld, ObjectKind.BattleNpc,
((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID)
: CreateIndividualUnchecked(IdentifierType.Owned, name, homeWorld, ObjectKind.BattleNpc,
((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID);
} }
return CreateNpc(ObjectKind.BattleNpc, ((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID, return check
actor->ObjectIndex); ? CreateNpc(ObjectKind.BattleNpc, ((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID,
actor->ObjectIndex)
: CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, actor->ObjectIndex, ObjectKind.BattleNpc,
((FFXIVClientStructs.FFXIV.Client.Game.Character.Character*)actor)->NameID);
} }
case ObjectKind.EventNpc: return CreateNpc(ObjectKind.EventNpc, actor->DataID, actor->ObjectIndex); case ObjectKind.EventNpc:
return check
? CreateNpc(ObjectKind.EventNpc, actor->DataID, actor->ObjectIndex)
: CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, actor->ObjectIndex, ObjectKind.EventNpc,
actor->ObjectIndex);
case ObjectKind.MountType: case ObjectKind.MountType:
case ObjectKind.Companion: case ObjectKind.Companion:
case (ObjectKind)15: // TODO: CS Update case (ObjectKind)15: // TODO: CS Update
@ -166,7 +178,10 @@ public partial class ActorManager
return ActorIdentifier.Invalid; return ActorIdentifier.Invalid;
var dataId = GetCompanionId(actor, &owner->GameObject); var dataId = GetCompanionId(actor, &owner->GameObject);
return CreateOwned(new ByteString(owner->GameObject.Name), owner->HomeWorld, (ObjectKind)actor->ObjectKind, dataId); return check
? CreateOwned(new ByteString(owner->GameObject.Name), owner->HomeWorld, (ObjectKind)actor->ObjectKind, dataId)
: CreateIndividualUnchecked(IdentifierType.Owned, new ByteString(owner->GameObject.Name), owner->HomeWorld,
(ObjectKind)actor->ObjectKind, dataId);
} }
default: return ActorIdentifier.Invalid; default: return ActorIdentifier.Invalid;
} }
@ -187,8 +202,8 @@ public partial class ActorManager
}; };
} }
public unsafe ActorIdentifier FromObject(GameObject? actor) public unsafe ActorIdentifier FromObject(GameObject? actor, bool check = true)
=> FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(actor?.Address ?? IntPtr.Zero)); => FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(actor?.Address ?? IntPtr.Zero), check);
public ActorIdentifier CreateIndividual(IdentifierType type, ByteString name, ushort homeWorld, ObjectKind kind, uint dataId) public ActorIdentifier CreateIndividual(IdentifierType type, ByteString name, ushort homeWorld, ObjectKind kind, uint dataId)
=> type switch => type switch

View file

@ -76,10 +76,10 @@ public sealed partial class IndividualCollections : IReadOnlyList< (string Displ
} }
public bool TryGetCollection( GameObject? gameObject, out ModCollection? collection ) public bool TryGetCollection( GameObject? gameObject, out ModCollection? collection )
=> TryGetCollection( _actorManager.FromObject( gameObject ), out collection ); => TryGetCollection( _actorManager.FromObject( gameObject, false ), out collection );
public unsafe bool TryGetCollection( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* gameObject, out ModCollection? collection ) public unsafe bool TryGetCollection( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* gameObject, out ModCollection? collection )
=> TryGetCollection( _actorManager.FromObject( gameObject ), out collection ); => TryGetCollection( _actorManager.FromObject( gameObject, false ), out collection );
private bool CheckWorlds( ActorIdentifier identifier, out ModCollection? collection ) private bool CheckWorlds( ActorIdentifier identifier, out ModCollection? collection )
{ {

View file

@ -8,7 +8,6 @@ using FFXIVClientStructs.FFXIV.Client.Game.Object;
using Penumbra.Api; using Penumbra.Api;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Classes; using OtterGui.Classes;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.String.Classes; using Penumbra.String.Classes;

View file

@ -38,7 +38,7 @@ public unsafe partial class PathResolver
} }
else else
{ {
var identifier = Penumbra.Actors.FromObject( gameObject ); var identifier = Penumbra.Actors.FromObject( gameObject, false );
var collection = CollectionByIdentifier( identifier ) var collection = CollectionByIdentifier( identifier )
?? CheckYourself( identifier, gameObject ) ?? CheckYourself( identifier, gameObject )
?? CollectionByAttributes( gameObject ) ?? CollectionByAttributes( gameObject )

View file

@ -190,7 +190,7 @@ public partial class ConfigWindow
{ {
ImGuiUtil.DrawTableColumn( $"{( ( GameObject* )obj.Address )->ObjectIndex}" ); ImGuiUtil.DrawTableColumn( $"{( ( GameObject* )obj.Address )->ObjectIndex}" );
ImGuiUtil.DrawTableColumn( $"0x{obj.Address:X}" ); ImGuiUtil.DrawTableColumn( $"0x{obj.Address:X}" );
var identifier = Penumbra.Actors.FromObject( obj ); var identifier = Penumbra.Actors.FromObject( obj, true );
ImGuiUtil.DrawTableColumn( Penumbra.Actors.ToString( identifier ) ); ImGuiUtil.DrawTableColumn( Penumbra.Actors.ToString( identifier ) );
ImGuiUtil.DrawTableColumn( identifier.DataId.ToString() ); ImGuiUtil.DrawTableColumn( identifier.DataId.ToString() );
} }