Decompiled source of UKSR v1.0.21

BepInEx\plugins\UKSRR\UKSRR.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UKSRR.Game;
using UKSRR.Integrity;
using UKSRR.Match;
using UKSRR.Network;
using UKSRR.Timing;
using UKSRR.UI;
using UnityEngine;
using UnityEngine.Events;
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("pink404")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UKSRR")]
[assembly: AssemblyTitle("UKSRR")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UKSRR
{
	[BepInPlugin("com.uksrr.client", "UKSR Ranked", "1.0.21")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.uksrr.client";

		public const string Name = "UKSR Ranked";

		public const string Version = "1.0.21";

		private Harmony _harmony;

		internal static Plugin Instance { get; private set; }

		internal MatchManager Matches { get; private set; }

		internal RankedNotificationManager Notifications { get; private set; }

		internal SteamRankedBridge Network { get; private set; }

		private void Awake()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			RankedSettings.Initialize(((BaseUnityPlugin)this).Config);
			ThumbnailCatalog.Initialize(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), ((BaseUnityPlugin)this).Logger);
			Matches = new MatchManager(((BaseUnityPlugin)this).Logger);
			RankedFinalRankHook.Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			Notifications = ((Component)this).gameObject.AddComponent<RankedNotificationManager>();
			Notifications.Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			Matches.InitializeNotifications(Notifications);
			Network = ((Component)this).gameObject.AddComponent<SteamRankedBridge>();
			Network.Initialize(Matches, Notifications, ((BaseUnityPlugin)this).Logger);
			_harmony = new Harmony("com.uksrr.client");
			_harmony.PatchAll();
			((Component)this).gameObject.AddComponent<SceneWatcher>().Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			((Component)this).gameObject.AddComponent<GameplayProbe>().Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			((Component)this).gameObject.AddComponent<RankedResultWatcher>().Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			RankedSpectatorOverlay rankedSpectatorOverlay = ((Component)this).gameObject.AddComponent<RankedSpectatorOverlay>();
			MainMenuInjector mainMenuInjector = ((Component)this).gameObject.AddComponent<MainMenuInjector>();
			rankedSpectatorOverlay.Initialize(Matches, Network, ((BaseUnityPlugin)this).Logger, null);
			mainMenuInjector.Initialize(Matches, Network, rankedSpectatorOverlay, ((BaseUnityPlugin)this).Logger);
			((Component)this).gameObject.AddComponent<PauseMenuRewriter>().Initialize(Matches, ((BaseUnityPlugin)this).Logger);
			((Component)this).gameObject.AddComponent<RankedHud>().Initialize(Matches, Network, Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "icon.png"));
			IntegrityScanner.LogLoadedPlugins(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UKSR Ranked v1.0.21 loaded. authoritative vanilla-timer IGT, one-step hybrid joins, Steam friend invites, in-level spectating, responsive UI, and shared results.");
		}

		private void Update()
		{
			Matches.Tick();
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
}
namespace UKSRR.UI
{
	public sealed class MainMenuInjector : MonoBehaviour
	{
		private enum SelectionContext
		{
			None,
			PrivateLobby,
			PublicMatch
		}

		private MatchManager _matches;

		private SteamRankedBridge _network;

		private RankedSpectatorOverlay _spectator;

		private ManualLogSource _log;

		private GameObject _rankedButton;

		private RankedPanel _panel;

		private Button _styleTemplate;

		private Button _vanillaPlay;

		private VanillaMenuBridge _vanillaMenus;

		private float _nextScan;

		private int _scanAttemptsRemaining;

		private SelectionContext _selectionContext;

		private int _publicBrowserPage;

		private int _lastLobbyUiRevision = -1;

		private float _nextUiAutoRefresh;

		private bool _spectatorResultsActive;

		private bool _pendingLevelPRank;

		private string _browseLayer = "OVERTURE";

		public void Initialize(MatchManager matches, SteamRankedBridge network, RankedSpectatorOverlay spectator, ManualLogSource log)
		{
			_matches = matches;
			_network = network;
			_spectator = spectator;
			_log = log;
			_vanillaMenus = new VanillaMenuBridge((MonoBehaviour)(object)this, _matches, _log, GetVanillaPlay, OpenRankedHome, OnLevelSelected);
			_scanAttemptsRemaining = 120;
			SceneManager.activeSceneChanged += OnActiveSceneChanged;
			_log.LogInfo((object)"UKSR Ranked injector initialized. Exact 0.3.1 discovery + scene-aware reinjection.");
		}

		private void OnDestroy()
		{
			SceneManager.activeSceneChanged -= OnActiveSceneChanged;
			if (_vanillaMenus != null)
			{
				_vanillaMenus.RestoreDifficultyButtonsPublic();
				_vanillaMenus.RestoreLevelButtons();
			}
		}

		private void OnActiveSceneChanged(Scene previous, Scene next)
		{
			_rankedButton = null;
			_vanillaPlay = null;
			_scanAttemptsRemaining = 8;
			_nextScan = Time.unscaledTime + 0.35f;
		}

		private void Update()
		{
			if ((Object)(object)_network != (Object)null && Time.unscaledTime >= _nextUiAutoRefresh)
			{
				_nextUiAutoRefresh = Time.unscaledTime + 0.2f;
				if (_network.LobbyUiRevision != _lastLobbyUiRevision)
				{
					_lastLobbyUiRevision = _network.LobbyUiRevision;
					if (_panel != null && _network.InLobby)
					{
						OpenNetworkPrivateLobby();
					}
				}
			}
			if (_panel != null && !_panel.Alive)
			{
				_panel = null;
			}
			if ((Object)(object)_network != (Object)null && _network.AlternativeOfferPending && _network.IsSearching)
			{
				OpenAlternativeQueueOffer();
				return;
			}
			if (_matches.ReturnToLobbyOnMenuRequested)
			{
				Button val = FindButton("PLAY");
				if ((Object)(object)val != (Object)null)
				{
					_vanillaPlay = val;
					Button val2 = FindButton("OPTIONS");
					_styleTemplate = (((Object)(object)val2 != (Object)null) ? val2 : val);
					bool num = _matches.State == MatchState.Finished;
					_matches.ConsumeReturnToLobbyRequest();
					if (num)
					{
						OpenMatchResults();
					}
					else if ((Object)(object)_network != (Object)null && !string.IsNullOrEmpty(_network.LobbyId))
					{
						if (_network.CurrentLobbyIsPrivate)
						{
							OpenNetworkPrivateLobby();
						}
						else
						{
							OpenPublicQueue();
						}
					}
					else
					{
						OpenRankedHome();
					}
					return;
				}
			}
			if (!((Object)(object)_rankedButton != (Object)null) && _scanAttemptsRemaining > 0 && !(Time.unscaledTime < _nextScan))
			{
				_scanAttemptsRemaining--;
				_nextScan = Time.unscaledTime + ((_scanAttemptsRemaining > 8) ? 0.1f : 0.5f);
				TryInjectMainMenuButton();
			}
		}

		private void TryInjectMainMenuButton()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			Button val = FindButton("PLAY");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_vanillaPlay = val;
			if (!((Object)(object)GameObject.Find("UKSRR_RankedPlay") != (Object)null))
			{
				Button val2 = FindButton("OPTIONS");
				_styleTemplate = (((Object)(object)val2 != (Object)null) ? val2 : val);
				Button val3 = Object.Instantiate<Button>(_styleTemplate, ((Component)val).transform.parent);
				((Component)val3).gameObject.SetActive(false);
				((Object)((Component)val3).gameObject).name = "UKSRR_RankedPlay";
				((Component)val3).transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				PlaceUnderPlay(val, val3);
				UiText.Set(((Component)val3).gameObject, "RANKED PLAY");
				val3.onClick = new ButtonClickedEvent();
				((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
				{
					OpenRankedDifficultySelect();
				});
				((Component)val3).gameObject.SetActive(true);
				_rankedButton = ((Component)val3).gameObject;
				_log.LogInfo((object)"Injected RANKED PLAY under PLAY. Exact 0.3.1 discovery succeeded.");
			}
		}

		private Button GetVanillaPlay()
		{
			if ((Object)(object)_vanillaPlay != (Object)null && (Object)(object)((Component)_vanillaPlay).gameObject != (Object)null)
			{
				return _vanillaPlay;
			}
			_vanillaPlay = FindButton("PLAY");
			return _vanillaPlay;
		}

		private static Button FindButton(string text)
		{
			return ((IEnumerable<Button>)Resources.FindObjectsOfTypeAll<Button>()).FirstOrDefault((Func<Button, bool>)delegate(Button b)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)b != (Object)null)
				{
					Scene scene = ((Component)b).gameObject.scene;
					if (((Scene)(ref scene)).IsValid() && ((Component)b).gameObject.activeInHierarchy)
					{
						return string.Equals(UiText.Get(((Component)b).gameObject).Trim(), text, StringComparison.OrdinalIgnoreCase);
					}
				}
				return false;
			});
		}

		private static void PlaceUnderPlay(Button play, Button ranked)
		{
			//IL_003c: 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)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)play).transform.parent;
			if ((Object)(object)((Component)parent).GetComponent<VerticalLayoutGroup>() != (Object)null || (Object)(object)((Component)parent).GetComponent<GridLayoutGroup>() != (Object)null)
			{
				return;
			}
			RectTransform component = ((Component)play).GetComponent<RectTransform>();
			RectTransform component2 = ((Component)ranked).GetComponent<RectTransform>();
			Rect rect = component.rect;
			float num = Mathf.Max(55f, Mathf.Abs(((Rect)(ref rect)).height) + 8f);
			component2.anchoredPosition = component.anchoredPosition + Vector2.down * num;
			foreach (Transform item in parent)
			{
				Transform val = item;
				if (!((Object)(object)val == (Object)(object)((Component)play).transform) && !((Object)(object)val == (Object)(object)((Component)ranked).transform))
				{
					RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
					if (!((Object)(object)val2 == (Object)null) && val2.anchoredPosition.y < component.anchoredPosition.y)
					{
						val2.anchoredPosition += Vector2.down * num;
					}
				}
			}
		}

		public void OpenRankedHome()
		{
			ClosePanel();
			Button vanillaPlay = GetVanillaPlay();
			if ((Object)(object)vanillaPlay == (Object)null)
			{
				_log.LogWarning((object)"UKSRR cannot open ranked menu because vanilla PLAY is unavailable.");
				return;
			}
			Button val = FindButton("OPTIONS");
			_styleTemplate = (((Object)(object)val != (Object)null) ? val : vanillaPlay);
			if ((Object)(object)_network == (Object)null || !_network.SteamProfileReady)
			{
				OpenSteamConnectionError();
				return;
			}
			_matches.EnterLobby();
			_panel = new RankedPanel(_styleTemplate, "UKSR RANKED");
			_panel.AddButton("PUBLIC MATCH", OpenPublicMatch);
			_panel.AddButton("PRIVATE LOBBY", OpenPrivateLobby);
			_panel.AddButton("PROFILE", OpenProfile);
			_panel.AddButton("SETTINGS", OpenSettings);
			_panel.AddButton("DIFFICULTY: " + _matches.DifficultyName, OpenRankedDifficultySelect);
			_panel.AddButton("BACK", ClosePanel);
		}

		private void OpenSteamConnectionError()
		{
			ClosePanel();
			Button vanillaPlay = GetVanillaPlay();
			if ((Object)(object)vanillaPlay != (Object)null)
			{
				Button val = FindButton("OPTIONS");
				_styleTemplate = (((Object)(object)val != (Object)null) ? val : vanillaPlay);
			}
			_panel = new RankedPanel(_styleTemplate, "STEAM CONNECTION ERROR");
			_panel.AddLabel("UKSR COULD NOT FIND A VALID STEAM PROFILE.");
			_panel.AddLabel(((Object)(object)_network == (Object)null) ? "NETWORK BRIDGE UNAVAILABLE" : _network.SteamConnectionError);
			_panel.AddLabel("STEAM MUST BE RUNNING AND ULTRAKILL MUST BE CONNECTED TO YOUR STEAM PROFILE.");
			_panel.AddButton("RETRY STEAM CONNECTION", delegate
			{
				if ((Object)(object)_network != (Object)null && _network.RefreshSteamIdentity())
				{
					OpenRankedHome();
				}
				else
				{
					OpenSteamConnectionError();
				}
			});
			_panel.AddButton("BACK", ClosePanel);
		}

		private void OpenRankedDifficultySelect()
		{
			ClosePanel();
			Button vanillaPlay = GetVanillaPlay();
			if ((Object)(object)vanillaPlay != (Object)null)
			{
				Button val = FindButton("OPTIONS");
				_styleTemplate = (((Object)(object)val != (Object)null) ? val : vanillaPlay);
			}
			_panel = new RankedPanel(_styleTemplate, "SELECT DIFFICULTY");
			List<RankedPanel.GridItem> items = new List<RankedPanel.GridItem>();
			AddDifficultyItem(items, 0, "HARMLESS");
			AddDifficultyItem(items, 1, "LENIENT");
			AddDifficultyItem(items, 2, "STANDARD");
			AddDifficultyItem(items, 3, "VIOLENT");
			AddDifficultyItem(items, 4, "BRUTAL");
			_panel.AddGrid(items, 2, 480f, 60f);
			((Selectable)_panel.AddButton("ULTRAKILL MUST DIE // DISABLED", null)).interactable = false;
			_panel.AddButton("BACK", OpenRankedHome);
		}

		private void AddDifficultyItem(List<RankedPanel.GridItem> items, int value, string name)
		{
			string label = ((_matches.Difficulty == value) ? ("> " + name + " <") : name);
			items.Add(new RankedPanel.GridItem(label, delegate
			{
				_matches.SetDifficulty(value, name);
				OpenRankedHome();
			}));
		}

		private void OpenPublicMatch()
		{
			_selectionContext = SelectionContext.PublicMatch;
			_publicBrowserPage = 0;
			OpenPublicCategorySelect();
		}

		private void OpenPublicCategorySelect()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "PUBLIC MATCH // CATEGORY");
			List<RankedPanel.GridItem> list = new List<RankedPanel.GridItem>();
			list.Add(new RankedPanel.GridItem("FULL GAME ANY%", delegate
			{
				_matches.SetCategory(CategoryDefinition.FullGameAny());
				StartPublicSearch();
			}));
			list.Add(new RankedPanel.GridItem("FULL GAME P-RANK", delegate
			{
				_matches.SetCategory(CategoryDefinition.FullGamePRank());
				StartPublicSearch();
			}));
			list.Add(new RankedPanel.GridItem("ACT ANY%", delegate
			{
				OpenPublicActSelect(pRank: false);
			}));
			list.Add(new RankedPanel.GridItem("ACT P-RANK", delegate
			{
				OpenPublicActSelect(pRank: true);
			}));
			list.Add(new RankedPanel.GridItem("LAYER ANY%", delegate
			{
				OpenPublicLayerSelect(pRank: false);
			}));
			list.Add(new RankedPanel.GridItem("LAYER P-RANK", delegate
			{
				OpenPublicLayerSelect(pRank: true);
			}));
			list.Add(new RankedPanel.GridItem("LEVEL ANY%", delegate
			{
				OpenLevelSelectForContext(pRank: false, SelectionContext.PublicMatch);
			}));
			list.Add(new RankedPanel.GridItem("LEVEL P-RANK", delegate
			{
				OpenLevelSelectForContext(pRank: true, SelectionContext.PublicMatch);
			}));
			_panel.AddPagedGrid(list, _publicBrowserPage, 3, delegate(int nextPage)
			{
				_publicBrowserPage = nextPage;
				OpenPublicCategorySelect();
			});
			_panel.AddBottomLeftAction("BACK", OpenRankedHome, 0);
		}

		private void OpenPublicActSelect(bool pRank)
		{
			OpenActSelectForContext(pRank, SelectionContext.PublicMatch);
		}

		private void OpenPublicLayerSelect(bool pRank)
		{
			OpenLayerSelectForContext(pRank, SelectionContext.PublicMatch);
		}

		private void StartPublicSearch()
		{
			if ((Object)(object)_network != (Object)null)
			{
				string level = ((_matches.Category == null) ? "" : _matches.Category.Scope);
				_network.BeginRankedSearchFor(level, _matches.DifficultyName);
			}
			OpenPublicQueue();
		}

		private void OpenPublicQueue()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "PUBLIC MATCH // MATCHMAKING");
			_panel.AddLabel("CATEGORY: " + ((_matches.Category == null) ? "NOT SELECTED" : _matches.Category.DisplayName));
			_panel.AddLabel("DIFFICULTY: " + _matches.DifficultyName);
			_panel.AddLabel("ELO: " + RankedSettings.Rating + " // SOFT MATCH ONLY");
			_panel.AddLabel("STATUS: " + (((Object)(object)_network == (Object)null) ? "NETWORK UNAVAILABLE" : _network.Status));
			if ((Object)(object)_network != (Object)null && _network.AlternativeQueueAvailable)
			{
				_panel.AddLabel("OTHER QUEUE: " + _network.AlternativeQueueLabel);
				_panel.AddButton("JOIN OTHER QUEUE", delegate
				{
					_network.AcceptAlternativeQueue();
					OpenPublicQueue();
				});
			}
			if ((Object)(object)_network != (Object)null && !string.IsNullOrEmpty(_network.LobbyId))
			{
				_panel.AddLabel("MATCH ID: " + _network.LobbyId);
			}
			_panel.AddButton(((Object)(object)_network != (Object)null && _network.IsSearching) ? "CANCEL MATCHMAKING" : "SEARCH AGAIN", delegate
			{
				if ((Object)(object)_network != (Object)null)
				{
					if (_network.IsSearching)
					{
						_network.CancelRankedSearch();
					}
					else
					{
						StartPublicSearch();
					}
				}
				OpenPublicQueue();
			});
			_panel.AddButton("CHANGE CATEGORY", OpenPublicCategorySelect);
			_panel.AddButton("BACK", OpenRankedHome);
		}

		private void OpenAlternativeQueueOffer()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "MATCHMAKING OPTION");
			_panel.AddLabel("NO ONE IS QUEUEING YOUR EXACT CATEGORY.");
			_panel.AddLabel("SOMEONE IS QUEUEING:");
			_panel.AddLabel(((Object)(object)_network == (Object)null) ? "UNKNOWN" : _network.AlternativeQueueLabel);
			_panel.AddLabel("WANT TO RUN THAT INSTEAD?");
			_panel.AddButton("YES // JOIN THAT QUEUE", delegate
			{
				if ((Object)(object)_network != (Object)null)
				{
					_network.AcceptAlternativeQueue();
				}
				OpenPublicQueue();
			});
			_panel.AddButton("NO // KEEP SEARCHING", delegate
			{
				if ((Object)(object)_network != (Object)null)
				{
					_network.DismissAlternativeQueue();
				}
				OpenPublicQueue();
			});
		}

		private void OpenMatchResults()
		{
			ClosePanel();
			Button vanillaPlay = GetVanillaPlay();
			if ((Object)(object)vanillaPlay != (Object)null)
			{
				Button val = FindButton("OPTIONS");
				_styleTemplate = (((Object)(object)val != (Object)null) ? val : vanillaPlay);
			}
			if ((Object)(object)_styleTemplate == (Object)null)
			{
				_log.LogWarning((object)"UKSR cannot open results because no menu button template is available.");
				OpenRankedHome();
				return;
			}
			List<RankedStanding> list = (((Object)(object)_network == (Object)null) ? new List<RankedStanding>() : _network.GetStandings());
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				if (!list[i].Finished && !list[i].Forfeit)
				{
					num++;
				}
			}
			if ((Object)(object)_network != (Object)null)
			{
				for (int j = 0; j < _network.LivePeers.Count; j++)
				{
					RankedLivePeer rankedLivePeer = _network.LivePeers[j];
					if (rankedLivePeer == null || rankedLivePeer.State == "finished" || rankedLivePeer.State == "forfeit")
					{
						continue;
					}
					bool flag = false;
					for (int k = 0; k < list.Count; k++)
					{
						if (list[k].SteamId == rankedLivePeer.SteamId)
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						num++;
					}
				}
			}
			_spectatorResultsActive = _matches != null && _matches.State == MatchState.Finished && num > 0;
			_panel = new RankedPanel(_styleTemplate, _spectatorResultsActive ? "SPECTATING REMAINING RUNNERS" : "MATCH RESULTS");
			if (_spectatorResultsActive)
			{
				_panel.AddLabel("YOUR RUN IS LOCKED IN // WAITING FOR " + num + " PLAYER" + ((num == 1) ? "" : "S"));
				_panel.AddLabel(" ");
				for (int l = 0; l < list.Count; l++)
				{
					RankedStanding rankedStanding = list[l];
					if (rankedStanding.IsSelf)
					{
						_panel.AddLabel("YOU // FINISHED // " + RankedNotificationManager.FormatTime(rankedStanding.Igt));
						continue;
					}
					if (rankedStanding.Finished)
					{
						_panel.AddLabel(rankedStanding.Name + " // FINISHED // " + RankedNotificationManager.FormatTime(rankedStanding.Igt));
						continue;
					}
					if (rankedStanding.Forfeit)
					{
						_panel.AddLabel(rankedStanding.Name + " // DNF");
						continue;
					}
					RankedLivePeer rankedLivePeer2 = null;
					if ((Object)(object)_network != (Object)null)
					{
						for (int m = 0; m < _network.LivePeers.Count; m++)
						{
							if (_network.LivePeers[m].SteamId == rankedStanding.SteamId)
							{
								rankedLivePeer2 = _network.LivePeers[m];
								break;
							}
						}
					}
					string text = rankedStanding.Name + " // RUNNING";
					if (rankedLivePeer2 != null)
					{
						text = text + " // IGT " + RankedNotificationManager.FormatTime(rankedLivePeer2.Igt);
						if (!string.IsNullOrEmpty(rankedLivePeer2.Level))
						{
							text = text + " // " + rankedLivePeer2.Level;
						}
					}
					_panel.AddLabel(text);
				}
				_panel.AddLabel(" ");
				_panel.AddLabel("RUNNING PLAYERS // SPECTATE FROM THE RIGHT");
				int num2 = 0;
				if ((Object)(object)_network != (Object)null)
				{
					for (int n = 0; n < _network.LivePeers.Count; n++)
					{
						RankedLivePeer rankedLivePeer3 = _network.LivePeers[n];
						if (rankedLivePeer3 == null || rankedLivePeer3.State != "running")
						{
							continue;
						}
						string label = rankedLivePeer3.Name + " // " + (string.IsNullOrEmpty(rankedLivePeer3.Level) ? "RUNNING" : rankedLivePeer3.Level) + " // IGT " + RankedNotificationManager.FormatTime(rankedLivePeer3.Igt);
						string steamId = rankedLivePeer3.SteamId;
						_panel.AddRightColumnButton(label, delegate
						{
							if ((Object)(object)_spectator != (Object)null)
							{
								_spectator.SpectateSteamId(steamId);
							}
						}, num2);
						num2++;
					}
				}
				_panel.AddBottomLeftAction("REFRESH RESULTS", OpenMatchResults, 0);
				((MonoBehaviour)this).StartCoroutine(RefreshResultsVisualNextFrames());
				return;
			}
			RankedStanding rankedStanding2 = null;
			for (int num3 = 0; num3 < list.Count; num3++)
			{
				if (list[num3].Finished)
				{
					rankedStanding2 = list[num3];
					break;
				}
			}
			if (rankedStanding2 != null)
			{
				_panel.AddLabel("WINNER // " + rankedStanding2.Name);
				_panel.AddLabel("BEST IGT // " + RankedNotificationManager.FormatTime(rankedStanding2.Igt));
			}
			else
			{
				_panel.AddLabel("NO FINISHER");
			}
			_panel.AddLabel(" ");
			int num4 = 1;
			for (int num5 = 0; num5 < list.Count; num5++)
			{
				RankedStanding rankedStanding3 = list[num5];
				string text2;
				if (!rankedStanding3.Finished)
				{
					text2 = ((!rankedStanding3.Forfeit) ? ("... " + rankedStanding3.Name + " // UNRESOLVED") : ("DNF // " + rankedStanding3.Name));
				}
				else
				{
					text2 = num4 + ". " + rankedStanding3.Name + "   IGT " + RankedNotificationManager.FormatTime(rankedStanding3.Igt) + "   RTA " + RankedNotificationManager.FormatTime(rankedStanding3.Rta);
					num4++;
				}
				if (rankedStanding3.IsSelf)
				{
					text2 += " // YOU";
				}
				_panel.AddLabel(text2);
			}
			if (list.Count == 0)
			{
				_panel.AddLabel("NO RESULT DATA");
			}
			_panel.AddButton("REFRESH RESULTS", OpenMatchResults);
			_panel.AddButton("RETURN TO LOBBY", delegate
			{
				_spectatorResultsActive = false;
				if ((Object)(object)_network != (Object)null && !string.IsNullOrEmpty(_network.LobbyId))
				{
					if (_network.CurrentLobbyIsPrivate)
					{
						OpenNetworkPrivateLobby();
					}
					else
					{
						OpenPublicQueue();
					}
				}
				else
				{
					OpenRankedHome();
				}
			});
			((MonoBehaviour)this).StartCoroutine(RefreshResultsVisualNextFrames());
			_panel.ForceRefresh();
		}

		private IEnumerator RefreshResultsVisualNextFrames()
		{
			yield return null;
			if (_panel != null && _panel.Alive)
			{
				_panel.ForceRefresh();
			}
			yield return (object)new WaitForSecondsRealtime(0.08f);
			if (_panel != null && _panel.Alive)
			{
				_panel.ForceRefresh();
			}
		}

		private void OpenNetworkPrivateLobby()
		{
			ClosePanel();
			_selectionContext = SelectionContext.PrivateLobby;
			_panel = new RankedPanel(_styleTemplate, "PRIVATE LOBBY");
			_panel.AddLabel("PLAYER: " + (((Object)(object)_network == (Object)null) ? "UNAVAILABLE" : (_network.SteamProfileReady ? _network.SteamName : "STEAM NOT CONNECTED")));
			if ((Object)(object)_network == (Object)null || string.IsNullOrEmpty(_network.LobbyId))
			{
				_panel.AddButton("CREATE ROOM", delegate
				{
					if ((Object)(object)_network != (Object)null)
					{
						_network.CreateRoom();
					}
					OpenNetworkPrivateLobby();
				});
				_panel.AddButton("JOIN ROOM FROM CLIPBOARD", delegate
				{
					if ((Object)(object)_network != (Object)null)
					{
						_network.JoinRoomFromClipboard();
					}
					OpenNetworkPrivateLobby();
				});
				_panel.AddLabel("COPY A UKSR ROOM CODE, THEN PRESS JOIN ROOM.");
				_panel.AddLabel("STATUS: " + (((Object)(object)_network == (Object)null) ? "NETWORK UNAVAILABLE" : _network.Status));
				_panel.AddButton("BACK", OpenRankedHome);
				return;
			}
			_panel.AddLabel("ROOM CODE: " + _network.LobbyCode);
			_panel.AddButton("COPY ROOM CODE", delegate
			{
				GUIUtility.systemCopyBuffer = _network.LobbyCode;
				OpenNetworkPrivateLobby();
			});
			_panel.AddRightColumnLabel("PLAYERS // " + _network.LobbyPlayers.Count + "/8", 0);
			for (int num = 0; num < _network.LobbyPlayers.Count && num < 8; num++)
			{
				_panel.AddRightColumnLabel(num + 1 + ". " + _network.LobbyPlayers[num], num + 1);
			}
			if (_network.IsLobbyOwner)
			{
				_panel.AddButton("CHANGE CATEGORY / MAP", OpenPrivateCategorySelect);
			}
			else
			{
				_panel.AddLabel("CATEGORY / LEVEL CONTROLLED BY HOST");
			}
			_panel.AddLabel("CATEGORY: " + ((_matches.Category == null) ? "WAITING FOR HOST" : _matches.Category.DisplayName));
			if (_matches.Category != null && _matches.Category.IsLevelSpecific)
			{
				_panel.AddLabel("LEVEL: " + (string.IsNullOrEmpty(_matches.SelectedLevel) ? "NOT SELECTED" : _matches.SelectedLevel));
			}
			_panel.AddBottomRightButton(_network.IsReady ? "READY: YES" : "READY UP", delegate
			{
				_network.SetRoomReady();
				OpenNetworkPrivateLobby();
			}, 1);
			if (_network.IsLobbyOwner && _network.AllPlayersReady)
			{
				_panel.AddBottomRightButton("START GAME", delegate
				{
					StartPrivateRankedRun();
				}, 0);
			}
			else if (_network.IsLobbyOwner)
			{
				((Selectable)_panel.AddBottomRightButton("WAITING FOR READY", null, 0)).interactable = false;
			}
			_panel.AddBottomLeftAction("LEAVE ROOM", delegate
			{
				_network.LeaveRoom();
				OpenRankedHome();
			}, 0);
			_panel.ForceRefresh();
		}

		private void StartPrivateRankedRun()
		{
			if (!((Object)(object)_network == (Object)null))
			{
				_network.StartRoom();
				if (_matches.State != MatchState.WaitingForFirstInput)
				{
					OpenNetworkPrivateLobby();
				}
				else
				{
					ClosePanel();
				}
			}
		}

		private void OpenPrivateCategorySelect()
		{
			if ((Object)(object)_network != (Object)null && !_network.IsLobbyOwner)
			{
				OpenNetworkPrivateLobby();
				return;
			}
			_selectionContext = SelectionContext.PrivateLobby;
			OpenCategorySelect();
		}

		private void OpenNetworkProfile()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "UKSR // PROFILE");
			_panel.AddLabel("PLAYER: " + (((Object)(object)_network == (Object)null) ? "UNKNOWN" : _network.SteamName));
			_panel.AddLabel("UKSR CLIENT: " + (((Object)(object)_network == (Object)null) ? "UNKNOWN" : _network.ClientId));
			_panel.AddLabel("STEAM: " + (((Object)(object)_network == (Object)null) ? "UNAVAILABLE" : (_network.SteamProfileReady ? _network.SteamId : "NOT CONNECTED")));
			_panel.AddLabel("CATEGORY: " + ((_matches.Category == null) ? "NOT SELECTED" : _matches.Category.DisplayName));
			_panel.AddLabel("DIFFICULTY: " + _matches.DifficultyName);
			_panel.AddLabel("ELO: " + RankedSettings.Rating);
			_panel.AddLabel("RECORD: " + RankedSettings.Record);
			_panel.AddButton("BACK", OpenRankedHome);
		}

		private void OpenSettings()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "UKSR // SETTINGS");
			_panel.AddButton("TIMER: " + (RankedSettings.TimerEnabled ? "ON" : "OFF"), delegate
			{
				RankedSettings.TimerEnabled = !RankedSettings.TimerEnabled;
				OpenSettings();
			});
			_panel.AddLabel("TIMER POSITION");
			List<RankedPanel.GridItem> list = new List<RankedPanel.GridItem>();
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.TopLeft, "TOP LEFT"), delegate
			{
				SetTimerPosition(TimerPosition.TopLeft);
			}));
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.TopCenter, "TOP CENTER"), delegate
			{
				SetTimerPosition(TimerPosition.TopCenter);
			}));
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.TopRight, "TOP RIGHT"), delegate
			{
				SetTimerPosition(TimerPosition.TopRight);
			}));
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.BottomLeft, "BOTTOM LEFT"), delegate
			{
				SetTimerPosition(TimerPosition.BottomLeft);
			}));
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.BottomCenter, "BOTTOM CENTER"), delegate
			{
				SetTimerPosition(TimerPosition.BottomCenter);
			}));
			list.Add(new RankedPanel.GridItem(TimerPositionLabel(TimerPosition.BottomRight, "BOTTOM RIGHT"), delegate
			{
				SetTimerPosition(TimerPosition.BottomRight);
			}));
			_panel.AddGrid(list, 3, 300f, 56f);
			_panel.AddLabel("TIMER PREVIEW");
			_panel.AddLabel(RankedSettings.TimerEnabled ? TimerPreviewText() : "[ TIMER DISABLED ]");
			_panel.AddButton("PROGRESS NOTIFICATIONS: " + (RankedSettings.ProgressNotifications ? "ON" : "OFF"), delegate
			{
				RankedSettings.ProgressNotifications = !RankedSettings.ProgressNotifications;
				OpenSettings();
			});
			_panel.AddButton("BACK", OpenRankedHome);
		}

		private void SetTimerPosition(TimerPosition position)
		{
			RankedSettings.TimerPosition = position;
			OpenSettings();
		}

		private static string TimerPositionLabel(TimerPosition position, string label)
		{
			if (RankedSettings.TimerPosition != position)
			{
				return label;
			}
			return "> " + label + " <";
		}

		private static string TimerPreviewText()
		{
			return "[" + RankedSettings.TimerPosition.ToString().ToUpperInvariant() + "]  RTA 00:01:23.456   IGT 00:01:19.882";
		}

		private void OpenCategorySelect()
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, (_selectionContext == SelectionContext.PrivateLobby) ? "PRIVATE LOBBY // CATEGORY" : "SELECT CATEGORY");
			List<RankedPanel.GridItem> list = new List<RankedPanel.GridItem>();
			list.Add(new RankedPanel.GridItem("FULL GAME ANY%", delegate
			{
				PickForContext(CategoryDefinition.FullGameAny());
			}));
			list.Add(new RankedPanel.GridItem("FULL GAME P-RANK", delegate
			{
				PickForContext(CategoryDefinition.FullGamePRank());
			}));
			list.Add(new RankedPanel.GridItem("ACT ANY%", delegate
			{
				OpenActSelectForContext(pRank: false, _selectionContext);
			}));
			list.Add(new RankedPanel.GridItem("ACT P-RANK", delegate
			{
				OpenActSelectForContext(pRank: true, _selectionContext);
			}));
			list.Add(new RankedPanel.GridItem("LAYER ANY%", delegate
			{
				OpenLayerSelectForContext(pRank: false, _selectionContext);
			}));
			list.Add(new RankedPanel.GridItem("LAYER P-RANK", delegate
			{
				OpenLayerSelectForContext(pRank: true, _selectionContext);
			}));
			list.Add(new RankedPanel.GridItem("LEVEL ANY%", delegate
			{
				_matches.SetCategory(CategoryDefinition.IndividualAny(""));
				_matches.SetSelectedLevel("");
				if (_selectionContext == SelectionContext.PrivateLobby)
				{
					OpenLevelSelectForContext(pRank: false, SelectionContext.PrivateLobby);
				}
				else
				{
					ReturnAfterCategoryChoice();
				}
			}));
			list.Add(new RankedPanel.GridItem("LEVEL P-RANK", delegate
			{
				_matches.SetCategory(CategoryDefinition.IndividualPRank(""));
				_matches.SetSelectedLevel("");
				if (_selectionContext == SelectionContext.PrivateLobby)
				{
					OpenLevelSelectForContext(pRank: true, SelectionContext.PrivateLobby);
				}
				else
				{
					ReturnAfterCategoryChoice();
				}
			}));
			_panel.AddGrid(list, 2, 480f, 60f);
			_panel.AddButton("BACK", (_selectionContext == SelectionContext.PrivateLobby) ? new Action(OpenNetworkPrivateLobby) : new Action(OpenRankedHome));
		}

		private void OpenActSelectForContext(bool pRank, SelectionContext context)
		{
			_selectionContext = context;
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, pRank ? "SELECT ACT // P-RANK" : "SELECT ACT // ANY%");
			string[] obj = new string[4] { "PRELUDE", "ACT I", "ACT II", "ACT III" };
			List<RankedPanel.GridItem> list = new List<RankedPanel.GridItem>();
			string[] array = obj;
			foreach (string text in array)
			{
				string captured = text;
				list.Add(new RankedPanel.GridItem(captured, delegate
				{
					CategoryDefinition category = (pRank ? CategoryDefinition.ActPRank(captured) : CategoryDefinition.ActAny(captured));
					_matches.SetCategory(category);
					if (_selectionContext == SelectionContext.PublicMatch)
					{
						StartPublicSearch();
					}
					else
					{
						OpenNetworkPrivateLobby();
					}
				}));
			}
			_panel.AddGrid(list, 2, 480f, 60f);
			_panel.AddButton("BACK", (_selectionContext == SelectionContext.PublicMatch) ? new Action(OpenPublicCategorySelect) : new Action(OpenCategorySelect));
		}

		private void OpenLayerSelectForContext(bool pRank, SelectionContext context)
		{
			_selectionContext = context;
			ClosePanel();
			if (string.IsNullOrEmpty(_browseLayer))
			{
				_browseLayer = "OVERTURE";
			}
			_panel = new RankedPanel(_styleTemplate, pRank ? "SELECT LAYER // P-RANK" : "SELECT LAYER // ANY%");
			List<RankedPanel.BrowserItem> list = new List<RankedPanel.BrowserItem>();
			LevelCatalog.LayerInfo[] layers = LevelCatalog.Layers;
			foreach (LevelCatalog.LayerInfo layerInfo in layers)
			{
				string captured = layerInfo.Name;
				list.Add(new RankedPanel.BrowserItem(captured, delegate
				{
					_browseLayer = captured;
					OpenLayerSelectForContext(pRank, context);
				}));
			}
			List<RankedPanel.PreviewItem> list2 = new List<RankedPanel.PreviewItem>();
			string[] levelsForLayer = LevelCatalog.GetLevelsForLayer(_browseLayer);
			foreach (string text in levelsForLayer)
			{
				list2.Add(new RankedPanel.PreviewItem(text, ThumbnailCatalog.GetTitle(text), text, null));
			}
			_panel.AddTwoPaneBrowser(list, list2, _browseLayer, delegate
			{
				CategoryDefinition category = (pRank ? CategoryDefinition.LayerPRank(_browseLayer) : CategoryDefinition.LayerAny(_browseLayer));
				_matches.SetCategory(category);
				if (_selectionContext == SelectionContext.PublicMatch)
				{
					StartPublicSearch();
				}
				else
				{
					OpenNetworkPrivateLobby();
				}
			});
			_panel.AddButton("BACK", (_selectionContext == SelectionContext.PublicMatch) ? new Action(OpenPublicCategorySelect) : new Action(OpenCategorySelect));
		}

		private void OpenLevelSelectForContext(bool pRank, SelectionContext context)
		{
			_selectionContext = context;
			ClosePanel();
			if (string.IsNullOrEmpty(_browseLayer))
			{
				_browseLayer = "OVERTURE";
			}
			_panel = new RankedPanel(_styleTemplate, pRank ? "SELECT LEVEL // P-RANK" : "SELECT LEVEL // ANY%");
			List<RankedPanel.BrowserItem> list = new List<RankedPanel.BrowserItem>();
			LevelCatalog.LayerInfo[] layers = LevelCatalog.Layers;
			foreach (LevelCatalog.LayerInfo layerInfo in layers)
			{
				string capturedLayer = layerInfo.Name;
				list.Add(new RankedPanel.BrowserItem(capturedLayer, delegate
				{
					_browseLayer = capturedLayer;
					OpenLevelSelectForContext(pRank, context);
				}));
			}
			List<RankedPanel.PreviewItem> list2 = new List<RankedPanel.PreviewItem>();
			string[] levelsForLayer = LevelCatalog.GetLevelsForLayer(_browseLayer);
			foreach (string text in levelsForLayer)
			{
				string capturedLevel = text;
				list2.Add(new RankedPanel.PreviewItem(capturedLevel, ThumbnailCatalog.GetTitle(capturedLevel), capturedLevel, delegate
				{
					_matches.SetSelectedLevel(capturedLevel);
					_matches.SetCategory(pRank ? CategoryDefinition.IndividualPRank(capturedLevel) : CategoryDefinition.IndividualAny(capturedLevel));
					OnLevelSelected();
				}));
			}
			_panel.AddTwoPaneBrowser(list, list2, _browseLayer, null);
			_panel.AddButton("BACK", (context == SelectionContext.PublicMatch) ? new Action(OpenPublicCategorySelect) : new Action(OpenNetworkPrivateLobby));
		}

		private void PickForContext(CategoryDefinition category)
		{
			_matches.SetCategory(category);
			ReturnAfterCategoryChoice();
		}

		private void ReturnAfterCategoryChoice()
		{
			if (_selectionContext == SelectionContext.PrivateLobby)
			{
				OpenNetworkPrivateLobby();
			}
			else if (_selectionContext == SelectionContext.PublicMatch)
			{
				StartPublicSearch();
			}
			else
			{
				OpenRankedHome();
			}
		}

		private void BeginLevelSelection(bool pRank)
		{
			_pendingLevelPRank = pRank;
			OpenLevelSelectForContext(pRank, _selectionContext);
		}

		private void OnLevelSelected()
		{
			if (_selectionContext == SelectionContext.PublicMatch)
			{
				StartPublicSearch();
			}
			else if (_selectionContext == SelectionContext.PrivateLobby)
			{
				OpenNetworkPrivateLobby();
			}
			else
			{
				OpenRankedHome();
			}
		}

		private void OpenPrivateLobby()
		{
			_selectionContext = SelectionContext.PrivateLobby;
			OpenNetworkPrivateLobby();
		}

		private void OpenProfile()
		{
			OpenNetworkProfile();
		}

		private void OpenError(string reason)
		{
			ClosePanel();
			_panel = new RankedPanel(_styleTemplate, "RANKED UNAVAILABLE");
			_panel.AddButton(reason, delegate
			{
			});
			_panel.AddButton("BACK", OpenRankedHome);
		}

		private void ClosePanel()
		{
			if (_panel != null)
			{
				_panel.Destroy();
			}
			_panel = null;
		}
	}
	public sealed class PauseMenuRewriter : MonoBehaviour
	{
		private MatchManager _matches;

		private ManualLogSource _log;

		private GameObject _hiddenVanilla;

		private GameObject _leaveMatchClone;

		private float _nextScan;

		public void Initialize(MatchManager matches, ManualLogSource log)
		{
			_matches = matches;
			_log = log;
		}

		private void Update()
		{
			if (!_matches.IsMatchActive)
			{
				Restore();
			}
			else if (!(Time.unscaledTime < _nextScan))
			{
				_nextScan = Time.unscaledTime + 0.25f;
				if ((Object)(object)_leaveMatchClone == (Object)null)
				{
					TryReplaceLeaveLevel();
				}
			}
		}

		private void TryReplaceLeaveLevel()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			Button val = ((IEnumerable<Button>)Resources.FindObjectsOfTypeAll<Button>()).FirstOrDefault((Func<Button, bool>)delegate(Button b)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)b != (Object)null)
				{
					Scene scene = ((Component)b).gameObject.scene;
					if (((Scene)(ref scene)).IsValid() && ((Component)b).gameObject.activeInHierarchy)
					{
						return IsLeaveLevelText(UiText.Get(((Component)b).gameObject));
					}
				}
				return false;
			});
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Button val2 = Object.Instantiate<Button>(val, ((Component)val).transform.parent);
			((Object)((Component)val2).gameObject).name = "UKSRR_LeaveMatch";
			((Component)val2).transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex());
			UiText.Set(((Component)val2).gameObject, "LEAVE MATCH");
			ButtonClickedEvent vanillaExit = val.onClick;
			val2.onClick = new ButtonClickedEvent();
			((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
			{
				_matches.Forfeit("LEFT MATCH");
				Restore();
				if (vanillaExit != null)
				{
					((UnityEvent)vanillaExit).Invoke();
				}
			});
			_hiddenVanilla = ((Component)val).gameObject;
			_hiddenVanilla.SetActive(false);
			_leaveMatchClone = ((Component)val2).gameObject;
			_log.LogInfo((object)"Pause menu: LEAVE LEVEL replaced with LEAVE MATCH.");
		}

		private static bool IsLeaveLevelText(string raw)
		{
			string text = (raw ?? "").Trim().ToUpperInvariant();
			switch (text)
			{
			default:
				return text == "LEVEL SELECT";
			case "LEAVE LEVEL":
			case "QUIT MISSION":
			case "EXIT LEVEL":
				return true;
			}
		}

		private void Restore()
		{
			if ((Object)(object)_hiddenVanilla != (Object)null)
			{
				_hiddenVanilla.SetActive(true);
			}
			if ((Object)(object)_leaveMatchClone != (Object)null)
			{
				Object.Destroy((Object)(object)_leaveMatchClone);
			}
			_hiddenVanilla = null;
			_leaveMatchClone = null;
		}
	}
	public sealed class RankedHud : MonoBehaviour
	{
		private MatchManager _matches;

		private SteamRankedBridge _network;

		private GUIStyle _label;

		private GUIStyle _timerLabel;

		private Texture2D _bg;

		private Texture2D _rankedIcon;

		public void Initialize(MatchManager matches, SteamRankedBridge network, string iconPath)
		{
			_matches = matches;
			_network = network;
			LoadRankedIcon(iconPath);
		}

		private void LoadRankedIcon(string path)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (string.IsNullOrEmpty(path) || !File.Exists(path))
			{
				return;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, array, false))
				{
					((Object)val).name = "UKSR_RankedBadge";
					_rankedIcon = val;
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			catch
			{
				_rankedIcon = null;
			}
		}

		private void Ensure()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_bg != (Object)null))
			{
				_bg = new Texture2D(1, 1);
				_bg.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.72f));
				_bg.Apply();
				_label = new GUIStyle(GUI.skin.label);
				_label.fontSize = 18;
				_label.fontStyle = (FontStyle)1;
				_label.normal.textColor = Color.white;
				_timerLabel = new GUIStyle(_label);
				_timerLabel.normal.textColor = new Color(0.18f, 1f, 0.28f, 1f);
			}
		}

		private void OnGUI()
		{
			if (_matches != null && _matches.IsMatchActive)
			{
				Ensure();
				if (RankedSettings.TimerEnabled)
				{
					DrawTimer();
				}
				DrawRankedBadge();
			}
		}

		private void DrawTimer()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			Rect val = TimerRect();
			GUI.DrawTexture(val, (Texture)(object)_bg);
			string text = ((_matches.Category == null) ? "RANKED" : _matches.Category.DisplayName);
			float num = ((Rect)(ref val)).x + 12f;
			float num2 = ((Rect)(ref val)).y + 10f;
			GUI.Label(new Rect(num, num2, 306f, 24f), "UKSR // " + text, _label);
			GUI.Label(new Rect(num, num2 + 28f, 290f, 24f), "RTA  " + Format(_matches.RtaSeconds), _timerLabel);
			GUI.Label(new Rect(num, num2 + 54f, 290f, 24f), "IGT  " + Format(_matches.IgtSeconds), _timerLabel);
			string text2 = ((!_matches.RtaStarted) ? (_matches.GameplayReady ? "RTA ARMED // MOVE TO START" : "WAITING FOR PLAYER") : (_matches.GameplayTimerAvailable ? _matches.Status : "RUNNING // IGT WAITING"));
			GUI.Label(new Rect(num, num2 + 80f, 290f, 24f), text2, _label);
			if ((Object)(object)_network != (Object)null && _network.LivePeers.Count > 0)
			{
				int num3 = Mathf.Min(4, _network.LivePeers.Count);
				for (int i = 0; i < num3; i++)
				{
					RankedLivePeer rankedLivePeer = _network.LivePeers[i];
					string text3 = rankedLivePeer.Name + "  IGT " + Format(rankedLivePeer.Igt) + (string.IsNullOrEmpty(rankedLivePeer.Level) ? "" : ("  " + rankedLivePeer.Level));
					GUI.Label(new Rect(num, num2 + 108f + (float)i * 22f, 306f, 22f), text3, _timerLabel);
				}
				if (_network.LivePeers.Count > num3)
				{
					GUI.Label(new Rect(num, num2 + 108f + (float)num3 * 22f, 306f, 22f), "+" + (_network.LivePeers.Count - num3) + " MORE", _label);
				}
			}
		}

		private void DrawRankedBadge()
		{
			//IL_0098: 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)
			//IL_005c: 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)
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((float)Screen.width - 24f - 7f, (float)Screen.height - 24f - 7f, 24f, 24f);
			if ((Object)(object)_rankedIcon != (Object)null)
			{
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, 0.68f);
				GUI.DrawTexture(val, (Texture)(object)_rankedIcon, (ScaleMode)2, true);
				GUI.color = color;
			}
			else
			{
				GUI.Label(new Rect(((Rect)(ref val)).x - 28f, ((Rect)(ref val)).y, 52f, 24f), "UKSR", _label);
			}
		}

		private Rect TimerRect()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			int num = ((!((Object)(object)_network == (Object)null)) ? Mathf.Min(4, _network.LivePeers.Count) : 0);
			float num2 = 142f + (float)num * 22f + (((Object)(object)_network != (Object)null && _network.LivePeers.Count > 4) ? 22f : 0f);
			return (Rect)(RankedSettings.TimerPosition switch
			{
				TimerPosition.TopLeft => new Rect(18f, 18f, 330f, num2), 
				TimerPosition.TopCenter => new Rect(((float)Screen.width - 330f) * 0.5f, 18f, 330f, num2), 
				TimerPosition.TopRight => new Rect((float)Screen.width - 330f - 18f, 18f, 330f, num2), 
				TimerPosition.BottomLeft => new Rect(18f, (float)Screen.height - num2 - 18f, 330f, num2), 
				TimerPosition.BottomCenter => new Rect(((float)Screen.width - 330f) * 0.5f, (float)Screen.height - num2 - 18f, 330f, num2), 
				_ => new Rect((float)Screen.width - 330f - 18f, (float)Screen.height - num2 - 18f, 330f, num2), 
			});
		}

		private static string Format(double t)
		{
			int num = (int)(t / 3600.0);
			int num2 = (int)(t % 3600.0 / 60.0);
			double num3 = t % 60.0;
			if (num <= 0)
			{
				return $"{num2:00}:{num3:00.000}";
			}
			return $"{num:00}:{num2:00}:{num3:00.000}";
		}
	}
	public sealed class RankedNotificationManager : MonoBehaviour
	{
		private sealed class Toast
		{
			public string Text;

			public float Expires;
		}

		private readonly List<Toast> _toasts = new List<Toast>();

		private MatchManager _matches;

		private ManualLogSource _log;

		private GUIStyle _style;

		private Texture2D _background;

		public void Initialize(MatchManager matches, ManualLogSource log)
		{
			_matches = matches;
			_log = log;
		}

		public void Checkpoint(string who, string checkpoint)
		{
			if (RankedSettings.ProgressNotifications)
			{
				Show(who + " HIT CHECKPOINT " + checkpoint);
			}
		}

		public void BossKilled(string who, string boss)
		{
			if (RankedSettings.ProgressNotifications)
			{
				Show(who + " KILLED " + boss);
			}
		}

		public void LevelCompleted(string who, string level, double rtaSeconds, double igtSeconds)
		{
			if (RankedSettings.ProgressNotifications)
			{
				Show(who + " BEAT " + level + "   RTA " + FormatTime(rtaSeconds) + "   IGT " + FormatTime(igtSeconds));
			}
		}

		public void SystemMessage(string message)
		{
			if (RankedSettings.ProgressNotifications)
			{
				Show(message);
			}
		}

		private void Show(string message)
		{
			_toasts.Add(new Toast
			{
				Text = message,
				Expires = Time.unscaledTime + 4.5f
			});
			if (_log != null)
			{
				_log.LogInfo((object)("UKSR NOTIFY: " + message));
			}
		}

		private void EnsureStyle()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_background != (Object)null))
			{
				_background = new Texture2D(1, 1);
				_background.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.78f));
				_background.Apply();
				_style = new GUIStyle(GUI.skin.label);
				_style.fontSize = 17;
				_style.fontStyle = (FontStyle)1;
				_style.normal.textColor = Color.white;
				_style.alignment = (TextAnchor)3;
			}
		}

		private void Update()
		{
			for (int num = _toasts.Count - 1; num >= 0; num--)
			{
				if (Time.unscaledTime >= _toasts[num].Expires)
				{
					_toasts.RemoveAt(num);
				}
			}
		}

		private void OnGUI()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (_toasts.Count != 0 && RankedSettings.ProgressNotifications)
			{
				EnsureStyle();
				Rect val = default(Rect);
				for (int i = 0; i < _toasts.Count; i++)
				{
					float num = (float)Screen.height - 24f - 46f - (float)(_toasts.Count - 1 - i) * 54f;
					((Rect)(ref val))..ctor(((float)Screen.width - 620f) * 0.5f, num, 620f, 46f);
					GUI.DrawTexture(val, (Texture)(object)_background);
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y, ((Rect)(ref val)).width - 24f, ((Rect)(ref val)).height), _toasts[i].Text, _style);
				}
			}
		}

		public static string FormatTime(double t)
		{
			int num = (int)(t / 3600.0);
			int num2 = (int)(t % 3600.0 / 60.0);
			double num3 = t % 60.0;
			if (num > 0)
			{
				return $"{num:00}:{num2:00}:{num3:00.000}";
			}
			return $"{num2:00}:{num3:00.000}";
		}
	}
	internal sealed class RankedPanel
	{
		internal sealed class GridItem
		{
			public string Label;

			public Action OnClick;

			public GridItem(string label, Action onClick)
			{
				Label = label;
				OnClick = onClick;
			}
		}

		internal sealed class BrowserItem
		{
			public string Label;

			public Action OnClick;

			public BrowserItem(string label, Action onClick)
			{
				Label = label;
				OnClick = onClick;
			}
		}

		internal sealed class PreviewItem
		{
			public string Title;

			public string Subtitle;

			public string SpriteKey;

			public Action OnClick;

			public PreviewItem(string title, string subtitle, string spriteKey, Action onClick)
			{
				Title = title;
				Subtitle = subtitle;
				SpriteKey = spriteKey;
				OnClick = onClick;
			}
		}

		private readonly GameObject _root;

		private readonly RectTransform _content;

		private readonly Button _template;

		private readonly List<GameObject> _created = new List<GameObject>();

		private readonly List<GameObject> _hiddenUnderlying = new List<GameObject>();

		private float _cursorY;

		private readonly float _buttonWidth;

		private readonly float _rowStep;

		private readonly string _title;

		private readonly bool _browserLayout;

		private readonly bool _lobbyLayout;

		private readonly bool _resultsLayout;

		private static readonly Dictionary<string, Sprite> PreviewCache = new Dictionary<string, Sprite>();

		public bool Alive => (Object)(object)_root != (Object)null;

		public RankedPanel(Button template, string title)
		{
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			_template = template;
			_title = title ?? "";
			_browserLayout = _title.IndexOf("PUBLIC MATCH", StringComparison.OrdinalIgnoreCase) >= 0 || _title.IndexOf("SELECT", StringComparison.OrdinalIgnoreCase) >= 0 || _title.IndexOf("BROWSER", StringComparison.OrdinalIgnoreCase) >= 0;
			_lobbyLayout = _title.IndexOf("PRIVATE LOBBY", StringComparison.OrdinalIgnoreCase) >= 0;
			_resultsLayout = _title.IndexOf("MATCH RESULTS", StringComparison.OrdinalIgnoreCase) >= 0 || _title.IndexOf("SPECTATING REMAINING RUNNERS", StringComparison.OrdinalIgnoreCase) >= 0;
			Canvas componentInParent = ((Component)template).GetComponentInParent<Canvas>();
			Selectable[] componentsInChildren = ((Component)componentInParent).GetComponentsInChildren<Selectable>(true);
			foreach (Selectable val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeSelf)
				{
					_hiddenUnderlying.Add(((Component)val).gameObject);
					((Component)val).gameObject.SetActive(false);
				}
			}
			_root = new GameObject("UKSRR_Panel", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			_root.transform.SetParent(((Component)componentInParent).transform, false);
			_root.transform.SetAsLastSibling();
			RectTransform val2 = (RectTransform)_root.transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			Image component = _root.GetComponent<Image>();
			((Graphic)component).color = new Color(0.01f, 0.01f, 0.01f, 0.985f);
			((Graphic)component).raycastTarget = true;
			GameObject val3 = new GameObject("UKSRR_Content", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(_root.transform, false);
			_content = (RectTransform)val3.transform;
			if (_browserLayout || _lobbyLayout || _resultsLayout)
			{
				_content.anchorMin = new Vector2(0.045f, 0.085f);
				_content.anchorMax = new Vector2(0.955f, 0.905f);
			}
			else
			{
				_content.anchorMin = new Vector2(0.075f, 0.1f);
				_content.anchorMax = new Vector2(0.925f, 0.9f);
			}
			_content.offsetMin = Vector2.zero;
			_content.offsetMax = Vector2.zero;
			GameObject val4 = new GameObject("UKSRR_Frame", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val4.transform.SetParent(_root.transform, false);
			val4.transform.SetSiblingIndex(0);
			RectTransform val5 = (RectTransform)val4.transform;
			val5.anchorMin = new Vector2(0.025f, 0.035f);
			val5.anchorMax = new Vector2(0.975f, 0.965f);
			val5.offsetMin = Vector2.zero;
			val5.offsetMax = Vector2.zero;
			Image component2 = val4.GetComponent<Image>();
			((Graphic)component2).color = new Color(0.04f, 0.04f, 0.04f, 0.985f);
			((Graphic)component2).raycastTarget = false;
			GameObject val6 = new GameObject("UKSRR_Accent", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val6.transform.SetParent(val4.transform, false);
			RectTransform val7 = (RectTransform)val6.transform;
			val7.anchorMin = new Vector2(0f, 1f);
			val7.anchorMax = new Vector2(1f, 1f);
			val7.pivot = new Vector2(0.5f, 1f);
			val7.sizeDelta = new Vector2(0f, 5f);
			val7.anchoredPosition = Vector2.zero;
			Image component3 = val6.GetComponent<Image>();
			((Graphic)component3).color = new Color(0.82f, 0.06f, 0.06f, 1f);
			((Graphic)component3).raycastTarget = false;
			float num = (float)Screen.width / 1920f;
			float num2 = (float)Screen.height / 1080f;
			float num3 = Mathf.Clamp(Mathf.Min(num, num2) * 0.64f, 0.46f, 0.92f);
			Canvas.ForceUpdateCanvases();
			Rect rect = _content.rect;
			float num4 = Mathf.Max(300f, ((Rect)(ref rect)).height * 0.5f);
			float num5 = ((_browserLayout || _lobbyLayout || _resultsLayout) ? 430f : 500f) * num3;
			rect = _content.rect;
			_buttonWidth = Mathf.Clamp(num5, 230f, ((Rect)(ref rect)).width * ((_browserLayout || _lobbyLayout || _resultsLayout) ? 0.22f : 0.25f));
			_rowStep = Mathf.Clamp(108f * num3, 58f, 86f);
			_cursorY = Mathf.Min(300f * num3, num4 - 66f * num3);
			AddBrand();
			AddTitle(title);
		}

		private static float scaleForScreen()
		{
			return Mathf.Clamp((float)Screen.height / 1080f * 0.72f, 0.58f, 0.9f);
		}

		private void AddBrand()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton("UKSR RANKED", null);
			((Selectable)obj).interactable = false;
			MakeTextOnly(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			((Transform)component).SetParent(_root.transform, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0f, 1f);
			float num = Mathf.Clamp((float)Screen.width * 0.028f, 18f, 46f);
			float num2 = Mathf.Clamp((float)Screen.height * 0.028f, 16f, 38f);
			component.anchoredPosition = new Vector2(num, 0f - num2);
			component.sizeDelta = new Vector2(Mathf.Clamp((float)Screen.width * 0.22f, 220f, 460f), 42f);
		}

		public void AddTitle(string title)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(title, null);
			((Selectable)obj).interactable = false;
			MakeTextOnly(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(0f, _cursorY);
			component.sizeDelta = new Vector2(_buttonWidth * 1.22f, Mathf.Clamp(58f * scaleForScreen(), 38f, 54f));
			_cursorY -= _rowStep * 0.96f;
		}

		public void AddLabel(string label)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, null);
			((Selectable)obj).interactable = false;
			MakeTextOnly(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(0f, _cursorY);
			component.sizeDelta = new Vector2(_buttonWidth * 1.22f, Mathf.Clamp(46f * scaleForScreen(), 30f, 44f));
			_cursorY -= _rowStep * 0.78f;
		}

		public Button AddButton(string label, Action onClick)
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			Button val = CloneButton(label, onClick);
			MakeCleanButton(val);
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			if (string.Equals(label, "BACK", StringComparison.OrdinalIgnoreCase))
			{
				((Transform)component).SetParent(_root.transform, false);
				((Vector2)(ref val2))..ctor(0f, 0f);
				component.anchorMax = val2;
				component.anchorMin = val2;
				component.pivot = new Vector2(0f, 0f);
				float num = 0f;
				float num2 = Mathf.Clamp((float)Screen.height * 0.012f, 6f, 14f);
				component.anchoredPosition = new Vector2(num, num2);
				component.sizeDelta = new Vector2(Mathf.Clamp((float)Screen.width * 0.14f, 170f, 280f), Mathf.Clamp((float)Screen.height * 0.052f, 34f, 52f));
				return val;
			}
			((Vector2)(ref val2))..ctor(0f, 0.5f);
			component.anchorMax = val2;
			component.anchorMin = val2;
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(0f, _cursorY);
			component.sizeDelta = new Vector2(_buttonWidth, Mathf.Clamp(42f * ((float)Screen.height / 1080f), 32f, 46f));
			_cursorY -= _rowStep;
			return val;
		}

		public Button AddRightColumnButton(string label, Action onClick, int slot)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, onClick);
			MakeCleanButton(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			float num = Mathf.Clamp((float)Screen.height / 1080f * 0.62f, 0.46f, 0.78f);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(1f, 0.5f);
			Rect rect = _content.rect;
			component.sizeDelta = new Vector2(Mathf.Clamp(((Rect)(ref rect)).width * 0.23f, 160f, 330f), Mathf.Clamp(56f * num, 32f, 46f));
			component.anchoredPosition = new Vector2(0f, 155f * num - (float)slot * 88f * num);
			return obj;
		}

		public void AddRightColumnLabel(string label, int slot)
		{
			//IL_004f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, null);
			((Selectable)obj).interactable = false;
			MakeTextOnly(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			float num = Mathf.Clamp((float)Screen.height / 1080f * 0.62f, 0.46f, 0.78f);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(1f, 0.5f);
			Rect rect = _content.rect;
			component.sizeDelta = new Vector2(Mathf.Clamp(((Rect)(ref rect)).width * 0.25f, 170f, 360f), Mathf.Clamp(42f * num, 30f, 42f));
			component.anchoredPosition = new Vector2(0f, 285f * num - (float)slot * 62f * num);
		}

		public Button AddBottomLeftAction(string label, Action onClick, int index)
		{
			//IL_003a: 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)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, onClick);
			MakeCleanButton(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			((Transform)component).SetParent(_root.transform, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0f, 0f);
			float num = Mathf.Clamp((float)Screen.height * 0.05f, 32f, 50f);
			float num2 = Mathf.Clamp((float)Screen.width * 0.12f, 140f, 240f);
			float num3 = 6f;
			component.anchoredPosition = new Vector2((float)index * (num2 + num3), Mathf.Clamp((float)Screen.height * 0.012f, 6f, 14f));
			component.sizeDelta = new Vector2(num2, num);
			FitRectToViewport(component, 110f, 28f);
			return obj;
		}

		public Button AddBottomRightButton(string label, Action onClick, int slot)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, onClick);
			MakeCleanButton(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			float num = Mathf.Clamp((float)Screen.height / 1080f * 0.62f, 0.46f, 0.78f);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 0f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(1f, 0f);
			Rect rect = _content.rect;
			component.sizeDelta = new Vector2(Mathf.Clamp(((Rect)(ref rect)).width * 0.23f, 160f, 330f), Mathf.Clamp(58f * num, 34f, 48f));
			component.anchoredPosition = new Vector2(0f, (float)slot * 72f * num);
			return obj;
		}

		private void FitRectToViewport(RectTransform rt, float minimumWidth, float minimumHeight)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rt == (Object)null))
			{
				Vector2 sizeDelta = rt.sizeDelta;
				float num = Mathf.Max(minimumWidth, (float)Screen.width * 0.42f);
				float num2 = Mathf.Max(minimumHeight, (float)Screen.height * 0.12f);
				sizeDelta.x = Mathf.Clamp(sizeDelta.x, minimumWidth, num);
				sizeDelta.y = Mathf.Clamp(sizeDelta.y, minimumHeight, num2);
				rt.sizeDelta = sizeDelta;
			}
		}

		private static void MakeCleanButton(Button button)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)button == (Object)null))
			{
				Image component = ((Component)button).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					component.sprite = null;
					component.type = (Type)0;
					((Graphic)component).color = new Color(0.11f, 0.11f, 0.11f, 0.96f);
					((Graphic)component).raycastTarget = true;
				}
				ColorBlock colors = ((Selectable)button).colors;
				((ColorBlock)(ref colors)).normalColor = new Color(1f, 1f, 1f, 1f);
				((ColorBlock)(ref colors)).highlightedColor = new Color(1.15f, 1.15f, 1.15f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
				((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).highlightedColor;
				((ColorBlock)(ref colors)).fadeDuration = 0.06f;
				((Selectable)button).colors = colors;
			}
		}

		private static void MakeTextOnly(Button button)
		{
			//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)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)button == (Object)null)
			{
				return;
			}
			Image[] componentsInChildren = ((Component)button).GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Color color = ((Graphic)val).color;
					color.a = 0f;
					((Graphic)val).color = color;
					((Graphic)val).raycastTarget = false;
				}
			}
		}

		public void ForceRefresh()
		{
			if ((Object)(object)_root == (Object)null)
			{
				return;
			}
			Graphic[] componentsInChildren = _root.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.SetVerticesDirty();
					val.SetMaterialDirty();
				}
			}
			Canvas.ForceUpdateCanvases();
		}

		public void AddGrid(IList<GridItem> items, int columns, float buttonWidth, float rowHeight)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			if (items != null && items.Count != 0)
			{
				columns = Mathf.Max(1, columns);
				Rect rect = _content.rect;
				float num = Mathf.Max(320f, ((Rect)(ref rect)).width);
				int num2 = Mathf.Max(1, Mathf.FloorToInt(num / Mathf.Max(220f, buttonWidth + 26f)));
				columns = Mathf.Min(columns, num2);
				float num3 = 38f;
				float num4 = 34f;
				float num5 = (num - num3 * (float)(columns - 1)) / (float)columns;
				float num6 = Mathf.Min(Mathf.Max(buttonWidth, 280f), num5);
				float cursorY = _cursorY;
				Vector2 val = default(Vector2);
				for (int i = 0; i < items.Count; i++)
				{
					int num7 = i % columns;
					int num8 = i / columns;
					GridItem gridItem = items[i];
					Button obj = CloneButton(gridItem.Label, gridItem.OnClick);
					MakeCleanButton(obj);
					RectTransform component = ((Component)obj).GetComponent<RectTransform>();
					((Vector2)(ref val))..ctor(0f, 0.5f);
					component.anchorMax = val;
					component.anchorMin = val;
					component.pivot = new Vector2(0f, 0.5f);
					component.anchoredPosition = new Vector2((float)num7 * (num6 + num3), cursorY - (float)num8 * (rowHeight + num4));
					component.sizeDelta = new Vector2(num6, Mathf.Max(60f, rowHeight));
				}
				int num9 = Mathf.CeilToInt((float)items.Count / (float)columns);
				_cursorY = cursorY - (float)num9 * (rowHeight + num4) - 34f;
			}
		}

		public void AddPagedGrid(IList<GridItem> items, int page, int requestedColumns, Action<int> changePage)
		{
			//IL_0031: 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_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)
			if (items == null || items.Count == 0)
			{
				return;
			}
			Canvas.ForceUpdateCanvases();
			Rect rect = _content.rect;
			float num = Mathf.Max(420f, ((Rect)(ref rect)).width);
			rect = _content.rect;
			float num2 = Mathf.Max(300f, ((Rect)(ref rect)).height - 185f);
			int num3 = Mathf.Clamp(requestedColumns, 1, (num >= 1500f) ? 4 : ((num >= 1040f) ? 3 : 2));
			float buttonWidth = Mathf.Clamp(num / (float)num3 - 28f, 210f, 430f);
			float num4 = Mathf.Clamp((float)Screen.height * 0.072f, 54f, 82f);
			float num5 = Mathf.Clamp((float)Screen.height * 0.02f, 14f, 28f);
			int num6 = Mathf.Max(2, Mathf.FloorToInt(num2 / (num4 + num5)));
			int num7 = Mathf.Max(1, num3 * num6);
			int num8 = Mathf.Max(1, Mathf.CeilToInt((float)items.Count / (float)num7));
			page = Mathf.Clamp(page, 0, num8 - 1);
			int num9 = page * num7;
			int num10 = Mathf.Min(num7, items.Count - num9);
			List<GridItem> list = new List<GridItem>();
			for (int i = 0; i < num10; i++)
			{
				list.Add(items[num9 + i]);
			}
			AddGrid(list, num3, buttonWidth, num4);
			AddBottomCenterLabel("PAGE " + (page + 1) + " / " + num8);
			if (num8 <= 1 || changePage == null)
			{
				return;
			}
			if (page > 0)
			{
				AddBottomLeftAction("< PREVIOUS", delegate
				{
					changePage(page - 1);
				}, 1);
			}
			if (page < num8 - 1)
			{
				AddBottomRightButton("NEXT >", delegate
				{
					changePage(page + 1);
				}, 0);
			}
		}

		public void AddBottomCenterLabel(string label)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			Button obj = CloneButton(label, null);
			((Selectable)obj).interactable = false;
			MakeTextOnly(obj);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			((Transform)component).SetParent(_root.transform, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0.5f, 0f);
			component.anchoredPosition = new Vector2(0f, Mathf.Clamp((float)Screen.height * 0.016f, 8f, 18f));
			component.sizeDelta = new Vector2(Mathf.Clamp((float)Screen.width * 0.18f, 180f, 360f), Mathf.Clamp((float)Screen.height * 0.04f, 28f, 44f));
		}

		public void AddTwoPaneBrowser(IList<BrowserItem> left, IList<PreviewItem> right, string selectedLeft, Action selectCurrent)
		{
			//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)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			Canvas.ForceUpdateCanvases();
			Rect rect = _content.rect;
			float num = Mathf.Max(360f, ((Rect)(ref rect)).height - 135f);
			float cursorY = _cursorY;
			rect = _content.rect;
			float num2 = Mathf.Min(cursorY, ((Rect)(ref rect)).height * 0.5f - 125f);
			rect = _content.rect;
			bool flag = ((Rect)(ref rect)).width < 900f;
			float num3;
			if (!flag)
			{
				rect = _content.rect;
				num3 = Mathf.Clamp(((Rect)(ref rect)).width * 0.2f, 190f, 300f);
			}
			else
			{
				rect = _content.rect;
				num3 = Mathf.Clamp(((Rect)(ref rect)).width * 0.28f, 150f, 240f);
			}
			float num4 = num3;
			float num5 = num4 + (flag ? 18f : 28f);
			float num6 = (flag ? 260f : 420f);
			rect = _content.rect;
			float num7 = Mathf.Max(num6, ((Rect)(ref rect)).width - num5);
			float num8 = Mathf.Clamp(num / Mathf.Max(9.5f, (float)left.Count + 1.5f), 44f, 62f);
			Vector2 val = default(Vector2);
			for (int i = 0; i < left.Count; i++)
			{
				BrowserItem browserItem = left[i];
				string label = ((browserItem.Label == selectedLeft) ? ("> " + browserItem.Label + " <") : browserItem.Label);
				Button obj = CloneButton(label, browserItem.OnClick);
				MakeCleanButton(obj);
				RectTransform component = ((Component)obj).GetComponent<RectTransform>();
				((Vector2)(ref val))..ctor(0f, 0.5f);
				component.anchorMax = val;
				component.anchorMin = val;
				component.pivot = new Vector2(0f, 0.5f);
				component.anchoredPosition = new Vector2(0f, num2 - (float)i * num8);
				component.sizeDelta = new Vector2(num4, Mathf.Max(50f, num8 - 9f));
			}
			if (selectCurrent != null)
			{
				Button obj2 = CloneButton("SELECT " + selectedLeft, selectCurrent);
				MakeCleanButton(obj2);
				RectTransform component2 = ((Component)obj2).GetComponent<RectTransform>();
				((Vector2)(ref val))..ctor(0f, 0.5f);
				component2.anchorMax = val;
				component2.anchorMin = val;
				component2.pivot = new Vector2(0f, 0.5f);
				component2.anchoredPosition = new Vector2(0f, num2 - (float)left.Count * num8 - 12f);
				component2.sizeDelta = new Vector2(num4, 64f);
			}
			int num9 = ((num7 >= 1250f) ? 3 : 2);
			float num10 = 40f;
			float num11 = 34f;
			int num12 = Mathf.Max(1, Mathf.CeilToInt((float)right.Count / (float)num9));
			float num13 = (num7 - num10 * (float)(num9 - 1)) / (float)num9;
			float num14 = Mathf.Clamp((num - num11 * (float)(num12 - 1)) / (float)num12, 105f, 155f);
			for (int j = 0; j < right.Count; j++)
			{
				int num15 = j % num9;
				int num16 = j / num9;
				PreviewItem previewItem = right[j];
				Button val2 = CloneButton(previewItem.Title, previewItem.OnClick);
				MakeCleanButton(val2);
				RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
				((Vector2)(ref val))..ctor(0f, 0.5f);
				component3.anchorMax = val;
				component3.anchorMin = val;
				component3.pivot = new Vector2(0f, 0.5f);
				component3.anchoredPosition = new Vector2(num5 + (float)num15 * (num13 + num10), num2 - (float)num16 * (num14 + num11));
				component3.sizeDelta = new Vector2(num13, num14);
				LayoutPreviewText(((Component)val2).gameObject);
				AddPreviewImage(((Component)val2).gameObject, previewItem.SpriteKey, previewItem.Subtitle);
			}
			float num17 = Mathf.Max((float)left.Count * num8 + 84f, (float)num12 * (num14 + num11));
			_cursorY = num2 - num17 - 30f;
		}

		private static void LayoutPreviewText(GameObject buttonObject)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Component[] componentsInChildren = buttonObject.GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				PropertyInfo property = ((object)val).GetType().GetProperty("text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (!(property == null) && !(property.PropertyType != typeof(string)))
				{
					Transform transform = val.transform;
					RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
					if (!((Object)(object)val2 == (Object)null))
					{
						val2.anchorMin = new Vector2(0.06f, 0.035f);
						val2.anchorMax = new Vector2(0.94f, 0.25f);
						val2.offsetMin = Vector2.zero;
						val2.offsetMax = Vector2.zero;
					}
				}
			}
		}

		private void AddPreviewImage(GameObject buttonObject, string spriteKey, string subtitle)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_006b: 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)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = FindPreviewSprite(spriteKey);
			if ((Object)(object)val == (Object)null)
			{
				val = CreateFallbackPreviewSprite(spriteKey);
			}
			GameObject val2 = new GameObject("UKSRR_Preview", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val2.transform.SetParent(buttonObject.transform, false);
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = new Vector2(0.055f, 0.3f);
			val3.anchorMax = new Vector2(0.945f, 0.94f);
			val3.offsetMin = Vector2.zero;
			val3.offsetMax = Vector2.zero;
			Image component = val2.GetComponent<Image>();
			component.sprite = val;
			component.preserveAspect = true;
			((Graphic)component).raycastTarget = false;
		}

		private static Sprite CreateFallbackPreviewSprite(string key)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(320, 180, (TextureFormat)4, false);
			int num = ((!string.IsNullOrEmpty(key)) ? key.GetHashCode() : 0);
			byte b = (byte)(42 + Math.Abs(num % 70));
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor(b, b, b, byte.MaxValue);
			Color32 val3 = default(Color32);
			((Color32)(ref val3))..ctor((byte)Mathf.Min(255, b + 26), (byte)Mathf.Min(255, b + 26), (byte)Mathf.Min(255, b + 26), byte.MaxValue);
			Color32[] array = (Color32[])(object)new Color32[57600];
			for (int i = 0; i < 180; i++)
			{
				for (int j = 0; j < 320; j++)
				{
					array[i * 320 + j] = (((j + i) / 20 % 2 == 0) ? val2 : val3);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			((Object)val).name = "UKSR_Fallback_" + (key ?? "LEVEL");
			return Sprite.Create(val, new Rect(0f, 0f, 320f, 180f), new Vector2(0.5f, 0.5f), 100f);
		}

		private static Sprite FindPreviewSprite(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				return null;
			}
			Sprite sprite = ThumbnailCatalog.GetSprite(key);
			if ((Object)(object)sprite != (Object)null)
			{
				return sprite;
			}
			string text = NormalizePreviewKey(key);
			if (PreviewCache.TryGetValue(text, out var value))
			{
				return value;
			}
			Sprite val = FindNamedSprite(text);
			if ((Object)(object)val != (Object)null)
			{
				PreviewCache[text] = val;
				return val;
			}
			Sprite val2 = FindSpriteFromMapMetadata(text);
			PreviewCache[text] = val2;
			return val2;
		}

		private static Sprite FindNamedSprite(string normalized)
		{
			Sprite result = null;
			int num = -1;
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if (!((Object)(object)val == (Object)null) && !string.IsNullOrEmpty(((Object)val).name))
				{
					string text = NormalizePreviewKey(((Object)val).name);
					int num2 = 0;
					if (text == normalized)
					{
						num2 = 100;
					}
					else if (text.Contains(normalized))
					{
						num2 = 60;
					}
					else if (normalized.Contains(text))
					{
						num2 = 25;
					}
					string value = ((normalized.Length == 2) ? (normalized.Substring(0, 1) + "x" + normalized.Substring(1, 1)) : normalized);
					if (text.Contains(value))
					{
						num2 += 5;
					}
					if (num2 > num)
					{
						result = val;
						num = num2;
					}
				}
			}
			if (num <= 0)
			{
				return null;
			}
			return result;
		}

		private static Sprite FindSpriteFromMapMetadata(string normalized)
		{
			ScriptableObject[] array = Resources.FindObjectsOfTypeAll<ScriptableObject>();
			foreach (ScriptableObject val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Type type = ((object)val).GetType();
				string text = ((type.Name == null) ? "" : type.Name.ToLowerInvariant());
				if (!text.Contains("map") && !text.Contains("level"))
				{
					continue;
				}
				BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
				bool flag = NormalizePreviewKey(((Object)val).name).Contains(normalized);
				Sprite val2 = null;
				FieldInfo[] fields = type.GetFields(bindingAttr);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(val);
					}
					catch
					{
					}
					string value = obj as string;
					if (!string.IsNullOrEmpty(value) && NormalizePreviewKey(value).Contains(normalized))
					{
						flag = true;
					}
					if ((Object)(object)val2 == (Object)null)
					{
						Sprite val3 = (Sprite)((obj is Sprite) ? obj : null);
						if ((Object)(object)val3 != (Object)null)
						{
							val2 = val3;
						}
					}
				}
				PropertyInfo[] properties = type.GetProperties(bindingAttr);
				foreach (PropertyInfo propertyInfo in properties)
				{
					if (!propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
					{
						continue;
					}
					object obj3 = null;
					try
					{
						obj3 = propertyInfo.GetValue(val, null);
					}
					catch
					{
					}
					string value2 = obj3 as string;
					if (!string.IsNullOrEmpty(value2) && NormalizePreviewKey(value2).Contains(normalized))
					{
						flag = true;
					}
					if ((Object)(object)val2 == (Object)null)
					{
						Sprite val4 = (Sprite)((obj3 is Sprite) ? obj3 : null);
						if ((Object)(object)val4 != (Object)null)
						{
							val2 = val4;
						}
					}
				}
				if (flag && (Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return null;
		}

		private static string NormalizePreviewKey(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			return value.Replace("-", "").Replace("_", "").Replace(" ", "")
				.Replace("/", "")
				.ToLowerInvariant();
		}

		private static void FitButtonText(GameObject buttonObject)
		{
			Component[] componentsInChildren = buttonObject.GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Type type = ((object)val).GetType();
				PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property == null || property.PropertyType != typeof(string))
				{
					continue;
				}
				string text = "";
				try
				{
					object value = property.GetValue(val, null);
					text = ((value == null) ? "" : value.ToString());
				}
				catch
				{
				}
				PropertyInfo property2 = type.GetProperty("resizeTextForBestFit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property2 != null && property2.PropertyType == typeof(bool) && property2.CanWrite)
				{
					try
					{
						property2.SetValue(val, true, null);
					}
					catch
					{
					}
				}
				PropertyInfo property3 = type.GetProperty("enableAutoSizing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property3 != null && property3.PropertyType == typeof(bool) && property3.CanWrite)
				{
					try
					{
						property3.SetValue(val, true, null);
					}
					catch
					{
					}
				}
				if (string.IsNullOrEmpty(text) || text.Length < 18)
				{
					continue;
				}
				PropertyInfo property4 = type.GetProperty("fontSize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property4 != null && property4.CanRead && property4.CanWrite)
				{
					try
					{
						float num = Convert.ToSingle(property4.GetValue(val, null));
						float num2 = ((text.Length >= 28) ? 0.66f : 0.78f);
						object value2 = Convert.ChangeType(num * num2, property4.PropertyType);
						property4.SetValue(val, value2, null);
					}
					catch
					{
					}
				}
			}
		}

		private Button CloneButton(string label, Action onClick)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			Button val = Object.Instantiate<Button>(_template, (Transform)(object)_content);
			((Component)val).gameObject.SetActive(true);
			((Object)((Component)val).gameObject).name = "UKSRR_" + SafeName(label);
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.SetActive(true);
				}
			}
			UiText.Set(((Component)val).gameObject, label);
			FitButtonText(((Component)val).gameObject);
			val.onClick = new ButtonClickedEvent();
			if (onClick != null)
			{
				((UnityEvent)val.onClick).AddListener((UnityAction)delegate
				{
					onClick();
				});
			}
			_created.Add(((Component)val).gameObject);
			ForceRefresh();
			return val;
		}

		private static string SafeName(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "Button";
			}
			return value.Replace(" ", "_").Replace("%", "Pct").Replace("/", "_")
				.Replace("\n", "_");
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			foreach (GameObject item in _hiddenUnderlying)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.SetActive(true);
				}
			}
			_hiddenUnderlying.Clear();
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
		}
	}
	public enum TimerPosition
	{
		TopLeft,
		TopCenter,
		TopRight,
		BottomLeft,
		BottomCenter,
		BottomRight
	}
	public static class RankedSettings
	{
		private static ConfigEntry<bool> _timerEnabled;

		private static ConfigEntry<string> _timerPosition;

		private static ConfigEntry<bool> _progressNotifications;

		private static ConfigEntry<int> _rating;

		private static ConfigEntry<int> _wins;

		private static ConfigEntry<int> _losses;

		private static ConfigEntry<int> _draws;

		private static ConfigEntry<string> _lastRatedMatch;

		public static bool TimerEnabled
		{
			get
			{
				if (_timerEnabled != null)
				{
					return _timerEnabled.Value;
				}
				return true;
			}
			set
			{
				if (_timerEnabled != null)
				{
					_timerEnabled.Value = value;
					((ConfigEntryBase)_timerEnabled).ConfigFile.Save();
				}
			}
		}

		public static TimerPosition TimerPosition
		{
			get
			{
				if (_timerPosition == null)
				{
					return TimerPosition.TopRight;
				}
				if (Enum.TryParse<TimerPosition