From 93ae7c9a660ba79064d8d0f067e0994eb2b24b65 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 26 Oct 2021 21:47:22 -0400 Subject: [PATCH] Fix data window hook --- .../Interface/Internal/Windows/DataWindow.cs | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index 5d2da5bd5..f928fe0f9 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -71,8 +72,6 @@ namespace Dalamud.Interface.Internal.Windows private UIDebug addonInspector = null; - private delegate int MessageBoxWDelegate(IntPtr hWnd, string text, string caption, NativeFunctions.MessageBoxType type); - private Hook? messageBoxMinHook; // IPC @@ -123,6 +122,12 @@ namespace Dalamud.Interface.Internal.Windows this.Load(); } + private delegate int MessageBoxWDelegate( + IntPtr hWnd, + [MarshalAs(UnmanagedType.LPWStr)] string text, + [MarshalAs(UnmanagedType.LPWStr)] string caption, + NativeFunctions.MessageBoxType type); + private enum DataKind { Server_OpCode, @@ -327,36 +332,7 @@ namespace Dalamud.Interface.Internal.Windows break; case DataKind.Hook: - { - try - { - if (ImGui.Button("Create")) - { - this.messageBoxMinHook = Hook.FromSymbol( - "User32", "MessageBoxW", MessageBoxWDetour); - } - - if (ImGui.Button("Enable")) this.messageBoxMinHook?.Enable(); - - if (ImGui.Button("Disable")) this.messageBoxMinHook?.Disable(); - - if (ImGui.Button("Dispose")) - { - this.messageBoxMinHook?.Dispose(); - this.messageBoxMinHook = null; - } - - if (ImGui.Button("Test")) NativeFunctions.MessageBoxW(IntPtr.Zero, "Hi", "Hello", NativeFunctions.MessageBoxType.Ok); - - if (this.messageBoxMinHook != null) - ImGui.Text("Enabled: " + this.messageBoxMinHook?.IsEnabled); - } - catch (Exception ex) - { - Log.Error(ex, "MinHook error caught"); - } - } - + this.DrawHook(); break; } } @@ -1609,6 +1585,37 @@ namespace Dalamud.Interface.Internal.Windows } } + private void DrawHook() + { + try + { + if (ImGui.Button("Create")) + this.messageBoxMinHook = Hook.FromSymbol("User32", "MessageBoxW", this.MessageBoxWDetour); + + if (ImGui.Button("Enable")) + this.messageBoxMinHook?.Enable(); + + if (ImGui.Button("Disable")) + this.messageBoxMinHook?.Disable(); + + if (ImGui.Button("Dispose")) + { + this.messageBoxMinHook?.Dispose(); + this.messageBoxMinHook = null; + } + + if (ImGui.Button("Test")) + NativeFunctions.MessageBoxW(IntPtr.Zero, "Hi", "Hello", NativeFunctions.MessageBoxType.Ok); + + if (this.messageBoxMinHook != null) + ImGui.Text("Enabled: " + this.messageBoxMinHook?.IsEnabled); + } + catch (Exception ex) + { + Log.Error(ex, "MinHook error caught"); + } + } + private async Task TestTaskInTaskDelay() { await Task.Delay(5000);