examine keybind; unlock cursor

This commit is contained in:
Tyfon
2024-07-22 15:04:00 -07:00
parent 7c5e31e677
commit 14c2e79658
5 changed files with 72 additions and 5 deletions

View File

@@ -0,0 +1,33 @@
using HarmonyLib;
using SPT.Reflection.Patching;
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace UIFixes;
public class UnlockCursorPatch : ModulePatch
{
private static readonly FullScreenMode[] WindowedModes = [FullScreenMode.Windowed, FullScreenMode.MaximizedWindow, FullScreenMode.FullScreenWindow];
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CursorManager), nameof(CursorManager.SetCursorLockMode));
}
[PatchPrefix]
public static bool Prefix(bool cursorVisible, FullScreenMode fullscreenMode, Action ___action_0)
{
Cursor.lockState = cursorVisible ?
Settings.UnlockCursor.Value && WindowedModes.Contains(fullscreenMode) ? CursorLockMode.None : CursorLockMode.Confined :
CursorLockMode.Locked;
if (___action_0 != null)
{
___action_0();
}
return false;
}
}