Add IBuddyList (#1261)

This commit is contained in:
MidoriKami 2023-06-24 17:11:17 -07:00 committed by GitHub
parent a7202096bf
commit ac74bd5fe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 34 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.Buddy; namespace Dalamud.Game.ClientState.Buddy;
@ -16,7 +17,10 @@ namespace Dalamud.Game.ClientState.Buddy;
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService] [ServiceManager.BlockingEarlyLoadedService]
public sealed partial class BuddyList : IServiceType #pragma warning disable SA1015
[ResolveVia<IBuddyList>]
#pragma warning restore SA1015
public sealed partial class BuddyList : IServiceType, IBuddyList
{ {
private const uint InvalidObjectID = 0xE0000000; 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}"); Log.Verbose($"Buddy list address 0x{this.address.BuddyList.ToInt64():X}");
} }
/// <summary> /// <inheritdoc/>
/// Gets the amount of battle buddies the local player has.
/// </summary>
public int Length public int Length
{ {
get get
@ -56,16 +58,16 @@ public sealed partial class BuddyList : IServiceType
/// <summary> /// <summary>
/// Gets a value indicating whether the local player's companion is present. /// Gets a value indicating whether the local player's companion is present.
/// </summary> /// </summary>
[Obsolete("Use CompanionBuddy != null", false)]
public bool CompanionBuddyPresent => this.CompanionBuddy != null; public bool CompanionBuddyPresent => this.CompanionBuddy != null;
/// <summary> /// <summary>
/// Gets a value indicating whether the local player's pet is present. /// Gets a value indicating whether the local player's pet is present.
/// </summary> /// </summary>
[Obsolete("Use PetBuddy != null", false)]
public bool PetBuddyPresent => this.PetBuddy != null; public bool PetBuddyPresent => this.PetBuddy != null;
/// <summary> /// <inheritdoc/>
/// Gets the active companion buddy.
/// </summary>
public BuddyMember? CompanionBuddy public BuddyMember? CompanionBuddy
{ {
get get
@ -75,9 +77,7 @@ public sealed partial class BuddyList : IServiceType
} }
} }
/// <summary> /// <inheritdoc/>
/// Gets the active pet buddy.
/// </summary>
public BuddyMember? PetBuddy public BuddyMember? PetBuddy
{ {
get 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; private unsafe FFXIVClientStructs.FFXIV.Client.Game.UI.Buddy* BuddyListStruct => (FFXIVClientStructs.FFXIV.Client.Game.UI.Buddy*)this.BuddyListAddress;
/// <summary> /// <inheritdoc/>
/// Gets a battle buddy at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>A <see cref="BuddyMember"/> at the specified spawn index.</returns>
public BuddyMember? this[int index] public BuddyMember? this[int index]
{ {
get get
@ -110,29 +106,19 @@ public sealed partial class BuddyList : IServiceType
} }
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the companion buddy.
/// </summary>
/// <returns>The memory address of the companion buddy.</returns>
public unsafe IntPtr GetCompanionBuddyMemberAddress() public unsafe IntPtr GetCompanionBuddyMemberAddress()
{ {
return (IntPtr)(&this.BuddyListStruct->Companion); return (IntPtr)(&this.BuddyListStruct->Companion);
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the pet buddy.
/// </summary>
/// <returns>The memory address of the pet buddy.</returns>
public unsafe IntPtr GetPetBuddyMemberAddress() public unsafe IntPtr GetPetBuddyMemberAddress()
{ {
return (IntPtr)(&this.BuddyListStruct->Pet); return (IntPtr)(&this.BuddyListStruct->Pet);
} }
/// <summary> /// <inheritdoc/>
/// Gets the address of the battle buddy at the specified index of the buddy list.
/// </summary>
/// <param name="index">The index of the battle buddy.</param>
/// <returns>The memory address of the battle buddy.</returns>
public unsafe IntPtr GetBattleBuddyMemberAddress(int index) public unsafe IntPtr GetBattleBuddyMemberAddress(int index)
{ {
if (index < 0 || index >= 3) if (index < 0 || index >= 3)
@ -141,11 +127,7 @@ public sealed partial class BuddyList : IServiceType
return (IntPtr)(this.BuddyListStruct->BattleBuddies + (index * BuddyMemberSize)); return (IntPtr)(this.BuddyListStruct->BattleBuddies + (index * BuddyMemberSize));
} }
/// <summary> /// <inheritdoc/>
/// Create a reference to a buddy.
/// </summary>
/// <param name="address">The address of the buddy in memory.</param>
/// <returns><see cref="BuddyMember"/> object containing the requested data.</returns>
public BuddyMember? CreateBuddyMemberReference(IntPtr address) public BuddyMember? CreateBuddyMemberReference(IntPtr address)
{ {
if (this.clientState.LocalContentId == 0) if (this.clientState.LocalContentId == 0)
@ -165,7 +147,7 @@ public sealed partial class BuddyList : IServiceType
/// <summary> /// <summary>
/// This collection represents the buddies present in your squadron or trust party. /// This collection represents the buddies present in your squadron or trust party.
/// </summary> /// </summary>
public sealed partial class BuddyList : IReadOnlyCollection<BuddyMember> public sealed partial class BuddyList
{ {
/// <inheritdoc/> /// <inheritdoc/>
int IReadOnlyCollection<BuddyMember>.Count => this.Length; int IReadOnlyCollection<BuddyMember>.Count => this.Length;

View file

@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Dalamud.Game.ClientState.Buddy;
namespace Dalamud.Plugin.Services;
/// <summary>
/// This collection represents the buddies present in your squadron or trust party.
/// It does not include the local player.
/// </summary>
public interface IBuddyList : IReadOnlyCollection<BuddyMember>
{
/// <summary>
/// Gets the amount of battle buddies the local player has.
/// </summary>
public int Length { get; }
/// <summary>
/// Gets the active companion buddy.
/// </summary>
public BuddyMember? CompanionBuddy { get; }
/// <summary>
/// Gets the active pet buddy.
/// </summary>
public BuddyMember? PetBuddy { get; }
/// <summary>
/// Gets a battle buddy at the specified spawn index.
/// </summary>
/// <param name="index">Spawn index.</param>
/// <returns>A <see cref="BuddyMember"/> at the specified spawn index.</returns>
public BuddyMember? this[int index] { get; }
/// <summary>
/// Gets the address of the companion buddy.
/// </summary>
/// <returns>The memory address of the companion buddy.</returns>
public nint GetCompanionBuddyMemberAddress();
/// <summary>
/// Gets the address of the pet buddy.
/// </summary>
/// <returns>The memory address of the pet buddy.</returns>
public nint GetPetBuddyMemberAddress();
/// <summary>
/// Gets the address of the battle buddy at the specified index of the buddy list.
/// </summary>
/// <param name="index">The index of the battle buddy.</param>
/// <returns>The memory address of the battle buddy.</returns>
public nint GetBattleBuddyMemberAddress(int index);
/// <summary>
/// Create a reference to a buddy.
/// </summary>
/// <param name="address">The address of the buddy in memory.</param>
/// <returns><see cref="BuddyMember"/> object containing the requested data.</returns>
public BuddyMember? CreateBuddyMemberReference(nint address);
}