Skip to content

Commit

Permalink
Compatibility with game version 0.13.0; default config improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiswkearney committed Mar 14, 2019
1 parent 7c760e6 commit a185569
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 59 deletions.
53 changes: 25 additions & 28 deletions HitScoreVisualizer/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;

using static HitScoreVisualizer.Utils.ReflectionUtil;

namespace HitScoreVisualizer
{
public class Config
Expand Down Expand Up @@ -106,13 +109,13 @@ public struct SegmentJudgment
private const string DEFAULT_JSON = @"{
""majorVersion"": 2,
""minorVersion"": 1,
""patchVersion"": 3,
""patchVersion"": 5,
""isDefaultConfig"": true,
""displayMode"": ""format"",
""judgments"": [
{
""threshold"": 110,
""text"": ""Fantastic%n%s%n%B %C %A"",
""text"": ""%BFantastic%A%n%s"",
""color"": [
1.0,
1.0,
Expand All @@ -122,7 +125,7 @@ public struct SegmentJudgment
},
{
""threshold"": 101,
""text"": ""<size=80%>Excellent</size>%n%s%n%B %C %A"",
""text"": ""<size=80%>%BExcellent%A</size>%n%s"",
""color"": [
0.0,
1.0,
Expand All @@ -132,7 +135,7 @@ public struct SegmentJudgment
},
{
""threshold"": 90,
""text"": ""<size=80%>Great</size>%n%s%n%B %C %A"",
""text"": ""<size=80%>%BGreat%A</size>%n%s"",
""color"": [
1.0,
0.980392158,
Expand All @@ -142,7 +145,7 @@ public struct SegmentJudgment
},
{
""threshold"": 80,
""text"": ""<size=80%>Good</size>%n%s%n%B %C %A"",
""text"": ""<size=80%>%BGood%A</size>%n%s"",
""color"": [
1.0,
0.6,
Expand All @@ -153,7 +156,7 @@ public struct SegmentJudgment
},
{
""threshold"": 60,
""text"": ""<size=80%>Decent</size>%n%s%n%B %C %A"",
""text"": ""<size=80%>%BDecent%A</size>%n%s"",
""color"": [
1.0,
0.0,
Expand All @@ -163,7 +166,7 @@ public struct SegmentJudgment
""fade"": true
},
{
""text"": ""<size=80%>Way Off</size>%n%s%n%B %C %A"",
""text"": ""<size=80%>%BWay Off%A</size>%n%s"",
""color"": [
0.5,
0.0,
Expand All @@ -175,44 +178,29 @@ public struct SegmentJudgment
],
""beforeCutAngleJudgments"": [
{
""threshold"": 70,
""threshold"": 70,
""text"": ""+""
},
{
""threshold"": 35,
""text"": "" ""
},
{
""threshold"": 0,
""text"": ""-""
}
],
""accuracyJudgments"": [
{
""threshold"": 10,
""threshold"": 10,
""text"": ""+""
},
{
""threshold"": 5,
""text"": "" ""
},
{
""threshold"": 0,
""text"": ""-""
}
],
""afterCutAngleJudgments"": [
{
""threshold"": 30,
""threshold"": 30,
""text"": ""+""
},
{
""threshold"": 15,
""text"": "" ""
},
{
""threshold"": 0,
""text"": ""-""
}
]
}";
Expand Down Expand Up @@ -278,9 +266,9 @@ public static void load()
loaded.patchVersion = 0;
isDirty = true;
}
if (loaded.majorVersion == 2 && loaded.minorVersion == 1 && loaded.patchVersion < 3)
if (loaded.majorVersion == 2 && loaded.minorVersion == 1 && loaded.patchVersion < Plugin.patchVersion)
{
loaded.patchVersion = 3;
loaded.patchVersion = Plugin.patchVersion;
isDirty = true;
}
if (isDirty) save();
Expand Down Expand Up @@ -345,8 +333,16 @@ public static void resetToDefault()
instance = DEFAULT_CONFIG;
}

public static void judge(FlyingScoreTextEffect text, NoteCutInfo noteCutInfo, SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, ref Color color, int score, int before, int after, int accuracy)
public static void judge(FlyingScoreEffect scoreEffect, NoteCutInfo noteCutInfo, SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, ref Color color, int score, int before, int after, int accuracy)
{
// as of 0.13, the TextMeshPro is private; use reflection to grab it out of a private field
TextMeshPro text = scoreEffect.getPrivateField<TextMeshPro>("_text");
// enable rich text
text.richText = true;
// disable word wrap, make sure full text displays
text.enableWordWrapping = false;
text.overflowMode = TextOverflowModes.Overflow;

Judgment judgment = DEFAULT_JUDGMENT;
int index; // save in case we need to fade
for (index = 0; index < instance.judgments.Length; index++)
Expand Down Expand Up @@ -435,6 +431,7 @@ public static void judge(FlyingScoreTextEffect text, NoteCutInfo noteCutInfo, Sa
}
if (instance.displayMode == "numeric")
{
text.text = score.ToString();
return;
}
if (instance.displayMode == "scoreOnTop")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Harmony;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace HitScoreVisualizer.Harmony_Patches
{
[HarmonyPatch(typeof(FlyingScoreEffect), "HandleSaberAfterCutSwingRatingCounterDidChangeEvent",
new Type[] { typeof(SaberAfterCutSwingRatingCounter), typeof(float) })]
class FlyingScoreEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent
{
static bool Prefix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreEffect __instance, ref Color ____color, NoteCutInfo ____noteCutInfo)
{
ScoreController.ScoreWithoutMultiplier(____noteCutInfo, saberAfterCutSwingRatingCounter, out int before_plus_acc, out int after, out int accuracy);
int total = before_plus_acc + after;
Config.judge(__instance, ____noteCutInfo, saberAfterCutSwingRatingCounter, ref ____color, total, before_plus_acc - accuracy, after, accuracy);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

namespace HitScoreVisualizer.Harmony_Patches
{
[HarmonyPatch(typeof(FlyingScoreTextEffect), "InitAndPresent",
[HarmonyPatch(typeof(FlyingScoreEffect), "InitAndPresent",
new Type[] {
typeof(NoteCutInfo),
typeof(int),
typeof(float),
typeof(Vector3),
typeof(Color),
typeof(SaberAfterCutSwingRatingCounter)})]
class FlyingScoreTextEffectInitAndPresent
class FlyingScoreEffectInitAndPresent
{
static void Postfix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreTextEffect __instance, ref Color ____color, NoteCutInfo noteCutInfo)
static void Postfix(SaberAfterCutSwingRatingCounter saberAfterCutSwingRatingCounter, FlyingScoreEffect __instance, ref Color ____color, NoteCutInfo noteCutInfo)
{
ScoreController.ScoreWithoutMultiplier(noteCutInfo, saberAfterCutSwingRatingCounter, out int before_plus_acc, out int after, out int accuracy);
int total = before_plus_acc + after;
Expand Down

This file was deleted.

11 changes: 8 additions & 3 deletions HitScoreVisualizer/HitScoreVisualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +55,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.TextMeshPro">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
Expand All @@ -63,10 +67,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Harmony Patches\FlyingScoreTextEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent.cs" />
<Compile Include="Harmony Patches\FlyingScoreTextEffectInitAndPresent.cs" />
<Compile Include="Harmony Patches\FlyingScoreEffectHandleSaberAfterCutSwingRatingCounterDidChangeEvent.cs" />
<Compile Include="Harmony Patches\FlyingScoreEffectInitAndPresent.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\ReflectionUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
4 changes: 2 additions & 2 deletions HitScoreVisualizer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace HitScoreVisualizer
public class Plugin : IPlugin
{
public string Name => "HitScoreVisualizer";
public string Version => "2.1.3";
public string Version => "2.1.5";

internal const int majorVersion = 2;
internal const int minorVersion = 1;
internal const int patchVersion = 3;
internal const int patchVersion = 5;

public void OnApplicationStart()
{
Expand Down
66 changes: 66 additions & 0 deletions HitScoreVisualizer/Utils/ReflectionUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Reflection;

namespace HitScoreVisualizer.Utils
{
static class ReflectionUtil
{
public static void SetPrivateField(object obj, string fieldName, object value)
{
var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(obj, value);
}

public static T GetPrivateField<T>(object obj, string fieldName)
{
var prop = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
var value = prop.GetValue(obj);
return (T)value;
}

public static void SetPrivateProperty(object obj, string propertyName, object value)
{
var prop = obj.GetType().GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(obj, value, null);
}

public static void SetPrivateFieldBase(object obj, string fieldName, object value)
{
var prop = obj.GetType().BaseType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(obj, value);
}

public static T GetPrivateFieldBase<T>(object obj, string fieldName)
{
var prop = obj.GetType().BaseType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
var value = prop.GetValue(obj);
return (T)value;
}

public static void SetPrivatePropertyBase(object obj, string propertyName, object value)
{
var prop = obj.GetType().BaseType.GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(obj, value, null);
}

public static void InvokePrivateMethod(object obj, string methodName, object[] methodParams)
{
MethodInfo dynMethod = obj.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
dynMethod.Invoke(obj, methodParams);
}

public static T getPrivateField<T>(this object obj, string fieldName) =>
GetPrivateField<T>(obj, fieldName);
public static void setPrivateField(this object obj, string fieldName, object value) =>
SetPrivateField(obj, fieldName, value);
public static T getPrivateFieldBase<T>(this object obj, string fieldName) =>
GetPrivateFieldBase<T>(obj, fieldName);
public static void setPrivateFieldBase(this object obj, string fieldName, object value) =>
SetPrivateFieldBase(obj, fieldName, value);
public static void setPrivateProperty(this object obj, string propertyName, object value) =>
setPrivateProperty(obj, propertyName, value);
public static void setPrivatePropertyBase(this object obj, string propertyName, object value) =>
setPrivatePropertyBase(obj, propertyName, value);
public static void invokePrivateMethod(this object obj, string methodName, object[] methodParams) =>
InvokePrivateMethod(obj, methodName, methodParams);
}
}

0 comments on commit a185569

Please sign in to comment.