Skip to content

Commit

Permalink
feat: PatchEnableOptionsWhilePlaying
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 24, 2024
1 parent 822a62e commit a460158
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Osu.Patcher.Hook/Patches/PatchEnableOptionsWhilePlaying.cs
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
}
);
}
37 changes: 37 additions & 0 deletions Osu.Stubs/Options.cs
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,
}
);
}

0 comments on commit a460158

Please sign in to comment.