From e469019c2080ba89ea9a35c200fcda59c0ecb017 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Wed, 17 Mar 2021 16:44:57 -0400 Subject: [PATCH] feat: refresh pf when changing preset --- .gitignore | 0 BetterPartyFinder.sln | 32 +++++++-------- BetterPartyFinder/Filter.cs | 2 +- BetterPartyFinder/GameFunctions.cs | 65 +++++++++++++++++++++--------- BetterPartyFinder/Plugin.cs | 2 +- BetterPartyFinder/PluginUi.cs | 5 +++ LICENCE | 0 README.md | 0 8 files changed, 69 insertions(+), 37 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 LICENCE mode change 100755 => 100644 README.md diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/BetterPartyFinder.sln b/BetterPartyFinder.sln index c02bc31..823d073 100755 --- a/BetterPartyFinder.sln +++ b/BetterPartyFinder.sln @@ -1,16 +1,16 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterPartyFinder", "BetterPartyFinder\BetterPartyFinder.csproj", "{3692974D-42C1-4590-AB61-3D94D26A0634}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3692974D-42C1-4590-AB61-3D94D26A0634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3692974D-42C1-4590-AB61-3D94D26A0634}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3692974D-42C1-4590-AB61-3D94D26A0634}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3692974D-42C1-4590-AB61-3D94D26A0634}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterPartyFinder", "BetterPartyFinder\BetterPartyFinder.csproj", "{3692974D-42C1-4590-AB61-3D94D26A0634}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3692974D-42C1-4590-AB61-3D94D26A0634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3692974D-42C1-4590-AB61-3D94D26A0634}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3692974D-42C1-4590-AB61-3D94D26A0634}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3692974D-42C1-4590-AB61-3D94D26A0634}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/BetterPartyFinder/Filter.cs b/BetterPartyFinder/Filter.cs index 0d16a5c..ab13c56 100755 --- a/BetterPartyFinder/Filter.cs +++ b/BetterPartyFinder/Filter.cs @@ -13,7 +13,7 @@ namespace BetterPartyFinder { } private void ReceiveListing(PartyFinderListing listing, PartyFinderListingEventArgs args) { - args.Visible = this.ListingVisible(listing); + args.Visible = args.Visible && this.ListingVisible(listing); } private bool ListingVisible(PartyFinderListing listing) { diff --git a/BetterPartyFinder/GameFunctions.cs b/BetterPartyFinder/GameFunctions.cs index d903b02..8a0eeff 100755 --- a/BetterPartyFinder/GameFunctions.cs +++ b/BetterPartyFinder/GameFunctions.cs @@ -1,14 +1,20 @@ using System; -#if DEBUG -using System.Linq; -#endif using System.Runtime.InteropServices; using Dalamud.Hooking; using Dalamud.Plugin; namespace BetterPartyFinder { public class GameFunctions : IDisposable { - private Plugin Plugin { get; } + #region Request PF Listings + + private delegate byte RequestPartyFinderListingsDelegate(IntPtr agent, short zero); + + private readonly RequestPartyFinderListingsDelegate _requestPartyFinderListings; + private readonly Hook _requestPfListingsHook; + + #endregion + + #region PF Listings events internal delegate void PartyFinderListingEventDelegate(PartyFinderListing listing, PartyFinderListingEventArgs args); @@ -16,17 +22,51 @@ namespace BetterPartyFinder { private delegate void HandlePfPacketDelegate(IntPtr param1, IntPtr data); - private readonly Hook? _handlePacketHook; + private readonly Hook _handlePacketHook; - internal GameFunctions(Plugin plugin) { + #endregion + + private Plugin Plugin { get; } + private IntPtr PartyFinderAgent { get; set; } = IntPtr.Zero; + + public GameFunctions(Plugin plugin) { this.Plugin = plugin; + var requestPfPtr = this.Plugin.Interface.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 80 BB ?? ?? ?? ?? ?? 74 2B"); var listingPtr = this.Plugin.Interface.TargetModuleScanner.ScanText("40 53 41 57 48 83 EC 28 48 8B D9"); + this._requestPartyFinderListings = Marshal.GetDelegateForFunctionPointer(requestPfPtr); + this._requestPfListingsHook = new Hook(requestPfPtr, new RequestPartyFinderListingsDelegate(this.OnRequestPartyFinderListings)); + this._requestPfListingsHook.Enable(); + this._handlePacketHook = new Hook(listingPtr, new HandlePfPacketDelegate(this.PacketDetour)); this._handlePacketHook.Enable(); } + public void Dispose() { + this._requestPfListingsHook.Dispose(); + this._handlePacketHook.Dispose(); + } + + private byte OnRequestPartyFinderListings(IntPtr agent, short zero) { + this.PartyFinderAgent = agent; + return this._requestPfListingsHook.Original(agent, zero); + } + + public void RequestPartyFinderListings() { + if (this.PartyFinderAgent == IntPtr.Zero) { + return; + } + + var addon = this.Plugin.Interface.Framework.Gui.GetAddonByName("LookingForGroup", 1); + if (addon == null) { + return; + } + + this._requestPartyFinderListings(this.PartyFinderAgent, 0); + } + + private void PacketDetour(IntPtr param1, IntPtr data) { if (data == IntPtr.Zero) { goto Return; @@ -50,15 +90,6 @@ namespace BetterPartyFinder { var needToRewrite = false; - #if DEBUG - var raw = Marshal.AllocHGlobal(PacketInfo.PacketSize); - Marshal.StructureToPtr(packet, raw, false); - var bytes = new byte[PacketInfo.PacketSize]; - Marshal.Copy(raw, bytes, 0, PacketInfo.PacketSize); - PluginLog.Log(string.Join("", bytes.Select(b => b.ToString("x2")))); - Marshal.FreeHGlobal(raw); - #endif - for (var i = 0; i < packet.listings.Length; i++) { if (packet.listings[i].IsNull()) { continue; @@ -96,10 +127,6 @@ namespace BetterPartyFinder { // free memory pinnedArray.Free(); } - - public void Dispose() { - this._handlePacketHook?.Dispose(); - } } internal class PartyFinderListingEventArgs { diff --git a/BetterPartyFinder/Plugin.cs b/BetterPartyFinder/Plugin.cs index b833dcb..3418db7 100755 --- a/BetterPartyFinder/Plugin.cs +++ b/BetterPartyFinder/Plugin.cs @@ -6,10 +6,10 @@ namespace BetterPartyFinder { internal DalamudPluginInterface Interface { get; private set; } = null!; internal Configuration Config { get; private set; } = null!; - internal GameFunctions Functions { get; private set; } = null!; private Filter Filter { get; set; } = null!; internal PluginUi Ui { get; set; } = null!; private Commands Commands { get; set; } = null!; + internal GameFunctions Functions { get; set; } = null!; public void Initialize(DalamudPluginInterface pluginInterface) { this.Interface = pluginInterface; diff --git a/BetterPartyFinder/PluginUi.cs b/BetterPartyFinder/PluginUi.cs index 4323a28..dedae7b 100755 --- a/BetterPartyFinder/PluginUi.cs +++ b/BetterPartyFinder/PluginUi.cs @@ -130,6 +130,7 @@ namespace BetterPartyFinder { } catch (NullReferenceException) { return; } + ImGui.SetWindowPos(new Vector2(addon.X, addon.Y - ImGui.GetFrameHeight())); } @@ -163,6 +164,8 @@ namespace BetterPartyFinder { if (ImGui.Selectable("")) { this.Plugin.Config.SelectedPreset = null; this.Plugin.Config.Save(); + + this.Plugin.Functions.RequestPartyFinderListings(); } foreach (var preset in this.Plugin.Config.Presets) { @@ -172,6 +175,8 @@ namespace BetterPartyFinder { this.Plugin.Config.SelectedPreset = preset.Key; this.Plugin.Config.Save(); + + this.Plugin.Functions.RequestPartyFinderListings(); } ImGui.EndCombo(); diff --git a/LICENCE b/LICENCE old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644