feat: refresh pf when changing preset

This commit is contained in:
Anna 2021-03-17 16:44:57 -04:00
parent 28f3d84b03
commit e469019c20
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
8 changed files with 69 additions and 37 deletions

0
.gitignore vendored Executable file → Normal file
View File

View File

@ -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

View File

@ -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) {

View File

@ -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<RequestPartyFinderListingsDelegate> _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<HandlePfPacketDelegate>? _handlePacketHook;
private readonly Hook<HandlePfPacketDelegate> _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<RequestPartyFinderListingsDelegate>(requestPfPtr);
this._requestPfListingsHook = new Hook<RequestPartyFinderListingsDelegate>(requestPfPtr, new RequestPartyFinderListingsDelegate(this.OnRequestPartyFinderListings));
this._requestPfListingsHook.Enable();
this._handlePacketHook = new Hook<HandlePfPacketDelegate>(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 {

View File

@ -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;

View File

@ -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("<none>")) {
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();

0
LICENCE Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File