diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index 2275345a5..8745931b8 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -97,6 +97,11 @@ namespace Dalamud.Game.ClientState /// public Condition Condition; + /// + /// The class facilitating target data access + /// + public Targets Targets; + /// /// Set up client state access. /// @@ -121,6 +126,8 @@ namespace Dalamud.Game.ClientState this.Condition = new Condition( Address ); + this.Targets = new Targets(dalamud, Address); + Log.Verbose("SetupTerritoryType address {SetupTerritoryType}", Address.SetupTerritoryType); this.setupTerritoryTypeHook = new Hook(Address.SetupTerritoryType, diff --git a/Dalamud/Game/ClientState/ClientStateAddressResolver.cs b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs index e858ac6fc..9787cb7ee 100644 --- a/Dalamud/Game/ClientState/ClientStateAddressResolver.cs +++ b/Dalamud/Game/ClientState/ClientStateAddressResolver.cs @@ -10,6 +10,7 @@ namespace Dalamud.Game.ClientState public IntPtr LocalContentId { get; private set; } public IntPtr JobGaugeData { get; private set; } public IntPtr KeyboardState { get; private set; } + public IntPtr TargetManager { get; private set; } // Functions public IntPtr SetupTerritoryType { get; private set; } @@ -35,6 +36,8 @@ namespace Dalamud.Game.ClientState PartyListUpdate = sig.ScanText("E8 ?? ?? ?? ?? 49 8B D4 4C 8D 87 ?? ?? ?? ??"); ConditionFlags = sig.GetStaticAddressFromSig("48 8D 0D ?? ?? ?? ?? BA ?? ?? ?? ?? 45 33 C0"); + + TargetManager = sig.GetStaticAddressFromSig("48 8B 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? FF 50 ?? 48 85 DB", 3); } } } diff --git a/Dalamud/Game/ClientState/Targets.cs b/Dalamud/Game/ClientState/Targets.cs new file mode 100644 index 000000000..0046093b5 --- /dev/null +++ b/Dalamud/Game/ClientState/Targets.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; +using Dalamud.Game.ClientState.Actors.Types; + +namespace Dalamud.Game.ClientState { + public sealed class Targets { + private ClientStateAddressResolver Address { get; } + private Dalamud dalamud; + + public Actor CurrentTarget => GetActorByOffset(0x80); + public Actor MouseOverTarget => GetActorByOffset(0xD0); + public Actor FocusTarget => GetActorByOffset(0xF8); + public Actor PreviousTarget => GetActorByOffset(0x110); + + internal Targets(Dalamud dalamud, ClientStateAddressResolver addressResolver) { + this.dalamud = dalamud; + Address = addressResolver; + } + + private Actor GetActorByOffset(int offset) { + if (Address.TargetManager == IntPtr.Zero) return null; + var actorAddress = Marshal.ReadIntPtr(Address.TargetManager + offset); + if (actorAddress == IntPtr.Zero) return null; + var data = Marshal.PtrToStructure(actorAddress); + return new Actor(actorAddress, data, this.dalamud); + } + } +}