Files
se-launcher/CringeLauncher/Patches/RenderHookPatch.cs
pas2704 303b765940
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m32s
Build / Build Nuget package (NuGet) (push) Successful in 2m13s
Build / Build Nuget package (CringePlugins) (push) Successful in 3m27s
Build / Build Nuget package (SharedCringe) (push) Successful in 2m36s
Build / Build Launcher (push) Successful in 3m41s
WIP on inputs going through gui
2024-11-08 01:13:36 -05:00

52 lines
1.4 KiB
C#

using Windows.Win32.Foundation;
using HarmonyLib;
using SharpDX.DXGI;
using VRage.Platform.Windows.Forms;
using SharpDX.Windows;
using System.Reflection;
namespace CringeLauncher.Patches;
[HarmonyPatch]
public class RenderHookPatch
{
[HarmonyPrefix, HarmonyPatch(typeof(SwapChain), nameof(SwapChain.Present))]
private static void PresentPrefix()
{
ImGuiHandler.Instance?.DoRender();
}
[HarmonyPostfix, HarmonyPatch(typeof(MyGameForm), "OnLoad")]
private static void LoadPostfix(MyGameForm __instance)
{
ImGuiHandler.Instance?.HookWindow((HWND)__instance.Handle);
}
[HarmonyPatch]
public static class RenderMessagePatches
{
[HarmonyTargetMethods]
private static IEnumerable<MethodInfo> 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;
}
}
}