Decompiled source of MonsterRoulette v3.0.0

MonsterRoulette.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MonsterRoulette.Config;
using MonsterRoulette.Core;
using MonsterRoulette.Events;
using MonsterRoulette.Network;
using MonsterRoulette.Spawning;
using MonsterRoulette.UI;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Rendering;

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

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MonsterRoulette
{
	[BepInPlugin("ThomasPlays.MonsterRoulette", "MonsterRoulette", "3.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "ThomasPlays.MonsterRoulette";

		public const string PluginName = "MonsterRoulette";

		public const string PluginVersion = "3.0.0";

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_005f: 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_00c0: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			RouletteConfig.Init(((BaseUnityPlugin)this).Config);
			RouletteNetwork.Register();
			new Harmony("ThomasPlays.MonsterRoulette").PatchAll(typeof(Plugin).Assembly);
			GameObject val = new GameObject("MonsterRoulette");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<RouletteAudio>();
			val.AddComponent<RouletteUI>();
			val.AddComponent<RouletteDirector>();
			val.AddComponent<RoundStartListener>();
			Commands.RegisterCommand(new ChatCommand("roulette", "Start the Monster Roulette now (host only). '/roulette portraits' saves all monster portraits as PNG.", (Action<bool, string[]>)delegate(bool isConsole, string[] args)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				if (args != null && args.Length != 0 && args[0].ToLowerInvariant() == "portraits")
				{
					string folder;
					int num = PortraitCache.ExportAll(out folder);
					SemiFunc.UIFocusText($"Saved {num} portraits to BepInEx/MonsterRoulette/portraits", Color.white, Color.green, 4f);
				}
				else
				{
					RouletteDirector.Instance?.TryStartManual();
				}
			}, (Func<bool, string, string[], List<string>>)null, (Func<bool>)(() => true), false));
			Log.LogInfo((object)("MonsterRoulette 3.0.0 loaded. Config: " + RouletteConfig.FilePath));
		}
	}
}
namespace MonsterRoulette.UI
{
	internal static class PortraitCache
	{
		private const int Size = 256;

		private const int StudioLayer = 31;

		private static readonly Vector3 StudioPos = new Vector3(0f, -4000f, 0f);

		private static readonly Dictionary<string, Texture2D> Portraits = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase);

		private static readonly HashSet<string> Failed = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static Queue<KeyValuePair<string, EnemySetup>> _todo;

		public static Texture2D Get(string name)
		{
			if (name != null && Portraits.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			return null;
		}

		public static void WarmUpStep()
		{
			if (_todo == null)
			{
				if ((Object)(object)EnemyDirector.instance == (Object)null)
				{
					return;
				}
				_todo = new Queue<KeyValuePair<string, EnemySetup>>();
				foreach (KeyValuePair<string, EnemySetup> item in MonsterCatalog.AllEnemies())
				{
					if (!Portraits.ContainsKey(item.Key) && !Failed.Contains(item.Key))
					{
						_todo.Enqueue(item);
					}
				}
			}
			if (_todo.Count == 0)
			{
				return;
			}
			KeyValuePair<string, EnemySetup> keyValuePair = _todo.Dequeue();
			if (!Portraits.ContainsKey(keyValuePair.Key) && !Failed.Contains(keyValuePair.Key))
			{
				Texture2D val = null;
				try
				{
					val = Render(keyValuePair.Value);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogDebug((object)("Portrait for " + keyValuePair.Key + " failed: " + ex.Message));
				}
				if ((Object)(object)val != (Object)null)
				{
					Portraits[keyValuePair.Key] = val;
				}
				else
				{
					Failed.Add(keyValuePair.Key);
				}
			}
		}

		public static void ResetQueue()
		{
			_todo = null;
		}

		public static void EnsureAll(string[] names)
		{
			if (names == null)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(names, StringComparer.OrdinalIgnoreCase);
			foreach (KeyValuePair<string, EnemySetup> item in MonsterCatalog.AllEnemies())
			{
				if (hashSet.Contains(item.Key) && !Portraits.ContainsKey(item.Key) && !Failed.Contains(item.Key))
				{
					Texture2D val = null;
					try
					{
						val = Render(item.Value);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogDebug((object)("Portrait for " + item.Key + " failed: " + ex.Message));
					}
					if ((Object)(object)val != (Object)null)
					{
						Portraits[item.Key] = val;
					}
					else
					{
						Failed.Add(item.Key);
					}
				}
			}
		}

		public static int ExportAll(out string folder)
		{
			folder = Path.Combine(Paths.BepInExRootPath, "MonsterRoulette", "portraits");
			Directory.CreateDirectory(folder);
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, EnemySetup> item in MonsterCatalog.AllEnemies())
			{
				list.Add(item.Key);
			}
			EnsureAll(list.ToArray());
			int num = 0;
			foreach (string item2 in list)
			{
				Texture2D val = Get(item2);
				if (!((Object)(object)val == (Object)null))
				{
					string path = string.Join("_", item2.Split(Path.GetInvalidFileNameChars())) + ".png";
					File.WriteAllBytes(Path.Combine(folder, path), ImageConversion.EncodeToPNG(val));
					num++;
				}
			}
			string text = string.Join(", ", Failed);
			Plugin.Log.LogInfo((object)string.Format("MonsterRoulette: saved {0} portraits to {1}. No portrait: {2}", num, folder, (text.Length > 0) ? text : "-"));
			return num;
		}

		private static Texture2D Render(EnemySetup setup)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_002b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			EnemyParent val = MonsterCatalog.FindEnemyParent(setup);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = new GameObject("MR_PortraitStudio")
			{
				hideFlags = (HideFlags)61
			};
			val2.transform.position = StudioPos;
			try
			{
				List<Renderer> list = BuildPosedCopy(val, val2.transform, ((Object)setup).name);
				if (list == null || list.Count == 0)
				{
					list = BuildMeshCopy(val, val2.transform);
				}
				if (list.Count == 0)
				{
					return null;
				}
				Bounds bounds = MainBounds(list);
				return Photograph(val2, bounds, ViewFor(((Object)setup).name));
			}
			finally
			{
				Object.DestroyImmediate((Object)(object)val2);
			}
		}

		private static List<Renderer> BuildPosedCopy(EnemyParent parent, Transform studio, string setupName)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)parent).gameObject;
			string text = (((Object)(object)parent.EnableObject != (Object)null) ? PathTo(gameObject.transform, parent.EnableObject.transform) : null);
			bool activeSelf = gameObject.activeSelf;
			GameObject val;
			try
			{
				gameObject.SetActive(false);
				val = Object.Instantiate<GameObject>(gameObject, studio);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Portrait clone of " + setupName + " failed: " + ex.Message));
				return null;
			}
			finally
			{
				gameObject.SetActive(activeSelf);
			}
			((Object)val).hideFlags = (HideFlags)61;
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			for (int i = 0; i < 4; i++)
			{
				bool flag = false;
				Component[] componentsInChildren = val.GetComponentsInChildren<Component>(true);
				foreach (Component val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && !(val2 is Transform) && !(val2 is MeshFilter) && !(val2 is MeshRenderer) && !(val2 is SkinnedMeshRenderer) && !(val2 is Animator))
					{
						try
						{
							Object.DestroyImmediate((Object)(object)val2);
							flag = true;
						}
						catch
						{
						}
					}
				}
				if (!flag)
				{
					break;
				}
			}
			if (text != null)
			{
				Transform val3 = ((text.Length == 0) ? val.transform : val.transform.Find(text));
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.SetActive(true);
				}
			}
			Transform[] componentsInChildren2 = val.GetComponentsInChildren<Transform>(true);
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				((Component)componentsInChildren2[j]).gameObject.layer = 31;
			}
			val.SetActive(true);
			Animator[] componentsInChildren3 = val.GetComponentsInChildren<Animator>();
			foreach (Animator val4 in componentsInChildren3)
			{
				try
				{
					val4.fireEvents = false;
					val4.cullingMode = (AnimatorCullingMode)0;
					val4.Update(0f);
					val4.Update(0.25f);
				}
				catch
				{
				}
			}
			List<Renderer> list = new List<Renderer>();
			Renderer[] componentsInChildren4 = val.GetComponentsInChildren<Renderer>();
			foreach (Renderer val5 in componentsInChildren4)
			{
				if (!val5.enabled || !((Component)val5).gameObject.activeInHierarchy || IsEffect(val5))
				{
					val5.enabled = false;
					continue;
				}
				SkinnedMeshRenderer val6 = (SkinnedMeshRenderer)(object)((val5 is SkinnedMeshRenderer) ? val5 : null);
				if (val6 != null)
				{
					val6.updateWhenOffscreen = true;
				}
				val5.shadowCastingMode = (ShadowCastingMode)0;
				val5.receiveShadows = false;
				list.Add(val5);
			}
			return list;
		}

		private static List<Renderer> BuildMeshCopy(EnemyParent parent, Transform studio)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			List<Renderer> list = new List<Renderer>();
			Transform transform = ((Component)parent).transform;
			Matrix4x4 worldToLocalMatrix = transform.worldToLocalMatrix;
			Renderer[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Mesh val2 = null;
				SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
				if (val3 != null)
				{
					val2 = val3.sharedMesh;
				}
				else if (val is MeshRenderer)
				{
					MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
					if ((Object)(object)component != (Object)null)
					{
						val2 = component.sharedMesh;
					}
				}
				if (!((Object)(object)val2 == (Object)null) && val.enabled && !IsEffect(val) && ActiveBelow(((Component)val).transform, ((Object)(object)parent.EnableObject != (Object)null) ? parent.EnableObject.transform : transform))
				{
					GameObject val4 = new GameObject("part")
					{
						hideFlags = (HideFlags)61,
						layer = 31
					};
					val4.transform.SetParent(studio, false);
					Matrix4x4 val5 = worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
					val4.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val5)).GetColumn(3));
					val4.transform.localRotation = ((Matrix4x4)(ref val5)).rotation;
					val4.transform.localScale = ((Matrix4x4)(ref val5)).lossyScale;
					val4.AddComponent<MeshFilter>().sharedMesh = val2;
					MeshRenderer val6 = val4.AddComponent<MeshRenderer>();
					((Renderer)val6).sharedMaterials = val.sharedMaterials;
					((Renderer)val6).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)val6).receiveShadows = false;
					list.Add((Renderer)(object)val6);
				}
			}
			return list;
		}

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

		private static string PathTo(Transform root, Transform target)
		{
			if ((Object)(object)target == (Object)(object)root)
			{
				return "";
			}
			List<string> list = new List<string>();
			Transform val = target;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				list.Insert(0, ((Object)val).name);
				val = val.parent;
			}
			return string.Join("/", list);
		}

		private static Vector3 ViewFor(string setupName)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			string text = (setupName ?? "").ToLowerInvariant();
			if (text.Contains("ceiling") || text.Contains("peeper"))
			{
				return Quaternion.Euler(50f, -20f, 0f) * Vector3.forward;
			}
			if (text.Contains("tick") || text.Contains("gnome") || text.Contains("head grab") || text.Contains("headgrab"))
			{
				return Quaternion.Euler(-30f, -25f, 0f) * Vector3.forward;
			}
			return Quaternion.Euler(-12f, -28f, 0f) * Vector3.forward;
		}

		private static bool IsEffect(Renderer r)
		{
			string text = ((Object)((Component)r).gameObject).name.ToLowerInvariant();
			if (text.Contains("debug") || text.Contains("collision") || text.Contains("effect") || text.Contains("particle") || text.Contains("death") || text.Contains("gib") || text.Contains("trigger"))
			{
				return true;
			}
			Material[] sharedMaterials = r.sharedMaterials;
			foreach (Material val in sharedMaterials)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null))
				{
					string text2 = ((Object)val.shader).name.ToLowerInvariant();
					if (text2.Contains("particle") || text2.Contains("additive"))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static Bounds MainBounds(List<Renderer> renderers)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			Bounds bounds;
			foreach (Renderer renderer in renderers)
			{
				bounds = renderer.bounds;
				list.Add(((Bounds)(ref bounds)).center);
			}
			List<float> list2 = list.ConvertAll((Vector3 c) => c.x);
			list2.Sort();
			List<float> list3 = list.ConvertAll((Vector3 c) => c.y);
			list3.Sort();
			List<float> list4 = list.ConvertAll((Vector3 c) => c.z);
			list4.Sort();
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(list2[list2.Count / 2], list3[list3.Count / 2], list4[list4.Count / 2]);
			Bounds? val2 = null;
			foreach (Renderer renderer2 in renderers)
			{
				bounds = renderer2.bounds;
				if (!(Vector3.Distance(((Bounds)(ref bounds)).center, val) > 4f))
				{
					bounds = renderer2.bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					if (!(((Vector3)(ref size)).magnitude > 12f))
					{
						if (!val2.HasValue)
						{
							val2 = renderer2.bounds;
							continue;
						}
						Bounds value = val2.Value;
						((Bounds)(ref value)).Encapsulate(renderer2.bounds);
						val2 = value;
						continue;
					}
				}
				renderer2.enabled = false;
			}
			return (Bounds)(((??)val2) ?? renderers[0].bounds);
		}

		private static Texture2D Photograph(GameObject studio, Bounds bounds, Vector3 dir)
		{
			//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)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010e: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: 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_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			Vector3 extents = ((Bounds)(ref bounds)).extents;
			float num = Mathf.Max(0.2f, ((Vector3)(ref extents)).magnitude);
			float num2 = num / Mathf.Sin(MathF.PI / 12f) * 1.02f;
			GameObject val = new GameObject("MR_PortraitCam")
			{
				hideFlags = (HideFlags)61
			};
			val.transform.SetParent(studio.transform, false);
			val.transform.position = ((Bounds)(ref bounds)).center + dir * num2;
			val.transform.LookAt(((Bounds)(ref bounds)).center);
			Camera val2 = val.AddComponent<Camera>();
			((Behaviour)val2).enabled = false;
			val2.cullingMask = int.MinValue;
			val2.clearFlags = (CameraClearFlags)2;
			val2.backgroundColor = new Color(0f, 0f, 0f, 0f);
			val2.fieldOfView = 30f;
			val2.nearClipPlane = 0.01f;
			val2.farClipPlane = num2 + num * 4f;
			val2.allowHDR = false;
			val2.allowMSAA = true;
			AddLight(studio, Quaternion.LookRotation(-dir + Vector3.down * 0.4f + Vector3.right * 0.5f), new Color(1f, 0.95f, 0.88f), 1.25f);
			AddLight(studio, Quaternion.LookRotation(-dir + Vector3.left * 0.8f), new Color(0.55f, 0.65f, 1f), 0.6f);
			AddLight(studio, Quaternion.LookRotation(dir + Vector3.down * 0.3f), new Color(1f, 0.35f, 0.3f), 0.9f);
			bool fog = RenderSettings.fog;
			AmbientMode ambientMode = RenderSettings.ambientMode;
			Color ambientLight = RenderSettings.ambientLight;
			RenderTexture temporary = RenderTexture.GetTemporary(256, 256, 24, (RenderTextureFormat)0);
			temporary.antiAliasing = 4;
			RenderTexture active = RenderTexture.active;
			try
			{
				RenderSettings.fog = false;
				RenderSettings.ambientMode = (AmbientMode)3;
				RenderSettings.ambientLight = new Color(0.45f, 0.45f, 0.5f);
				val2.targetTexture = temporary;
				val2.Render();
				RenderTexture.active = temporary;
				Texture2D val3 = new Texture2D(256, 256, (TextureFormat)4, false)
				{
					hideFlags = (HideFlags)61,
					filterMode = (FilterMode)1
				};
				val3.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
				val3.Apply();
				return HasContent(val3) ? val3 : null;
			}
			finally
			{
				RenderTexture.active = active;
				val2.targetTexture = null;
				RenderTexture.ReleaseTemporary(temporary);
				RenderSettings.fog = fog;
				RenderSettings.ambientMode = ambientMode;
				RenderSettings.ambientLight = ambientLight;
			}
		}

		private static void AddLight(GameObject studio, Quaternion rot, Color col, float intensity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("MR_PortraitLight")
			{
				hideFlags = (HideFlags)61
			};
			val.transform.SetParent(studio.transform, false);
			val.transform.rotation = rot;
			Light obj = val.AddComponent<Light>();
			obj.type = (LightType)1;
			obj.color = col;
			obj.intensity = intensity;
			obj.cullingMask = int.MinValue;
			obj.shadows = (LightShadows)0;
		}

		private static bool HasContent(Texture2D tex)
		{
			Color32[] pixels = tex.GetPixels32();
			int num = 0;
			for (int i = 0; i < pixels.Length; i += 7)
			{
				if (pixels[i].a > 40 && pixels[i].r + pixels[i].g + pixels[i].b > 30)
				{
					num++;
				}
			}
			return num > pixels.Length / 7 / 50;
		}
	}
	internal sealed class RouletteAudio : MonoBehaviour
	{
		private const int Rate = 44100;

		private AudioSource _source;

		private AudioClip _horn;

		private AudioClip _tick;

		private AudioClip _tickHigh;

		private AudioClip _reveal;

		private AudioClip _impact;

		private AudioClip _alarm;

		private AudioClip _clonk;

		private AudioClip _beep;

		private AudioClip _fanfare;

		public static RouletteAudio Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			_source = ((Component)this).gameObject.AddComponent<AudioSource>();
			_source.playOnAwake = false;
			_source.spatialBlend = 0f;
			_source.ignoreListenerPause = true;
			_horn = Make("mr_horn", 2.4f, delegate(float t, float d)
			{
				float num = 0f;
				for (int i = 1; i <= 5; i++)
				{
					float num2 = 1f / (float)(i * i);
					num += num2 * Mathf.Sin(461.18582f * (float)i * t);
					num += num2 * 0.7f * Mathf.Sin(488.83185f * (float)i * t);
				}
				float num3 = 1f + 0.06f * Mathf.Sin(MathF.PI * 10f * t);
				return num * 0.22f * num3 * Envelope(t, d, 0.6f, 1f);
			});
			_tick = Make("mr_tick", 0.05f, (float t, float d) => Mathf.Sin(MathF.PI * 1240f * t) * 0.18f * Mathf.Exp((0f - t) * 70f) + (Random.value * 2f - 1f) * 0.03f * Mathf.Exp((0f - t) * 200f));
			_reveal = Make("mr_reveal", 1.6f, (float t, float d) => (Mathf.Sin(1845.3717f * t) + 0.5f * Mathf.Sin(3690.1147f * t) * Mathf.Exp((0f - t) * 2f) + 0.25f * Mathf.Sin(MathF.PI * 1760f * t) * Mathf.Exp((0f - t) * 4f)) * 0.16f * Mathf.Exp((0f - t) * 2.2f) * Mathf.Clamp01(t / 0.01f));
			_impact = Make("mr_impact", 1.8f, delegate(float t, float d)
			{
				float num = Mathf.Lerp(60f, 32f, t / d);
				return (Mathf.Sin(MathF.PI * 2f * num * t) + (Random.value * 2f - 1f) * 0.12f * Mathf.Exp((0f - t) * 8f)) * 0.42f * Mathf.Exp((0f - t) * 1.8f) * Mathf.Clamp01(t / 0.02f);
			});
			_alarm = Make("mr_alarm", 1.5f, delegate(float t, float d)
			{
				float num = (((int)(t / 0.19f) % 2 == 0) ? 660f : 880f);
				float num2 = t % 0.19f;
				float num3 = Mathf.Clamp01(num2 / 0.01f) * Mathf.Clamp01((0.17f - num2) / 0.03f);
				return (Mathf.Sin(MathF.PI * 2f * num * t) * 0.7f + Mathf.Sign(Mathf.Sin(MathF.PI * 2f * num * t)) * 0.12f) * 0.16f * num3 * Mathf.Clamp01((d - t) / 0.3f);
			});
			_clonk = Make("mr_clonk", 0.45f, (float t, float d) => Mathf.Sin(MathF.PI * 190f * t) * 0.55f * Mathf.Exp((0f - t) * 28f) + (Mathf.Sin(MathF.PI * 2500f * t) + 0.6f * Mathf.Sin(MathF.PI * 3660f * t)) * 0.12f * Mathf.Exp((0f - t) * 18f) + (Random.value * 2f - 1f) * 0.25f * Mathf.Exp((0f - t) * 120f));
			_tickHigh = Make("mr_tick_high", 0.035f, (float t, float d) => Mathf.Sin(MathF.PI * 2300f * t) * 0.16f * Mathf.Exp((0f - t) * 110f));
			_beep = Make("mr_beep", 0.22f, (float t, float d) => Mathf.Sin(MathF.PI * 1976f * t) * 0.18f * Mathf.Clamp01(t / 0.005f) * Mathf.Clamp01((d - t) / 0.06f));
			_fanfare = Make("mr_fanfare", 1.6f, delegate(float t, float d)
			{
				float[] obj = new float[4] { 587.3f, 466.2f, 392f, 293.7f };
				int num = Mathf.Min(3, (int)(t / 0.22f));
				float num2 = t - (float)num * 0.22f;
				float num3 = obj[num];
				return (Mathf.Sin(MathF.PI * 2f * num3 * t) + 0.4f * Mathf.Sin(MathF.PI * 4f * num3 * t)) * 0.14f * Mathf.Exp((0f - num2) * ((num == 3) ? 1.5f : 5f)) * Mathf.Clamp01(num2 / 0.01f);
			});
		}

		public void Horn()
		{
			Play(_horn, 1f);
		}

		public void Alarm()
		{
			Play(_alarm, 1f);
		}

		public void Clonk()
		{
			Play(_clonk, 1f);
		}

		public void TickHigh()
		{
			Play(_tickHigh, 0.6f);
		}

		public void Beep()
		{
			Play(_beep, 1f);
		}

		public void MegaFanfare()
		{
			Play(_fanfare, 1f);
		}

		public void Tick()
		{
			Play(_tick, 0.6f);
		}

		public void Reveal()
		{
			Play(_reveal, 1f);
		}

		public void Impact()
		{
			Play(_impact, 1f);
		}

		private void Play(AudioClip clip, float volume)
		{
			if (!((Object)(object)clip == (Object)null) && !((Object)(object)_source == (Object)null))
			{
				_source.PlayOneShot(clip, volume * RouletteConfig.Current.soundVolume);
			}
		}

		private static float Envelope(float t, float d, float attack, float release)
		{
			if (t < attack)
			{
				return t / attack;
			}
			if (t > d - release)
			{
				return Mathf.Clamp01((d - t) / release);
			}
			return 1f;
		}

		private static AudioClip Make(string name, float seconds, Func<float, float, float> wave)
		{
			int num = Mathf.CeilToInt(seconds * 44100f);
			float[] array = new float[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = Mathf.Clamp(wave((float)i / 44100f, seconds), -1f, 1f);
			}
			AudioClip obj = AudioClip.Create(name, num, 1, 44100, false);
			obj.SetData(array, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}
	}
	internal sealed class RouletteUI : MonoBehaviour
	{
		private static readonly Color NeonCyan = new Color(0.2f, 0.95f, 1f);

		private static readonly Color NeonPink = new Color(1f, 0.25f, 0.75f);

		private static readonly Color AlarmRed = new Color(1f, 0.12f, 0.1f);

		private static readonly Color AlarmGold = new Color(1f, 0.78f, 0.15f);

		private RouletteEvent _evt;

		private string[] _countLabels;

		private float _finalA;

		private float _finalB;

		private float _finalCount;

		private bool _alarmDone;

		private bool _clonkA;

		private bool _clonkB;

		private bool _revealDone;

		private bool _spawnDone;

		private int _beepsDone;

		private int _lastTickA = int.MinValue;

		private int _lastTickB = int.MinValue;

		private int _lastTickCount = int.MinValue;

		private float _lastTickTime;

		private int _levelId;

		private Texture2D _black;

		private Texture2D _red;

		private GUIStyle _title;

		private GUIStyle _banner;

		private GUIStyle _sub;

		private GUIStyle _small;

		private GUIStyle _number;

		private GUIStyle _big;

		private GUIStyle _countdown;

		private GUIStyle _hubName;

		private float _styleScale = -1f;

		public static RouletteUI Instance { get; private set; }

		private float T
		{
			get
			{
				if (_evt != null)
				{
					return (float)(NetTime.Now - _evt.StartTime);
				}
				return -1f;
			}
		}

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_black = Solid(Color.black);
			_red = Solid(new Color(0.9f, 0.02f, 0.02f));
		}

		public void Play(RouletteEvent evt)
		{
			_evt = evt;
			_alarmDone = (_clonkA = (_clonkB = (_revealDone = (_spawnDone = false))));
			_beepsDone = 0;
			_lastTickA = (_lastTickB = (_lastTickCount = int.MinValue));
			_countLabels = new string[evt.CountSegments];
			for (int i = 0; i < _countLabels.Length; i++)
			{
				_countLabels[i] = (evt.CountMin + i).ToString();
			}
			int segments = evt.MonsterLabels.Length;
			_finalA = WheelRenderer.FinalAngle(evt.MonsterIndex, segments, evt.ExtraTurns, evt.JitterA);
			_finalB = WheelRenderer.FinalAngle(Mathf.Max(0, evt.MonsterIndex2), segments, evt.ExtraTurns + 1, evt.JitterB);
			_finalCount = WheelRenderer.FinalAngle(evt.Count - evt.CountMin, evt.CountSegments, evt.ExtraTurns + 1, evt.JitterCount);
			PortraitCache.EnsureAll(evt.MonsterLabels);
		}

		private float AngleA(float t, out float speed)
		{
			return WheelRenderer.Angle(t, _evt.MonsterSpinStart, _evt.MonsterSpin, _finalA, _evt.MonsterLabels.Length, out speed);
		}

		private float AngleB(float t, out float speed)
		{
			return WheelRenderer.Angle(t, _evt.MonsterSpinStart, _evt.MonsterSpin + 0.6f, _finalB, _evt.MonsterLabels.Length, out speed);
		}

		private float AngleCount(float t, out float speed)
		{
			return WheelRenderer.Angle(t, _evt.CountSpinStart, _evt.CountSpin, _finalCount, _evt.CountSegments, out speed);
		}

		private void Update()
		{
			//IL_02ae: 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)
			if (SemiFunc.RunIsLevel())
			{
				int num = (((Object)(object)LevelGenerator.Instance != (Object)null) ? ((Object)LevelGenerator.Instance).GetInstanceID() : 0);
				if (num != _levelId)
				{
					_levelId = num;
					PortraitCache.ResetQueue();
				}
				if ((Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
				{
					PortraitCache.WarmUpStep();
				}
			}
			if (_evt == null)
			{
				return;
			}
			if (!SemiFunc.RunIsLevel())
			{
				_evt = null;
				return;
			}
			float t = T;
			if (t < 0f)
			{
				return;
			}
			if (t > _evt.End)
			{
				_evt = null;
				return;
			}
			RouletteAudio instance = RouletteAudio.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (!_alarmDone)
			{
				_alarmDone = true;
				instance.Alarm();
				if (_evt.IsSpecial)
				{
					instance.MegaFanfare();
				}
			}
			int segments = _evt.MonsterLabels.Length;
			float speed;
			if (t >= _evt.MonsterSpinStart && t < _evt.MonsterAEnd)
			{
				Tick(ref _lastTickA, AngleA(t, out speed), segments, high: false);
			}
			if (_evt.Mega && t >= _evt.MonsterSpinStart && t < _evt.MonsterBEnd)
			{
				Tick(ref _lastTickB, AngleB(t, out speed), segments, high: false);
			}
			if (!_clonkA && t >= _evt.MonsterAEnd)
			{
				_clonkA = true;
				instance.Clonk();
			}
			if (_evt.Mega && !_clonkB && t >= _evt.MonsterBEnd)
			{
				_clonkB = true;
				instance.Clonk();
			}
			if (t >= _evt.CountSpinStart && t < _evt.CountSpinEnd)
			{
				Tick(ref _lastTickCount, AngleCount(t, out speed), _evt.CountSegments, high: true);
			}
			if (!_revealDone && t >= _evt.CountSpinEnd)
			{
				_revealDone = true;
				instance.Clonk();
				instance.Reveal();
				Shake(2.5f, 0.5f);
			}
			int num2 = Mathf.Clamp(Mathf.FloorToInt(t - _evt.CountdownStart) + 1, 0, Mathf.CeilToInt(_evt.Countdown));
			while (_beepsDone < num2)
			{
				_beepsDone++;
				instance.Beep();
			}
			if (!_spawnDone && t >= _evt.SpawnAt)
			{
				_spawnDone = true;
				instance.Impact();
				instance.Horn();
				Shake(6f, 1.2f);
				SemiFunc.UIBigMessage(_evt.ResultText, "{:O}", 25f, Color.red, Color.white);
			}
		}

		private void Tick(ref int last, float angle, int segments, bool high)
		{
			int num = Mathf.FloorToInt(angle / (360f / (float)segments));
			if (num == last)
			{
				return;
			}
			last = num;
			if (!(Time.unscaledTime - _lastTickTime < 0.025f))
			{
				_lastTickTime = Time.unscaledTime;
				if (high)
				{
					RouletteAudio.Instance?.TickHigh();
				}
				else
				{
					RouletteAudio.Instance?.Tick();
				}
			}
		}

		private static void Shake(float strength, float time)
		{
			GameDirector instance = GameDirector.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				if ((Object)(object)instance.CameraShake != (Object)null)
				{
					instance.CameraShake.Shake(strength, time);
				}
				if ((Object)(object)instance.CameraImpact != (Object)null)
				{
					instance.CameraImpact.Shake(strength * 0.6f, Mathf.Min(0.4f, time));
				}
			}
		}

		private void OnGUI()
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: 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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0633: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_08bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_08dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0843: Unknown result type (might be due to invalid IL or missing references)
			//IL_0850: Unknown result type (might be due to invalid IL or missing references)
			//IL_0855: Unknown result type (might be due to invalid IL or missing references)
			//IL_088f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			if (_evt == null)
			{
				return;
			}
			float t = T;
			if (!(t < 0f) && !(t > _evt.End))
			{
				float num = (float)Screen.height / 1080f * RouletteConfig.Current.uiScale;
				EnsureStyles(num);
				GUI.depth = -1000;
				float num2 = Screen.width;
				float num3 = Screen.height;
				float num4 = ((t > _evt.SpawnAt) ? (1f - Mathf.Clamp01((t - _evt.SpawnAt) / 0.6f)) : 1f);
				float num5 = Mathf.Clamp01(t / 0.35f) * num4;
				float unscaledTime = Time.unscaledTime;
				DrawFull(_black, 0.4f * num5);
				float num6 = Flash(t, _evt.CountSpinEnd, 0.6f) + Flash(t, _evt.SpawnAt, 0.5f);
				if (num6 > 0f)
				{
					DrawFull(_red, 0.45f * num6);
				}
				Matrix4x4 matrix = GUI.matrix;
				float num7 = Mathf.Max(Flash(t, _evt.CountSpinEnd, 0.5f), Flash(t, _evt.SpawnAt, 0.4f)) * 14f * num;
				if (num7 > 0f)
				{
					GUI.matrix = Matrix4x4.TRS(new Vector3((Mathf.PerlinNoise(unscaledTime * 40f, 0f) - 0.5f) * 2f * num7, (Mathf.PerlinNoise(0f, unscaledTime * 40f) - 0.5f) * 2f * num7, 0f), Quaternion.identity, Vector3.one) * matrix;
				}
				float num8 = 0.5f + 0.5f * Mathf.Sin(unscaledTime * (_evt.IsSpecial ? 10f : 4f));
				Color val = (_evt.IsSpecial ? Color.Lerp(AlarmRed, AlarmGold, num8) : Color.Lerp(NeonCyan, NeonPink, num8 * 0.6f));
				val.a = num5;
				int num9 = ((!_evt.Mega) ? 1 : 2);
				float num10 = 470f * num;
				float num11 = 330f * num;
				float num12 = 46f * num;
				float num13 = 40f * num;
				float num14 = num10 * (float)num9 + num11 + num12 * (float)num9;
				float num15 = num2 * 0.96f - num13 * 2f;
				if (num14 > num15)
				{
					float num16 = num15 / num14;
					num10 *= num16;
					num11 *= num16;
					num12 *= num16;
					num14 = num15;
				}
				float num17 = 96f * num;
				float num18 = 34f * num;
				float num19 = 46f * num;
				float num20 = 100f * num;
				float num21 = num14 + num13 * 2f;
				float num22 = num17 + num18 + num10 + num19 + num20;
				Rect r = default(Rect);
				((Rect)(ref r))..ctor(num2 / 2f - num21 / 2f, num3 / 2f - num22 / 2f + 20f * num, num21, num22);
				float u = Mathf.Clamp01(t / Mathf.Max(0.3f, _evt.Intro));
				float num23 = (1f - EaseOutBack(u)) * -120f * num;
				((Rect)(ref r)).y = ((Rect)(ref r)).y + num23;
				if (_evt.IsSpecial)
				{
					Color col = Color.Lerp(AlarmRed, AlarmGold, num8);
					col.a = num5 * (0.6f + 0.4f * num8);
					string text = (_evt.Mega ? "⚠ ACHTUNG: MEGA-CHALLENGE AKTIVIERT! ⚠" : "⚠ ACHTUNG: EXTREME COUNT AKTIVIERT! ⚠");
					SlotRenderer.TextWithShadow(new Rect(0f, ((Rect)(ref r)).y - 76f * num, num2, 64f * num), text, _banner, col, (TextAnchor)4);
				}
				SlotRenderer.GlassPanel(r, val, 30f * num, _evt.IsSpecial ? 1.7f : 1f);
				SlotRenderer.TextWithShadow(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 14f * num, ((Rect)(ref r)).width, 70f * num), "MONSTER ROULETTE", _title, val, (TextAnchor)4);
				float num24 = ((Rect)(ref r)).x + num13;
				float num25 = ((Rect)(ref r)).y + num17;
				float num26 = num25 + num18;
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(1f, 1f, 1f, 0.75f * num5);
				Color val3 = default(Color);
				((Color)(ref val3))..ctor(1f, 0.85f, 0.25f, num5);
				float pop = WheelPop(t, 0f);
				DrawMonsterWheel(new Rect(num24, num26, num10, num10), pop, _evt.Mega ? "MONSTER 1" : "MONSTER", num25, num18, num19, AngleA(t, out var speed), speed, (t >= _evt.MonsterAEnd) ? _evt.MonsterIndex : (-1), num5, val2, val3);
				num24 += num10 + num12;
				if (_evt.Mega)
				{
					DrawMonsterWheel(new Rect(num24, num26, num10, num10), WheelPop(t, 0.12f), "MONSTER 2", num25, num18, num19, AngleB(t, out var speed2), speed2, (t >= _evt.MonsterBEnd) ? _evt.MonsterIndex2 : (-1), num5, val2, val3);
					num24 += num10 + num12;
				}
				bool flag = t >= _evt.CountSpinStart;
				float alpha = num5 * (flag ? 1f : 0.45f);
				float s = WheelPop(t, 0.24f) * (flag ? (1f + 0.06f * Flash(t, _evt.CountSpinStart, 0.4f)) : 1f);
				float num27 = num26 + (num10 - num11) / 2f;
				SlotRenderer.TextWithShadow(new Rect(num24, num25, num11, num18), "COUNT", _sub, val2, (TextAnchor)4);
				Rect val4 = Scaled(new Rect(num24, num27, num11, num11), s);
				float speed3 = 0f;
				float angle = (flag ? AngleCount(t, out speed3) : 0f);
				int num28 = ((t >= _evt.CountSpinEnd) ? (_evt.Count - _evt.CountMin) : (-1));
				WheelRenderer.Draw(val4, _countLabels, portraits: false, angle, speed3, num28, _evt.IsSpecial, alpha, _number, _small);
				DrawHubNumber(val4, flag ? _countLabels[WheelRenderer.SegmentAtPointer(angle, _evt.CountSegments)] : "?", num28 >= 0, alpha);
				Rect r2 = default(Rect);
				((Rect)(ref r2))..ctor(((Rect)(ref r)).x, num26 + num10 + num19, ((Rect)(ref r)).width, num20 - 10f * num);
				if (t < _evt.MonsterSpinEnd)
				{
					SlotRenderer.TextWithShadow(r2, "Which monster is coming...?", _sub, new Color(1f, 1f, 1f, num5), (TextAnchor)4);
				}
				else if (t < _evt.CountSpinEnd)
				{
					string text2 = (_evt.Mega ? (_evt.MonsterName + " + " + _evt.MonsterName2) : _evt.MonsterName);
					SlotRenderer.TextWithShadow(r2, text2.ToUpperInvariant() + "! How many?", _sub, val3, (TextAnchor)4);
				}
				else if (t < _evt.CountdownStart)
				{
					SlotRenderer.TextWithShadow(r2, _evt.ResultText + "!", _big, new Color(1f, 0.3f, 0.2f, num5), (TextAnchor)4);
				}
				else if (t < _evt.SpawnAt)
				{
					int num29 = Mathf.Max(1, Mathf.CeilToInt(_evt.SpawnAt - t));
					float num30 = _evt.SpawnAt - t - (float)(num29 - 1);
					Color col2 = Color.Lerp(AlarmRed, Color.white, num30 * 0.5f);
					col2.a = num5;
					int fontSize = _countdown.fontSize;
					_countdown.fontSize = Mathf.RoundToInt((float)fontSize * (1f + 0.3f * num30));
					SlotRenderer.TextWithShadow(r2, $"SPAWNING IN {num29}...", _countdown, col2, (TextAnchor)4);
					_countdown.fontSize = fontSize;
				}
				else
				{
					SlotRenderer.TextWithShadow(r2, "SURVIVE!", _big, new Color(1f, 0.2f, 0.15f, num5), (TextAnchor)4);
				}
				GUI.matrix = matrix;
			}
		}

		private void DrawMonsterWheel(Rect rect, float pop, string label, float labelY, float labelH, float nameH, float angle, float speed, int winner, float alpha, Color labelCol, Color gold)
		{
			//IL_0012: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			SlotRenderer.TextWithShadow(new Rect(((Rect)(ref rect)).x, labelY, ((Rect)(ref rect)).width, labelH), label, _sub, labelCol, (TextAnchor)4);
			Rect rect2 = Scaled(rect, pop);
			WheelRenderer.Draw(rect2, _evt.MonsterLabels, portraits: true, angle, speed, winner, _evt.IsSpecial, alpha, _number, _small);
			int num = WheelRenderer.SegmentAtPointer(angle, _evt.MonsterLabels.Length);
			string text = _evt.MonsterLabels[num];
			float num2 = ((Rect)(ref rect2)).width * 0.27f;
			float s = ((winner >= 0) ? (1f + 0.08f * Mathf.Abs(Mathf.Sin(Time.unscaledTime * 4f))) : 1f);
			WheelRenderer.DrawPortrait(Scaled(new Rect(((Rect)(ref rect2)).center.x - num2 / 2f, ((Rect)(ref rect2)).center.y - num2 / 2f, num2, num2), s), text, alpha);
			Color col = (Color)((winner >= 0) ? gold : new Color(1f, 1f, 1f, alpha * ((speed > 300f) ? 0.55f : 0.9f)));
			SlotRenderer.TextWithShadow(new Rect(((Rect)(ref rect)).x - 20f, ((Rect)(ref rect)).yMax + 4f, ((Rect)(ref rect)).width + 40f, nameH), text.ToUpperInvariant(), _hubName, col, (TextAnchor)4);
		}

		private void DrawHubNumber(Rect wheel, string text, bool locked, float alpha)
		{
			//IL_0010: 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_0038: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref wheel)).width * 0.3f;
			Rect r = new Rect(((Rect)(ref wheel)).center.x - num / 2f, ((Rect)(ref wheel)).center.y - num / 2f, num, num);
			int fontSize = _big.fontSize;
			_big.fontSize = Mathf.RoundToInt(num * 0.55f);
			SlotRenderer.TextWithShadow(r, text, _big, locked ? new Color(1f, 0.85f, 0.25f, alpha) : new Color(1f, 1f, 1f, alpha), (TextAnchor)4);
			_big.fontSize = fontSize;
		}

		private float WheelPop(float t, float delay)
		{
			return EaseOutBack(Mathf.Clamp01((t - delay) / Mathf.Max(0.3f, _evt.Intro * 0.8f)));
		}

		private static float EaseOutBack(float u)
		{
			float num = u - 1f;
			return 1f + 2.70158f * num * num * num + 1.70158f * num * num;
		}

		private static Rect Scaled(Rect r, float s)
		{
			//IL_000f: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			s = Mathf.Max(0.01f, s);
			return new Rect(((Rect)(ref r)).center.x - ((Rect)(ref r)).width * s / 2f, ((Rect)(ref r)).center.y - ((Rect)(ref r)).height * s / 2f, ((Rect)(ref r)).width * s, ((Rect)(ref r)).height * s);
		}

		private static float Flash(float t, float at, float duration)
		{
			if (t < at || t > at + duration)
			{
				return 0f;
			}
			return 1f - (t - at) / duration;
		}

		private static void DrawFull(Texture2D tex, float alpha)
		{
			//IL_0009: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!(alpha <= 0f))
			{
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, alpha);
				GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)tex);
				GUI.color = color;
			}
		}

		private void EnsureStyles(float scale)
		{
			if (_title == null || !Mathf.Approximately(scale, _styleScale))
			{
				_styleScale = scale;
				_title = Make(56);
				_banner = Make(44);
				_sub = Make(24);
				_small = Make(15);
				_number = Make(30);
				_big = Make(52);
				_countdown = Make(58);
				_hubName = Make(32);
			}
			GUIStyle Make(int size)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					fontSize = Mathf.Max(10, Mathf.RoundToInt((float)size * scale)),
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4,
					wordWrap = false,
					clipping = (TextClipping)0
				};
				val.normal.textColor = Color.white;
				return val;
			}
		}

		private static Texture2D Solid(Color c)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}
	}
	internal static class SlotRenderer
	{
		private static GUIStyle _portraitStyle;

		public static void RoundedRect(Rect r, Color fill, float radius)
		{
			//IL_0000: 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)
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture, (ScaleMode)0, true, 0f, fill, 0f, radius);
		}

		public static void RoundedBorder(Rect r, Color col, float width, float radius)
		{
			//IL_0000: 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)
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture, (ScaleMode)0, true, 0f, col, width, radius);
		}

		public static void GlassPanel(Rect r, Color neon, float radius, float glow)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			for (int num = 3; num >= 1; num--)
			{
				float num2 = (float)num * 5f;
				RoundedBorder(new Rect(((Rect)(ref r)).x - num2, ((Rect)(ref r)).y - num2, ((Rect)(ref r)).width + num2 * 2f, ((Rect)(ref r)).height + num2 * 2f), new Color(neon.r, neon.g, neon.b, neon.a * glow * 0.12f * (float)(4 - num)), 6f, radius + num2);
			}
			RoundedRect(r, new Color(0.04f, 0.03f, 0.08f, 0.78f * neon.a), radius);
			RoundedRect(new Rect(((Rect)(ref r)).x + 4f, ((Rect)(ref r)).y + 4f, ((Rect)(ref r)).width - 8f, ((Rect)(ref r)).height * 0.42f), new Color(1f, 1f, 1f, 0.05f * neon.a), radius - 2f);
			RoundedBorder(r, neon, 3f, radius);
		}

		public static void Portrait(Rect r, string name, float alpha)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			Color val = ColorFromName(name);
			RoundedRect(r, new Color(val.r * 0.35f, val.g * 0.35f, val.b * 0.35f, alpha), ((Rect)(ref r)).width * 0.22f);
			RoundedBorder(r, new Color(val.r, val.g, val.b, alpha), 2f, ((Rect)(ref r)).width * 0.22f);
			float num = ((Rect)(ref r)).width * 0.16f;
			float num2 = ((Rect)(ref r)).y + ((Rect)(ref r)).height * 0.24f;
			RoundedRect(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.24f, num2, num, num), new Color(1f, 0.95f, 0.8f, alpha), num / 2f);
			RoundedRect(new Rect(((Rect)(ref r)).xMax - ((Rect)(ref r)).width * 0.24f - num, num2, num, num), new Color(1f, 0.95f, 0.8f, alpha), num / 2f);
			if (_portraitStyle == null)
			{
				_portraitStyle = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4,
					clipping = (TextClipping)0
				};
			}
			GUIStyle portraitStyle = _portraitStyle;
			portraitStyle.fontSize = Mathf.Max(8, Mathf.RoundToInt(((Rect)(ref r)).height * 0.34f));
			portraitStyle.normal.textColor = new Color(val.r * 0.6f + 0.4f, val.g * 0.6f + 0.4f, val.b * 0.6f + 0.4f, alpha);
			GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + ((Rect)(ref r)).height * 0.28f, ((Rect)(ref r)).width, ((Rect)(ref r)).height * 0.7f), Initials(name), portraitStyle);
		}

		public static void TextWithShadow(Rect r, string text, GUIStyle style, Color col, TextAnchor anchor)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			TextAnchor alignment = style.alignment;
			Color textColor = style.normal.textColor;
			style.alignment = anchor;
			float num = Mathf.Max(1.5f, (float)style.fontSize / 16f);
			style.normal.textColor = new Color(0f, 0f, 0f, col.a * 0.8f);
			GUI.Label(new Rect(((Rect)(ref r)).x + num, ((Rect)(ref r)).y + num, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, style);
			style.normal.textColor = col;
			GUI.Label(r, text, style);
			style.normal.textColor = textColor;
			style.alignment = alignment;
		}

		private static string Initials(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return "?";
			}
			string[] array = name.Split(' ');
			if (array.Length >= 2 && array[0].Length > 0 && array[1].Length > 0)
			{
				return (array[0].Substring(0, 1) + array[1].Substring(0, 1)).ToUpperInvariant();
			}
			return name.Substring(0, Mathf.Min(2, name.Length)).ToUpperInvariant();
		}

		private static Color ColorFromName(string name)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			int num = 17;
			string text = name ?? "";
			foreach (char c in text)
			{
				num = num * 31 + c;
			}
			return Color.HSVToRGB((float)(num & 0xFFFF) / 65535f, 0.75f, 0.95f);
		}
	}
	internal static class WheelRenderer
	{
		private const int TexSize = 768;

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

		private static Texture2D _pointer;

		private static readonly Color[] MonsterPalette = (Color[])(object)new Color[3]
		{
			new Color(0.55f, 0.05f, 0.08f),
			new Color(0.1f, 0.09f, 0.13f),
			new Color(0.3f, 0.07f, 0.35f)
		};

		private static readonly Color[] CountPalette = (Color[])(object)new Color[3]
		{
			new Color(0.85f, 0.58f, 0.06f),
			new Color(0.12f, 0.11f, 0.14f),
			new Color(0.7f, 0.25f, 0.05f)
		};

		private static Texture2D Pointer
		{
			get
			{
				//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_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Expected O, but got Unknown
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_pointer != (Object)null)
				{
					return _pointer;
				}
				Texture2D val = new Texture2D(64, 84, (TextureFormat)4, false)
				{
					filterMode = (FilterMode)1,
					hideFlags = (HideFlags)61
				};
				Color32[] array = (Color32[])(object)new Color32[5376];
				for (int i = 0; i < 84; i++)
				{
					for (int j = 0; j < 64; j++)
					{
						float num = (float)i / 84f * 32f;
						float num2 = Mathf.Abs((float)j - 31.5f);
						float num3 = num - num2;
						float num4 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(31.5f, 63.52f));
						float num5 = 19.2f - num4;
						float num6 = Mathf.Max(num3, num5);
						Color val2 = ((num6 > 4f) ? new Color(1f, 1f, 1f) : new Color(0.15f, 0.12f, 0.1f));
						if (num4 < 6.4f)
						{
							((Color)(ref val2))..ctor(0.85f, 0.66f, 0.22f);
						}
						val2.a = Mathf.Clamp01(num6 + 1f);
						array[i * 64 + j] = Color32.op_Implicit(val2);
					}
				}
				val.SetPixels32(array);
				val.Apply();
				_pointer = val;
				return val;
			}
		}

		public static float FinalAngle(int index, int segments, int extraTurns, float jitter)
		{
			float num = 360f / (float)segments;
			return (float)extraTurns * 360f + (360f - num * ((float)index + 0.5f)) + jitter * num;
		}

		public static float Angle(float t, float start, float duration, float final, int segments, out float speed)
		{
			float num = (t - start) / duration;
			if (num <= 0f)
			{
				speed = 0f;
				return 0f;
			}
			if (num < 1f)
			{
				float num2 = 1f - num;
				speed = final * 4f * num2 * num2 * num2 / duration;
				return final * (1f - num2 * num2 * num2 * num2);
			}
			speed = 0f;
			float num3 = (t - start - duration) / 0.45f;
			if (num3 >= 1f)
			{
				return final;
			}
			float num4 = 360f / (float)segments;
			return final - 0.08f * num4 * Mathf.Sin(num3 * MathF.PI) * (1f - num3 * 0.5f);
		}

		public static int SegmentAtPointer(float angle, int segments)
		{
			float num = 360f / (float)segments;
			return Mathf.Clamp(Mathf.FloorToInt(Mathf.Repeat(0f - angle, 360f) / num), 0, segments - 1);
		}

		public static void Draw(Rect rect, string[] items, bool portraits, float angle, float speed, int winner, bool special, float alpha, GUIStyle numberStyle, GUIStyle smallStyle)
		{
			//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_002a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Unknown result type (might be due to invalid IL or missing references)
			//IL_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0663: Unknown result type (might be due to invalid IL or missing references)
			//IL_0681: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0686: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0696: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06da: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			int num = items.Length;
			Vector2 center = ((Rect)(ref rect)).center;
			float num2 = ((Rect)(ref rect)).width / 2f;
			float num3 = 360f / (float)num;
			float unscaledTime = Time.unscaledTime;
			Matrix4x4 matrix = GUI.matrix;
			SlotRenderer.RoundedRect(new Rect(center.x - num2 * 1.06f, center.y - num2 * 1.02f, num2 * 2.12f, num2 * 2.12f), new Color(0f, 0f, 0f, 0.45f * alpha), num2 * 1.06f);
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, alpha);
			GUIUtility.RotateAroundPivot(angle, center);
			GUI.DrawTexture(rect, (Texture)(object)GetWheel(num, !portraits));
			GUI.matrix = matrix;
			GUI.color = color;
			int num4 = 28;
			float num5 = num2 * 0.955f;
			float num6 = Mathf.Max(5f, num2 * 0.045f);
			int num7 = Mathf.FloorToInt(unscaledTime * (special ? 16f : 9f));
			Vector2 val2 = default(Vector2);
			for (int i = 0; i < num4; i++)
			{
				float num8 = ((float)i / (float)num4 * 360f + angle) * (MathF.PI / 180f);
				bool num9 = ((winner >= 0) ? (Mathf.FloorToInt(unscaledTime * 6f) % 2 == 0) : ((i + num7) % 3 == 0));
				Color val = ((!special) ? new Color(1f, 0.92f, 0.6f) : ((i % 2 == 0) ? new Color(1f, 0.25f, 0.15f) : new Color(1f, 0.85f, 0.25f)));
				Color fill = (Color)(num9 ? val : new Color(0.35f, 0.28f, 0.18f));
				fill.a = alpha;
				((Vector2)(ref val2))..ctor(center.x + Mathf.Sin(num8) * num5, center.y - Mathf.Cos(num8) * num5);
				if (num9)
				{
					SlotRenderer.RoundedRect(new Rect(val2.x - num6, val2.y - num6, num6 * 2f, num6 * 2f), new Color(val.r, val.g, val.b, 0.25f * alpha), num6);
				}
				SlotRenderer.RoundedRect(new Rect(val2.x - num6 / 2f, val2.y - num6 / 2f, num6, num6), fill, num6 / 2f);
			}
			float num10 = num2 * (portraits ? 0.66f : 0.7f);
			float num11 = Mathf.Clamp(2f * num10 * Mathf.Sin(num3 * 0.5f * (MathF.PI / 180f)) * 0.86f, num2 * 0.08f, num2 * 0.3f);
			float num12 = Mathf.Clamp01((speed - 250f) / 900f);
			Vector2 val3 = default(Vector2);
			Rect r = default(Rect);
			Vector2 val4 = default(Vector2);
			for (int j = 0; j < num; j++)
			{
				float num13 = (angle + num3 * ((float)j + 0.5f)) * (MathF.PI / 180f);
				((Vector2)(ref val3))..ctor(center.x + Mathf.Sin(num13) * num10, center.y - Mathf.Cos(num13) * num10);
				bool flag = j == winner;
				float num14 = (flag ? (1f + 0.18f * Mathf.Abs(Mathf.Sin(unscaledTime * 5f))) : 1f);
				float num15 = num11 * num14 * (flag ? 1.25f : 1f);
				float num16 = alpha * (1f - 0.45f * num12) * ((winner >= 0 && !flag) ? 0.45f : 1f);
				((Rect)(ref r))..ctor(val3.x - num15 / 2f, val3.y - num15 / 2f, num15, num15);
				if (flag)
				{
					Color fill2 = (special ? new Color(1f, 0.3f, 0.15f, 0.55f * alpha) : new Color(1f, 0.85f, 0.25f, 0.55f * alpha));
					float num17 = num15 * 0.22f;
					SlotRenderer.RoundedRect(new Rect(((Rect)(ref r)).x - num17, ((Rect)(ref r)).y - num17, ((Rect)(ref r)).width + num17 * 2f, ((Rect)(ref r)).height + num17 * 2f), fill2, (num15 + num17 * 2f) / 2f);
				}
				if (portraits)
				{
					DrawPortrait(r, items[j], num16);
				}
				else
				{
					int fontSize = numberStyle.fontSize;
					numberStyle.fontSize = Mathf.Max(10, Mathf.RoundToInt(num15 * 0.62f));
					SlotRenderer.TextWithShadow(r, items[j], numberStyle, flag ? new Color(1f, 0.9f, 0.3f, num16) : new Color(1f, 1f, 1f, num16), (TextAnchor)4);
					numberStyle.fontSize = fontSize;
				}
				if (portraits && num <= 14 && num12 < 0.3f)
				{
					float num18 = num2 * 0.86f;
					((Vector2)(ref val4))..ctor(center.x + Mathf.Sin(num13) * num18, center.y - Mathf.Cos(num13) * num18);
					SlotRenderer.TextWithShadow(new Rect(val4.x - num2 * 0.2f, val4.y - 10f, num2 * 0.4f, 20f), items[j].ToUpperInvariant(), smallStyle, new Color(1f, 1f, 1f, num16 * 0.9f), (TextAnchor)4);
				}
			}
			float num19 = Mathf.Repeat(angle / num3, 1f);
			float num20 = ((num19 < 0.3f) ? (1f - num19 / 0.3f) : 0f);
			float num21 = Mathf.Clamp01(speed / 400f) * 0.7f + 0.3f;
			float num22 = ((speed > 1f) ? (num20 * 28f * num21) : 0f);
			float num23 = num2 * 0.2f;
			float num24 = num23 * 1.3f;
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(center.x, ((Rect)(ref rect)).y - num24 * 0.35f);
			GUIUtility.RotateAroundPivot(num22, val5);
			Color val6 = (special ? Color.Lerp(new Color(1f, 0.25f, 0.15f), new Color(1f, 0.85f, 0.25f), 0.5f + 0.5f * Mathf.Sin(unscaledTime * 10f)) : Color.white);
			GUI.color = new Color(val6.r, val6.g, val6.b, alpha);
			GUI.DrawTexture(new Rect(val5.x - num23 / 2f, val5.y, num23, num24), (Texture)(object)Pointer);
			GUI.color = color;
			GUI.matrix = matrix;
		}

		public static void DrawPortrait(Rect r, string name, float alpha)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = PortraitCache.Get(name);
			if ((Object)(object)val == (Object)null)
			{
				SlotRenderer.Portrait(r, name, alpha);
				return;
			}
			SlotRenderer.RoundedRect(r, new Color(0.02f, 0.02f, 0.04f, 0.75f * alpha), ((Rect)(ref r)).width / 2f);
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, alpha);
			GUI.DrawTexture(r, (Texture)(object)val, (ScaleMode)2, true);
			GUI.color = color;
			SlotRenderer.RoundedBorder(r, new Color(1f, 0.85f, 0.4f, 0.8f * alpha), Mathf.Max(1.5f, ((Rect)(ref r)).width * 0.03f), ((Rect)(ref r)).width / 2f);
		}

		private static Texture2D GetWheel(int segments, bool countWheel)
		{
			string key = (countWheel ? "c" : "m") + segments;
			if (Cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = BuildWheel(segments, countWheel ? CountPalette : MonsterPalette);
			Cache[key] = value;
			return value;
		}

		private static Texture2D BuildWheel(int segments, Color[] palette)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(768, 768, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
			Color32[] array = (Color32[])(object)new Color32[589824];
			float num = 383.5f;
			float num2 = 382f;
			float num3 = num2 * 0.91f;
			float num4 = num3 * 0.97f;
			float num5 = num2 * 0.3f;
			float num6 = 360f / (float)segments;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.85f, 0.66f, 0.22f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.45f, 0.32f, 0.08f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.9f, 0.75f, 0.35f);
			for (int i = 0; i < 768; i++)
			{
				for (int j = 0; j < 768; j++)
				{
					float num7 = (float)j - num;
					float num8 = (float)i - num;
					float num9 = Mathf.Sqrt(num7 * num7 + num8 * num8);
					if (num9 > num2 + 1f)
					{
						array[i * 768 + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
						continue;
					}
					Color val5;
					if (num9 > num3)
					{
						val5 = Color.Lerp(val3, val2, Mathf.PingPong((num9 - num3) / (num2 - num3) * 2f, 1f));
					}
					else if (num9 > num4)
					{
						val5 = val3;
					}
					else if (num9 < num5)
					{
						val5 = (Color)((num9 > num5 - 8f) ? val2 : new Color(0.05f, 0.04f, 0.07f));
					}
					else
					{
						float num10 = Mathf.Atan2(num7, num8) * 57.29578f;
						if (num10 < 0f)
						{
							num10 += 360f;
						}
						int num11 = Mathf.Min((int)(num10 / num6), segments - 1);
						val5 = palette[num11 % palette.Length];
						if (segments % palette.Length == 1 && num11 == segments - 1)
						{
							val5 = palette[1];
						}
						if (Mathf.Min(num10 - (float)num11 * num6, (float)(num11 + 1) * num6 - num10) * (MathF.PI / 180f) * num9 < 2.5f)
						{
							val5 = val4;
						}
						else
						{
							float num12 = (num9 - num5) / (num4 - num5);
							float num13 = 0.12f * Mathf.Clamp01(1f - Mathf.Abs(num12 - 0.55f) * 3f);
							val5 = Color.Lerp(val5 * 0.55f, val5, Mathf.Clamp01(num12 * 1.6f)) + new Color(num13, num13, num13, 0f);
						}
					}
					val5.a = Mathf.Clamp01(num2 + 1f - num9);
					array[i * 768 + j] = Color32.op_Implicit(val5);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			return val;
		}
	}
}
namespace MonsterRoulette.Spawning
{
	internal sealed class MonsterOption
	{
		public string DisplayName;

		public EnemySetup Setup;

		public float Weight;

		public int Tier;
	}
	internal static class MonsterCatalog
	{
		private struct Known
		{
			public string DisplayName;

			public string SetupName;

			public EnemySetup Setup;

			public int Tier;

			public bool Modded;
		}

		public static List<MonsterOption> Resolve(RouletteSettings s)
		{
			List<Known> list = CollectEnemies();
			if (!s.addModdedEnemies)
			{
				list.RemoveAll((Known k) => k.Modded);
			}
			s = AddMissingToConfig(s, list);
			List<MonsterOption> list2 = new List<MonsterOption>();
			foreach (MonsterEntry monster in s.monsters)
			{
				if (monster != null && monster.enabled && !string.IsNullOrWhiteSpace(monster.name) && !(monster.weight <= 0f))
				{
					Known? match = Find(list, monster.name.Trim());
					if (!match.HasValue)
					{
						Plugin.Log.LogDebug((object)("Monster '" + monster.name + "' not found in this game/modpack, skipped."));
					}
					else if (!list2.Exists((MonsterOption o) => (Object)(object)o.Setup == (Object)(object)match.Value.Setup))
					{
						list2.Add(new MonsterOption
						{
							DisplayName = match.Value.DisplayName,
							Setup = match.Value.Setup,
							Weight = monster.weight,
							Tier = match.Value.Tier
						});
					}
				}
			}
			if (list2.Count == 0 && s.useAllEnemiesWhenListEmpty)
			{
				foreach (Known item in list)
				{
					list2.Add(new MonsterOption
					{
						DisplayName = item.DisplayName,
						Setup = item.Setup,
						Weight = 1f,
						Tier = item.Tier
					});
				}
			}
			return list2;
		}

		public static List<KeyValuePair<string, EnemySetup>> AllEnemies()
		{
			List<KeyValuePair<string, EnemySetup>> list = new List<KeyValuePair<string, EnemySetup>>();
			foreach (Known item in CollectEnemies())
			{
				list.Add(new KeyValuePair<string, EnemySetup>(item.DisplayName, item.Setup));
			}
			return list;
		}

		private static Known? Find(List<Known> known, string name)
		{
			foreach (Known item in known)
			{
				if (string.Equals(item.DisplayName, name, StringComparison.OrdinalIgnoreCase))
				{
					return item;
				}
			}
			foreach (Known item2 in known)
			{
				if (Contains(item2.DisplayName, name) || Contains(item2.SetupName, name))
				{
					return item2;
				}
			}
			return null;
		}

		private static bool Contains(string haystack, string needle)
		{
			if (!string.IsNullOrEmpty(haystack))
			{
				return haystack.IndexOf(needle, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private static List<Known> CollectEnemies()
		{
			List<Known> list = new List<Known>();
			EnemyDirector instance = EnemyDirector.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return list;
			}
			HashSet<EnemySetup> hashSet = new HashSet<EnemySetup>();
			HashSet<EnemySetup> hashSet2 = new HashSet<EnemySetup>();
			try
			{
				foreach (EnemySetup registeredEnemy in Enemies.RegisteredEnemies)
				{
					if ((Object)(object)registeredEnemy != (Object)null)
					{
						hashSet2.Add(registeredEnemy);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Could not read REPOLib enemies: " + ex.Message));
			}
			List<EnemySetup>[] array = new List<EnemySetup>[3] { instance.enemiesDifficulty1, instance.enemiesDifficulty2, instance.enemiesDifficulty3 };
			for (int i = 0; i < array.Length; i++)
			{
				List<EnemySetup> list2 = array[i];
				if (list2 == null)
				{
					continue;
				}
				foreach (EnemySetup item in list2)
				{
					if ((Object)(object)item == (Object)null || !hashSet.Add(item))
					{
						continue;
					}
					string text = ((Object)item).name ?? "";
					string displayName = text.Replace("Enemy - ", "").Trim();
					try
					{
						EnemyParent val = FindEnemyParent(item);
						if ((Object)(object)val != (Object)null && !string.IsNullOrWhiteSpace(val.enemyName))
						{
							displayName = val.enemyName.Trim();
						}
					}
					catch (Exception ex2)
					{
						Plugin.Log.LogDebug((object)("Could not read enemy name of " + text + ": " + ex2.Message));
					}
					list.Add(new Known
					{
						DisplayName = displayName,
						SetupName = text,
						Setup = item,
						Tier = i + 1,
						Modded = hashSet2.Contains(item)
					});
				}
			}
			return list;
		}

		internal static EnemyParent FindEnemyParent(EnemySetup setup)
		{
			if (setup.spawnObjects == null)
			{
				return null;
			}
			foreach (PrefabRef spawnObject in setup.spawnObjects)
			{
				if (spawnObject == null || !((PrefabRef<GameObject>)(object)spawnObject).IsValid())
				{
					continue;
				}
				GameObject prefab = ((PrefabRef<GameObject>)(object)spawnObject).Prefab;
				if (!((Object)(object)prefab == (Object)null))
				{
					EnemyParent componentInChildren = prefab.GetComponentInChildren<EnemyParent>(true);
					if ((Object)(object)componentInChildren != (Object)null)
					{
						return componentInChildren;
					}
				}
			}
			return null;
		}

		private static RouletteSettings AddMissingToConfig(RouletteSettings s, List<Known> known)
		{
			List<string> list = new List<string>();
			foreach (Known item in known)
			{
				if (!list.Contains(item.DisplayName))
				{
					list.Add(item.DisplayName);
				}
			}
			RouletteConfig.AddMissingMonsters(list, (string display) => s.monsters.Exists((MonsterEntry m) => string.Equals(m.name, display, StringComparison.OrdinalIgnoreCase) || display.IndexOf(m.name, StringComparison.OrdinalIgnoreCase) >= 0));
			return RouletteConfig.Current;
		}
	}
	internal static class MonsterSpawner
	{
		public static IEnumerator SpawnGroup(EnemySetup setup, int count, RouletteSettings s)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)setup == (Object)null)
			{
				yield break;
			}
			List<Vector3> points = PickSpawnPoints(count, s.minSpawnDistanceFromPlayers);
			if (points.Count == 0)
			{
				Plugin.Log.LogWarning((object)"Monster Roulette: no spawn points found in this level.");
				yield break;
			}
			int spawned = 0;
			for (int i = 0; i < count; i++)
			{
				Vector3 val = points[i % points.Count];
				try
				{
					List<EnemyParent> list = Enemies.SpawnEnemy(setup, val, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), false);
					if (list != null && list.Count > 0)
					{
						spawned++;
						if (s.keepMonstersSpawned)
						{
							foreach (EnemyParent item in list)
							{
								KeepSpawned(item);
							}
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Monster Roulette: spawning " + ((Object)setup).name + " failed: " + ex.Message));
				}
				if (s.delayBetweenSpawns > 0f)
				{
					yield return (object)new WaitForSeconds(s.delayBetweenSpawns);
				}
			}
			Plugin.Log.LogInfo((object)$"Monster Roulette: spawned {spawned}/{count}x {((Object)setup).name}");
			if (s.alertMonstersToPlayers && (Object)(object)EnemyDirector.instance != (Object)null)
			{
				List<Vector3> list2 = PlayerPositions();
				if (list2.Count > 0)
				{
					EnemyDirector.instance.SetInvestigate(list2[Random.Range(0, list2.Count)], 30f, false);
				}
			}
		}

		private static void KeepSpawned(EnemyParent p)
		{
			if (!((Object)(object)p == (Object)null))
			{
				p.SpawnedTimeMin = 999999f;
				p.SpawnedTimeMax = 999999f;
				p.SpawnedTimer = 999999f;
			}
		}

		private static List<Vector3> PickSpawnPoints(int count, float minDistance)
		{
			//IL_0067: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || instance.LevelPathPoints == null)
			{
				return list;
			}
			List<Vector3> list2 = PlayerPositions();
			List<Vector3> list3 = new List<Vector3>();
			List<(Vector3, float)> list4 = new List<(Vector3, float)>();
			foreach (LevelPoint levelPathPoint in instance.LevelPathPoints)
			{
				if ((Object)(object)levelPathPoint == (Object)null || levelPathPoint.Truck)
				{
					continue;
				}
				Vector3 position = ((Component)levelPathPoint).transform.position;
				float num = float.MaxValue;
				foreach (Vector3 item in list2)
				{
					num = Mathf.Min(num, Vector3.Distance(item, position));
				}
				list4.Add((position, num));
				if (num >= minDistance)
				{
					list3.Add(position);
				}
			}
			if (list3.Count > 0)
			{
				Shuffle(list3);
				list.AddRange(list3.GetRange(0, Mathf.Min(count, list3.Count)));
			}
			else
			{
				list4.Sort(((Vector3 pos, float dist) a, (Vector3 pos, float dist) b) => b.dist.CompareTo(a.dist));
				for (int num2 = 0; num2 < Mathf.Min(count, list4.Count); num2++)
				{
					list.Add(list4[num2].Item1);
				}
			}
			return list;
		}

		private static List<Vector3> PlayerPositions()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			GameDirector instance = GameDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.PlayerList == null)
			{
				return list;
			}
			foreach (PlayerAvatar player in instance.PlayerList)
			{
				if ((Object)(object)player != (Object)null)
				{
					list.Add(((Component)player).transform.position);
				}
			}
			return list;
		}

		private static void Shuffle<T>(List<T> list)
		{
			for (int num = list.Count - 1; num > 0; num--)
			{
				int num2 = Random.Range(0, num + 1);
				int index = num;
				int index2 = num2;
				T value = list[num2];
				T value2 = list[num];
				list[index] = value;
				list[index2] = value2;
			}
		}
	}
}
namespace MonsterRoulette.Patches
{
	[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
	internal static class EnemySpawnPatch
	{
		private static void Postfix(ref int ___totalAmount)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && RouletteDirector.DecideForThisLevel() && RouletteConfig.Current.onlyRouletteMonsters)
			{
				Plugin.Log.LogInfo((object)$"MonsterRoulette: roulette round, skipping {___totalAmount} normal enemy spawns.");
				___totalAmount = 0;
			}
		}
	}
}
namespace MonsterRoulette.Network
{
	internal static class RouletteNetwork
	{
		private static NetworkedEvent _startEvent;

		public static void Register()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			_startEvent = new NetworkedEvent("MonsterRoulette_Start_v3", (Action<EventData>)delegate(EventData e)
			{
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					if (RouletteEvent.TryFromPayload(e.CustomData, out var e2))
					{
						RouletteUI.Instance?.Play(e2);
					}
					else
					{
						Plugin.Log.LogWarning((object)"Received invalid roulette event.");
					}
				}
			});
		}

		public static void Broadcast(RouletteEvent evt)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			RouletteUI.Instance?.Play(evt);
			if (NetTime.IsOnline)
			{
				_startEvent.RaiseEvent((object)evt.ToPayload(), new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}
	}
}
namespace MonsterRoulette.Events
{
	internal sealed class RouletteDirector : MonoBehaviour
	{
		private int _eventCounter;

		private bool _running;

		private static bool? _levelDecision;

		private static int _decisionLevelId;

		public static RouletteDirector Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		public static bool DecideForThisLevel()
		{
			int num = (((Object)(object)LevelGenerator.Instance != (Object)null) ? ((Object)LevelGenerator.Instance).GetInstanceID() : 0);
			if (_levelDecision.HasValue && _decisionLevelId == num)
			{
				return _levelDecision.Value;
			}
			_decisionLevelId = num;
			RouletteConfig.Reload();
			RouletteSettings current = RouletteConfig.Current;
			bool flag = current.enabled && SemiFunc.RunIsLevel() && !SemiFunc.RunIsArena() && !SemiFunc.RunIsShop() && !SemiFunc.RunIsTutorial() && SemiFunc.RunGetLevelsCompleted() >= current.minLevelsCompleted && Random.Range(0, 100) < current.triggerChancePercent;
			_levelDecision = flag;
			return flag;
		}

		public void OnRoundStarted()
		{
			bool num = DecideForThisLevel();
			_levelDecision = null;
			if (num)
			{
				StartRoulette();
			}
		}

		public void TryStartManual()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				SemiFunc.UIFocusText("Only the host can start the Monster Roulette.", Color.white, Color.red, 3f);
				return;
			}
			if (RoundStartListener.CurrentPlayableLevelId() == 0)
			{
				SemiFunc.UIFocusText("Monster Roulette only works inside a level.", Color.white, Color.red, 3f);
				return;
			}
			RouletteConfig.Reload();
			StartRoulette();
		}

		private void StartRoulette()
		{
			if (_running)
			{
				return;
			}
			RouletteSettings current = RouletteConfig.Current;
			List<MonsterOption> list = MonsterCatalog.Res