From 303b7659406835387ccc0c37ce2e97f0118298ae Mon Sep 17 00:00:00 2001 From: pas2704 Date: Fri, 8 Nov 2024 01:13:36 -0500 Subject: [PATCH] WIP on inputs going through gui --- CringeLauncher/ImGuiHandler.cs | 12 +++++---- CringeLauncher/Patches/RenderHookPatch.cs | 30 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/CringeLauncher/ImGuiHandler.cs b/CringeLauncher/ImGuiHandler.cs index b848e83..2e2dfcc 100644 --- a/CringeLauncher/ImGuiHandler.cs +++ b/CringeLauncher/ImGuiHandler.cs @@ -21,6 +21,8 @@ internal class ImGuiHandler : IDisposable public static ImGuiHandler? Instance; public static RenderTargetView? Rtv; + + public ImGuiIOPtr Io { get; private set; } private readonly IRootRenderComponent _renderHandler = new RenderHandler(); public unsafe void Init(nint windowHandle, Device1 device, DeviceContext deviceContext) @@ -29,14 +31,14 @@ internal class ImGuiHandler : IDisposable CreateContext(); - var io = GetIO(); + Io = GetIO(); var path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CringeLauncher", "imgui.ini"); - io.NativePtr->IniFilename = AnsiStringMarshaller.ConvertToUnmanaged(path); - - io.ConfigWindowsMoveFromTitleBarOnly = true; - io.ConfigFlags |= ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable; + Io.NativePtr->IniFilename = AnsiStringMarshaller.ConvertToUnmanaged(path); + + Io.ConfigWindowsMoveFromTitleBarOnly = true; + Io.ConfigFlags |= ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable; ImGui_ImplWin32_Init(windowHandle); ImGui_ImplDX11_Init(device.NativePointer, deviceContext.NativePointer); diff --git a/CringeLauncher/Patches/RenderHookPatch.cs b/CringeLauncher/Patches/RenderHookPatch.cs index 04f355a..a323895 100644 --- a/CringeLauncher/Patches/RenderHookPatch.cs +++ b/CringeLauncher/Patches/RenderHookPatch.cs @@ -2,6 +2,8 @@ using HarmonyLib; using SharpDX.DXGI; using VRage.Platform.Windows.Forms; +using SharpDX.Windows; +using System.Reflection; namespace CringeLauncher.Patches; @@ -19,4 +21,32 @@ public class RenderHookPatch { ImGuiHandler.Instance?.HookWindow((HWND)__instance.Handle); } + + + + [HarmonyPatch] + public static class RenderMessagePatches + { + [HarmonyTargetMethods] + private static IEnumerable TargetMethods() + { + yield return AccessTools.Method(typeof(MyGameForm), nameof(MyGameWindow.WndProc)); + yield return AccessTools.Method(typeof(RenderForm), "WndProc"); + } + + [HarmonyPrefix] + private static bool WndProcPrefix(MyGameForm __instance, ref Message m) + { + if (ImGuiHandler.Instance is not { } handler) + return true; + + if (m.Msg is >= 256 and <= 265) + return !handler.Io.WantTextInput; + + if (__instance.ShowCursor && m.Msg is >= 512 and <= 526) + return !handler.Io.WantCaptureMouse; + + return true; + } + } } \ No newline at end of file