Decompiled source of MapVotePlusPlus v1.0.1

MapVotePlusPlus.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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("Rory Durrant")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+450628aed0903647f349fa89b77ffe798cd38220")]
[assembly: AssemblyProduct("MapVotePlusPlus")]
[assembly: AssemblyTitle("MapVotePlusPlus")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/RoryDotGG/REPO-MapVotePlusPlus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MapVote
{
	internal static class Compat
	{
		private static readonly Dictionary<(Type, string, int), MethodInfo?> Methods = new Dictionary<(Type, string, int), MethodInfo>();

		public static object? Call(object target, string name, params object?[] args)
		{
			Type type = target.GetType();
			(Type, string, int) key = (type, name, args.Length);
			if (!Methods.TryGetValue(key, out MethodInfo value))
			{
				value = (Methods[key] = Find(type, name, args.Length));
			}
			if (value == null)
			{
				throw new MissingMethodException(type.Name, name);
			}
			ParameterInfo[] parameters = value.GetParameters();
			object[] array = new object[parameters.Length];
			Array.Copy(args, array, args.Length);
			for (int i = args.Length; i < parameters.Length; i++)
			{
				array[i] = parameters[i].DefaultValue;
			}
			return value.Invoke(target, array);
		}

		private static MethodInfo? Find(Type type, string name, int given)
		{
			return (from m in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
				where m.Name == name
				select (Method: m, Parameters: m.GetParameters()) into x
				where x.Parameters.Length >= given && x.Parameters.Skip(given).All((ParameterInfo p) => p.HasDefaultValue)
				orderby x.Parameters.Length
				select x.Method).FirstOrDefault();
		}
	}
	internal sealed class MapInfo
	{
		public string Name = "";

		public Texture? Art;

		public Rect ArtUv = new Rect(0f, 0f, 1f, 1f);

		public Color Color = Ui.Amber;

		private static readonly Dictionary<string, MapInfo> Cache = new Dictionary<string, MapInfo>();

		public static string DisplayName(string? levelName)
		{
			if (string.IsNullOrEmpty(levelName))
			{
				return "";
			}
			if (levelName == "__random__")
			{
				return "RANDOM";
			}
			foreach (Level item in VoteSession.Pool)
			{
				if (((Object)item).name == levelName)
				{
					return Get(item).Name;
				}
			}
			return Strip(levelName);
		}

		public static MapInfo Get(Level level)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.TryGetValue(((Object)level).name, out MapInfo value))
			{
				return value;
			}
			value = new MapInfo
			{
				Name = NameOf(level),
				Color = ColorOf(level)
			};
			Sprite val = ArtOf(level);
			if (Object.op_Implicit((Object)(object)val))
			{
				value.Art = (Texture?)(object)val.texture;
				Rect textureRect = val.textureRect;
				value.ArtUv = new Rect(((Rect)(ref textureRect)).x / (float)((Texture)val.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)val.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)val.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)val.texture).height);
			}
			Cache[((Object)level).name] = value;
			return value;
		}

		public static Rect Crop(Rect uv, Texture tex, float aspect)
		{
			//IL_0090: 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)
			float num = ((Rect)(ref uv)).width * (float)tex.width;
			float num2 = ((Rect)(ref uv)).height * (float)tex.height;
			if (num / num2 > aspect)
			{
				float num3 = num2 * aspect / (float)tex.width;
				return new Rect(((Rect)(ref uv)).x + (((Rect)(ref uv)).width - num3) / 2f, ((Rect)(ref uv)).y, num3, ((Rect)(ref uv)).height);
			}
			float num4 = num / aspect / (float)tex.height;
			return new Rect(((Rect)(ref uv)).x, ((Rect)(ref uv)).y + (((Rect)(ref uv)).height - num4) / 2f, ((Rect)(ref uv)).width, num4);
		}

		private static string Strip(string name)
		{
			return (name.StartsWith("Level - ", StringComparison.OrdinalIgnoreCase) ? name.Substring(8) : name).Trim().ToUpperInvariant();
		}

		private static string NameOf(Level level)
		{
			try
			{
				string text = (Object.op_Implicit((Object)(object)level.NarrativeNameLocalized) ? (Compat.Call(level.NarrativeNameLocalized, "GetLocalizedString") as string) : null);
				if (!string.IsNullOrWhiteSpace(text))
				{
					return text.Trim().ToUpperInvariant();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("No localized name for " + ((Object)level).name + ": " + ex.Message));
			}
			if (string.IsNullOrWhiteSpace(level.NarrativeName))
			{
				return Strip(((Object)level).name);
			}
			return level.NarrativeName.Trim().ToUpperInvariant();
		}

		private static Sprite? ArtOf(Level level)
		{
			PrefabRef<Sprite>[] array = new PrefabRef<Sprite>[3] { level.LoadingGraphic01, level.LoadingGraphic02, level.LoadingGraphic03 };
			foreach (PrefabRef<Sprite> val in array)
			{
				try
				{
					if (val != null && val.IsValid() && Object.op_Implicit((Object)(object)val.Prefab))
					{
						return val.Prefab;
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogDebug((object)("Loading graphic for " + ((Object)level).name + " unavailable: " + ex.Message));
				}
			}
			return null;
		}

		private static Color ColorOf(Level level)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(level.FogColor, ref num, ref num2, ref num3);
			if (num2 < 0.15f)
			{
				uint num4 = 2166136261u;
				string name = ((Object)level).name;
				foreach (char c in name)
				{
					num4 = (num4 ^ c) * 16777619;
				}
				num = (float)(num4 & 0xFFFF) / 65535f;
			}
			return Color.HSVToRGB(num, Mathf.Max(num2, 0.55f), 0.95f);
		}
	}
	internal sealed class NativeBoard : MonoBehaviour
	{
		private sealed class Row
		{
			public string Choice = "";

			public REPOButton Button;

			public TextMeshProUGUI Voters;

			public TextMeshProUGUI Count;
		}

		private const float LobbyLeft = 380f;

		private const float LobbyTop = 310f;

		private const float LobbyBottom = 23f;

		private const float LobbyWidth = 310f;

		private const float LobbyHeader = 62f;

		private const float Pad = 10f;

		private const float MaxPitch = 24f;

		private const float MaxNameSize = 18f;

		private static readonly List<NativeBoard> Live = new List<NativeBoard>();

		private static REPOPopupPage? _truckPage;

		private MenuPage? _page;

		private bool _lobby;

		private TMP_FontAsset? _font;

		private TextMeshProUGUI _status;

		private readonly List<Row> _rows = new List<Row>();

		private Color _normal = Color.gray;

		private int _seenRevision = -1;

		public static NativeBoard? Active
		{
			get
			{
				MenuPage current = (Object.op_Implicit((Object)(object)MenuManager.instance) ? MenuManager.instance.currentMenuPage : null);
				if (!Object.op_Implicit((Object)(object)current))
				{
					return null;
				}
				return Live.FirstOrDefault((NativeBoard b) => (Object)(object)b._page == (Object)(object)current);
			}
		}

		private void Awake()
		{
			Live.Add(this);
		}

		private void OnDestroy()
		{
			Live.Remove(this);
		}

		public static void BuildLobby(Transform page)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.VoteInLobbyMenu.Value)
			{
				return;
			}
			List<(string, Level)> list = Options();
			float num = Mathf.Min(24f, 215f / (float)list.Count);
			RectTransform val = Ui.Rect("MapVotePlusPlus", page);
			val.pivot = new Vector2(0f, 1f);
			((Transform)val).localPosition = Vector2.op_Implicit(new Vector2(380f, 310f));
			val.sizeDelta = new Vector2(310f, 62f + (float)list.Count * num + 10f);
			((Graphic)Ui.Image("Panel", (Transform)(object)val, Color.black.WithAlpha(0.62f))).rectTransform.Fill();
			NativeBoard nativeBoard = ((Component)val).gameObject.AddComponent<NativeBoard>();
			nativeBoard._page = ((Component)page).GetComponent<MenuPage>();
			nativeBoard._lobby = true;
			nativeBoard._font = MenuFont(page);
			float num2 = 290f;
			((TMP_Text)nativeBoard.Label("Title", (Transform)(object)val, 24f, Ui.Amber, new Vector2(10f, -38f), new Vector2(num2, 28f), (TextAlignmentOptions)4097)).text = "MAP VOTE";
			nativeBoard._status = nativeBoard.Label("Status", (Transform)(object)val, 11f, Ui.Muted, new Vector2(10f, -56f), new Vector2(num2, 16f), (TextAlignmentOptions)4097);
			RectTransform rectTransform = ((Graphic)Ui.Image("Line", (Transform)(object)val, Ui.Amber.WithAlpha(0.8f))).rectTransform;
			rectTransform.pivot = Vector2.zero;
			((Transform)rectTransform).localPosition = Vector2.op_Implicit(new Vector2(10f, -59f));
			rectTransform.sizeDelta = new Vector2(num2, 1.5f);
			float num3 = -62f;
			foreach (var item3 in list)
			{
				string item = item3.Item1;
				Level item2 = item3.Item2;
				num3 -= num;
				nativeBoard.BuildRow((Transform)(object)val, item, item2, new Vector2(10f, num3), num2, num);
			}
			nativeBoard.Refresh();
		}

		public static void ToggleTruckPage()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			if (IsOpen(_truckPage))
			{
				CloseTruckPage();
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)MenuManager.instance) || Object.op_Implicit((Object)(object)MenuManager.instance.currentMenuPage))
				{
					return;
				}
				REPOPopupPage val = MenuAPI.CreateREPOPopupPage("MAP VOTE", (PresetSide)1, false, true, 0f);
				NativeBoard board = ((Component)val).gameObject.AddComponent<NativeBoard>();
				board._page = val.menuPage;
				board._font = MenuFont(((Component)val).transform);
				float width = val.maskRectTransform.sizeDelta.x - 10f;
				val.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform scroller)
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					//IL_001c: Unknown result type (might be due to invalid IL or missing references)
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					board._status = board.Label("Status", scroller, 12f, Ui.Muted, Vector2.zero, new Vector2(width, 20f), (TextAlignmentOptions)4097);
					return ((TMP_Text)board._status).rectTransform;
				}, 0f, 4f);
				foreach (var item in Options())
				{
					var (choice, level) = item;
					val.AddElementToScrollView((ScrollViewBuilderDelegate)((Transform scroller) => board.BuildRow(scroller, choice, level, Vector2.zero, width, 24f)), 0f, 0f);
				}
				val.OpenPage(false);
				board.Refresh();
				_truckPage = val;
			}
		}

		public static void CloseTruckPage()
		{
			if (IsOpen(_truckPage))
			{
				_truckPage.ClosePage(true);
			}
			_truckPage = null;
		}

		private static bool IsOpen(REPOPopupPage? page)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			bool flag = Object.op_Implicit((Object)(object)page);
			if (flag)
			{
				PageState currentPageState = page.menuPage.currentPageState;
				bool flag2 = (((int)currentPageState == 2 || (int)currentPageState == 5) ? true : false);
				flag = !flag2;
			}
			return flag;
		}

		private static List<(string Choice, Level? Level)> Options()
		{
			return new(string, Level)[1] { ("__random__", null) }.Concat(VoteSession.Pool.Select((Level l) => (name: ((Object)l).name, l))).ToList();
		}

		private RectTransform BuildRow(Transform parent, string choice, Level? level, Vector2 position, float width, float pitch)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			//IL_0064: 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_0075: 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_0092: 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_00d2: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Ui.Rect(choice, parent);
			val.pivot = Vector2.zero;
			((Transform)val).localPosition = Vector2.op_Implicit(position);
			val.sizeDelta = new Vector2(width, pitch);
			MapInfo mapInfo = (Object.op_Implicit((Object)(object)level) ? MapInfo.Get(level) : null);
			RectTransform rectTransform = ((Graphic)Ui.Image("Tab", (Transform)(object)val, mapInfo?.Color ?? Ui.Amber)).rectTransform;
			rectTransform.pivot = Vector2.zero;
			((Transform)rectTransform).localPosition = Vector2.op_Implicit(new Vector2(0f, pitch * 0.2f));
			rectTransform.sizeDelta = new Vector2(3f, pitch * 0.6f);
			float num = pitch - 4f;
			float num2 = num * 1.8f;
			Thumbnail(val, mapInfo, new Vector2(6f, 2f), new Vector2(num2, num));
			float num3 = Mathf.Min(18f, pitch * 0.75f);
			float num4 = num2 + 12f;
			float num5 = width * 0.62f;
			REPOButton val2 = MenuAPI.CreateREPOButton(choice, (Action)delegate
			{
				Vote(choice);
			}, (Transform)(object)val, default(Vector2));
			TextMeshProUGUI labelTMP = val2.labelTMP;
			((TMP_Text)labelTMP).fontSize = num3;
			((TMP_Text)labelTMP).text = Fit((TMP_Text)(object)labelTMP, MapInfo.DisplayName(choice), num5 - num4 - 4f);
			((Transform)((REPOElement)val2).rectTransform).localPosition = Vector2.op_Implicit(new Vector2(num4, Mathf.Max(0f, (pitch - ((TMP_Text)labelTMP).GetPreferredValues("Ag").y) / 2f)));
			_normal = val2.menuButton.colorNormal;
			TextMeshProUGUI voters = Label("Voters", (Transform)(object)val, num3 * 0.62f, Ui.Muted, new Vector2(num5, 0f), new Vector2(width - num5 - 34f, pitch), (TextAlignmentOptions)4100);
			TextMeshProUGUI count = Label("Count", (Transform)(object)val, num3, Ui.Text, new Vector2(width - 28f, 0f), new Vector2(28f, pitch), (TextAlignmentOptions)4100);
			_rows.Add(new Row
			{
				Choice = choice,
				Button = val2,
				Voters = voters,
				Count = count
			});
			return val;
		}

		private void Thumbnail(RectTransform row, MapInfo? info, Vector2 position, Vector2 size)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00da: 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)
			RectTransform val = Ui.Rect("Thumb", (Transform)(object)row);
			val.pivot = Vector2.zero;
			((Transform)val).localPosition = Vector2.op_Implicit(position);
			val.sizeDelta = size;
			RawImage val2 = ((Component)val).gameObject.AddComponent<RawImage>();
			((Graphic)val2).raycastTarget = false;
			if (Object.op_Implicit((Object)(object)info?.Art))
			{
				val2.texture = info.Art;
				val2.uvRect = MapInfo.Crop(info.ArtUv, info.Art, size.x / size.y);
				return;
			}
			((Graphic)val2).color = ((info != null) ? Color.Lerp(Ui.Ink, info.Color, 0.55f) : Ui.Amber.WithAlpha(0.22f));
			TextMeshProUGUI obj = Ui.Label("Mark", (Transform)(object)val, size.y * 0.8f, (info != null) ? Ui.Ink.WithAlpha(0.75f) : Ui.Amber, (TextAlignmentOptions)514, (FontStyles)0, _font);
			((TMP_Text)obj).rectTransform.Fill();
			((TMP_Text)obj).text = ((info == null) ? "?" : ((info.Name.Length > 0) ? info.Name.Substring(0, 1) : "?"));
		}

		private static void Vote(string choice)
		{
			if (VoteSession.Phase == Phase.Open)
			{
				VoteSession.Cast(choice);
			}
		}

		public void QuickVote(int index)
		{
			if (index < _rows.Count)
			{
				if (VoteSession.Phase != Phase.Open)
				{
					Ui.Click((MenuClickEffectType)3);
					return;
				}
				VoteSession.Cast(_rows[index].Choice);
				Ui.Click((MenuClickEffectType)1);
			}
		}

		private void Update()
		{
			if (!_lobby && Object.op_Implicit((Object)(object)GameDirector.instance))
			{
				GameDirector.instance.disableEscMenuTimer = 0.2f;
			}
			Refresh();
		}

		private void Refresh()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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)
			Phase phase = VoteSession.Phase;
			bool flag = phase == Phase.Open;
			string text = (Object.op_Implicit((Object)(object)VoteUi.Instance) ? VoteUi.Instance.RevealedWinner : VoteSession.Winner);
			string myVote = VoteSession.MyVote;
			((TMP_Text)_status).text = Status(phase, text);
			foreach (Row row2 in _rows)
			{
				bool flag2 = (flag ? (row2.Choice == myVote) : (row2.Choice == text));
				row2.Button.menuButton.colorNormal = (flag2 ? Ui.Amber : ((!flag && text != null) ? _normal.WithAlpha(0.45f) : _normal));
			}
			if (VoteSession.Revision == _seenRevision)
			{
				return;
			}
			_seenRevision = VoteSession.Revision;
			foreach (Row row in _rows)
			{
				List<int> list = (from v in VoteSession.Votes
					where v.Value == row.Choice
					select v.Key into a
					orderby a
					select a).ToList();
				((TMP_Text)row.Count).text = ((list.Count > 0) ? list.Count.ToString() : "");
				((TMP_Text)row.Voters).text = string.Join(" ", list.Select((int a) => "<color=#" + Ui.HexOf(Ui.PlayerColor(a)) + ">" + VoteSession.PlayerName(a).ToUpperInvariant() + "</color>"));
			}
		}

		private string Status(Phase phase, string? winner)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			string text = $"{VoteSession.Votes.Count}/{VoteSession.PlayerCount} VOTED";
			float secondsLeft = VoteSession.SecondsLeft;
			if (phase == Phase.Open)
			{
				if (secondsLeft >= 0f)
				{
					return $"{text}   CLOSES IN {Mathf.CeilToInt(secondsLeft)}S";
				}
				if (_lobby)
				{
					return text + "   ROLLS WHEN THE HOST STARTS";
				}
				return text + "   NO VOTES = RANDOM";
			}
			if (winner == null)
			{
				if (phase == Phase.Revealing)
				{
					return "ROLLING...";
				}
				return "WAITING FOR HOST";
			}
			return "NEXT MAP  <color=#" + Ui.HexOf(Ui.Amber) + ">" + MapInfo.DisplayName(winner) + "</color>";
		}

		private static TMP_FontAsset? MenuFont(Transform page)
		{
			MenuButton componentInChildren = ((Component)page).GetComponentInChildren<MenuButton>(true);
			TextMeshProUGUI val = (Object.op_Implicit((Object)(object)componentInChildren) ? ((Component)componentInChildren).GetComponentInChildren<TextMeshProUGUI>(true) : ((Component)page).GetComponentInChildren<TextMeshProUGUI>(true));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return ((TMP_Text)val).font;
		}

		private TextMeshProUGUI Label(string name, Transform parent, float size, Color color, Vector2 position, Vector2 box, TextAlignmentOptions align = (TextAlignmentOptions)4097)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = Ui.Label(name, parent, size, color, align, (FontStyles)0, _font);
			RectTransform rectTransform = ((TMP_Text)obj).rectTransform;
			rectTransform.pivot = Vector2.zero;
			((Transform)rectTransform).localPosition = Vector2.op_Implicit(position);
			rectTransform.sizeDelta = box;
			return obj;
		}

		private static string Fit(TMP_Text label, string text, float maxWidth)
		{
			//IL_0002: 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)
			if (label.GetPreferredValues(text).x <= maxWidth)
			{
				return text;
			}
			for (int num = text.Length - 1; num > 1; num--)
			{
				string text2 = text.Substring(0, num).TrimEnd() + "...";
				if (label.GetPreferredValues(text2).x <= maxWidth)
				{
					return text2;
				}
			}
			return text;
		}
	}
	[BepInPlugin("RoryDotGG.MapVotePlusPlus", "MapVote++", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static BuilderDelegate <0>__BuildLobby;
		}

		public const string Guid = "RoryDotGG.MapVotePlusPlus";

		public const string Name = "MapVote++";

		public const string Version = "1.0.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<Key> ToggleKey;

		internal static ConfigEntry<int> VoteSeconds;

		internal static ConfigEntry<bool> VoteInLobbyMenu;

		internal static ConfigEntry<bool> VoteInTruck;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00b4: 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_00bf: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ToggleKey", (Key)27, "Opens and closes the map vote in the truck. In the lobby it's always on screen.");
			VoteSeconds = ((BaseUnityPlugin)this).Config.Bind<int>("Voting", "VoteSeconds", 25, new ConfigDescription("Truck only: how many seconds the vote stays open after the first vote. It ends early once everyone has voted. The lobby vote stays open until the host presses Start Game. The host's value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 120), Array.Empty<object>()));
			VoteInLobbyMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("Voting", "VoteInLobbyMenu", true, "Show the vote in the pre-game lobby menu.");
			VoteInTruck = ((BaseUnityPlugin)this).Config.Bind<bool>("Voting", "VoteInTruck", true, "Show the vote in the truck between levels.");
			VoteSession.RegisterEvents();
			object obj = <>O.<0>__BuildLobby;
			if (obj == null)
			{
				BuilderDelegate val = NativeBoard.BuildLobby;
				<>O.<0>__BuildLobby = val;
				obj = (object)val;
			}
			MenuAPI.AddElementToLobbyMenu((BuilderDelegate)obj);
			new Harmony("RoryDotGG.MapVotePlusPlus").PatchAll(typeof(Patches));
			GameObject val2 = new GameObject("MapVotePlusPlus")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val2);
			val2.AddComponent<VoteUi>();
			Log.LogInfo((object)"MapVote++ 1.0.1 loaded");
		}
	}
	internal static class Patches
	{
		[HarmonyPatch(typeof(RunManager), "SetRunLevel")]
		[HarmonyPrefix]
		private static bool SetRunLevel(RunManager __instance)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return true;
			}
			Level val = VoteSession.ConsumeWinner(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			__instance.levelCurrent = val;
			__instance.previousRunLevel = val;
			return false;
		}

		[HarmonyPatch(typeof(MenuPageLobby), "ButtonStart")]
		[HarmonyPrefix]
		private static bool LobbyStart(MenuPageLobby __instance)
		{
			return VoteSession.OnLobbyStart(__instance);
		}

		[HarmonyPatch(typeof(TruckScreenText), "ChatMessageLobby")]
		[HarmonyPostfix]
		private static void TruckSent()
		{
			VoteSession.OnTruckSent();
		}

		[HarmonyPatch(typeof(TruckScreenText), "GotoNextLevel")]
		[HarmonyPrefix]
		private static bool TruckDepart(TruckScreenText __instance)
		{
			return VoteSession.OnTruckDepart(__instance);
		}
	}
	internal static class Ui
	{
		public static readonly Color Panel = Hex("0D0D10F2");

		public static readonly Color Text = Hex("F3EEE4");

		public static readonly Color Muted = Hex("8E887E");

		public static readonly Color Amber = Hex("FFB31A");

		public static readonly Color Ink = Hex("141414");

		private static readonly Color[] PlayerColors = (Color[])(object)new Color[8]
		{
			Hex("FFB31A"),
			Hex("4FD1C5"),
			Hex("F56565"),
			Hex("9F7AEA"),
			Hex("68D391"),
			Hex("63B3ED"),
			Hex("F687B3"),
			Hex("F6E05E")
		};

		private static Sprite? _rounded;

		private static Sprite? _roundedSmall;

		private static Sprite? _fade;

		private static TMP_FontAsset? _font;

		private static readonly List<TextMeshProUGUI> Texts = new List<TextMeshProUGUI>();

		public static Sprite Rounded => _rounded ?? (_rounded = MakeRounded(64, 14));

		public static Sprite RoundedSmall => _roundedSmall ?? (_roundedSmall = MakeRounded(32, 6));

		public static Sprite FadeRight => _fade ?? (_fade = MakeFade(64));

		public static bool FontReady => Object.op_Implicit((Object)(object)_font);

		public static Color Hex(string hex)
		{
			//IL_001a: 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)
			Color result = default(Color);
			if (!ColorUtility.TryParseHtmlString("#" + hex, ref result))
			{
				return Color.magenta;
			}
			return result;
		}

		public static string HexOf(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(c);
		}

		public static Color WithAlpha(this Color c, float a)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new Color(c.r, c.g, c.b, a);
		}

		public static Color PlayerColor(int actor)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return PlayerColors[(actor % PlayerColors.Length + PlayerColors.Length) % PlayerColors.Length];
		}

		public static float Damp(float current, float target, float speed)
		{
			return Mathf.Lerp(current, target, 1f - Mathf.Exp((0f - speed) * Time.unscaledDeltaTime));
		}

		public static bool KeyDown(Key key)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (Keyboard.current != null && (int)key != 0)
			{
				return ((ButtonControl)Keyboard.current[key]).wasPressedThisFrame;
			}
			return false;
		}

		public static RectTransform Rect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)parent).gameObject.layer
			}.transform;
			((Transform)val).SetParent(parent, false);
			return val;
		}

		public static Image Image(string name, Transform parent, Color color, Sprite? sprite = null)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Image val = ((Component)Rect(name, parent)).gameObject.AddComponent<Image>();
			((Graphic)val).color = color;
			((Graphic)val).raycastTarget = false;
			if (Object.op_Implicit((Object)(object)sprite))
			{
				val.sprite = sprite;
				val.type = (Type)((sprite.border != Vector4.zero) ? 1 : 0);
			}
			return val;
		}

		public static TextMeshProUGUI Label(string name, Transform parent, float size, Color color, TextAlignmentOptions align = (TextAlignmentOptions)4097, FontStyles style = (FontStyles)1, TMP_FontAsset? font = null)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_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_0055: Expected I4, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)Rect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((TMP_Text)val).fontStyle = style;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).richText = true;
			int num = align & 0xFF00;
			((TMP_Text)val).margin = new Vector4(0f, (num == 256) ? 0f : (0f - size), 0f, (num == 1024) ? 0f : (0f - size));
			if (Object.op_Implicit((Object)(object)font))
			{
				((TMP_Text)val).font = font;
				return val;
			}
			if (Object.op_Implicit((Object)(object)_font))
			{
				((TMP_Text)val).font = _font;
			}
			if (Texts.Count > 256)
			{
				Texts.RemoveAll((TextMeshProUGUI t) => !Object.op_Implicit((Object)(object)t));
			}
			Texts.Add(val);
			return val;
		}

		public static RectTransform Place(this RectTransform r, Vector2 anchor, Vector2 pos, Vector2 size)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = (r.pivot = anchor);
			Vector2 anchorMin = (r.anchorMax = val);
			r.anchorMin = anchorMin;
			r.anchoredPosition = pos;
			r.sizeDelta = size;
			return r;
		}

		public static RectTransform Fill(this RectTransform r, float l = 0f, float t = 0f, float rt = 0f, float b = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			r.anchorMin = Vector2.zero;
			r.anchorMax = Vector2.one;
			r.pivot = new Vector2(0.5f, 0.5f);
			r.offsetMin = new Vector2(l, b);
			r.offsetMax = new Vector2(0f - rt, 0f - t);
			return r;
		}

		public static void TryResolveFont(Transform ours)
		{
			if (Object.op_Implicit((Object)(object)_font))
			{
				return;
			}
			TMP_FontAsset val = null;
			int num = -1;
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val2 in array)
			{
				if (Object.op_Implicit((Object)(object)((TMP_Text)val2).font) && !((TMP_Text)val2).transform.IsChildOf(ours))
				{
					int num2 = ((!Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<HUDCanvas>()) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<MenuPage>())) ? 1 : 2);
					if (num2 > num)
					{
						val = ((TMP_Text)val2).font;
						num = num2;
					}
				}
			}
			if (val == null)
			{
				val = TMP_Settings.defaultFontAsset;
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			_font = val;
			Texts.RemoveAll((TextMeshProUGUI t) => !Object.op_Implicit((Object)(object)t));
			foreach (TextMeshProUGUI text in Texts)
			{
				((TMP_Text)text).font = _font;
			}
		}

		public static void Sound(Action<MenuManager> play)
		{
			try
			{
				if (Object.op_Implicit((Object)(object)MenuManager.instance))
				{
					play(MenuManager.instance);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Menu sound failed: " + ex.Message));
			}
		}

		public static void Click(MenuClickEffectType type, float pitch = -1f, float volume = -1f)
		{
			//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)
			Sound(delegate(MenuManager m)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				Compat.Call(m, "MenuEffectClick", type, null, pitch, volume, true);
			});
		}

		public static void Tick(float pitch = 1f)
		{
			Click((MenuClickEffectType)4, pitch, 0.6f);
		}

		private static Sprite Finish(Texture2D tex, Vector4 border)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			((Texture)tex).wrapMode = (TextureWrapMode)1;
			((Texture)tex).filterMode = (FilterMode)1;
			tex.Apply(false, true);
			((Object)tex).hideFlags = (HideFlags)61;
			Sprite obj = Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, border);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static Sprite MakeRounded(int size, int radius)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = Mathf.Max(Mathf.Abs((float)j + 0.5f - (float)size / 2f) - ((float)size / 2f - (float)radius), 0f);
					float num2 = Mathf.Max(Mathf.Abs((float)i + 0.5f - (float)size / 2f) - ((float)size / 2f - (float)radius), 0f);
					float num3 = Mathf.Clamp01((float)radius - Mathf.Sqrt(num * num + num2 * num2) + 0.5f);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num3));
				}
			}
			return Finish(val, new Vector4((float)radius, (float)radius, (float)radius, (float)radius));
		}

		private static Sprite MakeFade(int width)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_003a: 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)
			Texture2D val = new Texture2D(width, 1, (TextureFormat)4, false);
			for (int i = 0; i < width; i++)
			{
				val.SetPixel(i, 0, new Color(1f, 1f, 1f, Mathf.SmoothStep(0f, 1f, (float)i / ((float)width - 1f))));
			}
			return Finish(val, Vector4.zero);
		}
	}
	public static class VoteLogic
	{
		public const string RandomChoice = "__random__";

		public static List<string> RandomPool(IReadOnlyList<string> pool, string? previous)
		{
			List<string> list = pool.Where((string p) => p != previous).ToList();
			if (list.Count <= 0)
			{
				return pool.ToList();
			}
			return list;
		}

		public static List<string> ValidBallots(IReadOnlyList<string> pool, IEnumerable<string> ballots)
		{
			return ballots.Where((string b) => b == "__random__" || pool.Contains(b)).ToList();
		}

		public static Dictionary<string, float> Odds(IReadOnlyList<string> pool, IEnumerable<string> ballots, string? previous)
		{
			Dictionary<string, float> dictionary = pool.ToDictionary((string p) => p, (string _) => 0f);
			if (pool.Count == 0)
			{
				return dictionary;
			}
			List<string> list = ValidBallots(pool, ballots);
			List<string> list2 = RandomPool(pool, previous);
			if (list.Count == 0)
			{
				foreach (string item in list2)
				{
					dictionary[item] = 1f / (float)list2.Count;
				}
				dictionary["__random__"] = 1f;
				return dictionary;
			}
			float num = 1f / (float)list.Count;
			int num2 = 0;
			foreach (string item2 in list)
			{
				if (item2 == "__random__")
				{
					num2++;
				}
				else
				{
					dictionary[item2] += num;
				}
			}
			foreach (string item3 in list2)
			{
				dictionary[item3] += (float)num2 * num / (float)list2.Count;
			}
			dictionary["__random__"] = (float)num2 * num;
			return dictionary;
		}

		public static string? Resolve(IReadOnlyList<string> pool, IEnumerable<string> ballots, string? previous, Random rng)
		{
			if (pool.Count == 0)
			{
				return null;
			}
			List<string> list = ValidBallots(pool, ballots);
			string text = ((list.Count == 0) ? "__random__" : list[rng.Next(list.Count)]);
			if (text != "__random__")
			{
				return text;
			}
			List<string> list2 = RandomPool(pool, previous);
			return list2[rng.Next(list2.Count)];
		}
	}
	internal enum Phase
	{
		Closed,
		Open,
		Revealing,
		Locked
	}
	internal enum VoteContext
	{
		None,
		LobbyMenu,
		Truck
	}
	internal static class VoteSession
	{
		public const float RevealSeconds = 4.6f;

		private const float AllVotedSeconds = 3f;

		public static readonly Dictionary<int, string> Votes = new Dictionary<int, string>();

		private static float _deadline = -1f;

		private static VoteContext _lastContext;

		private static Action? _afterReveal;

		private static readonly Random Rng = new Random();

		private static NetworkedEvent _cast = null;

		private static NetworkedEvent _state = null;

		private static NetworkedEvent _syncRequest = null;

		public static Phase Phase { get; private set; }

		public static string? Winner { get; private set; }

		public static int Revision { get; private set; }

		public static float SecondsLeft
		{
			get
			{
				if (!(_deadline < 0f))
				{
					return Mathf.Max(0f, _deadline - Time.unscaledTime);
				}
				return -1f;
			}
		}

		public static bool IsHost => SemiFunc.IsMasterClientOrSingleplayer();

		public static int LocalActor
		{
			get
			{
				if (!SemiFunc.IsMultiplayer())
				{
					return 1;
				}
				return PhotonNetwork.LocalPlayer.ActorNumber;
			}
		}

		public static int PlayerCount
		{
			get
			{
				if (!SemiFunc.IsMultiplayer())
				{
					return 1;
				}
				Room currentRoom = PhotonNetwork.CurrentRoom;
				if (currentRoom == null)
				{
					return 1;
				}
				return currentRoom.PlayerCount;
			}
		}

		public static string? MyVote
		{
			get
			{
				if (!Votes.TryGetValue(LocalActor, out string value))
				{
					return null;
				}
				return value;
			}
		}

		public static List<Level> Pool => Levels.AllLevels.Where((Level l) => Object.op_Implicit((Object)(object)l)).ToList();

		public static List<string> PoolNames => Pool.Select((Level l) => ((Object)l).name).ToList();

		public static string? PreviousLevel
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)RunManager.instance) || !Object.op_Implicit((Object)(object)RunManager.instance.previousRunLevel))
				{
					return null;
				}
				return ((Object)RunManager.instance.previousRunLevel).name;
			}
		}

		public static VoteContext Context
		{
			get
			{
				RunManager instance = RunManager.instance;
				if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.levelCurrent))
				{
					return VoteContext.None;
				}
				if ((Object)(object)instance.levelCurrent == (Object)(object)instance.levelLobbyMenu && Plugin.VoteInLobbyMenu.Value)
				{
					return VoteContext.LobbyMenu;
				}
				if ((Object)(object)instance.levelCurrent == (Object)(object)instance.levelLobby && Plugin.VoteInTruck.Value && InTruck(instance))
				{
					return VoteContext.Truck;
				}
				return VoteContext.None;
			}
		}

		private static bool InTruck(RunManager rm)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			LevelGenerator instance = LevelGenerator.Instance;
			GameDirector instance2 = GameDirector.instance;
			bool flag = Object.op_Implicit((Object)(object)instance) && instance.Generated && (Object)(object)instance.Level == (Object)(object)rm.levelLobby && Object.op_Implicit((Object)(object)instance2);
			if (flag)
			{
				gameState currentState = instance2.currentState;
				bool flag2 = (((int)currentState == 2 || (int)currentState == 7) ? true : false);
				flag = flag2;
			}
			return flag;
		}

		public static void RegisterEvents()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			_cast = new NetworkedEvent("MapVotePlusPlus.Cast", (Action<EventData>)OnCast);
			_state = new NetworkedEvent("MapVotePlusPlus.State", (Action<EventData>)OnState);
			_syncRequest = new NetworkedEvent("MapVotePlusPlus.SyncRequest", (Action<EventData>)delegate
			{
				if (IsHost)
				{
					Broadcast();
				}
			});
		}

		public static void Tick()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			RunManager instance = RunManager.instance;
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.levelCurrent) && (Object)(object)instance.levelCurrent == (Object)(object)instance.levelMainMenu)
			{
				if (Phase != Phase.Closed || Winner != null)
				{
					ResetLocal();
				}
				_lastContext = VoteContext.None;
				return;
			}
			VoteContext context = Context;
			if (context != _lastContext)
			{
				_lastContext = context;
				if (context != VoteContext.None)
				{
					if (!IsHost)
					{
						_syncRequest.RaiseEvent((object)null, NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable);
					}
					else if (Phase == Phase.Closed)
					{
						Open();
					}
					else
					{
						Broadcast();
					}
				}
			}
			if (IsHost && context != VoteContext.None && !(_deadline < 0f) && !(Time.unscaledTime < _deadline))
			{
				if (Phase == Phase.Open)
				{
					BeginReveal();
				}
				else if (Phase == Phase.Revealing)
				{
					Lock();
				}
			}
		}

		public static void Cast(string choice)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (Phase == Phase.Open)
			{
				if (MyVote == choice)
				{
					choice = "";
				}
				if (choice == "")
				{
					Votes.Remove(LocalActor);
				}
				else
				{
					Votes[LocalActor] = choice;
				}
				Revision++;
				_cast.RaiseEvent((object)choice, NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable);
			}
		}

		public static void ClearMyVote()
		{
			if (MyVote != null)
			{
				Cast(MyVote);
			}
		}

		private static void OnCast(EventData e)
		{
			if (!IsHost || Phase != Phase.Open)
			{
				return;
			}
			string text = (e.CustomData as string) ?? "";
			if (text == "")
			{
				Votes.Remove(e.Sender);
			}
			else
			{
				if (!(text == "__random__") && !PoolNames.Contains(text))
				{
					return;
				}
				Votes[e.Sender] = text;
			}
			if (Context == VoteContext.Truck)
			{
				float unscaledTime = Time.unscaledTime;
				if (_deadline < 0f && Votes.Count > 0)
				{
					_deadline = unscaledTime + (float)Plugin.VoteSeconds.Value;
				}
				if (Votes.Count >= PlayerCount && _deadline > unscaledTime + 3f)
				{
					_deadline = unscaledTime + 3f;
				}
			}
			Broadcast();
		}

		private static void OnState(EventData e)
		{
			if (!IsHost && e.CustomData is object[] array && array.Length == 5)
			{
				Phase = (Phase)(int)array[0];
				float num = (float)array[1];
				_deadline = ((num < 0f) ? (-1f) : (Time.unscaledTime + num));
				Votes.Clear();
				int[] array2 = (int[])array[2];
				string[] array3 = (string[])array[3];
				for (int i = 0; i < array2.Length && i < array3.Length; i++)
				{
					Votes[array2[i]] = array3[i];
				}
				string text = (string)array[4];
				Winner = ((text != null && text.Length > 0) ? text : null);
				Revision++;
			}
		}

		private static void Broadcast()
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMultiplayer() && PhotonNetwork.CurrentRoom != null)
			{
				foreach (int item in Votes.Keys.Where((int a) => PhotonNetwork.CurrentRoom.GetPlayer(a, false) == null).ToList())
				{
					Votes.Remove(item);
				}
			}
			Revision++;
			object[] array = new object[5]
			{
				(int)Phase,
				SecondsLeft,
				Votes.Keys.ToArray(),
				Votes.Values.ToArray(),
				Winner ?? ""
			};
			_state.RaiseEvent((object)array, NetworkingEvents.RaiseOthers, SendOptions.SendReliable);
		}

		private static void Open()
		{
			Phase = Phase.Open;
			Votes.Clear();
			Winner = null;
			_deadline = -1f;
			Broadcast();
		}

		private static void BeginReveal()
		{
			Winner = VoteLogic.Resolve(PoolNames, Votes.Values, PreviousLevel, Rng);
			Phase = Phase.Revealing;
			_deadline = Time.unscaledTime + 4.6f;
			Plugin.Log.LogInfo((object)$"Vote closed with {Votes.Count} ballot(s); next map: {Winner}");
			Broadcast();
		}

		private static void Lock()
		{
			Phase = Phase.Locked;
			_deadline = -1f;
			Broadcast();
			Action? afterReveal = _afterReveal;
			_afterReveal = null;
			afterReveal?.Invoke();
		}

		private static void ResetLocal()
		{
			Phase = Phase.Closed;
			Votes.Clear();
			Winner = null;
			_deadline = -1f;
			_afterReveal = null;
			Revision++;
		}

		public static bool OnLobbyStart(MenuPageLobby lobby)
		{
			if (!IsHost)
			{
				return true;
			}
			if (lobby.joiningPlayer)
			{
				return true;
			}
			return HoldForReveal(delegate
			{
				if (Object.op_Implicit((Object)(object)lobby))
				{
					lobby.ButtonStart();
				}
			});
		}

		public static void OnTruckSent()
		{
			if (IsHost && Context == VoteContext.Truck && Phase == Phase.Open)
			{
				BeginReveal();
			}
		}

		public static bool OnTruckDepart(TruckScreenText screen)
		{
			if (!IsHost || Context != VoteContext.Truck)
			{
				return true;
			}
			return HoldForReveal(delegate
			{
				if (Object.op_Implicit((Object)(object)screen))
				{
					screen.GotoNextLevel();
				}
			});
		}

		private static bool HoldForReveal(Action resume)
		{
			Phase phase = Phase;
			if ((uint)(phase - 1) > 1u)
			{
				return true;
			}
			_afterReveal = resume;
			if (Phase == Phase.Open)
			{
				BeginReveal();
			}
			return false;
		}

		public static Level? ConsumeWinner(RunManager rm)
		{
			Phase phase = Phase;
			string text;
			if (phase != Phase.Open)
			{
				if ((uint)(phase - 2) > 1u)
				{
					goto IL_004c;
				}
				text = Winner;
			}
			else
			{
				if (Votes.Count <= 0)
				{
					goto IL_004c;
				}
				text = VoteLogic.Resolve(PoolNames, Votes.Values, PreviousLevel, Rng);
			}
			goto IL_004e;
			IL_004c:
			text = null;
			goto IL_004e;
			IL_004e:
			string name = text;
			if (Phase == Phase.Closed && name == null)
			{
				return null;
			}
			Level val = ((name == null) ? null : ((IEnumerable<Level>)rm.levels).FirstOrDefault((Func<Level, bool>)((Level l) => Object.op_Implicit((Object)(object)l) && ((Object)l).name == name)));
			Phase = Phase.Closed;
			Votes.Clear();
			Winner = (Object.op_Implicit((Object)(object)val) ? ((Object)val).name : null);
			_deadline = -1f;
			_afterReveal = null;
			Broadcast();
			if (Object.op_Implicit((Object)(object)val))
			{
				Plugin.Log.LogInfo((object)("Loading voted map " + ((Object)val).name));
			}
			return val;
		}

		public static string PlayerName(int actor)
		{
			if (!SemiFunc.IsMultiplayer())
			{
				PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
				if (!Object.op_Implicit((Object)(object)val))
				{
					return "You";
				}
				return SemiFunc.PlayerGetName(val);
			}
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.photonView) && item.photonView.OwnerActorNr == actor)
				{
					return item.playerName;
				}
			}
			Room currentRoom = PhotonNetwork.CurrentRoom;
			object obj;
			if (currentRoom == null)
			{
				obj = null;
			}
			else
			{
				Player player = currentRoom.GetPlayer(actor, false);
				obj = ((player != null) ? player.NickName : null);
			}
			if (obj == null)
			{
				obj = "?";
			}
			return (string)obj;
		}
	}
	internal sealed class VoteUi : MonoBehaviour
	{
		private const float CellWidth = 340f;

		private const float SpinSeconds = 3.3f;

		private const float HoldSeconds = 2.8f;

		private const float WindowWidth = 1080f;

		private const float WindowHeight = 150f;

		private RectTransform _root;

		private Canvas _canvas;

		private RectTransform _chip;

		private CanvasGroup _chipGroup;

		private Image _chipBorder;

		private TextMeshProUGUI _chipKey;

		private TextMeshProUGUI _chipTitle;

		private TextMeshProUGUI _chipSub;

		private float _chipT;

		private RectTransform _reveal;

		private RectTransform _revealBody;

		private RectTransform _window;

		private RectTransform _reel;

		private CanvasGroup _revealGroup;

		private Image _revealCenter;

		private TextMeshProUGUI _revealTitle;

		private readonly List<TextMeshProUGUI> _cells = new List<TextMeshProUGUI>();

		private string? _reelFor;

		private int _reelWinner;

		private int _lastTickCell;

		private float _reelStart = -999f;

		private float _punch;

		private bool _landed;

		private VoteContext _context;

		private VoteContext _lastContext;

		private int _seenRevision = -1;

		private float _fontRetry;

		public static VoteUi? Instance { get; private set; }

		public string? RevealedWinner
		{
			get
			{
				if (VoteSession.Phase != Phase.Revealing || (_landed && !(_reelFor != VoteSession.Winner)))
				{
					return VoteSession.Winner;
				}
				return null;
			}
		}

		private void Awake()
		{
			Instance = this;
			Build();
		}

		private void Update()
		{
			VoteSession.Tick();
			if (!Ui.FontReady && (_fontRetry -= Time.unscaledDeltaTime) <= 0f)
			{
				Ui.TryResolveFont((Transform)(object)_root);
				_fontRetry = 1f;
			}
			_context = VoteSession.Context;
			if (_context != _lastContext)
			{
				OnContextChanged();
			}
			if (VoteSession.Revision != _seenRevision)
			{
				OnStateChanged();
			}
			HandleInput();
			bool flag = (_context != VoteContext.None || _revealGroup.alpha > 0.01f) && Ui.FontReady && !GameMenuBlocking();
			((Behaviour)_canvas).enabled = flag;
			if (flag)
			{
				AnimateChip();
				AnimateReveal();
			}
		}

		private bool GameMenuBlocking()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			MenuPage val = (Object.op_Implicit((Object)(object)MenuManager.instance) ? MenuManager.instance.currentMenuPage : null);
			if (_context != VoteContext.LobbyMenu)
			{
				return Object.op_Implicit((Object)(object)val);
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				return (int)val.menuPageIndex != 8;
			}
			return true;
		}

		private void OnContextChanged()
		{
			_lastContext = _context;
			_reelFor = null;
			_reelStart = -999f;
			_seenRevision = -1;
			if (_context != VoteContext.Truck)
			{
				NativeBoard.CloseTruckPage();
			}
		}

		private void OnStateChanged()
		{
			_seenRevision = VoteSession.Revision;
			if (VoteSession.Phase == Phase.Revealing && VoteSession.Winner != null && _reelFor != VoteSession.Winner)
			{
				StartReel(VoteSession.Winner, VoteLogic.Odds(VoteSession.PoolNames, VoteSession.Votes.Values, VoteSession.PreviousLevel));
			}
		}

		private void HandleInput()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (_context == VoteContext.None || !SemiFunc.NoTextInputsActive() || (Object.op_Implicit((Object)(object)ChatManager.instance) && ChatManager.instance.chatActive))
			{
				return;
			}
			if (_context == VoteContext.Truck && Ui.KeyDown(Plugin.ToggleKey.Value))
			{
				NativeBoard.ToggleTruckPage();
			}
			NativeBoard active = NativeBoard.Active;
			if (!Object.op_Implicit((Object)(object)active))
			{
				return;
			}
			if (Ui.KeyDown((Key)32))
			{
				active.QuickVote(0);
			}
			for (int i = 0; i < 9; i++)
			{
				if (Ui.KeyDown((Key)(41 + i)) || Ui.KeyDown((Key)(85 + i)))
				{
					active.QuickVote(i + 1);
				}
			}
		}

		private void AnimateChip()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0254: Unknown result type (might be due to invalid IL or missing references)
			Phase phase = VoteSession.Phase;
			bool flag = phase == Phase.Open && VoteSession.MyVote == null;
			bool flag2 = _context == VoteContext.Truck && (_reelStart < 0f || Time.unscaledTime - _reelStart > 6.1f);
			_chipT = Ui.Damp(_chipT, flag2 ? 1f : 0f, 12f);
			_chipGroup.alpha = _chipT;
			_chip.anchoredPosition = new Vector2(-36f + (1f - _chipT) * 40f, 36f);
			if (!(_chipT < 0.01f))
			{
				((TMP_Text)_chipKey).text = KeyName();
				float secondsLeft = VoteSession.SecondsLeft;
				string text = string.Format("{0}/{1} VOTED{2}", VoteSession.Votes.Count, VoteSession.PlayerCount, (secondsLeft >= 0f) ? $"  /  {Mathf.CeilToInt(secondsLeft)}S" : "");
				string text2 = "<color=#" + Ui.HexOf(Ui.Muted) + ">";
				string text3 = "<color=#" + Ui.HexOf(Ui.Amber) + ">";
				switch (phase)
				{
				case Phase.Open:
					((TMP_Text)_chipTitle).text = (flag ? "VOTE FOR THE NEXT MAP" : ("YOU PICKED " + text3 + MapInfo.DisplayName(VoteSession.MyVote) + "</color>"));
					((TMP_Text)_chipSub).text = text2 + text + "</color>";
					break;
				case Phase.Revealing:
					((TMP_Text)_chipTitle).text = "ROLLING...";
					((TMP_Text)_chipSub).text = text2 + "NEXT MAP INCOMING</color>";
					break;
				default:
					((TMP_Text)_chipTitle).text = ((VoteSession.Winner != null) ? "NEXT MAP" : "MAP VOTE");
					((TMP_Text)_chipSub).text = ((VoteSession.Winner != null) ? (text3 + MapInfo.DisplayName(VoteSession.Winner) + "</color>") : (text2 + "RANDOM MAP</color>"));
					break;
				}
				float a = (flag ? (0.45f + 0.45f * Mathf.Sin(Time.unscaledTime * 3.2f)) : 0.15f);
				((Graphic)_chipBorder).color = Ui.Amber.WithAlpha(a);
			}
		}

		private unsafe string KeyName()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Key value = Plugin.ToggleKey.Value;
			Keyboard current = Keyboard.current;
			KeyControl obj = ((current != null) ? current[value] : null);
			string text = ((obj != null) ? ((InputControl)obj).displayName : null);
			return ((text != null && text.Length > 0) ? text : ((object)(*(Key*)(&value))/*cast due to .constrained prefix*/).ToString()).ToUpperInvariant();
		}

		private void StartReel(string winner, Dictionary<string, float> odds)
		{
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			_reelFor = winner;
			_landed = false;
			_lastTickCell = 0;
			float secondsLeft = VoteSession.SecondsLeft;
			_reelStart = Time.unscaledTime - ((secondsLeft >= 0f) ? (4.6f - secondsLeft) : 0f);
			if (_context == VoteContext.Truck)
			{
				NativeBoard.CloseTruckPage();
			}
			float value;
			List<string> list = VoteSession.PoolNames.Where((string n) => odds.TryGetValue(n, out value) && value > 0f).ToList();
			if (list.Count == 0)
			{
				list = VoteSession.PoolNames;
			}
			_reelWinner = 30;
			foreach (TextMeshProUGUI cell in _cells)
			{
				Object.Destroy((Object)(object)((Component)cell).gameObject);
			}
			_cells.Clear();
			string avoid = null;
			for (int num = 0; num < 34; num++)
			{
				string text = ((num == _reelWinner) ? winner : PickWeighted(list, odds, avoid));
				avoid = text;
				TextMeshProUGUI val = Ui.Label("Cell", (Transform)(object)_reel, 48f, Ui.Text, (TextAlignmentOptions)514, (FontStyles)1);
				((TMP_Text)val).rectTransform.Place(new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(316f, 88f));
				((TMP_Text)val).text = MapInfo.DisplayName(text);
				((TMP_Text)val).enableAutoSizing = true;
				((TMP_Text)val).fontSizeMin = 24f;
				((TMP_Text)val).fontSizeMax = 48f;
				_cells.Add(val);
			}
			((TMP_Text)_revealTitle).text = "NEXT MAP";
			((Graphic)_revealTitle).color = Ui.Muted;
			Ui.Sound(delegate(MenuManager m)
			{
				m.MenuEffectPopUpOpen();
			});
		}

		private static string PickWeighted(List<string> names, Dictionary<string, float> odds, string? avoid)
		{
			for (int i = 0; i < 4; i++)
			{
				float value2;
				float num = Random.value * names.Sum((string n) => (!odds.TryGetValue(n, out value2)) ? 0.05f : Mathf.Max(value2, 0.05f));
				foreach (string name in names)
				{
					num -= (odds.TryGetValue(name, out var value) ? Mathf.Max(value, 0.05f) : 0.05f);
					if (num <= 0f && (name != avoid || names.Count == 1))
					{
						return name;
					}
				}
			}
			return names[Random.Range(0, names.Count)];
		}

		private void AnimateReveal()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: 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_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.unscaledTime - _reelStart;
			bool flag = _reelFor != null && num < 6.1f;
			float speed = (flag ? 14f : ((_context == VoteContext.None) ? 12f : 6f));
			_revealGroup.alpha = Ui.Damp(_revealGroup.alpha, flag ? 1f : 0f, speed);
			bool flag2 = _revealGroup.alpha > 0.01f;
			if (((Component)_reveal).gameObject.activeSelf != flag2)
			{
				((Component)_reveal).gameObject.SetActive(flag2);
			}
			if (!flag2 || _cells.Count == 0)
			{
				return;
			}
			((Transform)_revealBody).localScale = Vector3.one * (0.9f + 0.1f * _revealGroup.alpha);
			float num2 = Mathf.Clamp01(num / 3.3f);
			float num3 = (1f - Mathf.Pow(1f - num2, 4f)) * (float)_reelWinner * 340f;
			int num4 = Mathf.RoundToInt(num3 / 340f);
			if (flag && num4 != _lastTickCell && !_landed)
			{
				_lastTickCell = num4;
				Ui.Tick(0.85f + 0.35f * num2);
			}
			if (flag && num2 >= 1f && !_landed)
			{
				_landed = true;
				_punch = 1f;
				((Graphic)_revealTitle).color = Ui.Amber;
				Ui.Click((MenuClickEffectType)1, 0.9f);
			}
			for (int i = 0; i < _cells.Count; i++)
			{
				TextMeshProUGUI val = _cells[i];
				float num5 = (float)i * 340f - num3;
				bool flag3 = Mathf.Abs(num5) < 883.99994f;
				if (((Component)val).gameObject.activeSelf != flag3)
				{
					((Component)val).gameObject.SetActive(flag3);
				}
				if (flag3)
				{
					float num6 = Mathf.Clamp01(Mathf.Abs(num5) / 578f);
					((TMP_Text)val).rectTransform.anchoredPosition = new Vector2(num5, 0f);
					((Transform)((TMP_Text)val).rectTransform).localScale = Vector3.one * (1f - 0.2f * num6 + ((i == _reelWinner) ? (_punch * 0.12f) : 0f));
					Color c = ((_landed && i == _reelWinner) ? Ui.Amber : Ui.Text);
					((Graphic)val).color = c.WithAlpha(1f - num6 * 0.85f);
				}
			}
			_punch = Ui.Damp(_punch, 0f, 6f);
			((Transform)_window).localScale = Vector3.one * (1f + _punch * 0.05f);
			((Graphic)_revealCenter).color = Ui.Amber.WithAlpha(_landed ? (0.16f + _punch * 0.3f) : 0.07f);
		}

		private void Build()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			GameObject val = new GameObject("MapVotePlusPlusCanvas")
			{
				layer = 5
			};
			val.transform.SetParent(((Component)this).transform, false);
			_canvas = val.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 900;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.matchWidthOrHeight = 1f;
			_root = (RectTransform)val.transform;
			BuildChip();
			BuildReveal();
			((Behaviour)_canvas).enabled = false;
		}

		private static Image Shadow(Transform parent, float spread)
		{
			//IL_0006: 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)
			Image obj = Ui.Image("Shadow", parent, Color.black.WithAlpha(0.5f), Ui.Rounded);
			((Graphic)obj).rectTransform.Fill(0f - spread, (0f - spread) * 0.6f, 0f - spread, (0f - spread) * 1.4f);
			return obj;
		}

		private void BuildChip()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			_chip = Ui.Rect("Chip", (Transform)(object)_root).Place(new Vector2(1f, 0f), new Vector2(-36f, 36f), new Vector2(420f, 70f));
			_chipGroup = ((Component)_chip).gameObject.AddComponent<CanvasGroup>();
			_chipGroup.alpha = 0f;
			Shadow((Transform)(object)_chip, 12f);
			_chipBorder = Ui.Image("Border", (Transform)(object)_chip, Ui.Amber.WithAlpha(0.3f), Ui.Rounded);
			((Graphic)_chipBorder).rectTransform.Fill(-2f, -2f, -2f, -2f);
			((Graphic)Ui.Image("Bg", (Transform)(object)_chip, Ui.Panel, Ui.Rounded)).rectTransform.Fill();
			Image val = Ui.Image("Key", (Transform)(object)_chip, Ui.Amber, Ui.RoundedSmall);
			((Graphic)val).rectTransform.Place(new Vector2(0f, 0.5f), new Vector2(12f, 0f), new Vector2(46f, 46f));
			_chipKey = Ui.Label("KeyText", (Transform)(object)((Graphic)val).rectTransform, 22f, Ui.Ink, (TextAlignmentOptions)514, (FontStyles)1);
			((TMP_Text)_chipKey).rectTransform.Fill(3f, 3f, 3f, 3f);
			((TMP_Text)_chipKey).enableAutoSizing = true;
			((TMP_Text)_chipKey).fontSizeMin = 10f;
			((TMP_Text)_chipKey).fontSizeMax = 22f;
			_chipTitle = Ui.Label("Title", (Transform)(object)_chip, 19f, Ui.Text, (TextAlignmentOptions)1025, (FontStyles)1);
			((TMP_Text)_chipTitle).rectTransform.Place(new Vector2(0f, 1f), new Vector2(72f, -10f), new Vector2(330f, 28f));
			((TMP_Text)_chipTitle).characterSpacing = 2f;
			_chipSub = Ui.Label("Sub", (Transform)(object)_chip, 15f, Ui.Muted, (TextAlignmentOptions)257, (FontStyles)1);
			((TMP_Text)_chipSub).rectTransform.Place(new Vector2(0f, 1f), new Vector2(72f, -39f), new Vector2(330f, 20f));
			((TMP_Text)_chipSub).characterSpacing = 2f;
		}

		private void BuildReveal()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: 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_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: 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_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			_reveal = Ui.Rect("Reveal", (Transform)(object)_root).Fill();
			_revealGroup = ((Component)_reveal).gameObject.AddComponent<CanvasGroup>();
			_revealGroup.alpha = 0f;
			((Graphic)Ui.Image("Dim", (Transform)(object)_reveal, Color.black.WithAlpha(0.72f))).rectTransform.Fill();
			_revealBody = Ui.Rect("Body", (Transform)(object)_reveal).Place(new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(1080f, 150f));
			_revealTitle = Ui.Label("Title", (Transform)(object)_revealBody, 30f, Ui.Muted, (TextAlignmentOptions)514, (FontStyles)1);
			((TMP_Text)_revealTitle).rectTransform.Place(new Vector2(0.5f, 1f), new Vector2(0f, 68f), new Vector2(1080f, 36f));
			((TMP_Text)_revealTitle).characterSpacing = 12f;
			_window = Ui.Rect("Window", (Transform)(object)_revealBody).Fill();
			Shadow((Transform)(object)_window, 24f);
			((Graphic)Ui.Image("Frame", (Transform)(object)_window, Ui.Amber.WithAlpha(0.9f), Ui.Rounded)).rectTransform.Fill(-2f, -2f, -2f, -2f);
			((Graphic)Ui.Image("Bg", (Transform)(object)_window, Ui.Panel, Ui.Rounded)).rectTransform.Fill();
			_revealCenter = Ui.Image("Centre", (Transform)(object)_window, Ui.Amber.WithAlpha(0.07f), Ui.RoundedSmall);
			((Graphic)_revealCenter).rectTransform.Place(new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(330f, 128f));
			RectTransform val = Ui.Rect("Mask", (Transform)(object)_window).Fill(8f, 8f, 8f, 8f);
			((Component)val).gameObject.AddComponent<RectMask2D>();
			_reel = Ui.Rect("Reel", (Transform)(object)val).Place(new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero);
			RectTransform rectTransform = ((Graphic)Ui.Image("FadeL", (Transform)(object)_window, Ui.Panel, Ui.FadeRight)).rectTransform;
			rectTransform.Place(new Vector2(0f, 0.5f), new Vector2(8f, 0f), new Vector2(220f, 134f));
			((Transform)rectTransform).localScale = new Vector3(-1f, 1f, 1f);
			rectTransform.pivot = new Vector2(1f, 0.5f);
			((Graphic)Ui.Image("FadeR", (Transform)(object)_window, Ui.Panel, Ui.FadeRight)).rectTransform.Place(new Vector2(1f, 0.5f), new Vector2(-8f, 0f), new Vector2(220f, 134f));
			(Vector2, float)[] array = new(Vector2, float)[2]
			{
				(new Vector2(0.5f, 1f), 8f),
				(new Vector2(0.5f, 0f), -8f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(Vector2, float) tuple = array[i];
				Vector2 item = tuple.Item1;
				float item2 = tuple.Item2;
				RectTransform rectTransform2 = ((Graphic)Ui.Image("Marker", (Transform)(object)_window, Ui.Amber, Ui.RoundedSmall)).rectTransform;
				Vector2 anchorMin = (rectTransform2.anchorMax = item);
				rectTransform2.anchorMin = anchorMin;
				rectTransform2.pivot = new Vector2(0.5f, 0.5f);
				rectTransform2.anchoredPosition = new Vector2(0f, item2);
				rectTransform2.sizeDelta = new Vector2(18f, 18f);
				((Transform)rectTransform2).localRotation = Quaternion.Euler(0f, 0f, 45f);
			}
			((Component)_reveal).gameObject.SetActive(false);
		}
	}
}