Skip to content

Commit

Permalink
feat: PatchOsuDirect
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 23, 2024
1 parent 602f37c commit e290ab7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Osu.Patcher.Hook/Patches/BasePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Osu.Patcher.Hook.Patches;
/// </summary>
public abstract class BasePatch
{
#region Patching Utils

/// <summary>
/// Finds and no-ops everything after a certain IL bytecode signature.
/// </summary>
Expand Down Expand Up @@ -211,6 +209,4 @@ internal static IEnumerable<CodeInstruction> InsertAfterSignature(
if (!found)
throw new Exception("Could not find the target signature in method!");
}

#endregion
}
58 changes: 58 additions & 0 deletions Osu.Patcher.Hook/Patches/PatchOsuDirect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using JetBrains.Annotations;
using Osu.Stubs;
using static System.Reflection.Emit.OpCodes;

namespace Osu.Patcher.Hook.Patches;

/// <summary>
/// Re-enable osu!direct. This has no impact on Bancho since you can't even use this project on Bancho.
/// Changes the following code in <c>osu.Online.OsuDirect:HandlePickup()</c>
/// <br /><br />
/// From:
/// <code><![CDATA[
/// if (BanchoClient.Permission & Permissions.Supporter > Permissions.None || ...)
/// ]]></code>
/// To:
/// <code><![CDATA[
/// if ((BanchoClient.Permission & Permissions.Supporter) + 8 > Permissions.None || ...)
/// ]]></code>
/// </summary>
[HarmonyPatch]
[UsedImplicitly]
public class PatchOsuDirect : BasePatch
{
private static readonly OpCode[] Signature =
{
// Call,
// Ldc_I4_4,
// And,
// -- Inject right here to replace the result of And --
Ldc_I4_0,
Bgt_S,
Ldsfld,
Call,
Ldc_I4_S,
};

[UsedImplicitly]
[HarmonyTargetMethod]
private static MethodBase Target() => OsuDirect.HandlePickup.Reference;

[UsedImplicitly]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) =>
InsertBeforeSignature(
instructions,
Signature,
new CodeInstruction[]
{
// Replace the result of Add with a higher value than compared against
new(Pop),
new(Ldc_I4_8),
}
);
}
34 changes: 34 additions & 0 deletions Osu.Stubs/OsuDirect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using JetBrains.Annotations;
using Osu.Stubs.Opcode;
using static System.Reflection.Emit.OpCodes;

namespace Osu.Stubs;

/// <summary>
/// Original: <c>osu.Online.OsuDirect</c>
/// b20240102.2: <c>#=zz3BVwBujgm4LKna55Dwx3UA=</c>
/// </summary>
public abstract class OsuDirect
{
/// <summary>
/// Original: <c>HandlePickup()</c>
/// b20240102.2: <c>#=zJczNz_3lxxrQQnnZog==</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod HandlePickup = new(
"osu.Online.OsuDirect#HandlePickup",
new[]
{
Ldloc_0,
Ldfld,
Ldloc_0,
Ldflda,
Call,
Ldloc_0,
Ldftn,
Newobj,
Call,
Ret,
}
);
}

0 comments on commit e290ab7

Please sign in to comment.