Skip to content

Commit c7ddb5d

Browse files
committed
updated to 1.0.0 and now uses BSIPA, slight performane improvements
1 parent d0664c9 commit c7ddb5d

File tree

5 files changed

+131
-80
lines changed

5 files changed

+131
-80
lines changed

PerfectDisplay.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Linq;
33
using UnityEngine;
44
using System.Collections;
5+
using CustomUI.Utilities;
56

67
namespace PerfectionDisplay
78
{
89
class PerfectDisplay : MonoBehaviour
910
{
1011
ScoreController scoreController;
12+
StandardLevelGameplayManager gameplayManager;
1113
public static Vector3 displayPosition = new Vector3(0, 2.3f, 7f);
1214
public static int[] scoreRanges = { 100, 90, 50 };
1315
public static string[] hitScoreNames;
@@ -25,7 +27,8 @@ IEnumerator WaitForLoad()
2527
while (!loaded)
2628
{
2729
scoreController = Resources.FindObjectsOfTypeAll<ScoreController>().FirstOrDefault();
28-
if (scoreController == null)
30+
gameplayManager = Resources.FindObjectsOfTypeAll<StandardLevelGameplayManager>().FirstOrDefault();
31+
if (scoreController == null || gameplayManager == null)
2932
yield return new WaitForSeconds(0.1f);
3033
else
3134
loaded = true;
@@ -61,6 +64,11 @@ private void Init()
6164
scoreController.noteWasMissedEvent += Miss;
6265
scoreController.noteWasCutEvent += Cut;
6366
}
67+
if(gameplayManager != null)
68+
{
69+
gameplayManager.GetPrivateField<Signal>("_levelFinishedSignal").Subscribe(SongFinish);
70+
gameplayManager.GetPrivateField<Signal>("_levelFailedSignal").Subscribe(SongFinish);
71+
}
6472
UpdateText();
6573
}
6674
public void Miss(NoteData data, int c)
@@ -84,7 +92,7 @@ public void Cut(NoteData data, NoteCutInfo info, int combo)
8492
{
8593
if (didDone) return;
8694
didDone = true;
87-
ScoreController.ScoreWithoutMultiplier(info, info.afterCutSwingRatingCounter, out int before, out int after, out int distScore);
95+
ScoreController.RawScoreWithoutMultiplier(info, info.afterCutSwingRatingCounter, out int before, out int after, out int distScore);
8896
int total = before + after;
8997
for (int i = 0; i < scoreRanges.Length; i++)
9098
{
@@ -122,8 +130,9 @@ public void UpdateText()
122130
}
123131
sections[scoreRanges.Length + 1].UpdatePosition(-(width / 2) + curX);
124132
}
125-
126-
133+
}
134+
public void SongFinish()
135+
{
127136
Plugin.lastText = "Range\n";
128137
for (int i = 0; i < scoreRanges.Length; i++)
129138
{

Perfection Display.csproj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>PerfectionDisplay</RootNamespace>
1111
<AssemblyName>Perfect Display</AssemblyName>
12-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
@@ -33,19 +33,19 @@
3333
<Prefer32Bit>false</Prefer32Bit>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="Assembly-CSharp">
37-
<HintPath>E:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp.dll</HintPath>
36+
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
37+
<SpecificVersion>False</SpecificVersion>
38+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp.dll</HintPath>
39+
</Reference>
40+
<Reference Include="BeatSaberCustomUI">
41+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\BeatSaberCustomUI.dll</HintPath>
3842
</Reference>
3943
<Reference Include="HitScoreVisualizer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
4044
<SpecificVersion>False</SpecificVersion>
4145
<HintPath>E:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\HitScoreVisualizer.dll</HintPath>
4246
</Reference>
43-
<Reference Include="IllusionInjector, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
44-
<SpecificVersion>False</SpecificVersion>
45-
<HintPath>E:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionInjector.dll</HintPath>
46-
</Reference>
47-
<Reference Include="IllusionPlugin">
48-
<HintPath>E:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll</HintPath>
47+
<Reference Include="IPA.Loader">
48+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
4949
</Reference>
5050
<Reference Include="System" />
5151
<Reference Include="System.Core" />
@@ -85,5 +85,8 @@
8585
<Compile Include="Plugin.cs" />
8686
<Compile Include="Properties\AssemblyInfo.cs" />
8787
</ItemGroup>
88+
<ItemGroup>
89+
<EmbeddedResource Include="manifest.json" />
90+
</ItemGroup>
8891
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8992
</Project>

Plugin.cs

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
using IllusionPlugin;
2-
using IllusionInjector;
3-
using System;
1+
using System;
42
using System.Globalization;
53
using System.Linq;
64
using TMPro;
75
using UnityEngine;
86
using UnityEngine.SceneManagement;
97
using HitScoreVisualizer;
108
using System.Text.RegularExpressions;
9+
using IPA;
10+
using IPA.Config;
11+
using CustomUI.Utilities;
12+
using System.Collections;
1113

1214
namespace PerfectionDisplay
1315
{
14-
public class Plugin : IPlugin
16+
public class Plugin : IBeatSaberPlugin
1517
{
16-
public string Name => "Perfection Display";
17-
public string Version => "1.5.1";
18-
1918
public static string lastText = "";
2019
public static string lastPercent = "";
2120
public static string lastCount = "";
@@ -30,8 +29,6 @@ public class Plugin : IPlugin
3029

3130
public void OnApplicationStart()
3231
{
33-
SceneManager.activeSceneChanged += OnSceneChanged;
34-
3532
if (ModPrefs.GetString("PerfectionDisplay", "Position") == "")
3633
{
3734
ModPrefs.SetString("PerfectionDisplay", "Position",FormattableString.Invariant($"{PerfectDisplay.displayPosition.x:0.00},{PerfectDisplay.displayPosition.y:0.00},{PerfectDisplay.displayPosition.z:0.00}"));
@@ -78,15 +75,20 @@ public void OnApplicationStart()
7875
PerfectDisplay.showNumbers = ModPrefs.GetBool("PerfectionDisplay", "Show Count", PerfectDisplay.showNumbers, true);
7976
PerfectDisplay.showPercent = ModPrefs.GetBool("PerfectionDisplay", "Show Percent", PerfectDisplay.showPercent, true);
8077
PerfectDisplay.shouldHitscore = ModPrefs.GetBool("PerfectionDisplay", "HitScoreVisualizer Integration", PerfectDisplay.shouldHitscore, true);
78+
79+
BSEvents.menuSceneLoadedFresh += MenuSceneActive;
80+
BSEvents.menuSceneActive += MenuSceneActive;
81+
BSEvents.gameSceneActive += GameSceneActive;
8182
}
8283

8384
public void OnApplicationQuit()
8485
{
85-
SceneManager.activeSceneChanged -= OnSceneChanged;
86+
BSEvents.menuSceneActive -= MenuSceneActive;
87+
BSEvents.gameSceneActive -= GameSceneActive;
8688
}
8789
private void LoadHitScore()
8890
{
89-
Config.Judgment[] judgments = Config.instance.judgments;
91+
HitScoreVisualizer.Config.Judgment[] judgments = HitScoreVisualizer.Config.instance.judgments;
9092
PerfectDisplay.scoreRanges = new int[judgments.Length - 1];
9193
PerfectDisplay.hitScoreNames = new string[judgments.Length];
9294
PerfectDisplay.colors = new string[judgments.Length + 1];
@@ -100,56 +102,6 @@ private void LoadHitScore()
100102
}
101103
private void OnSceneChanged(Scene _, Scene scene)
102104
{
103-
if (gameScenesManager == null)
104-
{
105-
gameScenesManager = Resources.FindObjectsOfTypeAll<GameScenesManager>().FirstOrDefault();
106-
if (gameScenesManager != null)
107-
{
108-
gameScenesManager.transitionDidFinishEvent += OnTransition;
109-
}
110-
}
111-
if (init)
112-
{
113-
init = false;
114-
Console.WriteLine(PluginManager.Plugins);
115-
if (PerfectDisplay.shouldHitscore && PluginManager.Plugins.Any(x => x.Name == "HitScoreVisualizer")) LoadHitScore();
116-
else PerfectDisplay.shouldHitscore = false;
117-
}
118-
if(scene.name.Equals("MenuCore"))
119-
{
120-
mainFont = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().First(t => t.font?.name == "Teko-Medium SDF No Glow").font;
121-
if (text != null) MonoBehaviour.Destroy(text);
122-
if (percent != null) MonoBehaviour.Destroy(percent);
123-
if (count != null) MonoBehaviour.Destroy(count);
124-
ResultsViewController results = Resources.FindObjectsOfTypeAll<ResultsViewController>().FirstOrDefault();
125-
int extraOffset = -12;
126-
text = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
127-
text.fontSize = 5;
128-
text.color = Color.white;
129-
text.lineSpacing = -15f;
130-
text.paragraphSpacing = -15f;
131-
text.text = lastText;
132-
text.alignment = TextAlignmentOptions.TopLeft;
133-
text.rectTransform.localPosition = new Vector3(-20+extraOffset, 35, 0);
134-
percent = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
135-
percent.fontSize = 5;
136-
percent.color = Color.white;
137-
percent.paragraphSpacing = -15f;
138-
percent.lineSpacing = -15f;
139-
percent.text = lastCount;
140-
percent.alignment = TextAlignmentOptions.TopLeft;
141-
percent.rectTransform.localPosition = new Vector3(0 + extraOffset, 35, 0);
142-
count = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
143-
count.fontSize = 5;
144-
count.color = Color.white;
145-
count.lineSpacing = -15f;
146-
count.paragraphSpacing = -15f;
147-
count.text = lastPercent;
148-
count.alignment = TextAlignmentOptions.TopLeft;
149-
count.rectTransform.localPosition = new Vector3(15 + extraOffset, 35, 0);
150-
return;
151-
}
152-
if (scene.name.Equals("GameCore")) new GameObject("PerfectDisplay").AddComponent<PerfectDisplay>();
153105
}
154106
private void OnSceneLoad(Scene _, LoadSceneMode mode)
155107
{
@@ -160,23 +112,95 @@ public void OnTransition()
160112
if (percent!= null) percent.text = lastPercent;
161113
if (count != null) count.text = lastCount;
162114
}
115+
163116

164-
public void OnLevelWasLoaded(int level)
117+
public void OnUpdate()
165118
{
119+
}
166120

121+
public void OnFixedUpdate()
122+
{
167123
}
168124

169-
public void OnLevelWasInitialized(int level)
125+
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
170126
{
171127

172128
}
173129

174-
public void OnUpdate()
130+
public void OnSceneUnloaded(Scene scene)
175131
{
132+
176133
}
177134

178-
public void OnFixedUpdate()
135+
public void OnActiveSceneChanged(Scene _, Scene scene)
179136
{
137+
if (gameScenesManager == null)
138+
{
139+
gameScenesManager = Resources.FindObjectsOfTypeAll<GameScenesManager>().FirstOrDefault();
140+
if (gameScenesManager != null)
141+
{
142+
gameScenesManager.transitionDidFinishEvent += OnTransition;
143+
}
144+
}
145+
if (init)
146+
{
147+
init = false;
148+
if (PerfectDisplay.shouldHitscore && IPA.Loader.PluginManager.Plugins.Any(x => x.Name == "HitScoreVisualizer")) LoadHitScore();
149+
else PerfectDisplay.shouldHitscore = false;
150+
}
151+
}
152+
153+
public void GameSceneActive()
154+
{
155+
new GameObject("PerfectDisplay").AddComponent<PerfectDisplay>();
156+
}
157+
public void MenuSceneActive()
158+
{
159+
if (mainFont == null) gameScenesManager.StartCoroutine(FontHunter());
160+
if (text != null) MonoBehaviour.Destroy(text);
161+
if (percent != null) MonoBehaviour.Destroy(percent);
162+
if (count != null) MonoBehaviour.Destroy(count);
163+
ResultsViewController results = Resources.FindObjectsOfTypeAll<ResultsViewController>().FirstOrDefault();
164+
int extraOffset = -12;
165+
text = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
166+
text.fontSize = 5;
167+
text.color = Color.white;
168+
text.lineSpacing = -15f;
169+
text.paragraphSpacing = -15f;
170+
text.text = lastText;
171+
text.alignment = TextAlignmentOptions.TopLeft;
172+
text.rectTransform.localPosition = new Vector3(-20 + extraOffset, 35, 0);
173+
percent = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
174+
percent.fontSize = 5;
175+
percent.color = Color.white;
176+
percent.paragraphSpacing = -15f;
177+
percent.lineSpacing = -15f;
178+
percent.text = lastCount;
179+
percent.alignment = TextAlignmentOptions.TopLeft;
180+
percent.rectTransform.localPosition = new Vector3(0 + extraOffset, 35, 0);
181+
count = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().Last(x => (x.name == "Title")), results.transform, false);
182+
count.fontSize = 5;
183+
count.color = Color.white;
184+
count.lineSpacing = -15f;
185+
count.paragraphSpacing = -15f;
186+
count.text = lastPercent;
187+
count.alignment = TextAlignmentOptions.TopLeft;
188+
count.rectTransform.localPosition = new Vector3(15 + extraOffset, 35, 0);
189+
}
190+
//For some reason can't find the font right when scene loads so this will hunt it down
191+
public IEnumerator FontHunter()
192+
{
193+
while (mainFont == null)
194+
{
195+
try
196+
{
197+
mainFont = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>().First(t => t.font?.name == "Teko-Medium SDF No Glow").font;
198+
} catch
199+
{
200+
201+
}
202+
yield return new WaitForSeconds(1f);
203+
}
180204
}
181205
}
182206
}

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.5.1.0")]
36-
[assembly: AssemblyFileVersion("1.5.1.0")]
35+
[assembly: AssemblyVersion("1.6.0.0")]
36+
[assembly: AssemblyFileVersion("1.6.0.0")]

manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/nike4613/ModSaber-MetadataFileSchema/master/Schema.json",
3+
"author": "monkeymanboy",
4+
"description": "Adds more info to the results screen and during gameplay if enabled. Will use HitScoreVisualizer config if you have the plugin and integration is enabled.",
5+
"gameVersion": "1.0.0",
6+
"id": "PerfectionDisplay",
7+
"name": "Perfection Display",
8+
"version": "1.6.0",
9+
"dependsOn": {
10+
"BSIPA": "^3.12.19",
11+
"CustomUI": "^1.5.4"
12+
},
13+
"features": [
14+
]
15+
}

0 commit comments

Comments
 (0)