Fix issue with assigning indexed npcs.

This commit is contained in:
Ottermandias 2023-03-05 14:52:28 +01:00
parent 009499cdf6
commit 64c8f29c47
9 changed files with 31 additions and 29 deletions

View file

@ -256,7 +256,7 @@ public sealed partial class ActorManager : IDisposable
return false; return false;
} }
id = FromObject(&other->GameObject, out _, false, true); id = FromObject(&other->GameObject, out _, false, true, false);
return true; return true;
} }
@ -283,7 +283,7 @@ public sealed partial class ActorManager : IDisposable
if (obj != null if (obj != null
&& obj->ObjectKind is (byte)ObjectKind.Player && obj->ObjectKind is (byte)ObjectKind.Player
&& Compare(gameObject, (Character*)obj)) && Compare(gameObject, (Character*)obj))
return FromObject(obj, out _, false, true); return FromObject(obj, out _, false, true, false);
} }
return ActorIdentifier.Invalid; return ActorIdentifier.Invalid;

View file

@ -244,7 +244,7 @@ public partial class ActorManager
/// Compute an ActorIdentifier from a GameObject. If check is true, the values are checked for validity. /// 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,
out FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* owner, bool allowPlayerNpc, bool check) out FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* owner, bool allowPlayerNpc, bool check, bool withoutIndex)
{ {
owner = null; owner = null;
if (actor == null) if (actor == null)
@ -298,9 +298,10 @@ public partial class ActorManager
} }
} }
var index = withoutIndex ? ushort.MaxValue : actor->ObjectIndex;
return check return check
? CreateNpc(ObjectKind.BattleNpc, nameId, actor->ObjectIndex) ? CreateNpc(ObjectKind.BattleNpc, nameId, index)
: CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, actor->ObjectIndex, ObjectKind.BattleNpc, nameId); : CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, index, ObjectKind.BattleNpc, nameId);
} }
case ObjectKind.EventNpc: case ObjectKind.EventNpc:
{ {
@ -326,9 +327,10 @@ public partial class ActorManager
} }
} }
var index = withoutIndex ? ushort.MaxValue : actor->ObjectIndex;
return check return check
? CreateNpc(ObjectKind.EventNpc, dataId, actor->ObjectIndex) ? CreateNpc(ObjectKind.EventNpc, dataId, index)
: CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, actor->ObjectIndex, ObjectKind.EventNpc, dataId); : CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, index, ObjectKind.EventNpc, dataId);
} }
case ObjectKind.MountType: case ObjectKind.MountType:
case ObjectKind.Companion: case ObjectKind.Companion:
@ -357,7 +359,7 @@ public partial class ActorManager
default: default:
{ {
var name = new ByteString(actor->Name); var name = new ByteString(actor->Name);
var index = actor->ObjectIndex; var index = withoutIndex ? ushort.MaxValue : actor->ObjectIndex;
return CreateIndividualUnchecked(IdentifierType.UnkObject, name, index, ObjectKind.None, 0); return CreateIndividualUnchecked(IdentifierType.UnkObject, name, index, ObjectKind.None, 0);
} }
} }
@ -379,12 +381,12 @@ public partial class ActorManager
} }
public unsafe ActorIdentifier FromObject(GameObject? actor, out FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* owner, public unsafe ActorIdentifier FromObject(GameObject? actor, out FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* owner,
bool allowPlayerNpc, bool check) bool allowPlayerNpc, bool check, bool withoutIndex)
=> FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(actor?.Address ?? IntPtr.Zero), out owner, allowPlayerNpc, => FromObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(actor?.Address ?? IntPtr.Zero), out owner, allowPlayerNpc,
check); check, withoutIndex);
public unsafe ActorIdentifier FromObject(GameObject? actor, bool allowPlayerNpc, bool check) public unsafe ActorIdentifier FromObject(GameObject? actor, bool allowPlayerNpc, bool check, bool withoutIndex)
=> FromObject(actor, out _, allowPlayerNpc, check); => FromObject(actor, out _, allowPlayerNpc, check, withoutIndex);
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
@ -551,13 +553,13 @@ public partial class ActorManager
=> actor is >= ScreenActor.CharacterScreen and <= ScreenActor.Card8; => actor is >= ScreenActor.CharacterScreen and <= ScreenActor.Card8;
/// <summary> Verify that the object index is a valid index for an NPC. </summary> /// <summary> Verify that the object index is a valid index for an NPC. </summary>
public static bool VerifyIndex(ushort index) public bool VerifyIndex(ushort index)
{ {
return index switch return index switch
{ {
ushort.MaxValue => true, ushort.MaxValue => true,
< 200 => index % 2 == 0, < 200 => index % 2 == 0,
> (ushort)ScreenActor.Card8 => index < 426, > (ushort)ScreenActor.Card8 => index < _objects.Length,
_ => false, _ => false,
}; };
} }

View file

@ -848,7 +848,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
return PenumbraApiEc.InvalidArgument; return PenumbraApiEc.InvalidArgument;
} }
var identifier = Penumbra.Actors.FromObject( Dalamud.Objects[ actorIndex ], false, false ); var identifier = Penumbra.Actors.FromObject( Dalamud.Objects[ actorIndex ], false, false, true );
if( !identifier.IsValid ) if( !identifier.IsValid )
{ {
return PenumbraApiEc.InvalidArgument; return PenumbraApiEc.InvalidArgument;
@ -1042,7 +1042,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
} }
var ptr = ( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* )Dalamud.Objects.GetObjectAddress( gameObjectIdx ); var ptr = ( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* )Dalamud.Objects.GetObjectAddress( gameObjectIdx );
return Penumbra.Actors.FromObject( ptr, out _, false, true ); return Penumbra.Actors.FromObject( ptr, out _, false, true, true );
} }
// Resolve a path given by string for a specific collection. // Resolve a path given by string for a specific collection.

View file

@ -143,10 +143,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, true, false ), out collection ); => TryGetCollection( _actorManager.FromObject( gameObject, true, false, 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 _, true, false ), out collection ); => TryGetCollection( _actorManager.FromObject( gameObject, out _, true, false, false ), out collection );
private bool CheckWorlds( ActorIdentifier identifier, out ModCollection? collection ) private bool CheckWorlds( ActorIdentifier identifier, out ModCollection? collection )
{ {

View file

@ -47,7 +47,7 @@ public readonly struct ResolveData
try try
{ {
var id = Penumbra.Actors.FromObject( ( GameObject* )AssociatedGameObject, out _, false, true ); var id = Penumbra.Actors.FromObject( ( GameObject* )AssociatedGameObject, out _, false, true, true );
if( id.IsValid ) if( id.IsValid )
{ {
var name = id.ToString(); var name = id.ToString();

View file

@ -297,7 +297,7 @@ public class CommandHandler : IDisposable
{ {
if( ObjectReloader.GetName( split[ 2 ].ToLowerInvariant(), out var obj ) ) if( ObjectReloader.GetName( split[ 2 ].ToLowerInvariant(), out var obj ) )
{ {
identifier = _actors.FromObject( obj, false, true ); identifier = _actors.FromObject( obj, false, true, true );
if( !identifier.IsValid ) if( !identifier.IsValid )
{ {
Dalamud.Chat.Print( new SeStringBuilder().AddText( "The placeholder " ).AddGreen( split[ 2 ] ) Dalamud.Chat.Print( new SeStringBuilder().AddText( "The placeholder " ).AddGreen( split[ 2 ] )

View file

@ -56,7 +56,7 @@ public unsafe partial class PathResolver
return IdentifiedCache.Set( collection2, ActorIdentifier.Invalid, gameObject ); return IdentifiedCache.Set( collection2, ActorIdentifier.Invalid, gameObject );
} }
var identifier = Penumbra.Actors.FromObject( gameObject, out var owner, true, false ); var identifier = Penumbra.Actors.FromObject( gameObject, out var owner, true, false, false );
if( identifier.Type is IdentifierType.Special ) if( identifier.Type is IdentifierType.Special )
{ {
( identifier, var type ) = Penumbra.CollectionManager.Individuals.ConvertSpecialIdentifier( identifier ); ( identifier, var type ) = Penumbra.CollectionManager.Individuals.ConvertSpecialIdentifier( identifier );

View file

@ -243,10 +243,10 @@ public partial class ConfigWindow
var buttonWidth1 = new Vector2( 90 * ImGuiHelpers.GlobalScale, 0 ); var buttonWidth1 = new Vector2( 90 * ImGuiHelpers.GlobalScale, 0 );
var buttonWidth2 = new Vector2( 120 * ImGuiHelpers.GlobalScale, 0 ); var buttonWidth2 = new Vector2( 120 * ImGuiHelpers.GlobalScale, 0 );
var assignWidth = new Vector2((_window._inputTextWidth.X - ImGui.GetStyle().ItemSpacing.X) / 2, 0); var assignWidth = new Vector2( ( _window._inputTextWidth.X - ImGui.GetStyle().ItemSpacing.X ) / 2, 0 );
var change = DrawNewCurrentPlayerCollection(assignWidth); var change = DrawNewCurrentPlayerCollection( assignWidth );
ImGui.SameLine(); ImGui.SameLine();
change |= DrawNewTargetCollection(assignWidth); change |= DrawNewTargetCollection( assignWidth );
change |= DrawNewPlayerCollection( buttonWidth1, width ); change |= DrawNewPlayerCollection( buttonWidth1, width );
ImGui.SameLine(); ImGui.SameLine();
@ -263,7 +263,7 @@ public partial class ConfigWindow
} }
} }
private static bool DrawNewCurrentPlayerCollection(Vector2 width) private static bool DrawNewCurrentPlayerCollection( Vector2 width )
{ {
var player = Penumbra.Actors.GetCurrentPlayer(); var player = Penumbra.Actors.GetCurrentPlayer();
var result = Penumbra.CollectionManager.Individuals.CanAdd( player ); var result = Penumbra.CollectionManager.Individuals.CanAdd( player );
@ -285,10 +285,10 @@ public partial class ConfigWindow
return false; return false;
} }
private static bool DrawNewTargetCollection(Vector2 width) private static bool DrawNewTargetCollection( Vector2 width )
{ {
var target = Dalamud.Targets.Target; var target = Dalamud.Targets.Target;
var player = Penumbra.Actors.FromObject( target, false, true ); var player = Penumbra.Actors.FromObject( target, false, true, true );
var result = Penumbra.CollectionManager.Individuals.CanAdd( player ); var result = Penumbra.CollectionManager.Individuals.CanAdd( player );
var tt = result switch var tt = result switch
{ {
@ -299,7 +299,7 @@ public partial class ConfigWindow
}; };
if( ImGuiUtil.DrawDisabledButton( "Assign Current Target", width, tt, result != IndividualCollections.AddResult.Valid ) ) if( ImGuiUtil.DrawDisabledButton( "Assign Current Target", width, tt, result != IndividualCollections.AddResult.Valid ) )
{ {
Penumbra.CollectionManager.Individuals.Add( new[] { player }, Penumbra.CollectionManager.Default ); Penumbra.CollectionManager.Individuals.Add( Penumbra.CollectionManager.Individuals.GetGroup( player ), Penumbra.CollectionManager.Default );
return true; return true;
} }

View file

@ -215,7 +215,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, false, true ); var identifier = Penumbra.Actors.FromObject( obj, false, true, false );
ImGuiUtil.DrawTableColumn( Penumbra.Actors.ToString( identifier ) ); ImGuiUtil.DrawTableColumn( Penumbra.Actors.ToString( identifier ) );
var id = obj.ObjectKind == ObjectKind.BattleNpc ? $"{identifier.DataId} | {obj.DataId}" : identifier.DataId.ToString(); var id = obj.ObjectKind == ObjectKind.BattleNpc ? $"{identifier.DataId} | {obj.DataId}" : identifier.DataId.ToString();
ImGuiUtil.DrawTableColumn( id ); ImGuiUtil.DrawTableColumn( id );