-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PatchEnableOptionsWhilePlaying
- Loading branch information
1 parent
822a62e
commit a460158
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// Allows the options screen to be expanded (with Ctrl-O) while in a Play state. | ||
/// Changes the following code in <c>osu.GameModes.Options.Options:get_CanExpand()</c>: | ||
/// <br /><br /> | ||
/// From: | ||
/// <code><![CDATA[ | ||
/// case OsuModes.Play: | ||
/// return ModManager.CheckActive(Mods.Autoplay); | ||
/// ]]></code> | ||
/// To: | ||
/// <code><![CDATA[ | ||
/// case OsuModes.Play: | ||
/// ModManager.CheckActive(Mods.Autoplay); | ||
/// return true; | ||
/// ]]></code> | ||
/// </summary> | ||
[HarmonyPatch] | ||
[UsedImplicitly] | ||
public class PatchEnableOptionsWhilePlaying : BasePatch | ||
{ | ||
[UsedImplicitly] | ||
[HarmonyTargetMethod] | ||
private static MethodBase Target() => Options.GetCanExpand.Reference; | ||
|
||
[UsedImplicitly] | ||
[HarmonyTranspiler] | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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 | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using JetBrains.Annotations; | ||
using Osu.Stubs.Opcode; | ||
using static System.Reflection.Emit.OpCodes; | ||
|
||
namespace Osu.Stubs; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.GameModes.Options.Options</c> | ||
/// b20240123: <c>#=zIP$6zD_IcaL0ugvXAFTvJYG2gFLx</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
public class Options | ||
{ | ||
/// <summary> | ||
/// Original: <c>CanExpand</c> (property getter) | ||
/// b20240123: <c>#=zxcgzxWXF$WLr</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
public static readonly LazyMethod<bool> 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, | ||
} | ||
); | ||
} |