-
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.
- Loading branch information
1 parent
eb4aace
commit ee0e2ca
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
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,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using Osu.Stubs; | ||
using static System.Reflection.Emit.OpCodes; | ||
|
||
namespace Osu.Patcher.Hook.Patches; | ||
|
||
/// <summary> | ||
/// Makes the mods list overlay that is shown when entering play mode always show, like in a replay | ||
/// but faded to a user customizable amount. | ||
/// </summary> | ||
[HarmonyPatch] | ||
[UsedImplicitly] | ||
public class PatchShowModsInGameplay | ||
{ | ||
// TODO: make this user configurable | ||
private const float ModsNewAlpha = .2f; | ||
|
||
[UsedImplicitly] | ||
[HarmonyTargetMethod] | ||
private static MethodBase Target() => Player.OnLoadComplete.Reference; | ||
|
||
[UsedImplicitly] | ||
[HarmonyTranspiler] | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
// Replace a "0f" representing a fade target value after an arbitrary "94f" constant | ||
// Also set the pSprite parameter "alwaysDraw" to true | ||
|
||
var replaceState = ReplaceState.Find; | ||
|
||
return instructions.Manipulator( | ||
inst => | ||
{ | ||
switch (replaceState) | ||
{ | ||
case ReplaceState.Find when inst.Is(Ldc_R4, 94f): | ||
replaceState = ReplaceState.ReplaceAlwaysDraw; | ||
return false; | ||
|
||
// This is calling "InputManager.get_ReplayMode()" | ||
case ReplaceState.ReplaceAlwaysDraw when inst.opcode == Call: | ||
return true; | ||
|
||
// This is loading the transformation fade end value | ||
case ReplaceState.ReplaceFadeEndValue when inst.Is(Ldc_R4, 0f): | ||
return true; | ||
|
||
case ReplaceState.Finished: | ||
default: | ||
return false; | ||
} | ||
}, | ||
inst => | ||
{ | ||
switch (replaceState) | ||
{ | ||
case ReplaceState.ReplaceAlwaysDraw: | ||
inst.opcode = Ldc_I4_1; // Load "true" for the parameter "alwaysDraw" | ||
inst.operand = null; | ||
replaceState = ReplaceState.ReplaceFadeEndValue; | ||
break; | ||
case ReplaceState.ReplaceFadeEndValue: | ||
inst.operand = ModsNewAlpha; | ||
replaceState = ReplaceState.Finished; | ||
break; | ||
case ReplaceState.Find: | ||
case ReplaceState.Finished: | ||
default: | ||
throw new Exception(); | ||
} | ||
} | ||
); | ||
} | ||
|
||
[UsedImplicitly] | ||
[HarmonyFinalizer] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
private static void Finalizer(Exception? __exception) | ||
{ | ||
if (__exception != null) | ||
{ | ||
Console.WriteLine($"Exception due to {nameof(PatchShowModsInGameplay)}: {__exception}"); | ||
} | ||
} | ||
|
||
private enum ReplaceState | ||
{ | ||
Find, | ||
ReplaceAlwaysDraw, | ||
ReplaceFadeEndValue, | ||
Finished, | ||
} | ||
} |
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