Decompiled source of Gentlemens Map Vote v0.3.0

GentlemensMapVote/GentlemensMapVote.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using AGD.ModAPI;
using AGD.Modding;
using AGDKit;
using Character;
using Core;
using DisputeLib;
using FMOD;
using FMOD.Studio;
using FMODUnity;
using FishNet;
using FishNet.Connection;
using FishNet.Managing.Client;
using FishNet.Object;
using Game;
using HeldItems;
using Items;
using Newtonsoft.Json.Linq;
using Player;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Localization;
using UnityEngine.Playables;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Util;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GentlemensMapVote
{
	internal static class VoteHud
	{
		public static Ballot Ballot;

		public static int[] Counts = new int[4];

		public static int Voted;

		public static int Expected = 1;

		public static int Mine = -1;

		public static Voter[] Voters = new Voter[0];

		public static int LocalClientId = -1;

		public static int Winner = -1;

		public static string WinnerTitle;

		public static float LocalCloses;

		public static float ResultAt = -99f;

		public static float LastHeard = -99f;

		private static VoteHudRunner _runner;

		public static bool Showing
		{
			get
			{
				if (Ballot == null)
				{
					return false;
				}
				if (Winner >= 0)
				{
					return Time.unscaledTime - ResultAt < 3f;
				}
				if (Time.unscaledTime - LastHeard < 3f)
				{
					return Time.unscaledTime < LocalCloses + 3f;
				}
				return false;
			}
		}

		public static void Install()
		{
			VoteNet.OnOpen += GotOpen;
			VoteNet.OnTally += GotTally;
			VoteNet.OnVoters += GotVoters;
			VoteNet.OnResult += GotResult;
			_runner = Kit.Host.AddComponent<VoteHudRunner>();
		}

		public static void Uninstall()
		{
			VoteNet.OnOpen -= GotOpen;
			VoteNet.OnTally -= GotTally;
			VoteNet.OnVoters -= GotVoters;
			VoteNet.OnResult -= GotResult;
			if ((Object)(object)_runner != (Object)null)
			{
				Object.Destroy((Object)(object)_runner);
			}
			Ballot = null;
			Avatars.Clear();
		}

		private static void GotOpen(Ballot b)
		{
			Ballot = b;
			Counts = new int[4];
			Voted = 0;
			Mine = -1;
			Winner = -1;
			WinnerTitle = null;
			Voters = new Voter[0];
			try
			{
				ClientManager clientManager = InstanceFinder.ClientManager;
				LocalClientId = (((Object)(object)clientManager != (Object)null && clientManager.Connection != (NetworkConnection)null) ? clientManager.Connection.ClientId : (-1));
			}
			catch (Exception)
			{
				LocalClientId = -1;
			}
			LocalCloses = Time.unscaledTime + b.Seconds;
			LastHeard = Time.unscaledTime;
			VoteSfx.Preload();
			Kit.Log("client: ballot #" + b.Serial + " (" + b.Maps.Length + " maps, " + b.Seconds.ToString("0") + " s)");
		}

		private static void GotTally(int serial, int[] counts, int voted, int expected)
		{
			if (Ballot != null && serial == Ballot.Serial)
			{
				Counts = counts;
				Voted = voted;
				Expected = Math.Max(1, expected);
				LastHeard = Time.unscaledTime;
			}
		}

		private static void GotVoters(int serial, Voter[] voters)
		{
			if (Ballot != null && serial == Ballot.Serial)
			{
				Voters = voters;
			}
		}

		private static void GotResult(int serial, int choice, string title)
		{
			if (Ballot != null && serial == Ballot.Serial)
			{
				Winner = choice;
				WinnerTitle = title;
				ResultAt = Time.unscaledTime;
				LastHeard = Time.unscaledTime;
				Kit.Log("client: next map " + title);
			}
		}

		public static void Vote(int choice)
		{
			if (Ballot != null && Winner < 0 && (choice == 3 || (choice >= 0 && choice < Ballot.Maps.Length)))
			{
				Mine = choice;
				VoteNet.SendVote(Ballot.Serial, choice);
			}
		}

		public static string TitleOf(int choice)
		{
			if (Ballot == null)
			{
				return "";
			}
			if (choice == 3)
			{
				return "Random";
			}
			if (choice < 0 || choice >= Ballot.Maps.Length)
			{
				return "";
			}
			MapEntry[] allMaps = SessionContentRegistry.AllMaps;
			int num = Ballot.Maps[choice];
			if (allMaps != null && num >= 0 && num < allMaps.Length && allMaps[num] != null)
			{
				string text = VoteServer.Title(allMaps[num]);
				if (!string.IsNullOrEmpty(text) && text != "?")
				{
					return text;
				}
			}
			return Ballot.Titles[choice];
		}

		public static Sprite IconOf(int choice)
		{
			if (Ballot == null || choice < 0 || choice >= Ballot.Maps.Length)
			{
				return null;
			}
			MapEntry[] allMaps = SessionContentRegistry.AllMaps;
			int num = Ballot.Maps[choice];
			if (allMaps == null || num < 0 || num >= allMaps.Length || allMaps[num] == null)
			{
				return null;
			}
			return allMaps[num].icon;
		}
	}
	internal static class Avatars
	{
		private static readonly Dictionary<ulong, Sprite> _sprites = new Dictionary<ulong, Sprite>();

		private static readonly Dictionary<ulong, float> _retryAt = new Dictionary<ulong, float>();

		public static Sprite Get(ulong id)
		{
			//IL_004d: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_0200: Expected O, but got Unknown
			if (id == 0L)
			{
				return null;
			}
			if (_sprites.TryGetValue(id, out var value))
			{
				return value;
			}
			if (_retryAt.TryGetValue(id, out var value2) && Time.unscaledTime < value2)
			{
				return null;
			}
			_retryAt[id] = Time.unscaledTime + 2f;
			try
			{
				CSteamID val = default(CSteamID);
				((CSteamID)(ref val))..ctor(id);
				int smallFriendAvatar = SteamFriends.GetSmallFriendAvatar(val);
				if (smallFriendAvatar <= 0)
				{
					SteamFriends.RequestUserInformation(val, false);
					return null;
				}
				uint num = default(uint);
				uint num2 = default(uint);
				if (!SteamUtils.GetImageSize(smallFriendAvatar, ref num, ref num2) || num == 0 || num2 == 0 || num > 256 || num2 > 256)
				{
					return null;
				}
				byte[] array = new byte[num * num2 * 4];
				if (!SteamUtils.GetImageRGBA(smallFriendAvatar, array, array.Length))
				{
					return null;
				}
				int num3 = (int)num;
				int num4 = (int)num2;
				byte[] array2 = new byte[array.Length];
				float num5 = (float)num3 / 2f;
				for (int i = 0; i < num4; i++)
				{
					for (int j = 0; j < num3; j++)
					{
						int num6 = ((num4 - 1 - i) * num3 + j) * 4;
						int num7 = (i * num3 + j) * 4;
						float num8 = Mathf.Sqrt(((float)j + 0.5f - num5) * ((float)j + 0.5f - num5) + ((float)i + 0.5f - (float)num4 / 2f) * ((float)i + 0.5f - (float)num4 / 2f));
						array2[num7] = array[num6];
						array2[num7 + 1] = array[num6 + 1];
						array2[num7 + 2] = array[num6 + 2];
						array2[num7 + 3] = (byte)((float)(int)array[num6 + 3] * Mathf.Clamp01(num5 - num8 + 0.5f));
					}
				}
				Texture2D val2 = new Texture2D(num3, num4, (TextureFormat)4, false);
				val2.LoadRawTextureData(array2);
				val2.Apply();
				((Texture)val2).wrapMode = (TextureWrapMode)1;
				value = Sprite.Create(val2, new Rect(0f, 0f, (float)num3, (float)num4), new Vector2(0.5f, 0.5f), 100f);
				_sprites[id] = value;
				return value;
			}
			catch (Exception)
			{
				return null;
			}
		}

		public static void Clear()
		{
			foreach (Sprite value in _sprites.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					if ((Object)(object)value.texture != (Object)null)
					{
						Object.Destroy((Object)(object)value.texture);
					}
					Object.Destroy((Object)(object)value);
				}
			}
			_sprites.Clear();
			_retryAt.Clear();
		}
	}
	internal class VoteHudRunner : MonoBehaviour
	{
		private class Chip
		{
			public RectTransform Rt;

			public Image Ring;

			public Image Face;

			public TextMeshProUGUI Letter;

			public int Id = int.MinValue;

			public bool HasAvatar;

			public bool Mine;

			public Vector2 Pos;
		}

		private class Card
		{
			public RectTransform Rt;

			public RectTransform Pill;

			public RectTransform Crown;

			public RectTransform Frame;

			public CanvasGroup Group;

			public Image Face;

			public Image Shadow;

			public Image Photo;

			public Image PillImg;

			public Image Outline;

			public Image Dim;

			public TextMeshProUGUI Title;

			public TextMeshProUGUI Desc;

			public TextMeshProUGUI Key;

			public TextMeshProUGUI Missing;

			public int Slot;

			public int LastCount;

			public float Lift;

			public float Hov;

			public float PopAt = -99f;
		}

		private static readonly Color Red = Hex(13388349);

		private static readonly Color Ink = Hex(9056036);

		private static readonly Color Brown = Hex(3875864);

		private static readonly Color Gold = Hex(16758610);

		private static readonly Color Pill = Hex(4670790);

		private static readonly Color Cream = Hex(13879202);

		private static readonly float[] Tilt = new float[4] { -3f, 2f, -1.5f, 3f };

		private static readonly Vector2 Mid = new Vector2(0.5f, 0.5f);

		private const float CardW = 340f;

		private const float CardH = 500f;

		private const float Gap = 380f;

		private GameObject _canvas;

		private CanvasGroup _group;

		private TextMeshProUGUI _header;

		private TextMeshProUGUI _timer;

		private TextMeshProUGUI _footer;

		private RectTransform _timerChip;

		private RectTransform _footerPill;

		private readonly Card[] _cards = new Card[4];

		private int _built = -1;

		private int _lastSecond = -1;

		private int _count = 4;

		private float _secondAt;

		private bool _raised;

		private int _dealt;

		private int _lastMine = -1;

		private int _lastVoted;

		private float _mineAt = -99f;

		private float _allInAt = -1f;

		private bool _drummed;

		private bool _crowned;

		private Dictionary<string, Sprite> _sprites;

		private Sprite _circle;

		private RectTransform _chipLayer;

		private readonly Dictionary<int, Chip> _chips = new Dictionary<int, Chip>();

		private readonly List<int> _seen = new List<int>();

		private readonly List<Chip> _slots = new List<Chip>();

		private readonly List<int> _drop = new List<int>();

		private const float ChipSize = 44f;

		private const float ChipGap = 48f;

		private const float SlotSize = 34f;

		private const float SlotGap = 40f;

		private static readonly Color[] Palette = (Color[])(object)new Color[6]
		{
			Hex(14242639),
			Hex(5214169),
			Hex(6140779),
			Hex(14721072),
			Hex(10185673),
			Hex(4174768)
		};

		private TMP_FontAsset _title;

		private TMP_FontAsset _body;

		private void Update()
		{
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0784: Unknown result type (might be due to invalid IL or missing references)
			//IL_0804: Unknown result type (might be due to invalid IL or missing references)
			//IL_0820: Unknown result type (might be due to invalid IL or missing references)
			//IL_0819: Unknown result type (might be due to invalid IL or missing references)
			//IL_0865: Unknown result type (might be due to invalid IL or missing references)
			//IL_085e: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			if (!VoteHud.Showing)
			{
				if ((Object)(object)_canvas != (Object)null && _canvas.activeSelf)
				{
					_canvas.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_canvas == (Object)null)
			{
				Build();
			}
			if (!_canvas.activeSelf)
			{
				_canvas.SetActive(true);
			}
			Ballot ballot = VoteHud.Ballot;
			if (_built != ballot.Serial)
			{
				_built = ballot.Serial;
				Fill(ballot);
				ResetChips();
				_dealt = 0;
				_lastMine = -1;
				_lastVoted = 0;
				_mineAt = -99f;
				_allInAt = -1f;
				_drummed = false;
				_crowned = false;
			}
			ReadInput();
			float unscaledTime = Time.unscaledTime;
			float unscaledDeltaTime = Time.unscaledDeltaTime;
			float num = VoteHud.LocalCloses - ballot.Seconds;
			bool flag = VoteHud.Winner >= 0;
			int num2 = (flag ? (-1) : VoteMouse.Hover);
			if (VoteHud.Mine != _lastMine)
			{
				_lastMine = VoteHud.Mine;
				if (_lastMine >= 0)
				{
					_mineAt = unscaledTime;
					VoteSfx.Vote(mine: true);
				}
			}
			if (VoteHud.Voted > _lastVoted && unscaledTime - _mineAt > 0.6f)
			{
				VoteSfx.Vote(mine: false);
			}
			_lastVoted = VoteHud.Voted;
			if (_allInAt < 0f && VoteHud.Voted >= VoteHud.Expected && VoteHud.Voted > 0)
			{
				_allInAt = unscaledTime;
			}
			if (!flag && !_drummed && (VoteHud.LocalCloses - unscaledTime <= 1f || (_allInAt >= 0f && unscaledTime - _allInAt >= 0.5f)))
			{
				_drummed = true;
				VoteSfx.Drum();
			}
			float num3 = (flag ? EaseInOut(Mathf.Clamp01((unscaledTime - VoteHud.ResultAt) / 0.45f)) : 0f);
			float num4 = (flag ? Mathf.Clamp01((3f - (unscaledTime - VoteHud.ResultAt)) / 0.35f) : 1f);
			_group.alpha = Mathf.Clamp01((unscaledTime - num) / 0.25f) * num4;
			((TMP_Text)_header).text = (flag ? ("NEXT MAP: " + (VoteHud.WinnerTitle ?? "").ToUpperInvariant()) : "VOTE FOR THE NEXT MAP");
			((Component)_footerPill).gameObject.SetActive(!flag);
			((TMP_Text)_footer).text = "Press <color=#FFB752>1-" + _count + "</color>, <color=#FFB752>click</color> a card or use the <color=#FFB752>D-pad</color>     " + VoteHud.Voted + "/" + VoteHud.Expected + " voted";
			int num5 = Mathf.CeilToInt(Mathf.Max(0f, VoteHud.LocalCloses - unscaledTime));
			if (num5 != _lastSecond)
			{
				_lastSecond = num5;
				_secondAt = unscaledTime;
				if (!flag && num5 >= 1 && num5 <= 3)
				{
					VoteSfx.Tick(num5);
				}
			}
			((Component)_timerChip).gameObject.SetActive(!flag);
			((TMP_Text)_timer).text = num5.ToString();
			float num6 = 1f + (1f - Mathf.Clamp01((unscaledTime - _secondAt) / 0.3f)) * ((num5 <= 3) ? 0.25f : 0.08f);
			((Transform)_timerChip).localScale = new Vector3(num6, num6, 1f);
			if (flag && !_raised)
			{
				_raised = true;
				if (VoteHud.Winner < 4)
				{
					((Transform)_cards[VoteHud.Winner].Rt).SetAsLastSibling();
				}
			}
			for (int i = 0; i < 4; i++)
			{
				Card card = _cards[i];
				if (!((Component)card.Rt).gameObject.activeSelf)
				{
					continue;
				}
				bool flag2 = VoteHud.Mine == i;
				bool flag3 = flag && VoteHud.Winner == i;
				int num7 = ((i < VoteHud.Counts.Length) ? VoteHud.Counts[i] : 0);
				if (num7 != card.LastCount)
				{
					card.LastCount = num7;
					card.PopAt = unscaledTime;
				}
				((TMP_Text)card.Desc).text = num7 switch
				{
					1 => "1 vote", 
					0 => "<alpha=#70>No votes yet", 
					_ => num7 + " votes", 
				};
				float num8 = 1f + 0.3f * (1f - Mathf.Clamp01((unscaledTime - card.PopAt) / 0.25f));
				((Transform)((TMP_Text)card.Desc).rectTransform).localScale = new Vector3(num8, num8, 1f);
				card.Lift = Mathf.MoveTowards(card.Lift, (flag2 && !flag) ? 1f : 0f, unscaledDeltaTime * 6f);
				float num9 = EaseOut(card.Lift);
				card.Hov = Mathf.MoveTowards(card.Hov, (num2 == i && !flag2) ? 1f : 0f, unscaledDeltaTime * 8f);
				float num10 = EaseOut(card.Hov);
				float num11 = Mathf.Clamp01((unscaledTime - num - 0.08f * (float)card.Slot) / 0.4f);
				if (num11 > 0f && (_dealt & (1 << i)) == 0)
				{
					_dealt |= 1 << i;
					VoteSfx.Deal(card.Slot);
				}
				float num12 = EaseOutBack(num11);
				float num13 = Slot(card.Slot);
				float num14 = -20f + (1f - num12) * -760f + 24f * num9 + 10f * num10;
				float num15 = Tilt[card.Slot] * (1f - num9) * (1f - 0.5f * num10) + (1f - num12) * 14f;
				float num16 = 1f + 0.05f * num9 + 0.03f * num10;
				float alpha = Mathf.Clamp01(num11 * 3f);
				if (flag)
				{
					if (flag3)
					{
						num13 = Mathf.Lerp(num13, 0f, num3);
						num14 = Mathf.Lerp(num14, -10f, num3);
						num15 = Mathf.Lerp(num15, 0f, num3);
						num16 = Mathf.Lerp(num16, 1.12f, num3);
					}
					else
					{
						num14 -= 90f * num3;
					}
				}
				card.Rt.anchoredPosition = new Vector2(num13, num14);
				((Transform)card.Rt).localEulerAngles = new Vector3(0f, 0f, num15);
				((Transform)card.Rt).localScale = new Vector3(num16, num16, 1f);
				card.Group.alpha = alpha;
				((Graphic)card.Dim).color = new Color(0f, 0f, 0f, (flag && !flag3) ? (0.55f * num3) : 0f);
				((Graphic)card.Shadow).rectTransform.anchoredPosition = new Vector2(10f, -12f - 10f * num9);
				((Component)card.Outline).gameObject.SetActive(flag2 || flag3 || card.Hov > 0.01f);
				((Graphic)card.Outline).color = (Color)(flag3 ? Gold : (flag2 ? new Color(Gold.r, Gold.g, Gold.b, 0.75f + 0.25f * Mathf.Sin(unscaledTime * 5f)) : new Color(Gold.r, Gold.g, Gold.b, 0.5f * num10)));
				((Component)card.Pill).gameObject.SetActive(!flag);
				card.Pill.sizeDelta = new Vector2(flag2 ? 190f : 96f, 46f);
				((Graphic)card.PillImg).color = (flag2 ? Gold : Pill);
				((TMP_Text)card.Key).text = (flag2 ? "YOUR VOTE" : (card.Slot + 1).ToString());
				((Graphic)card.Key).color = (flag2 ? Brown : Color.white);
				((TMP_Text)card.Key).fontSize = (flag2 ? 24f : 30f);
				((Component)card.Crown).gameObject.SetActive(flag3);
				if (flag3)
				{
					float num17 = EaseOutBack(Mathf.Clamp01((unscaledTime - VoteHud.ResultAt - 0.3f) / 0.35f));
					((Transform)card.Crown).localScale = new Vector3(num17, num17, 1f);
					if (num17 > 0f && !_crowned)
					{
						_crowned = true;
						VoteSfx.Crown();
					}
				}
			}
			UpdateChips(unscaledDeltaTime);
		}

		private void UpdateChips(float dt)
		{
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: 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_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			Voter[] array = VoteHud.Voters ?? new Voter[0];
			_drop.Clear();
			foreach (int key in _chips.Keys)
			{
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].ClientId == key)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					_drop.Add(key);
				}
			}
			foreach (int item in _drop)
			{
				Object.Destroy((Object)(object)((Component)_chips[item].Rt).gameObject);
				_chips.Remove(item);
				_seen.Remove(item);
			}
			for (int j = 0; j < array.Length; j++)
			{
				if (!_seen.Contains(array[j].ClientId))
				{
					_seen.Add(array[j].ClientId);
				}
			}
			int num = Mathf.Clamp(Mathf.Max(VoteHud.Expected, _seen.Count), 1, 12);
			while (_slots.Count < num)
			{
				_slots.Add(MakeChip(34f));
			}
			for (int k = 0; k < _slots.Count; k++)
			{
				Chip chip = _slots[k];
				bool flag2 = k < num && VoteHud.Winner < 0;
				((Component)chip.Rt).gameObject.SetActive(flag2);
				if (flag2)
				{
					chip.Rt.anchoredPosition = new Vector2(((float)k - (float)(num - 1) / 2f) * 40f, -447f);
					ApplyFace(chip, (k < _seen.Count) ? Find(array, _seen[k]) : null);
				}
			}
			Voter[] array2 = array;
			foreach (Voter voter in array2)
			{
				if (!_chips.TryGetValue(voter.ClientId, out var value))
				{
					value = MakeChip(44f);
					_chips[voter.ClientId] = value;
					int num2 = _seen.IndexOf(voter.ClientId);
					value.Pos = (Vector2)((num2 >= 0 && num2 < _slots.Count) ? _slots[num2].Rt.anchoredPosition : new Vector2(0f, -447f));
				}
				ApplyFace(value, voter);
				int choice = voter.Choice;
				if (choice < 0 || choice > 3 || !((Component)_cards[choice].Rt).gameObject.activeSelf)
				{
					((Component)value.Rt).gameObject.SetActive(false);
					continue;
				}
				((Component)value.Rt).gameObject.SetActive(true);
				int num3 = 0;
				int num4 = 0;
				Voter[] array3 = array;
				foreach (Voter voter2 in array3)
				{
					if (voter2.Choice == choice)
					{
						num4++;
						if (voter2.ClientId < voter.ClientId)
						{
							num3++;
						}
					}
				}
				Card obj = _cards[choice];
				float x = ((Transform)obj.Rt).localScale.x;
				float num5 = ((Transform)obj.Rt).localEulerAngles.z * ((float)Math.PI / 180f);
				float num6 = Mathf.Cos(num5);
				float num7 = Mathf.Sin(num5);
				Vector2 val = new Vector2(((float)num3 - (float)(num4 - 1) / 2f) * 48f, -284f) * x;
				Vector2 val2 = obj.Rt.anchoredPosition + new Vector2(val.x * num6 - val.y * num7, val.x * num7 + val.y * num6);
				float num8 = Mathf.Max(60f, Vector2.Distance(value.Pos, val2) * 12f) * dt;
				value.Pos = Vector2.MoveTowards(value.Pos, val2, num8);
				value.Rt.anchoredPosition = value.Pos;
			}
		}

		private static Voter Find(Voter[] voters, int id)
		{
			for (int i = 0; i < voters.Length; i++)
			{
				if (voters[i].ClientId == id)
				{
					return voters[i];
				}
			}
			return null;
		}

		private void ApplyFace(Chip ch, Voter v)
		{
			//IL_0058: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			if (v == null)
			{
				if (ch.Id != int.MinValue)
				{
					ch.Id = int.MinValue;
					ch.HasAvatar = false;
					ch.Mine = false;
					ch.Face.sprite = _circle;
					((Graphic)ch.Face).color = new Color(0.28f, 0.27f, 0.28f, 0.8f);
					((Graphic)ch.Ring).color = new Color(0f, 0f, 0f, 0.35f);
					((TMP_Text)ch.Letter).text = "";
				}
				return;
			}
			Sprite val = Avatars.Get(v.SteamId);
			bool flag = v.ClientId == VoteHud.LocalClientId;
			if (ch.Id != v.ClientId || ch.HasAvatar != ((Object)(object)val != (Object)null) || ch.Mine != flag)
			{
				ch.Id = v.ClientId;
				ch.HasAvatar = (Object)(object)val != (Object)null;
				ch.Mine = flag;
				((Graphic)ch.Ring).color = (flag ? Gold : Brown);
				if ((Object)(object)val != (Object)null)
				{
					ch.Face.sprite = val;
					((Graphic)ch.Face).color = Color.white;
					((TMP_Text)ch.Letter).text = "";
				}
				else
				{
					ch.Face.sprite = _circle;
					((Graphic)ch.Face).color = Palette[(v.ClientId % 6 + 6) % 6];
					string text = (v.Name ?? "").Trim();
					((TMP_Text)ch.Letter).text = ((text.Length > 0) ? text.Substring(0, 1).ToUpperInvariant() : "?");
				}
			}
		}

		private Chip MakeChip(float size)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0049: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			Chip chip = new Chip();
			chip.Id = -2147483647;
			chip.Rt = Rect("Chip", (Transform)(object)_chipLayer, Mid, Mid, new Vector2(size, size));
			chip.Ring = Img(Rect("Ring", (Transform)(object)chip.Rt, Mid, Mid, new Vector2(size + 8f, size + 8f)), _circle, Brown);
			chip.Face = Img(Rect("Face", (Transform)(object)chip.Rt, Mid, Mid, new Vector2(size, size)), _circle, Color.white);
			chip.Letter = Text(chip.Rt, _title, size * 0.58f, new Vector2(0f, 1f), Color.white, size);
			Outline(chip.Letter, 0.25f);
			return chip;
		}

		private void ResetChips()
		{
			foreach (Chip value in _chips.Values)
			{
				if ((Object)(object)value.Rt != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value.Rt).gameObject);
				}
			}
			_chips.Clear();
			_seen.Clear();
			foreach (Chip slot in _slots)
			{
				slot.Id = -2147483647;
			}
		}

		private static Sprite MakeCircle()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00d6: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = Mathf.Sqrt(((float)j + 0.5f - 32f) * ((float)j + 0.5f - 32f) + ((float)i + 0.5f - 32f) * ((float)i + 0.5f - 32f));
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * Mathf.Clamp01(32f - num)));
				}
			}
			val.SetPixels32(array);
			val.Apply();
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
		}

		private void ReadInput()
		{
			if (VoteHud.Winner >= 0)
			{
				return;
			}
			int num = -1;
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if (((ButtonControl)current.digit1Key).wasPressedThisFrame || ((ButtonControl)current.numpad1Key).wasPressedThisFrame)
				{
					num = 0;
				}
				else if (((ButtonControl)current.digit2Key).wasPressedThisFrame || ((ButtonControl)current.numpad2Key).wasPressedThisFrame)
				{
					num = 1;
				}
				else if (((ButtonControl)current.digit3Key).wasPressedThisFrame || ((ButtonControl)current.numpad3Key).wasPressedThisFrame)
				{
					num = 2;
				}
				else if (((ButtonControl)current.digit4Key).wasPressedThisFrame || ((ButtonControl)current.numpad4Key).wasPressedThisFrame)
				{
					num = 3;
				}
			}
			Gamepad current2 = Gamepad.current;
			if (num < 0 && current2 != null)
			{
				if (current2.dpad.left.wasPressedThisFrame)
				{
					num = 0;
				}
				else if (current2.dpad.up.wasPressedThisFrame)
				{
					num = 1;
				}
				else if (current2.dpad.right.wasPressedThisFrame)
				{
					num = 2;
				}
				else if (current2.dpad.down.wasPressedThisFrame)
				{
					num = 3;
				}
			}
			if (num >= 0)
			{
				VoteHud.Vote((num < VoteHud.Ballot.Maps.Length) ? num : 3);
			}
		}

		private float Slot(int slot)
		{
			return ((float)slot - (float)(_count - 1) / 2f) * 380f;
		}

		private void Fill(Ballot b)
		{
			//IL_00e6: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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)
			int num = b.Maps.Length;
			_count = num + 1;
			_raised = false;
			_lastSecond = -1;
			for (int i = 0; i < 4; i++)
			{
				Card card = _cards[i];
				bool flag = i == 3;
				bool flag2 = flag || i < num;
				((Component)card.Rt).gameObject.SetActive(flag2);
				if (flag2)
				{
					((Transform)card.Rt).SetSiblingIndex(i);
					card.Slot = (flag ? num : i);
					card.Lift = 0f;
					card.LastCount = 0;
					card.PopAt = -99f;
					((TMP_Text)card.Title).text = VoteHud.TitleOf(i).ToUpperInvariant();
					card.Face.sprite = Sprite(flag ? "Card-05-No_OutlineBackGround" : "Card-05-No_Outline");
					((Graphic)card.Face).color = (((Object)(object)card.Face.sprite != (Object)null) ? Color.white : Cream);
					((Component)card.Frame).gameObject.SetActive(!flag);
					Sprite val = (flag ? null : VoteHud.IconOf(i));
					card.Photo.sprite = val;
					((Graphic)card.Photo).color = (((Object)(object)val != (Object)null) ? Color.white : Brown);
					((TMP_Text)card.Missing).text = (((Object)(object)val == (Object)null) ? "?" : "");
					((TMP_Text)card.Desc).rectTransform.anchoredPosition = new Vector2(0f, flag ? (-138f) : (-72f));
				}
			}
		}

		private void Build()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: 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_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: 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_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			_sprites = new Dictionary<string, Sprite>();
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if ((Object)(object)val != (Object)null && !_sprites.ContainsKey(((Object)val).name))
				{
					_sprites[((Object)val).name] = val;
				}
			}
			TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			_title = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name == "Caprasimo"));
			_body = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name == "BreeSerif-Regular SDF")) ?? _title;
			_canvas = new GameObject("MapVoteHud");
			Object.DontDestroyOnLoad((Object)(object)_canvas);
			Canvas obj = _canvas.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 420;
			CanvasScaler obj2 = _canvas.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.matchWidthOrHeight = 1f;
			RectTransform val2 = Rect("Root", _canvas.transform, Vector2.zero, Vector2.one, Vector2.zero);
			Img(val2, null, new Color(0f, 0f, 0f, 0.5f));
			_group = ((Component)val2).gameObject.AddComponent<CanvasGroup>();
			_group.blocksRaycasts = false;
			_header = Text(val2, _title, 72f, new Vector2(0f, 440f), Color.white, 1600f);
			Outline(_header, 0.22f);
			_timerChip = Rect("Timer", (Transform)(object)val2, Mid, Mid, new Vector2(120f, 120f));
			_timerChip.anchoredPosition = new Vector2(0f, 330f);
			Image val3 = Img(_timerChip, Sprite("numberspot"), Red);
			if ((Object)(object)val3.sprite != (Object)null)
			{
				((Graphic)val3).color = Color.white;
			}
			val3.preserveAspect = true;
			_timer = Text(_timerChip, _title, 56f, new Vector2(0f, 2f), Color.white, 120f);
			Outline(_timer, 0.3f);
			_footerPill = Rect("Footer", (Transform)(object)val2, Mid, Mid, new Vector2(880f, 64f));
			_footerPill.anchoredPosition = new Vector2(0f, -385f);
			Sliced(Img(_footerPill, Sprite("ButtonMain"), new Color(0.1f, 0.1f, 0.1f, 0.8f)), 30f);
			_footer = Text(_footerPill, _body, 31f, Vector2.zero, Color.white, 860f);
			RectTransform parent = Rect("Cards", (Transform)(object)val2, Mid, Mid, Vector2.zero);
			for (int num = 0; num < 4; num++)
			{
				_cards[num] = MakeCard(parent, num);
			}
			_circle = MakeCircle();
			_chipLayer = Rect("Chips", (Transform)(object)val2, Mid, Mid, Vector2.zero);
		}

		private Card MakeCard(RectTransform parent, int i)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Expected O, but got Unknown
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			Card card = new Card();
			card.Rt = Rect("Card" + i, (Transform)(object)parent, Mid, Mid, new Vector2(340f, 500f));
			card.Group = ((Component)card.Rt).gameObject.AddComponent<CanvasGroup>();
			card.Shadow = Img(Rect("Shadow", (Transform)(object)card.Rt, Mid, Mid, new Vector2(340f, 500f)), Sprite("Card-05-No_Outline"), new Color(0f, 0f, 0f, 0.65f));
			card.Outline = Sliced(Img(Rect("Outline", (Transform)(object)card.Rt, Mid, Mid, new Vector2(356f, 516f)), Sprite("ButtonMainOutline_16px"), Gold), 8f);
			card.Face = Img(Rect("Face", (Transform)(object)card.Rt, Mid, Mid, new Vector2(340f, 500f)), null, Cream);
			RectTransform val = Rect("Banner", (Transform)(object)card.Rt, Mid, Mid, new Vector2(372f, 92f));
			val.anchoredPosition = new Vector2(0f, 191f);
			Image val2 = Img(val, Sprite("FlatBanner"), Red);
			if ((Object)(object)val2.sprite != (Object)null)
			{
				((Graphic)val2).color = new Color(0.8f, 0.28f, 0.24f);
			}
			card.Title = Text(val, _title, 34f, new Vector2(0f, 4f), Color.white, 276f);
			((TMP_Text)card.Title).enableAutoSizing = true;
			((TMP_Text)card.Title).fontSizeMin = 20f;
			((TMP_Text)card.Title).fontSizeMax = 34f;
			card.Frame = Rect("Frame", (Transform)(object)card.Rt, Mid, Mid, new Vector2(292f, 168f));
			card.Frame.anchoredPosition = new Vector2(0f, 68f);
			Img(card.Frame, null, Brown);
			card.Photo = Img(Rect("Photo", (Transform)(object)card.Frame, Mid, Mid, new Vector2(282f, 158f)), null, Color.white);
			card.Photo.preserveAspect = true;
			card.Missing = Text((RectTransform)((Component)card.Photo).transform, _title, 90f, Vector2.zero, Gold, 244f);
			card.Desc = Text(card.Rt, _body, 32f, new Vector2(0f, -72f), Ink, 300f);
			card.Pill = Rect("Key", (Transform)(object)card.Rt, Mid, Mid, new Vector2(96f, 46f));
			card.Pill.anchoredPosition = new Vector2(0f, -192f);
			card.PillImg = Sliced(Img(card.Pill, Sprite("ButtonMain"), Pill), 30f);
			card.Key = Text(card.Pill, _title, 30f, new Vector2(0f, 1f), Color.white, 190f);
			card.Dim = Img(Rect("Dim", (Transform)(object)card.Rt, Mid, Mid, new Vector2(340f, 500f)), Sprite("Card-05-No_Outline"), Color.clear);
			card.Crown = Rect("Crown", (Transform)(object)card.Rt, Mid, Mid, new Vector2(120f, 110f));
			card.Crown.anchoredPosition = new Vector2(0f, 308f);
			Img(card.Crown, Sprite("Crown_Icon"), Gold).preserveAspect = true;
			((Component)card.Crown).gameObject.SetActive(false);
			return card;
		}

		private Sprite Sprite(string name)
		{
			if (_sprites == null || !_sprites.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

		private static Image Img(RectTransform rt, Sprite sp, Color c)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)rt).gameObject.AddComponent<Image>();
			obj.sprite = sp;
			((Graphic)obj).color = c;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static Image Sliced(Image im, float ppuMul)
		{
			if ((Object)(object)im.sprite == (Object)null)
			{
				return im;
			}
			im.type = (Type)1;
			im.pixelsPerUnitMultiplier = ppuMul;
			return im;
		}

		private static void Outline(TextMeshProUGUI t, float width)
		{
			//IL_0008: 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)
			((TMP_Text)t).outlineWidth = width;
			((TMP_Text)t).outlineColor = Color32.op_Implicit(Brown);
		}

		private static float EaseOut(float t)
		{
			return 1f - (1f - t) * (1f - t);
		}

		private static float EaseInOut(float t)
		{
			return t * t * (3f - 2f * t);
		}

		private static float EaseOutBack(float t)
		{
			t -= 1f;
			return 1f + t * t * (2.4f * t + 1.4f);
		}

		private static Color Hex(int rgb)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
		}

		private static RectTransform Rect(string name, Transform parent, Vector2 min, Vector2 max, Vector2 size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			//IL_0032: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent(parent, false);
			val.anchorMin = min;
			val.anchorMax = max;
			val.sizeDelta = size;
			val.anchoredPosition = Vector2.zero;
			return val;
		}

		private static TextMeshProUGUI Text(RectTransform parent, TMP_FontAsset font, float size, Vector2 pos, Color c, float width)
		{
			//IL_0006: 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_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_004d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Rect("Text", (Transform)(object)parent, Mid, Mid, new Vector2(width, size * 1.4f));
			obj.anchoredPosition = pos;
			TextMeshProUGUI val = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val).font = font;
			}
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = c;
			((TMP_Text)val).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			((Graphic)val).raycastTarget = false;
			return val;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_canvas != (Object)null)
			{
				Object.Destroy((Object)(object)_canvas);
			}
			if ((Object)(object)_circle != (Object)null)
			{
				if ((Object)(object)_circle.texture != (Object)null)
				{
					Object.Destroy((Object)(object)_circle.texture);
				}
				Object.Destroy((Object)(object)_circle);
			}
		}
	}
	public class Ballot
	{
		public int Serial;

		public float Seconds;

		public int[] Maps = new int[0];

		public string[] Titles = new string[0];
	}
	public class Voter
	{
		public int ClientId;

		public int Choice;

		public string Name = "";

		public ulong SteamId;
	}
	internal static class VoteNet
	{
		public const int Random = 3;

		private const string Open = "open";

		private const string Tally = "tally";

		private const string Result = "result";

		private const string Vote = "vote";

		public static event Action<Ballot> OnOpen;

		public static event Action<int, int[], int, int> OnTally;

		public static event Action<int, Voter[]> OnVoters;

		public static event Action<int, int, string> OnResult;

		public static event Action<IModPlayer, int, int> OnVote;

		public static void Register()
		{
			IModNetwork network = Kit.Context.Network;
			if (!(network.RegisterClientHandler("open", (Action<ModReader>)GotOpen) & network.RegisterClientHandler("tally", (Action<ModReader>)GotTally) & network.RegisterClientHandler("result", (Action<ModReader>)GotResult) & network.RegisterServerHandler("vote", (Action<IModPlayer, ModReader>)GotVote)))
			{
				Kit.Warn("a message handler was not registered");
			}
		}

		private static void GotOpen(ModReader r)
		{
			Ballot ballot = new Ballot();
			ballot.Serial = r.ReadInt();
			ballot.Seconds = r.ReadFloat();
			int num = Math.Min(r.ReadInt(), 3);
			ballot.Maps = new int[num];
			ballot.Titles = new string[num];
			for (int i = 0; i < num; i++)
			{
				ballot.Maps[i] = r.ReadInt();
				ballot.Titles[i] = r.ReadString();
			}
			if (VoteNet.OnOpen != null)
			{
				VoteNet.OnOpen(ballot);
			}
		}

		private static void GotTally(ModReader r)
		{
			int arg = r.ReadInt();
			int[] array = new int[4];
			for (int i = 0; i < 4; i++)
			{
				array[i] = r.ReadInt();
			}
			int arg2 = r.ReadInt();
			int arg3 = r.ReadInt();
			int num = Math.Max(0, Math.Min(r.ReadInt(), 64));
			Voter[] array2 = new Voter[num];
			for (int j = 0; j < num; j++)
			{
				Voter voter = new Voter();
				voter.ClientId = r.ReadInt();
				voter.Choice = r.ReadInt();
				voter.Name = r.ReadString();
				int num2 = r.ReadInt();
				int num3 = r.ReadInt();
				voter.SteamId = ((ulong)(uint)num2 << 32) | (uint)num3;
				array2[j] = voter;
			}
			try
			{
				if (VoteNet.OnTally != null)
				{
					VoteNet.OnTally(arg, array, arg2, arg3);
				}
			}
			catch (Exception ex)
			{
				Kit.Warn("tally handler: " + ex.Message);
			}
			if (VoteNet.OnVoters != null)
			{
				VoteNet.OnVoters(arg, array2);
			}
		}

		private static void GotResult(ModReader r)
		{
			int arg = r.ReadInt();
			int arg2 = r.ReadInt();
			string arg3 = r.ReadString();
			if (VoteNet.OnResult != null)
			{
				VoteNet.OnResult(arg, arg2, arg3);
			}
		}

		private static void GotVote(IModPlayer from, ModReader r)
		{
			int arg = r.ReadInt();
			int arg2 = r.ReadInt();
			if (VoteNet.OnVote != null)
			{
				VoteNet.OnVote(from, arg, arg2);
			}
		}

		public static void SendOpen(Ballot b)
		{
			Kit.Context.Network.SendToClients("open", (Action<ModWriter>)delegate(ModWriter w)
			{
				w.WriteInt(b.Serial);
				w.WriteFloat(b.Seconds);
				w.WriteInt(b.Maps.Length);
				for (int i = 0; i < b.Maps.Length; i++)
				{
					w.WriteInt(b.Maps[i]);
					w.WriteString(b.Titles[i] ?? "");
				}
			}, true, true);
		}

		public static void SendTally(int serial, int[] counts, int voted, int expected, IList<Voter> voters)
		{
			Kit.Context.Network.SendToClients("tally", (Action<ModWriter>)delegate(ModWriter w)
			{
				w.WriteInt(serial);
				for (int i = 0; i < 4; i++)
				{
					w.WriteInt(counts[i]);
				}
				w.WriteInt(voted);
				w.WriteInt(expected);
				int num = ((voters != null) ? voters.Count : 0);
				w.WriteInt(num);
				for (int j = 0; j < num; j++)
				{
					Voter voter = voters[j];
					w.WriteInt(voter.ClientId);
					w.WriteInt(voter.Choice);
					w.WriteString(voter.Name ?? "");
					w.WriteInt((int)(voter.SteamId >> 32));
					w.WriteInt((int)(voter.SteamId & 0xFFFFFFFFu));
				}
			}, true, true);
		}

		public static void SendResult(int serial, int choice, string title)
		{
			Kit.Context.Network.SendToClients("result", (Action<ModWriter>)delegate(ModWriter w)
			{
				w.WriteInt(serial);
				w.WriteInt(choice);
				w.WriteString(title ?? "");
			}, true, true);
		}

		public static void SendVote(int serial, int choice)
		{
			Kit.Context.Network.SendToServer("vote", (Action<ModWriter>)delegate(ModWriter w)
			{
				w.WriteInt(serial);
				w.WriteInt(choice);
			}, true);
		}
	}
	public class Plugin : IModPlugin
	{
		public void OnLoad(IModContext context)
		{
			Kit.Init(context);
			Kit.Try("net", VoteNet.Register);
			Kit.Try("server", VoteServer.Install);
			Kit.Try("hud", VoteHud.Install);
			Kit.Try("mouse", VoteMouse.Install);
			Kit.Log("loaded");
		}

		public void OnUnload()
		{
			VoteServer.Uninstall();
			VoteHud.Uninstall();
			VoteMouse.Uninstall();
			Kit.Shutdown();
		}
	}
	internal static class VoteServer
	{
		public const float ResultSeconds = 2.5f;

		public const float GraceSeconds = 3f;

		public static bool Open;

		public static Ballot Current;

		public static int Serial;

		public static float OpenedAt;

		public static float ClosesAt;

		public static float ReleaseAt;

		public static int LastChoice = -2;

		public static string LastScene;

		public static int Ballots;

		public static int TestOverride = -1;

		public static float TestSeconds = -1f;

		private static readonly Dictionary<int, int> _votes = new Dictionary<int, int>();

		private static readonly Random _rng = new Random();

		private static int _expected;

		private static float _nextTally;

		private static float _allInAt = -1f;

		private const float SettleSeconds = 1.5f;

		private static VoteRunner _runner;

		private static int _optVer = -1;

		private static bool _enabled = true;

		private static float _seconds = 12f;

		private static readonly List<int> _history = new List<int>();

		private static List<MapEntry> _randomPool = new List<MapEntry>();

		private static HashSet<int> _eligible = new HashSet<int>();

		private static int _votedLive;

		private static readonly Dictionary<int, Voter> _known = new Dictionary<int, Voter>();

		private static MethodInfo _steamOf;

		private static bool _steamLooked;

		private static bool _warned;

		public static int MatchWonSkips;

		public static bool Enabled
		{
			get
			{
				ReadOptions();
				if (TestOverride < 0)
				{
					return _enabled;
				}
				return TestOverride == 1;
			}
		}

		public static float Seconds
		{
			get
			{
				ReadOptions();
				if (!(TestSeconds > 0f))
				{
					return _seconds;
				}
				return TestSeconds;
			}
		}

		private static void ReadOptions()
		{
			int version = ModOptions.Version;
			if (version != _optVer)
			{
				_optVer = version;
				_enabled = ModOptions.Bool(Kit.ModId, "enabled", fallback: true);
				_seconds = Mathf.Clamp(ModOptions.Float(Kit.ModId, "vote_seconds", 12f), 5f, 30f);
			}
		}

		public static void Install()
		{
			VoteNet.OnVote += GotVote;
			_runner = Kit.Host.AddComponent<VoteRunner>();
		}

		public static void Uninstall()
		{
			VoteNet.OnVote -= GotVote;
			if ((Object)(object)_runner != (Object)null)
			{
				_runner.Release("unload");
				_runner.Unhook();
				Object.Destroy((Object)(object)_runner);
			}
			Open = false;
		}

		public static void Played(int mapId)
		{
			if (mapId >= 0)
			{
				_history.Remove(mapId);
				_history.Add(mapId);
			}
		}

		public static void NewMatch()
		{
			_history.Clear();
		}

		public static bool TryOpen(DisputeManager dm)
		{
			if (!string.IsNullOrEmpty(Reflect.Get<string>(dm, "_overrideLevel")))
			{
				Kit.Log("next map already chosen by someone else, no vote");
				return false;
			}
			SessionManager instance = SessionManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			List<MapEntry> source = instance.AvailableMaps.Where((MapEntry m) => m != null && m.scenes != null && m.scenes.Length != 0).ToList();
			HashSet<int> played = Reflect.Get<HashSet<int>>(dm, "_playedLevels") ?? new HashSet<int>();
			int cur = dm.LevelIdx.Value;
			List<MapEntry> list = source.Where((MapEntry m) => m.GetMapId() != cur).ToList();
			if (list.Count < 2)
			{
				Kit.Log("only " + list.Count + " other map(s) in the lobby, no vote");
				return false;
			}
			MapEntry[] all = SessionContentRegistry.AllMaps;
			Func<MapEntry, bool> seen = (MapEntry m) => played.Contains(m.GetMapId()) || _history.Contains(m.GetMapId());
			List<MapEntry> list2 = (from m in list
				where !seen(m)
				orderby _rng.Next()
				select m).Take(3).ToList();
			int count = list2.Count;
			if (list2.Count < 3)
			{
				list2.AddRange((from m in list.Where(seen)
					orderby _history.IndexOf(m.GetMapId()), _rng.Next()
					select m).Take(3 - list2.Count));
			}
			list2 = list2.OrderBy((MapEntry m) => _rng.Next()).ToList();
			_randomPool = list;
			Ballot ballot = new Ballot();
			ballot.Serial = ++Serial;
			ballot.Seconds = Seconds;
			ballot.Maps = list2.Select((MapEntry m) => Array.IndexOf(all, m)).ToArray();
			ballot.Titles = list2.Select((MapEntry m) => Title(m)).ToArray();
			if (ballot.Maps.Any((int i) => i < 0))
			{
				Kit.Warn("a candidate map is not in AllMaps, no vote");
				return false;
			}
			Current = ballot;
			_votes.Clear();
			_known.Clear();
			_eligible = Connections(instance);
			_expected = Math.Max(1, _eligible.Count);
			LastScene = null;
			LastChoice = -2;
			Open = true;
			Ballots++;
			OpenedAt = Time.unscaledTime;
			ClosesAt = Time.unscaledTime + ballot.Seconds;
			ReleaseAt = -1f;
			_nextTally = 0f;
			_allInAt = -1f;
			_votedLive = 0;
			try
			{
				VoteNet.SendOpen(ballot);
			}
			catch (Exception ex)
			{
				Kit.Warn("vote #" + ballot.Serial + " could not be sent, no vote: " + ex.Message);
				Open = false;
				Current = null;
				return false;
			}
			Kit.Log("vote #" + ballot.Serial + " open for " + ballot.Seconds.ToString("0") + " s, " + _expected + " voter(s): " + string.Join(" | ", ballot.Titles) + " | Random (" + count + " unplayed, " + (list2.Count - count) + " replayed, Random from " + list.Count + ")");
			return true;
		}

		public static string Title(MapEntry m)
		{
			try
			{
				if (m.levelTitle != null && !((LocalizedReference)m.levelTitle).IsEmpty)
				{
					string localizedString = m.levelTitle.GetLocalizedString();
					if (!string.IsNullOrEmpty(localizedString))
					{
						return localizedString;
					}
				}
			}
			catch (Exception)
			{
			}
			if (!string.IsNullOrEmpty(m.TitleFallback))
			{
				return m.TitleFallback;
			}
			if (m.scenes == null || m.scenes.Length == 0)
			{
				return "?";
			}
			return m.scenes[0];
		}

		private static HashSet<int> Connections(SessionManager sm)
		{
			if ((Object)(object)sm == (Object)null || sm.serverPlayers == null)
			{
				return new HashSet<int>(_eligible);
			}
			return new HashSet<int>(from p in sm.serverPlayers
				where (Object)(object)p != (Object)null && ((NetworkBehaviour)p).Owner != (NetworkConnection)null && ((NetworkBehaviour)p).Owner.IsValid
				select ((NetworkBehaviour)p).Owner.ClientId);
		}

		private static void GotVote(IModPlayer from, int serial, int choice)
		{
			PlayerController val = Players.Pc(from);
			if (!((Object)(object)val == (Object)null) && !(((NetworkBehaviour)val).Owner == (NetworkConnection)null))
			{
				Cast(((NetworkBehaviour)val).Owner.ClientId, serial, choice);
			}
		}

		public static void Cast(int voter, int serial, int choice)
		{
			if (Open && Current != null && serial == Current.Serial && (choice == 3 || (choice >= 0 && choice < Current.Maps.Length)) && _eligible.Contains(voter) && (!_votes.TryGetValue(voter, out var value) || value != choice))
			{
				_votes[voter] = choice;
				_nextTally = 0f;
				_allInAt = -1f;
				Kit.Log("vote #" + serial + ": client " + voter + " -> " + ((choice == 3) ? "Random" : Current.Titles[choice]));
			}
		}

		public static bool Tick()
		{
			if (Current == null)
			{
				return true;
			}
			if (Open)
			{
				int[] counts = Counts();
				if (Time.unscaledTime >= _nextTally)
				{
					HashSet<int> live = Connections(SessionManager.Instance);
					live.IntersectWith(_eligible);
					_expected = Math.Max(1, live.Count);
					_votedLive = _votes.Keys.Count((int k) => live.Contains(k));
					_nextTally = Time.unscaledTime + 0.5f;
					VoteNet.SendTally(Current.Serial, counts, _votedLive, _expected, Voters());
				}
				if (_votedLive < _expected)
				{
					_allInAt = -1f;
				}
				else if (_allInAt < 0f)
				{
					_allInAt = Time.unscaledTime;
				}
				if (Time.unscaledTime >= ClosesAt || (_allInAt >= 0f && Time.unscaledTime >= _allInAt + 1.5f))
				{
					Close(counts);
				}
				return false;
			}
			return Time.unscaledTime >= ReleaseAt;
		}

		private static List<Voter> Voters()
		{
			List<Voter> list = new List<Voter>();
			SessionManager instance = SessionManager.Instance;
			foreach (KeyValuePair<int, int> vote in _votes)
			{
				Voter voter = new Voter();
				voter.ClientId = vote.Key;
				voter.Choice = vote.Value;
				if (_known.TryGetValue(vote.Key, out var value))
				{
					voter.Name = value.Name;
					voter.SteamId = value.SteamId;
				}
				else
				{
					NetworkConnection val = null;
					if ((Object)(object)instance != (Object)null && instance.serverPlayers != null)
					{
						foreach (PlayerController serverPlayer in instance.serverPlayers)
						{
							if (!((Object)(object)serverPlayer == (Object)null) && !(((NetworkBehaviour)serverPlayer).Owner == (NetworkConnection)null) && ((NetworkBehaviour)serverPlayer).Owner.ClientId == vote.Key)
							{
								val = ((NetworkBehaviour)serverPlayer).Owner;
								try
								{
									voter.Name = serverPlayer.DisplayNameWithoutTitle ?? "";
								}
								catch (Exception)
								{
									voter.Name = "";
								}
								break;
							}
						}
					}
					voter.SteamId = ((val != (NetworkConnection)null) ? SteamIdOf(val) : 0);
					if (val != (NetworkConnection)null)
					{
						_known[vote.Key] = voter;
					}
				}
				list.Add(voter);
			}
			return list;
		}

		private static ulong SteamIdOf(NetworkConnection conn)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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)
			try
			{
				if (conn.IsLocalClient)
				{
					return SteamAPI.IsSteamRunning() ? SteamUser.GetSteamID().m_SteamID : 0;
				}
				if (!_steamLooked)
				{
					_steamLooked = true;
					_steamOf = typeof(SessionManager).GetMethod("TryGetTransportSteamId", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (_steamOf == null)
				{
					if (!_warned)
					{
						_warned = true;
						Kit.Warn("TryGetTransportSteamId not found, voter chips show letters");
					}
					return 0uL;
				}
				object[] array = new object[2]
				{
					conn,
					(object)default(CSteamID)
				};
				object obj = (_steamOf.IsStatic ? null : SessionManager.Instance);
				if (!(bool)_steamOf.Invoke(obj, array))
				{
					return 0uL;
				}
				return ((CSteamID)array[1]).m_SteamID;
			}
			catch (Exception ex)
			{
				if (!_warned)
				{
					_warned = true;
					Kit.Warn("steam id lookup failed: " + ex.Message);
				}
				return 0uL;
			}
		}

		private static int[] Counts()
		{
			int[] array = new int[4];
			foreach (int value in _votes.Values)
			{
				array[value]++;
			}
			return array;
		}

		private static void Close(int[] counts)
		{
			Open = false;
			ReleaseAt = Time.unscaledTime + 2.5f;
			VoteNet.SendTally(Current.Serial, counts, _votedLive, _expected, Voters());
			int best = counts.Max();
			int num = -1;
			if (best > 0)
			{
				List<int> list = (from i in Enumerable.Range(0, 4)
					where counts[i] == best
					select i).ToList();
				num = list[_rng.Next(list.Count)];
			}
			LastChoice = num;
			LastScene = null;
			string text = "Random";
			if (num >= 0 && num < Current.Maps.Length)
			{
				MapEntry val = SessionContentRegistry.AllMaps[Current.Maps[num]];
				LastScene = val.scenes[_rng.Next(val.scenes.Length)];
				text = Current.Titles[num];
			}
			else if (num == 3 && _randomPool.Count > 0)
			{
				MapEntry val2 = _randomPool[_rng.Next(_randomPool.Count)];
				LastScene = val2.scenes[_rng.Next(val2.scenes.Length)];
				text = Title(val2);
			}
			VoteNet.SendResult(Current.Serial, (num < 0) ? 3 : num, text);
			Kit.Log("vote #" + Current.Serial + " closed after " + (Time.unscaledTime - OpenedAt).ToString("0.0") + " s: " + string.Join("/", counts.Select((int x) => x.ToString()).ToArray()) + " (" + _votes.Count + "/" + _expected + " voted) -> " + text + ((LastScene != null) ? (" (" + LastScene + ")") : " (the game picks)"));
		}

		public static void Apply(DisputeManager dm)
		{
			if (LastScene != null)
			{
				Reflect.Set(dm, "_overrideLevel", LastScene);
			}
			Current = null;
			Open = false;
		}

		public static void Reset()
		{
			Open = false;
			Current = null;
			_votes.Clear();
			_known.Clear();
			_randomPool = new List<MapEntry>();
		}
	}
	internal class VoteRunner : MonoBehaviour
	{
		private DisputeManager _dm;

		private bool _hooked;

		private bool _holding;

		private bool _roundEnded;

		private int _releasedFrame = -10;

		private DisputeRoundState? _heldPrev;

		private State<DisputeRoundState> _loading;

		private Action<DisputeRoundState?> _enterOrig;

		private Action<float, float> _updateOrig;

		private void OnEnable()
		{
			Kit.Context.Events.OnRoundEnd += OnRoundEnd;
		}

		private void OnDisable()
		{
			Kit.Context.Events.OnRoundEnd -= OnRoundEnd;
		}

		private void OnRoundEnd(RoundEvent e)
		{
			_roundEnded = true;
		}

		private void Update()
		{
			if (!InstanceFinder.IsServerStarted)
			{
				Lose();
				return;
			}
			DisputeManager instance = DisputeManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Lose();
				return;
			}
			if ((Object)(object)instance != (Object)(object)_dm)
			{
				Lose();
				_dm = instance;
				_hooked = false;
				_roundEnded = false;
				VoteServer.NewMatch();
			}
			StateMachine<DisputeRoundState> stateMachine = instance.StateMachine;
			if (stateMachine == null)
			{
				return;
			}
			if (!_hooked)
			{
				_hooked = true;
				try
				{
					Hook(instance, stateMachine);
				}
				catch (Exception ex)
				{
					Kit.Error("hook failed, the game picks maps as usual: " + ex.Message);
				}
			}
			if (_holding)
			{
				bool flag;
				try
				{
					flag = VoteServer.Tick() || Time.unscaledTime > VoteServer.ClosesAt + 2.5f + 3f;
				}
				catch (Exception ex2)
				{
					Kit.Error("vote failed: " + ex2);
					flag = true;
				}
				if (flag)
				{
					Release("vote over");
				}
			}
		}

		private void Hook(DisputeManager dm, StateMachine<DisputeRoundState> sm)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo field = typeof(DisputeManager).GetField("_overrideLevel", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(DisputeManager).GetField("_playedLevels", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null || field.FieldType != typeof(string) || field2 == null || field2.FieldType != typeof(HashSet<int>))
			{
				Kit.Error("DisputeManager changed (_overrideLevel / _playedLevels missing or retyped), no map vote");
				return;
			}
			Dictionary<DisputeRoundState, State<DisputeRoundState>> dictionary = (Dictionary<DisputeRoundState, State<DisputeRoundState>>)typeof(StateMachine<DisputeRoundState>).GetProperty("States", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetValue(sm, null);
			_loading = dictionary[(DisputeRoundState)8];
			_enterOrig = _loading.OnEnter;
			_loading.OnEnter = OnEnterLoading;
			_updateOrig = _loading.OnUpdate;
			_loading.OnUpdate = OnUpdateLoading;
			Kit.Log("hooked Loading (state now " + ((object)sm.CurrentState/*cast due to .constrained prefix*/).ToString() + ")");
		}

		private void OnEnterLoading(DisputeRoundState? prev)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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)
			try
			{
				VoteServer.Played(_dm.LevelIdx.Value);
			}
			catch (Exception)
			{
			}
			bool flag = false;
			try
			{
				flag = _dm.HasWon.Value;
			}
			catch (Exception)
			{
			}
			if (flag)
			{
				if (_roundEnded)
				{
					VoteServer.MatchWonSkips++;
					Kit.Log("match won, no vote for the post-match map");
				}
				VoteServer.NewMatch();
				_roundEnded = false;
				_enterOrig(prev);
				return;
			}
			if (prev == (DisputeRoundState?)6 && _roundEnded && VoteServer.Enabled)
			{
				bool flag2 = false;
				try
				{
					flag2 = VoteServer.TryOpen(_dm);
				}
				catch (Exception ex3)
				{
					Kit.Error("vote open failed: " + ex3);
				}
				if (flag2)
				{
					_holding = true;
					_heldPrev = prev;
					return;
				}
			}
			_enterOrig(prev);
		}

		private void OnUpdateLoading(float a, float b)
		{
			if (!_holding && Time.frameCount > _releasedFrame + 2 && _updateOrig != null)
			{
				_updateOrig(a, b);
			}
		}

		public void Release(string why)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			if (!_holding)
			{
				return;
			}
			_holding = false;
			_releasedFrame = Time.frameCount;
			Kit.Log("releasing Loading (" + why + ")");
			if ((Object)(object)_dm != (Object)null && _enterOrig != null && _dm.StateMachine != null && (int)_dm.StateMachine.CurrentState == 8)
			{
				try
				{
					VoteServer.Apply(_dm);
				}
				catch (Exception ex)
				{
					Kit.Error("vote apply failed: " + ex.Message);
				}
				_enterOrig(_heldPrev);
			}
			VoteServer.Reset();
		}

		public void Unhook()
		{
			try
			{
				if (_loading != null && _enterOrig != null)
				{
					_loading.OnEnter = _enterOrig;
				}
				if (_loading != null)
				{
					_loading.OnUpdate = _updateOrig;
				}
			}
			catch (Exception)
			{
			}
			_loading = null;
			_hooked = false;
		}

		private void Lose()
		{
			if (!((Object)(object)_dm == (Object)null))
			{
				_holding = false;
				VoteServer.Reset();
				Unhook();
				_dm = null;
			}
		}

		private void OnDestroy()
		{
			Unhook();
		}
	}
	public class VoteMouse : MonoBehaviour
	{
		public static int Hover = -1;

		private static VoteMouse _inst;

		private bool _active;

		private bool _savedVisible;

		private CursorLockMode _savedLock;

		private int _serial = -1;

		private readonly RectTransform[] _cards = (RectTransform[])(object)new RectTransform[4];

		public static void Install()
		{
			if (!((Object)(object)_inst != (Object)null))
			{
				_inst = Kit.Host.AddComponent<VoteMouse>();
			}
		}

		public static void Uninstall()
		{
			if ((Object)(object)_inst != (Object)null)
			{
				Object.Destroy((Object)(object)_inst);
			}
			_inst = null;
			Hover = -1;
		}

		private void Update()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (VoteHud.Ballot == null || !VoteHud.Showing || VoteHud.Winner >= 0)
			{
				Release();
				return;
			}
			if (!_active)
			{
				_active = true;
				_savedLock = Cursor.lockState;
				_savedVisible = Cursor.visible;
			}
			else if ((int)Cursor.lockState != 0 || !Cursor.visible)
			{
				_savedLock = Cursor.lockState;
				_savedVisible = Cursor.visible;
			}
			Unlock();
			if (VoteHud.Ballot.Serial != _serial || NeedCards())
			{
				FindCards();
			}
			Hover = -1;
			Mouse current = Mouse.current;
			if (current == null)
			{
				return;
			}
			Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
			for (int i = 0; i < _cards.Length; i++)
			{
				RectTransform val2 = _cards[i];
				if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(val2, val, (Camera)null))
				{
					Hover = i;
					break;
				}
			}
			if (Hover >= 0 && current.leftButton.wasPressedThisFrame)
			{
				VoteHud.Vote((Hover < VoteHud.Ballot.Maps.Length) ? Hover : 3);
			}
		}

		private void LateUpdate()
		{
			if (_active)
			{
				Unlock();
			}
		}

		private void OnDestroy()
		{
			Release();
		}

		private static void Unlock()
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		private void Release()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Hover = -1;
			if (_active)
			{
				_active = false;
				Cursor.lockState = _savedLock;
				Cursor.visible = _savedVisible;
			}
		}

		private bool NeedCards()
		{
			for (int i = 0; i < _cards.Length; i++)
			{
				if ((Object)(object)_cards[i] == (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private void FindCards()
		{
			_serial = VoteHud.Ballot.Serial;
			GameObject val = GameObject.Find("MapVoteHud");
			for (int i = 0; i < _cards.Length; i++)
			{
				_cards[i] = null;
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform[] componentsInChildren = val.GetComponentsInChildren<RectTransform>(true);
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				string name = ((Object)componentsInChildren[j]).name;
				if (name.Length == 5 && name.StartsWith("Card") && name[4] >= '0' && name[4] <= '3')
				{
					_cards[name[4] - 48] = componentsInChildren[j];
				}
			}
		}
	}
	public static class VoteSfx
	{
		private static readonly string[] Files = new string[5] { "deal", "vote", "tick", "drum", "crown" };

		private static readonly HashSet<string> _warned = new HashSet<string>();

		public static void Preload()
		{
			for (int i = 0; i < Files.Length; i++)
			{
				string f = Files[i];
				Kit.Try("sfx preload " + f, delegate
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					Sfx.Load(Path(f), threeD: false);
				});
			}
		}

		public static void Deal(int slot)
		{
			Play("deal", 0.7f, 1f + 0.03f * (float)slot);
		}

		public static void Vote(bool mine)
		{
			Play("vote", mine ? 0.9f : 0.5f, mine ? 1f : 1.08f);
		}

		public static void Tick(int secondsLeft)
		{
			Play("tick", 0.6f, (secondsLeft <= 1) ? 1.15f : 1f);
		}

		public static void Drum()
		{
			Play("drum", 0.8f, 1f);
		}

		public static void Crown()
		{
			Play("crown", 0.9f, 1f);
		}

		private static string Path(string name)
		{
			return "sounds/" + name + ".wav";
		}

		private static void Play(string name, float volume, float pitch)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			string relative = Path(name);
			try
			{
				Sfx.Play2D(relative, volume, pitch);
			}
			catch (Exception ex)
			{
				if (_warned.Add(name))
				{
					Kit.Warn("ballot sound " + name + ": " + ex.Message);
				}
			}
		}
	}
}
namespace AGDKit
{
	public static class Anim
	{
		public static class Slots
		{
			public const string Idle = "root|Idle-NonOrnate";

			public const string Move = "root|ForwardMovement(ArmsTest2)";

			public const string Aim = "Aiming_NoItem";

			public const string Use = "Using_NoItem";

			public const string UsePhase2 = "UsingPhase2_NoItem";

			public const string UsePhase3 = "UsingPhase3_NoItem";
		}

		public static AnimationClip Clip(string itemName, string slot)
		{
			Item val = Kit.FindItem(itemName);
			if ((Object)(object)val == (Object)null || (Object)(object)val.OverrideController == (Object)null)
			{
				Kit.Warn("Anim.Clip: no item/controller " + itemName);
				return null;
			}
			List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			val.OverrideController.GetOverrides(list);
			foreach (KeyValuePair<AnimationClip, AnimationClip> item in list)
			{
				if ((Object)(object)item.Key != (Object)null && ((Object)item.Key).name == slot)
				{
					return item.Value ?? item.Key;
				}
			}
			Kit.Warn("Anim.Clip: slot " + slot + " not found on " + itemName);
			return null;
		}

		public static AnimatorOverrideController Override(AnimatorOverrideController baseOc, Dictionary<string, AnimationClip> slots, string name)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			AnimatorOverrideController val = new AnimatorOverrideController(baseOc.runtimeAnimatorController);
			((Object)val).name = name;
			List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			baseOc.GetOverrides(list);
			for (int i = 0; i < list.Count; i++)
			{
				if ((Object)(object)list[i].Key != (Object)null && slots.TryGetValue(((Object)list[i].Key).name, out var value) && (Object)(object)value != (Object)null)
				{
					list[i] = new KeyValuePair<AnimationClip, AnimationClip>(list[i].Key, value);
				}
			}
			val.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
			foreach (string s in slots.Keys)
			{
				if (!list.Any((KeyValuePair<AnimationClip, AnimationClip> p) => (Object)(object)p.Key != (Object)null && ((Object)p.Key).name == s))
				{
					Kit.Warn("Anim.Override: unknown slot " + s);
				}
			}
			return val;
		}
	}
	public class Spin : MonoBehaviour
	{
		public Vector3 Axis = Vector3.up;

		public float Speed = 360f;

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.Rotate(Axis, Speed * Time.deltaTime, (Space)1);
		}
	}
	public class Bob : MonoBehaviour
	{
		public Vector3 Direction = Vector3.up;

		public float Amplitude = 0.05f;

		public float Frequency = 1.5f;

		private Vector3 _start;

		private void Awake()
		{
			//IL_0007: 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)
			_start = ((Component)this).transform.localPosition;
		}

		private void Update()
		{
			//IL_0007: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localPosition = _start + Direction * Mathf.Sin(Time.time * Frequency * (float)Math.PI * 2f) * Amplitude;
		}
	}
	public class Glow : MonoBehaviour
	{
		public Color Color = Color.cyan;

		public float Min = 0.5f;

		public float Max = 2f;

		public float Frequency = 1f;

		private Material _m;

		private void Awake()
		{
			Renderer component = ((Component)this).GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				_m = component.material;
				_m.EnableKeyword("_EMISSION");
			}
		}

		private void Update()
		{
			//IL_0056: 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)
			if (!((Object)(object)_m == (Object)null))
			{
				float num = Mathf.Lerp(Min, Max, 0.5f + 0.5f * Mathf.Sin(Time.time * Frequency * (float)Math.PI * 2f));
				_m.SetColor("_EmissionColor", Color * num);
			}
		}
	}
	public static class Lights
	{
		public static Light Point(Transform parent, Color color, float intensity = 1.5f, float range = 3f)
		{
			//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_0024: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Light");
			val.transform.SetParent(parent, false);
			Light obj = val.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = color;
			obj.intensity = intensity;
			obj.range = range;
			obj.shadows = (LightShadows)0;
			return obj;
		}
	}
	public static class Art
	{
		private static readonly Dictionary<string, Texture2D> _tex = new Dictionary<string, Texture2D>();

		public static Texture2D Texture(string relative, bool linear = false)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			if (_tex.TryGetValue(relative, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string text = Kit.Asset(relative);
			if (!File.Exists(text))
			{
				Kit.Warn("missing texture " + text);
				return null;
			}
			value = new Texture2D(2, 2, (TextureFormat)4, true, linear);
			ImageConversion.LoadImage(value, File.ReadAllBytes(text), false);
			((Object)value).name = Path.GetFileNameWithoutExtension(text);
			((Texture)value).wrapMode = (TextureWrapMode)0;
			((Texture)value).filterMode = (FilterMode)2;
			((Texture)value).anisoLevel = 4;
			_tex[relative] = value;
			return value;
		}

		public static Sprite Sprite(string relative, float pixelsPerUnit = 50f)
		{
			//IL_0033: 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)
			Texture2D val = Texture(relative);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
			((Object)obj).name = ((Object)val).name;
			return obj;
		}

		public static Texture2D ReadableCopy(Sprite src)
		{
			//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_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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			//IL_009d: Expected O, but got Unknown
			Rect val;
			try
			{
				val = src.textureRect;
			}
			catch
			{
				val = src.rect;
			}
			Texture2D texture = src.texture;
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			Graphics.Blit((Texture)(object)texture, temporary);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			int num = Mathf.RoundToInt(((Rect)(ref val)).width);
			int num2 = Mathf.RoundToInt(((Rect)(ref val)).height);
			Texture2D val2 = new Texture2D(num, num2, (TextureFormat)4, false);
			val2.ReadPixels(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, (float)num, (float)num2), 0, 0);
			val2.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val2;
		}

		public static Sprite Recolor(Sprite src, Color tint, string name)
		{
			//IL_0022: 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_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			//IL_00bb: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)src == (Object)null)
			{
				return null;
			}
			Texture2D val = ReadableCopy(src);
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				Color val2 = pixels[i];
				float num = Mathf.Max(val2.r, Mathf.Max(val2.g, val2.b)) * 0.6f + (val2.r + val2.g + val2.b) / 3f * 0.4f;
				Color val3 = Color.Lerp(val2, new Color(tint.r * num * 1.35f, tint.g * num * 1.35f, tint.b * num * 1.35f), 0.7f);
				val3.a = val2.a;
				pixels[i] = val3;
			}
			val.SetPixels(pixels);
			val.Apply();
			((Object)val).name = name;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), src.pixelsPerUnit);
			((Object)obj).name = name;
			return obj;
		}

		public static void SavePng(Texture2D t, string path)
		{
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			File.WriteAllBytes(path, ImageConversion.EncodeToPNG(t));
		}
	}
	public static class Bundles
	{
		private static readonly Dictionary<string, AssetBundle> _loaded = new Dictionary<string, AssetBundle>();

		public static BundleRef Load(string relative)
		{
			if (!_loaded.TryGetValue(relative, out var value) || (Object)(object)value == (Object)null)
			{
				string text = Kit.Asset(relative);
				if (!File.Exists(text))
				{
					Kit.Warn("missing bundle " + text);
					return new BundleRef(null);
				}
				string want = Path.GetFileName(text).ToLowerInvariant();
				value = AssetBundle.GetAllLoadedAssetBundles().FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle x) => ((Object)x).name == want)) ?? AssetBundle.LoadFromFile(text);
				if ((Object)(object)value == (Object)null)
				{
					Kit.Warn("could not load bundle " + text + " (built with a different Unity version?)");
					return new BundleRef(null);
				}
				if (_loaded.Count == 0)
				{
					Kit.OnShutdown(delegate
					{
						foreach (AssetBundle value2 in _loaded.Values)
						{
							if ((Object)(object)value2 != (Object)null)
							{
								value2.Unload(false);
							}
						}
						_loaded.Clear();
					});
				}
				_loaded[relative] = value;
			}
			return new BundleRef(value);
		}
	}
	public class BundleRef
	{
		public readonly AssetBundle Bundle;

		public BundleRef(AssetBundle b)
		{
			Bundle = b;
		}

		public T Asset<T>(string name) where T : Object
		{
			if ((Object)(object)Bundle == (Object)null)
			{
				return default(T);
			}
			T val = Bundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Kit.Warn("bundle " + ((Object)Bundle).name + " has no " + typeof(T).Name + " '" + name + "'. Contains: " + string.Join(", ", Bundle.GetAllAssetNames()));
			}
			return val;
		}

		public GameObject Prefab(string name)
		{
			GameObject val = this.Asset<GameObject>(name);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, Kit.Templates);
			((Object)val2).name = name;
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = val3.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					sharedMaterials[j] = FixMaterial(sharedMaterials[j]);
				}
				val3.sharedMaterials = sharedMaterials;
			}
			return val2;
		}

		public static Material FixMaterial(Material m)
		{
			//IL_00ee: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: 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_01b4: 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)
			if ((Object)(object)m == (Object)null || (Object)(object)m.shader == (Object)null)
			{
				return m;
			}
			Shader val = Shader.Find(((Object)m.shader).name);
			if (!(((Object)m.shader).name == "Standard") && !((Object)m.shader).name.StartsWith("Standard (") && !((Object)m.shader).name.StartsWith("Legacy Shaders/") && !((Object)m.shader).name.StartsWith("Mobile/") && !((Object)m.shader).name.StartsWith("Autodesk") && (Object)(object)val != (Object)null && val.isSupported)
			{
				m.shader = val;
				return m;
			}
			Color color = (m.HasProperty("_BaseColor") ? m.GetColor("_BaseColor") : (m.HasProperty("_Color") ? m.GetColor("_Color") : Color.white));
			Texture val2 = (m.HasProperty("_BaseMap") ? m.GetTexture("_BaseMap") : (m.HasProperty("_MainTex") ? m.GetTexture("_MainTex") : null));
			float metallic = (m.HasProperty("_Metallic") ? m.GetFloat("_Metallic") : 0f);
			float smoothness = (m.HasProperty("_Smoothness") ? m.GetFloat("_Smoothness") : (m.HasProperty("_Glossiness") ? m.GetFloat("_Glossiness") : 0.3f));
			Color emission = ((m.IsKeywordEnabled("_EMISSION") && m.HasProperty("_EmissionColor")) ? m.GetColor("_EmissionColor") : Color.black);
			Material val3 = Models.Material(color, null, smoothness, metallic, emission);
			if ((Object)(object)val2 != (Object)null)
			{
				val3.SetTexture("_BaseMap", val2);
			}
			((Object)val3).name = ((Object)m).name + " (URP)";
			Kit.Log("bundle material '" + ((Object)m).name + "' used " + ((Object)m.shader).name + " -> converted to URP/Lit");
			return val3;
		}

		public AnimationClip Clip(string name)
		{
			return this.Asset<AnimationClip>(name);
		}

		public Texture2D Texture(string name)
		{
			return this.Asset<Texture2D>(name);
		}

		public Sprite Sprite(string name)
		{
			return this.Asset<Sprite>(name);
		}
	}
	public static class Kit
	{
		private static readonly List<Action> _cleanup = new List<Action>();

		private static GameObject _host;

		public static IModContext Context { get; private set; }

		public static string ModId { get; private set; }

		public static string Root { get; private set; }

		public static string DataDir { get; private set; }

		public static GameObject Host
		{
			get
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				if ((Object)(object)_host == (Object)null)
				{
					_host = new GameObject("AGDKit_" + ModId);
					Object.DontDestroyOnLoad((Object)(object)_host);
				}
				return _host;
			}
		}

		public static Transform Templates
		{
			get
			{
				//IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references)
				Transform val = Host.transform.Find("Templates");
				if ((Object)(object)val == (Object)null)
				{
					GameObject val2 = new GameObject("Templates");
					val2.SetActive(false);
					val2.transform.SetParent(Host.transform, false);
					val = val2.transform;
				}
				return val;
			}
		}

		public static GameDesignData Design => GameSingleton.GameDesignData;

		public static void Init(IModContext context)
		{
			Context = context;
			ModId = context.ModId;
			Root = context.InstallPath;
			DataDir = Path.Combine(Path.Combine(Application.persistentDataPath, "ModData"), ModId);
			Directory.CreateDirectory(DataDir);
			_cleanup.Clear();
		}

		public static void Shutdown()
		{
			for (int num = _cleanup.Count - 1; num >= 0; num--)
			{
				try
				{
					_cleanup[num]();
				}
				catch (Exception ex)
				{
					Error("cleanup: " + ex);
				}
			}
			_cleanup.Clear();
			if ((Object)(object)_host != (Object)null)
			{
				Object.Destroy((Object)(object)_host);
			}
			_host = null;
		}

		public static void OnShutdown(Action a)
		{
			_cleanup.Add(a);
		}

		public static string Asset(string relative)
		{
			return Path.Combine(Path.Combine(Root, "assets"), relative.Replace('/', Path.DirectorySeparatorChar));
		}

		public static Item FindItem(string name)
		{
			return ((IEnumerable<Item>)Design.itemList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && ((Object)i).name == name));
		}

		public static Perk FindPerk(string name)
		{
			return ((IEnumerable<Perk>)Design.perks).FirstOrDefault((Func<Perk, bool>)((Perk p) => (Object)(object)p != (Object)null && ((Object)p).name == name));
		}

		public static ItemTag Tag(string name)
		{
			return ((IEnumerable<ItemTag>)Design.itemTagList).FirstOrDefault((Func<ItemTag, bool>)((ItemTag t) => (Object)(object)t != (Object)null && ((Object)t).name == name));
		}

		public static void Log(string msg)
		{
			Debug.Log((object)("[" + ModId + "] " + msg));
		}

		public static void Warn(string msg)
		{
			Debug.LogWarning((object)("[" + ModId + "] " + msg));
		}

		public static void Error(string msg)
		{
			Debug.LogError((object)("[" + ModId + "] " + msg));
		}

		public static void Try(string what, Action fn)
		{
			try
			{
				fn();
			}
			catch (Exception ex)
			{
				Error(what + " failed: " + ex);
			}
		}
	}
	public static class Reflect
	{
		private const BindingFlags F = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Dictionary<KeyValuePair<Type, string>, FieldInfo> FieldCache = new Dictionary<KeyValuePair<Type, string>, FieldInfo>();

		private static FieldInfo Field(Type type, string name)
		{
			KeyValuePair<Type, string> key = new KeyValuePair<Type, string>(type, name);
			if (FieldCache.TryGetValue(key, out var value))
			{
				return value;
			}
			Type type2 = type;
			while (type2 != null && value == null)
			{
				value = type2.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				type2 = type2.BaseType;
			}
			FieldCache[key] = value;
			return value;
		}

		public static bool Has(object o, string field)
		{
			if (o != null)
			{
				return Field(o.GetType(), field) != null;
			}
			return false;
		}

		public static void Set(object o, string field, object value)
		{
			FieldInfo fieldInfo = Field(o.GetType(), field);
			if (fieldInfo == null)
			{
				Kit.Warn("no field " + o.GetType().Name + "." + field);
				return;
			}
			if (value != null && !fieldInfo.FieldType.IsInstanceOfType(value))
			{
				value = Convert.ChangeType(value, fieldInfo.FieldType);
			}
			fieldInfo.SetValue(o, value);
		}

		public static T Get<T>(object o, string field)
		{
			FieldInfo fieldInfo = ((o == null) ? null : Field(o.GetType(), field));
			if (!(fieldInfo == null))
			{
				return (T)fieldInfo.GetValue(o);
			}
			return default(T);
		}

		public static object Call(object o, string method, params object[] args)
		{
			Type type = o.GetType();
			while (type != null)
			{
				MethodInfo methodInfo = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo x) => x.Name == method && x.GetParameters().Length == args.Length);
				if (methodInfo != null)
				{
					return methodInfo.Invoke(o, args);
				}
				type = type.BaseType;
			}
			throw new MissingMethodException(o.GetType().Name, method);
		}
	}
	public static class Models
	{
		private static Material _base;

		public static Material Material(Color color, string texture = null, float smoothness = 0.3f, float metallic = 0f, Color emission = default(Color), string normalMap = null)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_008b: 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_0068: 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)
			if ((Object)(object)_base == (Object)null)
			{
				Item val = Kit.FindItem("Sword");
				Renderer val2 = (((Object)(object)val != (Object)null) ? ((IEnumerable<Renderer>)val.prefab.GetComponentsInChildren<Renderer>(true)).FirstOrDefault((Func<Renderer, bool>)((Renderer x) => (Object)(object)x.sharedMaterial != (Object)null && ((Object)x.sharedMaterial.shader).name == "Universal Render Pipeline/Lit")) : null);
				_base = (Material)(((Object)(object)val2 != (Object)null) ? ((object)val2.sharedMaterial) : ((object)new Material(Shader.Find("Universal Render Pipeline/Lit"))));
			}
			Material val3 = new Material(_base);
			((Object)val3).name = "kit_" + ColorUtility.ToHtmlStringRGB(color);
			val3.SetTexture("_BaseMap", (Texture)(object)((texture != null) ? Art.Texture(texture) : null));
			val3.SetColor("_BaseColor", color);
			val3.SetTexture("_MetallicGlossMap", (Texture)null);
			val3.DisableKeyword("_METALLICSPECGLOSSMAP");
			val3.SetFloat("_Metallic", metallic);
			val3.SetFloat("_Smoothness", smoothness);
			val3.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
			if (normalMap != null)
			{
				val3.SetTexture("_BumpMap", (Texture)(object)Art.Texture(normalMap, linear: true));
				val3.EnableKeyword("_NORMALMAP");
			}
			else
			{
				val3.SetTexture("_BumpMap", (Texture)null);
				val3.DisableKeyword("_NORMALMAP");
			}
			if (((Color)(ref emission)).maxColorComponent > 0f)
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", emission);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			return val3;
		}

		public static List<Renderer> WeaponRenderers(GameObject prefab)
		{
			HashSet<Transform> debug = DebugObjects(prefab);
			return (from r in prefab.GetComponentsInChildren<Renderer>(true)
				where (r is MeshRenderer || r is SkinnedMeshRenderer) && ActiveInPrefab(((Component)r).transform, prefab.transform) && !r.sharedMaterials.Any((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && ((Object)m.shader).name.Contains("Ghost")) && !PathContains(((Component)r).transform, prefab.transform, "Aim Indicator") && !UnderAny(((Component)r).transform, prefab.transform, debug)
				select r).ToList();
		}

		public static HashSet<Transform> DebugObjects(GameObject prefab)
		{
			HashSet<Transform> hashSet = new HashSet<Transform>();
			MonoBehaviour[] componentsInChildren = prefab.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Type type = ((object)val).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (fieldInfo.Name.IndexOf("debug", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							object? value = fieldInfo.GetValue(val);
							Transform val2 = (Transform)((value is Transform) ? value : null);
							GameObject val3 = (GameObject)((value is GameObject) ? value : null);
							if ((Object)(object)val2 != (Object)null)
							{
								hashSet.Add(val2);
							}
							else if ((Object)(object)val3 != (Object)null)
							{
								hashSet.Add(val3.transform);
							}
						}
					}
					type = type.BaseType;
				}
			}
			return hashSet;
		}

		private static bool ActiveInPrefab(Transform t, Transform root)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
			{
				if (!((Component)t).gameObject.activeSelf)
				{
					return false;
				}
				t = t.parent;
			}
			return true;
		}

		private static bool UnderAny(Transform t, Transform root, HashSet<Transform> set)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
			{
				if (set.Contains(t))
				{
					return true;