From a4601581315bdbd06770c5569ba5e2e817ded301 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Sun, 24 Mar 2024 10:14:07 -0700 Subject: [PATCH] feat: PatchEnableOptionsWhilePlaying --- .../Patches/PatchEnableOptionsWhilePlaying.cs | 55 +++++++++++++++++++ Osu.Stubs/Options.cs | 37 +++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs create mode 100644 Osu.Stubs/Options.cs diff --git a/Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs b/Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs new file mode 100644 index 0000000..d1d6f69 --- /dev/null +++ b/Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs @@ -0,0 +1,55 @@ +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 options screen to be expanded (with Ctrl-O) while in a Play state. +/// Changes the following code in osu.GameModes.Options.Options:get_CanExpand(): +///

+/// From: +/// +/// To: +/// +///
+[HarmonyPatch] +[UsedImplicitly] +public class PatchEnableOptionsWhilePlaying : BasePatch +{ + [UsedImplicitly] + [HarmonyTargetMethod] + private static MethodBase Target() => Options.GetCanExpand.Reference; + + [UsedImplicitly] + [HarmonyTranspiler] + private static IEnumerable Transpiler(IEnumerable instructions) => + InsertAfterSignature( + instructions, + new[] + { + Ldloc_2, + Ldloc_3, + And, + Ldc_I4_0, + Cgt, + // -- Inject right here to replace the result of Cgt -- + // Ret, + }, + new CodeInstruction[] + { + new(Pop), + new(Ldc_I4_1), // Push "true" onto stack + } + ); +} \ No newline at end of file diff --git a/Osu.Stubs/Options.cs b/Osu.Stubs/Options.cs new file mode 100644 index 0000000..1d2ab65 --- /dev/null +++ b/Osu.Stubs/Options.cs @@ -0,0 +1,37 @@ +using JetBrains.Annotations; +using Osu.Stubs.Opcode; +using static System.Reflection.Emit.OpCodes; + +namespace Osu.Stubs; + +/// +/// Original: osu.GameModes.Options.Options +/// b20240123: #=zIP$6zD_IcaL0ugvXAFTvJYG2gFLx +/// +[UsedImplicitly] +public class Options +{ + /// + /// Original: CanExpand (property getter) + /// b20240123: #=zxcgzxWXF$WLr + /// + [UsedImplicitly] + public static readonly LazyMethod GetCanExpand = new( + "Options#get_CanExpand", + new[] + { + Ldc_I4, + Stloc_1, + Ldsfld, + Ldloc_1, + Stloc_3, + Stloc_2, + Ldloc_2, + Ldloc_3, + And, + Ldc_I4_0, + Cgt, + Ret, + } + ); +} \ No newline at end of file