Decompiled source of PegTheStreamer v1.2.0

PegTheStreamer.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Battle.Enemies;
using BepInEx;
using Cruciball;
using Currency;
using HarmonyLib;
using I2.Loc;
using PegTheStreamer.Behaviours;
using PegTheStreamer.Behaviours.Settings;
using PegTheStreamer.Behaviours.VoteOptions;
using PegTheStreamer.Behaviours.VoteStarters;
using PeglinUI;
using PeglinUI.PostBattle;
using PeglinUI.SettingsMenu;
using PeglinUI.SettingsMenu.Options;
using Relics;
using TMPro;
using UI;
using UnityEngine;
using UnityEngine.Events;
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.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace PegTheStreamer
{
	[BepInPlugin("ru.rwarazor.peglin.PegTheStreamer", "PegTheStreamer", "1.2.0")]
	[BepInProcess("Peglin.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("ru.rwarazor.peglin.PegTheStreamer");

		private void Awake()
		{
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ru.rwarazor.peglin.PegTheStreamer is loaded!");
		}
	}
	public static class Utils
	{
		public static Transform FindContents()
		{
			return GameObject.Find("PauseCanvas").transform.Find("NewOptionsPanel/BasePanel/GeneralSettings/ScrollView/OptionsSubpanel/Viewport/Contents");
		}

		public static void SetOptionDescription(GameObject option, string description)
		{
			Component component = ((Component)option.transform.Find("Text (TMP)")).GetComponent(typeof(TextMeshProUGUI));
			((TMP_Text)((component is TextMeshProUGUI) ? component : null)).text = description;
			Object.Destroy((Object)(object)((Component)option.transform.Find("Text (TMP)")).GetComponent(typeof(Localize)));
		}

		public static CarouselTextItem[] textsFromStrings(string[] strings)
		{
			CarouselTextItem[] array = (CarouselTextItem[])(object)new CarouselTextItem[strings.Length];
			for (int i = 0; i < strings.Length; i++)
			{
				array[i].item = strings[i];
				array[i].isTranslatable = false;
			}
			return array;
		}

		public static void SetCarouselOptionsText(CarouselOptions option, string[] strings)
		{
			option.textItems = textsFromStrings(strings);
		}

		public static void SetOptionColor(GameObject option, Color color)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Component component = option.GetComponent(typeof(Image));
			((Graphic)((component is Image) ? component : null)).color = color;
		}

		private static GameObject CopyOption(string optionToCopy, string newDescription, Color newColor)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindContents();
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val.Find(optionToCopy)).gameObject, val);
			SetOptionDescription(val2, newDescription);
			SetOptionColor(val2, newColor);
			return val2;
		}

		public static CarouselOptionsBoolean CreateBinaryOption(string description, Color color)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Component component = CopyOption("VSyncSelection", description, color).GetComponent(typeof(CarouselOptionsBoolean));
			return (CarouselOptionsBoolean)(object)((component is CarouselOptionsBoolean) ? component : null);
		}

		public static CarouselOptionsInt CreateIntOption(string description, Color color, string[] optionsDescriptions)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Component component = CopyOption("VignetteControl", description, color).GetComponent(typeof(CarouselOptionsInt));
			CarouselOptionsInt val = (CarouselOptionsInt)(object)((component is CarouselOptionsInt) ? component : null);
			SetCarouselOptionsText((CarouselOptions)(object)val, optionsDescriptions);
			return val;
		}

		private static void DeleteCarousel(GameObject option)
		{
			Object.DestroyImmediate((Object)(object)((Component)option.transform.Find("ArrowSelection")).gameObject);
			Object.DestroyImmediate((Object)(object)((Component)option.transform.Find("Carousel")).gameObject);
			Object.DestroyImmediate((Object)(object)option.GetComponent(typeof(CarouselOptionsBoolean)));
			Object.DestroyImmediate((Object)(object)option.GetComponent(typeof(Selectable)));
		}

		private static GameObject AddViewport(GameObject option)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_003b: 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)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text Area", new Type[1] { typeof(RectTransform) });
			Component component = val.GetComponent(typeof(RectTransform));
			RectTransform val2 = (RectTransform)(object)((component is RectTransform) ? component : null);
			val.AddComponent<RectMask2D>().padding = Vector4.zero;
			((Transform)val2).SetParent(option.transform, false);
			((Transform)val2).localScale = Vector3.one;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.sizeDelta = Vector2.zero;
			val2.pivot = new Vector2(0f, 0.5f);
			val2.offsetMin = new Vector2(570f, 0f);
			val2.offsetMax = new Vector2(-110f, 0f);
			return val;
		}

		public static TMP_InputField CreateInputFieldOption(string description, string placeholder, Color color, Color textColor)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CopyOption("VSyncSelection", description, color);
			DeleteCarousel(val);
			GameObject val2 = AddViewport(val);
			TextMeshProUGUI val3 = CreateText(val2.transform, "", new Vector3(120f, 0f, 0f));
			((Graphic)val3).color = textColor;
			((TMP_Text)val3).verticalAlignment = (VerticalAlignmentOptions)8192;
			((TMP_Text)val3).enableWordWrapping = false;
			TextMeshProUGUI val4 = CreateText(val2.transform, placeholder, new Vector3(120f, 0f, 0f));
			textColor.a *= 0.5f;
			((Graphic)val4).color = textColor;
			((TMP_Text)val4).verticalAlignment = (VerticalAlignmentOptions)8192;
			((TMP_Text)val4).enableWordWrapping = false;
			Component obj = val.AddComponent(typeof(TMP_InputField));
			TMP_InputField val5 = (TMP_InputField)(object)((obj is TMP_InputField) ? obj : null);
			? val6 = val5;
			Transform transform = val2.transform;
			((TMP_InputField)val6).textViewport = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			val5.textComponent = (TMP_Text)(object)val3;
			val5.placeholder = (Graphic)(object)val4;
			return val5;
		}

		public static TextMeshProUGUI CreateText(Transform parent, string text, Vector3 localPosition)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text");
			Component obj = val.AddComponent(typeof(TextMeshProUGUI));
			TextMeshProUGUI val2 = (TextMeshProUGUI)(object)((obj is TextMeshProUGUI) ? obj : null);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localScale = Vector3.one;
			((TMP_Text)val2).text = text;
			return val2;
		}

		public static TextMeshProUGUI CreateVoteTimerText(Transform parent, Vector3 localPosition)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = CreateText(parent, "VOTE NOW: 99s left", localPosition);
			((Behaviour)val).enabled = false;
			return val;
		}

		public static void PressButton(GameObject button)
		{
			Component component = button.GetComponent(typeof(Button));
			((component is Button) ? component : null).SendMessage("Press");
		}

		public static void EnsureGameUnpaused()
		{
			if (PauseMenu.Paused)
			{
				Component component = GameObject.Find("PauseCanvas").GetComponent(typeof(PauseMenu));
				((PauseMenu)((component is PauseMenu) ? component : null)).Resume();
			}
		}

		public static void EnsureInventoryClosed()
		{
			if (InventoryViewController.isOpen)
			{
				Component component = GameObject.Find("InventoryView").GetComponent(typeof(InventoryViewController));
				((InventoryViewController)((component is InventoryViewController) ? component : null)).HideInventory();
			}
		}

		public static void EnsurePostBattleUpgradesMainWindowOpen()
		{
			Component component = GameObject.Find("BattleUpgradesCanvas").GetComponent(typeof(BattleUpgradeCanvas));
			((BattleUpgradeCanvas)((component is BattleUpgradeCanvas) ? component : null)).BackFromInventory();
		}
	}
	public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
	{
		private static T _instance;

		public static T Instance
		{
			get
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				if (_instance == null)
				{
					GameObject val = new GameObject(typeof(T).Name);
					Object.DontDestroyOnLoad((Object)(object)val);
					Component obj = val.AddComponent(typeof(T));
					_instance = (T)(object)((obj is T) ? obj : null);
				}
				return _instance;
			}
		}

		public static void EnsureInstanceCreated()
		{
			T instance = Instance;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ru.rwarazor.peglin.PegTheStreamer";

		public const string PLUGIN_NAME = "PegTheStreamer";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace PegTheStreamer.Patches
{
	[HarmonyPatch(typeof(Enemy))]
	internal class AddNicknamePatch
	{
		public static bool IsBoss(EnemyType type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			return (type & 0x280) == 128;
		}

		[HarmonyPatch("Initialize")]
		public static void Postfix(Enemy __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if (IsBoss(__instance.enemyTypes) && !((Object)__instance).name.Contains("Tree"))
			{
				__instance.HealthBarObj.AddComponent(typeof(BossTwitchNickname));
			}
			else
			{
				__instance.HealthBarObj.AddComponent(typeof(EnemyTwitchNickname));
			}
		}
	}
	[HarmonyPatch(typeof(GameInit))]
	internal class ClearStartingDeck
	{
		[HarmonyPatch("Start")]
		public static void Prefix(GameInit __instance, LoadMapData ___LoadData)
		{
			if (___LoadData.NewGame && (bool)PTSSettingsManager.EnableMod && (bool)PTSSettingsManager.DoSlayTheStreamerStart)
			{
				StaticGameData.StartingOrbs = null;
				Singleton<STSStartManager>.Instance.state = STSStartManager.STSState.SHOULD_START;
			}
			else
			{
				Singleton<STSStartManager>.Instance.state = STSStartManager.STSState.DISABLED;
			}
		}
	}
	[HarmonyPatch(typeof(BattleController))]
	internal class StopBattleUntilDeckChosen
	{
		[HarmonyPatch("Update")]
		public static bool Prefix()
		{
			if (Singleton<STSStartManager>.Instance.state == STSStartManager.STSState.SHOULD_START || Singleton<STSStartManager>.Instance.state == STSStartManager.STSState.STARTED)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(InventoryViewController))]
	internal class UseInventoryViewAsTemplate
	{
		[HarmonyPatch("OnEnable")]
		public static void Postfix()
		{
			if (Singleton<STSStartManager>.Instance.state == STSStartManager.STSState.SHOULD_START)
			{
				Singleton<STSStartManager>.Instance.SetupStartingDeckChoice();
			}
		}
	}
	[HarmonyPatch(typeof(OptionsMenu))]
	internal class OptionsMenuPatch
	{
		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable()
		{
			Singleton<PTSSettingsManager>.Instance.ShowSettings();
			Singleton<PTSSettingsManager>.Instance.AddApplyActions();
		}

		[HarmonyPatch("OnDisable")]
		[HarmonyPrefix]
		public static void OnDisable()
		{
			Singleton<PTSSettingsManager>.Instance.RemoveApplyActions();
		}
	}
	[HarmonyPatch(typeof(PauseMenu))]
	internal class PauseMenuPatch
	{
		[HarmonyPatch("Awake")]
		public static void Postfix(PauseMenu __instance)
		{
			EnsureOptions(((Component)((Component)__instance).transform.Find("NewOptionsPanel")).gameObject);
		}

		public static void EnsureOptions(GameObject optionsMenu)
		{
			if (!((Object)(object)((optionsMenu != null) ? optionsMenu.GetComponent(typeof(OptionsCertificate)) : null) != (Object)null))
			{
				optionsMenu.AddComponent(typeof(OptionsCertificate));
				Object.Destroy((Object)(object)((Component)optionsMenu.transform.Find("ClickableButtonAccept")).GetComponent(typeof(RewiredUIButtonTrigger)));
				Object.Destroy((Object)(object)((Component)optionsMenu.transform.Find("ClickableButtonApply")).GetComponent(typeof(RewiredUIButtonTrigger)));
				Object.Destroy((Object)(object)((Component)optionsMenu.transform.Find("ClickableButtonCancel")).GetComponent(typeof(RewiredUIButtonTrigger)));
				Singleton<PTSSettingsManager>.Instance.CreateUI();
				PTSSettingsManager.TwitchOAuth.UIText.inputType = (InputType)2;
			}
		}
	}
	[HarmonyPatch(typeof(SettingsManager))]
	internal class SettingsManagerPatch
	{
		[HarmonyPatch("ApplySettings")]
		[HarmonyPostfix]
		public static void ApplySettingsPostfix(SettingsManager __instance)
		{
			Singleton<PTSSettingsManager>.Instance.ApplySettings();
		}

		[HarmonyPatch("RevertSettings")]
		[HarmonyPrefix]
		public static void RevertSettingsPrefix(SettingsManager __instance)
		{
			Singleton<PTSSettingsManager>.Instance.RevertSettings();
		}
	}
}
namespace PegTheStreamer.Patches.VoteStartersPatch
{
	[HarmonyPatch(typeof(GameInit))]
	internal class StartingRelicPatch
	{
		[HarmonyPatch("Start")]
		public static void Postfix(GameInit __instance)
		{
			Singleton<TwitchNamesPoolManager>.EnsureInstanceCreated();
			if ((bool)PTSSettingsManager.EnableMod && (bool)PTSSettingsManager.EnableVoteStarting)
			{
				((Component)__instance).gameObject.AddComponent(typeof(StartingRelic));
			}
		}

		[HarmonyPatch("AddRelic")]
		[HarmonyPrefix]
		public static void PickInterrupt(GameInit __instance)
		{
			Singleton<VoteManager>.Instance.InterruptVote();
		}

		[HarmonyPatch("SkipRelic")]
		[HarmonyPrefix]
		public static void SkipInterrupt(GameInit __instance)
		{
			Singleton<VoteManager>.Instance.InterruptVote();
		}
	}
}
namespace PegTheStreamer.Patches.VoteStarters
{
	[HarmonyPatch(typeof(BattleUpgradeCanvas))]
	internal class PostBattleRelicPatch
	{
		[HarmonyPatch("SetupRelicGrant")]
		[HarmonyPostfix]
		public static void SetupRelicGrant(BattleUpgradeCanvas __instance, RelicRarity rarity, bool isTreasure = false)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Invalid comparison between Unknown and I4
			if ((bool)PTSSettingsManager.EnableMod)
			{
				Singleton<VoteManager>.Instance.InterruptVote();
				PostBattleRelic.RelicTypeId relicTypeId = PostBattleRelic.RelicTypeId.NONE;
				if (isTreasure && (bool)PTSSettingsManager.EnableVoteChest)
				{
					relicTypeId = PostBattleRelic.RelicTypeId.CHEST;
				}
				if (!isTreasure && (int)rarity == 2 && (bool)PTSSettingsManager.EnableVoteElite)
				{
					relicTypeId = PostBattleRelic.RelicTypeId.ELITE;
				}
				if (!isTreasure && (int)rarity == 3 && (bool)PTSSettingsManager.EnableVoteBoss)
				{
					relicTypeId = PostBattleRelic.RelicTypeId.BOSS;
				}
				if (relicTypeId != 0)
				{
					PostBattleRelic postBattleRelic = ((Component)__instance).gameObject.AddComponent(typeof(PostBattleRelic)) as PostBattleRelic;
					postBattleRelic.RelicType = relicTypeId;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BattleUpgradeCanvas))]
	internal class PostBattleUpgradesPatch
	{
		[HarmonyPatch("SetUpPostBattleOptions")]
		[HarmonyPostfix]
		public static void PostBattleUpgrades(BattleUpgradeCanvas __instance, DeckManager ____deckManager)
		{
			if ((bool)PTSSettingsManager.EnableMod && (bool)PTSSettingsManager.EnableVotePostbattle)
			{
				(((Component)__instance).gameObject.AddComponent(typeof(PostBattleUpgrades)) as PostBattleUpgrades).deckManager = ____deckManager;
			}
		}
	}
	[HarmonyPatch(typeof(CurrencyManager))]
	internal class PostBattleUpgradesInterruptsPatch
	{
		[HarmonyPatch("RemoveGold")]
		[HarmonyPrefix]
		public static void RemoveGold(BattleUpgradeCanvas __instance)
		{
			Singleton<VoteManager>.Instance.InterruptVote();
		}
	}
}
namespace PegTheStreamer.Behaviours
{
	internal class EnemyTwitchNickname : MonoBehaviour
	{
		protected bool _holdingName = false;

		protected string _name;

		protected TextMeshProUGUI _text;

		protected virtual void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			if (Singleton<TwitchNamesPoolManager>.Instance.TryFetchName(out _name))
			{
				_holdingName = true;
				_text = Utils.CreateText(((Component)this).transform, _name, new Vector3(0f, -0.075f, 0f));
				((TMP_Text)_text).horizontalAlignment = (HorizontalAlignmentOptions)2;
				((TMP_Text)_text).verticalAlignment = (VerticalAlignmentOptions)4096;
				((TMP_Text)_text).fontSizeMin = 0.4f;
				((TMP_Text)_text).fontSizeMax = 0.6f;
				((TMP_Text)_text).maxVisibleLines = 1;
				((TMP_Text)_text).overflowMode = (TextOverflowModes)3;
				((TMP_Text)_text).enableAutoSizing = true;
				Transform transform = ((Component)_text).gameObject.transform;
				Vector2 sizeDelta = ((RectTransform)((transform is RectTransform) ? transform : null)).sizeDelta;
				Transform transform2 = ((Component)this).gameObject.transform;
				sizeDelta.x = ((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta.x - 0.2f;
				Transform transform3 = ((Component)_text).gameObject.transform;
				((RectTransform)((transform3 is RectTransform) ? transform3 : null)).sizeDelta = sizeDelta;
				((Graphic)_text).color = new Color(1f, 1f, 0.8f, 1f);
			}
		}

		private void OnDisable()
		{
			if (_holdingName)
			{
				Singleton<TwitchNamesPoolManager>.Instance.FreeName(_name);
			}
		}
	}
	internal class BossTwitchNickname : EnemyTwitchNickname
	{
		protected override void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			base.Awake();
			if (_holdingName)
			{
				((TMP_Text)_text).transform.localPosition = new Vector3(0.5f, 1.23f, 0f);
				((TMP_Text)_text).fontSizeMin = 0.6f;
				((TMP_Text)_text).fontSizeMax = 0.8f;
			}
		}
	}
	internal class STSStartManager : Singleton<STSStartManager>
	{
		public enum STSState
		{
			DISABLED,
			SHOULD_START,
			STARTED,
			FINISHED
		}

		public STSState state = STSState.DISABLED;

		public static int deckSize = 4;

		public static int poolSize => PTSSettingsManager.STSStartPoolSize;

		private void SetupViewController(GameObject view)
		{
			Component component = view.GetComponent(typeof(InventoryViewController));
			InventoryViewController val = (InventoryViewController)(object)((component is InventoryViewController) ? component : null);
			STSPoolViewController sTSPoolViewController = view.AddComponent(typeof(STSPoolViewController)) as STSPoolViewController;
			sTSPoolViewController.deckManager = val.deckManager;
			sTSPoolViewController.relicManager = val.relicManager;
			sTSPoolViewController.cruciballManager = val.cruciballManager;
			sTSPoolViewController.upgradeConfirmationPanelInspect = val.upgradeConfirmationPanelInspect;
			sTSPoolViewController.orbsLeftToAdd = deckSize;
			Object.Destroy((Object)(object)val);
		}

		private void SetupGridPopulator(GameObject grid)
		{
			Component component = grid.GetComponent(typeof(InventoryGridPopulator));
			InventoryGridPopulator val = (InventoryGridPopulator)(object)((component is InventoryGridPopulator) ? component : null);
			STSPoolPopulator sTSPoolPopulator = grid.AddComponent(typeof(STSPoolPopulator)) as STSPoolPopulator;
			sTSPoolPopulator.deckManager = val.deckManager;
			sTSPoolPopulator.relicManager = val.relicManager;
			sTSPoolPopulator.cruciballManager = val.cruciballManager;
			sTSPoolPopulator.upgradeOptionPrefab = val.upgradeOptionPrefab;
			sTSPoolPopulator.poolSize = poolSize;
			Object.Destroy((Object)(object)val);
		}

		private GameObject CreateWindow()
		{
			GameObject val = GameObject.Find("InventoryView");
			GameObject val2 = Object.Instantiate<GameObject>(val);
			val2.SetActive(false);
			Object.Destroy((Object)(object)((Component)val2.transform.Find("Container")).GetComponent(typeof(Button)));
			Object.Destroy((Object)(object)((Component)val2.transform.Find("Container/Frame")).GetComponent(typeof(Button)));
			Object.Destroy((Object)(object)((Component)val2.transform.Find("Container/Frame/CloseButton")).gameObject);
			SetupViewController(val2);
			SetupGridPopulator(((Component)val2.transform.Find("Container/Frame/TileFill/BallInventoryView/Scroll View/Viewport/OrbGrid")).gameObject);
			((Component)val2.transform.Find("Container")).gameObject.SetActive(true);
			return val2;
		}

		public void SetupStartingDeckChoice()
		{
			state = STSState.STARTED;
			GameObject val = CreateWindow();
			val.SetActive(true);
		}
	}
	public class TwitchManager : Singleton<TwitchManager>
	{
		public delegate void OnChatMessage(string chatter, string msg);

		private TcpClient Twitch;

		private StreamReader Reader;

		private StreamWriter Writer;

		private const string URL = "irc.chat.twitch.tv";

		private const int PORT = 6667;

		private float lastTimeTried;

		private float currentDelay = 1f;

		private string User => PTSSettingsManager.TwitchLogin;

		private string OAuth => PTSSettingsManager.TwitchOAuth;

		public event OnChatMessage onChatMessage;

		public bool EnsureConnected()
		{
			if (Twitch != null && Twitch.Connected)
			{
				return true;
			}
			if (!ExponentialBackoff())
			{
				return false;
			}
			Debug.Log((object)"Connecting to Twitch");
			Twitch = new TcpClient("irc.chat.twitch.tv", 6667);
			Reader = new StreamReader(Twitch.GetStream());
			Writer = new StreamWriter(Twitch.GetStream());
			Connect(User);
			if (Twitch.Connected)
			{
				Debug.Log((object)"Connection successful?");
				SendChatMessage("Welcome to Peg The Streamer!");
				currentDelay = 1f;
				return true;
			}
			Debug.Log((object)$"Connection failed :(, trying again in {currentDelay} seconds");
			return false;
		}

		public void SendChatMessage(string msg)
		{
			if ((bool)PTSSettingsManager.DoSendChatMessages)
			{
				Writer.WriteLine("PRIVMSG #" + User.ToLower() + " :" + msg);
				Writer.Flush();
			}
		}

		private void Awake()
		{
			lastTimeTried = -1f;
		}

		private void Update()
		{
			if (Singleton<VoteManager>.Instance.IsVoteActive && !Twitch.Connected)
			{
				EnsureConnected();
			}
			while (true)
			{
				TcpClient twitch = Twitch;
				if (twitch != null && twitch.Available > 0)
				{
					HandleRawLine(Reader.ReadLine());
					continue;
				}
				break;
			}
		}

		private void Connect(string channel)
		{
			Writer.Write("PASS " + OAuth + "\nNICK " + User.ToLower() + "\nJOIN #" + channel.ToLower() + "\n");
			Writer.Flush();
		}

		private bool ExponentialBackoff()
		{
			if (Time.realtimeSinceStartup >= lastTimeTried + currentDelay)
			{
				lastTimeTried = Time.realtimeSinceStartup;
				currentDelay = Mathf.Min(64f, currentDelay * 2f);
				return true;
			}
			return false;
		}

		private void HandleRawLine(string rawLine)
		{
			if (rawLine.StartsWith("PING "))
			{
				Writer.WriteLine("PONG " + rawLine.Substring(5));
				Writer.Flush();
			}
			else if (rawLine.Contains("PRIVMSG"))
			{
				int num = rawLine.IndexOf(":") + 1;
				int length = rawLine.IndexOf(" ", num) - num;
				int startIndex = rawLine.IndexOf(":", num + 1) + 1;
				string chatter = rawLine.Substring(num, length);
				string msg = rawLine.Substring(startIndex);
				this.onChatMessage?.Invoke(chatter, msg);
			}
		}
	}
	internal class TwitchNamesPoolManager : Singleton<TwitchNamesPoolManager>
	{
		private HashSet<string> _currentlyUsed = new HashSet<string>();

		private HashSet<string> _unused = new HashSet<string>();

		public bool TryFetchName(out string res)
		{
			if (_unused.Count == 0)
			{
				res = null;
				return false;
			}
			res = _unused.ElementAt(Random.Range(0, _unused.Count));
			_unused.Remove(res);
			_currentlyUsed.Add(res);
			return true;
		}

		public void FreeName(string res)
		{
			_currentlyUsed.Remove(res);
			if (FilterNickname(res))
			{
				_unused.Add(res);
			}
		}

		private string StripNickname(string name)
		{
			return name.Substring(0, name.IndexOf("!"));
		}

		private bool FilterNickname(string name)
		{
			return name.Length <= 12;
		}

		private void HandleChatMessage(string chatter, string msg)
		{
			chatter = StripNickname(chatter);
			if (!_currentlyUsed.Contains(chatter) && FilterNickname(chatter))
			{
				_unused.Add(chatter);
			}
		}

		private void Awake()
		{
			Singleton<TwitchManager>.Instance.onChatMessage += HandleChatMessage;
		}

		private void OnDestroy()
		{
			Singleton<TwitchManager>.Instance.onChatMessage -= HandleChatMessage;
		}
	}
	public class VoteManager : Singleton<VoteManager>
	{
		private bool _isVoteActive = false;

		private int _totalVotes;

		private List<VoteOption> _options;

		private float _startTime;

		private float _expectedEndTime;

		private bool _multipleVotes;

		private HashSet<string> chattersWithVote;

		private bool _shoudlChangeOddity;

		private bool _oddity;

		private bool _lastOddity;

		private const int ALPH_SIZE = 26;

		public bool IsVoteActive => _isVoteActive;

		public TextMeshProUGUI VoteTimerText { get; set; }

		public void CleanVote()
		{
			_options = new List<VoteOption>();
			_totalVotes = 0;
			_shoudlChangeOddity = false;
			chattersWithVote = new HashSet<string>();
		}

		public void AddVoteOption(VoteOption option)
		{
			_options.Add(option);
		}

		public void ChangeOddity()
		{
			_shoudlChangeOddity = true;
		}

		public void StartVote()
		{
			Debug.Log((object)"StartVote");
			if (IsVoteActive)
			{
				InterruptVote();
			}
			_oddity = _shoudlChangeOddity && !_lastOddity;
			if (_options.Count == 0)
			{
				return;
			}
			if (_options.Count == 1)
			{
				if ((bool)PTSSettingsManager.DoForceOnlyOption)
				{
					_options[0].Choose();
				}
			}
			else
			{
				StartVoteSuccessfully();
			}
		}

		public void StartVoteSuccessfully()
		{
			Debug.Log((object)"StartVoteSuccessfully");
			_isVoteActive = true;
			_options.Sort();
			_startTime = Time.realtimeSinceStartup;
			_expectedEndTime = _startTime + (float)(int)PTSSettingsManager.VoteTime;
			_multipleVotes = PTSSettingsManager.AllowMultipleVotes;
			UpdateText();
			Singleton<TwitchManager>.Instance.onChatMessage += HandleMessage;
			StartVoteChatMessage();
		}

		public void InterruptVote()
		{
			Debug.Log((object)"InterruptVote");
			if (!IsVoteActive)
			{
				return;
			}
			Singleton<TwitchManager>.Instance.onChatMessage -= HandleMessage;
			_isVoteActive = false;
			_lastOddity = _oddity;
			HideVoteTimer();
			foreach (VoteOption option in _options)
			{
				if (Object.op_Implicit((Object)(object)option))
				{
					option.HideCountText();
				}
			}
		}

		public void EndVote()
		{
			Debug.Log((object)"EndVote");
			if (IsVoteActive)
			{
				InterruptVote();
				SelectWinner();
			}
		}

		public void Update()
		{
			if (IsVoteActive)
			{
				UpdateText();
			}
		}

		public void LateUpdate()
		{
			if (IsVoteActive && Time.realtimeSinceStartup >= _expectedEndTime)
			{
				EndVote();
			}
		}

		private string GetOptionIndex(int index)
		{
			if (!_oddity)
			{
				return index.ToString();
			}
			StringBuilder stringBuilder = new StringBuilder();
			while (index > 0 || stringBuilder.Length == 0)
			{
				stringBuilder.Append((char)(65 + index % 26));
				index /= 26;
			}
			return stringBuilder.ToString();
		}

		private bool TryParseOptionIndex(string index, out int ans)
		{
			if (!_oddity)
			{
				return int.TryParse(index, out ans);
			}
			ans = 0;
			foreach (char c in index)
			{
				if (c < 'A' || c > 'Z')
				{
					return false;
				}
				ans = ans * 26 + (c - 65);
			}
			return true;
		}

		private void ShowVoteTimer()
		{
			if (Object.op_Implicit((Object)(object)VoteTimerText))
			{
				((Behaviour)VoteTimerText).enabled = true;
			}
		}

		private void HideVoteTimer()
		{
			if (Object.op_Implicit((Object)(object)VoteTimerText))
			{
				((Behaviour)VoteTimerText).enabled = false;
			}
		}

		private void UpdateText()
		{
			for (int i = 0; i < _options.Count; i++)
			{
				VoteOption voteOption = _options[i];
				voteOption.ShowCountText();
				voteOption.SetCountText($"#{GetOptionIndex(i)}: {voteOption.Votes} ({((_totalVotes != 0) ? (voteOption.Votes * 100 / _totalVotes) : 0)}%)");
			}
			ShowVoteTimer();
			((TMP_Text)VoteTimerText).text = $"VOTE NOW: {Mathf.Max(0, Mathf.RoundToInt(_expectedEndTime - Time.realtimeSinceStartup))}s left";
		}

		private void StartVoteChatMessage()
		{
			string text = "VOTE NOW:";
			for (int i = 0; i < _options.Count; i++)
			{
				VoteOption voteOption = _options[i];
				text = text + " #" + GetOptionIndex(i) + ": " + _options[i].GetOptionTextForChat() + ";";
			}
			Singleton<TwitchManager>.Instance.SendChatMessage(text);
		}

		private void EndVoteChatMessage(VoteOption winner)
		{
			string msg = "Vote ended... chose " + winner.GetOptionTextForChat();
			Singleton<TwitchManager>.Instance.SendChatMessage(msg);
		}

		private void HandleMessage(string chatter, string message)
		{
			if (message[0] == '#')
			{
				int length = ((message.IndexOf(" ") == -1) ? (message.Length - 1) : (message.IndexOf(" ") - 1));
				if (TryParseOptionIndex(message.Substring(1, length), out var ans))
				{
					AddChatVote(chatter, ans);
				}
			}
		}

		private void AddChatVote(string chatter, int option)
		{
			if (IsVoteActive && option >= 0 && option < _options.Count && (_multipleVotes || !chattersWithVote.Contains(chatter)))
			{
				_options[option].Votes++;
				_totalVotes++;
				chattersWithVote.Add(chatter);
			}
		}

		private void SelectWinner()
		{
			List<VoteOption> list = new List<VoteOption>();
			foreach (VoteOption option in _options)
			{
				if (list.Count == 0 || option.Votes == list[0].Votes)
				{
					list.Add(option);
				}
				else if (option.Votes > list[0].Votes)
				{
					list = new List<VoteOption>();
					list.Add(option);
				}
			}
			VoteOption voteOption = list[Random.Range(0, list.Count)];
			EndVoteChatMessage(voteOption);
			voteOption.Choose();
		}
	}
	public class OptionsCertificate : MonoBehaviour
	{
	}
	public class PTSSettingsManager : Singleton<PTSSettingsManager>
	{
		private static readonly Color backgroundColor = new Color(0.8f, 0.45f, 0.2f, 0.2f);

		private static readonly Color textColor = new Color(0.2f, 0.1961f, 0.2392f, 1f);

		public static SettingBoolean EnableMod = new SettingBoolean("EnableMod", "Peg The Streamer?", defaultValue: true, backgroundColor);

		public static SettingBoolean DoPullNicknames = new SettingBoolean("DoPullNicknames", "Peg The Chat?", defaultValue: true, backgroundColor);

		public static SettingString TwitchLogin = new SettingString("TwitchLogin", "Twitch login: ", "", "Enter login here", backgroundColor, textColor);

		public static SettingString TwitchOAuth = new SettingString("TwitchOAuth", "Twitch OAuth: ", "", "Enter OAuth here", backgroundColor, textColor);

		public static SettingBoolean DoSendChatMessages = new SettingBoolean("DoSendChatMessages", "Send chat messages?", defaultValue: true, backgroundColor);

		public static SettingInt VoteTime = new SettingInt("VoteTime", "Vote timer (seconds)", 35, new int[11]
		{
			10, 15, 20, 25, 30, 35, 40, 50, 60, 90,
			120
		}, backgroundColor);

		public static SettingBoolean DoSlayTheStreamerStart = new SettingBoolean("DoSlayTheStreamerStart", "Do slay the streamer start", defaultValue: true, backgroundColor);

		public static SettingBoolean DoForceOnlyOption = new SettingBoolean("DoForceOnlyOption", "Auto-choose if single option", defaultValue: true, backgroundColor);

		public static SettingBoolean EnableVoteStarting = new SettingBoolean("EnableVoteStarting", "Vote for starting relic", defaultValue: true, backgroundColor);

		public static SettingBoolean AllowSkipStarting = new SettingBoolean("AllowSkipStarting", "Allow skip starting relic", defaultValue: false, backgroundColor);

		public static SettingBoolean EnableVotePostbattle = new SettingBoolean("EnableVotePostbattle", "Vote for post-battle reward", defaultValue: true, backgroundColor);

		public static SettingInt MaxPostbattleVotes = new SettingInt("MaxPostbattleVotes", "Max postbattle votes", 1, new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, backgroundColor);

		public static SettingBoolean AllowPostbattleUpgrades = new SettingBoolean("AllowPostbattleUpgrades", "Allow post-battle orb upgrades", defaultValue: false, backgroundColor);

		public static SettingBoolean AllowPostbattleHeal = new SettingBoolean("AllowPostbattleHeal", "Allow post-battle heal", defaultValue: false, backgroundColor);

		public static SettingBoolean AllowPostbattleToad = new SettingBoolean("AllowPostbattleToad", "Allow post-battle +max HP", defaultValue: false, backgroundColor);

		public static SettingBoolean EnableVoteChest = new SettingBoolean("EnableVoteChest", "Vote for chest relics", defaultValue: true, backgroundColor);

		public static SettingBoolean AllowSkipChest = new SettingBoolean("AllowSkipChest", "Allow skip chest relic", defaultValue: false, backgroundColor);

		public static SettingBoolean EnableVoteElite = new SettingBoolean("EnableVoteElite", "Vote for elite relics", defaultValue: true, backgroundColor);

		public static SettingBoolean AllowSkipElite = new SettingBoolean("AllowSkipElite", "Allow skip elite relic", defaultValue: false, backgroundColor);

		public static SettingBoolean EnableVoteBoss = new SettingBoolean("EnableVoteBoss", "Vote for boss relics", defaultValue: true, backgroundColor);

		public static SettingBoolean AllowSkipBoss = new SettingBoolean("AllowSkipBoss", "Allow skip boss relic", defaultValue: false, backgroundColor);

		public static SettingInt STSStartPoolSize = new SettingInt("STSStartPoolSize", "STS start orb pool size", 15, new int[6] { 4, 10, 12, 15, 20, 25 }, backgroundColor);

		public static SettingBoolean AllowMultipleVotes = new SettingBoolean("AllowMultipleVotes", "Multiple votes/chatter (DEBUG)", defaultValue: false, backgroundColor);

		private SettingBase[] settings = new SettingBase[23]
		{
			EnableMod, DoPullNicknames, TwitchLogin, TwitchOAuth, DoSendChatMessages, VoteTime, DoSlayTheStreamerStart, DoForceOnlyOption, EnableVoteStarting, AllowSkipStarting,
			EnableVotePostbattle, MaxPostbattleVotes, AllowPostbattleUpgrades, AllowPostbattleHeal, AllowPostbattleToad, EnableVoteChest, AllowSkipChest, EnableVoteElite, AllowSkipElite, EnableVoteBoss,
			AllowSkipBoss, STSStartPoolSize, AllowMultipleVotes
		};

		private void Awake()
		{
			LoadSettings();
		}

		private void Start()
		{
			InitializePreviousSettings();
			SaveSettings();
		}

		public void ApplySettings()
		{
			SaveSettings();
			InitializePreviousSettings();
		}

		public void LoadSettings()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.LoadValue();
			}
		}

		public void SaveSettings()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.SaveValue();
			}
			PlayerPrefs.Save();
		}

		public void InitializePreviousSettings()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.InitializePreviousValue();
			}
		}

		public void RevertSettings()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.RevertValue();
			}
			ApplySettings();
		}

		public void ShowSettings()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.ShowValue();
			}
		}

		public void AddApplyActions()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.AddApplyAction();
			}
		}

		public void RemoveApplyActions()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.RemoveApplyAction();
			}
		}

		public void CreateUI()
		{
			SettingBase[] array = settings;
			foreach (SettingBase settingBase in array)
			{
				settingBase.CreateUI();
			}
		}
	}
	internal class STSPoolPopulator : MonoBehaviour
	{
		public int poolSize;

		public DeckManager deckManager;

		public RelicManager relicManager;

		public CruciballManager cruciballManager;

		public GameObject upgradeOptionPrefab;

		private List<GameObject> GetRandomOrbPool()
		{
			float value = Random.value;
			if (value <= 0.6f)
			{
				return deckManager.CommonOrbPool;
			}
			if (value <= 0.9f)
			{
				return deckManager.UncommonOrbPool;
			}
			return deckManager.RareOrbPool;
		}

		private GameObject GetRandomOrb()
		{
			List<GameObject> randomOrbPool = GetRandomOrbPool();
			return randomOrbPool[Random.Range(0, randomOrbPool.Count)];
		}

		private void OnEnable()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < poolSize; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(upgradeOptionPrefab, ((Component)this).transform);
				GameObject randomOrb = GetRandomOrb();
				val.transform.localScale = Vector3.one;
				UpgradeOption component = val.GetComponent<UpgradeOption>();
				component.SpecifiedOrb = randomOrb;
				component.upgradeType = (UpgradeType)4;
				val.GetComponent<ButtonHandleHover>().noteOffset = 10;
			}
		}
	}
	internal class STSPoolViewController : MonoBehaviour
	{
		private bool isOpen = false;

		private GameObject chosenOption = null;

		public int orbsLeftToAdd;

		public DeckManager deckManager;

		public CruciballManager cruciballManager;

		public RelicManager relicManager;

		public UpgradeConfirmationOrbInspect upgradeConfirmationPanelInspect;

		public TMP_Text chooseText;

		private void OnEnable()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			isOpen = true;
			UpgradeOption.OnUpgradeOptionClicked = (UpgradeOptionClicked)Delegate.Combine((Delegate?)(object)UpgradeOption.OnUpgradeOptionClicked, (Delegate?)new UpgradeOptionClicked(HandleUpgradeOptionClicked));
			upgradeConfirmationPanelInspect.Init(deckManager, relicManager, cruciballManager);
			UpdateText();
		}

		private void OnDisable()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			isOpen = false;
			UpgradeOption.OnUpgradeOptionClicked = (UpgradeOptionClicked)Delegate.Remove((Delegate?)(object)UpgradeOption.OnUpgradeOptionClicked, (Delegate?)new UpgradeOptionClicked(HandleUpgradeOptionClicked));
		}

		private void HandleUpgradeOptionClicked(UpgradeType type, GameObject clickedButton = null, GameObject chosen = null)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			if (isOpen && (int)type == 4)
			{
				chosenOption = clickedButton;
				((Component)upgradeConfirmationPanelInspect).gameObject.SetActive(true);
				upgradeConfirmationPanelInspect.PopulateForNewOrb(chosen, 0);
			}
			else if ((int)type == 5)
			{
				((Component)upgradeConfirmationPanelInspect).gameObject.SetActive(false);
				Object.Destroy((Object)(object)chosenOption);
				deckManager.AddOrbToDeck(chosen);
				orbsLeftToAdd--;
				UpdateText();
				if (orbsLeftToAdd == 0)
				{
					FinishChoosingStartingDeck();
				}
			}
		}

		private void FinishChoosingStartingDeck()
		{
			((Component)this).gameObject.SetActive(false);
			GameObject.FindWithTag("GameController").GetComponent(typeof(BattleController)).SendMessage("DestroyCurrentBall");
			deckManager.ShuffleCompleteDeck(true);
			Singleton<STSStartManager>.Instance.state = STSStartManager.STSState.FINISHED;
		}

		private void UpdateText()
		{
			if ((Object)(object)chooseText == (Object)null)
			{
				SetupText();
			}
			chooseText.text = $"Choose your deck! {orbsLeftToAdd} orbs left";
		}

		private void SetupText()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = (chooseText = (TMP_Text)(object)Utils.CreateText(((Component)this).transform, "placeholder choose orbs text", new Vector3(0f, 200f, 0f)));
			val.horizontalAlignment = (HorizontalAlignmentOptions)2;
			val.fontSize = 45f;
			val.maxVisibleLines = 1;
			val.overflowMode = (TextOverflowModes)3;
			Transform transform = ((Component)val).gameObject.transform;
			Vector2 sizeDelta = ((RectTransform)((transform is RectTransform) ? transform : null)).sizeDelta;
			Transform transform2 = ((Component)this).transform;
			sizeDelta.x = ((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta.x - 0.2f;
			Transform transform3 = ((Component)val).gameObject.transform;
			((RectTransform)((transform3 is RectTransform) ? transform3 : null)).sizeDelta = sizeDelta;
		}
	}
}
namespace PegTheStreamer.Behaviours.VoteStarters
{
	public class PostBattleOrbUpgrade : VoteStarter
	{
		public PostBattleUpgrades parentVoteStarter;

		public DeckManager deckManager;

		protected override bool StartVote()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			if (!Singleton<TwitchManager>.Instance.EnsureConnected())
			{
				return false;
			}
			Transform val = ((Component)this).transform.Find("Container/UpgradePanel/Image/BallInventoryView/Scroll View/Viewport/OrbGrid");
			if (deckManager.GetUpgradeableOrbs().Count == 1)
			{
				PostBattleUpgradeOrbVoteOption postBattleUpgradeOrbVoteOption = ((Component)val.GetChild(0)).gameObject.AddComponent(typeof(PostBattleUpgradeOrbVoteOption)) as PostBattleUpgradeOrbVoteOption;
				postBattleUpgradeOrbVoteOption.OrbIndex = 0;
				postBattleUpgradeOrbVoteOption.voteStarter = parentVoteStarter;
				postBattleUpgradeOrbVoteOption.Choose();
				return true;
			}
			VoteManager instance = Singleton<VoteManager>.Instance;
			instance.CleanVote();
			int num = 0;
			foreach (Transform item in val)
			{
				Transform val2 = item;
				if (((Component)val2).gameObject.activeInHierarchy)
				{
					PostBattleUpgradeOrbVoteOption postBattleUpgradeOrbVoteOption2 = ((Component)val2).gameObject.AddComponent(typeof(PostBattleUpgradeOrbVoteOption)) as PostBattleUpgradeOrbVoteOption;
					postBattleUpgradeOrbVoteOption2.OrbIndex = num++;
					postBattleUpgradeOrbVoteOption2.voteStarter = parentVoteStarter;
					instance.AddVoteOption(postBattleUpgradeOrbVoteOption2);
				}
			}
			instance.VoteTimerText = Utils.CreateVoteTimerText(((Component)this).gameObject.transform.Find("Container"), new Vector3(15f, 228f, 0f));
			Component component = ((Component)((Component)this).transform.Find("Container/UpgradePanel/Image/BallInventoryView/CloseButton")).GetComponent(typeof(Button));
			((Behaviour)((component is MonoBehaviour) ? component : null)).enabled = false;
			instance.ChangeOddity();
			instance.StartVote();
			return true;
		}
	}
	public class PostBattleRelic : VoteStarter
	{
		public enum RelicTypeId
		{
			NONE,
			CHEST,
			ELITE,
			BOSS
		}

		public RelicTypeId RelicType { get; set; }

		protected override bool StartVote()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if (!Singleton<TwitchManager>.Instance.EnsureConnected())
			{
				return false;
			}
			Transform val = ((Component)this).transform.Find("Container/UpgradePanel/Image/RelicContainer");
			Transform val2 = val.Find("RelicContainer");
			VoteManager instance = Singleton<VoteManager>.Instance;
			instance.CleanVote();
			int num = 0;
			foreach (Transform item in val2)
			{
				Transform val3 = item;
				if (((Component)val3).gameObject.activeInHierarchy)
				{
					PostBattleRelicVoteOption postBattleRelicVoteOption = ((Component)val3).gameObject.AddComponent(typeof(PostBattleRelicVoteOption)) as PostBattleRelicVoteOption;
					postBattleRelicVoteOption.RelicIndex = num++;
					instance.AddVoteOption(postBattleRelicVoteOption);
				}
			}
			SettingBoolean settingBoolean;
			switch (RelicType)
			{
			default:
				Debug.Log((object)"Vote for chest relic");
				settingBoolean = PTSSettingsManager.AllowSkipChest;
				break;
			case RelicTypeId.ELITE:
				Debug.Log((object)"Vote for elite relic");
				settingBoolean = PTSSettingsManager.AllowSkipElite;
				break;
			case RelicTypeId.BOSS:
				Debug.Log((object)"Vote for boss relic");
				settingBoolean = PTSSettingsManager.AllowSkipBoss;
				break;
			}
			if ((bool)settingBoolean)
			{
				PostBattleSkipRelicVoteOption option = ((Component)val.Find("SkipButton")).gameObject.AddComponent(typeof(PostBattleSkipRelicVoteOption)) as PostBattleSkipRelicVoteOption;
				instance.AddVoteOption(option);
			}
			instance.VoteTimerText = Utils.CreateVoteTimerText(((Component)this).transform.Find("Container"), new Vector3(15f, 228f, 0f));
			instance.StartVote();
			return true;
		}
	}
	public class PostBattleUpgrades : VoteStarter
	{
		private int votesStarted = 0;

		private float _start_time = 0f;

		public bool didHeal = false;

		public bool didToad = false;

		public DeckManager deckManager;

		public float TimeOut
		{
			set
			{
				_start_time = Time.realtimeSinceStartup + value;
			}
		}

		public static bool CanAffordNewOrb(GameObject orb)
		{
			Transform obj = orb.transform.Find("Gold Container");
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj3 = obj.Find("Gold Text");
				obj2 = ((obj3 != null) ? ((Component)obj3).GetComponent(typeof(TextMeshProUGUI)) : null);
			}
			TextMeshProUGUI val = (TextMeshProUGUI)((obj2 is TextMeshProUGUI) ? obj2 : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			int num = int.Parse(((TMP_Text)val).text);
			return CurrencyManager.Instance.CanAfford(num);
		}

		public static bool CanAffordHeal(GameObject healButton)
		{
			Transform obj = healButton.transform.Find("Gold Container (1)");
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj3 = obj.Find("Gold Text");
				obj2 = ((obj3 != null) ? ((Component)obj3).GetComponent(typeof(TextMeshProUGUI)) : null);
			}
			TextMeshProUGUI val = (TextMeshProUGUI)((obj2 is TextMeshProUGUI) ? obj2 : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			int num = int.Parse(((TMP_Text)val).text);
			return CurrencyManager.Instance.CanAfford(num);
		}

		public static bool CanAffordUpgrade(GameObject upgradeButton)
		{
			return CanAffordNewOrb(upgradeButton);
		}

		protected override bool StartVote()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			if (votesStarted >= (int)PTSSettingsManager.MaxPostbattleVotes)
			{
				return true;
			}
			if (Time.realtimeSinceStartup < _start_time)
			{
				return false;
			}
			if (!Singleton<TwitchManager>.Instance.EnsureConnected())
			{
				return false;
			}
			Debug.Log((object)"Vote for postbattle upgrades");
			Transform val = ((Component)this).transform.Find("Container/UpgradePanel/Image/OptionsContainer");
			Transform val2 = val.Find("SuggestionOrbRow");
			VoteManager instance = Singleton<VoteManager>.Instance;
			instance.CleanVote();
			int num = 0;
			foreach (Transform item in val2)
			{
				Transform val3 = item;
				if (((Component)val3).gameObject.activeSelf && CanAffordNewOrb(((Component)val3).gameObject))
				{
					PostBattleNewOrbVoteOption postBattleNewOrbVoteOption = ((Component)val3).gameObject.AddComponent(typeof(PostBattleNewOrbVoteOption)) as PostBattleNewOrbVoteOption;
					postBattleNewOrbVoteOption.OrbIndex = num++;
					postBattleNewOrbVoteOption.voteStarter = this;
					instance.AddVoteOption(postBattleNewOrbVoteOption);
				}
			}
			if (deckManager.GetUpgradeableOrbs().Count > 0 && (bool)PTSSettingsManager.AllowPostbattleUpgrades)
			{
				GameObject gameObject = ((Component)val.Find("ButtonLayout/HealUpgradeContainer/UpgradeButton")).gameObject;
				if ((Object)(object)gameObject != (Object)null && gameObject.activeInHierarchy && CanAffordUpgrade(gameObject))
				{
					PostBattleUpgradeVoteOption postBattleUpgradeVoteOption = gameObject.gameObject.AddComponent(typeof(PostBattleUpgradeVoteOption)) as PostBattleUpgradeVoteOption;
					instance.AddVoteOption(postBattleUpgradeVoteOption);
					postBattleUpgradeVoteOption.voteStarter = this;
					postBattleUpgradeVoteOption.deckManager = deckManager;
				}
			}
			if (!didHeal && (bool)PTSSettingsManager.AllowPostbattleHeal)
			{
				GameObject gameObject2 = ((Component)val.Find("ButtonLayout/HealUpgradeContainer/HealButton")).gameObject;
				if ((Object)(object)gameObject2 != (Object)null && gameObject2.activeInHierarchy && CanAffordHeal(gameObject2))
				{
					PostBattleHealVoteOption postBattleHealVoteOption = gameObject2.gameObject.AddComponent(typeof(PostBattleHealVoteOption)) as PostBattleHealVoteOption;
					instance.AddVoteOption(postBattleHealVoteOption);
					postBattleHealVoteOption.voteStarter = this;
				}
			}
			if (!didToad && (bool)PTSSettingsManager.AllowPostbattleToad)
			{
				GameObject gameObject3 = ((Component)val.Find("ButtonLayout/ToademContainer/ToademMaxHPButton")).gameObject;
				if ((Object)(object)gameObject3 != (Object)null && gameObject3.activeInHierarchy && CanAffordHeal(gameObject3))
				{
					PostBattleToadMaxHPVoteOption postBattleToadMaxHPVoteOption = gameObject3.gameObject.AddComponent(typeof(PostBattleToadMaxHPVoteOption)) as PostBattleToadMaxHPVoteOption;
					instance.AddVoteOption(postBattleToadMaxHPVoteOption);
					postBattleToadMaxHPVoteOption.voteStarter = this;
				}
			}
			GameObject gameObject4 = ((Component)val.Find("ContinueButton")).gameObject;
			PostBattleSkipUpgradeVoteOption option = gameObject4.gameObject.AddComponent(typeof(PostBattleSkipUpgradeVoteOption)) as PostBattleSkipUpgradeVoteOption;
			instance.AddVoteOption(option);
			instance.VoteTimerText = Utils.CreateVoteTimerText(((Component)this).gameObject.transform.Find("Container"), new Vector3(15f, 228f, 0f));
			if (votesStarted > 0)
			{
				instance.ChangeOddity();
			}
			instance.StartVote();
			votesStarted++;
			return true;
		}
	}
	public class StartingRelic : VoteStarter
	{
		protected override bool StartVote()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if (!Singleton<TwitchManager>.Instance.EnsureConnected())
			{
				return false;
			}
			Debug.Log((object)"Vote for starting relic");
			Transform val = GameObject.Find("Camera").transform.Find("Canvas");
			Transform val2 = val.Find("HorizontalContainer");
			VoteManager instance = Singleton<VoteManager>.Instance;
			instance.CleanVote();
			int num = 0;
			foreach (Transform item in val2)
			{
				Transform val3 = item;
				if (((Component)val3).gameObject.activeInHierarchy)
				{
					StartingRelicVoteOption startingRelicVoteOption = ((Component)val3).gameObject.AddComponent(typeof(StartingRelicVoteOption)) as StartingRelicVoteOption;
					startingRelicVoteOption.RelicIndex = num++;
					instance.AddVoteOption(startingRelicVoteOption);
				}
			}
			if ((bool)PTSSettingsManager.AllowSkipStarting)
			{
				SkipStartingVoteOption option = ((Component)val.Find("SkipButton")).gameObject.AddComponent(typeof(SkipStartingVoteOption)) as SkipStartingVoteOption;
				instance.AddVoteOption(option);
			}
			instance.VoteTimerText = Utils.CreateVoteTimerText(val, new Vector3(15f, 120f, 0f));
			instance.StartVote();
			return true;
		}
	}
	public abstract class VoteStarter : MonoBehaviour
	{
		private bool _shouldStartVote = true;

		private int framesPassed = 0;

		public bool ShouldStartVote
		{
			get
			{
				return _shouldStartVote;
			}
			set
			{
				_shouldStartVote = value;
			}
		}

		private void LateUpdate()
		{
			if (ShouldStartVote && framesPassed > 0 && StartVote())
			{
				ShouldStartVote = false;
			}
			framesPassed++;
		}

		private void OnDisable()
		{
			Singleton<VoteManager>.Instance.InterruptVote();
		}

		protected abstract bool StartVote();
	}
}
namespace PegTheStreamer.Behaviours.VoteOptions
{
	public class PostBattleHealVoteOption : BattleUpgradeVoteOption
	{
		public override void Choose()
		{
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.EnsurePostBattleUpgradesMainWindowOpen();
			Utils.PressButton(((Component)this).gameObject);
			NextVote();
			voteStarter.didHeal = true;
		}

		public override int GetByTypeNamingPriority()
		{
			return 3;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "Heal";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle heal", new Vector3(100f, -10f, 0f));
		}
	}
	public class PostBattleNewOrbVoteOption : BattleUpgradeVoteOption
	{
		public int OrbIndex { get; set; }

		public override void Choose()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.EnsurePostBattleUpgradesMainWindowOpen();
			Utils.PressButton(((Component)this).gameObject);
			Transform val = GameObject.Find("BattleUpgradesCanvas").transform.Find("Container/UpgradeConfirmationPanel OrbPreview/Options And Navigation/ButtonContainer");
			foreach (Transform item in val)
			{
				Transform val2 = item;
				if ((Object)(object)val2.Find("UpgradeButton") != (Object)null)
				{
					Component component = ((Component)val2.Find("UpgradeButton")).GetComponent(typeof(Button));
					((MonoBehaviour)((component is Button) ? component : null)).Invoke("Press", 0f);
				}
			}
			NextVote();
		}

		public override int GetByTypeNamingPriority()
		{
			return 1;
		}

		public override int GetInTypeNamingPriority()
		{
			return OrbIndex;
		}

		public override string GetOptionTextForChat()
		{
			Component component = ((Component)this).gameObject.GetComponent(typeof(UpgradeOption));
			return ((UpgradeOption)((component is UpgradeOption) ? component : null)).attack.Name;
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle new orb", new Vector3(51f, -57f, 0f));
		}
	}
	internal class PostBattleRelicVoteOption : VoteOption
	{
		public int RelicIndex { get; set; }

		public override void Choose()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.PressButton(((Component)this).gameObject);
			Transform val = GameObject.Find("BattleUpgradesCanvas").transform.Find("Container/UpgradeConfirmationPanel Relic/Options And Navigation/ButtonContainer");
			foreach (Transform item in val)
			{
				Transform val2 = item;
				if ((Object)(object)val2.Find("UpgradeButton") != (Object)null)
				{
					Component component = ((Component)val2.Find("UpgradeButton")).GetComponent(typeof(Button));
					((MonoBehaviour)((component is Button) ? component : null)).Invoke("Press", 0f);
				}
			}
		}

		public override int GetByTypeNamingPriority()
		{
			return 1;
		}

		public override int GetInTypeNamingPriority()
		{
			return RelicIndex;
		}

		public override string GetOptionTextForChat()
		{
			Component component = ((Component)((Component)this).transform.Find("Image")).GetComponent(typeof(RelicIcon));
			return ((RelicIcon)((component is RelicIcon) ? component : null)).relic.englishDisplayName;
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "chest relic", new Vector3(44f, -93f, 0f));
		}
	}
	internal class PostBattleSkipRelicVoteOption : VoteOption
	{
		public override void Choose()
		{
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.PressButton(((Component)this).gameObject);
		}

		public override int GetByTypeNamingPriority()
		{
			return 0;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "Skip";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "skip relic", new Vector3(45f, 22f, 0f));
		}
	}
	public class PostBattleSkipUpgradeVoteOption : VoteOption
	{
		public override void Choose()
		{
		}

		public override int GetByTypeNamingPriority()
		{
			return 0;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "Skip";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle skip", new Vector3(170f, -8f, 0f));
		}
	}
	public class PostBattleToadMaxHPVoteOption : BattleUpgradeVoteOption
	{
		public override void Choose()
		{
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.EnsurePostBattleUpgradesMainWindowOpen();
			Utils.PressButton(((Component)this).gameObject);
			NextVote();
			voteStarter.didToad = true;
		}

		public override int GetByTypeNamingPriority()
		{
			return 4;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "+Max HP";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle toad max hp", new Vector3(313f, -45f, 0f));
			((TMP_Text)_voteCountText).fontSize = 28f;
		}
	}
	public class PostBattleUpgradeOrbVoteOption : BattleUpgradeVoteOption
	{
		public int OrbIndex { get; set; }

		public override void Choose()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.PressButton(((Component)this).gameObject);
			Transform val = GameObject.Find("BattleUpgradesCanvas").transform.Find("Container/UpgradeConfirmationPanel OrbUpgrade/Options And Navigation/ButtonContainer");
			foreach (Transform item in val)
			{
				Transform val2 = item;
				if ((Object)(object)val2.Find("UpgradeButton") != (Object)null)
				{
					Component component = ((Component)val2.Find("UpgradeButton")).GetComponent(typeof(Button));
					((MonoBehaviour)((component is Button) ? component : null)).Invoke("Press", 0f);
				}
			}
			NextVote();
		}

		public override int GetByTypeNamingPriority()
		{
			return 0;
		}

		public override int GetInTypeNamingPriority()
		{
			return OrbIndex;
		}

		public override string GetOptionTextForChat()
		{
			Component component = ((Component)this).gameObject.GetComponent(typeof(UpgradeOption));
			return ((UpgradeOption)((component is UpgradeOption) ? component : null)).attack.Name;
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle upgrade orb", new Vector3(51f, -57f, 0f));
		}
	}
	internal class PostBattleUpgradeVoteOption : VoteOption
	{
		public PostBattleUpgrades voteStarter;

		public DeckManager deckManager;

		public override void Choose()
		{
			Utils.EnsureGameUnpaused();
			Utils.EnsureInventoryClosed();
			Utils.PressButton(((Component)this).gameObject);
			PostBattleOrbUpgrade postBattleOrbUpgrade = GameObject.Find("BattleUpgradesCanvas").AddComponent(typeof(PostBattleOrbUpgrade)) as PostBattleOrbUpgrade;
			postBattleOrbUpgrade.parentVoteStarter = voteStarter;
			postBattleOrbUpgrade.deckManager = deckManager;
		}

		public override int GetByTypeNamingPriority()
		{
			return 2;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "Upgrade orb";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "postbattle heal", new Vector3(65f, -57f, 0f));
		}
	}
	internal class SkipStartingVoteOption : VoteOption
	{
		public override void Choose()
		{
			Component component = GameObject.Find("GameInit").GetComponent(typeof(GameInit));
			GameInit val = (GameInit)(object)((component is GameInit) ? component : null);
			val.SkipRelic();
		}

		public override int GetByTypeNamingPriority()
		{
			return 0;
		}

		public override int GetInTypeNamingPriority()
		{
			return 0;
		}

		public override string GetOptionTextForChat()
		{
			return "Skip";
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "skip relic", new Vector3(45f, 22f, 0f));
		}
	}
	internal class StartingRelicVoteOption : VoteOption
	{
		public int RelicIndex { get; set; }

		public override void Choose()
		{
			Component component = GameObject.Find("GameInit").GetComponent(typeof(GameInit));
			GameInit val = (GameInit)(object)((component is GameInit) ? component : null);
			val.ChooseRelic(RelicIndex);
			val.AddRelic();
		}

		public override int GetByTypeNamingPriority()
		{
			return 1;
		}

		public override int GetInTypeNamingPriority()
		{
			return RelicIndex;
		}

		public override string GetOptionTextForChat()
		{
			Component component = ((Component)((Component)this).transform.Find("Image")).GetComponent(typeof(RelicIcon));
			return ((RelicIcon)((component is RelicIcon) ? component : null)).relic.englishDisplayName;
		}

		protected override void SetupCountText()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_voteCountText = Utils.CreateText(((Component)this).gameObject.transform, "starting relic", new Vector3(44f, -93f, 0f));
		}
	}
	public abstract class VoteOption : MonoBehaviour, IComparable<VoteOption>
	{
		protected TextMeshProUGUI _voteCountText;

		public int Votes { get; set; }

		public void Awake()
		{
			SetupCountText();
			HideCountText();
		}

		public void SetCountText(string str)
		{
			((TMP_Text)_voteCountText).text = str;
		}

		public abstract void Choose();

		public abstract string GetOptionTextForChat();

		public void ShowCountText()
		{
			if (Object.op_Implicit((Object)(object)_voteCountText))
			{
				((Behaviour)_voteCountText).enabled = true;
			}
		}

		public void HideCountText()
		{
			if (Object.op_Implicit((Object)(object)_voteCountText))
			{
				((Behaviour)_voteCountText).enabled = false;
			}
		}

		protected abstract void SetupCountText();

		public abstract int GetByTypeNamingPriority();

		public abstract int GetInTypeNamingPriority();

		public int CompareTo(VoteOption other)
		{
			if (GetByTypeNamingPriority() < other.GetByTypeNamingPriority())
			{
				return -1;
			}
			if (GetByTypeNamingPriority() > other.GetByTypeNamingPriority())
			{
				return 1;
			}
			return GetInTypeNamingPriority().CompareTo(other.GetInTypeNamingPriority());
		}
	}
	public abstract class BattleUpgradeVoteOption : VoteOption
	{
		public PostBattleUpgrades voteStarter;

		protected void NextVote()
		{
			voteStarter.TimeOut = 2f;
			voteStarter.ShouldStartVote = true;
		}
	}
}
namespace PegTheStreamer.Behaviours.Settings
{
	public abstract class SettingBase
	{
		public abstract void LoadValue();

		public abstract void SaveValue();

		public abstract void RevertValue();

		public abstract void InitializePreviousValue();

		public abstract void AddApplyAction();

		public abstract void RemoveApplyAction();

		public abstract void ShowValue();

		public abstract void CreateUI();
	}
	public abstract class Setting<T> : SettingBase
	{
		protected T _lastValue;

		protected T _defaultValue;

		protected string _playerPrefsKey;

		protected string _description;

		protected Color _backgroundColor;

		public T Value { get; set; }

		public static implicit operator T(Setting<T> obj)
		{
			return obj.Value;
		}

		protected Setting(string prefsKey, string description, T defaultValue, Color color)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			_playerPrefsKey = prefsKey;
			_description = description;
			_defaultValue = defaultValue;
			_backgroundColor = color;
		}

		public override void RevertValue()
		{
			Value = _lastValue;
		}

		public override void InitializePreviousValue()
		{
			_lastValue = Value;
		}

		protected virtual void ApplyAction(T value)
		{
			Value = value;
		}
	}
	public class SettingBoolean : Setting<bool>
	{
		private CarouselOptionsBoolean UIOption;

		public SettingBoolean(string prefsKey, string description, bool defaultValue, Color color)
			: base(prefsKey, description, defaultValue, color)
		{
		}//IL_0004: Unknown result type (might be due to invalid IL or missing references)


		public override void LoadValue()
		{
			base.Value = PlayerPrefs.GetInt(_playerPrefsKey, _defaultValue ? 1 : 0) == 1;
		}

		public override void SaveValue()
		{
			PlayerPrefs.SetInt(_playerPrefsKey, base.Value ? 1 : 0);
		}

		public override void AddApplyAction()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			UIOption.changeSettingAction = (BooleanAction)Delegate.Combine((Delegate?)(object)UIOption.changeSettingAction, (Delegate?)new BooleanAction(ApplyAction));
		}

		public override void RemoveApplyAction()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			UIOption.changeSettingAction = (BooleanAction)Delegate.Remove((Delegate?)(object)UIOption.changeSettingAction, (Delegate?)new BooleanAction(ApplyAction));
		}

		public override void ShowValue()
		{
			UIOption.ShowOption(base.Value);
		}

		public override void CreateUI()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			UIOption = Utils.CreateBinaryOption(_description, _backgroundColor);
		}
	}
	public class SettingInt : Setting<int>
	{
		private int[] _values;

		private CarouselOptionsInt UIOption;

		public SettingInt(string prefsKey, string description, int defaultValue, int[] values, Color color)
			: base(prefsKey, description, defaultValue, color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			_values = values;
		}

		public override void LoadValue()
		{
			base.Value = PlayerPrefs.GetInt(_playerPrefsKey, _defaultValue);
		}

		public override void SaveValue()
		{
			PlayerPrefs.SetInt(_playerPrefsKey, base.Value);
		}

		protected override void ApplyAction(int value)
		{
			base.Value = _values[value];
		}

		public override void AddApplyAction()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			UIOption.changeSettingAction = (IntAction)Delegate.Combine((Delegate?)(object)UIOption.changeSettingAction, (Delegate?)new IntAction(ApplyAction));
		}

		public override void RemoveApplyAction()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			UIOption.changeSettingAction = (IntAction)Delegate.Remove((Delegate?)(object)UIOption.changeSettingAction, (Delegate?)new IntAction(ApplyAction));
		}

		public override void ShowValue()
		{
			UIOption.ShowOption(Array.FindIndex(_values, (int val) => val == base.Value));
		}

		public override void CreateUI()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			string[] array = new string[_values.Length];
			for (int i = 0; i < _values.Length; i++)
			{
				array[i] = _values[i].ToString();
			}
			UIOption = Utils.CreateIntOption(_description, _backgroundColor, array);
		}
	}
	public class SettingString : Setting<string>
	{
		private string _placeholderText;

		private Color _textColor;

		public TMP_InputField UIText;

		public SettingString(string prefsKey, string description, string defaultValue, string placeholder, Color color, Color textColor)
			: base(prefsKey, description, defaultValue, color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			_placeholderText = placeholder;
			_textColor = textColor;
		}

		public override void LoadValue()
		{
			base.Value = PlayerPrefs.GetString(_playerPrefsKey, _defaultValue);
		}

		public override void SaveValue()
		{
			PlayerPrefs.SetString(_playerPrefsKey, base.Value);
		}

		public override void AddApplyAction()
		{
			((UnityEvent<string>)(object)UIText.onDeselect).AddListener((UnityAction<string>)ApplyAction);
			((UnityEvent<string>)(object)UIText.onSubmit).AddListener((UnityAction<string>)ApplyAction);
		}

		public override void RemoveApplyAction()
		{
			((UnityEvent<string>)(object)UIText.onDeselect).RemoveListener((UnityAction<string>)ApplyAction);
			((UnityEvent<string>)(object)UIText.onSubmit).RemoveListener((UnityAction<string>)ApplyAction);
		}

		public override void ShowValue()
		{
			UIText.text = base.Value;
		}

		public override void CreateUI()
		{
			//IL_000f: 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)
			UIText = Utils.CreateInputFieldOption(_description, _placeholderText, _backgroundColor, _textColor);
		}
	}
}