Replace old vfunc calls with directly CS functions

This commit is contained in:
Infi
2024-04-11 07:40:47 +02:00
parent c24ca3c007
commit 8b7a671e52
3 changed files with 30 additions and 42 deletions
+3 -14
View File
@@ -1,7 +1,6 @@
using ChatTwo.Util;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
@@ -21,20 +20,12 @@ internal sealed unsafe class Context
[Signature("E8 ?? ?? ?? ?? EB 3F 83 F8 FE", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<AgentInterface*, ushort, uint, byte, void> ItemComparisonNative = null!;
[Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 83 F8 0F", Fallibility = Fallibility.Fallible)]
[Signature("48 89 5C 24 ?? 57 48 83 EC ?? 8B FA B8", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<IntPtr, uint, void> SearchForRecipesUsingItemNative = null!;
[Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<void*, uint, byte, void> SearchForItemNative = null!;
#region Offsets
[Signature(
"FF 90 ?? ?? ?? ?? 8B 93 ?? ?? ?? ?? 48 8B C8 E8 ?? ?? ?? ?? 41 0F B6 D4 48 8B CB E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 81 FF ?? ?? ?? ?? 0F 85",
Offset = 2
)]
private readonly int? SearchForRecipesUsingItemVfunc;
#endregion
private Plugin Plugin { get; }
internal Context(Plugin plugin)
@@ -93,12 +84,10 @@ internal sealed unsafe class Context
internal void SearchForRecipesUsingItem(uint itemId)
{
if (SearchForRecipesUsingItemNative == null || SearchForRecipesUsingItemVfunc is not { } offset)
if (SearchForRecipesUsingItemNative == null)
return;
var uiModule = Framework.Instance()->GetUiModule();
var vf = (delegate* unmanaged<UIModule*, IntPtr>) uiModule->vfunc[offset / 8];
var a1 = vf(uiModule);
var a1 = (nint) AgentModule.Instance()->GetAgentByInternalId(AgentId.RecipeProductList);
SearchForRecipesUsingItemNative(a1, itemId);
}
+6 -18
View File
@@ -5,6 +5,7 @@ using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Client.UI.Info;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Lumina.Excel.GeneratedSheets;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
@@ -22,9 +23,6 @@ internal unsafe class GameFunctions : IDisposable
}
#region Functions
[Signature("E8 ?? ?? ?? ?? 8B FD 8B CD", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<IntPtr, uint, IntPtr> GetInfoProxyByIndexNative = null!;
[Signature("E8 ?? ?? ?? ?? 84 C0 74 0D B0 02", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<IntPtr, byte> IsMentorNative = null!;
@@ -53,9 +51,6 @@ internal unsafe class GameFunctions : IDisposable
private readonly IntPtr? IsMentorA1;
#pragma warning restore 0649
[Signature("FF 90 ?? ?? ?? ?? 48 8B C8 BA ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B F0 48 85 C0 0F 84 ?? ?? ?? ?? 48 8B 10 33 ED", Offset = 2)]
private readonly int? InfoModuleVfunc;
private Plugin Plugin { get; }
internal Party Party { get; }
internal Chat Chat { get; }
@@ -82,20 +77,13 @@ internal unsafe class GameFunctions : IDisposable
Marshal.FreeHGlobal(PlaceholderNamePtr);
}
private IntPtr GetInfoModule()
{
if (InfoModuleVfunc is not { } vfunc)
return IntPtr.Zero;
var uiModule = Framework.Instance()->GetUiModule();
var getInfoModule = (delegate* unmanaged<UIModule*, IntPtr>) uiModule->vfunc[vfunc / 8];
return getInfoModule(uiModule);
}
internal IntPtr GetInfoProxyByIndex(uint idx)
{
var infoModule = GetInfoModule();
return infoModule == IntPtr.Zero ? IntPtr.Zero : GetInfoProxyByIndexNative(infoModule, idx);
var infoModule = InfoModule.Instance();
if (infoModule == null)
return nint.Zero;
return (nint) infoModule->GetInfoProxyById(idx);
}
internal uint? GetCurrentChatLogEntryIndex()