From 0e3e3a72de043cc63f337a1c490e677b4ec60d32 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:54:34 -0700 Subject: [PATCH] feat: PatchAllowPlayModeReload --- .../Patches/PatchAllowPlayModeReload.cs | 57 +++++++++++++++++++ Osu.Stubs/GameBase.cs | 42 ++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 Osu.Patcher.Hook/Patches/PatchAllowPlayModeReload.cs diff --git a/Osu.Patcher.Hook/Patches/PatchAllowPlayModeReload.cs b/Osu.Patcher.Hook/Patches/PatchAllowPlayModeReload.cs new file mode 100644 index 0000000..68b238b --- /dev/null +++ b/Osu.Patcher.Hook/Patches/PatchAllowPlayModeReload.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using System.Reflection; +using HarmonyLib; +using JetBrains.Annotations; +using Osu.Stubs; +using static System.Reflection.Emit.OpCodes; + +namespace Osu.Patcher.Hook.Patches; + +/// +/// Allows the Play game mode to be reloaded without having the Autoplay mod. +/// This allows for automatically applying settings changes (in combination with the +/// patch without having to exit play mode to apply changes. +/// Changes the following code in osu.GameBase:get_ModeCanReload(): +///

+/// From: +/// +/// To: +/// +///
+[HarmonyPatch] +[UsedImplicitly] +public class PatchAllowPlayModeReload : BasePatch +{ + [UsedImplicitly] + [HarmonyTargetMethod] + private static MethodBase Target() => GameBase.GetModeCanReload.Reference; + + [UsedImplicitly] + [HarmonyTranspiler] + private static IEnumerable Transpiler(IEnumerable instructions) => + InsertBeforeSignature( + instructions, + new[] + { + // Ldsfld, // Loads the ReplayScore to check if it's null + // -- Inject right here to override the value -- + Brfalse_S, + Ldsfld, + Ldfld, + Call, + }, + new CodeInstruction[] + { + new(Pop), + new(Ldc_I4_1), + new(Ret), + } + ); +} \ No newline at end of file diff --git a/Osu.Stubs/GameBase.cs b/Osu.Stubs/GameBase.cs index 89f38ad..41dd40c 100644 --- a/Osu.Stubs/GameBase.cs +++ b/Osu.Stubs/GameBase.cs @@ -11,6 +11,48 @@ namespace Osu.Stubs; [UsedImplicitly] public class GameBase { + /// + /// Original: get_ModeCanReload() + /// b20240123: #=zL6aRJUMxZO5fmlF9KQ== + /// + [UsedImplicitly] + public static readonly LazyMethod GetModeCanReload = new( + "GameBase#get_ModeCanReload()", + new[] + { + Ldc_I4_7, + Bgt_S, + Ldloc_0, + Ldc_I4_2, + Beq_S, + Ldloc_0, + Ldc_I4_7, + Beq_S, + Br_S, + } + ); + + // /// + // /// Original: loadQueuedMode(int disposalDelay) + // /// b20240123: #=zCDewMhQMM5f_ + // /// + // [UsedImplicitly] + // public static readonly LazyMethod LoadQueuedMode = new( + // "GameBase#loadQueuedMode(...)", + // new[] + // { + // Initobj, + // Ldloc_S, + // Ldloca_S, + // Initobj, + // Ldloc_S, + // Ldc_I4_0, + // Ldc_I4_0, + // Call, + // Ldnull, + // } + // ); + /// /// Original: softHandle(Exception e) /// b20240123: #=z8BJOiJxSLUwM