From 8b7a671e52fe8dd0d0305242029291fd1528b171 Mon Sep 17 00:00:00 2001 From: Infi Date: Thu, 11 Apr 2024 07:40:47 +0200 Subject: [PATCH] Replace old vfunc calls with directly CS functions --- ChatTwo/GameFunctions/Context.cs | 17 +++----------- ChatTwo/GameFunctions/GameFunctions.cs | 24 +++++--------------- ChatTwo/Ipc/ExtraChat.cs | 31 +++++++++++++++++--------- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/ChatTwo/GameFunctions/Context.cs b/ChatTwo/GameFunctions/Context.cs index d8d9178..f62059e 100755 --- a/ChatTwo/GameFunctions/Context.cs +++ b/ChatTwo/GameFunctions/Context.cs @@ -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 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 SearchForRecipesUsingItemNative = null!; [Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9", Fallibility = Fallibility.Fallible)] private readonly delegate* unmanaged 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->vfunc[offset / 8]; - var a1 = vf(uiModule); + var a1 = (nint) AgentModule.Instance()->GetAgentByInternalId(AgentId.RecipeProductList); SearchForRecipesUsingItemNative(a1, itemId); } diff --git a/ChatTwo/GameFunctions/GameFunctions.cs b/ChatTwo/GameFunctions/GameFunctions.cs index 3994614..278c9ae 100755 --- a/ChatTwo/GameFunctions/GameFunctions.cs +++ b/ChatTwo/GameFunctions/GameFunctions.cs @@ -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 GetInfoProxyByIndexNative = null!; - [Signature("E8 ?? ?? ?? ?? 84 C0 74 0D B0 02", Fallibility = Fallibility.Fallible)] private readonly delegate* unmanaged 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->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() diff --git a/ChatTwo/Ipc/ExtraChat.cs b/ChatTwo/Ipc/ExtraChat.cs index 113a025..b594bcc 100644 --- a/ChatTwo/Ipc/ExtraChat.cs +++ b/ChatTwo/Ipc/ExtraChat.cs @@ -2,9 +2,11 @@ using Dalamud.Plugin.Ipc; namespace ChatTwo.Ipc; -internal sealed class ExtraChat : IDisposable { +internal sealed class ExtraChat : IDisposable +{ [Serializable] - private struct OverrideInfo { + private struct OverrideInfo + { public string? Channel; public ushort UiColour; public uint Rgba; @@ -24,7 +26,8 @@ internal sealed class ExtraChat : IDisposable { private Dictionary ChannelNamesInternal { get; set; } = new(); internal IReadOnlyDictionary ChannelNames => ChannelNamesInternal; - internal ExtraChat(Plugin plugin) { + internal ExtraChat(Plugin plugin) + { Plugin = plugin; OverrideChannelGate = Plugin.Interface.GetIpcSubscriber("ExtraChat.OverrideChannelColour"); @@ -34,20 +37,26 @@ internal sealed class ExtraChat : IDisposable { OverrideChannelGate.Subscribe(OnOverrideChannel); ChannelCommandColoursGate.Subscribe(OnChannelCommandColours); ChannelNamesGate.Subscribe(OnChannelNames); - try { + try + { ChannelCommandColoursInternal = ChannelCommandColoursGate.InvokeFunc(null!); ChannelNamesInternal = ChannelNamesGate.InvokeFunc(null!); - } catch (Exception) { + } + catch (Exception) + { // no-op } } - public void Dispose() { + public void Dispose() + { OverrideChannelGate.Unsubscribe(OnOverrideChannel); } - private void OnOverrideChannel(OverrideInfo info) { - if (info.Channel == null) { + private void OnOverrideChannel(OverrideInfo info) + { + if (info.Channel == null) + { ChannelOverride = null; return; } @@ -55,11 +64,13 @@ internal sealed class ExtraChat : IDisposable { ChannelOverride = (info.Channel, info.Rgba); } - private void OnChannelCommandColours(Dictionary obj) { + private void OnChannelCommandColours(Dictionary obj) + { ChannelCommandColoursInternal = obj; } - private void OnChannelNames(Dictionary obj) { + private void OnChannelNames(Dictionary obj) + { ChannelNamesInternal = obj; } }