-
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 66bece8
Showing
25 changed files
with
783 additions
and
11 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
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,98 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
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. | ||
/// This needs [email protected] or score-p.png in your skin's score font assets! | ||
/// </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 | ||
) | ||
{ | ||
var currentSkin = SkinManager.Current.Get(); | ||
var scoreFont = SkinOsu.FontScore.Get(currentSkin); | ||
var scoreFontOverlap = SkinOsu.FontScoreOverlap.Get(currentSkin); | ||
|
||
var performanceSprite = ((ConstructorInfo)pSpriteText.Constructor.Reference).Invoke( | ||
[ | ||
/* text: */ "00.0pp", | ||
/* fontName: */ scoreFont, | ||
/* spacingOverlap: */ (float)scoreFontOverlap, | ||
/* fieldType: */ alignRight ? Fields.TopRight : Fields.TopLeft, | ||
/* origin: */ alignRight ? Origins.TopRight : Origins.TopLeft, | ||
/* clock: */ Clocks.Game, | ||
/* startPosition: */ ((ConstructorInfo)Vector2.Constructor.Reference).Invoke([0f, 0f]), | ||
/* drawDepth: */ 0.95f, | ||
/* alwaysDraw: */ true, | ||
/* color: */ Color.White, | ||
/* precache: */ true, | ||
/* source: */ SkinSource.ExceptBeatmap, | ||
]); | ||
|
||
// Cannot be startPosition directly | ||
// TODO: don't add 9f offset if [email protected]/score-p.png texture exists | ||
var positionX = Vector2.X.Get(position) + 9f; | ||
var positionY = GetYOffset(Vector2.Y.Get(position), scale, __instance); | ||
var newPosition = ((ConstructorInfo)Vector2.Constructor.Reference).Invoke([positionX, positionY]); | ||
pDrawable.Position.Set(performanceSprite, newPosition); | ||
|
||
pDrawable.Scale.Set(performanceSprite, 0.50f); | ||
pSpriteText.TextConstantSpacing.Set(performanceSprite, true); | ||
pSpriteText.MeasureText.Invoke(performanceSprite); | ||
|
||
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}"); | ||
} | ||
} | ||
|
||
private static float GetYOffset(float baseYPosition, float scale, object scoreDisplay) | ||
{ | ||
// Read the heights of both pSpriteTexts: s_Score, s_Accuracy | ||
var sprites = ScoreDisplay.RuntimeType | ||
.GetDeclaredFields() | ||
.Where(f => f.FieldType == pSpriteText.RuntimeType) | ||
.Select(f => f.GetValue(scoreDisplay)); | ||
var spriteSizes = sprites | ||
.Where(s => s != null) | ||
.Select(s => pSpriteText.MeasureText.Invoke(s)); | ||
var totalSpriteHeight = spriteSizes.Sum(v => Vector2.Y.Get(v)) * 0.58f * scale; | ||
|
||
// Preserve additional spacing between s_Score and s_Accuracy | ||
var additionalOffset = SkinManager.GetUseNewLayout.Invoke() ? 3f : 0f; | ||
|
||
return baseYPosition + totalSpriteHeight + additionalOffset; | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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 | ||
{ | ||
if (!PerformanceCounter.TryGetTarget(out var sprite) || sprite == null) | ||
return; | ||
|
||
// Technically this should be run with "GameBase.Scheduler.AddOnce(() => ...)" but it works anyways, so... | ||
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
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; | ||
} |
Oops, something went wrong.