Skip to content

Commit a185569

Browse files
Compatibility with game version 0.13.0; default config improvements
1 parent 7c760e6 commit a185569

7 files changed

+128
-59
lines changed

HitScoreVisualizer/Config.cs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
using System.Linq;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using TMPro;
910
using UnityEngine;
1011

12+
using static HitScoreVisualizer.Utils.ReflectionUtil;
13+
1114
namespace HitScoreVisualizer
1215
{
1316
public class Config
@@ -106,13 +109,13 @@ public struct SegmentJudgment
106109
private const string DEFAULT_JSON = @"{
107110
""majorVersion"": 2,
108111
""minorVersion"": 1,
109-
""patchVersion"": 3,
112+
""patchVersion"": 5,
110113
""isDefaultConfig"": true,
111114
""displayMode"": ""format"",
112115
""judgments"": [
113116
{
114117
""threshold"": 110,
115-
""text"": ""Fantastic%n%s%n%B %C %A"",
118+
""text"": ""%BFantastic%A%n%s"",
116119
""color"": [
117120
1.0,
118121
1.0,
@@ -122,7 +125,7 @@ public struct SegmentJudgment
122125
},
123126
{
124127
""threshold"": 101,
125-
""text"": ""<size=80%>Excellent</size>%n%s%n%B %C %A"",
128+
""text"": ""<size=80%>%BExcellent%A</size>%n%s"",
126129
""color"": [
127130
0.0,
128131
1.0,
@@ -132,7 +135,7 @@ public struct SegmentJudgment
132135
},
133136
{
134137
""threshold"": 90,
135-
""text"": ""<size=80%>Great</size>%n%s%n%B %C %A"",
138+
""text"": ""<size=80%>%BGreat%A</size>%n%s"",
136139
""color"": [
137140
1.0,
138141
0.980392158,
@@ -142,7 +145,7 @@ public struct SegmentJudgment
142145
},
143146
{
144147
""threshold"": 80,
145-
""text"": ""<size=80%>Good</size>%n%s%n%B %C %A"",
148+
""text"": ""<size=80%>%BGood%A</size>%n%s"",
146149
""color"": [
147150
1.0,
148151
0.6,
@@ -153,7 +156,7 @@ public struct SegmentJudgment
153156
},
154157
{
155158
""threshold"": 60,
156-
""text"": ""<size=80%>Decent</size>%n%s%n%B %C %A"",
159+
""text"": ""<size=80%>%BDecent%A</size>%n%s"",
157160
""color"": [
158161
1.0,
159162
0.0,
@@ -163,7 +166,7 @@ public struct SegmentJudgment
163166
""fade"": true
164167
},
165168
{
166-
""text"": ""<size=80%>Way Off</size>%n%s%n%B %C %A"",
169+
""text"": ""<size=80%>%BWay Off%A</size>%n%s"",
167170
""color"": [
168171
0.5,
169172
0.0,
@@ -175,44 +178,29 @@ public struct SegmentJudgment
175178
],
176179
""beforeCutAngleJudgments"": [
177180
{
178-
""threshold"": 70,
181+
""threshold"": 70,
179182
""text"": ""+""
180183
},
181184
{
182-
""threshold"": 35,
183185
""text"": "" ""
184-
},
185-
{
186-
""threshold"": 0,
187-
""text"": ""-""
188186
}
189187
],
190188
""accuracyJudgments"": [
191189
{
192-
""threshold"": 10,
190+
""threshold"": 10,
193191
""text"": ""+""
194192
},
195193
{
196-
""threshold"": 5,
197194
""text"": "" ""
198-
},
199-
{
200-
""threshold"": 0,
201-
""text"": ""-""
202195
}
203196
],
204197
""afterCutAngleJudgments"": [
205198
{
206-
""threshold"": 30,
199+
""threshold"": 30,
207200
""text"": ""+""
208201
},
209202
{
210-
""threshold"": 15,
211203
""text"": "" ""
212-
},
213-
{
214-
""threshold"": 0,
215-
""text"": ""-""
216204
}
217205
]
218206
}";
@@ -278,9 +266,9 @@ public static void load()
278266
loaded.patchVersion = 0;
279267
isDirty = true;
280268
}
281-
if (loaded.majorVersion == 2 && loaded.minorVersion == 1 && loaded.patchVersion < 3)
269+
if (loaded.majorVersion == 2 && loaded.minorVersion == 1 && loaded.patchVersion < Plugin.patchVersion)
282270
{
283-
loaded.patchVersion = 3;
271+
loaded.patchVersion = Plugin.patchVersion;
284272
isDirty = true;
285273
}
286274
if (isDirty) save();
@@ -345,8 +333,16 @@ public static void resetToDefault()
345333
instance = DEFAULT_CONFIG;
346334
}
347335

348-
public static void judge(FlyingScoreTextEffect text, NoteCutInfo noteCutInfo, SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, ref Color color, int score, int before, int after, int accuracy)
336+
public static void judge(FlyingScoreEffect scoreEffect, NoteCutInfo noteCutInfo, SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, ref Color color, int score, int before, int after, int accuracy)
349337
{
338+
// as of 0.13, the TextMeshPro is private; use reflection to grab it out of a private field
339+
TextMeshPro text = scoreEffect.getPrivateField<TextMeshPro>("_text");
340+
// enable rich text
341+
text.richText = true;
342+
// disable word wrap, make sure full text displays
343+
text.enableWordWrapping = false;
344+
text.overflowMode = TextOverflowModes.Overflow;
345+
350346
Judgment judgment = DEFAULT_JUDGMENT;
351347
int index; // save in case we need to fade
352348
for (index = 0; index < instance.judgments.Length; index++)
@@ -435,6 +431,7 @@ public static void judge(FlyingScoreTextEffect text, NoteCutInfo noteCutInfo, Sa
435431
}
436432
if (instance.displayMode == "numeric")
437433
{
434+
text.text = score.ToString();
438435
return;
439436
}
440437
if (instance.displayMode == "scoreOnTop")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Harmony;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UnityEngine;
8+
9+
namespace HitScoreVisualizer.Harmony_Patches
10+
{
11+
[HarmonyPatch(typeof(FlyingScoreEffect), "HandleSaberAfterCutSwingRatingCounterDidChangeEvent",
12+
new Type[] { typeof(SaberAfterCutSwingRatingCounter), typeof(float) })]
13+
class FlyingScoreEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent
14+
{
15+
static bool Prefix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreEffect __instance, ref Color ____color, NoteCutInfo ____noteCutInfo)
16+
{
17+
ScoreController.ScoreWithoutMultiplier(____noteCutInfo, saberAfterCutSwingRatingCounter, out int before_plus_acc, out int after, out int accuracy);
18+
int total = before_plus_acc + after;
19+
Config.judge(__instance, ____noteCutInfo, saberAfterCutSwingRatingCounter, ref ____color, total, before_plus_acc - accuracy, after, accuracy);
20+
return false;
21+
}
22+
}
23+
}

HitScoreVisualizer/Harmony Patches/FlyingScoreTextEffectInitAndPresent.cs renamed to HitScoreVisualizer/Harmony Patches/FlyingScoreEffectInitAndPresent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88

99
namespace HitScoreVisualizer.Harmony_Patches
1010
{
11-
[HarmonyPatch(typeof(FlyingScoreTextEffect), "InitAndPresent",
11+
[HarmonyPatch(typeof(FlyingScoreEffect), "InitAndPresent",
1212
new Type[] {
1313
typeof(NoteCutInfo),
1414
typeof(int),
15+
typeof(float),
1516
typeof(Vector3),
1617
typeof(Color),
1718
typeof(SaberAfterCutSwingRatingCounter)})]
18-
class FlyingScoreTextEffectInitAndPresent
19+
class FlyingScoreEffectInitAndPresent
1920
{
20-
static void Postfix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreTextEffect __instance, ref Color ____color, NoteCutInfo noteCutInfo)
21+
static void Postfix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreEffect __instance, ref Color ____color, NoteCutInfo noteCutInfo)
2122
{
2223
ScoreController.ScoreWithoutMultiplier(noteCutInfo, saberAfterCutSwingRatingCounter, out int before_plus_acc, out int after, out int accuracy);
2324
int total = before_plus_acc + after;

HitScoreVisualizer/Harmony Patches/FlyingScoreTextEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

HitScoreVisualizer/HitScoreVisualizer.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll</HintPath>
4545
</Reference>
4646
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Newtonsoft.Json.dll</HintPath>
4849
</Reference>
4950
<Reference Include="System" />
5051
<Reference Include="System.Core" />
@@ -54,6 +55,9 @@
5455
<Reference Include="System.Data" />
5556
<Reference Include="System.Net.Http" />
5657
<Reference Include="System.Xml" />
58+
<Reference Include="Unity.TextMeshPro">
59+
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
60+
</Reference>
5761
<Reference Include="UnityEngine">
5862
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
5963
</Reference>
@@ -63,10 +67,11 @@
6367
</ItemGroup>
6468
<ItemGroup>
6569
<Compile Include="Config.cs" />
66-
<Compile Include="Harmony Patches\FlyingScoreTextEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent.cs" />
67-
<Compile Include="Harmony Patches\FlyingScoreTextEffectInitAndPresent.cs" />
70+
<Compile Include="Harmony Patches\FlyingScoreEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent.cs" />
71+
<Compile Include="Harmony Patches\FlyingScoreEffectInitAndPresent.cs" />
6872
<Compile Include="Plugin.cs" />
6973
<Compile Include="Properties\AssemblyInfo.cs" />
74+
<Compile Include="Utils\ReflectionUtil.cs" />
7075
</ItemGroup>
7176
<ItemGroup>
7277
<None Include="packages.config" />

HitScoreVisualizer/Plugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace HitScoreVisualizer
99
public class Plugin : IPlugin
1010
{
1111
public string Name => "HitScoreVisualizer";
12-
public string Version => "2.1.3";
12+
public string Version => "2.1.5";
1313

1414
internal const int majorVersion = 2;
1515
internal const int minorVersion = 1;
16-
internal const int patchVersion = 3;
16+
internal const int patchVersion = 5;
1717

1818
public void OnApplicationStart()
1919
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Reflection;
2+
3+
namespace HitScoreVisualizer.Utils
4+
{
5+
static class ReflectionUtil
6+
{
7+
public static void SetPrivateField(object obj, string fieldName, object value)
8+
{
9+
var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
10+
prop.SetValue(obj, value);
11+
}
12+
13+
public static T GetPrivateField<T>(object obj, string fieldName)
14+
{
15+
var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
16+
var value = prop.GetValue(obj);
17+
return (T)value;
18+
}
19+
20+
public static void SetPrivateProperty(object obj, string propertyName, object value)
21+
{
22+
var prop = obj.GetType().GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
23+
prop.SetValue(obj, value, null);
24+
}
25+
26+
public static void SetPrivateFieldBase(object obj, string fieldName, object value)
27+
{
28+
var prop = obj.GetType().BaseType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
29+
prop.SetValue(obj, value);
30+
}
31+
32+
public static T GetPrivateFieldBase<T>(object obj, string fieldName)
33+
{
34+
var prop = obj.GetType().BaseType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
35+
var value = prop.GetValue(obj);
36+
return (T)value;
37+
}
38+
39+
public static void SetPrivatePropertyBase(object obj, string propertyName, object value)
40+
{
41+
var prop = obj.GetType().BaseType.GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
42+
prop.SetValue(obj, value, null);
43+
}
44+
45+
public static void InvokePrivateMethod(object obj, string methodName, object[] methodParams)
46+
{
47+
MethodInfo dynMethod = obj.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
48+
dynMethod.Invoke(obj, methodParams);
49+
}
50+
51+
public static T getPrivateField<T>(this object obj, string fieldName) =>
52+
GetPrivateField<T>(obj, fieldName);
53+
public static void setPrivateField(this object obj, string fieldName, object value) =>
54+
SetPrivateField(obj, fieldName, value);
55+
public static T getPrivateFieldBase<T>(this object obj, string fieldName) =>
56+
GetPrivateFieldBase<T>(obj, fieldName);
57+
public static void setPrivateFieldBase(this object obj, string fieldName, object value) =>
58+
SetPrivateFieldBase(obj, fieldName, value);
59+
public static void setPrivateProperty(this object obj, string propertyName, object value) =>
60+
setPrivateProperty(obj, propertyName, value);
61+
public static void setPrivatePropertyBase(this object obj, string propertyName, object value) =>
62+
setPrivatePropertyBase(obj, propertyName, value);
63+
public static void invokePrivateMethod(this object obj, string methodName, object[] methodParams) =>
64+
InvokePrivateMethod(obj, methodName, methodParams);
65+
}
66+
}

0 commit comments

Comments
 (0)