Skip to content

Commit

Permalink
feat: PatchLogSoftErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 24, 2024
1 parent a460158 commit 0b17ca0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Osu.Patcher.Hook/Patches/PatchLogSoftErrors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Reflection;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;

namespace Osu.Patcher.Hook.Patches;

/// <summary>
/// Hooks <c>osu.GameBase:softHandle(Exception)</c> to log all soft exceptions thrown inside osu! to our console.
/// </summary>
[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}");
}
1 change: 0 additions & 1 deletion Osu.Stubs/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static class EventManager
/// Original: <c>set_ShowStoryboard</c> (property setter)
/// b20240102.2: <c>#=zKZugEelWoTXb</c>
/// </summary>
/// <returns></returns>
[UsedImplicitly]
public static readonly LazyMethod SetShowStoryboard = new(
"EventManager#ShowStoryboard.set",
Expand Down
35 changes: 35 additions & 0 deletions Osu.Stubs/GameBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using JetBrains.Annotations;
using Osu.Stubs.Opcode;
using static System.Reflection.Emit.OpCodes;

namespace Osu.Stubs;

/// <summary>
/// Original: <c>osu.GameBase</c>
/// b20240123: <c>#=zduF3QmjgMG4eSc$fOQ==</c>
/// </summary>
[UsedImplicitly]
public class GameBase
{
/// <summary>
/// Original: <c>softHandle(Exception e)</c>
/// b20240123: <c>#=z8BJOiJxSLUwM</c>
/// </summary>
[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,
}
);
}

0 comments on commit 0b17ca0

Please sign in to comment.