From ac74bd5fe02f01be00ed77bddf0bbfa652ae36a7 Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 17:11:17 -0700 Subject: [PATCH] Add IBuddyList (#1261) --- Dalamud/Game/ClientState/Buddy/BuddyList.cs | 50 ++++++----------- Dalamud/Plugin/Services/IBuddyList.cs | 61 +++++++++++++++++++++ 2 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 Dalamud/Plugin/Services/IBuddyList.cs diff --git a/Dalamud/Game/ClientState/Buddy/BuddyList.cs b/Dalamud/Game/ClientState/Buddy/BuddyList.cs index 4c8de5586..dc2cb9fae 100644 --- a/Dalamud/Game/ClientState/Buddy/BuddyList.cs +++ b/Dalamud/Game/ClientState/Buddy/BuddyList.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.Buddy; @@ -16,7 +17,10 @@ namespace Dalamud.Game.ClientState.Buddy; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed partial class BuddyList : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed partial class BuddyList : IServiceType, IBuddyList { private const uint InvalidObjectID = 0xE0000000; @@ -33,9 +37,7 @@ public sealed partial class BuddyList : IServiceType Log.Verbose($"Buddy list address 0x{this.address.BuddyList.ToInt64():X}"); } - /// - /// Gets the amount of battle buddies the local player has. - /// + /// public int Length { get @@ -56,16 +58,16 @@ public sealed partial class BuddyList : IServiceType /// /// Gets a value indicating whether the local player's companion is present. /// + [Obsolete("Use CompanionBuddy != null", false)] public bool CompanionBuddyPresent => this.CompanionBuddy != null; /// /// Gets a value indicating whether the local player's pet is present. /// + [Obsolete("Use PetBuddy != null", false)] public bool PetBuddyPresent => this.PetBuddy != null; - /// - /// Gets the active companion buddy. - /// + /// public BuddyMember? CompanionBuddy { get @@ -75,9 +77,7 @@ public sealed partial class BuddyList : IServiceType } } - /// - /// Gets the active pet buddy. - /// + /// public BuddyMember? PetBuddy { get @@ -96,11 +96,7 @@ public sealed partial class BuddyList : IServiceType private unsafe FFXIVClientStructs.FFXIV.Client.Game.UI.Buddy* BuddyListStruct => (FFXIVClientStructs.FFXIV.Client.Game.UI.Buddy*)this.BuddyListAddress; - /// - /// Gets a battle buddy at the specified spawn index. - /// - /// Spawn index. - /// A at the specified spawn index. + /// public BuddyMember? this[int index] { get @@ -110,29 +106,19 @@ public sealed partial class BuddyList : IServiceType } } - /// - /// Gets the address of the companion buddy. - /// - /// The memory address of the companion buddy. + /// public unsafe IntPtr GetCompanionBuddyMemberAddress() { return (IntPtr)(&this.BuddyListStruct->Companion); } - /// - /// Gets the address of the pet buddy. - /// - /// The memory address of the pet buddy. + /// public unsafe IntPtr GetPetBuddyMemberAddress() { return (IntPtr)(&this.BuddyListStruct->Pet); } - /// - /// Gets the address of the battle buddy at the specified index of the buddy list. - /// - /// The index of the battle buddy. - /// The memory address of the battle buddy. + /// public unsafe IntPtr GetBattleBuddyMemberAddress(int index) { if (index < 0 || index >= 3) @@ -141,11 +127,7 @@ public sealed partial class BuddyList : IServiceType return (IntPtr)(this.BuddyListStruct->BattleBuddies + (index * BuddyMemberSize)); } - /// - /// Create a reference to a buddy. - /// - /// The address of the buddy in memory. - /// object containing the requested data. + /// public BuddyMember? CreateBuddyMemberReference(IntPtr address) { if (this.clientState.LocalContentId == 0) @@ -165,7 +147,7 @@ public sealed partial class BuddyList : IServiceType /// /// This collection represents the buddies present in your squadron or trust party. /// -public sealed partial class BuddyList : IReadOnlyCollection +public sealed partial class BuddyList { /// int IReadOnlyCollection.Count => this.Length; diff --git a/Dalamud/Plugin/Services/IBuddyList.cs b/Dalamud/Plugin/Services/IBuddyList.cs new file mode 100644 index 000000000..f273d71c9 --- /dev/null +++ b/Dalamud/Plugin/Services/IBuddyList.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +using Dalamud.Game.ClientState.Buddy; + +namespace Dalamud.Plugin.Services; + +/// +/// This collection represents the buddies present in your squadron or trust party. +/// It does not include the local player. +/// +public interface IBuddyList : IReadOnlyCollection +{ + /// + /// Gets the amount of battle buddies the local player has. + /// + public int Length { get; } + + /// + /// Gets the active companion buddy. + /// + public BuddyMember? CompanionBuddy { get; } + + /// + /// Gets the active pet buddy. + /// + public BuddyMember? PetBuddy { get; } + + /// + /// Gets a battle buddy at the specified spawn index. + /// + /// Spawn index. + /// A at the specified spawn index. + public BuddyMember? this[int index] { get; } + + /// + /// Gets the address of the companion buddy. + /// + /// The memory address of the companion buddy. + public nint GetCompanionBuddyMemberAddress(); + + /// + /// Gets the address of the pet buddy. + /// + /// The memory address of the pet buddy. + public nint GetPetBuddyMemberAddress(); + + /// + /// Gets the address of the battle buddy at the specified index of the buddy list. + /// + /// The index of the battle buddy. + /// The memory address of the battle buddy. + public nint GetBattleBuddyMemberAddress(int index); + + /// + /// Create a reference to a buddy. + /// + /// The address of the buddy in memory. + /// object containing the requested data. + public BuddyMember? CreateBuddyMemberReference(nint address); +}