diff --git a/Osu.Patcher.Hook/Patches/PatchLogSoftErrors.cs b/Osu.Patcher.Hook/Patches/PatchLogSoftErrors.cs new file mode 100644 index 0000000..cd80f72 --- /dev/null +++ b/Osu.Patcher.Hook/Patches/PatchLogSoftErrors.cs @@ -0,0 +1,24 @@ +using System; +using System.Reflection; +using HarmonyLib; +using JetBrains.Annotations; +using Osu.Stubs; + +namespace Osu.Patcher.Hook.Patches; + +/// +/// Hooks osu.GameBase:softHandle(Exception) to log all soft exceptions thrown inside osu! to our console. +/// +[HarmonyPatch] +[UsedImplicitly] +public class PatchLogSoftErrors +{ + [UsedImplicitly] + [HarmonyTargetMethod] + private static MethodBase Target() => GameBase.SoftHandle.Reference; + + [UsedImplicitly] + [HarmonyPrefix] + private static void Before([HarmonyArgument(0)] Exception exception) => + Console.WriteLine($"osu! experienced an internal error: {exception}"); +} \ No newline at end of file diff --git a/Osu.Stubs/EventManager.cs b/Osu.Stubs/EventManager.cs index 18fd396..a67e5c4 100644 --- a/Osu.Stubs/EventManager.cs +++ b/Osu.Stubs/EventManager.cs @@ -17,7 +17,6 @@ public static class EventManager /// Original: set_ShowStoryboard (property setter) /// b20240102.2: #=zKZugEelWoTXb /// - /// [UsedImplicitly] public static readonly LazyMethod SetShowStoryboard = new( "EventManager#ShowStoryboard.set", diff --git a/Osu.Stubs/GameBase.cs b/Osu.Stubs/GameBase.cs new file mode 100644 index 0000000..89f38ad --- /dev/null +++ b/Osu.Stubs/GameBase.cs @@ -0,0 +1,35 @@ +using JetBrains.Annotations; +using Osu.Stubs.Opcode; +using static System.Reflection.Emit.OpCodes; + +namespace Osu.Stubs; + +/// +/// Original: osu.GameBase +/// b20240123: #=zduF3QmjgMG4eSc$fOQ== +/// +[UsedImplicitly] +public class GameBase +{ + /// + /// Original: softHandle(Exception e) + /// b20240123: #=z8BJOiJxSLUwM + /// + [UsedImplicitly] + public static readonly LazyMethod SoftHandle = new( + "GameBase#softHandle(...)", + new[] + { + Ldarg_0, + Isinst, + Brtrue_S, + Ldarg_0, + Isinst, + Brtrue_S, + Ldarg_0, + Isinst, + Brfalse_S, + Ldc_I4_8, + } + ); +} \ No newline at end of file