feat(df): add Duty Finder functions

This commit is contained in:
Anna 2021-07-11 21:41:48 -04:00
parent c9eb6ce323
commit 08c969208c
3 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,82 @@
using System;
using System.Runtime.InteropServices;
using Dalamud.Game;
using Lumina.Excel.GeneratedSheets;
namespace XivCommon.Functions {
/// <summary>
/// Duty Finder functions
/// </summary>
public class DutyFinder {
private static class Signatures {
internal const string OpenRegularDuty = "48 89 6C 24 ?? 48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 41 0F B6 E8";
internal const string OpenRoulette = "E9 ?? ?? ?? ?? 8B 93 ?? ?? ?? ?? 48 83 C4 20";
}
private const uint ContentsFinderAgentId = 50;
private delegate IntPtr OpenDutyDelegate(IntPtr agent, uint contentFinderCondition, byte a3);
private delegate IntPtr OpenRouletteDelegate(IntPtr agent, byte roulette, byte a3);
private GameFunctions Functions { get; }
private readonly OpenDutyDelegate? _openDuty;
private readonly OpenRouletteDelegate? _openRoulette;
internal DutyFinder(GameFunctions functions, SigScanner scanner) {
this.Functions = functions;
if (scanner.TryScanText(Signatures.OpenRegularDuty, out var openDutyPtr, "Duty Finder (open duty)")) {
this._openDuty = Marshal.GetDelegateForFunctionPointer<OpenDutyDelegate>(openDutyPtr);
}
if (scanner.TryScanText(Signatures.OpenRoulette, out var openRoulettePtr, "Duty Finder (open roulette)")) {
this._openRoulette = Marshal.GetDelegateForFunctionPointer<OpenRouletteDelegate>(openRoulettePtr);
}
}
/// <summary>
/// Opens the Duty Finder to the given duty.
/// </summary>
/// <param name="condition">duty to show</param>
public void OpenDuty(ContentFinderCondition condition) {
this.OpenDuty(condition.RowId);
}
/// <summary>
/// Opens the Duty Finder to the given duty ID.
/// </summary>
/// <param name="contentFinderCondition">ID of duty to show</param>
public void OpenDuty(uint contentFinderCondition) {
if (this._openDuty == null) {
throw new InvalidOperationException("Could not find signature for open duty function");
}
var agent = this.Functions.GetAgentByInternalId(ContentsFinderAgentId);
this._openDuty(agent, contentFinderCondition, 0);
}
/// <summary>
/// Opens the Duty Finder to the given roulette.
/// </summary>
/// <param name="roulette">roulette to show</param>
public void OpenRoulette(ContentRoulette roulette) {
this.OpenRoulette((byte) roulette.RowId);
}
/// <summary>
/// Opens the Duty Finder to the given roulette ID.
/// </summary>
/// <param name="roulette">ID of roulette to show</param>
public void OpenRoulette(byte roulette) {
if (this._openRoulette == null) {
throw new InvalidOperationException("Could not find signature for open roulette function");
}
var agent = this.Functions.GetAgentByInternalId(ContentsFinderAgentId);
this._openRoulette(agent, roulette, 0);
}
}
}

View File

@ -79,6 +79,11 @@ namespace XivCommon {
/// </summary>
public NamePlates NamePlates { get; }
/// <summary>
/// Duty Finder functions
/// </summary>
public DutyFinder DutyFinder { get; }
internal GameFunctions(Hooks hooks, DalamudPluginInterface @interface) {
this.Interface = @interface;
@ -98,6 +103,7 @@ namespace XivCommon {
this.ContextMenu = new ContextMenu(this, scanner, seStringManager, @interface.ClientState.ClientLanguage, hooks);
this.Tooltips = new Tooltips(scanner, @interface.Framework, @interface.Framework.Gui, seStringManager, hooks.HasFlag(Hooks.Tooltips));
this.NamePlates = new NamePlates(this, scanner, seStringManager, hooks.HasFlag(Hooks.NamePlates));
this.DutyFinder = new DutyFinder(this, scanner);
if (scanner.TryScanText(Signatures.GetAgentByInternalId, out var byInternalIdPtr, "GetAgentByInternalId")) {
this.GetAgentByInternalIdInternal = Marshal.GetDelegateForFunctionPointer<GetAgentByInternalIdDelegate>(byInternalIdPtr);

View File

@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<Version>2.1.1</Version>
<Version>2.2.0-alpha.1</Version>
<DebugType>full</DebugType>
</PropertyGroup>
@ -28,6 +28,14 @@
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>