From 852d68f32682aca47717af65c0c03d06e506c0da Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 20:59:37 -0700 Subject: [PATCH] Add IPartyList (#1271) --- Dalamud/Game/ClientState/Party/PartyList.cs | 66 +++++------------ Dalamud/Plugin/Services/IPartyList.cs | 81 +++++++++++++++++++++ 2 files changed, 99 insertions(+), 48 deletions(-) create mode 100644 Dalamud/Plugin/Services/IPartyList.cs diff --git a/Dalamud/Game/ClientState/Party/PartyList.cs b/Dalamud/Game/ClientState/Party/PartyList.cs index 80fe7d41f..529b57b6f 100644 --- a/Dalamud/Game/ClientState/Party/PartyList.cs +++ b/Dalamud/Game/ClientState/Party/PartyList.cs @@ -5,6 +5,7 @@ using System.Runtime.InteropServices; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Serilog; namespace Dalamud.Game.ClientState.Party; @@ -15,7 +16,10 @@ namespace Dalamud.Game.ClientState.Party; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed unsafe partial class PartyList : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed unsafe partial class PartyList : IServiceType, IPartyList { private const int GroupLength = 8; 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}"); } - /// - /// Gets the amount of party members the local player has. - /// + /// public int Length => this.GroupManagerStruct->MemberCount; - /// - /// Gets the index of the party leader. - /// + /// public uint PartyLeaderIndex => this.GroupManagerStruct->PartyLeaderIndex; - /// - /// Gets a value indicating whether this group is an alliance. - /// + /// public bool IsAlliance => this.GroupManagerStruct->AllianceFlags > 0; - /// - /// Gets the address of the Group Manager. - /// + /// public IntPtr GroupManagerAddress => this.address.GroupManager; - /// - /// Gets the address of the party list within the group manager. - /// + /// public IntPtr GroupListAddress => (IntPtr)GroupManagerStruct->PartyMembers; - /// - /// Gets the address of the alliance member list within the group manager. - /// + /// public IntPtr AllianceListAddress => (IntPtr)this.GroupManagerStruct->AllianceMembers; - /// - /// Gets the ID of the party. - /// + /// public long PartyId => this.GroupManagerStruct->PartyId; private static int PartyMemberSize { get; } = Marshal.SizeOf(); private FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager* GroupManagerStruct => (FFXIVClientStructs.FFXIV.Client.Game.Group.GroupManager*)this.GroupManagerAddress; - /// - /// Get a party member at the specified spawn index. - /// - /// Spawn index. - /// A at the specified spawn index. + /// public PartyMember? this[int index] { get @@ -98,11 +84,7 @@ public sealed unsafe partial class PartyList : IServiceType } } - /// - /// Gets the address of the party member at the specified index of the party list. - /// - /// The index of the party member. - /// The memory address of the party member. + /// public IntPtr GetPartyMemberAddress(int index) { if (index < 0 || index >= GroupLength) @@ -111,11 +93,7 @@ public sealed unsafe partial class PartyList : IServiceType return this.GroupListAddress + (index * PartyMemberSize); } - /// - /// Create a reference to an FFXIV party member. - /// - /// The address of the party member in memory. - /// The party member object containing the requested data. + /// public PartyMember? CreatePartyMemberReference(IntPtr address) { if (this.clientState.LocalContentId == 0) @@ -127,11 +105,7 @@ public sealed unsafe partial class PartyList : IServiceType return new PartyMember(address); } - /// - /// Gets the address of the alliance member at the specified index of the alliance list. - /// - /// The index of the alliance member. - /// The memory address of the alliance member. + /// public IntPtr GetAllianceMemberAddress(int index) { if (index < 0 || index >= AllianceLength) @@ -140,11 +114,7 @@ public sealed unsafe partial class PartyList : IServiceType return this.AllianceListAddress + (index * PartyMemberSize); } - /// - /// Create a reference to an FFXIV alliance member. - /// - /// The address of the alliance member in memory. - /// The party member object containing the requested data. + /// public PartyMember? CreateAllianceMemberReference(IntPtr address) { if (this.clientState.LocalContentId == 0) @@ -160,7 +130,7 @@ public sealed unsafe partial class PartyList : IServiceType /// /// This collection represents the party members present in your party or alliance. /// -public sealed partial class PartyList : IReadOnlyCollection +public sealed partial class PartyList { /// int IReadOnlyCollection.Count => this.Length; diff --git a/Dalamud/Plugin/Services/IPartyList.cs b/Dalamud/Plugin/Services/IPartyList.cs new file mode 100644 index 000000000..fbf663a00 --- /dev/null +++ b/Dalamud/Plugin/Services/IPartyList.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; + +using Dalamud.Game.ClientState.Party; + +namespace Dalamud.Plugin.Services; + +/// +/// This collection represents the actors present in your party or alliance. +/// +public interface IPartyList : IReadOnlyCollection +{ + /// + /// Gets the amount of party members the local player has. + /// + public int Length { get; } + + /// + /// Gets the index of the party leader. + /// + public uint PartyLeaderIndex { get; } + + /// + /// Gets a value indicating whether this group is an alliance. + /// + public bool IsAlliance { get; } + + /// + /// Gets the address of the Group Manager. + /// + public nint GroupManagerAddress { get; } + + /// + /// Gets the address of the party list within the group manager. + /// + public nint GroupListAddress { get; } + + /// + /// Gets the address of the alliance member list within the group manager. + /// + public nint AllianceListAddress { get; } + + /// + /// Gets the ID of the party. + /// + public long PartyId { get; } + + /// + /// Get a party member at the specified spawn index. + /// + /// Spawn index. + /// A at the specified spawn index. + public PartyMember? this[int index] { get; } + + /// + /// Gets the address of the party member at the specified index of the party list. + /// + /// The index of the party member. + /// The memory address of the party member. + public nint GetPartyMemberAddress(int index); + + /// + /// Create a reference to an FFXIV party member. + /// + /// The address of the party member in memory. + /// The party member object containing the requested data. + public PartyMember? CreatePartyMemberReference(nint address); + + /// + /// Gets the address of the alliance member at the specified index of the alliance list. + /// + /// The index of the alliance member. + /// The memory address of the alliance member. + public nint GetAllianceMemberAddress(int index); + + /// + /// Create a reference to an FFXIV alliance member. + /// + /// The address of the alliance member in memory. + /// The party member object containing the requested data. + public PartyMember? CreateAllianceMemberReference(nint address); +}