Skip to content

Commit

Permalink
refactor(stubs): restructure lazys & clean up stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 31, 2024
1 parent f51439d commit 1c39e58
Show file tree
Hide file tree
Showing 42 changed files with 634 additions and 567 deletions.
10 changes: 5 additions & 5 deletions Osu.Patcher.Hook/Patches/LivePerformance/AddPerformanceToUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ 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,
/* 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]),
/* startPosition: */ Vector2.Constructor.Invoke([0f, 0f]),
/* drawDepth: */ 0.95f,
/* alwaysDraw: */ true,
/* color: */ Color.White,
Expand All @@ -60,7 +60,7 @@ private static void After(
// TODO: don't add 9f offset if [email protected]/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);
Expand All @@ -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)
Expand Down
61 changes: 30 additions & 31 deletions Osu.Stubs/Beatmap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -11,21 +10,38 @@

namespace Osu.Stubs;

/// <summary>
/// Original: <c>osu.GameplayElements.Beatmaps.Beatmap</c>
/// b20240123: <c>#=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
public static class Beatmap
{
/// <summary>
/// Original: <c>osu.GameplayElements.Beatmaps.Beatmap</c>
/// b20240123: <c>#=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf</c>
/// </summary>
public static readonly LazyType Class = new(
"osu.GameplayElements.Beatmaps.Beatmap",
() => Score.Constructor.Reference
.GetParameters()[1] // 2nd param is of type Beatmap
.ParameterType
);

/// <summary>
/// Original: <c>Beatmap(string filename)</c>
/// b20240123: <c>#=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf</c>
/// </summary>
public static readonly LazyConstructor Constructor = new(
"osu.GameplayElements.Beatmaps.Beatmap::Beatmap(string)",
() => Class.Reference
.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
.Single()
);

/// <summary>
/// Original: Unknown, best guess: <c>SetContainingFolder(string absoluteDirPath)</c>
/// b20240123: <c>#=zQwzJucCIbIUZrSZR8Q==</c>
/// </summary>
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,
Expand All @@ -39,21 +55,20 @@ public static class Beatmap
Callvirt,
Stfld, // Reference to ContainingFolder
Ret,
}
]
);

/// <summary>
/// Original: <c>Filename</c>
/// b20240123: <c>#=zdZI_NOQ=</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyField<string?> 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();
Expand All @@ -68,9 +83,8 @@ public static class Beatmap
/// Original: Unknown, best guess: <c>ContainingFolder</c> (not absolute)
/// b20240123: <c>#=zDmW9P6igScNm</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyField<string?> ContainingFolder = new(
"Beatmap#ContainingFolder",
"osu.GameplayElements.Beatmaps.Beatmap::ContainingFolder",
() =>
{
// Last Stfld is a reference to ContainingFolder
Expand All @@ -83,26 +97,11 @@ public static class Beatmap
}
);

/// <summary>
/// Original: <c>Beatmap(string filename)</c>
/// b20240123: <c>#=znWyq67N7qygzmzTavD7zPPRqI0zwVZPmTyOyayVHbxCf</c>
/// </summary>
[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;

/// <summary>
/// Utility wrapper to get the full beatmap path of a <c>Beatmap</c>.
/// </summary>
/// <param name="beatmap">An instance of <c>Beatmap</c> that was initialized with the filepath.</param>
/// <returns>The absolute path, or null if this isn't a file-backed Beatmap.</returns>
[UsedImplicitly]
public static string? GetBeatmapPath(object beatmap)
{
var filename = Filename.Get(beatmap);
Expand Down
22 changes: 9 additions & 13 deletions Osu.Stubs/BeatmapTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ namespace Osu.Stubs;
/// Original: <c>osu.GameplayElements.Beatmaps.BeatmapTreeItem</c>
/// b20240102.2: <c>#=z5dQ2d9vSoRzE9rWp7h5_dJ$Z1Sw13QcKf_J$7ZjIN21zOue2gQ==</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
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[]
{
public static readonly LazyMethod UpdateSprites = LazyMethod.ByPartialSignature(
"osu.GameplayElements.Beatmaps.BeatmapTreeItem::UpdateSprites(TreeItemState, bool)",
[
Pop,
Ldsfld,
Ldftn,
Expand All @@ -33,18 +31,16 @@ public static class BeatmapTreeItem
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[]
{
public static readonly LazyMethod PopulateSprites = LazyMethod.ByPartialSignature(
"osu.GameplayElements.Beatmaps.BeatmapTreeItem::PopulateSprites()",
[
Brfalse,
Ldsfld,
Ldfld,
Expand All @@ -57,6 +53,6 @@ public static class BeatmapTreeItem
Ldc_I4_5,
Newarr,
Dup,
}
]
);
}
6 changes: 3 additions & 3 deletions Osu.Stubs/BeatmapTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Osu.Stubs;
/// Original: <c>osu.GameplayElements.Beatmaps.BeatmapTreeManager</c>
/// b20240102.2: <c>#=zV51QPv13Z_vZJRxEY28cvGye77gU6YZQsv_F5muuWuN62V5sIQ==</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
public static class BeatmapTreeManager
{
/// <summary>
/// Original: <c>CurrentGroupMode</c> of type <c><![CDATA[ Bindable<TreeGroupMode> ]]></c>
/// Original: <c>CurrentGroupMode</c> of type <c>Bindable{TreeGroupMode}</c>
/// b20240102.2: <c>#=zbF4rnAiPRGJl</c>
/// </summary>
public static readonly LazyField<object> CurrentGroupMode = new(
"BeatmapTreeManager#CurrentGroupMode",
"osu.GameplayElements.Beatmaps.BeatmapTreeManager::CurrentGroupMode",
() => SongSelection.FindReferences().CurrentGroupMode
);
}
25 changes: 14 additions & 11 deletions Osu.Stubs/Bindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ namespace Osu.Stubs;
/// Original: <c>osu.Helpers.Bindable</c>
/// b20240102.2: <c>#=zDruHkLGdhQjyjYxqzw==</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
public static class Bindable
{
/// <summary>
/// Original: <c>Value.get</c> (property getter method)
/// Original: <c>get_Value()</c> (property getter method)
/// b20240102.2: <c>#=zHO4Uaog=</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod<object> GetValue = new("Bindable#Value.get", () =>
{
var instructions = MethodReader.GetInstructions(SongSelection.BeatmapTreeManagerOnRightClicked.Reference);
public static readonly LazyMethod<object> GetValue = new(
"osu.Helpers.Bindable::get_Value()",
() =>
{
var instructions = MethodReader
.GetInstructions(SongSelection.BeatmapTreeManagerOnRightClicked.Reference);

// Get reference to Bindable:Value.get (property getter)
return (MethodBase)instructions
.First(inst => inst.Opcode == Callvirt)
.Operand;
});
// Get reference to Bindable:Value.get (property getter)
return (MethodInfo)instructions
.First(inst => inst.Opcode == Callvirt)
.Operand;
}
);
}
12 changes: 5 additions & 7 deletions Osu.Stubs/ErrorSubmission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ namespace Osu.Stubs;
/// Original: <c>osu.Helpers.ErrorSubmission</c>
/// v20230326: <c>#=zhC91LB1xsJMwYkF0UQ==</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
public static class ErrorSubmission
{
/// <summary>
/// Original: osu.Helpers.ErrorSubmission:Submit(OsuError)
/// v20230326: #=zhC91LB1xsJMwYkF0UQ==:#=zPqLxZPA=
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod Submit = new(
"ErrorSubmission#Submit",
new[]
{
public static readonly LazyMethod Submit = LazyMethod.ByPartialSignature(
"osu.Helpers.ErrorSubmission::Submit(OsuError)",
[
Ldsfld,
Ldc_I4_0,
Ble_S,
Expand All @@ -34,6 +32,6 @@ public static class ErrorSubmission
Ldarg_0,
Ldfld,
Ldarg_0,
}
]
);
}
17 changes: 7 additions & 10 deletions Osu.Stubs/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ namespace Osu.Stubs;
/// Original: <c>osu.GameplayElements.Events.EventManager</c>
/// b20240102.2: <c>#=zbJqkrJF69yLASpsnblYMeq3jWETw</c>
/// </summary>
[UsedImplicitly]
[PublicAPI]
public static class EventManager
{
/// <summary>
/// Original: <c>set_ShowStoryboard</c> (property setter)
/// Original: <c>set_ShowStoryboard()</c> (property setter)
/// b20240102.2: <c>#=zKZugEelWoTXb</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod SetShowStoryboard = new(
"EventManager#ShowStoryboard.set",
new[]
{
public static readonly LazyMethod SetShowStoryboard = LazyMethod.BySignature(
"osu.GameplayElements.Events.EventManager::set_ShowStoryBoard()",
[
Ldarg_0,
Ldsfld,
Bne_Un_S,
Expand All @@ -34,16 +32,15 @@ public static class EventManager
Ldsfld,
Callvirt,
Ret,
}
]
);

/// <summary>
/// The compiler generated backing field for the <c>ShowStoryboard</c> property.
/// See: <see cref="SetShowStoryboard" />
/// </summary>
[UsedImplicitly]
public static readonly LazyField<bool> ShowStoryboard = new(
"EventManager#ShowStoryboard.backing",
"osu.GameplayElements.Events.EventManager::[ShowStoryboard backing]",
() =>
{
// Find a single StoreField instruction in the setter for this property
Expand Down
24 changes: 10 additions & 14 deletions Osu.Stubs/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ namespace Osu.Stubs;
/// Original: <c>osu.GameBase</c>
/// b20240123: <c>#=zduF3QmjgMG4eSc$fOQ==</c>
/// </summary>
[UsedImplicitly]
public class GameBase
[PublicAPI]
public static class GameBase
{
/// <summary>
/// Original: <c>get_ModeCanReload()</c>
/// b20240123: <c>#=zL6aRJUMxZO5fmlF9KQ==</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod<bool> GetModeCanReload = new(
"GameBase#get_ModeCanReload()",
new[]
{
public static readonly LazyMethod<bool> GetModeCanReload = LazyMethod<bool>.ByPartialSignature(
"osu.GameBase::get_ModeCanReload()",
[
Ldc_I4_7,
Bgt_S,
Ldloc_0,
Expand All @@ -29,18 +27,16 @@ public class GameBase
Ldc_I4_7,
Beq_S,
Br_S,
}
]
);

/// <summary>
/// Original: <c>softHandle(Exception e)</c>
/// b20240123: <c>#=z8BJOiJxSLUwM</c>
/// </summary>
[UsedImplicitly]
public static readonly LazyMethod SoftHandle = new(
"GameBase#softHandle(...)",
new[]
{
public static readonly LazyMethod SoftHandle = LazyMethod.ByPartialSignature(
"osu.GameBase::softHandle(Exception)",
[
Ldarg_0,
Isinst,
Brtrue_S,
Expand All @@ -51,6 +47,6 @@ public class GameBase
Isinst,
Brfalse_S,
Ldc_I4_8,
}
]
);
}
Loading

0 comments on commit 1c39e58

Please sign in to comment.