From e290ab780b7f8d4a88338a50365d90a0e5847f9a Mon Sep 17 00:00:00 2001
From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com>
Date: Sat, 23 Mar 2024 15:07:25 -0700
Subject: [PATCH] feat: PatchOsuDirect
---
Osu.Patcher.Hook/Patches/BasePatch.cs | 4 --
Osu.Patcher.Hook/Patches/PatchOsuDirect.cs | 58 ++++++++++++++++++++++
Osu.Stubs/OsuDirect.cs | 34 +++++++++++++
3 files changed, 92 insertions(+), 4 deletions(-)
create mode 100644 Osu.Patcher.Hook/Patches/PatchOsuDirect.cs
create mode 100644 Osu.Stubs/OsuDirect.cs
diff --git a/Osu.Patcher.Hook/Patches/BasePatch.cs b/Osu.Patcher.Hook/Patches/BasePatch.cs
index f86b4a9..0603031 100644
--- a/Osu.Patcher.Hook/Patches/BasePatch.cs
+++ b/Osu.Patcher.Hook/Patches/BasePatch.cs
@@ -11,8 +11,6 @@ namespace Osu.Patcher.Hook.Patches;
///
public abstract class BasePatch
{
- #region Patching Utils
-
///
/// Finds and no-ops everything after a certain IL bytecode signature.
///
@@ -211,6 +209,4 @@ internal static IEnumerable InsertAfterSignature(
if (!found)
throw new Exception("Could not find the target signature in method!");
}
-
- #endregion
}
\ No newline at end of file
diff --git a/Osu.Patcher.Hook/Patches/PatchOsuDirect.cs b/Osu.Patcher.Hook/Patches/PatchOsuDirect.cs
new file mode 100644
index 0000000..6e79ca6
--- /dev/null
+++ b/Osu.Patcher.Hook/Patches/PatchOsuDirect.cs
@@ -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;
+
+///
+/// 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 osu.Online.OsuDirect:HandlePickup()
+///
+/// From:
+/// Permissions.None || ...)
+/// ]]>
+/// To:
+/// Permissions.None || ...)
+/// ]]>
+///
+[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 Transpiler(IEnumerable instructions) =>
+ InsertBeforeSignature(
+ instructions,
+ Signature,
+ new CodeInstruction[]
+ {
+ // Replace the result of Add with a higher value than compared against
+ new(Pop),
+ new(Ldc_I4_8),
+ }
+ );
+}
\ No newline at end of file
diff --git a/Osu.Stubs/OsuDirect.cs b/Osu.Stubs/OsuDirect.cs
new file mode 100644
index 0000000..ef8f150
--- /dev/null
+++ b/Osu.Stubs/OsuDirect.cs
@@ -0,0 +1,34 @@
+using JetBrains.Annotations;
+using Osu.Stubs.Opcode;
+using static System.Reflection.Emit.OpCodes;
+
+namespace Osu.Stubs;
+
+///
+/// Original: osu.Online.OsuDirect
+/// b20240102.2: #=zz3BVwBujgm4LKna55Dwx3UA=
+///
+public abstract class OsuDirect
+{
+ ///
+ /// Original: HandlePickup()
+ /// b20240102.2: #=zJczNz_3lxxrQQnnZog==
+ ///
+ [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,
+ }
+ );
+}
\ No newline at end of file