-
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
da5a600
commit afb58d0
Showing
18 changed files
with
511 additions
and
7 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
Osu.Patcher.Hook/Patches/LivePerformance/PatchAddPerformanceToUi.cs
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,70 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using Osu.Stubs; | ||
|
||
namespace Osu.Patcher.Hook.Patches.LivePerformance; | ||
|
||
/// <summary> | ||
/// Hooks the constructor of <c>ScoreDisplay</c> to add our own <c>pTextSprite</c> for displaying | ||
/// the performance counter to the ScoreDisplay's sprite manager. | ||
/// </summary> | ||
[HarmonyPatch] | ||
[UsedImplicitly] | ||
public class PatchAddPerformanceToScoreDisplay | ||
{ | ||
[UsedImplicitly] | ||
[HarmonyTargetMethod] | ||
private static MethodBase Target() => ScoreDisplay.Constructor.Reference; | ||
|
||
[UsedImplicitly] | ||
[HarmonyPostfix] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
private static void After( | ||
object __instance, // ScoreDisplay | ||
[HarmonyArgument(0)] object spriteManager, // SpriteManager | ||
[HarmonyArgument(1)] object position, // Vector2 | ||
[HarmonyArgument(2)] bool alignRight, | ||
[HarmonyArgument(3)] float scale, | ||
[HarmonyArgument(4)] bool showScore, | ||
[HarmonyArgument(5)] bool showAccuracy | ||
) | ||
{ | ||
var positionX = Vector2.X.Get(position); | ||
|
||
// TODO: use correct position | ||
var startPosition = ((ConstructorInfo)Vector2.Constructor.Reference).Invoke([positionX, 0f]); | ||
|
||
var performanceSprite = ((ConstructorInfo)pSpriteText.Constructor.Reference).Invoke( | ||
[ | ||
/* text: */ "0000.0", | ||
/* fontName: */ "", // TODO: use correct value | ||
/* spacingOverlap: */ 0f, // TODO: use correct value | ||
/* fieldType: */ alignRight ? Fields.TopRight : Fields.TopLeft, | ||
/* origin: */ alignRight ? Origins.TopRight : Origins.TopLeft, | ||
/* clock: */ Clocks.Game, | ||
/* startPosition: */ startPosition, | ||
/* drawDepth: */ 0.95f, | ||
/* alwaysDraw: */ true, | ||
/* color: */ Color.White, // TODO: try GhostWhite | ||
/* precache: */ true, | ||
/* source: */ SkinSource.All, | ||
]); | ||
|
||
SpriteManager.Add.Invoke(spriteManager, [performanceSprite]); | ||
PerformanceDisplay.SetPerformanceCounter(performanceSprite); | ||
} | ||
|
||
[UsedImplicitly] | ||
[HarmonyFinalizer] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
private static void Finalizer(Exception? __exception) | ||
{ | ||
if (__exception != null) | ||
{ | ||
Console.WriteLine($"Exception due to {nameof(PatchAddPerformanceToScoreDisplay)}: {__exception}"); | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
Osu.Patcher.Hook/Patches/LivePerformance/PerformanceDisplay.cs
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,42 @@ | ||
using System; | ||
using Osu.Stubs; | ||
|
||
namespace Osu.Patcher.Hook.Patches.LivePerformance; | ||
|
||
internal static class PerformanceDisplay | ||
{ | ||
/// <summary> | ||
/// The last known patched instance of our <c>pSpriteText</c> performance counter sprite. | ||
/// </summary> | ||
private static readonly WeakReference<object?> PerformanceCounter = new(null); | ||
|
||
/// <summary> | ||
/// Set a new active performance counter to update. | ||
/// </summary> | ||
/// <param name="sprite">The <c>pSpriteText</c> performance counter sprite.</param> | ||
public static void SetPerformanceCounter(object sprite) => | ||
PerformanceCounter.SetTarget(sprite); | ||
|
||
/// <summary> | ||
/// Change the pp value for the currently active performance counter. | ||
/// </summary> | ||
public static void UpdatePerformanceCounter(double pp) | ||
{ | ||
try | ||
{ | ||
var ruleset = Ruleset.Instance.Get(); | ||
|
||
var scoreDisplay = Ruleset.ScoreDisplay.Get(ruleset); | ||
if (scoreDisplay == null) return; | ||
|
||
if (!PerformanceCounter.TryGetTarget(out var sprite)) | ||
return; | ||
|
||
pText.SetText.Invoke(sprite, [$"{pp:00.0}pp"]); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Failed to set performance counter sprite text: {e}"); | ||
} | ||
} | ||
} |
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,16 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using JetBrains.Annotations; | ||
|
||
namespace Osu.Stubs; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.Graphics.Sprites.Clocks</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
public class Clocks | ||
{ | ||
public const int Game = 0; | ||
public const int Audio = 0; | ||
public const int AudioOnce = 0; | ||
} |
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
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,32 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using JetBrains.Annotations; | ||
|
||
namespace Osu.Stubs; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.Graphics.Sprites.Fields</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
public class Fields | ||
{ | ||
public const int GameField = 1; | ||
public const int GameFieldWide = 2; | ||
public const int Storyboard = 3; | ||
public const int StoryboardCentre = 4; | ||
public const int Native = 5; | ||
public const int TopLeft = 6; | ||
public const int TopCentre = 7; | ||
public const int TopRight = 8; | ||
public const int CentreLeft = 9; | ||
public const int Centre = 10; | ||
public const int CentreRight = 11; | ||
public const int BottomLeft = 12; | ||
public const int BottomCentre = 13; | ||
public const int BottomRight = 14; | ||
public const int StandardGameFieldScale = 15; | ||
public const int NativeStandardScale = 16; | ||
public const int NativeRight = 17; | ||
public const int NativeBottomRight = 18; | ||
public const int NativeBottomCentre = 19; | ||
} |
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ public class Logger | |
Leave_S, | ||
Ret, | ||
}, | ||
false, | ||
true | ||
); | ||
} |
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
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
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,23 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using JetBrains.Annotations; | ||
|
||
namespace Osu.Stubs; | ||
|
||
/// <summary> | ||
/// Original: <c>osu.Graphics.Sprites.Origins</c> | ||
/// </summary> | ||
[UsedImplicitly] | ||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
public class Origins | ||
{ | ||
public const int TopLeft = 0; | ||
public const int Centre = 1; | ||
public const int CentreLeft = 2; | ||
public const int TopRight = 3; | ||
public const int BottomCentre = 4; | ||
public const int TopCentre = 5; | ||
public const int Custom = 6; | ||
public const int CentreRight = 7; | ||
public const int BottomLeft = 8; | ||
public const int BottomRight = 9; | ||
} |
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
Oops, something went wrong.