refactor: use XivCommon for game functions

This commit is contained in:
Anna 2021-04-11 09:31:00 -04:00
parent 704e11bb41
commit fc17137014
5 changed files with 21 additions and 69 deletions

View File

@ -8,34 +8,37 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud, Version=5.2.4.2, Culture=neutral, PublicKeyToken=null">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll</HintPath>
<Reference Include="Dalamud">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\5.2.4.3\Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET, Version=1.72.0.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="ImGui.NET">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="ImGuiScene">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="Lumina">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="Lumina.Excel">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<Reference Include="System.Memory">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\System.Memory.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
<PackageReference Include="DalamudPackager" Version="1.2.1" />
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all" />
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all" />
<PackageReference Include="XivCommon" Version="1.1.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ILMerge/>
</Weavers>

View File

@ -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<RequestPartyFinderListingsDelegate> _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<RequestPartyFinderListingsDelegate>(requestPfPtr);
this._requestPfListingsHook = new Hook<RequestPartyFinderListingsDelegate>(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);
}
}
}

View File

@ -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();
}
}
}

View File

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