Replace old vfunc calls with directly CS functions
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using ChatTwo.Util;
|
using ChatTwo.Util;
|
||||||
using Dalamud.Utility.Signatures;
|
using Dalamud.Utility.Signatures;
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
|
|
||||||
@@ -21,20 +20,12 @@ internal sealed unsafe class Context
|
|||||||
[Signature("E8 ?? ?? ?? ?? EB 3F 83 F8 FE", Fallibility = Fallibility.Fallible)]
|
[Signature("E8 ?? ?? ?? ?? EB 3F 83 F8 FE", Fallibility = Fallibility.Fallible)]
|
||||||
private readonly delegate* unmanaged<AgentInterface*, ushort, uint, byte, void> ItemComparisonNative = null!;
|
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!;
|
private readonly delegate* unmanaged<IntPtr, uint, void> SearchForRecipesUsingItemNative = null!;
|
||||||
|
|
||||||
[Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9", Fallibility = Fallibility.Fallible)]
|
[Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9", Fallibility = Fallibility.Fallible)]
|
||||||
private readonly delegate* unmanaged<void*, uint, byte, void> SearchForItemNative = null!;
|
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; }
|
private Plugin Plugin { get; }
|
||||||
|
|
||||||
internal Context(Plugin plugin)
|
internal Context(Plugin plugin)
|
||||||
@@ -93,12 +84,10 @@ internal sealed unsafe class Context
|
|||||||
|
|
||||||
internal void SearchForRecipesUsingItem(uint itemId)
|
internal void SearchForRecipesUsingItem(uint itemId)
|
||||||
{
|
{
|
||||||
if (SearchForRecipesUsingItemNative == null || SearchForRecipesUsingItemVfunc is not { } offset)
|
if (SearchForRecipesUsingItemNative == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var uiModule = Framework.Instance()->GetUiModule();
|
var a1 = (nint) AgentModule.Instance()->GetAgentByInternalId(AgentId.RecipeProductList);
|
||||||
var vf = (delegate* unmanaged<UIModule*, IntPtr>) uiModule->vfunc[offset / 8];
|
|
||||||
var a1 = vf(uiModule);
|
|
||||||
SearchForRecipesUsingItemNative(a1, itemId);
|
SearchForRecipesUsingItemNative(a1, itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Dalamud.Utility.Signatures;
|
|||||||
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.UI.Info;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||||
@@ -22,9 +23,6 @@ internal unsafe class GameFunctions : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Functions
|
#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)]
|
[Signature("E8 ?? ?? ?? ?? 84 C0 74 0D B0 02", Fallibility = Fallibility.Fallible)]
|
||||||
private readonly delegate* unmanaged<IntPtr, byte> IsMentorNative = null!;
|
private readonly delegate* unmanaged<IntPtr, byte> IsMentorNative = null!;
|
||||||
|
|
||||||
@@ -53,9 +51,6 @@ internal unsafe class GameFunctions : IDisposable
|
|||||||
private readonly IntPtr? IsMentorA1;
|
private readonly IntPtr? IsMentorA1;
|
||||||
#pragma warning restore 0649
|
#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; }
|
private Plugin Plugin { get; }
|
||||||
internal Party Party { get; }
|
internal Party Party { get; }
|
||||||
internal Chat Chat { get; }
|
internal Chat Chat { get; }
|
||||||
@@ -82,20 +77,13 @@ internal unsafe class GameFunctions : IDisposable
|
|||||||
Marshal.FreeHGlobal(PlaceholderNamePtr);
|
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)
|
internal IntPtr GetInfoProxyByIndex(uint idx)
|
||||||
{
|
{
|
||||||
var infoModule = GetInfoModule();
|
var infoModule = InfoModule.Instance();
|
||||||
return infoModule == IntPtr.Zero ? IntPtr.Zero : GetInfoProxyByIndexNative(infoModule, idx);
|
if (infoModule == null)
|
||||||
|
return nint.Zero;
|
||||||
|
|
||||||
|
return (nint) infoModule->GetInfoProxyById(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal uint? GetCurrentChatLogEntryIndex()
|
internal uint? GetCurrentChatLogEntryIndex()
|
||||||
|
|||||||
+21
-10
@@ -2,9 +2,11 @@ using Dalamud.Plugin.Ipc;
|
|||||||
|
|
||||||
namespace ChatTwo.Ipc;
|
namespace ChatTwo.Ipc;
|
||||||
|
|
||||||
internal sealed class ExtraChat : IDisposable {
|
internal sealed class ExtraChat : IDisposable
|
||||||
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
private struct OverrideInfo {
|
private struct OverrideInfo
|
||||||
|
{
|
||||||
public string? Channel;
|
public string? Channel;
|
||||||
public ushort UiColour;
|
public ushort UiColour;
|
||||||
public uint Rgba;
|
public uint Rgba;
|
||||||
@@ -24,7 +26,8 @@ internal sealed class ExtraChat : IDisposable {
|
|||||||
private Dictionary<Guid, string> ChannelNamesInternal { get; set; } = new();
|
private Dictionary<Guid, string> ChannelNamesInternal { get; set; } = new();
|
||||||
internal IReadOnlyDictionary<Guid, string> ChannelNames => ChannelNamesInternal;
|
internal IReadOnlyDictionary<Guid, string> ChannelNames => ChannelNamesInternal;
|
||||||
|
|
||||||
internal ExtraChat(Plugin plugin) {
|
internal ExtraChat(Plugin plugin)
|
||||||
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
|
|
||||||
OverrideChannelGate = Plugin.Interface.GetIpcSubscriber<OverrideInfo, object>("ExtraChat.OverrideChannelColour");
|
OverrideChannelGate = Plugin.Interface.GetIpcSubscriber<OverrideInfo, object>("ExtraChat.OverrideChannelColour");
|
||||||
@@ -34,20 +37,26 @@ internal sealed class ExtraChat : IDisposable {
|
|||||||
OverrideChannelGate.Subscribe(OnOverrideChannel);
|
OverrideChannelGate.Subscribe(OnOverrideChannel);
|
||||||
ChannelCommandColoursGate.Subscribe(OnChannelCommandColours);
|
ChannelCommandColoursGate.Subscribe(OnChannelCommandColours);
|
||||||
ChannelNamesGate.Subscribe(OnChannelNames);
|
ChannelNamesGate.Subscribe(OnChannelNames);
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
ChannelCommandColoursInternal = ChannelCommandColoursGate.InvokeFunc(null!);
|
ChannelCommandColoursInternal = ChannelCommandColoursGate.InvokeFunc(null!);
|
||||||
ChannelNamesInternal = ChannelNamesGate.InvokeFunc(null!);
|
ChannelNamesInternal = ChannelNamesGate.InvokeFunc(null!);
|
||||||
} catch (Exception) {
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose()
|
||||||
|
{
|
||||||
OverrideChannelGate.Unsubscribe(OnOverrideChannel);
|
OverrideChannelGate.Unsubscribe(OnOverrideChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOverrideChannel(OverrideInfo info) {
|
private void OnOverrideChannel(OverrideInfo info)
|
||||||
if (info.Channel == null) {
|
{
|
||||||
|
if (info.Channel == null)
|
||||||
|
{
|
||||||
ChannelOverride = null;
|
ChannelOverride = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,11 +64,13 @@ internal sealed class ExtraChat : IDisposable {
|
|||||||
ChannelOverride = (info.Channel, info.Rgba);
|
ChannelOverride = (info.Channel, info.Rgba);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChannelCommandColours(Dictionary<string, uint> obj) {
|
private void OnChannelCommandColours(Dictionary<string, uint> obj)
|
||||||
|
{
|
||||||
ChannelCommandColoursInternal = obj;
|
ChannelCommandColoursInternal = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChannelNames(Dictionary<Guid, string> obj) {
|
private void OnChannelNames(Dictionary<Guid, string> obj)
|
||||||
|
{
|
||||||
ChannelNamesInternal = obj;
|
ChannelNamesInternal = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user