Input keybinds: hold ` for free mouse, use alt + delete to toggle free mouse
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (NuGet) (push) Successful in 53s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 58s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m2s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m19s
Build / Build Launcher (push) Successful in 1m49s
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (NuGet) (push) Successful in 53s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 58s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m2s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m19s
Build / Build Launcher (push) Successful in 1m49s
This commit is contained in:
@@ -11,18 +11,22 @@ using ImGuiNET;
|
|||||||
using SharpDX.Direct3D11;
|
using SharpDX.Direct3D11;
|
||||||
using static ImGuiNET.ImGui;
|
using static ImGuiNET.ImGui;
|
||||||
using VRage;
|
using VRage;
|
||||||
|
using Sandbox.Graphics.GUI;
|
||||||
|
|
||||||
namespace CringeLauncher;
|
namespace CringeLauncher;
|
||||||
|
|
||||||
internal class ImGuiHandler : IDisposable
|
internal class ImGuiHandler : IDisposable
|
||||||
{
|
{
|
||||||
private DeviceContext? _deviceContext;
|
private DeviceContext? _deviceContext;
|
||||||
|
private int _blockKeysCounter;
|
||||||
private static nint _wndproc;
|
private static nint _wndproc;
|
||||||
|
|
||||||
public bool BlockMouse { get; private set; }
|
public bool BlockMouse { get; private set; }
|
||||||
public bool BlockKeys { get; private set; }
|
public bool BlockKeys => _blockKeysCounter > 0;
|
||||||
public bool DrawMouse { get; private set; }
|
public bool DrawMouse { get; private set; }
|
||||||
|
|
||||||
|
internal bool MouseToggle { get; set; }
|
||||||
|
internal bool MouseKey { get; set; }
|
||||||
|
|
||||||
public static ImGuiHandler? Instance;
|
public static ImGuiHandler? Instance;
|
||||||
|
|
||||||
@@ -74,8 +78,25 @@ internal class ImGuiHandler : IDisposable
|
|||||||
|
|
||||||
var io = GetIO();
|
var io = GetIO();
|
||||||
BlockMouse = io.WantCaptureMouse;
|
BlockMouse = io.WantCaptureMouse;
|
||||||
BlockKeys = io.WantTextInput;
|
|
||||||
DrawMouse = io.MouseDrawCursor;
|
if (io.WantTextInput)
|
||||||
|
_blockKeysCounter = 10; //WantTextInput can be false briefly after pressing enter in a textbox
|
||||||
|
else
|
||||||
|
_blockKeysCounter--;
|
||||||
|
|
||||||
|
DrawMouse = io.MouseDrawCursor || MouseToggle || MouseKey;
|
||||||
|
|
||||||
|
var focusedScreen = MyScreenManager.GetScreenWithFocus(); //migrated logic from MyDX9Gui.Draw
|
||||||
|
|
||||||
|
if (DrawMouse || focusedScreen?.GetDrawMouseCursor() == true || (MyScreenManager.InputToNonFocusedScreens && MyScreenManager.GetScreensCount() > 1))
|
||||||
|
{
|
||||||
|
MyGuiSandbox.SetMouseCursorVisibility(true, false);
|
||||||
|
}
|
||||||
|
else if (focusedScreen != null)
|
||||||
|
{
|
||||||
|
MyGuiSandbox.SetMouseCursorVisibility(focusedScreen.GetDrawMouseCursor());
|
||||||
|
}
|
||||||
|
|
||||||
_renderHandler.OnFrame();
|
_renderHandler.OnFrame();
|
||||||
|
|
||||||
Render();
|
Render();
|
||||||
@@ -92,8 +113,27 @@ internal class ImGuiHandler : IDisposable
|
|||||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||||
private static unsafe int WndProcHook(HWND hWnd, int msg, nint wParam, nint lParam)
|
private static unsafe int WndProcHook(HWND hWnd, int msg, nint wParam, nint lParam)
|
||||||
{
|
{
|
||||||
|
//special handling for the mouse free key
|
||||||
|
|
||||||
|
if (msg is 0x0100 or 0x104 && (int)wParam == 0xC0 && Instance != null)
|
||||||
|
{
|
||||||
|
Instance.MouseKey = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg is 0x0101 or 0x105 && (int)wParam == 0xC0 && Instance != null)
|
||||||
|
{
|
||||||
|
Instance.MouseKey = false;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg == 0x102 && (char)(int)wParam == '`')
|
||||||
|
return 0;
|
||||||
|
|
||||||
//ignore input if mouse is hidden
|
//ignore input if mouse is hidden
|
||||||
if (MyVRage.Platform?.Input?.ShowCursor == false && Instance?.DrawMouse != true)
|
if (Instance?.BlockKeys != true && MyVRage.Platform?.Input?.ShowCursor == false && Instance?.DrawMouse != true)
|
||||||
return CallWindowProc(_wndproc, hWnd, msg, wParam, lParam);
|
return CallWindowProc(_wndproc, hWnd, msg, wParam, lParam);
|
||||||
|
|
||||||
var hookResult = ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam);
|
var hookResult = ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam);
|
||||||
@@ -101,11 +141,11 @@ internal class ImGuiHandler : IDisposable
|
|||||||
if (hookResult != 0)
|
if (hookResult != 0)
|
||||||
return hookResult;
|
return hookResult;
|
||||||
|
|
||||||
var io = GetIO();
|
|
||||||
|
|
||||||
if (!_init)
|
if (!_init)
|
||||||
return CallWindowProc(_wndproc, hWnd, msg, wParam, lParam);
|
return CallWindowProc(_wndproc, hWnd, msg, wParam, lParam);
|
||||||
|
|
||||||
|
var io = GetIO();
|
||||||
|
|
||||||
var blockMessage = (msg is >= 256 and <= 265 && io.WantTextInput)
|
var blockMessage = (msg is >= 256 and <= 265 && io.WantTextInput)
|
||||||
|| (msg is >= 512 and <= 526 && io.WantCaptureMouse);
|
|| (msg is >= 512 and <= 526 && io.WantCaptureMouse);
|
||||||
|
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using Sandbox.Engine.Platform.VideoMode;
|
||||||
|
using Sandbox.Game.World;
|
||||||
using Sandbox.Graphics;
|
using Sandbox.Graphics;
|
||||||
|
using Sandbox.Graphics.GUI;
|
||||||
|
using System.Reflection.Emit;
|
||||||
using VRage;
|
using VRage;
|
||||||
using VRage.Input;
|
using VRage.Input;
|
||||||
using VRage.Input.Keyboard;
|
using VRage.Input.Keyboard;
|
||||||
@@ -25,6 +29,45 @@ internal static class InputPatch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix, HarmonyPatch(typeof(MyVRageInput), nameof(MyVRageInput.GetMouseXForGamePlayF))]
|
||||||
|
private static bool GetMouseXForGamePlayFPrefix(ref float __result)
|
||||||
|
{
|
||||||
|
if (ImGuiHandler.Instance?.DrawMouse == true)
|
||||||
|
{
|
||||||
|
__result = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix, HarmonyPatch(typeof(MyVRageInput), nameof(MyVRageInput.GetMouseYForGamePlayF))]
|
||||||
|
private static bool GetMouseYForGamePlayFPrefix(ref float __result)
|
||||||
|
{
|
||||||
|
if (ImGuiHandler.Instance?.DrawMouse == true)
|
||||||
|
{
|
||||||
|
__result = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyTranspiler, HarmonyPatch(typeof(MyDX9Gui), nameof(MyDX9Gui.Draw))]
|
||||||
|
private static List<CodeInstruction> Dx9GuiDrawTranspiler(IEnumerable<CodeInstruction> instructions)
|
||||||
|
{
|
||||||
|
var list = instructions.ToList();
|
||||||
|
|
||||||
|
var method = AccessTools.Method(typeof(MyVideoSettingsManager), nameof(MyVideoSettingsManager.IsHardwareCursorUsed));
|
||||||
|
|
||||||
|
var index = list.FindIndex(b => b.Calls(method));
|
||||||
|
|
||||||
|
list[index].opcode = OpCodes.Ret;
|
||||||
|
list[index].operand = null;
|
||||||
|
|
||||||
|
list.RemoveRange(index + 1, list.Count - index - 1);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix, HarmonyPatch(typeof(MyGuiLocalizedKeyboardState), nameof(MyGuiLocalizedKeyboardState.GetCurrentState))]
|
[HarmonyPrefix, HarmonyPatch(typeof(MyGuiLocalizedKeyboardState), nameof(MyGuiLocalizedKeyboardState.GetCurrentState))]
|
||||||
private static bool GetKeyboardStatePrefix(ref MyKeyboardState __result)
|
private static bool GetKeyboardStatePrefix(ref MyKeyboardState __result)
|
||||||
{
|
{
|
||||||
@@ -46,4 +89,16 @@ internal static class InputPatch
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(MySession), nameof(MySession.HandleInput))]
|
||||||
|
private static void HandleInputPostfix()
|
||||||
|
{
|
||||||
|
if (ImGuiHandler.Instance == null || MyInput.Static == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Delete))
|
||||||
|
{
|
||||||
|
ImGuiHandler.Instance.MouseToggle = !ImGuiHandler.Instance.MouseToggle;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ using VRage;
|
|||||||
namespace CringeLauncher.Patches;
|
namespace CringeLauncher.Patches;
|
||||||
|
|
||||||
[HarmonyPatch(typeof(CustomRootWriter), "Init")]
|
[HarmonyPatch(typeof(CustomRootWriter), "Init")]
|
||||||
public class XmlRootWriterPatch
|
public static class XmlRootWriterPatch
|
||||||
{
|
{
|
||||||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user