Skip to content

Commit

Permalink
feat: PatchAllowPlayModeReload
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 24, 2024
1 parent 0b17ca0 commit 0e3e3a7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Osu.Patcher.Hook/Patches/PatchAllowPlayModeReload.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Allows the <c>Play</c> game mode to be reloaded without having the Autoplay mod.
/// This allows for automatically applying settings changes (in combination with the
/// <see cref="PatchEnableOptionsWhilePlaying" /> patch without having to exit play mode to apply changes.
/// Changes the following code in <c>osu.GameBase:get_ModeCanReload()</c>:
/// <br /><br />
/// From:
/// <code><![CDATA[
/// if (mode == OsuModes.Play) {
/// if (InputManager.ReplayScore == null)
/// return false;
/// ]]></code>
/// To:
/// <code><![CDATA[
/// if (mode == OsuModes.Play) {
/// return true;
/// ]]></code>
/// </summary>
[HarmonyPatch]
[UsedImplicitly]
public class PatchAllowPlayModeReload : BasePatch
{
[UsedImplicitly]
[HarmonyTargetMethod]
private static MethodBase Target() => GameBase.GetModeCanReload.Reference;

[UsedImplicitly]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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),
}
);
}
42 changes: 42 additions & 0 deletions Osu.Stubs/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,48 @@ namespace Osu.Stubs;
[UsedImplicitly]
public class GameBase
{
/// <summary>
/// Original: <c>get_ModeCanReload()</c>
/// b20240123: <c>#=zL6aRJUMxZO5fmlF9KQ==</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod<bool> 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,
}
);

// /// <summary>
// /// Original: <c>loadQueuedMode(int disposalDelay)</c>
// /// b20240123: <c>#=zCDewMhQMM5f_</c>
// /// </summary>
// [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,
// }
// );

/// <summary>
/// Original: <c>softHandle(Exception e)</c>
/// b20240123: <c>#=z8BJOiJxSLUwM</c>
Expand Down

0 comments on commit 0e3e3a7

Please sign in to comment.