All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m30s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m45s
Build / Build Nuget package (NuGet) (push) Successful in 1m47s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m58s
Build / Build Launcher (push) Successful in 2m24s
Improvements for imgui input handling
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using HarmonyLib;
|
|
using Sandbox.Graphics;
|
|
using VRage;
|
|
using VRage.Input;
|
|
using VRage.Input.Keyboard;
|
|
using VRage.Platform.Windows.Input;
|
|
using VRageMath;
|
|
|
|
namespace CringeLauncher.Patches;
|
|
|
|
[HarmonyPatch]
|
|
internal static class InputPatch
|
|
{
|
|
[HarmonyPostfix, HarmonyPatch(typeof(MyDirectInput), nameof(MyDirectInput.GetMouseState))]
|
|
private static void GetMouseStatePostfix(ref MyMouseState state)
|
|
{
|
|
if (ImGuiHandler.Instance?.BlockMouse == true && (MyVRage.Platform.Input.ShowCursor || ImGuiHandler.Instance.DrawMouse))
|
|
{
|
|
state.LeftButton = false;
|
|
state.RightButton = false;
|
|
state.MiddleButton = false;
|
|
state.XButton1 = false;
|
|
state.XButton2 = false;
|
|
state.ScrollWheelValue = 0;
|
|
}
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(MyGuiLocalizedKeyboardState), nameof(MyGuiLocalizedKeyboardState.GetCurrentState))]
|
|
private static bool GetKeyboardStatePrefix(ref MyKeyboardState __result)
|
|
{
|
|
if (ImGuiHandler.Instance?.BlockKeys == true)
|
|
{
|
|
__result = default;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPrefix, HarmonyPatch(typeof(MyGuiManager), nameof(MyGuiManager.MouseCursorPosition), MethodType.Getter)]
|
|
private static bool GetMouseCursorPositionPrefix(ref Vector2 __result)
|
|
{
|
|
if (ImGuiHandler.Instance?.BlockMouse == true && (MyVRage.Platform.Input.ShowCursor || ImGuiHandler.Instance.DrawMouse))
|
|
{
|
|
__result = Vector2.Zero;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|