From d378fe1dfcb0255eaa03d0818d7025ce4cbaeb26 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Sun, 10 Sep 2023 15:20:44 -0700
Subject: [PATCH] Add IPartyFinderGui (v9) (#1279)
---
.../Game/Gui/PartyFinder/PartyFinderGui.cs | 52 +++++++++++++------
Dalamud/Plugin/Services/IPartyFinderGui.cs | 23 ++++++++
2 files changed, 59 insertions(+), 16 deletions(-)
create mode 100644 Dalamud/Plugin/Services/IPartyFinderGui.cs
diff --git a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs
index 6427f2a54..85c6a4a39 100644
--- a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs
+++ b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs
@@ -6,6 +6,7 @@ using Dalamud.Game.Gui.PartyFinder.Types;
using Dalamud.Hooking;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
+using Dalamud.Plugin.Services;
using Serilog;
namespace Dalamud.Game.Gui.PartyFinder;
@@ -13,10 +14,9 @@ namespace Dalamud.Game.Gui.PartyFinder;
///
/// This class handles interacting with the native PartyFinder window.
///
-[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService]
-public sealed class PartyFinderGui : IDisposable, IServiceType
+internal sealed class PartyFinderGui : IDisposable, IServiceType, IPartyFinderGui
{
private readonly PartyFinderAddressResolver address;
private readonly IntPtr memory;
@@ -35,25 +35,14 @@ public sealed class PartyFinderGui : IDisposable, IServiceType
this.memory = Marshal.AllocHGlobal(PartyFinderPacket.PacketSize);
- this.receiveListingHook = Hook.FromAddress(this.address.ReceiveListing, new ReceiveListingDelegate(this.HandleReceiveListingDetour));
+ this.receiveListingHook = Hook.FromAddress(this.address.ReceiveListing, this.HandleReceiveListingDetour);
}
- ///
- /// Event type fired each time the game receives an individual Party Finder listing.
- /// Cannot modify listings but can hide them.
- ///
- /// The listings received.
- /// Additional arguments passed by the game.
- public delegate void PartyFinderListingEventDelegate(PartyFinderListing listing, PartyFinderListingEventArgs args);
-
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate void ReceiveListingDelegate(IntPtr managerPtr, IntPtr data);
- ///
- /// Event fired each time the game receives an individual Party Finder listing.
- /// Cannot modify listings but can hide them.
- ///
- public event PartyFinderListingEventDelegate ReceiveListing;
+ ///
+ public event IPartyFinderGui.PartyFinderListingEventDelegate? ReceiveListing;
///
/// Dispose of managed and unmanaged resources.
@@ -138,3 +127,34 @@ public sealed class PartyFinderGui : IDisposable, IServiceType
}
}
}
+
+[PluginInterface]
+[InterfaceVersion("1.0")]
+[ServiceManager.ScopedService]
+#pragma warning disable SA1015
+[ResolveVia]
+#pragma warning restore SA1015
+internal class PartyFinderGuiPluginScoped : IDisposable, IServiceType, IPartyFinderGui
+{
+ [ServiceManager.ServiceDependency]
+ private readonly PartyFinderGui partyFinderGuiService = Service.Get();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ internal PartyFinderGuiPluginScoped()
+ {
+ this.partyFinderGuiService.ReceiveListing += this.ReceiveListingForward;
+ }
+
+ ///
+ public event IPartyFinderGui.PartyFinderListingEventDelegate? ReceiveListing;
+
+ ///
+ public void Dispose()
+ {
+ this.partyFinderGuiService.ReceiveListing -= this.ReceiveListingForward;
+ }
+
+ private void ReceiveListingForward(PartyFinderListing listing, PartyFinderListingEventArgs args) => this.ReceiveListing?.Invoke(listing, args);
+}
diff --git a/Dalamud/Plugin/Services/IPartyFinderGui.cs b/Dalamud/Plugin/Services/IPartyFinderGui.cs
new file mode 100644
index 000000000..f656963db
--- /dev/null
+++ b/Dalamud/Plugin/Services/IPartyFinderGui.cs
@@ -0,0 +1,23 @@
+using Dalamud.Game.Gui.PartyFinder.Types;
+
+namespace Dalamud.Plugin.Services;
+
+///
+/// This class handles interacting with the native PartyFinder window.
+///
+public interface IPartyFinderGui
+{
+ ///
+ /// Event type fired each time the game receives an individual Party Finder listing.
+ /// Cannot modify listings but can hide them.
+ ///
+ /// The listings received.
+ /// Additional arguments passed by the game.
+ public delegate void PartyFinderListingEventDelegate(PartyFinderListing listing, PartyFinderListingEventArgs args);
+
+ ///
+ /// Event fired each time the game receives an individual Party Finder listing.
+ /// Cannot modify listings but can hide them.
+ ///
+ public event PartyFinderListingEventDelegate ReceiveListing;
+}