mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 13:14:17 +01:00
Target Info Change
casting actors to the right type methods for changing targets
This commit is contained in:
parent
d9c8eeedd3
commit
469fecf484
3 changed files with 49 additions and 29 deletions
|
|
@ -60,7 +60,7 @@ namespace Dalamud.Game.ClientState.Actors {
|
|||
get => ActorsCache[index];
|
||||
}
|
||||
|
||||
private Actor ReadActorFromMemory(IntPtr offset)
|
||||
internal Actor ReadActorFromMemory(IntPtr offset)
|
||||
{
|
||||
try {
|
||||
var actorStruct = Marshal.PtrToStructure<Structs.Actor>(offset);
|
||||
|
|
|
|||
48
Dalamud/Game/ClientState/Actors/Targets.cs
Normal file
48
Dalamud/Game/ClientState/Actors/Targets.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
|
||||
namespace Dalamud.Game.ClientState.Actors {
|
||||
public static class TargetOffsets {
|
||||
public const int CurrentTarget = 0x80;
|
||||
public const int MouseOverTarget = 0xD0;
|
||||
public const int FocusTarget = 0xF8;
|
||||
public const int PreviousTarget = 0x110;
|
||||
}
|
||||
|
||||
public sealed class Targets {
|
||||
private ClientStateAddressResolver Address { get; }
|
||||
private Dalamud dalamud;
|
||||
|
||||
public Actor CurrentTarget => GetActorByOffset(TargetOffsets.CurrentTarget);
|
||||
public Actor MouseOverTarget => GetActorByOffset(TargetOffsets.MouseOverTarget);
|
||||
public Actor FocusTarget => GetActorByOffset(TargetOffsets.FocusTarget);
|
||||
public Actor PreviousTarget => GetActorByOffset(TargetOffsets.PreviousTarget);
|
||||
|
||||
internal Targets(Dalamud dalamud, ClientStateAddressResolver addressResolver) {
|
||||
this.dalamud = dalamud;
|
||||
Address = addressResolver;
|
||||
}
|
||||
|
||||
public void SetCurrentTarget(Actor actor) => SetTarget(actor?.Address ?? IntPtr.Zero, TargetOffsets.CurrentTarget);
|
||||
public void SetCurrentTarget(IntPtr actorAddress) => SetTarget(actorAddress, TargetOffsets.CurrentTarget);
|
||||
|
||||
public void SetFocusTarget(Actor actor) => SetTarget(actor?.Address ?? IntPtr.Zero, TargetOffsets.FocusTarget);
|
||||
public void SetFocusTarget(IntPtr actorAddress) => SetTarget(actorAddress, TargetOffsets.FocusTarget);
|
||||
|
||||
public void ClearCurrentTarget() => SetCurrentTarget(IntPtr.Zero);
|
||||
public void ClearFocusTarget() => SetFocusTarget(IntPtr.Zero);
|
||||
|
||||
private void SetTarget(IntPtr actorAddress, int offset) {
|
||||
if (Address.TargetManager == IntPtr.Zero) return;
|
||||
Marshal.WriteIntPtr(Address.TargetManager, offset, actorAddress);
|
||||
}
|
||||
|
||||
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;
|
||||
return this.dalamud.ClientState.Actors.ReadActorFromMemory(actorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
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<Structs.Actor>(actorAddress);
|
||||
return new Actor(actorAddress, data, this.dalamud);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue