Actor formatting, updates for resolvers

This commit is contained in:
Raymond 2021-07-15 14:28:57 -04:00
parent c1755d4bf8
commit 976688a924
4 changed files with 27 additions and 20 deletions

View file

@ -17,6 +17,7 @@ namespace Dalamud.Game.ClientState.Actors
private const int ActorTableLength = 424;
private readonly Dalamud dalamud;
private readonly ClientStateAddressResolver address;
/// <summary>
/// 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>
internal ActorTable(Dalamud dalamud, ClientStateAddressResolver addressResolver)
{
this.Address = addressResolver;
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>
@ -52,13 +53,11 @@ namespace Dalamud.Game.ClientState.Actors
}
}
private ClientStateAddressResolver Address { get; }
/// <summary>
/// Get an actor at the specified spawn index.
/// </summary>
/// <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]
public Actor this[int index]
{
@ -73,7 +72,7 @@ namespace Dalamud.Game.ClientState.Actors
/// Get an actor at the specified address.
/// </summary>
/// <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]
{
get
@ -93,11 +92,9 @@ namespace Dalamud.Game.ClientState.Actors
public unsafe IntPtr GetActorAddress(int index)
{
if (index >= ActorTableLength)
{
return IntPtr.Zero;
}
return *(IntPtr*)(this.Address.ActorTable + (8 * index));
return *(IntPtr*)(this.address.ActorTable + (8 * index));
}
/// <summary>
@ -109,12 +106,12 @@ namespace Dalamud.Game.ClientState.Actors
internal unsafe Actor CreateActorReference(IntPtr offset)
{
if (this.dalamud.ClientState.LocalContentId == 0)
{
return null;
}
if (offset == IntPtr.Zero)
return null;
var objKind = *(ObjectKind*)(offset + ActorOffsets.ObjectKind);
return objKind switch
{
ObjectKind.Player => new PlayerCharacter(offset, this.dalamud),

View file

@ -40,6 +40,16 @@ namespace Dalamud.Game.ClientState.Actors.Types
/// <returns>True or false.</returns>
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>
/// Gets a value indicating whether this actor is still valid in memory.
/// </summary>
@ -69,7 +79,7 @@ namespace Dalamud.Game.ClientState.Actors.Types
public override bool Equals(object obj) => ((IEquatable<Actor>)this).Equals(obj as Actor);
/// <inheritdoc/>
public override int GetHashCode() => base.GetHashCode();
public override int GetHashCode() => this.ActorId.GetHashCode();
}
/// <summary>

View file

@ -1,6 +1,6 @@
using System;
using Dalamud.Game.ClientState.Actors.Resolvers;
using Dalamud.Game.ClientState.Resolvers;
using Dalamud.Game.ClientState.Structs;
using Dalamud.Memory;
@ -65,7 +65,7 @@ namespace Dalamud.Game.ClientState.Actors.Types
/// <summary>
/// Gets the ClassJob of this Chara.
/// </summary>
public ClassJob ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
public ClassJobResolver ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
/// <summary>
/// Gets the level of this Chara.

View file

@ -1,6 +1,6 @@
using System;
using Dalamud.Game.ClientState.Actors.Resolvers;
using Dalamud.Game.ClientState.Resolvers;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Memory;
@ -23,14 +23,14 @@ namespace Dalamud.Game.ClientState.Actors.Types
}
/// <summary>
/// Gets the current <see cref="World">world</see> of the character.
/// Gets the current <see cref="WorldResolver">world</see> of the character.
/// </summary>
public World CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
public WorldResolver CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
/// <summary>
/// Gets the home <see cref="World">world</see> of the character.
/// Gets the home <see cref="WorldResolver">world</see> of the character.
/// </summary>
public World HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
public WorldResolver HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
/// <summary>
/// Gets the Free Company tag of this player.