From fc171370149c3bef92b847192c21b9e747c63d57 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 11 Apr 2021 09:31:00 -0400 Subject: [PATCH] refactor: use XivCommon for game functions --- BetterPartyFinder/BetterPartyFinder.csproj | 19 ++++---- BetterPartyFinder/FodyWeavers.xml | 3 ++ BetterPartyFinder/GameFunctions.cs | 55 ---------------------- BetterPartyFinder/Plugin.cs | 7 +-- BetterPartyFinder/PluginUi.cs | 6 +-- 5 files changed, 21 insertions(+), 69 deletions(-) create mode 100755 BetterPartyFinder/FodyWeavers.xml delete mode 100755 BetterPartyFinder/GameFunctions.cs diff --git a/BetterPartyFinder/BetterPartyFinder.csproj b/BetterPartyFinder/BetterPartyFinder.csproj index bfd4058..fb08d0a 100755 --- a/BetterPartyFinder/BetterPartyFinder.csproj +++ b/BetterPartyFinder/BetterPartyFinder.csproj @@ -8,34 +8,37 @@ - - $(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll + + $(AppData)\XIVLauncher\addon\Hooks\5.2.4.3\Dalamud.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\System.Memory.dll False - + + + + diff --git a/BetterPartyFinder/FodyWeavers.xml b/BetterPartyFinder/FodyWeavers.xml new file mode 100755 index 0000000..2dfb1f4 --- /dev/null +++ b/BetterPartyFinder/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + diff --git a/BetterPartyFinder/GameFunctions.cs b/BetterPartyFinder/GameFunctions.cs deleted file mode 100755 index c05a971..0000000 --- a/BetterPartyFinder/GameFunctions.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Dalamud.Hooking; - -namespace BetterPartyFinder { - public class GameFunctions : IDisposable { - #region Request PF Listings - - private delegate byte RequestPartyFinderListingsDelegate(IntPtr agent, byte categoryIdx); - - private readonly RequestPartyFinderListingsDelegate _requestPartyFinderListings; - private readonly Hook _requestPfListingsHook; - - #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("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 40 0F 10 81 ?? ?? ?? ??"); - - this._requestPartyFinderListings = Marshal.GetDelegateForFunctionPointer(requestPfPtr); - this._requestPfListingsHook = new Hook(requestPfPtr, new RequestPartyFinderListingsDelegate(this.OnRequestPartyFinderListings)); - this._requestPfListingsHook.Enable(); - } - - public void Dispose() { - this._requestPfListingsHook.Dispose(); - } - - private byte OnRequestPartyFinderListings(IntPtr agent, byte categoryIdx) { - this.PartyFinderAgent = agent; - return this._requestPfListingsHook.Original(agent, categoryIdx); - } - - public void RequestPartyFinderListings() { - // Updated 5.41 - const int categoryOffset = 10_655; - - if (this.PartyFinderAgent == IntPtr.Zero) { - return; - } - - var addon = this.Plugin.Interface.Framework.Gui.GetAddonByName("LookingForGroup", 1); - if (addon == null) { - return; - } - - var categoryIdx = Marshal.ReadByte(this.PartyFinderAgent + categoryOffset); - this._requestPartyFinderListings(this.PartyFinderAgent, categoryIdx); - } - } -} diff --git a/BetterPartyFinder/Plugin.cs b/BetterPartyFinder/Plugin.cs index 3418db7..e8c4cdd 100755 --- a/BetterPartyFinder/Plugin.cs +++ b/BetterPartyFinder/Plugin.cs @@ -1,4 +1,5 @@ using Dalamud.Plugin; +using XivCommon; namespace BetterPartyFinder { public class Plugin : IDalamudPlugin { @@ -9,7 +10,7 @@ namespace BetterPartyFinder { private Filter Filter { get; set; } = null!; internal PluginUi Ui { get; set; } = null!; private Commands Commands { get; set; } = null!; - internal GameFunctions Functions { get; set; } = null!; + internal XivCommonBase Common { get; set; } = null!; public void Initialize(DalamudPluginInterface pluginInterface) { this.Interface = pluginInterface; @@ -17,7 +18,7 @@ namespace BetterPartyFinder { this.Config = Configuration.Load(this) ?? new Configuration(); this.Config.Initialise(this); - this.Functions = new GameFunctions(this); + this.Common = new XivCommonBase(this.Interface, Hooks.PartyFinder); this.Filter = new Filter(this); this.Ui = new PluginUi(this); this.Commands = new Commands(this); @@ -30,7 +31,7 @@ namespace BetterPartyFinder { this.Commands.Dispose(); this.Ui.Dispose(); this.Filter.Dispose(); - this.Functions.Dispose(); + this.Common.Dispose(); } } } diff --git a/BetterPartyFinder/PluginUi.cs b/BetterPartyFinder/PluginUi.cs index d0a4bbc..7bb6b7b 100755 --- a/BetterPartyFinder/PluginUi.cs +++ b/BetterPartyFinder/PluginUi.cs @@ -125,7 +125,7 @@ namespace BetterPartyFinder { var showWindow = this.Visible || addon?.Visible == true; if (!showWindow || !ImGui.Begin(this.Plugin.Name, ref this._visible)) { - if (ImGui.IsWindowCollapsed() && addon != null && addon.Visible) { + if (ImGui.IsWindowCollapsed() && addon is {Visible: true}) { // wait until addon is initialised to show try { _ = addon.Width; @@ -167,7 +167,7 @@ namespace BetterPartyFinder { this.Plugin.Config.SelectedPreset = null; this.Plugin.Config.Save(); - this.Plugin.Functions.RequestPartyFinderListings(); + this.Plugin.Common.Functions.PartyFinder.RefreshListings(); } foreach (var preset in this.Plugin.Config.Presets) { @@ -178,7 +178,7 @@ namespace BetterPartyFinder { this.Plugin.Config.SelectedPreset = preset.Key; this.Plugin.Config.Save(); - this.Plugin.Functions.RequestPartyFinderListings(); + this.Plugin.Common.Functions.PartyFinder.RefreshListings(); } ImGui.EndCombo();