mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Convert PartyMember to readonly struct
This commit is contained in:
parent
d1dc81318a
commit
53b94caeb7
2 changed files with 62 additions and 48 deletions
|
|
@ -8,6 +8,7 @@ using Dalamud.IoC.Internal;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
|
|
||||||
using CSGroupManager = FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager;
|
using CSGroupManager = FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager;
|
||||||
|
using CSPartyMember = FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember;
|
||||||
|
|
||||||
namespace Dalamud.Game.ClientState.Party;
|
namespace Dalamud.Game.ClientState.Party;
|
||||||
|
|
||||||
|
|
@ -42,20 +43,20 @@ internal sealed unsafe partial class PartyList : IServiceType, IPartyList
|
||||||
public bool IsAlliance => this.GroupManagerStruct->MainGroup.AllianceFlags > 0;
|
public bool IsAlliance => this.GroupManagerStruct->MainGroup.AllianceFlags > 0;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public unsafe IntPtr GroupManagerAddress => (nint)CSGroupManager.Instance();
|
public unsafe nint GroupManagerAddress => (nint)CSGroupManager.Instance();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IntPtr GroupListAddress => (IntPtr)Unsafe.AsPointer(ref GroupManagerStruct->MainGroup.PartyMembers[0]);
|
public nint GroupListAddress => (nint)Unsafe.AsPointer(ref GroupManagerStruct->MainGroup.PartyMembers[0]);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IntPtr AllianceListAddress => (IntPtr)Unsafe.AsPointer(ref this.GroupManagerStruct->MainGroup.AllianceMembers[0]);
|
public nint AllianceListAddress => (nint)Unsafe.AsPointer(ref this.GroupManagerStruct->MainGroup.AllianceMembers[0]);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public long PartyId => this.GroupManagerStruct->MainGroup.PartyId;
|
public long PartyId => this.GroupManagerStruct->MainGroup.PartyId;
|
||||||
|
|
||||||
private static int PartyMemberSize { get; } = Marshal.SizeOf<FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember>();
|
private static int PartyMemberSize { get; } = Marshal.SizeOf<CSPartyMember>();
|
||||||
|
|
||||||
private FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager* GroupManagerStruct => (FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager*)this.GroupManagerAddress;
|
private CSGroupManager* GroupManagerStruct => (CSGroupManager*)this.GroupManagerAddress;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IPartyMember? this[int index]
|
public IPartyMember? this[int index]
|
||||||
|
|
@ -80,45 +81,45 @@ internal sealed unsafe partial class PartyList : IServiceType, IPartyList
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IntPtr GetPartyMemberAddress(int index)
|
public nint GetPartyMemberAddress(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= GroupLength)
|
if (index < 0 || index >= GroupLength)
|
||||||
return IntPtr.Zero;
|
return 0;
|
||||||
|
|
||||||
return this.GroupListAddress + (index * PartyMemberSize);
|
return this.GroupListAddress + (index * PartyMemberSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IPartyMember? CreatePartyMemberReference(IntPtr address)
|
public IPartyMember? CreatePartyMemberReference(nint address)
|
||||||
{
|
{
|
||||||
if (this.clientState.LocalContentId == 0)
|
if (this.clientState.LocalContentId == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (address == IntPtr.Zero)
|
if (address == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new PartyMember(address);
|
return new PartyMember((CSPartyMember*)address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IntPtr GetAllianceMemberAddress(int index)
|
public nint GetAllianceMemberAddress(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= AllianceLength)
|
if (index < 0 || index >= AllianceLength)
|
||||||
return IntPtr.Zero;
|
return 0;
|
||||||
|
|
||||||
return this.AllianceListAddress + (index * PartyMemberSize);
|
return this.AllianceListAddress + (index * PartyMemberSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IPartyMember? CreateAllianceMemberReference(IntPtr address)
|
public IPartyMember? CreateAllianceMemberReference(nint address)
|
||||||
{
|
{
|
||||||
if (this.clientState.LocalContentId == 0)
|
if (this.clientState.LocalContentId == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (address == IntPtr.Zero)
|
if (address == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new PartyMember(address);
|
return new PartyMember((CSPartyMember*)address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Game.ClientState.Objects;
|
using Dalamud.Game.ClientState.Objects;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Dalamud.Game.ClientState.Statuses;
|
using Dalamud.Game.ClientState.Statuses;
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Memory;
|
|
||||||
|
|
||||||
using Lumina.Excel;
|
using Lumina.Excel;
|
||||||
|
|
||||||
|
using CSPartyMember = FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember;
|
||||||
|
|
||||||
namespace Dalamud.Game.ClientState.Party;
|
namespace Dalamud.Game.ClientState.Party;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface representing a party member.
|
/// Interface representing a party member.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPartyMember
|
public interface IPartyMember : IEquatable<IPartyMember>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the address of this party member in memory.
|
/// Gets the address of this party member in memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IntPtr Address { get; }
|
nint Address { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of buffs or debuffs applied to this party member.
|
/// Gets a list of buffs or debuffs applied to this party member.
|
||||||
|
|
@ -108,69 +109,81 @@ public interface IPartyMember
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class represents a party member in the group manager.
|
/// This struct represents a party member in the group manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal unsafe class PartyMember : IPartyMember
|
/// <param name="ptr">A pointer to the PartyMember.</param>
|
||||||
|
internal unsafe readonly struct PartyMember(CSPartyMember* ptr) : IPartyMember
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc/>
|
||||||
/// Initializes a new instance of the <see cref="PartyMember"/> class.
|
public nint Address => (nint)ptr;
|
||||||
/// </summary>
|
|
||||||
/// <param name="address">Address of the party member.</param>
|
|
||||||
internal PartyMember(IntPtr address)
|
|
||||||
{
|
|
||||||
this.Address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IntPtr Address { get; }
|
public StatusList Statuses => new(&ptr->StatusManager);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public StatusList Statuses => new(&this.Struct->StatusManager);
|
public Vector3 Position => ptr->Position;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public Vector3 Position => this.Struct->Position;
|
public long ContentId => (long)ptr->ContentId;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public long ContentId => (long)this.Struct->ContentId;
|
public uint ObjectId => ptr->EntityId;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public uint ObjectId => this.Struct->EntityId;
|
public uint EntityId => ptr->EntityId;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public uint EntityId => this.Struct->EntityId;
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IGameObject? GameObject => Service<ObjectTable>.Get().SearchById(this.EntityId);
|
public IGameObject? GameObject => Service<ObjectTable>.Get().SearchById(this.EntityId);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public uint CurrentHP => this.Struct->CurrentHP;
|
public uint CurrentHP => ptr->CurrentHP;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public uint MaxHP => this.Struct->MaxHP;
|
public uint MaxHP => ptr->MaxHP;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ushort CurrentMP => this.Struct->CurrentMP;
|
public ushort CurrentMP => ptr->CurrentMP;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ushort MaxMP => this.Struct->MaxMP;
|
public ushort MaxMP => ptr->MaxMP;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public RowRef<Lumina.Excel.Sheets.TerritoryType> Territory => LuminaUtils.CreateRef<Lumina.Excel.Sheets.TerritoryType>(this.Struct->TerritoryType);
|
public RowRef<Lumina.Excel.Sheets.TerritoryType> Territory => LuminaUtils.CreateRef<Lumina.Excel.Sheets.TerritoryType>(ptr->TerritoryType);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public RowRef<Lumina.Excel.Sheets.World> World => LuminaUtils.CreateRef<Lumina.Excel.Sheets.World>(this.Struct->HomeWorld);
|
public RowRef<Lumina.Excel.Sheets.World> World => LuminaUtils.CreateRef<Lumina.Excel.Sheets.World>(ptr->HomeWorld);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public SeString Name => SeString.Parse(this.Struct->Name);
|
public SeString Name => SeString.Parse(ptr->Name);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public byte Sex => this.Struct->Sex;
|
public byte Sex => ptr->Sex;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public RowRef<Lumina.Excel.Sheets.ClassJob> ClassJob => LuminaUtils.CreateRef<Lumina.Excel.Sheets.ClassJob>(this.Struct->ClassJob);
|
public RowRef<Lumina.Excel.Sheets.ClassJob> ClassJob => LuminaUtils.CreateRef<Lumina.Excel.Sheets.ClassJob>(ptr->ClassJob);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public byte Level => this.Struct->Level;
|
public byte Level => ptr->Level;
|
||||||
|
|
||||||
private FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember*)this.Address;
|
public static bool operator ==(PartyMember x, PartyMember y) => x.Equals(y);
|
||||||
|
|
||||||
|
public static bool operator !=(PartyMember x, PartyMember y) => !(x == y);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool Equals(IPartyMember? other)
|
||||||
|
{
|
||||||
|
return this.EntityId == other.EntityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||||
|
{
|
||||||
|
return obj is PartyMember fate && this.Equals(fate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.EntityId.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue