-
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
1464569
commit 822a62e
Showing
3 changed files
with
135 additions
and
1 deletion.
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,72 @@ | ||
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> | ||
/// Changes the default alpha on beatmap thumbnails in song select. | ||
/// </summary> | ||
[HarmonyPatch] | ||
[UsedImplicitly] | ||
public class PatchBeatmapThumbnailAlpha : BasePatch | ||
{ | ||
// TODO: make this user configurable through settings | ||
private const int NewDeselectedAlpha = 185; // 0-255 | ||
|
||
[UsedImplicitly] | ||
[HarmonyTargetMethods] | ||
private static IEnumerable<MethodBase> Target() => | ||
[ | ||
BeatmapTreeItem.PopulateSprites.Reference, | ||
BeatmapTreeItem.UpdateSprites.Reference, | ||
]; | ||
|
||
/// <summary> | ||
/// Changes the target color used as an alpha overlay over the thumbnail. | ||
/// Replaces all <c>50</c>s as in <c>new Color(50, 50, 50, ...)</c> with a higher value. | ||
/// Applied to both <c>UpdateSprites</c> and <c>PopulateSprites</c>. | ||
/// </summary> | ||
[UsedImplicitly] | ||
[HarmonyTranspiler] | ||
private static IEnumerable<CodeInstruction> ChangeDeselectFade(IEnumerable<CodeInstruction> instructions) => | ||
instructions.Manipulator( | ||
inst => inst.Is(Ldc_I4_S, 50), | ||
inst => inst.operand = NewDeselectedAlpha | ||
); | ||
|
||
|
||
/// <summary> | ||
/// Avoid re-fading in from zero when alpha already high from previous patches. | ||
/// Replaces the following code with Nop: <code>thumbnail.FadeInFromZero(instant ? 0 : 1000);</code> | ||
/// This is only applicable to <c>UpdateSprites()</c>. | ||
/// </summary> | ||
[UsedImplicitly] | ||
[HarmonyTranspiler] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
private static IEnumerable<CodeInstruction> DisableFadeInFromZero( | ||
IEnumerable<CodeInstruction> instructions, | ||
MethodBase __originalMethod) | ||
{ | ||
if (__originalMethod != BeatmapTreeItem.UpdateSprites.Reference) | ||
return instructions; | ||
|
||
return NoopSignature(instructions, new[] | ||
{ | ||
Ldarg_0, | ||
Ldfld, | ||
Ldloc_0, | ||
Ldfld, | ||
Brtrue_S, | ||
Ldc_I4, | ||
Br_S, | ||
Ldc_I4_0, | ||
Callvirt, | ||
Pop, | ||
}); | ||
} | ||
} |
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,62 @@ | ||
using JetBrains.Annotations; | ||
using Osu.Stubs.Opcode; | ||
using static System.Reflection.Emit.OpCodes; | ||
|
||
namespace Osu.Stubs; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.GameplayElements.Beatmaps.BeatmapTreeItem</c> | ||
/// b20240102.2: <c>#=z5dQ2d9vSoRzE9rWp7h5_dJ$Z1Sw13QcKf_J$7ZjIN21zOue2gQ==</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
public static class BeatmapTreeItem | ||
{ | ||
/// <summary> | ||
/// Original: <c>PopulateSprites(TreeItemState lastState, bool instant)</c> | ||
/// b20240102.2: <c>#=ztf5JjnV1ubq2KLwXBg==</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
public static readonly LazyMethod UpdateSprites = new( | ||
"BeatmapTreeItem#UpdateSprites(...)", | ||
new[] | ||
{ | ||
Pop, | ||
Ldsfld, | ||
Ldftn, | ||
Newobj, | ||
Dup, | ||
Stsfld, | ||
Callvirt, | ||
Ret, | ||
Ldarg_0, | ||
Ldfld, | ||
Ldloc_0, | ||
Ldftn, | ||
Newobj, | ||
} | ||
); | ||
|
||
/// <summary> | ||
/// Original: <c>PopulateSprites()</c> | ||
/// b20240102.2: <c>#=zGdedQLY8W$wSqdNzBA==</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
public static readonly LazyMethod PopulateSprites = new( | ||
"BeatmapTreeItem#PopulateSprites()", | ||
new[] | ||
{ | ||
Brfalse, | ||
Ldsfld, | ||
Ldfld, | ||
Ldc_I4, | ||
Clt, | ||
Ldc_I4_0, | ||
Ceq, | ||
Stloc_S, | ||
Ldarg_0, | ||
Ldc_I4_5, | ||
Newarr, | ||
Dup, | ||
} | ||
); | ||
} |
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