feat: enhance hook patching with improved error handling and remove InputPausePatch
This commit is contained in:
Binary file not shown.
@@ -20,10 +20,13 @@ internal static class HookIntegration
|
||||
|
||||
var harmony = new HarmonyLib.Harmony("com.teamgreg.gregcore");
|
||||
|
||||
// [GREG_SYNC_INSERT_PATCHES]
|
||||
|
||||
SafePatch(harmony, typeof(Il2Cpp.Player), nameof(Il2Cpp.Player.UpdateCoin), typeof(gregCore.GameLayer.Patches.Economy.PlayerPatch), nameof(gregCore.GameLayer.Patches.Economy.PlayerPatch.OnCoinUpdated));
|
||||
|
||||
// Block Pause-Menu when Console is open
|
||||
SafePatch(harmony, typeof(global::Il2Cpp.InputController.IUIActions), nameof(global::Il2Cpp.InputController.IUIActions.OnPause), typeof(gregCore.GameLayer.Patches.UI.InputPausePatch), nameof(gregCore.GameLayer.Patches.UI.InputPausePatch.Prefix));
|
||||
// NOTE: Interface patching via IUIActions might cause native crashes in Unity 6.
|
||||
// SafePatch(harmony, typeof(global::Il2Cpp.InputController.IUIActions), nameof(global::Il2Cpp.InputController.IUIActions.OnPause), typeof(gregCore.GameLayer.Patches.UI.InputPausePatch), nameof(gregCore.GameLayer.Patches.UI.InputPausePatch.Prefix), isPrefix: true);
|
||||
}
|
||||
|
||||
internal static void Emit(HookName hook, EventPayload payload)
|
||||
@@ -40,18 +43,41 @@ internal static class HookIntegration
|
||||
_logger.Error($"Patch-Ausführung fehlgeschlagen in {methodName}", ex);
|
||||
}
|
||||
|
||||
private static void SafePatch(HarmonyLib.Harmony harmony, Type targetType, string methodName, Type postfixType, string postfixMethod)
|
||||
private static void SafePatch(HarmonyLib.Harmony harmony, Type targetType, string methodName, Type? patchType, string? patchMethod, bool isPrefix = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (targetType == null)
|
||||
{
|
||||
_logger.Warning($"Patch-Ziel-Typ ist null für {methodName}");
|
||||
return;
|
||||
}
|
||||
|
||||
var original = AccessTools.Method(targetType, methodName);
|
||||
var postfix = new HarmonyLib.HarmonyMethod(postfixType, postfixMethod);
|
||||
harmony.Patch(original, postfix: postfix);
|
||||
_logger.Debug($"Patch installiert: {targetType.Name}.{methodName}");
|
||||
if (original == null)
|
||||
{
|
||||
_logger.Warning($"Methode nicht gefunden: {targetType.FullName}.{methodName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (patchType == null || string.IsNullOrEmpty(patchMethod))
|
||||
{
|
||||
_logger.Warning($"Patch-Implementierung fehlt für {methodName}");
|
||||
return;
|
||||
}
|
||||
|
||||
var harmonyMethod = new HarmonyLib.HarmonyMethod(patchType, patchMethod);
|
||||
|
||||
if (isPrefix)
|
||||
harmony.Patch(original, prefix: harmonyMethod);
|
||||
else
|
||||
harmony.Patch(original, postfix: harmonyMethod);
|
||||
|
||||
_logger.Debug($"Patch installiert: {targetType.Name}.{methodName} ({(isPrefix ? "Prefix" : "Postfix")})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warning($"Patch fehlgeschlagen: {targetType.Name}.{methodName} — {ex.Message}");
|
||||
_logger.Warning($"Patch fehlgeschlagen: {targetType?.Name}.{methodName} — {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/// <file-summary>
|
||||
/// Schicht: GameLayer
|
||||
/// Zweck: Blockiert die Pause-Logik des Spiels wenn die Console offen ist.
|
||||
/// Maintainer: Harmony Patch. Zielt auf die InputSystem-Aktion 'Pause'.
|
||||
/// </file-summary>
|
||||
|
||||
using HarmonyLib;
|
||||
using gregCore.Infrastructure.UI;
|
||||
|
||||
namespace gregCore.GameLayer.Patches.UI;
|
||||
|
||||
[HarmonyPatch(typeof(global::Il2Cpp.InputController.IUIActions), nameof(global::Il2Cpp.InputController.IUIActions.OnPause))]
|
||||
internal static class InputPausePatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
internal static bool Prefix()
|
||||
{
|
||||
// Wenn die DevConsole offen ist, darf das Pause-Menü nicht aufgehen
|
||||
if (GregDevConsole.Instance.IsOpen)
|
||||
{
|
||||
return false; // Verhindert das Auslösen der Original-Methode
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user