Decompiled source of Taberry v1.1.0

plugins\Taberry.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NukeLib.UI;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using TMPro;
using Taberry.Cybergrind;
using Taberry.NormalLevel;
using Taberry.NormalLevel.Ranks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Taberry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fae6dd83acde3bf93896593dfdec1a5f276a5814")]
[assembly: AssemblyProduct("Taberry")]
[assembly: AssemblyTitle("Taberry")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Taberry
{
	public static class ConfigManager
	{
		public enum RequirementType
		{
			Next,
			SRank
		}

		public enum DeadEnemyIconDisplayType
		{
			Cross,
			Hide
		}

		private static PluginConfigurator config;

		public static BoolField ShowByDefault;

		public static FloatField PanelScale;

		public static BoolField ToggleAnimation;

		public static BoolField ShowLevelName;

		public static BoolField ShowLevelDifficulty;

		public static BoolField ShowRankStats;

		public static BoolField ShowRequirements;

		public static EnumField<RequirementType> RequirementStyle;

		public static BoolField ShowSecrets;

		public static BoolField ShowChallenge;

		public static BoolField ShowWave;

		public static BoolField ShowCGDifficulty;

		public static BoolField ShowEnemies;

		public static EnumField<IconStyle> IconStyle;

		public static BoolField ShowTotalTime;

		public static BoolField ShowWaveTime;

		public static EnumField<DeadEnemyIconDisplayType> DeadEnemyDisplayType;

		public static void Initialize()
		{
		}

		static ConfigManager()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00f1: 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_0116: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			config = PluginConfigurator.Create("Taberry", "com.github.end-4.taberry");
			string text = Path.Combine(Plugin.workingDir, "icon.png");
			if (File.Exists(text))
			{
				config.SetIconWithURL(text);
			}
			new ConfigHeader(config.rootPanel, "", 10);
			new ConfigHeader(config.rootPanel, "-- <color=#12b4ff>GENERAL</color> --", 24);
			ShowByDefault = new BoolField(config.rootPanel, "Show by default", "showByDefault", true);
			PanelScale = new FloatField(config.rootPanel, "Panel scale", "panelScale", 1f);
			PanelScale.postValueChangeEvent += (PostFloatValueChangeEvent)delegate(float f)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				UIUtils.FindRecursive("Canvas/Level Stats Controller/").transform.localScale = f * Vector3.one;
			};
			ToggleAnimation = new BoolField(config.rootPanel, "Toggle animation", "toggleAnimation", true);
			new ConfigHeader(config.rootPanel, "-- <color=#eb3b3b>NORMAL LEVELS</color> --", 24);
			ShowLevelName = new BoolField(config.rootPanel, "Show level name", "showLevelName", true);
			ShowLevelDifficulty = new BoolField(config.rootPanel, "Show difficulty", "showLevelDifficulty", true);
			ShowRankStats = new BoolField(config.rootPanel, "Show rank stats", "showRankStats", true);
			ShowRequirements = new BoolField(config.rootPanel, "Show rank requirements", "showRequirements", true);
			RequirementStyle = new EnumField<RequirementType>(config.rootPanel, "Requirement style", "requirementStyle", RequirementType.Next);
			ShowSecrets = new BoolField(config.rootPanel, "Show secrets", "showSecrets", true);
			ShowChallenge = new BoolField(config.rootPanel, "Show challenge", "showChallenge", true);
			new ConfigHeader(config.rootPanel, "", 10);
			new ConfigHeader(config.rootPanel, "-- <color=#fbc94c>CYBER GRIND</color> --", 24);
			ShowWave = new BoolField(config.rootPanel, "Show wave", "showWave", true);
			ShowCGDifficulty = new BoolField(config.rootPanel, "Show difficulty", "showCGDifficulty", true);
			ShowEnemies = new BoolField(config.rootPanel, "Show enemy icons", "showEnemies", true);
			IconStyle = new EnumField<IconStyle>(config.rootPanel, "Icon style", "cgIconStyle", (IconStyle)0);
			ShowTotalTime = new BoolField(config.rootPanel, "Show total time", "showTotalTime", true);
			ShowWaveTime = new BoolField(config.rootPanel, "Show wave time", "showWaveTime", true);
			DeadEnemyDisplayType = new EnumField<DeadEnemyIconDisplayType>(config.rootPanel, "Dead enemy display type", "deadEnemyDisplayType", DeadEnemyIconDisplayType.Cross);
		}
	}
	internal static class DifficultyHelper
	{
		public static int difficulty => MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);

		public static string GetDifficultyName(int difficulty)
		{
			return difficulty switch
			{
				0 => "Harmless", 
				1 => "Lenient", 
				2 => "Standard", 
				3 => "Violent", 
				4 => "Brutal", 
				5 => "ULTRAKILL Must Die", 
				_ => "Unknown difficulty", 
			};
		}

		public static string GetDifficultyName()
		{
			return GetDifficultyName(difficulty);
		}
	}
	[BepInPlugin("com.github.end-4.taberry", "Taberry", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource Log;

		public static string workingPath = Assembly.GetExecutingAssembly().Location;

		public static string workingDir = Path.GetDirectoryName(workingPath);

		public const string PluginGUID = "com.github.end-4.taberry";

		public const string PluginName = "Taberry";

		public const string PluginVersion = "1.1.0";

		internal static readonly string BundlePath = Path.Combine(workingDir, "assets", "taberry.bundle");

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				Log = ((BaseUnityPlugin)this).Logger;
				ConfigManager.Initialize();
				new Harmony("Taberry").PatchAll();
				SceneManager.sceneLoaded += OnSceneLoaded;
				Log.LogInfo((object)"Taberry loaded");
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIUtils.FindRecursive("Canvas/Level Stats Controller/");
			if ((Object)(object)val != (Object)null)
			{
				val.transform.localScale = ConfigManager.PanelScale.value * Vector3.one;
			}
			if (SceneHelper.CurrentScene == "Main Menu" || SceneHelper.CurrentScene == "uk_construct")
			{
				return;
			}
			if (SceneHelper.CurrentScene == "Endless")
			{
				CybergrindHandler.Setup();
				return;
			}
			GameObject val2 = UIUtils.FindRecursive("Canvas/Level Stats Controller");
			if (!((Object)(object)val2 == (Object)null) && val2.activeSelf)
			{
				NormalLevelHandler.Setup();
			}
		}
	}
	public class TabEnabler : MonoBehaviour
	{
		public GameObject levelStats;

		private void Start()
		{
			if ((Object)(object)levelStats != (Object)null)
			{
				UpdateAnchors();
				levelStats.SetActive(ConfigManager.ShowByDefault.value);
			}
		}

		private void OnEnable()
		{
			PrefsManager.onPrefChanged = (Action<string, object>)Delegate.Combine(PrefsManager.onPrefChanged, new Action<string, object>(OnPrefChanged));
		}

		private void OnDisable()
		{
			PrefsManager.onPrefChanged = (Action<string, object>)Delegate.Remove(PrefsManager.onPrefChanged, new Action<string, object>(OnPrefChanged));
		}

		private void OnPrefChanged(string key, object value)
		{
			if (key == "weaponHoldPosition")
			{
				UpdateAnchors();
			}
		}

		private void UpdateAnchors()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)levelStats == (Object)null))
			{
				int num = MonoSingleton<PrefsManager>.Instance.GetInt("weaponHoldPosition", 0);
				RectTransform val = (RectTransform)levelStats.transform;
				if (num == 2)
				{
					val.anchoredPosition = Vector2.one;
					val.pivot = Vector2.one;
				}
				else
				{
					val.anchoredPosition = new Vector2(0f, 1f);
					val.pivot = new Vector2(0f, 1f);
				}
				((Transform)val).localPosition = Vector3.zero;
			}
		}

		private void Update()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (MonoSingleton<InputManager>.Instance.InputSource.Stats.WasPerformedThisFrame && !((Object)(object)levelStats == (Object)null))
			{
				SlideFadeToggleEffectExtensions.SetActiveAnimated(levelStats, !levelStats.activeSelf, new Vector2(0f, 30f), 25f);
			}
		}
	}
}
namespace Taberry.NormalLevel
{
	public class LevelMiscController : MonoBehaviour
	{
		private GameObject SecretsGroup;

		private GameObject Challenge;

		private GameObject ChallengeDone;

		private List<GameObject> SecretOrbs = new List<GameObject>();

		private List<GameObject> SecretOrbDoneMarks = new List<GameObject>();

		private HashSet<int> ActivatedSecretOrbs = new HashSet<int>();

		private bool? lastChallengeActiveState;

		private bool? lastChallengeDoneActiveState;

		private static StatsManager sman => MonoSingleton<StatsManager>.Instance;

		private void Awake()
		{
			SecretsGroup = UIUtils.FindRecursive(((Component)this).gameObject, "Secrets/SecretOrbs");
			Challenge = UIUtils.FindRecursive(((Component)this).gameObject, "Challenge");
			ChallengeDone = UIUtils.FindRecursive(((Component)this).gameObject, "ChallengeDone");
		}

		private void Start()
		{
			for (int i = 0; i < sman.secretObjects.Length; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(NormalLevelHandler.SecretPrefab, SecretsGroup.transform);
				SecretOrbs.Add(val);
				GameObject item = UIUtils.FindRecursive(val, "DoneMark");
				SecretOrbDoneMarks.Add(item);
			}
			UpdateVisibilities();
			NormalLevelHandler.UnfuckLayouts();
		}

		public void UpdateVisibilities()
		{
			GameObject val = UIUtils.FindRecursive(((Component)this).gameObject, "Secrets");
			if (!((Object)(object)val == (Object)null))
			{
				UIUtils.FindRecursive(((Component)this).gameObject, "Secrets/SecretIcon").SetActive(SecretOrbs.Count > 0);
				val.SetActive(ConfigManager.ShowSecrets.value && SecretOrbs.Count > 0);
				UIUtils.FindRecursive(((Component)this).gameObject, "padder").SetActive(!val.activeSelf);
			}
		}

		private void Update()
		{
			foreach (int prevSecret in sman.prevSecrets)
			{
				if (ActivatedSecretOrbs.Add(prevSecret) && prevSecret < SecretOrbDoneMarks.Count && (Object)(object)SecretOrbDoneMarks[prevSecret] != (Object)null)
				{
					SecretOrbDoneMarks[prevSecret].SetActive(true);
				}
			}
			foreach (int newSecret in sman.newSecrets)
			{
				if (ActivatedSecretOrbs.Add(newSecret) && newSecret < SecretOrbDoneMarks.Count && (Object)(object)SecretOrbDoneMarks[newSecret] != (Object)null)
				{
					SecretOrbDoneMarks[newSecret].SetActive(true);
				}
			}
			bool flag = false;
			bool flag2 = false;
			ChallengeManager instance = MonoSingleton<ChallengeManager>.Instance;
			if ((Object)(object)instance != (Object)null && instance.challengeDone && !instance.challengeFailed)
			{
				flag = false;
				flag2 = ConfigManager.ShowChallenge.value;
			}
			else
			{
				flag = ConfigManager.ShowChallenge.value;
				flag2 = false;
			}
			if ((Object)(object)Challenge != (Object)null && (!lastChallengeActiveState.HasValue || lastChallengeActiveState.Value != flag))
			{
				Challenge.SetActive(flag);
				lastChallengeActiveState = flag;
			}
			if ((Object)(object)ChallengeDone != (Object)null && (!lastChallengeDoneActiveState.HasValue || lastChallengeDoneActiveState.Value != flag2))
			{
				ChallengeDone.SetActive(flag2);
				lastChallengeDoneActiveState = flag2;
			}
		}
	}
	public class LevelScoresController : MonoBehaviour
	{
		private class ScoreComponentCache
		{
			public GameObject Root;

			public Image CircProgMaskImage;

			public Image CircProgBorderImage;

			public TextMeshProUGUI ValueTextComp;

			public TextMeshProUGUI RequirementTextComp;

			public float LastValue = -1f;

			public Color LastBorderColor = Color.clear;

			public string LastValueText = string.Empty;

			public string LastRequirementText = string.Empty;

			public float LastFillAmount = -1f;

			public ConfigManager.RequirementType LastReqStyle = (ConfigManager.RequirementType)(-1);
		}

		private GameObject? TimeObj;

		private GameObject? KillsObj;

		private GameObject? StyleObj;

		private ScoreComponentCache? timeCache;

		private ScoreComponentCache? killsCache;

		private ScoreComponentCache? styleCache;

		private static StatsManager sman => MonoSingleton<StatsManager>.Instance;

		private Color RankColor(string formattedRankText)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Match match = Regex.Match(formattedRankText, "#([A-Fa-f0-9]{6})");
			Color result = default(Color);
			if (match.Success && ColorUtility.TryParseHtmlString(match.Value, ref result))
			{
				return result;
			}
			return Color.white;
		}

		private string FormatTime(float seconds)
		{
			int num = (int)seconds / 60;
			float num2 = seconds % 60f;
			return string.Format("{0}:{1}", num, num2.ToString("00.000"));
		}

		private void Awake()
		{
			TimeObj = UIUtils.FindRecursive(((Component)this).gameObject, "Time");
			KillsObj = UIUtils.FindRecursive(((Component)this).gameObject, "Kills");
			StyleObj = UIUtils.FindRecursive(((Component)this).gameObject, "Style");
			if ((Object)(object)TimeObj != (Object)null)
			{
				timeCache = CreateCache(TimeObj);
			}
			if ((Object)(object)KillsObj != (Object)null)
			{
				killsCache = CreateCache(KillsObj);
			}
			if ((Object)(object)StyleObj != (Object)null)
			{
				styleCache = CreateCache(StyleObj);
			}
		}

		private ScoreComponentCache CreateCache(GameObject target)
		{
			return new ScoreComponentCache
			{
				Root = target,
				CircProgMaskImage = UIUtils.FindRecursive(target, "CircProg/CircProgMask").GetComponent<Image>(),
				CircProgBorderImage = UIUtils.FindRecursive(target, "CircProg/CircProgMask/CircProgBorder").GetComponent<Image>(),
				ValueTextComp = UIUtils.FindRecursive(target, "ValueText").GetComponent<TextMeshProUGUI>(),
				RequirementTextComp = UIUtils.FindRecursive(target, "RequirementText").GetComponent<TextMeshProUGUI>()
			};
		}

		private void Start()
		{
			UpdateVisibilities();
			NormalLevelHandler.UnfuckLayouts();
		}

		internal void UpdateVisibilities()
		{
			if ((Object)(object)TimeObj != (Object)null)
			{
				UIUtils.FindRecursive(TimeObj, "RequirementText").SetActive(ConfigManager.ShowRequirements.value && !NormalLevelHandler.IsSecretLevel);
			}
			if ((Object)(object)KillsObj != (Object)null)
			{
				UIUtils.FindRecursive(KillsObj, "RequirementText").SetActive(ConfigManager.ShowRequirements.value && !NormalLevelHandler.IsSecretLevel);
			}
			if ((Object)(object)StyleObj != (Object)null)
			{
				UIUtils.FindRecursive(StyleObj, "RequirementText").SetActive(ConfigManager.ShowRequirements.value && !NormalLevelHandler.IsSecretLevel);
			}
			if (NormalLevelHandler.IsSecretLevel)
			{
				if ((Object)(object)TimeObj != (Object)null)
				{
					UIUtils.FindRecursive(TimeObj, "CircProg/CircProgMask").SetActive(false);
				}
				if ((Object)(object)KillsObj != (Object)null)
				{
					KillsObj.SetActive(false);
				}
				if ((Object)(object)StyleObj != (Object)null)
				{
					StyleObj.SetActive(false);
				}
			}
		}

		private void UpdateRank(ScoreComponentCache cache, int[] ranks, float currentValue, bool reverse, Func<float, string>? valueToStringTransform = null)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (valueToStringTransform == null)
			{
				valueToStringTransform = (float f) => f.ToString();
			}
			string text = valueToStringTransform(currentValue);
			if (cache.LastValueText != text)
			{
				((TMP_Text)cache.ValueTextComp).text = text;
				cache.LastValueText = text;
			}
			float num = (reverse ? ranks[0] : ranks[^1]);
			float num2 = ((num != 0f) ? (currentValue / num) : 0f);
			if (reverse)
			{
				num2 = 1f - num2;
			}
			num2 = Mathf.Clamp01(num2);
			if (!Mathf.Approximately(cache.LastFillAmount, num2))
			{
				cache.CircProgMaskImage.fillAmount = num2;
				cache.LastFillAmount = num2;
			}
			int rank = SingularRankHelper.GetRank(ranks, currentValue, reverse);
			Color val = default(Color);
			ColorUtility.TryParseHtmlString(SingularRankHelper.GetRankForegroundColor(rank), ref val);
			if (cache.LastBorderColor != val)
			{
				((Graphic)cache.CircProgBorderImage).color = val;
				cache.LastBorderColor = val;
			}
			ConfigManager.RequirementType value = ConfigManager.RequirementStyle.value;
			if (!Mathf.Approximately(cache.LastValue, currentValue) || cache.LastReqStyle != value)
			{
				int num3 = rank;
				switch (value)
				{
				case ConfigManager.RequirementType.Next:
					num3 = SingularRankHelper.ClampRank(rank + ((!reverse) ? 1 : 0), ranks);
					break;
				case ConfigManager.RequirementType.SRank:
					num3 = ranks.Length;
					break;
				}
				int num4 = Math.Min(num3 - 1, ranks.Length - 1);
				float arg = ranks[num4];
				string rankForegroundColor = SingularRankHelper.GetRankForegroundColor(num3);
				string text2 = valueToStringTransform(arg);
				string text3 = "<color=grey>/</color><color=" + rankForegroundColor + ">" + text2 + "</color>";
				if (cache.LastRequirementText != text3)
				{
					((TMP_Text)cache.RequirementTextComp).text = text3;
					cache.LastRequirementText = text3;
				}
				cache.LastReqStyle = value;
			}
			cache.LastValue = currentValue;
		}

		private void Update()
		{
			if (timeCache != null && (Object)(object)TimeObj != (Object)null && TimeObj.activeSelf)
			{
				UpdateRank(timeCache, sman.timeRanks, sman.seconds, reverse: true, FormatTime);
			}
			if (killsCache != null && (Object)(object)KillsObj != (Object)null && KillsObj.activeSelf)
			{
				UpdateRank(killsCache, sman.killRanks, sman.kills, reverse: false);
			}
			if (styleCache != null && (Object)(object)StyleObj != (Object)null && StyleObj.activeSelf)
			{
				UpdateRank(styleCache, sman.styleRanks, sman.stylePoints, reverse: false);
			}
		}
	}
	public class LevelTitleController : MonoBehaviour
	{
		private GameObject SmallText;

		private GameObject BigText;

		private TextMeshProUGUI? smallTextComp;

		private TextMeshProUGUI? bigTextComp;

		private string lastSmallText = string.Empty;

		private string lastBigText = string.Empty;

		internal void UpdateTitle()
		{
			if (!((Object)(object)smallTextComp == (Object)null) && !((Object)(object)bigTextComp == (Object)null))
			{
				MapInfo instance = MapInfo.Instance;
				StockMapInfo instance2 = StockMapInfo.Instance;
				string text = ((MapInfoBase)(instance?)).levelName ?? instance2?.assets.LargeText ?? SceneHelper.CurrentScene ?? "???";
				int num = text.IndexOf(':');
				string text2;
				string text3;
				if (num != -1)
				{
					ReadOnlySpan<char> readOnlySpan = text.AsSpan();
					text2 = readOnlySpan.Slice(0, num).Trim().ToString();
					text3 = readOnlySpan.Slice(num + 1).Trim().ToString();
				}
				else
				{
					text2 = (SceneHelper.IsPlayingCustom ? "Custom level" : "Campaign");
					text3 = ((text.Length > 0) ? text : (SceneHelper.CurrentScene ?? string.Empty));
				}
				string text4 = ((!ConfigManager.ShowLevelDifficulty.value) ? text2 : (DifficultyHelper.GetDifficultyName() + " > " + text2));
				bool flag = false;
				if (lastSmallText != text4)
				{
					((TMP_Text)smallTextComp).text = text4;
					lastSmallText = text4;
					flag = true;
				}
				if (lastBigText != text3)
				{
					((TMP_Text)bigTextComp).text = text3;
					lastBigText = text3;
					flag = true;
				}
				if (flag)
				{
					NormalLevelHandler.UnfuckLayouts();
				}
			}
		}

		internal void UpdateTitle(bool _)
		{
			UpdateTitle();
		}

		private void Awake()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			SmallText = UIUtils.FindRecursive(((Component)this).gameObject, "LevelInfoRow/Small");
			BigText = UIUtils.FindRecursive(((Component)this).gameObject, "Main");
			if ((Object)(object)SmallText != (Object)null)
			{
				smallTextComp = SmallText.GetComponent<TextMeshProUGUI>();
			}
			if ((Object)(object)BigText != (Object)null)
			{
				bigTextComp = BigText.GetComponent<TextMeshProUGUI>();
			}
			ConfigManager.ShowLevelDifficulty.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateTitle);
		}

		private void Start()
		{
			UpdateTitle();
		}

		private void OnDestroy()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			ConfigManager.ShowLevelDifficulty.postValueChangeEvent -= new PostBoolValueChangeEvent(UpdateTitle);
		}
	}
	internal static class NormalLevelHandler
	{
		internal static GameObject LevelStatsPrefab;

		internal static GameObject SecretPrefab;

		internal static bool IsSecretLevel;

		private static GameObject LevelStats;

		internal static GameObject LevelName;

		internal static GameObject LevelStatsColumn;

		internal static GameObject LevelMiscRow;

		static NormalLevelHandler()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			ConfigManager.ShowLevelName.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowRankStats.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowRequirements.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowSecrets.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowChallenge.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
		}

		private static void UpdateVisibilities(bool _)
		{
			UpdateVisibilities();
		}

		private static void UpdateVisibilities()
		{
			if ((Object)(object)LevelName != (Object)null)
			{
				LevelName.SetActive(ConfigManager.ShowLevelName.value);
			}
			if ((Object)(object)LevelStatsColumn != (Object)null)
			{
				LevelStatsColumn.SetActive(ConfigManager.ShowRankStats.value);
				LevelStatsColumn.GetComponent<LevelScoresController>().UpdateVisibilities();
			}
			if ((Object)(object)LevelMiscRow != (Object)null)
			{
				LevelMiscRow.SetActive((ConfigManager.ShowSecrets.value || ConfigManager.ShowChallenge.value) && !IsSecretLevel);
				LevelMiscRow.GetComponent<LevelMiscController>().UpdateVisibilities();
			}
			if ((Object)(object)LevelStats != (Object)null)
			{
				LevelStats.SetActive(ConfigManager.ShowLevelName.value || ConfigManager.ShowRankStats.value || ConfigManager.ShowSecrets.value || ConfigManager.ShowChallenge.value);
			}
		}

		public static void UnfuckLayouts()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)LevelStats.transform);
		}

		internal static void Setup()
		{
			GameObject val = UIUtils.FindRecursive("Canvas/Level Stats Controller");
			GameObject obj = UIUtils.FindRecursive(val, "Level Stats (1)");
			if ((Object)(object)LevelStatsPrefab == (Object)null || (Object)(object)SecretPrefab == (Object)null)
			{
				AssetBundle val2 = AssetBundle.LoadFromFile(Plugin.BundlePath);
				if ((Object)(object)LevelStatsPrefab == (Object)null)
				{
					LevelStatsPrefab = val2.LoadAsset<GameObject>("LevelStats");
				}
				if ((Object)(object)SecretPrefab == (Object)null)
				{
					SecretPrefab = val2.LoadAsset<GameObject>("Secret");
				}
				val2.Unload(false);
			}
			IsSecretLevel = Object.FindObjectOfType<LevelStats>().secretLevel;
			Object.Destroy((Object)(object)obj);
			LevelStats = Object.Instantiate<GameObject>(LevelStatsPrefab, val.transform);
			LevelName = UIUtils.FindRecursive(LevelStats, "Name");
			LevelStatsColumn = UIUtils.FindRecursive(LevelStats, "StatsColumn");
			LevelMiscRow = UIUtils.FindRecursive(LevelStats, "MiscRow");
			UnfuckLayouts();
			Object.Destroy((Object)(object)val.GetComponent<LevelStatsEnabler>());
			val.AddComponent<TabEnabler>().levelStats = LevelStats;
			LevelName.AddComponent<LevelTitleController>();
			LevelStatsColumn.AddComponent<LevelScoresController>();
			LevelMiscRow.AddComponent<LevelMiscController>();
			UpdateVisibilities();
		}
	}
}
namespace Taberry.NormalLevel.Ranks
{
	public static class SingularRankHelper
	{
		public static int GetRank(int[] ranksToCheck, float value, bool reverse)
		{
			int i;
			for (i = 0; i < ranksToCheck.Length && ((reverse && value <= (float)ranksToCheck[i]) || (!reverse && value >= (float)ranksToCheck[i])); i++)
			{
			}
			if (ranksToCheck != null && ranksToCheck.Length != 0)
			{
				return Mathf.Clamp(i, 0, ranksToCheck.Length);
			}
			return 0;
		}

		public static int ClampRank(int rank, int[] ranksToCheck)
		{
			return Mathf.Clamp(rank, 0, ranksToCheck.Length);
		}

		public static string GetRankForegroundColor(int rank)
		{
			return rank switch
			{
				0 => "#0094FF", 
				1 => "#4CFF00", 
				2 => "#FFD800", 
				3 => "#FF6A00", 
				4 => "#FF0000", 
				_ => "#FFFFFF", 
			};
		}
	}
}
namespace Taberry.Cybergrind
{
	internal static class CybergrindHandler
	{
		internal enum EnemyCategory
		{
			Common,
			Uncommon,
			Special,
			Mass
		}

		internal class EnemyIconRecord : IComparable<EnemyIconRecord>
		{
			public readonly EnemyIdentifier Enemy;

			public readonly EnemyCategory Type;

			public readonly bool IsRadiant;

			public readonly GameObject IconObject;

			public readonly GameObject RadiantModifier;

			public readonly GameObject IdolModifier;

			public readonly GameObject Eliminated;

			public bool LastActiveState = true;

			public bool LastBlessedState;

			public bool LastDeadState;

			public EnemyIconRecord(EnemyIdentifier enemy, EnemyCategory type, bool isRadiant, GameObject iconObject)
			{
				Enemy = enemy;
				Type = type;
				IsRadiant = isRadiant;
				IconObject = iconObject;
				RadiantModifier = UIUtils.FindRecursive(iconObject, "RadiantModifier");
				IdolModifier = UIUtils.FindRecursive(iconObject, "IdolModifier");
				Eliminated = UIUtils.FindRecursive(iconObject, "Eliminated");
			}

			public int CompareTo(EnemyIconRecord other)
			{
				if (other == null)
				{
					return 1;
				}
				int num = Type.CompareTo(other.Type);
				if (num != 0)
				{
					return num;
				}
				int num2 = MonoSingleton<EnemyTracker>.Instance.GetEnemyRank(Enemy).CompareTo(MonoSingleton<EnemyTracker>.Instance.GetEnemyRank(other.Enemy));
				if (num2 != 0)
				{
					return num2;
				}
				int num3 = string.Compare(Enemy.FullName, other.Enemy.FullName, StringComparison.InvariantCultureIgnoreCase);
				if (num3 == 0)
				{
					return ((Object)Enemy).GetInstanceID().CompareTo(((Object)other.Enemy).GetInstanceID());
				}
				return num3;
			}
		}

		internal static GameObject EnemyIconPrefab;

		internal static GameObject CGStatsPrefab;

		internal static GameObject? CGStatsObject;

		internal static GameObject? WaveProgress;

		internal static GameObject? CGEnemies;

		internal static GameObject? TimeGroup;

		internal static GameObject? TotalTime;

		internal static GameObject? ThisWaveTime;

		internal static TextMeshProUGUI? TotalTimeTextComp;

		internal static TextMeshProUGUI? ThisWaveTimeTextComp;

		internal static WaveIndicatorController? WaveIndicatorComp;

		private static bool? lastWaveVisible;

		private static bool? lastEnemiesVisible;

		private static bool? lastTotalTimeVisible;

		private static bool? lastWaveTimeVisible;

		private static bool? lastTimeGroupVisible;

		private static bool? lastStatsObjectVisible;

		internal static List<EnemyIconRecord> icons;

		static CybergrindHandler()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			icons = new List<EnemyIconRecord>();
			ConfigManager.ShowWave.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowEnemies.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowTotalTime.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowWaveTime.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
			ConfigManager.ShowCGDifficulty.postValueChangeEvent += new PostBoolValueChangeEvent(UpdateVisibilities);
		}

		private static bool AreAnyIconsActive()
		{
			for (int i = 0; i < icons.Count; i++)
			{
				EnemyIconRecord enemyIconRecord = icons[i];
				if ((Object)(object)enemyIconRecord?.IconObject != (Object)null && enemyIconRecord.IconObject.activeSelf)
				{
					return true;
				}
			}
			return false;
		}

		internal static void UpdateVisibilities()
		{
			bool value = ConfigManager.ShowWave.value;
			if ((Object)(object)WaveProgress != (Object)null && (!lastWaveVisible.HasValue || lastWaveVisible.Value != value))
			{
				WaveProgress.SetActive(value);
				lastWaveVisible = value;
			}
			bool flag = ConfigManager.ShowEnemies.value && AreAnyIconsActive();
			if ((Object)(object)CGEnemies != (Object)null && (!lastEnemiesVisible.HasValue || lastEnemiesVisible.Value != flag))
			{
				CGEnemies.SetActive(flag);
				lastEnemiesVisible = flag;
			}
			bool value2 = ConfigManager.ShowTotalTime.value;
			if ((Object)(object)TotalTime != (Object)null && (!lastTotalTimeVisible.HasValue || lastTotalTimeVisible.Value != value2))
			{
				TotalTime.SetActive(value2);
				lastTotalTimeVisible = value2;
			}
			bool value3 = ConfigManager.ShowWaveTime.value;
			if ((Object)(object)ThisWaveTime != (Object)null && (!lastWaveTimeVisible.HasValue || lastWaveTimeVisible.Value != value3))
			{
				ThisWaveTime.SetActive(value3);
				lastWaveTimeVisible = value3;
			}
			bool flag2 = ConfigManager.ShowTotalTime.value || ConfigManager.ShowWaveTime.value;
			if ((Object)(object)TimeGroup != (Object)null && (!lastTimeGroupVisible.HasValue || lastTimeGroupVisible.Value != flag2))
			{
				TimeGroup.SetActive(flag2);
				lastTimeGroupVisible = flag2;
			}
			bool flag3 = ((Object)(object)WaveProgress != (Object)null && WaveProgress.activeSelf) || ((Object)(object)CGEnemies != (Object)null && CGEnemies.activeSelf) || ((Object)(object)TimeGroup != (Object)null && TimeGroup.activeSelf);
			if ((Object)(object)CGStatsObject != (Object)null && (!lastStatsObjectVisible.HasValue || lastStatsObjectVisible.Value != flag3))
			{
				CGStatsObject.SetActive(flag3);
				lastStatsObjectVisible = flag3;
			}
			if ((Object)(object)WaveIndicatorComp != (Object)null)
			{
				WaveIndicatorComp.UpdateVisibilities();
			}
		}

		private static void UpdateVisibilities(bool _)
		{
			UpdateVisibilities();
		}

		public static void Setup()
		{
			GameObject val = UIUtils.FindRecursive("Canvas/Level Stats Controller");
			GameObject obj = UIUtils.FindRecursive(val, "Level Stats (1)");
			if ((Object)(object)CGStatsPrefab == (Object)null || (Object)(object)EnemyIconPrefab == (Object)null)
			{
				AssetBundle val2 = AssetBundle.LoadFromFile(Plugin.BundlePath);
				if ((Object)(object)CGStatsPrefab == (Object)null)
				{
					CGStatsPrefab = val2.LoadAsset<GameObject>("CGStats");
				}
				if ((Object)(object)EnemyIconPrefab == (Object)null)
				{
					EnemyIconPrefab = val2.LoadAsset<GameObject>("CGEnemy");
				}
				val2.Unload(false);
			}
			Object.Destroy((Object)(object)obj);
			CGStatsObject = Object.Instantiate<GameObject>(CGStatsPrefab, val.transform);
			GameObject val3 = (WaveProgress = UIUtils.FindRecursive(CGStatsObject, "Wave"));
			CGEnemies = UIUtils.FindRecursive(CGStatsObject, "Enemies");
			TimeGroup = UIUtils.FindRecursive(CGStatsObject, "Time");
			TotalTime = UIUtils.FindRecursive(TimeGroup, "Total");
			ThisWaveTime = UIUtils.FindRecursive(TimeGroup, "ThisWave");
			if ((Object)(object)TotalTime != (Object)null)
			{
				TotalTimeTextComp = TotalTime.GetComponent<TextMeshProUGUI>();
			}
			if ((Object)(object)ThisWaveTime != (Object)null)
			{
				ThisWaveTimeTextComp = ThisWaveTime.GetComponent<TextMeshProUGUI>();
			}
			Object.Destroy((Object)(object)val.GetComponent<LevelStatsEnabler>());
			val.AddComponent<TabEnabler>().levelStats = CGStatsObject;
			if ((Object)(object)val3 != (Object)null)
			{
				WaveIndicatorComp = val3.AddComponent<WaveIndicatorController>();
			}
			CGStatsObject.AddComponent<WeaponPosLayoutAdapter>();
			if ((Object)(object)CGEnemies != (Object)null)
			{
				CGEnemies.AddComponent<WeaponPosLayoutAdapter>();
			}
			lastWaveVisible = null;
			lastEnemiesVisible = null;
			lastTotalTimeVisible = null;
			lastWaveTimeVisible = null;
			lastTimeGroupVisible = null;
			lastStatsObjectVisible = null;
			UpdateVisibilities();
		}

		public static void UnfuckEnemiesLayout()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			if (!((Object)(object)CGEnemies == (Object)null))
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)CGEnemies.transform);
			}
		}
	}
	[HarmonyPatch]
	internal static class CybergrindPatches
	{
		private static float lastSeconds;

		private static StatsManager sman => MonoSingleton<StatsManager>.Instance;

		[HarmonyPatch(typeof(EndlessGrid), "Start")]
		[HarmonyPostfix]
		private static void EndlessGrid_Start()
		{
			CybergrindHandler.icons.Clear();
			lastSeconds = sman.seconds;
		}

		[HarmonyPatch(typeof(EndlessGrid), "SpawnOnGrid")]
		[HarmonyPostfix]
		private static void EndlessGrid_SpawnOnGrid(GameObject obj, bool radiant, GameObject __result, PrefabDatabase ___prefabs)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			EnemyIdentifier val = ((__result != null) ? __result.GetComponentInChildren<EnemyIdentifier>(true) : null);
			if (val != null)
			{
				GameObject val2 = Object.Instantiate<GameObject>(CybergrindHandler.EnemyIconPrefab, CybergrindHandler.CGEnemies.transform);
				EnemyIconController obj2 = UIUtils.FindRecursive(val2, "TypeIcon").AddComponent<EnemyIconController>();
				obj2.enemyIdentifier = val;
				obj2.style = ConfigManager.IconStyle.value;
				CybergrindHandler.EnemyCategory type = CybergrindHandler.EnemyCategory.Common;
				if (___prefabs.uncommonEnemies.Any((EndlessEnemy prefab) => (Object)(object)prefab.prefab == (Object)(object)obj))
				{
					type = CybergrindHandler.EnemyCategory.Uncommon;
				}
				else if (___prefabs.specialEnemies.Any((EndlessEnemy prefab) => (Object)(object)prefab.prefab == (Object)(object)obj))
				{
					type = CybergrindHandler.EnemyCategory.Special;
				}
				else if ((Object)(object)obj == (Object)(object)___prefabs.hideousMass)
				{
					type = CybergrindHandler.EnemyCategory.Mass;
				}
				CybergrindHandler.EnemyIconRecord enemyIconRecord = new CybergrindHandler.EnemyIconRecord(val, type, radiant, val2);
				if (radiant && (Object)(object)enemyIconRecord.RadiantModifier != (Object)null)
				{
					enemyIconRecord.RadiantModifier.SetActive(true);
				}
				if ((Object)(object)enemyIconRecord.IdolModifier != (Object)null)
				{
					enemyIconRecord.IdolModifier.SetActive(val.blessed);
				}
				enemyIconRecord.LastBlessedState = val.blessed;
				CybergrindHandler.icons.Add(enemyIconRecord);
				CybergrindHandler.icons.Sort();
				for (int num = 0; num < CybergrindHandler.icons.Count; num++)
				{
					CybergrindHandler.icons[num].IconObject.transform.SetAsLastSibling();
				}
				CybergrindHandler.UnfuckEnemiesLayout();
				CybergrindHandler.UpdateVisibilities();
			}
		}

		[HarmonyPatch(typeof(EndlessGrid), "Update")]
		[HarmonyPostfix]
		private static void EndlessGrid_Update()
		{
			bool flag = false;
			bool flag2 = false;
			for (int num = CybergrindHandler.icons.Count - 1; num >= 0; num--)
			{
				CybergrindHandler.EnemyIconRecord enemyIconRecord = CybergrindHandler.icons[num];
				if ((Object)(object)enemyIconRecord.IconObject == (Object)null)
				{
					CybergrindHandler.icons.RemoveAt(num);
					flag = true;
					flag2 = true;
				}
				else if ((Object)(object)enemyIconRecord.Enemy == (Object)null)
				{
					if (enemyIconRecord.LastActiveState)
					{
						enemyIconRecord.IconObject.SetActive(false);
						enemyIconRecord.LastActiveState = false;
						flag = true;
						flag2 = true;
					}
				}
				else
				{
					bool blessed = enemyIconRecord.Enemy.blessed;
					if (blessed != enemyIconRecord.LastBlessedState)
					{
						if ((Object)(object)enemyIconRecord.IdolModifier != (Object)null)
						{
							enemyIconRecord.IdolModifier.SetActive(blessed);
						}
						enemyIconRecord.LastBlessedState = blessed;
					}
					bool dead = enemyIconRecord.Enemy.dead;
					if (dead != enemyIconRecord.LastDeadState)
					{
						if ((Object)(object)enemyIconRecord.Eliminated != (Object)null)
						{
							enemyIconRecord.Eliminated.SetActive(dead);
						}
						enemyIconRecord.LastDeadState = dead;
						bool flag3 = !dead || ConfigManager.DeadEnemyDisplayType.value == ConfigManager.DeadEnemyIconDisplayType.Cross;
						if (enemyIconRecord.LastActiveState != flag3)
						{
							enemyIconRecord.IconObject.SetActive(flag3);
							enemyIconRecord.LastActiveState = flag3;
							flag = true;
							flag2 = true;
						}
					}
				}
			}
			if (flag)
			{
				CybergrindHandler.UnfuckEnemiesLayout();
			}
			if (flag2)
			{
				CybergrindHandler.UpdateVisibilities();
			}
			float seconds = sman.seconds;
			float num2 = Mathf.Max(0f, seconds - lastSeconds);
			int num3 = (int)(seconds / 60f);
			float num4 = seconds % 60f;
			int num5 = (int)(num2 / 60f);
			float num6 = num2 % 60f;
			if ((Object)(object)CybergrindHandler.TotalTimeTextComp != (Object)null)
			{
				((TMP_Text)CybergrindHandler.TotalTimeTextComp).text = string.Format("{0}:{1}", num3, num4.ToString("00.000"));
			}
			if ((Object)(object)CybergrindHandler.ThisWaveTimeTextComp != (Object)null)
			{
				((TMP_Text)CybergrindHandler.ThisWaveTimeTextComp).text = string.Format("+ {0}:{1}", num5, num6.ToString("00.000"));
			}
		}

		[HarmonyPatch(typeof(EndlessGrid), "NextWave")]
		[HarmonyPostfix]
		private static void EndlessGrid_NextWave()
		{
			for (int i = 0; i < CybergrindHandler.icons.Count; i++)
			{
				if ((Object)(object)CybergrindHandler.icons[i].IconObject != (Object)null)
				{
					Object.Destroy((Object)(object)CybergrindHandler.icons[i].IconObject);
				}
			}
			CybergrindHandler.icons.Clear();
			lastSeconds = sman.seconds;
			CybergrindHandler.UnfuckEnemiesLayout();
			CybergrindHandler.UpdateVisibilities();
		}
	}
	public class WaveIndicatorController : MonoBehaviour
	{
		private TextMeshProUGUI WaveText;

		private GameObject? DifficultyTextObj;

		private Image CircProgMask;

		private ActivateNextWave NextWaveObj;

		private int lastWave = -1;

		private float lastFontSize = -1f;

		private float lastPercentage = -1f;

		private bool? lastDifficultyVisibility;

		internal void UpdateVisibilities()
		{
			bool value = ConfigManager.ShowCGDifficulty.value;
			if ((Object)(object)DifficultyTextObj != (Object)null && (!lastDifficultyVisibility.HasValue || lastDifficultyVisibility.Value != value))
			{
				DifficultyTextObj.SetActive(value);
				lastDifficultyVisibility = value;
			}
		}

		private void Start()
		{
			WaveText = UIUtils.FindRecursive(((Component)this).gameObject, "WaveNumber/NumberText").GetComponent<TextMeshProUGUI>();
			DifficultyTextObj = UIUtils.FindRecursive(((Component)this).gameObject, "WaveNumber/Difficulty");
			CircProgMask = UIUtils.FindRecursive(((Component)this).gameObject, "WaveCircularProgress").GetComponent<Image>();
			NextWaveObj = Object.FindObjectOfType<ActivateNextWave>();
			if ((Object)(object)DifficultyTextObj != (Object)null)
			{
				TextMeshProUGUI component = DifficultyTextObj.GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component != (Object)null)
				{
					((TMP_Text)component).text = DifficultyHelper.GetDifficultyName();
				}
			}
			UpdateVisibilities();
		}

		private void Update()
		{
			EndlessGrid instance = MonoSingleton<EndlessGrid>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			int currentWave = instance.currentWave;
			if (currentWave != lastWave)
			{
				string text = currentWave.ToString();
				((TMP_Text)WaveText).text = text;
				lastWave = currentWave;
				float num = ((text.Length > 2) ? 20f : 24f);
				if (!Mathf.Approximately(((TMP_Text)WaveText).fontSize, num))
				{
					((TMP_Text)WaveText).fontSize = num;
				}
			}
			if ((Object)(object)NextWaveObj != (Object)null)
			{
				float num2 = ((instance.enemyAmount == 0) ? 0f : ((float)NextWaveObj.deadEnemies / (float)instance.enemyAmount));
				num2 = Mathf.Clamp01(num2);
				if (!Mathf.Approximately(lastPercentage, num2))
				{
					CircProgMask.fillAmount = num2;
					lastPercentage = num2;
				}
			}
		}
	}
	public class WeaponPosLayoutAdapter : MonoBehaviour
	{
		private void OnEnable()
		{
			PrefsManager.onPrefChanged = (Action<string, object>)Delegate.Combine(PrefsManager.onPrefChanged, new Action<string, object>(OnPrefChanged));
		}

		private void OnDisable()
		{
			PrefsManager.onPrefChanged = (Action<string, object>)Delegate.Remove(PrefsManager.onPrefChanged, new Action<string, object>(OnPrefChanged));
		}

		private void Start()
		{
			OnPrefChanged("weaponHoldPosition", MonoSingleton<PrefsManager>.Instance.GetInt("weaponHoldPosition", 0));
		}

		private void OnPrefChanged(string key, object value)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			if (!(key == "weaponHoldPosition"))
			{
				return;
			}
			int num = (int)value;
			HorizontalLayoutGroup component = ((Component)this).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)component != (Object)null)
			{
				((HorizontalOrVerticalLayoutGroup)component).reverseArrangement = num == 2;
				return;
			}
			GridLayoutGroup component2 = ((Component)this).GetComponent<GridLayoutGroup>();
			if ((Object)(object)component2 != (Object)null)
			{
				if ((int)component2.startCorner == 0 || (int)component2.startCorner == 1)
				{
					component2.startCorner = (Corner)(num == 2);
				}
				else
				{
					component2.startCorner = (Corner)((num == 2) ? 3 : 2);
				}
			}
		}
	}
}