mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Actor formatting, updates for resolvers
This commit is contained in:
parent
c1755d4bf8
commit
976688a924
4 changed files with 27 additions and 20 deletions
|
|
@ -17,6 +17,7 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
private const int ActorTableLength = 424;
|
private const int ActorTableLength = 424;
|
||||||
|
|
||||||
private readonly Dalamud dalamud;
|
private readonly Dalamud dalamud;
|
||||||
|
private readonly ClientStateAddressResolver address;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ActorTable"/> class.
|
/// Initializes a new instance of the <see cref="ActorTable"/> class.
|
||||||
|
|
@ -25,10 +26,10 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
/// <param name="addressResolver">Client state address resolver.</param>
|
/// <param name="addressResolver">Client state address resolver.</param>
|
||||||
internal ActorTable(Dalamud dalamud, ClientStateAddressResolver addressResolver)
|
internal ActorTable(Dalamud dalamud, ClientStateAddressResolver addressResolver)
|
||||||
{
|
{
|
||||||
this.Address = addressResolver;
|
|
||||||
this.dalamud = dalamud;
|
this.dalamud = dalamud;
|
||||||
|
this.address = addressResolver;
|
||||||
|
|
||||||
Log.Verbose("Actor table address {ActorTable}", this.Address.ActorTable);
|
Log.Verbose($"Actor table address 0x{this.address.ActorTable.ToInt64():X}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -52,13 +53,11 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientStateAddressResolver Address { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get an actor at the specified spawn index.
|
/// Get an actor at the specified spawn index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">Spawn index.</param>
|
/// <param name="index">Spawn index.</param>
|
||||||
/// <returns>An <see cref="Actor" /> at the specified spawn index.</returns>
|
/// <returns>An <see cref="Actor"/> at the specified spawn index.</returns>
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
public Actor this[int index]
|
public Actor this[int index]
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +72,7 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
/// Get an actor at the specified address.
|
/// Get an actor at the specified address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="address">The actor address.</param>
|
/// <param name="address">The actor address.</param>
|
||||||
/// <returns>An <see cref="Actor" /> at the specified address.</returns>
|
/// <returns>An <see cref="Actor"/> at the specified address.</returns>
|
||||||
public Actor this[IntPtr address]
|
public Actor this[IntPtr address]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -93,11 +92,9 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
public unsafe IntPtr GetActorAddress(int index)
|
public unsafe IntPtr GetActorAddress(int index)
|
||||||
{
|
{
|
||||||
if (index >= ActorTableLength)
|
if (index >= ActorTableLength)
|
||||||
{
|
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
|
||||||
|
|
||||||
return *(IntPtr*)(this.Address.ActorTable + (8 * index));
|
return *(IntPtr*)(this.address.ActorTable + (8 * index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -109,12 +106,12 @@ namespace Dalamud.Game.ClientState.Actors
|
||||||
internal unsafe Actor CreateActorReference(IntPtr offset)
|
internal unsafe Actor CreateActorReference(IntPtr offset)
|
||||||
{
|
{
|
||||||
if (this.dalamud.ClientState.LocalContentId == 0)
|
if (this.dalamud.ClientState.LocalContentId == 0)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
if (offset == IntPtr.Zero)
|
||||||
|
return null;
|
||||||
|
|
||||||
var objKind = *(ObjectKind*)(offset + ActorOffsets.ObjectKind);
|
var objKind = *(ObjectKind*)(offset + ActorOffsets.ObjectKind);
|
||||||
|
|
||||||
return objKind switch
|
return objKind switch
|
||||||
{
|
{
|
||||||
ObjectKind.Player => new PlayerCharacter(offset, this.dalamud),
|
ObjectKind.Player => new PlayerCharacter(offset, this.dalamud),
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,16 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
||||||
/// <returns>True or false.</returns>
|
/// <returns>True or false.</returns>
|
||||||
public static implicit operator bool(Actor actor) => IsValid(actor);
|
public static implicit operator bool(Actor actor) => IsValid(actor);
|
||||||
|
|
||||||
|
public static bool operator ==(Actor actor1, Actor actor2)
|
||||||
|
{
|
||||||
|
if (actor1 is null || actor2 is null)
|
||||||
|
return Equals(actor1, actor2);
|
||||||
|
|
||||||
|
return actor1.Equals(actor2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Actor actor1, Actor actor2) => !(actor1 == actor2);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this actor is still valid in memory.
|
/// Gets a value indicating whether this actor is still valid in memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -69,7 +79,7 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
||||||
public override bool Equals(object obj) => ((IEquatable<Actor>)this).Equals(obj as Actor);
|
public override bool Equals(object obj) => ((IEquatable<Actor>)this).Equals(obj as Actor);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override int GetHashCode() => base.GetHashCode();
|
public override int GetHashCode() => this.ActorId.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Dalamud.Game.ClientState.Actors.Resolvers;
|
using Dalamud.Game.ClientState.Resolvers;
|
||||||
using Dalamud.Game.ClientState.Structs;
|
using Dalamud.Game.ClientState.Structs;
|
||||||
using Dalamud.Memory;
|
using Dalamud.Memory;
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ClassJob of this Chara.
|
/// Gets the ClassJob of this Chara.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ClassJob ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
|
public ClassJobResolver ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the level of this Chara.
|
/// Gets the level of this Chara.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Dalamud.Game.ClientState.Actors.Resolvers;
|
using Dalamud.Game.ClientState.Resolvers;
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Memory;
|
using Dalamud.Memory;
|
||||||
|
|
||||||
|
|
@ -23,14 +23,14 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current <see cref="World">world</see> of the character.
|
/// Gets the current <see cref="WorldResolver">world</see> of the character.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public World CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
|
public WorldResolver CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the home <see cref="World">world</see> of the character.
|
/// Gets the home <see cref="WorldResolver">world</see> of the character.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public World HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
|
public WorldResolver HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Free Company tag of this player.
|
/// Gets the Free Company tag of this player.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue