Add ITargetManager (#1277)

Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
MidoriKami 2023-06-24 23:55:18 -07:00 committed by GitHub
parent 8f971934f3
commit fe46fd33dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 19 deletions

View file

@ -12,7 +12,10 @@ namespace Dalamud.Game.ClientState.Objects;
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService] [ServiceManager.BlockingEarlyLoadedService]
public sealed unsafe class TargetManager : IServiceType #pragma warning disable SA1015
[ResolveVia<ITargetManager>]
#pragma warning restore SA1015
public sealed unsafe class TargetManager : IServiceType, ITargetManager
{ {
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly ClientState clientState = Service<ClientState>.Get(); private readonly ClientState clientState = Service<ClientState>.Get();
@ -28,50 +31,38 @@ public sealed unsafe class TargetManager : IServiceType
this.address = this.clientState.AddressResolver; this.address = this.clientState.AddressResolver;
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the target manager.
/// </summary>
public IntPtr Address => this.address.TargetManager; public IntPtr Address => this.address.TargetManager;
/// <summary> /// <inheritdoc/>
/// Gets or sets the current target.
/// </summary>
public GameObject? Target public GameObject? Target
{ {
get => this.objectTable.CreateObjectReference((IntPtr)Struct->Target); get => this.objectTable.CreateObjectReference((IntPtr)Struct->Target);
set => this.SetTarget(value); set => this.SetTarget(value);
} }
/// <summary> /// <inheritdoc/>
/// Gets or sets the mouseover target.
/// </summary>
public GameObject? MouseOverTarget public GameObject? MouseOverTarget
{ {
get => this.objectTable.CreateObjectReference((IntPtr)Struct->MouseOverTarget); get => this.objectTable.CreateObjectReference((IntPtr)Struct->MouseOverTarget);
set => this.SetMouseOverTarget(value); set => this.SetMouseOverTarget(value);
} }
/// <summary> /// <inheritdoc/>
/// Gets or sets the focus target.
/// </summary>
public GameObject? FocusTarget public GameObject? FocusTarget
{ {
get => this.objectTable.CreateObjectReference((IntPtr)Struct->FocusTarget); get => this.objectTable.CreateObjectReference((IntPtr)Struct->FocusTarget);
set => this.SetFocusTarget(value); set => this.SetFocusTarget(value);
} }
/// <summary> /// <inheritdoc/>
/// Gets or sets the previous target.
/// </summary>
public GameObject? PreviousTarget public GameObject? PreviousTarget
{ {
get => this.objectTable.CreateObjectReference((IntPtr)Struct->PreviousTarget); get => this.objectTable.CreateObjectReference((IntPtr)Struct->PreviousTarget);
set => this.SetPreviousTarget(value); set => this.SetPreviousTarget(value);
} }
/// <summary> /// <inheritdoc/>
/// Gets or sets the soft target.
/// </summary>
public GameObject? SoftTarget public GameObject? SoftTarget
{ {
get => this.objectTable.CreateObjectReference((IntPtr)Struct->SoftTarget); get => this.objectTable.CreateObjectReference((IntPtr)Struct->SoftTarget);
@ -84,84 +75,99 @@ public sealed unsafe class TargetManager : IServiceType
/// Sets the current target. /// Sets the current target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
[Obsolete("Use Target Property", false)]
public void SetTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the mouseover target. /// Sets the mouseover target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
[Obsolete("Use MouseOverTarget Property", false)]
public void SetMouseOverTarget(GameObject? actor) => this.SetMouseOverTarget(actor?.Address ?? IntPtr.Zero); public void SetMouseOverTarget(GameObject? actor) => this.SetMouseOverTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the focus target. /// Sets the focus target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
[Obsolete("Use FocusTarget Property", false)]
public void SetFocusTarget(GameObject? actor) => this.SetFocusTarget(actor?.Address ?? IntPtr.Zero); public void SetFocusTarget(GameObject? actor) => this.SetFocusTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the previous target. /// Sets the previous target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
[Obsolete("Use PreviousTarget Property", false)]
public void SetPreviousTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetPreviousTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the soft target. /// Sets the soft target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
[Obsolete("Use SoftTarget Property", false)]
public void SetSoftTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetSoftTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the current target. /// Sets the current target.
/// </summary> /// </summary>
/// <param name="actorAddress">Actor (address) to target.</param> /// <param name="actorAddress">Actor (address) to target.</param>
[Obsolete("Use Target Property", false)]
public void SetTarget(IntPtr actorAddress) => Struct->Target = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; public void SetTarget(IntPtr actorAddress) => Struct->Target = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress;
/// <summary> /// <summary>
/// Sets the mouseover target. /// Sets the mouseover target.
/// </summary> /// </summary>
/// <param name="actorAddress">Actor (address) to target.</param> /// <param name="actorAddress">Actor (address) to target.</param>
[Obsolete("Use MouseOverTarget Property", false)]
public void SetMouseOverTarget(IntPtr actorAddress) => Struct->MouseOverTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; public void SetMouseOverTarget(IntPtr actorAddress) => Struct->MouseOverTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress;
/// <summary> /// <summary>
/// Sets the focus target. /// Sets the focus target.
/// </summary> /// </summary>
/// <param name="actorAddress">Actor (address) to target.</param> /// <param name="actorAddress">Actor (address) to target.</param>
[Obsolete("Use FocusTarget Property", false)]
public void SetFocusTarget(IntPtr actorAddress) => Struct->FocusTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; public void SetFocusTarget(IntPtr actorAddress) => Struct->FocusTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress;
/// <summary> /// <summary>
/// Sets the previous target. /// Sets the previous target.
/// </summary> /// </summary>
/// <param name="actorAddress">Actor (address) to target.</param> /// <param name="actorAddress">Actor (address) to target.</param>
[Obsolete("Use PreviousTarget Property", false)]
public void SetPreviousTarget(IntPtr actorAddress) => Struct->PreviousTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; public void SetPreviousTarget(IntPtr actorAddress) => Struct->PreviousTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress;
/// <summary> /// <summary>
/// Sets the soft target. /// Sets the soft target.
/// </summary> /// </summary>
/// <param name="actorAddress">Actor (address) to target.</param> /// <param name="actorAddress">Actor (address) to target.</param>
[Obsolete("Use SoftTarget Property", false)]
public void SetSoftTarget(IntPtr actorAddress) => Struct->SoftTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; public void SetSoftTarget(IntPtr actorAddress) => Struct->SoftTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress;
/// <summary> /// <summary>
/// Clears the current target. /// Clears the current target.
/// </summary> /// </summary>
[Obsolete("Use Target Property", false)]
public void ClearTarget() => this.SetTarget(IntPtr.Zero); public void ClearTarget() => this.SetTarget(IntPtr.Zero);
/// <summary> /// <summary>
/// Clears the mouseover target. /// Clears the mouseover target.
/// </summary> /// </summary>
[Obsolete("Use MouseOverTarget Property", false)]
public void ClearMouseOverTarget() => this.SetMouseOverTarget(IntPtr.Zero); public void ClearMouseOverTarget() => this.SetMouseOverTarget(IntPtr.Zero);
/// <summary> /// <summary>
/// Clears the focus target. /// Clears the focus target.
/// </summary> /// </summary>
[Obsolete("Use FocusTarget Property", false)]
public void ClearFocusTarget() => this.SetFocusTarget(IntPtr.Zero); public void ClearFocusTarget() => this.SetFocusTarget(IntPtr.Zero);
/// <summary> /// <summary>
/// Clears the previous target. /// Clears the previous target.
/// </summary> /// </summary>
[Obsolete("Use PreviousTarget Property", false)]
public void ClearPreviousTarget() => this.SetPreviousTarget(IntPtr.Zero); public void ClearPreviousTarget() => this.SetPreviousTarget(IntPtr.Zero);
/// <summary> /// <summary>
/// Clears the soft target. /// Clears the soft target.
/// </summary> /// </summary>
[Obsolete("Use SoftTarget Property", false)]
public void ClearSoftTarget() => this.SetSoftTarget(IntPtr.Zero); public void ClearSoftTarget() => this.SetSoftTarget(IntPtr.Zero);
} }

View file

@ -0,0 +1,44 @@
using Dalamud.Game.ClientState.Objects.Types;
namespace Dalamud.Game.ClientState.Objects;
/// <summary>
/// Get and set various kinds of targets for the player.
/// </summary>
public interface ITargetManager
{
/// <summary>
/// Gets the address of the target manager.
/// </summary>
public nint Address { get; }
/// <summary>
/// Gets or sets the current target.
/// Set to null to clear the target.
/// </summary>
public GameObject? Target { get; set; }
/// <summary>
/// Gets or sets the mouseover target.
/// Set to null to clear the target.
/// </summary>
public GameObject? MouseOverTarget { get; set; }
/// <summary>
/// Gets or sets the focus target.
/// Set to null to clear the target.
/// </summary>
public GameObject? FocusTarget { get; set; }
/// <summary>
/// Gets or sets the previous target.
/// Set to null to clear the target.
/// </summary>
public GameObject? PreviousTarget { get; set; }
/// <summary>
/// Gets or sets the soft target.
/// Set to null to clear the target.
/// </summary>
public GameObject? SoftTarget { get; set; }
}