From fe46fd33dc0d74e54d445c6ae44bd9804c078d89 Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 23:55:18 -0700 Subject: [PATCH] Add ITargetManager (#1277) Co-authored-by: goat <16760685+goaaats@users.noreply.github.com> --- .../Game/ClientState/Objects/TargetManager.cs | 44 +++++++++++-------- Dalamud/Plugin/Services/ITargetManager.cs | 44 +++++++++++++++++++ 2 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 Dalamud/Plugin/Services/ITargetManager.cs diff --git a/Dalamud/Game/ClientState/Objects/TargetManager.cs b/Dalamud/Game/ClientState/Objects/TargetManager.cs index ccd89e6a3..c4c1e3822 100644 --- a/Dalamud/Game/ClientState/Objects/TargetManager.cs +++ b/Dalamud/Game/ClientState/Objects/TargetManager.cs @@ -12,7 +12,10 @@ namespace Dalamud.Game.ClientState.Objects; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed unsafe class TargetManager : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed unsafe class TargetManager : IServiceType, ITargetManager { [ServiceManager.ServiceDependency] private readonly ClientState clientState = Service.Get(); @@ -28,50 +31,38 @@ public sealed unsafe class TargetManager : IServiceType this.address = this.clientState.AddressResolver; } - /// - /// Gets the address of the target manager. - /// + /// public IntPtr Address => this.address.TargetManager; - /// - /// Gets or sets the current target. - /// + /// public GameObject? Target { get => this.objectTable.CreateObjectReference((IntPtr)Struct->Target); set => this.SetTarget(value); } - /// - /// Gets or sets the mouseover target. - /// + /// public GameObject? MouseOverTarget { get => this.objectTable.CreateObjectReference((IntPtr)Struct->MouseOverTarget); set => this.SetMouseOverTarget(value); } - /// - /// Gets or sets the focus target. - /// + /// public GameObject? FocusTarget { get => this.objectTable.CreateObjectReference((IntPtr)Struct->FocusTarget); set => this.SetFocusTarget(value); } - /// - /// Gets or sets the previous target. - /// + /// public GameObject? PreviousTarget { get => this.objectTable.CreateObjectReference((IntPtr)Struct->PreviousTarget); set => this.SetPreviousTarget(value); } - /// - /// Gets or sets the soft target. - /// + /// public GameObject? SoftTarget { get => this.objectTable.CreateObjectReference((IntPtr)Struct->SoftTarget); @@ -84,84 +75,99 @@ public sealed unsafe class TargetManager : IServiceType /// Sets the current target. /// /// Actor to target. + [Obsolete("Use Target Property", false)] public void SetTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); /// /// Sets the mouseover target. /// /// Actor to target. + [Obsolete("Use MouseOverTarget Property", false)] public void SetMouseOverTarget(GameObject? actor) => this.SetMouseOverTarget(actor?.Address ?? IntPtr.Zero); /// /// Sets the focus target. /// /// Actor to target. + [Obsolete("Use FocusTarget Property", false)] public void SetFocusTarget(GameObject? actor) => this.SetFocusTarget(actor?.Address ?? IntPtr.Zero); /// /// Sets the previous target. /// /// Actor to target. + [Obsolete("Use PreviousTarget Property", false)] public void SetPreviousTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); /// /// Sets the soft target. /// /// Actor to target. + [Obsolete("Use SoftTarget Property", false)] public void SetSoftTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); /// /// Sets the current target. /// /// Actor (address) to target. + [Obsolete("Use Target Property", false)] public void SetTarget(IntPtr actorAddress) => Struct->Target = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; /// /// Sets the mouseover target. /// /// Actor (address) to target. + [Obsolete("Use MouseOverTarget Property", false)] public void SetMouseOverTarget(IntPtr actorAddress) => Struct->MouseOverTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; /// /// Sets the focus target. /// /// Actor (address) to target. + [Obsolete("Use FocusTarget Property", false)] public void SetFocusTarget(IntPtr actorAddress) => Struct->FocusTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; /// /// Sets the previous target. /// /// Actor (address) to target. + [Obsolete("Use PreviousTarget Property", false)] public void SetPreviousTarget(IntPtr actorAddress) => Struct->PreviousTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; /// /// Sets the soft target. /// /// Actor (address) to target. + [Obsolete("Use SoftTarget Property", false)] public void SetSoftTarget(IntPtr actorAddress) => Struct->SoftTarget = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)actorAddress; /// /// Clears the current target. /// + [Obsolete("Use Target Property", false)] public void ClearTarget() => this.SetTarget(IntPtr.Zero); /// /// Clears the mouseover target. /// + [Obsolete("Use MouseOverTarget Property", false)] public void ClearMouseOverTarget() => this.SetMouseOverTarget(IntPtr.Zero); /// /// Clears the focus target. /// + [Obsolete("Use FocusTarget Property", false)] public void ClearFocusTarget() => this.SetFocusTarget(IntPtr.Zero); /// /// Clears the previous target. /// + [Obsolete("Use PreviousTarget Property", false)] public void ClearPreviousTarget() => this.SetPreviousTarget(IntPtr.Zero); /// /// Clears the soft target. /// + [Obsolete("Use SoftTarget Property", false)] public void ClearSoftTarget() => this.SetSoftTarget(IntPtr.Zero); } diff --git a/Dalamud/Plugin/Services/ITargetManager.cs b/Dalamud/Plugin/Services/ITargetManager.cs new file mode 100644 index 000000000..108b1ca03 --- /dev/null +++ b/Dalamud/Plugin/Services/ITargetManager.cs @@ -0,0 +1,44 @@ +using Dalamud.Game.ClientState.Objects.Types; + +namespace Dalamud.Game.ClientState.Objects; + +/// +/// Get and set various kinds of targets for the player. +/// +public interface ITargetManager +{ + /// + /// Gets the address of the target manager. + /// + public nint Address { get; } + + /// + /// Gets or sets the current target. + /// Set to null to clear the target. + /// + public GameObject? Target { get; set; } + + /// + /// Gets or sets the mouseover target. + /// Set to null to clear the target. + /// + public GameObject? MouseOverTarget { get; set; } + + /// + /// Gets or sets the focus target. + /// Set to null to clear the target. + /// + public GameObject? FocusTarget { get; set; } + + /// + /// Gets or sets the previous target. + /// Set to null to clear the target. + /// + public GameObject? PreviousTarget { get; set; } + + /// + /// Gets or sets the soft target. + /// Set to null to clear the target. + /// + public GameObject? SoftTarget { get; set; } +}