Pause game input while typing (chat/console/admin); isolate sync subsystems so one error doesn't stop everything
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+45
-1
@@ -74,11 +74,15 @@ namespace MSCO
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
/// <summary>PlayMaker-Aktionen, die den Mauszeiger setzen, überspringen, solange ein Fenster offen ist.</summary>
|
||||
/// <summary>
|
||||
/// PlayMaker-Aktionen, die den Mauszeiger setzen, überspringen, solange ein Fenster offen ist. Außerdem die
|
||||
/// Tastenabfragen des Spiels (cInput) sperren: sonst löst Tippen im Chat Spielaktionen aus (Benutzen, Hupe ...).
|
||||
/// </summary>
|
||||
static void PatchCursorActions()
|
||||
{
|
||||
if (patched) return;
|
||||
patched = true;
|
||||
PatchGameInput();
|
||||
try
|
||||
{
|
||||
Type action = null;
|
||||
@@ -104,5 +108,45 @@ namespace MSCO
|
||||
}
|
||||
|
||||
static bool SkipWhileLocked() { return !locked; }
|
||||
|
||||
static void PatchGameInput()
|
||||
{
|
||||
try
|
||||
{
|
||||
Type input = typeof(cInput);
|
||||
HarmonyInstance harmony = HarmonyInstance.Create("mbm.msco.inputlock.keys");
|
||||
var boolPrefix = new HarmonyMethod(typeof(InputLock).GetMethod("NoKeyWhileLocked", BindingFlags.Static | BindingFlags.NonPublic));
|
||||
var floatPrefix = new HarmonyMethod(typeof(InputLock).GetMethod("NoAxisWhileLocked", BindingFlags.Static | BindingFlags.NonPublic));
|
||||
int count = 0;
|
||||
foreach (MethodInfo m in input.GetMethods(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
bool keyQuery = m.Name == "GetKey" || m.Name == "GetKeyDown" || m.Name == "GetKeyUp" ||
|
||||
m.Name == "GetButton" || m.Name == "GetButtonDown" || m.Name == "GetButtonUp";
|
||||
bool axisQuery = m.Name == "GetAxis" || m.Name == "GetAxisRaw";
|
||||
if (keyQuery && m.ReturnType == typeof(bool)) { harmony.Patch(m, boolPrefix, null); count++; }
|
||||
else if (axisQuery && m.ReturnType == typeof(float)) { harmony.Patch(m, floatPrefix, null); count++; }
|
||||
}
|
||||
ModConsole.Print("[MSCO] Game input is paused while typing (" + count + " cInput queries)");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ModConsole.Warning("[MSCO] Could not pause game input while typing: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Harmony-Prefixe: solange ein Eingabefenster offen ist, meldet cInput "nichts gedrückt"
|
||||
static bool NoKeyWhileLocked(ref bool __result)
|
||||
{
|
||||
if (!locked) return true;
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool NoAxisWhileLocked(ref float __result)
|
||||
{
|
||||
if (!locked) return true;
|
||||
__result = 0f;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user