2021-04-06 08:41:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Dalamud.Game;
|
|
|
|
|
using Dalamud.Hooking;
|
|
|
|
|
|
|
|
|
|
namespace XivCommon.Functions {
|
2021-04-11 14:13:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A class containing Party Finder functionality
|
|
|
|
|
/// </summary>
|
2021-04-06 08:41:38 +00:00
|
|
|
|
public class PartyFinder : IDisposable {
|
|
|
|
|
private delegate byte RequestPartyFinderListingsDelegate(IntPtr agent, byte categoryIdx);
|
|
|
|
|
|
|
|
|
|
private RequestPartyFinderListingsDelegate RequestPartyFinderListings { get; }
|
2021-04-11 13:24:56 +00:00
|
|
|
|
private Hook<RequestPartyFinderListingsDelegate>? RequestPfListingsHook { get; }
|
2021-04-06 08:41:38 +00:00
|
|
|
|
|
2021-04-11 13:24:56 +00:00
|
|
|
|
private bool Enabled { get; }
|
2021-04-06 08:41:38 +00:00
|
|
|
|
private IntPtr PartyFinderAgent { get; set; } = IntPtr.Zero;
|
|
|
|
|
|
2021-04-11 13:24:56 +00:00
|
|
|
|
internal PartyFinder(SigScanner scanner, bool hook) {
|
2021-04-06 08:41:38 +00:00
|
|
|
|
var requestPfPtr = scanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 40 0F 10 81 ?? ?? ?? ??");
|
|
|
|
|
|
|
|
|
|
this.RequestPartyFinderListings = Marshal.GetDelegateForFunctionPointer<RequestPartyFinderListingsDelegate>(requestPfPtr);
|
2021-04-11 13:24:56 +00:00
|
|
|
|
|
|
|
|
|
this.Enabled = hook;
|
|
|
|
|
|
|
|
|
|
if (!hook) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 08:41:38 +00:00
|
|
|
|
this.RequestPfListingsHook = new Hook<RequestPartyFinderListingsDelegate>(requestPfPtr, new RequestPartyFinderListingsDelegate(this.OnRequestPartyFinderListings));
|
|
|
|
|
this.RequestPfListingsHook.Enable();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 14:13:10 +00:00
|
|
|
|
/// <inheritdoc />
|
2021-04-06 08:41:38 +00:00
|
|
|
|
public void Dispose() {
|
2021-04-11 13:24:56 +00:00
|
|
|
|
this.RequestPfListingsHook?.Dispose();
|
2021-04-06 08:41:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte OnRequestPartyFinderListings(IntPtr agent, byte categoryIdx) {
|
|
|
|
|
this.PartyFinderAgent = agent;
|
2021-04-11 13:24:56 +00:00
|
|
|
|
return this.RequestPfListingsHook!.Original(agent, categoryIdx);
|
2021-04-06 08:41:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 13:42:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// Refresh the Party Finder listings. This does not open the Party Finder.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// This maintains the currently selected category.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="InvalidOperationException">If the <see cref="Hooks.PartyFinder"/> hook is not enabled</exception>
|
2021-04-06 08:41:38 +00:00
|
|
|
|
public void RefreshListings() {
|
2021-04-11 13:24:56 +00:00
|
|
|
|
if (!this.Enabled) {
|
|
|
|
|
throw new InvalidOperationException("PartyFinder hooks are not enabled");
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 09:33:38 +00:00
|
|
|
|
// Updated 5.5
|
2021-04-06 08:41:38 +00:00
|
|
|
|
const int categoryOffset = 10_655;
|
|
|
|
|
|
|
|
|
|
if (this.PartyFinderAgent == IntPtr.Zero) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var categoryIdx = Marshal.ReadByte(this.PartyFinderAgent + categoryOffset);
|
|
|
|
|
this.RequestPartyFinderListings(this.PartyFinderAgent, categoryIdx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|