From 1c39e58cc84ffa7e0de12df0bed962175bbcb55f Mon Sep 17 00:00:00 2001
From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com>
Date: Sat, 30 Mar 2024 23:36:33 -0700
Subject: [PATCH] refactor(stubs): restructure lazys & clean up stubs
---
.../LivePerformance/AddPerformanceToUi.cs | 10 +--
Osu.Stubs/Beatmap.cs | 61 +++++++------
Osu.Stubs/BeatmapTreeItem.cs | 22 ++---
Osu.Stubs/BeatmapTreeManager.cs | 6 +-
Osu.Stubs/Bindable.cs | 25 +++---
Osu.Stubs/ErrorSubmission.cs | 12 ++-
Osu.Stubs/EventManager.cs | 17 ++--
Osu.Stubs/GameBase.cs | 24 +++--
Osu.Stubs/IncreaseScoreType.cs | 24 ++---
Osu.Stubs/Logger.cs | 16 ++--
Osu.Stubs/NotificationManager.cs | 12 ++-
Osu.Stubs/Obfuscated.cs | 47 +++++-----
Osu.Stubs/Options.cs | 9 +-
Osu.Stubs/OsuDirect.cs | 15 ++--
Osu.Stubs/Player.cs | 48 +++++-----
Osu.Stubs/Ruleset.cs | 73 +++++++--------
Osu.Stubs/Score.cs | 88 ++++++++++---------
Osu.Stubs/ScoreChange.cs | 51 ++++++-----
Osu.Stubs/ScoreDisplay.cs | 49 +++++------
Osu.Stubs/ScoreProcessor.cs | 31 +++----
Osu.Stubs/SkinManager.cs | 34 ++++---
Osu.Stubs/SkinOsu.cs | 27 +++---
Osu.Stubs/SongSelection.cs | 24 +++--
Osu.Stubs/SpriteManager.cs | 31 ++++---
Osu.Stubs/Vector2.cs | 34 ++++---
Osu.Stubs/Wrappers/Clocks.cs | 6 +-
Osu.Stubs/Wrappers/Color.cs | 2 +
Osu.Stubs/Wrappers/Fields.cs | 4 +-
Osu.Stubs/Wrappers/Notifications.cs | 3 +-
Osu.Stubs/Wrappers/Origins.cs | 6 +-
Osu.Stubs/Wrappers/SkinSource.cs | 7 +-
Osu.Stubs/Wrappers/VoidDelegate.cs | 4 +-
Osu.Stubs/pDrawable.cs | 51 +++++------
Osu.Stubs/pSpriteText.cs | 46 +++++-----
Osu.Stubs/pText.cs | 15 ++--
Osu.Utils/Extensions/ArrayExtensions.cs | 4 -
Osu.Utils/Extensions/TranspilerExtensions.cs | 6 --
Osu.Utils/Lazy/LazyConstructor.cs | 47 ++++++++++
Osu.Utils/Lazy/LazyField.cs | 26 ++----
Osu.Utils/Lazy/LazyInfo.cs | 56 ++++++++++++
Osu.Utils/Lazy/LazyMethod.cs | 87 +++++++++---------
Osu.Utils/Lazy/LazyType.cs | 41 +++++++++
42 files changed, 634 insertions(+), 567 deletions(-)
create mode 100644 Osu.Utils/Lazy/LazyConstructor.cs
create mode 100644 Osu.Utils/Lazy/LazyInfo.cs
create mode 100644 Osu.Utils/Lazy/LazyType.cs
diff --git a/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs b/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs
index f95bd82..d2b65d3 100644
--- a/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs
+++ b/Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs
@@ -40,7 +40,7 @@ private static void After(
var scoreFont = SkinOsu.FontScore.Get(currentSkin);
var scoreFontOverlap = SkinOsu.FontScoreOverlap.Get(currentSkin);
- var performanceSprite = ((ConstructorInfo)pSpriteText.Constructor.Reference).Invoke(
+ var performanceSprite = pSpriteText.Constructor.Invoke(
[
/* text: */ "00.0pp",
/* fontName: */ scoreFont,
@@ -48,7 +48,7 @@ private static void After(
/* fieldType: */ alignRight ? Fields.TopRight : Fields.TopLeft,
/* origin: */ alignRight ? Origins.TopRight : Origins.TopLeft,
/* clock: */ Clocks.Game,
- /* startPosition: */ ((ConstructorInfo)Vector2.Constructor.Reference).Invoke([0f, 0f]),
+ /* startPosition: */ Vector2.Constructor.Invoke([0f, 0f]),
/* drawDepth: */ 0.95f,
/* alwaysDraw: */ true,
/* color: */ Color.White,
@@ -60,7 +60,7 @@ private static void After(
// TODO: don't add 9f offset if score-p@2x.png/score-p.png texture exists
var positionX = Vector2.X.Get(position) + 8f;
var positionY = GetYOffset(Vector2.Y.Get(position), scale, __instance);
- var newPosition = ((ConstructorInfo)Vector2.Constructor.Reference).Invoke([positionX, positionY]);
+ var newPosition = Vector2.Constructor.Invoke([positionX, positionY]);
pDrawable.Position.Set(performanceSprite, newPosition);
pDrawable.Scale.Set(performanceSprite, 0.50f);
@@ -76,9 +76,9 @@ private static void After(
private static float GetYOffset(float baseYPosition, float scale, object scoreDisplay)
{
// Read the heights of both pSpriteTexts: s_Score, s_Accuracy
- var sprites = ScoreDisplay.RuntimeType
+ var sprites = ScoreDisplay.Class.Reference
.GetDeclaredFields()
- .Where(f => f.FieldType == pSpriteText.RuntimeType)
+ .Where(f => f.FieldType == pSpriteText.Class.Reference)
.Select(f => f.GetValue(scoreDisplay));
var spriteSizes = sprites
.Where(s => s != null)
diff --git a/Osu.Stubs/Beatmap.cs b/Osu.Stubs/Beatmap.cs
index d90bbe7..88d0103 100644
--- a/Osu.Stubs/Beatmap.cs
+++ b/Osu.Stubs/Beatmap.cs
@@ -1,4 +1,3 @@
-using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -11,21 +10,38 @@
namespace Osu.Stubs;
-///
-/// Original: osu.GameplayElements.Beatmaps.Beatmap
-/// b20240123: #=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf
-///
-[UsedImplicitly]
+[PublicAPI]
public static class Beatmap
{
+ ///
+ /// Original: osu.GameplayElements.Beatmaps.Beatmap
+ /// b20240123: #=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf
+ ///
+ public static readonly LazyType Class = new(
+ "osu.GameplayElements.Beatmaps.Beatmap",
+ () => Score.Constructor.Reference
+ .GetParameters()[1] // 2nd param is of type Beatmap
+ .ParameterType
+ );
+
+ ///
+ /// Original: Beatmap(string filename)
+ /// b20240123: #=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf
+ ///
+ public static readonly LazyConstructor Constructor = new(
+ "osu.GameplayElements.Beatmaps.Beatmap::Beatmap(string)",
+ () => Class.Reference
+ .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
+ .Single()
+ );
+
///
/// Original: Unknown, best guess: SetContainingFolder(string absoluteDirPath)
/// b20240123: #=zQwzJucCIbIUZrSZR8Q==
///
- private static readonly LazyMethod SetContainingFolder = new(
- "Beatmap#SetContainingFolder(...)",
- new[]
- {
+ private static readonly LazyMethod SetContainingFolder = LazyMethod.ByPartialSignature(
+ "osu.GameplayElements.Beatmaps.Beatmap::[unknown, SetContainingFolder?]",
+ [
Callvirt,
Starg_S,
Ldarg_0,
@@ -39,21 +55,20 @@ public static class Beatmap
Callvirt,
Stfld, // Reference to ContainingFolder
Ret,
- }
+ ]
);
///
/// Original: Filename
/// b20240123: #=zdZI_NOQ=
///
- [UsedImplicitly]
public static readonly LazyField Filename = new(
- "Beatmap#Filename",
+ "osu.GameplayElements.Beatmaps.Beatmap::Filename",
() =>
{
// Find the field this code is referencing: "this.Filename = Path.GetFileName(filename);"
var findMethod = typeof(Path).GetMethod(nameof(Path.GetFileName))!;
- var storeInstruction = MethodReader.GetInstructions(PrimaryConstructor)
+ var storeInstruction = MethodReader.GetInstructions(Constructor.Reference)
.SkipWhile(inst => !findMethod.Equals(inst.Operand))
.Skip(1)
.First();
@@ -68,9 +83,8 @@ public static class Beatmap
/// Original: Unknown, best guess: ContainingFolder (not absolute)
/// b20240123: #=zDmW9P6igScNm
///
- [UsedImplicitly]
public static readonly LazyField ContainingFolder = new(
- "Beatmap#ContainingFolder",
+ "osu.GameplayElements.Beatmaps.Beatmap::ContainingFolder",
() =>
{
// Last Stfld is a reference to ContainingFolder
@@ -83,26 +97,11 @@ public static class Beatmap
}
);
- ///
- /// Original: Beatmap(string filename)
- /// b20240123: #=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf
- ///
- [UsedImplicitly]
- public static ConstructorInfo PrimaryConstructor => RuntimeType
- .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
- .Single();
-
- [UsedImplicitly]
- public static Type RuntimeType => (Score.ConstructorFromReplayAndMap.Reference as ConstructorInfo)!
- .GetParameters()[1] // 2nd param is of type Beatmap
- .ParameterType;
-
///
/// Utility wrapper to get the full beatmap path of a Beatmap.
///
/// An instance of Beatmap that was initialized with the filepath.
/// The absolute path, or null if this isn't a file-backed Beatmap.
- [UsedImplicitly]
public static string? GetBeatmapPath(object beatmap)
{
var filename = Filename.Get(beatmap);
diff --git a/Osu.Stubs/BeatmapTreeItem.cs b/Osu.Stubs/BeatmapTreeItem.cs
index 4a006e6..1b8b151 100644
--- a/Osu.Stubs/BeatmapTreeItem.cs
+++ b/Osu.Stubs/BeatmapTreeItem.cs
@@ -8,18 +8,16 @@ namespace Osu.Stubs;
/// Original: osu.GameplayElements.Beatmaps.BeatmapTreeItem
/// b20240102.2: #=z5dQ2d9vSoRzE9rWp7h5_dJ$Z1Sw13QcKf_J$7ZjIN21zOue2gQ==
///
-[UsedImplicitly]
+[PublicAPI]
public static class BeatmapTreeItem
{
///
/// Original: PopulateSprites(TreeItemState lastState, bool instant)
/// b20240102.2: #=ztf5JjnV1ubq2KLwXBg==
///
- [UsedImplicitly]
- public static readonly LazyMethod UpdateSprites = new(
- "BeatmapTreeItem#UpdateSprites(...)",
- new[]
- {
+ public static readonly LazyMethod UpdateSprites = LazyMethod.ByPartialSignature(
+ "osu.GameplayElements.Beatmaps.BeatmapTreeItem::UpdateSprites(TreeItemState, bool)",
+ [
Pop,
Ldsfld,
Ldftn,
@@ -33,18 +31,16 @@ public static class BeatmapTreeItem
Ldloc_0,
Ldftn,
Newobj,
- }
+ ]
);
///
/// Original: PopulateSprites()
/// b20240102.2: #=zGdedQLY8W$wSqdNzBA==
///
- [UsedImplicitly]
- public static readonly LazyMethod PopulateSprites = new(
- "BeatmapTreeItem#PopulateSprites()",
- new[]
- {
+ public static readonly LazyMethod PopulateSprites = LazyMethod.ByPartialSignature(
+ "osu.GameplayElements.Beatmaps.BeatmapTreeItem::PopulateSprites()",
+ [
Brfalse,
Ldsfld,
Ldfld,
@@ -57,6 +53,6 @@ public static class BeatmapTreeItem
Ldc_I4_5,
Newarr,
Dup,
- }
+ ]
);
}
\ No newline at end of file
diff --git a/Osu.Stubs/BeatmapTreeManager.cs b/Osu.Stubs/BeatmapTreeManager.cs
index 35b84e9..07dcbd7 100644
--- a/Osu.Stubs/BeatmapTreeManager.cs
+++ b/Osu.Stubs/BeatmapTreeManager.cs
@@ -7,15 +7,15 @@ namespace Osu.Stubs;
/// Original: osu.GameplayElements.Beatmaps.BeatmapTreeManager
/// b20240102.2: #=zV51QPv13Z_vZJRxEY28cvGye77gU6YZQsv_F5muuWuN62V5sIQ==
///
-[UsedImplicitly]
+[PublicAPI]
public static class BeatmapTreeManager
{
///
- /// Original: CurrentGroupMode of type ]]>
+ /// Original: CurrentGroupMode of type Bindable{TreeGroupMode}
/// b20240102.2: #=zbF4rnAiPRGJl
///
public static readonly LazyField