Add IPartyList (#1271)

This commit is contained in:
MidoriKami 2023-06-24 20:59:37 -07:00 committed by GitHub
parent aacfe4d679
commit 852d68f326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 48 deletions

View file

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
using Serilog; using Serilog;
namespace Dalamud.Game.ClientState.Party; namespace Dalamud.Game.ClientState.Party;
@ -15,7 +16,10 @@ namespace Dalamud.Game.ClientState.Party;
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService] [ServiceManager.BlockingEarlyLoadedService]
public sealed unsafe partial class PartyList : IServiceType #pragma warning disable SA1015
[ResolveVia<IPartyList>]
#pragma warning restore SA1015
public sealed unsafe partial class PartyList : IServiceType, IPartyList
{ {
private const int GroupLength = 8; private const int GroupLength = 8;
private const int AllianceLength = 20; private const int AllianceLength = 20;
@ -33,50 +37,32 @@ public sealed unsafe partial class PartyList : IServiceType
Log.Verbose($"Group manager address 0x{this.address.GroupManager.ToInt64():X}"); Log.Verbose($"Group manager address 0x{this.address.GroupManager.ToInt64():X}");
} }
/// <summary> /// <inheritdoc/>
/// Gets the amount of party members the local player has.
/// </summary>
public int Length => this.GroupManagerStruct->MemberCount; public int Length => this.GroupManagerStruct->MemberCount;
/// <summary> /// <inheritdoc/>
/// Gets the index of the party leader.
/// </summary>
public uint PartyLeaderIndex => this.GroupManagerStruct->PartyLeaderIndex; public uint PartyLeaderIndex => this.GroupManagerStruct->PartyLeaderIndex;
/// <summary> /// <inheritdoc/>
/// Gets a value indicating whether this group is an alliance.
/// </summary>
public bool IsAlliance => this.GroupManagerStruct->AllianceFlags > 0; public bool IsAlliance => this.GroupManagerStruct->AllianceFlags > 0;
/// <summary> /// <inheritdoc/>
/// Gets the address of the Group Manager.
/// </summary>
public IntPtr GroupManagerAddress => this.address.GroupManager; public IntPtr GroupManagerAddress => this.address.GroupManager;
/// <summary> /// <inheritdoc/>
/// Gets the address of the party list within the group manager.
/// </summary>
public IntPtr GroupListAddress => (IntPtr)GroupManagerStruct->PartyMembers; public IntPtr GroupListAddress => (IntPtr)GroupManagerStruct->PartyMembers;
/// <summary> /// <inheritdoc/>
/// Gets the address of the alliance member list within the group manager.
/// </summary>
public IntPtr AllianceListAddress => (IntPtr)this.GroupManagerStruct->AllianceMembers; public IntPtr AllianceListAddress => (IntPtr)this.GroupManagerStruct->AllianceMembers;
/// <summary> /// <inheritdoc/>
/// Gets the ID of the party.
/// </summary>
public long PartyId => this.GroupManagerStruct->PartyId; public long PartyId => this.GroupManagerStruct->PartyId;
private static int PartyMemberSize { get; } = Marshal.SizeOf<FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember>(); private static int PartyMemberSize { get; } = Marshal.SizeOf<FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember>();
private FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager* GroupManagerStruct => (FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager*)this.GroupManagerAddress; private FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager* GroupManagerStruct => (FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager*)this.GroupManagerAddress;
/// <summary> /// <inheritdoc/>
/// Get a party member at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>A <see cref="PartyMember"/> at the specified spawn index.</returns>
public PartyMember? this[int index] public PartyMember? this[int index]
{ {
get get
@ -98,11 +84,7 @@ public sealed unsafe partial class PartyList : IServiceType
} }
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the party member at the specified index of the party list.
/// </summary>
/// <param name="index">The index of the party member.</param>
/// <returns>The memory address of the party member.</returns>
public IntPtr GetPartyMemberAddress(int index) public IntPtr GetPartyMemberAddress(int index)
{ {
if (index < 0 || index >= GroupLength) if (index < 0 || index >= GroupLength)
@ -111,11 +93,7 @@ public sealed unsafe partial class PartyList : IServiceType
return this.GroupListAddress + (index * PartyMemberSize); return this.GroupListAddress + (index * PartyMemberSize);
} }
/// <summary> /// <inheritdoc/>
/// Create a reference to an FFXIV party member.
/// </summary>
/// <param name="address">The address of the party member in memory.</param>
/// <returns>The party member object containing the requested data.</returns>
public PartyMember? CreatePartyMemberReference(IntPtr address) public PartyMember? CreatePartyMemberReference(IntPtr address)
{ {
if (this.clientState.LocalContentId == 0) if (this.clientState.LocalContentId == 0)
@ -127,11 +105,7 @@ public sealed unsafe partial class PartyList : IServiceType
return new PartyMember(address); return new PartyMember(address);
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the alliance member at the specified index of the alliance list.
/// </summary>
/// <param name="index">The index of the alliance member.</param>
/// <returns>The memory address of the alliance member.</returns>
public IntPtr GetAllianceMemberAddress(int index) public IntPtr GetAllianceMemberAddress(int index)
{ {
if (index < 0 || index >= AllianceLength) if (index < 0 || index >= AllianceLength)
@ -140,11 +114,7 @@ public sealed unsafe partial class PartyList : IServiceType
return this.AllianceListAddress + (index * PartyMemberSize); return this.AllianceListAddress + (index * PartyMemberSize);
} }
/// <summary> /// <inheritdoc/>
/// Create a reference to an FFXIV alliance member.
/// </summary>
/// <param name="address">The address of the alliance member in memory.</param>
/// <returns>The party member object containing the requested data.</returns>
public PartyMember? CreateAllianceMemberReference(IntPtr address) public PartyMember? CreateAllianceMemberReference(IntPtr address)
{ {
if (this.clientState.LocalContentId == 0) if (this.clientState.LocalContentId == 0)
@ -160,7 +130,7 @@ public sealed unsafe partial class PartyList : IServiceType
/// <summary> /// <summary>
/// This collection represents the party members present in your party or alliance. /// This collection represents the party members present in your party or alliance.
/// </summary> /// </summary>
public sealed partial class PartyList : IReadOnlyCollection<PartyMember> public sealed partial class PartyList
{ {
/// <inheritdoc/> /// <inheritdoc/>
int IReadOnlyCollection<PartyMember>.Count => this.Length; int IReadOnlyCollection<PartyMember>.Count => this.Length;

View file

@ -0,0 +1,81 @@
using System.Collections.Generic;
using Dalamud.Game.ClientState.Party;
namespace Dalamud.Plugin.Services;
/// <summary>
/// This collection represents the actors present in your party or alliance.
/// </summary>
public interface IPartyList : IReadOnlyCollection<PartyMember>
{
/// <summary>
/// Gets the amount of party members the local player has.
/// </summary>
public int Length { get; }
/// <summary>
/// Gets the index of the party leader.
/// </summary>
public uint PartyLeaderIndex { get; }
/// <summary>
/// Gets a value indicating whether this group is an alliance.
/// </summary>
public bool IsAlliance { get; }
/// <summary>
/// Gets the address of the Group Manager.
/// </summary>
public nint GroupManagerAddress { get; }
/// <summary>
/// Gets the address of the party list within the group manager.
/// </summary>
public nint GroupListAddress { get; }
/// <summary>
/// Gets the address of the alliance member list within the group manager.
/// </summary>
public nint AllianceListAddress { get; }
/// <summary>
/// Gets the ID of the party.
/// </summary>
public long PartyId { get; }
/// <summary>
/// Get a party member at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>A <see cref="PartyMember"/> at the specified spawn index.</returns>
public PartyMember? this[int index] { get; }
/// <summary>
/// Gets the address of the party member at the specified index of the party list.
/// </summary>
/// <param name="index">The index of the party member.</param>
/// <returns>The memory address of the party member.</returns>
public nint GetPartyMemberAddress(int index);
/// <summary>
/// Create a reference to an FFXIV party member.
/// </summary>
/// <param name="address">The address of the party member in memory.</param>
/// <returns>The party member object containing the requested data.</returns>
public PartyMember? CreatePartyMemberReference(nint address);
/// <summary>
/// Gets the address of the alliance member at the specified index of the alliance list.
/// </summary>
/// <param name="index">The index of the alliance member.</param>
/// <returns>The memory address of the alliance member.</returns>
public nint GetAllianceMemberAddress(int index);
/// <summary>
/// Create a reference to an FFXIV alliance member.
/// </summary>
/// <param name="address">The address of the alliance member in memory.</param>
/// <returns>The party member object containing the requested data.</returns>
public PartyMember? CreateAllianceMemberReference(nint address);
}