Decompiled source of JudgementCounter v1.0.3

BepInEx/plugins/JudgementCounter.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TootTallyCore;
using TootTallyCore.Utils.TootTallyModules;
using TootTallySettings;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("JudgementCounter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Real Time Hit Note Judgement Counter")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9254ad9336e356ba83d8ce136c173bbc8d8c4ed0")]
[assembly: AssemblyProduct("JudgementCounter")]
[assembly: AssemblyTitle("JudgementCounter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace JudgementCounter
{
	public static class JudgementCounterManager
	{
		public enum DisplayPosition
		{
			BottomLeft,
			TopLeft
		}

		private static GameObject _uiholder;

		private static Text _judgmentLabels;

		private static Text[] _counterRows = (Text[])(object)new Text[5];

		[HarmonyPatch(typeof(GameController), "doScoreText")]
		[HarmonyPostfix]
		private static void DoScorePatch(GameController __instance)
		{
			if (Plugin.Instance.ModuleConfigEnabled.Value && !((Object)(object)_counterRows[0] == (Object)null))
			{
				UpdateCounterText(0, __instance.scores_A);
				UpdateCounterText(1, __instance.scores_B);
				UpdateCounterText(2, __instance.scores_C);
				UpdateCounterText(3, __instance.scores_D);
				UpdateCounterText(4, __instance.scores_F);
			}
		}

		private static void UpdateCounterText(int index, int scoreValue)
		{
			string text = scoreValue.ToString();
			_counterRows[index].text = text;
			if (text.Length >= 4)
			{
				_counterRows[index].fontSize = 12;
			}
			else
			{
				_counterRows[index].fontSize = 13;
			}
		}

		[HarmonyPatch(typeof(GameController), "Start")]
		[HarmonyPostfix]
		private static void OnGameControllerStart(GameController __instance)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			_uiholder = GameObject.Find("GameplayCanvas/UIHolder");
			if (!((Object)(object)_uiholder == (Object)null))
			{
				float num = 13f;
				DisplayPosition value = Plugin.Instance.DisplayPosition.Value;
				if (1 == 0)
				{
				}
				(float, float, float, float) tuple = ((value != DisplayPosition.BottomLeft) ? (0.0175f, 0.89f, 0.03f, 0.996f) : (0.0175f, 0.01f, 0.03f, 0.116f));
				if (1 == 0)
				{
				}
				(float, float, float, float) tuple2 = tuple;
				float item = tuple2.Item1;
				float item2 = tuple2.Item2;
				float item3 = tuple2.Item3;
				float item4 = tuple2.Item4;
				string text = ColorUtility.ToHtmlStringRGBA(Plugin.Instance.ColorPerfect.Value);
				string text2 = ColorUtility.ToHtmlStringRGBA(Plugin.Instance.ColorNice.Value);
				string text3 = ColorUtility.ToHtmlStringRGBA(Plugin.Instance.ColorOk.Value);
				string text4 = ColorUtility.ToHtmlStringRGBA(Plugin.Instance.ColorMeh.Value);
				string text5 = ColorUtility.ToHtmlStringRGBA(Plugin.Instance.ColorNasty.Value);
				_judgmentLabels = Object.Instantiate<Text>(__instance.ui_score, _uiholder.transform);
				((Object)_judgmentLabels).name = "JudgmentLabels";
				_judgmentLabels.supportRichText = true;
				_judgmentLabels.fontSize = 13;
				_judgmentLabels.alignment = (TextAnchor)0;
				_judgmentLabels.horizontalOverflow = (HorizontalWrapMode)1;
				_judgmentLabels.text = "<color=#" + text + ">P</color>\n<color=#" + text2 + ">N</color>\n<color=#" + text3 + ">O</color>\n<color=#" + text4 + ">M</color>\n<color=#" + text5 + ">X</color>";
				RectTransform component = ((Component)_judgmentLabels).GetComponent<RectTransform>();
				component.anchorMax = new Vector2(item, item2);
				component.anchorMin = new Vector2(item, item2);
				component.pivot = Vector2.one * 0.5f;
				component.anchoredPosition = Vector2.zero;
				component.sizeDelta = new Vector2(50f, 100f);
				for (int i = 0; i < 5; i++)
				{
					_counterRows[i] = Object.Instantiate<Text>(__instance.ui_score, _uiholder.transform);
					((Object)_counterRows[i]).name = $"JudgmentCounter_{i}";
					_counterRows[i].fontSize = 13;
					_counterRows[i].alignment = (TextAnchor)3;
					_counterRows[i].text = "0";
					_counterRows[i].horizontalOverflow = (HorizontalWrapMode)1;
					_counterRows[i].verticalOverflow = (VerticalWrapMode)1;
					_counterRows[i].resizeTextForBestFit = false;
					RectTransform component2 = ((Component)_counterRows[i]).GetComponent<RectTransform>();
					component2.anchorMax = new Vector2(item3, item4);
					component2.anchorMin = new Vector2(item3, item4);
					component2.pivot = Vector2.one * 0.5f;
					component2.anchoredPosition = new Vector2(0f, 0f - (float)i * num);
					component2.sizeDelta = new Vector2(40f, 15f);
				}
			}
		}

		[HarmonyPatch(typeof(GameController), "Update")]
		[HarmonyPostfix]
		private static void Postfix(GameController __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__instance.musictrack_status != 2)
			{
				return;
			}
			if ((Object)(object)_judgmentLabels != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_judgmentLabels).gameObject);
			}
			for (int i = 0; i < 5; i++)
			{
				if ((Object)(object)_counterRows[i] != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_counterRows[i]).gameObject);
				}
				_counterRows[i] = null;
			}
			_judgmentLabels = null;
			_uiholder = null;
		}
	}
	[BepInPlugin("JudgementCounter", "JudgementCounter", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin, ITootTallyModule
	{
		public static Plugin Instance;

		private const string CONFIG_NAME = "JudgementCounter.cfg";

		private Harmony _harmony;

		public static TootTallySettingPage settingPage;

		public ConfigEntry<bool> ModuleConfigEnabled { get; set; }

		public bool IsConfigInitialized { get; set; }

		public ConfigEntry<JudgementCounterManager.DisplayPosition> DisplayPosition { get; set; }

		public ConfigEntry<Color> ColorPerfect { get; set; }

		public ConfigEntry<Color> ColorNice { get; set; }

		public ConfigEntry<Color> ColorOk { get; set; }

		public ConfigEntry<Color> ColorMeh { get; set; }

		public ConfigEntry<Color> ColorNasty { get; set; }

		public string Name
		{
			get
			{
				return "JudgementCounter";
			}
			set
			{
				Name = value;
			}
		}

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
			}
		}

		private void TryInitialize()
		{
			ModuleConfigEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Modules", "Judgement Counter", true, "Displays a live hit note window overlay during gameplay.");
			TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
			Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
		}

		public void LoadModule()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.BepInExRootPath, "config/");
			ConfigFile val = new ConfigFile(text + "JudgementCounter.cfg", true)
			{
				SaveOnConfigSet = true
			};
			DisplayPosition = val.Bind<JudgementCounterManager.DisplayPosition>("Settings", "DisplayPosition", JudgementCounterManager.DisplayPosition.TopLeft, "Judgement Display Position.");
			ColorPerfect = val.Bind<Color>("Hex Colors", "Perfecto Color", new Color(0f, 1f, 1f), "Hex for Perfectos.");
			ColorNice = val.Bind<Color>("Hex Colors", "Nice Color", new Color(0f, 1f, 0f), "Hex for Nices.");
			ColorOk = val.Bind<Color>("Hex Colors", "OK Color", new Color(1f, 1f, 0f), "Hex for OKs.");
			ColorMeh = val.Bind<Color>("Hex Colors", "Meh Color", new Color(1f, 0.5f, 0f), "Hex for Mehs.");
			ColorNasty = val.Bind<Color>("Hex Colors", "Nasty Color", new Color(1f, 0f, 0f), "Hex for Nastys.");
			settingPage = TootTallySettingsManager.AddNewPage("Judgement Counter", "Judgement Counter", 40f, new Color(0f, 0f, 0f, 0f));
			if (settingPage != null)
			{
				settingPage.AddLabel("Display Position", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddDropdown("Display Position", (ConfigEntryBase)(object)DisplayPosition);
				settingPage.AddLabel("Perfecto Color Hex", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddColorSliders("Perfecto Color", "Perfecto Color", ColorPerfect);
				settingPage.AddLabel("Nice Color Hex", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddColorSliders("Nice Color Hex", "Nice Color", ColorNice);
				settingPage.AddLabel("OK Color Hex", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddColorSliders("OK Color Hex", "OK Color", ColorOk);
				settingPage.AddLabel("Meh Color Hex", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddColorSliders("Meh Color Hex", "Meh Color", ColorMeh);
				settingPage.AddLabel("Nasty Color Hex", (FontStyles)0, (TextAlignmentOptions)4097);
				settingPage.AddColorSliders("Nasty Color Hex", "Nasty Color", ColorNasty);
			}
			_harmony.PatchAll(typeof(JudgementCounterManager));
			LogInfo("Module loaded!");
		}

		public void UnloadModule()
		{
			_harmony.UnpatchSelf();
			TootTallySettingPage obj = settingPage;
			if (obj != null)
			{
				obj.Remove();
			}
			LogInfo("Module unloaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "JudgementCounter";

		public const string PLUGIN_NAME = "JudgementCounter";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}