Decompiled source of ChaosCarnival v1.0.27

ChaosCarnival.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ChaosCarnival.Features;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("ChaosCarnival")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Chaos-party content mod for R.E.P.O. — cursed farting loot, Fart Goblins, mystery lottery, the Klutz treatment, and more.")]
[assembly: AssemblyFileVersion("1.0.27.0")]
[assembly: AssemblyInformationalVersion("1.0.27")]
[assembly: AssemblyProduct("ChaosCarnival")]
[assembly: AssemblyTitle("ChaosCarnival")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("1.0.27.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ChaosCarnival
{
	public class CarnivalState
	{
		public int CursedViewID = -1;

		public int CursedHolderViewID = -1;

		public int[] GoblinViewIDs = Array.Empty<int>();

		public string KlutzName = "";

		public int LotteryViewID = -1;

		public float LotteryValue;

		public int ToiletViewID = -1;

		public int MeltdownViewID = -1;

		public float MeltdownValue;

		public bool MeltdownLocked;

		public int CurseType;

		public int[] InfectedViewIDs = Array.Empty<int>();

		public string[] TallyNames = Array.Empty<string>();

		public float[] TallyDamage = Array.Empty<float>();

		public bool BlackoutActive;

		public int SnitchViewID = -1;

		public float[] PortalExit = Array.Empty<float>();

		public float[] PortalEntry = Array.Empty<float>();

		public int PowerUpViewID = -1;

		public int PowerUpPhase;

		public int TokenViewID = -1;

		public float[] ToiletPos = Array.Empty<float>();

		public int PossessedPlayerViewID = -1;

		public int RouletteOutbreak;

		public float[] PortalData = Array.Empty<float>();

		public object[] Pack()
		{
			return new object[25]
			{
				CursedViewID, CursedHolderViewID, GoblinViewIDs, KlutzName, LotteryViewID, LotteryValue, ToiletViewID, MeltdownViewID, MeltdownValue, MeltdownLocked,
				CurseType, InfectedViewIDs, TallyNames, TallyDamage, ToiletPos, BlackoutActive, SnitchViewID, PortalExit, PortalEntry, PowerUpViewID,
				PowerUpPhase, TokenViewID, PossessedPlayerViewID, RouletteOutbreak, PortalData
			};
		}

		public static CarnivalState Unpack(object[] d)
		{
			if (d == null)
			{
				return new CarnivalState();
			}
			return new CarnivalState
			{
				CursedViewID = ToInt(0),
				CursedHolderViewID = ToInt(1),
				GoblinViewIDs = ToIntArray(2),
				KlutzName = ToString(3),
				LotteryViewID = ToInt(4),
				LotteryValue = ToFloat(5),
				ToiletViewID = ToInt(6),
				MeltdownViewID = ToInt(7),
				MeltdownValue = ToFloat(8),
				MeltdownLocked = ToBool(9),
				CurseType = ToInt(10, 0),
				InfectedViewIDs = ToIntArray(11),
				TallyNames = ToStringArray(12),
				TallyDamage = ToFloatArray(13),
				ToiletPos = ToFloatArray(14),
				BlackoutActive = ToBool(15),
				SnitchViewID = ToInt(16),
				PortalExit = ToFloatArray(17),
				PortalEntry = ToFloatArray(18),
				PowerUpViewID = ToInt(19),
				PowerUpPhase = ToInt(20, 0),
				TokenViewID = ToInt(21),
				PossessedPlayerViewID = ToInt(22),
				RouletteOutbreak = ToInt(23, 0),
				PortalData = ToFloatArray(24)
			};
			bool ToBool(int index, bool fallback = false)
			{
				if (index >= d.Length || d[index] == null)
				{
					return fallback;
				}
				try
				{
					return Convert.ToBoolean(d[index]);
				}
				catch
				{
					return fallback;
				}
			}
			float ToFloat(int index, float fallback = 0f)
			{
				if (index >= d.Length || d[index] == null)
				{
					return fallback;
				}
				try
				{
					return Convert.ToSingle(d[index]);
				}
				catch
				{
					return fallback;
				}
			}
			float[] ToFloatArray(int index)
			{
				if (index >= d.Length || d[index] == null)
				{
					return Array.Empty<float>();
				}
				try
				{
					if (d[index] is float[] result)
					{
						return result;
					}
					Array array = (Array)d[index];
					float[] array2 = new float[array.Length];
					for (int i = 0; i < array.Length; i++)
					{
						array2[i] = Convert.ToSingle(array.GetValue(i));
					}
					return array2;
				}
				catch
				{
					return Array.Empty<float>();
				}
			}
			int ToInt(int index, int fallback = -1)
			{
				if (index >= d.Length || d[index] == null)
				{
					return fallback;
				}
				try
				{
					return Convert.ToInt32(d[index]);
				}
				catch
				{
					return fallback;
				}
			}
			int[] ToIntArray(int index)
			{
				if (index >= d.Length || d[index] == null)
				{
					return Array.Empty<int>();
				}
				try
				{
					if (d[index] is int[] result)
					{
						return result;
					}
					Array array = (Array)d[index];
					int[] array2 = new int[array.Length];
					for (int i = 0; i < array.Length; i++)
					{
						array2[i] = Convert.ToInt32(array.GetValue(i));
					}
					return array2;
				}
				catch
				{
					return Array.Empty<int>();
				}
			}
			string ToString(int index, string fallback = "")
			{
				if (index >= d.Length || d[index] == null)
				{
					return fallback;
				}
				try
				{
					return Convert.ToString(d[index]);
				}
				catch
				{
					return fallback;
				}
			}
			string[] ToStringArray(int index)
			{
				if (index >= d.Length || d[index] == null)
				{
					return Array.Empty<string>();
				}
				try
				{
					if (d[index] is string[] result)
					{
						return result;
					}
					Array array = (Array)d[index];
					string[] array2 = new string[array.Length];
					for (int i = 0; i < array.Length; i++)
					{
						array2[i] = Convert.ToString(array.GetValue(i));
					}
					return array2;
				}
				catch
				{
					return Array.Empty<string>();
				}
			}
		}
	}
	public static class Fx
	{
		public const string GlowLightName = "ChaosCarnival.GlowLight";

		public const string AuraName = "ChaosCarnival.Aura";

		public static void Glow(GameObject obj, Color color, float emission = 1.8f, float lightRange = 4.5f, float lightIntensity = 2.2f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_0072: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)obj == (Object)null || (Object)obj.transform.Find("ChaosCarnival.GlowLight") != (Object)null)
			{
				return;
			}
			try
			{
				Renderer[] componentsInChildren = obj.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					if ((Object)val == (Object)null || val.materials == null)
					{
						continue;
					}
					Material[] materials = val.materials;
					foreach (Material val2 in materials)
					{
						if (!((Object)val2 == (Object)null))
						{
							val2.EnableKeyword("_EMISSION");
							val2.SetColor("_EmissionColor", color * emission);
						}
					}
				}
				GameObject val3 = new GameObject("ChaosCarnival.GlowLight");
				val3.transform.SetParent(obj.transform, false);
				val3.transform.localPosition = Vector3.up * 0.1f;
				Light obj2 = val3.AddComponent<Light>();
				obj2.type = (LightType)2;
				obj2.color = color;
				obj2.range = lightRange;
				obj2.intensity = lightIntensity;
				obj2.shadows = (LightShadows)0;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Fx] Glow failed on " + ((Object)obj).name + ": " + ex.Message));
			}
		}

		public static void Poof(Vector3 position, Color color, int particles = 30)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0011: 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_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_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0068: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			try
			{
				GameObject val = new GameObject("ChaosCarnival.Poof");
				val.transform.position = position + Vector3.up * 0.4f;
				ParticleSystem val2 = val.AddComponent<ParticleSystem>();
				MainModule main = val2.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(color);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.25f, 0.6f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.8f, 2.2f);
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 0.9f);
				((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.05f);
				((MainModule)(ref main)).loop = false;
				((MainModule)(ref main)).playOnAwake = false;
				EmissionModule emission = val2.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)particles)
				});
				ShapeModule shape = val2.shape;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radius = 0.35f;
				((Renderer)val.GetComponent<ParticleSystemRenderer>()).material = new Material(Shader.Find("Sprites/Default"))
				{
					color = color
				};
				val2.Play();
				Object.Destroy((Object)val, 2f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Fx] Poof failed: " + ex.Message));
			}
		}

		public static void Aura(GameObject obj, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0050: 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_006b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0102: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			if ((Object)obj == (Object)null || (Object)obj.transform.Find("ChaosCarnival.Aura") != (Object)null)
			{
				return;
			}
			try
			{
				GameObject val = new GameObject("ChaosCarnival.Aura");
				val.transform.SetParent(obj.transform, false);
				val.transform.localPosition = Vector3.up * 0.6f;
				ParticleSystem obj2 = val.AddComponent<ParticleSystem>();
				MainModule main = obj2.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(color.r, color.g, color.b, 0.55f));
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.15f, 0.4f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.2f, 0.7f);
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.8f, 1.4f);
				((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.08f);
				((MainModule)(ref main)).loop = true;
				EmissionModule emission = obj2.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(14f);
				ShapeModule shape = obj2.shape;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radius = 0.45f;
				((Renderer)val.GetComponent<ParticleSystemRenderer>()).material = new Material(Shader.Find("Sprites/Default"))
				{
					color = color
				};
				obj2.Play();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Fx] Aura failed: " + ex.Message));
			}
		}

		public static void RemoveAura(GameObject obj)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			if (!((Object)obj == (Object)null))
			{
				Transform val = obj.transform.Find("ChaosCarnival.Aura");
				if ((Object)val != (Object)null)
				{
					Object.Destroy((Object)((Component)val).gameObject);
				}
			}
		}

		public static T GetField<T>(object obj, string field)
		{
			if (obj == null)
			{
				return default(T);
			}
			FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), field);
			if (!(fieldInfo == null))
			{
				return (T)fieldInfo.GetValue(obj);
			}
			return default(T);
		}

		public static void SetField(object obj, string field, object value)
		{
			AccessTools.Field(obj?.GetType(), field)?.SetValue(obj, value);
		}

		public static void CallMethod(object obj, string method, params object[] args)
		{
			AccessTools.Method(obj?.GetType(), method, (Type[])null, (Type[])null)?.Invoke(obj, args);
		}
	}
	public static class Hud
	{
		private static Texture2D _bg;

		private static GUIStyle _title;

		private static GUIStyle _row;

		private static GUIStyle _rowKlutz;

		private static GUIStyle _banner;

		private static string _bannerText;

		private static float _bannerUntil;

		private static float _spinStart;

		private static float _spinUntil;

		private static float _nextFlip;

		private static string _spinLabel;

		private static readonly string[] SpinLabels;

		public static void StartSpin(float seconds)
		{
			_spinStart = Time.time;
			_spinUntil = Time.time + seconds;
			_nextFlip = 0f;
		}

		static Hud()
		{
			_spinStart = -1f;
			_spinUntil = -1f;
			_spinLabel = "";
			SpinLabels = new string[14]
			{
				"x2 JACKPOT!!", "x1.5 WINNER!", "NOTHING...", "x0.75 TAX", "x0.5 BUST!!", "MONSTER NAP", "HEALING WAVE", "BANKRUPT!!", "SACRIFICE!", "BUBBLE GUTS!",
				"GOLDEN RAIN!", "LIGHTS OUT!", "GRAVE ROBBER!", "JITTERS!"
			};
			Net.OnBroadcast += delegate(string text, float seconds)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_bannerText = text;
				_bannerUntil = Time.time + seconds;
				_spinUntil = -1f;
				try
				{
					SemiFunc.UIBigMessage(text, "\ud83c\udfb0", 1.1f, Color.yellow, Color.white);
				}
				catch
				{
				}
			};
		}

		public static void Draw()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Enabled)
			{
				return;
			}
			DrawBanner();
			if (!Plugin.CfgHud.Value || !ShouldShow())
			{
				return;
			}
			EnsureStyles();
			CarnivalState state = Net.State;
			int num = Mathf.Max(1, state.TallyNames.Length);
			float num2 = 250f;
			float num3 = 52f + 20f * (float)num + (string.IsNullOrEmpty(state.KlutzName) ? 0f : 22f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((float)Screen.width - num2 - 18f, 80f, num2, num3);
			GUI.DrawTexture(val, (Texture)_bg, (ScaleMode)0);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 10f, ((Rect)(ref val)).y + 8f, ((Rect)(ref val)).width - 20f, ((Rect)(ref val)).height - 12f));
			GUILayout.Label("ACCIDENT TALLY", _title, Array.Empty<GUILayoutOption>());
			if (state.TallyNames.Length == 0)
			{
				GUILayout.Label("Clean record... so far.", _row, Array.Empty<GUILayoutOption>());
			}
			else
			{
				for (int i = 0; i < state.TallyNames.Length && i < state.TallyDamage.Length; i++)
				{
					bool flag = state.TallyNames[i].Equals(state.KlutzName, StringComparison.OrdinalIgnoreCase);
					GUILayout.Label($"{state.TallyNames[i]}  —  ${state.TallyDamage[i]:F0}", flag ? _rowKlutz : _row, Array.Empty<GUILayoutOption>());
				}
			}
			if (!string.IsNullOrEmpty(state.KlutzName))
			{
				GUILayout.Label("CURRENT KLUTZ: " + state.KlutzName, _rowKlutz, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndArea();
		}

		private static void DrawBanner()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_0109: 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_0151: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _spinUntil)
			{
				EnsureStyles();
				if (Time.time >= _nextFlip)
				{
					float num = Mathf.Clamp01((Time.time - _spinStart) / (_spinUntil - _spinStart));
					_spinLabel = SpinLabels[Random.Range(0, SpinLabels.Length)];
					_nextFlip = Time.time + Mathf.Lerp(0.07f, 0.5f, num * num);
				}
				Rect val = new Rect((float)Screen.width * 0.5f - 320f, (float)Screen.height * 0.12f, 640f, 46f);
				GUI.DrawTexture(val, (Texture)_bg, (ScaleMode)0);
				GUI.Label(val, "THE WHEEL SPINS...  [ " + _spinLabel + " ]", _banner);
			}
			else if (!string.IsNullOrEmpty(_bannerText) && !(Time.time > _bannerUntil))
			{
				EnsureStyles();
				float num2 = Mathf.Clamp01((_bannerUntil - Time.time) / 0.6f);
				Color color = GUI.color;
				Rect val2 = new Rect((float)Screen.width * 0.5f - 320f, (float)Screen.height * 0.12f, 640f, 46f);
				GUI.color = new Color(1f, 1f, 1f, num2 * 0.85f);
				GUI.DrawTexture(val2, (Texture)_bg, (ScaleMode)0);
				GUI.color = new Color(1f, 1f, 1f, num2);
				GUI.Label(val2, _bannerText, _banner);
				GUI.color = color;
			}
		}

		private static bool ShouldShow()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			try
			{
				PlayerAvatar instance = PlayerAvatar.instance;
				if ((Object)instance != (Object)null && Fx.GetField<bool>(instance, "isDisabled"))
				{
					return true;
				}
				MapToolController instance2 = MapToolController.instance;
				if ((Object)instance2 != (Object)null && Fx.GetField<bool>(instance2, "Active"))
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static void EnsureStyles()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_003e: 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_0057: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00ac: Expected O, but got Unknown
			//IL_00ac: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00e4: Expected O, but got Unknown
			//IL_00e4: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			if (!((Object)_bg != (Object)null))
			{
				_bg = new Texture2D(1, 1, (TextureFormat)4, false);
				_bg.SetPixel(0, 0, new Color(0.05f, 0.02f, 0.08f, 0.82f));
				_bg.Apply();
				GUIStyle val = new GUIStyle
				{
					fontSize = 15,
					fontStyle = (FontStyle)1
				};
				val.normal.textColor = new Color(1f, 0.85f, 0.2f);
				_title = val;
				GUIStyle val2 = new GUIStyle
				{
					fontSize = 13
				};
				val2.normal.textColor = Color.white;
				_row = val2;
				GUIStyle val3 = new GUIStyle
				{
					fontSize = 13,
					fontStyle = (FontStyle)1
				};
				val3.normal.textColor = new Color(1f, 0.35f, 0.3f);
				_rowKlutz = val3;
				GUIStyle val4 = new GUIStyle
				{
					fontSize = 22,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				val4.normal.textColor = new Color(1f, 0.9f, 0.4f);
				_banner = val4;
			}
		}
	}
	public static class Net
	{
		private static NetworkedEvent _stateEvent;

		private static NetworkedEvent _poofEvent;

		private static NetworkedEvent _pingEvent;

		private static NetworkedEvent _textEvent;

		private static bool _dirty;

		private static float _heartbeat;

		private const float HeartbeatSeconds = 2f;

		private static readonly RaiseEventOptions ToAll = new RaiseEventOptions
		{
			Receivers = (ReceiverGroup)1
		};

		public static CarnivalState State { get; private set; } = new CarnivalState();

		public static bool IsAuthority
		{
			get
			{
				if (SemiFunc.IsMultiplayer())
				{
					return PhotonNetwork.IsMasterClient;
				}
				return true;
			}
		}

		public static event Action OnStateChanged;

		public static event Action<Vector3[]> OnPoof;

		public static event Action<int, Vector3> OnPing;

		public static event Action<string, float> OnBroadcast;

		public static void Init()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			_stateEvent = new NetworkedEvent("ChaosCarnival.State", (Action<EventData>)OnStateEvent);
			_poofEvent = new NetworkedEvent("ChaosCarnival.Poof", (Action<EventData>)OnPoofEvent);
			_pingEvent = new NetworkedEvent("ChaosCarnival.Ping", (Action<EventData>)OnPingEvent);
			_textEvent = new NetworkedEvent("ChaosCarnival.Text", (Action<EventData>)OnTextEvent);
		}

		public static void MarkDirty()
		{
			_dirty = true;
		}

		public static void ResetRound()
		{
			State = new CarnivalState();
			MarkDirty();
		}

		public static void ResetRoundPreservingKlutz()
		{
			string klutzName = State.KlutzName;
			State = new CarnivalState
			{
				KlutzName = klutzName
			};
			MarkDirty();
		}

		public static void Tick()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAuthority)
			{
				return;
			}
			_heartbeat -= Time.deltaTime;
			if (!_dirty && !(_heartbeat <= 0f))
			{
				return;
			}
			_dirty = false;
			_heartbeat = 2f;
			try
			{
				_stateEvent.RaiseEvent((object)State.Pack(), ToAll, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] State broadcast failed: " + ex.Message));
			}
		}

		public static void SendPoof(Vector3[] positions)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAuthority || positions == null || positions.Length == 0)
			{
				return;
			}
			try
			{
				object[] array = new object[positions.Length];
				for (int i = 0; i < positions.Length; i++)
				{
					array[i] = positions[i];
				}
				_poofEvent.RaiseEvent((object)array, ToAll, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Poof broadcast failed: " + ex.Message));
			}
		}

		private static void OnStateEvent(EventData e)
		{
			try
			{
				State = CarnivalState.Unpack((object[])e.CustomData);
				Net.OnStateChanged?.Invoke();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Bad state payload: " + ex.Message));
			}
		}

		public static void SendPing(int type, Vector3 position)
		{
			//IL_001f: 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)
			if (!IsAuthority)
			{
				return;
			}
			try
			{
				_pingEvent.RaiseEvent((object)new object[2] { type, position }, ToAll, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Ping broadcast failed: " + ex.Message));
			}
		}

		public static void Broadcast(string text, float seconds = 4f)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAuthority || string.IsNullOrEmpty(text))
			{
				return;
			}
			try
			{
				_textEvent.RaiseEvent((object)new object[2] { text, seconds }, ToAll, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Broadcast failed: " + ex.Message));
			}
		}

		private static void OnTextEvent(EventData e)
		{
			try
			{
				object[] array = (object[])e.CustomData;
				Net.OnBroadcast?.Invoke((string)array[0], (float)array[1]);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Bad broadcast payload: " + ex.Message));
			}
		}

		private static void OnPingEvent(EventData e)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object[] array = (object[])e.CustomData;
				Net.OnPing?.Invoke((int)array[0], (Vector3)array[1]);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Bad ping payload: " + ex.Message));
			}
		}

		private static void OnPoofEvent(EventData e)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object[] array = (object[])e.CustomData;
				Vector3[] array2 = (Vector3[])(object)new Vector3[array.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array2[i] = (Vector3)array[i];
				}
				Net.OnPoof?.Invoke(array2);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Bad poof payload: " + ex.Message));
			}
		}

		public static PlayerAvatar FindAvatar(int avatarViewID)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (avatarViewID < 0)
			{
				return null;
			}
			if (avatarViewID > 0)
			{
				PhotonView val = PhotonView.Find(avatarViewID);
				if ((Object)val != (Object)null)
				{
					PlayerAvatar component = ((Component)val).GetComponent<PlayerAvatar>();
					if ((Object)component != (Object)null)
					{
						return component;
					}
				}
			}
			if ((Object)PlayerAvatar.instance != (Object)null)
			{
				return PlayerAvatar.instance;
			}
			return null;
		}

		public static GameObject FindViewObject(int viewID)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (viewID < 0)
			{
				return null;
			}
			PhotonView val = PhotonView.Find(viewID);
			if (!((Object)val != (Object)null))
			{
				return null;
			}
			return ((Component)val).gameObject;
		}
	}
	public static class ObjLoader
	{
		private class Mtl
		{
			public Color Color = Color.gray;

			public string TexPath;
		}

		public static string AssetDir
		{
			get
			{
				string text = "";
				try
				{
					string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
					if (!string.IsNullOrEmpty(directoryName))
					{
						text = Path.Combine(directoryName, "assets");
					}
				}
				catch
				{
				}
				if (string.IsNullOrEmpty(text) || !Directory.Exists(text))
				{
					text = Path.Combine(Paths.PluginPath, "BonelessProductions-ChaosCarnival", "assets");
				}
				if (!Directory.Exists(text))
				{
					text = Path.Combine(Paths.PluginPath, "ChaosCarnival", "assets");
				}
				if (!Directory.Exists(text))
				{
					try
					{
						string[] directories = Directory.GetDirectories(Paths.PluginPath, "assets", SearchOption.AllDirectories);
						foreach (string text2 in directories)
						{
							if (Directory.Exists(Path.Combine(text2, "models")))
							{
								text = text2;
								break;
							}
						}
					}
					catch
					{
					}
				}
				return text;
			}
		}

		public static GameObject Load(string objPath, float scale = 1f, Shader customShader = null)
		{
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Expected O, but got Unknown
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Expected O, but got Unknown
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Expected O, but got Unknown
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Expected O, but got Unknown
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_0736: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Expected O, but got Unknown
			//IL_079a: Unknown result type (might be due to invalid IL or missing references)
			//IL_079f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Expected O, but got Unknown
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_0562: Unknown result type (might be due to invalid IL or missing references)
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_069d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Expected O, but got Unknown
			//IL_06aa: Expected O, but got Unknown
			//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Expected O, but got Unknown
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Expected O, but got Unknown
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Expected O, but got Unknown
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05df: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ea: Expected O, but got Unknown
			//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Expected O, but got Unknown
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_061e: Expected O, but got Unknown
			//IL_0638: Unknown result type (might be due to invalid IL or missing references)
			//IL_0642: Expected O, but got Unknown
			try
			{
				if (!File.Exists(objPath))
				{
					Plugin.Log.LogWarning((object)("[ObjLoader] Not found: " + objPath));
					return null;
				}
				List<Vector3> positions = new List<Vector3>();
				List<Vector3> normals = new List<Vector3>();
				List<Vector2> uvs = new List<Vector2>();
				Dictionary<string, List<int>> dictionary = new Dictionary<string, List<int>>();
				Dictionary<string, int> vertexMap = new Dictionary<string, int>();
				List<Vector3> finalVerts = new List<Vector3>();
				List<Vector3> finalNorms = new List<Vector3>();
				List<Vector2> finalUVs = new List<Vector2>();
				bool anyNormals = false;
				string key = "default";
				string mtlFile = null;
				CultureInfo inv = CultureInfo.InvariantCulture;
				foreach (string item4 in File.ReadLines(objPath))
				{
					string text = item4.Trim();
					if (text.Length == 0 || text[0] == '#')
					{
						continue;
					}
					string[] array = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					switch (array[0])
					{
					case "mtllib":
						mtlFile = text.Substring(7).Trim();
						break;
					case "usemtl":
						key = array[1];
						break;
					case "v":
						positions.Add(new Vector3(0f - float.Parse(array[1], inv), float.Parse(array[2], inv), float.Parse(array[3], inv)));
						break;
					case "vn":
						normals.Add(new Vector3(0f - float.Parse(array[1], inv), float.Parse(array[2], inv), float.Parse(array[3], inv)));
						break;
					case "vt":
						uvs.Add(new Vector2(float.Parse(array[1], inv), (array.Length > 2) ? float.Parse(array[2], inv) : 0f));
						break;
					case "f":
					{
						if (!dictionary.TryGetValue(key, out var value))
						{
							List<int> list = (dictionary[key] = new List<int>());
							value = list;
						}
						int item = Corner(array[1]);
						for (int i = 2; i < array.Length - 1; i++)
						{
							int item2 = Corner(array[i]);
							int item3 = Corner(array[i + 1]);
							value.Add(item);
							value.Add(item3);
							value.Add(item2);
						}
						break;
					}
					}
				}
				if (finalVerts.Count == 0)
				{
					Plugin.Log.LogWarning((object)"[ObjLoader] Empty mesh.");
					return null;
				}
				Mesh val = new Mesh
				{
					name = Path.GetFileNameWithoutExtension(objPath)
				};
				if (finalVerts.Count > 65000)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.SetVertices(finalVerts);
				val.SetNormals(finalNorms);
				val.SetUVs(0, finalUVs);
				List<string> list3 = new List<string>(dictionary.Keys);
				val.subMeshCount = list3.Count;
				for (int j = 0; j < list3.Count; j++)
				{
					val.SetTriangles(dictionary[list3[j]], j);
				}
				if (!anyNormals)
				{
					val.RecalculateNormals();
				}
				val.RecalculateBounds();
				Dictionary<string, Mtl> dictionary2 = LoadMtl(objPath, mtlFile);
				Shader val2 = customShader ?? Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("HDRP/Lit") ?? Shader.Find("Standard") ?? Shader.Find("Sprites/Default");
				if ((Object)val2 == (Object)null)
				{
					Material[] array2 = Resources.FindObjectsOfTypeAll<Material>();
					foreach (Material val3 in array2)
					{
						if ((Object)val3 != (Object)null && (Object)val3.shader != (Object)null && (((Object)val3.shader).name.Contains("Lit") || ((Object)val3.shader).name.Contains("Standard")))
						{
							val2 = val3.shader;
							break;
						}
					}
				}
				if ((Object)val2 == (Object)null)
				{
					val2 = Shader.Find("Sprites/Default") ?? Shader.Find("UI/Default") ?? Shader.Find("Hidden/Internal-Colored");
				}
				Material[] array3 = (Material[])(object)new Material[list3.Count];
				for (int l = 0; l < list3.Count; l++)
				{
					Material val4 = new Material(val2);
					Mtl mtl = null;
					if (dictionary2.TryGetValue(list3[l], out var value2))
					{
						mtl = value2;
					}
					else if (dictionary2.Count > 0)
					{
						using Dictionary<string, Mtl>.Enumerator enumerator2 = dictionary2.GetEnumerator();
						if (enumerator2.MoveNext())
						{
							mtl = enumerator2.Current.Value;
						}
					}
					if (mtl != null)
					{
						Color val5 = (val4.color = mtl.Color);
						Color val6 = val5;
						if (val4.HasProperty("_BaseColor"))
						{
							val4.SetColor("_BaseColor", val6);
						}
						if (val4.HasProperty("_Color"))
						{
							val4.SetColor("_Color", val6);
						}
						if (val4.HasProperty("_MainColor"))
						{
							val4.SetColor("_MainColor", val6);
						}
						if (val4.HasProperty("_Tint"))
						{
							val4.SetColor("_Tint", val6);
						}
						Texture2D val7 = ((mtl.TexPath != null) ? LoadTexture(mtl.TexPath) : CreateSolidTexture(val6));
						if ((Object)val7 != (Object)null)
						{
							val4.mainTexture = (Texture)val7;
							if (val4.HasProperty("_BaseMap"))
							{
								val4.SetTexture("_BaseMap", (Texture)val7);
							}
							if (val4.HasProperty("_MainTex"))
							{
								val4.SetTexture("_MainTex", (Texture)val7);
							}
						}
					}
					else
					{
						val4.color = Color.gray;
						if (val4.HasProperty("_BaseColor"))
						{
							val4.SetColor("_BaseColor", Color.gray);
						}
						if (val4.HasProperty("_Color"))
						{
							val4.SetColor("_Color", Color.gray);
						}
						Texture val8 = (Texture)CreateSolidTexture(Color.gray);
						Texture val9 = val8;
						val4.mainTexture = val8;
						Texture2D val10 = (Texture2D)val9;
						if (val4.HasProperty("_BaseMap"))
						{
							val4.SetTexture("_BaseMap", (Texture)val10);
						}
						if (val4.HasProperty("_MainTex"))
						{
							val4.SetTexture("_MainTex", (Texture)val10);
						}
					}
					array3[l] = val4;
				}
				GameObject val11 = new GameObject(((Object)val).name);
				val11.AddComponent<MeshFilter>().sharedMesh = val;
				((Renderer)val11.AddComponent<MeshRenderer>()).sharedMaterials = array3;
				val11.transform.localScale = Vector3.one * scale;
				ManualLogSource log = Plugin.Log;
				string text2 = $"[ObjLoader] Loaded \"{((Object)val).name}\": {finalVerts.Count} verts, ";
				object arg = list3.Count;
				string arg2 = (anyNormals ? "file" : "computed");
				Bounds bounds = val.bounds;
				log.LogInfo((object)(text2 + $"{arg} mat(s), normals={arg2}, bounds {((Bounds)(ref bounds)).size}."));
				return val11;
				int Corner(string token)
				{
					//IL_0085: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ec: 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)
					if (vertexMap.TryGetValue(token, out var value3))
					{
						return value3;
					}
					string[] array4 = token.Split('/');
					int index = int.Parse(array4[0], inv) - 1;
					int num = ((array4.Length > 1 && array4[1].Length > 0) ? (int.Parse(array4[1], inv) - 1) : (-1));
					int num2 = ((array4.Length > 2 && array4[2].Length > 0) ? (int.Parse(array4[2], inv) - 1) : (-1));
					finalVerts.Add(positions[index]);
					if (num2 >= 0 && num2 < normals.Count)
					{
						finalNorms.Add(normals[num2]);
						anyNormals = true;
					}
					else
					{
						finalNorms.Add(Vector3.up);
					}
					finalUVs.Add((num >= 0 && num < uvs.Count) ? uvs[num] : Vector2.zero);
					int num3 = finalVerts.Count - 1;
					vertexMap[token] = num3;
					return num3;
				}
			}
			catch (Exception arg3)
			{
				Plugin.Log.LogError((object)$"[ObjLoader] Failed loading {objPath}: {arg3}");
				return null;
			}
		}

		private static Dictionary<string, Mtl> LoadMtl(string objPath, string mtlFile)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Mtl> dictionary = new Dictionary<string, Mtl>();
			try
			{
				if (string.IsNullOrEmpty(mtlFile))
				{
					return dictionary;
				}
				string path = Path.GetDirectoryName(objPath) ?? "";
				string path2 = Path.Combine(path, mtlFile);
				if (!File.Exists(path2))
				{
					return dictionary;
				}
				CultureInfo invariantCulture = CultureInfo.InvariantCulture;
				Mtl mtl = null;
				foreach (string item in File.ReadLines(path2))
				{
					string text = item.Trim();
					if (text.StartsWith("newmtl "))
					{
						mtl = new Mtl();
						dictionary[text.Substring(7).Trim()] = mtl;
					}
					else if (mtl != null)
					{
						if (text.StartsWith("Kd "))
						{
							string[] array = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
							mtl.Color = new Color(float.Parse(array[1], invariantCulture), float.Parse(array[2], invariantCulture), float.Parse(array[3], invariantCulture));
						}
						else if (text.StartsWith("map_Kd "))
						{
							string path3 = text.Substring(7).Trim().Replace("\\", "/");
							mtl.TexPath = Path.Combine(path, path3);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[ObjLoader] MTL parse failed: " + ex.Message));
			}
			return dictionary;
		}

		private static Texture2D LoadTexture(string path)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			try
			{
				if (string.IsNullOrEmpty(path) || !File.Exists(path))
				{
					return null;
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
				byte[] array = File.ReadAllBytes(path);
				MethodInfo methodInfo = AccessTools.Method(typeof(Texture2D), "LoadImage", new Type[1] { typeof(byte[]) }, (Type[])null);
				if (methodInfo != null && (bool)methodInfo.Invoke(val, new object[1] { array }))
				{
					return val;
				}
				MethodInfo methodInfo2 = AccessTools.Method("UnityEngine.ImageConversion:LoadImage", new Type[2]
				{
					typeof(Texture2D),
					typeof(byte[])
				}, (Type[])null);
				if (methodInfo2 != null && (bool)methodInfo2.Invoke(null, new object[2] { val, array }))
				{
					return val;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[ObjLoader] Texture load failed (" + path + "): " + ex.Message));
			}
			return null;
		}

		private static Texture2D CreateSolidTexture(Color color)
		{
			//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_000c: 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_0019: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}
	}
	public static class Patches
	{
		private static readonly FieldInfo NameplateText = AccessTools.Field(typeof(WorldSpaceUIPlayerName), "text");

		private static readonly FieldInfo NameplateAvatar = AccessTools.Field(typeof(WorldSpaceUIPlayerName), "playerAvatar");

		private static readonly FieldInfo LastPlayerGrabbing = AccessTools.Field(typeof(PhysGrabObject), "lastPlayerGrabbing");

		[HarmonyPatch(typeof(ValuableDirector), "VolumesAndSwitchSetup")]
		[HarmonyPostfix]
		public static void OnValuablesSpawned()
		{
			try
			{
				if (Plugin.Enabled && Net.IsAuthority && Plugin.IsAdventureLevel())
				{
					Net.ResetRoundPreservingKlutz();
					Curses.HostRoundSetup();
					Lottery.HostRoundSetup();
					Meltdown.HostRoundSetup();
					Snitch.HostRoundSetup();
					Blackout.HostRoundSetup();
					Portals.HostRoundSetup();
					Roulette.HostRoundSetup();
					CustomItems.HostRoundRoll();
					TestMode.QueuePlacement();
					Plugin.Log.LogInfo((object)"[Round] New round initialized.");
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnValuablesSpawned: {arg}");
			}
		}

		[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
		[HarmonyPrefix]
		public static void OnLevelChange()
		{
			try
			{
				if (Plugin.Enabled && Net.IsAuthority)
				{
					Klutz.HostRoundEnd();
					Lottery.HostRoundEnd();
					Meltdown.HostRoundEnd();
					Blackout.HostRoundEnd();
					Curses.HostCleanup();
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnLevelChange: {arg}");
			}
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabStarted")]
		[HarmonyPostfix]
		public static void OnGrabStarted(PhysGrabObject __instance, PhysGrabber player)
		{
			try
			{
				Curses.HostOnGrab(__instance, player);
				Meltdown.HostOnGrab(__instance, player);
				Roulette.HostOnGrab(__instance, player);
				TestMode.HostOnGrab(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnGrabStarted: {arg}");
			}
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabEnded")]
		[HarmonyPostfix]
		public static void OnGrabEnded(PhysGrabObject __instance)
		{
			try
			{
				Curses.HostOnRelease(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnGrabEnded: {arg}");
			}
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
		[HarmonyPrefix]
		public static void OnItemBreak(PhysGrabObjectImpactDetector __instance, float valueLost, PhotonMessageInfo _info, PhysGrabObject ___physGrabObject)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0077: 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: Expected O, but got Unknown
			//IL_007f: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			try
			{
				if (Plugin.Enabled && (Object)___physGrabObject != (Object)null && Net.State.PossessedPlayerViewID != -1)
				{
					PhotonView component = ((Component)___physGrabObject).GetComponent<PhotonView>();
					if ((Object)component != (Object)null && component.ViewID == Net.State.CursedViewID)
					{
						Curses.RestorePossession();
						if (Net.IsAuthority)
						{
							Curses.HostClearPossession();
						}
					}
				}
				if (!Plugin.Enabled || !Net.IsAuthority || valueLost <= 0f)
				{
					return;
				}
				string playerName = null;
				if (_info.Sender != null && !string.IsNullOrEmpty(_info.Sender.NickName))
				{
					playerName = _info.Sender.NickName;
				}
				else if ((Object)___physGrabObject != (Object)null && LastPlayerGrabbing != null)
				{
					object value = LastPlayerGrabbing.GetValue(___physGrabObject);
					PlayerAvatar val = (PlayerAvatar)((value is PlayerAvatar) ? value : null);
					if ((Object)val != (Object)null)
					{
						playerName = Fx.GetField<string>(val, "playerName");
					}
				}
				Klutz.HostRecordBreak(playerName, valueLost);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnItemBreak: {arg}");
			}
		}

		[HarmonyPatch(typeof(WorldSpaceUIPlayerName), "Update")]
		[HarmonyPostfix]
		public static void OnNameplateUpdate(WorldSpaceUIPlayerName __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			try
			{
				if (Plugin.Enabled)
				{
					object obj = NameplateText?.GetValue(__instance);
					object obj2 = ((obj is TextMeshProUGUI) ? obj : null);
					object obj3 = NameplateAvatar?.GetValue(__instance);
					Klutz.DecorateNameplate(avatar: (PlayerAvatar)((obj3 is PlayerAvatar) ? obj3 : null), text: (TextMeshProUGUI)obj2);
				}
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(PlayerHealth), "Hurt")]
		[HarmonyPrefix]
		public static bool OnPlayerHurt(PlayerHealth __instance)
		{
			try
			{
				return WeenieBox.BlockLocalDamage(__instance);
			}
			catch
			{
				return true;
			}
		}

		[HarmonyPatch(typeof(Enemy), "SetChaseTarget")]
		[HarmonyPrefix]
		public static bool OnEnemySetChaseTarget(Enemy __instance, PlayerAvatar playerAvatar)
		{
			try
			{
				return WeenieBox.BlockChaseTarget(__instance, playerAvatar);
			}
			catch
			{
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemInfoUI), "ItemInfoText")]
		[HarmonyPrefix]
		public static void OnItemInfoText(ItemAttributes _itemAttributes, ref string message)
		{
			try
			{
				Lottery.DecorateItemInfo(_itemAttributes, ref message);
				Meltdown.DecorateItemInfo(_itemAttributes, ref message);
				Roulette.DecorateItemInfo(_itemAttributes, ref message);
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInHaulList")]
		[HarmonyPrefix]
		public static void OnExtractionCashout()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			try
			{
				if (Net.State.PossessedPlayerViewID != -1 && Net.State.CursedViewID != -1)
				{
					GameObject val = Net.FindViewObject(Net.State.CursedViewID);
					if ((Object)val != (Object)null)
					{
						List<GameObject> list = (((Object)RoundDirector.instance != (Object)null) ? Fx.GetField<List<GameObject>>(RoundDirector.instance, "dollarHaulList") : null);
						if (list != null && list.Contains(val))
						{
							Curses.RestorePossession();
							if (Net.IsAuthority)
							{
								Curses.HostClearPossession();
							}
						}
					}
				}
				Roulette.HostOnExtraction();
				Lottery.HostOnExtractionCashout();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnExtractionCashout: {arg}");
			}
		}

		[HarmonyPatch(typeof(ItemGun), "ShootBulletRPC")]
		[HarmonyPostfix]
		public static void OnGunShot(ItemGun __instance, Vector3 _endPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Portals.HostOnGunShot(__instance, _endPosition);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnGunShot: {arg}");
			}
		}

		[HarmonyPatch(typeof(ItemHealthPack), "Update")]
		[HarmonyPrefix]
		public static bool OnHealthPackUpdate(ItemHealthPack __instance)
		{
			try
			{
				if (JumperCables.HandleUse(__instance))
				{
					return false;
				}
				if (PowerUp.HandleUse(__instance))
				{
					return false;
				}
				if (WeenieBox.HandleUse(__instance))
				{
					return false;
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnHealthPackUpdate: {arg}");
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyGnomeDirector), "Update")]
		[HarmonyPostfix]
		public static void OnGnomeDirectorUpdate()
		{
			try
			{
				Curses.HostRetargetGoblins();
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(PhysGrabCart), "Start")]
		[HarmonyPostfix]
		public static void OnCartStart(PhysGrabCart __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			try
			{
				ItemAttributes component = ((Component)__instance).GetComponent<ItemAttributes>();
				if (((Object)component != (Object)null && CustomItems.IsWeenieBox(component)) || WeenieBox.DeployingTimer > 0f)
				{
					((Component)__instance).gameObject.AddComponent<WeenieBoxController>();
					Plugin.Log.LogInfo((object)"[Weenie] Attached WeenieBoxController to spawned physical cart.");
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnCartStart: {arg}");
			}
		}
	}
	[BepInPlugin("com.chaoscarnival.repo", "ChaosCarnival", "1.0.27")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<bool> CfgEnabled;

		public static ConfigEntry<bool> CfgCurses;

		public static ConfigEntry<bool> CfgCurseFarts;

		public static ConfigEntry<bool> CfgCurseTiny;

		public static ConfigEntry<bool> CfgCurseJitters;

		public static ConfigEntry<bool> CfgCurseDecay;

		public static ConfigEntry<bool> CfgCurseRadiation;

		public static ConfigEntry<bool> CfgCurseConfession;

		public static ConfigEntry<bool> CfgCurseSloth;

		public static ConfigEntry<bool> CfgCurseHelium;

		public static ConfigEntry<bool> CfgCurseBlind;

		public static ConfigEntry<bool> CfgCurseMagnet;

		public static ConfigEntry<bool> CfgCursePossession;

		public static ConfigEntry<float> CfgInfectionSeconds;

		public static ConfigEntry<bool> CfgKlutz;

		public static ConfigEntry<bool> CfgWeenieBox;

		public static ConfigEntry<float> CfgWeenieBoxRadius;

		public static ConfigEntry<int> CfgClownNoseId;

		public static ConfigEntry<float> CfgNoseScale;

		public static ConfigEntry<bool> CfgMeltdown;

		public static ConfigEntry<float> CfgMeltdownInterval;

		public static ConfigEntry<float> CfgFartMinInterval;

		public static ConfigEntry<float> CfgFartMaxInterval;

		public static ConfigEntry<bool> CfgVoiceVibrato;

		public static ConfigEntry<bool> CfgTestMode;

		public static ConfigEntry<float> CfgFeatureChance;

		public static ConfigEntry<float> CfgShopChance;

		public static ConfigEntry<bool> CfgHud;

		public static ConfigEntry<int> CfgGoblinGroups;

		public static ConfigEntry<bool> CfgBlackout;

		public static ConfigEntry<float> CfgBlackoutInterval;

		public static ConfigEntry<float> CfgBlackoutDuration;

		public static ConfigEntry<bool> CfgSnitch;

		public static ConfigEntry<int> CfgSnitchUnmaskAfter;

		public static ConfigEntry<bool> CfgRoulette;

		public static ConfigEntry<bool> CfgPortalGun;

		public static ConfigEntry<bool> CfgPortalView;

		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static bool Enabled
		{
			get
			{
				if (CfgEnabled != null)
				{
					return CfgEnabled.Value;
				}
				return true;
			}
		}

		public static bool FeatureRoll()
		{
			if (!TestMode.On)
			{
				return Random.value <= CfgFeatureChance.Value;
			}
			return true;
		}

		private void Awake()
		{
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Expected O, but got Unknown
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Expected O, but got Unknown
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Expected O, but got Unknown
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Expected O, but got Unknown
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Expected O, but got Unknown
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Expected O, but got Unknown
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Expected O, but got Unknown
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Expected O, but got Unknown
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Expected O, but got Unknown
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Expected O, but got Unknown
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Expected O, but got Unknown
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Expected O, but got Unknown
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Expected O, but got Unknown
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Expected O, but got Unknown
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Expected O, but got Unknown
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Expected O, but got Unknown
			//IL_060f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle for all ChaosCarnival features.");
			CfgCurses = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Enabled", true, "One random valuable per round is cursed (red glow) with a RANDOM curse from the pool below. All curses come with Fart Goblins.");
			CfgCurseFarts = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-BubbleGuts", true, "Pool: farts through the holder's voice with matching voice vibrato.");
			CfgCurseTiny = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Tiny", true, "Pool: holder shrinks to half size with a squeaky voice.");
			CfgCurseJitters = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Jitters", true, "Pool: holder's movement randomly lurches and stutters.");
			CfgCurseDecay = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Decay", true, "Pool: holder's health ticks down (never below 1 HP).");
			CfgCurseRadiation = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Radiation", true, "Pool: holder emits toxic glow that INFECTS nearby players; contagious, drains health.");
			CfgCurseConfession = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Confession", true, "Pool: the holder's character periodically blurts embarrassing TTS confessions.");
			CfgCurseSloth = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Sloth", true, "Pool: holder moves in slow motion with a deep sluggish voice.");
			CfgCurseHelium = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Helium", true, "Pool: holder goes floaty (most gravity cancelled) with a helium voice.");
			CfgCurseBlind = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Blind", true, "Pool: crushing tunnel vision for the holder.");
			CfgCurseMagnet = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Magnet", true, "Pool: nearby loose loot is dragged toward the holder. Property damage likely.");
			CfgCursePossession = ((BaseUnityPlugin)this).Config.Bind<bool>("Cursed Item", "Curse-Possession", true, "Pool: traps the player as the item in 3rd person view; microphone speech shakes the item.");
			CfgInfectionSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Cursed Item", "InfectionSeconds", 12f, new ConfigDescription("How long a radiation infection lasts after last contact.", (AcceptableValueBase)new AcceptableValueRange<float>(4f, 60f), Array.Empty<object>()));
			CfgFartMinInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Fart Curse", "FartMinInterval", 1.2f, "Minimum seconds between farts while holding the cursed item.");
			CfgFartMaxInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Fart Curse", "FartMaxInterval", 2.8f, "Maximum seconds between farts while holding the cursed item.");
			CfgVoiceVibrato = ((BaseUnityPlugin)this).Config.Bind<bool>("Fart Curse", "VoiceVibrato", true, "Wobble the holder's actual voice in time with each fart.");
			CfgKlutz = ((BaseUnityPlugin)this).Config.Bind<bool>("Klutz", "Enabled", true, "Track item damage; the round's worst offender gets a clown nose and a [Klutz] tag.");
			CfgWeenieBox = ((BaseUnityPlugin)this).Config.Bind<bool>("Weenie Hiding Box", "Enabled", true, "Spawn a purchasable Weenie Hiding Box: players squatting flat inside it are safe and unseen.");
			CfgWeenieBoxRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Weenie Hiding Box", "Radius", 1.8f, new ConfigDescription("How close (meters) you must be to the box center to be protected.", (AcceptableValueBase)new AcceptableValueRange<float>(1f, 4f), Array.Empty<object>()));
			CfgMeltdown = ((BaseUnityPlugin)this).Config.Bind<bool>("Meltdown Contraband", "Enabled", true, "Mid-round loot race: a blue-glowing valuable's huge value melts every second until first grab locks it.");
			CfgMeltdownInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Meltdown Contraband", "IntervalSeconds", 200f, new ConfigDescription("Seconds between contraband drops after the first.", (AcceptableValueBase)new AcceptableValueRange<float>(60f, 600f), Array.Empty<object>()));
			CfgClownNoseId = ((BaseUnityPlugin)this).Config.Bind<int>("Klutz", "ClownNoseCosmeticId", 315, "Cosmetic ID force-equipped on the Klutz (default: clown nose).");
			CfgNoseScale = ((BaseUnityPlugin)this).Config.Bind<float>("Klutz", "NoseScale", 2f, new ConfigDescription("Size multiplier for the Klutz's clown nose. 1 = normal, 2 = double.", (AcceptableValueBase)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			CfgTestMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "TestMode", false, "PLAYTESTING ONLY: teleports special items to the spawn room (frozen until grabbed) and speeds up the first Contraband drop. Turn OFF for real runs.");
			CfgFeatureChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpecialItemChance", 0.25f, new ConfigDescription("Chance (0-1) for EACH special item (cursed, lottery, snitch, contraband, safety container, roulette token) to appear in a level. Test Mode forces all on.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			CfgShopChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "ShopItemChance", 0.25f, new ConfigDescription("Chance (0-1) for EACH custom purchasable (Jumper Cables, Portal Gun, Chaos Power-Up) to be available per level's shop stock.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			CfgHud = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "TallyOverlay", true, "Show the live Accident Tally + current Klutz while the map tool is open, and always while dead.");
			CfgGoblinGroups = ((BaseUnityPlugin)this).Config.Bind<int>("Cursed Item", "GoblinGroups", 1, new ConfigDescription("Fart Goblin GROUPS spawned on grab (each group is several gnomes).", (AcceptableValueBase)new AcceptableValueRange<int>(1, 4), Array.Empty<object>()));
			CfgBlackout = ((BaseUnityPlugin)this).Config.Bind<bool>("Blackout Protocol", "Enabled", true, "Periodic lights-out events: level goes dark, loot glows, enemies hunt by hints.");
			CfgBlackoutInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Blackout Protocol", "IntervalSeconds", 240f, new ConfigDescription("Seconds between blackouts after the first.", (AcceptableValueBase)new AcceptableValueRange<float>(90f, 600f), Array.Empty<object>()));
			CfgBlackoutDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Blackout Protocol", "DurationSeconds", 20f, new ConfigDescription("How long each blackout lasts.", (AcceptableValueBase)new AcceptableValueRange<float>(10f, 60f), Array.Empty<object>()));
			CfgSnitch = ((BaseUnityPlugin)this).Config.Bind<bool>("The Snitch", "Enabled", true, "One unmarked valuable rats out its carrier to every monster while carried.");
			CfgSnitchUnmaskAfter = ((BaseUnityPlugin)this).Config.Bind<int>("The Snitch", "UnmaskAfterScreams", 4, new ConfigDescription("Publicly reveal the snitch after this many screams.", (AcceptableValueBase)new AcceptableValueRange<int>(2, 10), Array.Empty<object>()));
			CfgRoulette = ((BaseUnityPlugin)this).Config.Bind<bool>("Extraction Roulette", "Enabled", true, "Every completed extraction spins a wheel: jackpots, taxes, monster naps, healing waves.");
			CfgPortalGun = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal Gun", "Enabled", true, "Shop weapon that shoots linked portals. Players (not items) travel entry -> exit.");
			CfgPortalView = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal Gun", "SeeThroughPortals", true, "Render a live view of the other side on each portal (small perf cost: two 256px cameras).");
			SoundBank.Bootstrap();
			Net.Init();
			Roulette.Init();
			_harmony = new Harmony("com.chaoscarnival.repo");
			_harmony.PatchAll(typeof(Patches));
			Log.LogInfo((object)string.Format("{0} v{1} loaded. Enabled={2}", "ChaosCarnival", "1.0.27", Enabled));
		}

		public static bool IsAdventureLevel()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			RunManager instance = RunManager.instance;
			if ((Object)instance != (Object)null && instance.levels != null && (Object)instance.levelCurrent != (Object)null)
			{
				return instance.levels.Contains(instance.levelCurrent);
			}
			return false;
		}

		private void Update()
		{
			if (!Enabled)
			{
				return;
			}
			try
			{
				CustomItems.TryRegister();
			}
			catch
			{
			}
			if (!IsAdventureLevel())
			{
				return;
			}
			try
			{
				Net.Tick();
				Curses.Tick();
				Curses.HostTick();
				Klutz.Tick();
				Lottery.Tick();
				Lottery.HostTick();
				WeenieBox.Tick();
				Meltdown.Tick();
				Meltdown.HostTick();
				Blackout.Tick();
				Blackout.HostTick();
				Snitch.HostTick();
				Roulette.Tick();
				Roulette.HostTick();
				Portals.Tick();
				Portals.HostTick();
				PowerUp.Tick();
				PowerUp.HostTick();
				TestMode.Tick();
			}
			catch (Exception arg)
			{
				if (Time.frameCount % 300 == 0)
				{
					Log.LogError((object)$"Update tick error: {arg}");
				}
			}
		}

		private void LateUpdate()
		{
			if (!Enabled || !IsAdventureLevel())
			{
				return;
			}
			try
			{
				Curses.LateTick();
			}
			catch
			{
			}
		}

		private void OnGUI()
		{
			if (!Enabled || !IsAdventureLevel())
			{
				return;
			}
			try
			{
				Hud.Draw();
			}
			catch
			{
			}
		}
	}
	public static class PluginInfo
	{
		public const string GUID = "com.chaoscarnival.repo";

		public const string NAME = "ChaosCarnival";

		public const string VERSION = "1.0.1";
	}
	public class SoundBank : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class _003CLoadSingleFileWeb_003Ed__16 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int _003C_003E1__state;

			private object _003C_003E2__current;

			public string file;

			public AudioType type;

			public Action<AudioClip> callback;

			private AudioClip _003Cclip_003E5__2;

			private UnityWebRequest _003Creq_003E5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return _003C_003E2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return _003C_003E2__current;
				}
			}

			[DebuggerHidden]
			public _003CLoadSingleFileWeb_003Ed__16(int _003C_003E1__state)
			{
				this._003C_003E1__state = _003C_003E1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = _003C_003E1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						_003C_003Em__Finally1();
					}
				}
				_003Cclip_003E5__2 = null;
				_003Creq_003E5__3 = null;
				_003C_003E1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_003a: 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_0062: Expected O, but got Unknown
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Invalid comparison between Unknown and I4
				try
				{
					switch (_003C_003E1__state)
					{
					default:
						return false;
					case 0:
					{
						_003C_003E1__state = -1;
						string absoluteUri = new Uri(file).AbsoluteUri;
						_003Cclip_003E5__2 = null;
						_003Creq_003E5__3 = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, type);
						_003C_003E1__state = -3;
						DownloadHandlerAudioClip val = (DownloadHandlerAudioClip)_003Creq_003E5__3.downloadHandler;
						if (val != null)
						{
							val.streamAudio = false;
						}
						_003Creq_003E5__3.timeout = 10;
						_003C_003E2__current = _003Creq_003E5__3.SendWebRequest();
						_003C_003E1__state = 1;
						return true;
					}
					case 1:
						_003C_003E1__state = -3;
						if ((int)_003Creq_003E5__3.result == 1)
						{
							try
							{
								_003Cclip_003E5__2 = DownloadHandlerAudioClip.GetContent(_003Creq_003E5__3);
							}
							catch
							{
							}
						}
						_003C_003Em__Finally1();
						_003Creq_003E5__3 = null;
						callback?.Invoke(_003Cclip_003E5__2);
						return false;
					}
				}
				catch
				{
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				return MoveNext();
			}

			private void _003C_003Em__Finally1()
			{
				_003C_003E1__state = -1;
				if (_003Creq_003E5__3 != null)
				{
					((IDisposable)_003Creq_003E5__3).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static readonly List<AudioClip> Farts = new List<AudioClip>();

		public static readonly List<AudioClip> Carnival = new List<AudioClip>();

		public static readonly List<AudioClip> Roulette = new List<AudioClip>();

		private bool _started;

		public static SoundBank Instance { get; private set; }

		public static bool Ready { get; private set; }

		public static void Bootstrap()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//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_0022: Expected O, but got Unknown
			if (!((Object)Instance != (Object)null))
			{
				GameObject val = new GameObject("ChaosCarnival.SoundBank");
				Object.DontDestroyOnLoad((Object)val);
				Instance = val.AddComponent<SoundBank>();
			}
		}

		private void Awake()
		{
			if (!_started)
			{
				_started = true;
				LoadAll();
			}
		}

		private void LoadAll()
		{
			string text = "";
			try
			{
				string location = Assembly.GetExecutingAssembly().Location;
				if (!string.IsNullOrEmpty(location))
				{
					string directoryName = Path.GetDirectoryName(location);
					if (!string.IsNullOrEmpty(directoryName))
					{
						text = Path.Combine(directoryName, "sounds");
					}
				}
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(text) || !Directory.Exists(text))
			{
				text = Path.Combine(Paths.PluginPath, "ChaosCarnival", "sounds");
			}
			if (!Directory.Exists(text))
			{
				try
				{
					string[] directories = Directory.GetDirectories(Paths.PluginPath, "sounds", SearchOption.AllDirectories);
					foreach (string text2 in directories)
					{
						if (Directory.Exists(Path.Combine(text2, "farts")))
						{
							text = text2;
							break;
						}
					}
				}
				catch
				{
				}
			}
			Plugin.Log.LogInfo((object)("[SoundBank] Resolving audio directory to: " + text));
			LoadFolder(Path.Combine(text, "farts"), Farts, "farts");
			LoadFolder(Path.Combine(text, "carnival"), Carnival, "carnival");
			LoadFolder(Path.Combine(text, "roulette"), Roulette, "roulette");
			Ready = Farts.Count > 0 || Carnival.Count > 0 || Roulette.Count > 0;
			Plugin.Log.LogInfo((object)$"[SoundBank] Ready! Loaded farts={Farts.Count}, carnival={Carnival.Count}, roulette={Roulette.Count}");
		}

		private void LoadFolder(string dir, List<AudioClip> into, string folderName)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			if (!Directory.Exists(dir))
			{
				return;
			}
			string[] files = Directory.GetFiles(dir, "*.*");
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			Array.Sort(files, delegate(string a, string b)
			{
				string text3 = Path.GetExtension(a).ToLowerInvariant();
				string text4 = Path.GetExtension(b).ToLowerInvariant();
				bool flag = text3 == ".wav";
				bool flag2 = text4 == ".wav";
				if (flag && !flag2)
				{
					return -1;
				}
				return (!flag && flag2) ? 1 : a.CompareTo(b);
			});
			string[] array = files;
			foreach (string text in array)
			{
				string text2 = Path.GetExtension(text).ToLowerInvariant();
				if (text2 != ".wav" && text2 != ".ogg" && text2 != ".mp3")
				{
					continue;
				}
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
				if (hashSet.Contains(fileNameWithoutExtension))
				{
					continue;
				}
				AudioClip val = null;
				if (text2 == ".wav")
				{
					try
					{
						val = LoadWavFile(text);
					}
					catch
					{
					}
				}
				if ((Object)val != (Object)null)
				{
					hashSet.Add(fileNameWithoutExtension);
					((Object)val).name = fileNameWithoutExtension;
					into.Add(val);
					Plugin.Log.LogInfo((object)$"[SoundBank] Loaded '{fileNameWithoutExtension}' into {folderName} ({val.length:F2}s)");
				}
				else
				{
					Plugin.Log.LogWarning((object)("[SoundBank] Could not decode audio file: " + text));
				}
			}
		}

		private IEnumerator LoadSingleFileWeb(string file, AudioType type, Action<AudioClip> callback)
		{
			//IL_000e: 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)
			try
			{
				int num = default(int);
				switch (num)
				{
				case 0:
				{
					string absoluteUri = new Uri(file).AbsoluteUri;
					UnityWebRequest val = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, type);
					DownloadHandlerAudioClip val2 = (DownloadHandlerAudioClip)val.downloadHandler;
					if (val2 != null)
					{
						val2.streamAudio = false;
					}
					val.timeout = 10;
					val.SendWebRequest();
					/*Error near IL_00f3: Unexpected return in MoveNext()*/;
				}
				case 1:
				{
					UnityWebRequest val = default(UnityWebRequest);
					AudioClip content = default(AudioClip);
					if ((int)val.result == 1)
					{
						try
						{
							content = DownloadHandlerAudioClip.GetContent(val);
						}
						catch
						{
						}
					}
					((_003CLoadSingleFileWeb_003Ed__16)/*Error near IL_00c1: stateMachine*/)._003C_003Em__Finally1();
					callback?.Invoke(content);
					break;
				}
				}
			}
			catch
			{
				((IDisposable)/*Error near IL_00ea: stateMachine*/).Dispose();
				throw;
			}
			yield break;
		}

		public static AudioClip LoadWavFile(string filePath)
		{
			byte[] array = File.ReadAllBytes(filePath);
			if (array.Length < 44)
			{
				return null;
			}
			if (array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70)
			{
				return null;
			}
			if (array[8] != 87 || array[9] != 65 || array[10] != 86 || array[11] != 69)
			{
				return null;
			}
			int num = BitConverter.ToInt16(array, 22);
			int num2 = BitConverter.ToInt32(array, 24);
			int num3 = BitConverter.ToInt16(array, 34);
			for (int i = 12; i < array.Length - 8; i++)
			{
				if (array[i] != 100 || array[i + 1] != 97 || array[i + 2] != 116 || array[i + 3] != 97)
				{
					continue;
				}
				i += 4;
				int num4 = BitConverter.ToInt32(array, i);
				i += 4;
				int num5 = num3 / 8;
				if (num5 <= 0)
				{
					return null;
				}
				int num6 = num4 / num5;
				int num7 = num6 / num;
				float[] array2 = new float[num6];
				switch (num3)
				{
				case 16:
				{
					int num9 = 0;
					for (int k = i; k < i + num4 && k < array.Length - 1; k += 2)
					{
						short num10 = BitConverter.ToInt16(array, k);
						array2[num9++] = (float)num10 / 32768f;
					}
					break;
				}
				case 32:
				{
					int num11 = 0;
					for (int l = i; l < i + num4 && l < array.Length - 3; l += 4)
					{
						array2[num11++] = BitConverter.ToSingle(array, l);
					}
					break;
				}
				case 8:
				{
					int num8 = 0;
					for (int j = i; j < i + num4 && j < array.Length; j++)
					{
						array2[num8++] = (float)(array[j] - 128) / 128f;
					}
					break;
				}
				}
				AudioClip obj = AudioClip.Create(Path.GetFileNameWithoutExtension(filePath), num7, num, num2, false);
				obj.SetData(array2, 0);
				return obj;
			}
			return null;
		}

		public static AudioClip RandomFart()
		{
			if (Farts.Count == 0)
			{
				return null;
			}
			return Farts[Random.Range(0, Farts.Count)];
		}
	}
	public static class TestMode
	{
		private static float _pendingTimer = -1f;

		private static bool _placedCursed;

		private static bool _placedLottery;

		private static bool _placedCustoms;

		public static bool On
		{
			get
			{
				if (Plugin.Enabled)
				{
					return Plugin.CfgTestMode.Value;
				}
				return false;
			}
		}

		public static Vector3 Anchor { get; private set; } = Vector3.zero;

		public static void QueuePlacement()
		{
			if (On && Net.IsAuthority)
			{
				_placedCursed = false;
				_placedLottery = false;
				_placedCustoms = false;
				_pendingTimer = 2f;
			}
		}

		public static void Tick()
		{
			if (!On || !Net.IsAuthority || _pendingTimer < 0f)
			{
				return;
			}
			_pendingTimer -= Time.deltaTime;
			if (!(_pendingTimer > 0f))
			{
				_pendingTimer = 1.2f;
				HostPlaceItems();
				if (_placedCursed && _placedLottery && _placedCustoms)
				{
					_pendingTimer = -1f;
				}
			}
		}

		public static void HostPlaceItems()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0114: 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_0128: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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_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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_017e: 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_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			if (!On || !Net.IsAuthority)
			{
				return;
			}
			Anchor = FindAnchor();
			if (Anchor == Vector3.zero)
			{
				return;
			}
			if (!_placedCursed && Net.State.CursedViewID != -1 && Place(Net.State.CursedViewID, Anchor + Vector3.forward * 1.5f + Vector3.up * 0.2f))
			{
				_placedCursed = true;
			}
			if (!_placedLottery && Net.State.LotteryViewID != -1 && Place(Net.State.LotteryViewID, Anchor + Vector3.left * 1.5f + Vector3.up * 0.2f))
			{
				_placedLottery = true;
			}
			if (!_placedCustoms)
			{
				bool num = SpawnCustomItem("Jumper Cables", Anchor + Vector3.back * 1.2f + Vector3.up * 0.6f);
				bool flag = SpawnCustomItem("Portal Gun", Anchor + Vector3.back * 2f + Vector3.up * 0.6f);
				bool flag2 = SpawnCustomItem("Chaos Power-Up", Anchor + Vector3.back * 2.8f + Vector3.up * 0.6f);
				bool flag3 = SpawnCustomItem("Weenie hiding box", Anchor + Vector3.right * 1.5f + Vector3.up * 0.6f);
				ExtractionPoint val = Object.FindObjectOfType<ExtractionPoint>();
				if ((Object)val != (Object)null)
				{
					SpawnCustomItem("Weenie hiding box", ((Component)val).transform.position + Vector3.right * 2.5f + Vector3.up * 1f);
				}
				if (num && flag && flag2 && flag3)
				{
					_placedCustoms = true;
				}
			}
		}

		public static void HostOnGrab(PhysGrabObject obj)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (On && Net.IsAuthority && !((Object)obj == (Object)null))
			{
				Rigidbody component = ((Component)obj).GetComponent<Rigidbody>();
				if ((Object)component != (Object)null && component.isKinematic)
				{
					component.isKinematic = false;
				}
			}
		}

		private static bool SpawnCustomItem(string itemName, Vector3 position)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			try
			{
				foreach (Item allItem in Items.AllItems)
				{
					if (!((Object)allItem == (Object)null) && !(allItem.itemName != itemName) && (Object)Items.SpawnItem(allItem, position, Quaternion.identity) != (Object)null)
					{
						Plugin.Log.LogInfo((object)("[Test] Dropped \"" + itemName + "\" at spawn."));
						return true;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Test] Spawn \"" + itemName + "\" failed: " + ex.Message));
			}
			return false;
		}

		public static bool Place(int viewID, Vector3 position, bool freeze = true)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0023: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if (viewID == -1)
			{
				return false;
			}
			GameObject val = Net.FindViewObject(viewID);
			if ((Object)val == (Object)null)
			{
				return false;
			}
			val.transform.position = position;
			val.transform.rotation = Quaternion.identity;
			PhysGrabObject component = val.GetComponent<PhysGrabObject>();
			if ((Object)component != (Object)null)
			{
				((Component)component).transform.position = position;
				((Component)component).transform.rotation = Quaternion.identity;
			}
			Rigidbody component2 = val.GetComponent<Rigidbody>();
			if ((Object)component2 != (Object)null)
			{
				component2.position = position;
				component2.rotation = Quaternion.identity;
				component2.velocity = Vector3.zero;
				component2.angularVelocity = Vector3.zero;
				component2.isKinematic = freeze;
			}
			if (viewID == Net.State.ToiletViewID)
			{
				Net.State.ToiletPos = new float[3] { position.x, position.y, position.z };
				Net.MarkDirty();
			}
			return true;
		}

		private static Vector3 FindAnchor()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_005e: 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)
			//IL_00a3: Expected O, but got Unknown
			//IL_008b: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)instance != (Object)null && ((Component)instance).transform.position != Vector3.zero)
			{
				return ((Component)instance).transform.position;
			}
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			foreach (PlayerAvatar val in array)
			{
				if ((Object)val != (Object)null)
				{
					return ((Component)val).transform.position;
				}
			}
			SpawnPoint val2 = Object.FindObjectOfType<SpawnPoint>();
			if ((Object)val2 != (Object)null)
			{
				return ((Component)val2).transform.position;
			}
			LevelGenerator val3 = Object.FindObjectOfType<LevelGenerator>();
			if (!((Object)val3 != (Object)null))
			{
				return Vector3.zero;
			}
			return ((Component)val3).transform.position;
		}

		private static void Chat(string msg)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if ((Object)ChatManager.instance != (Object)null)
			{
				ChatManager.instance.ForceSendMessage(msg);
			}
		}
	}
}
namespace ChaosCarnival.Features
{
	public static class Blackout
	{
		private static readonly Color LootGlow = new Color(0.9f, 0.75f, 0.35f);

		private static float _nextTimer = -1f;

		private static float _endTimer;

		private static float _huntTimer;

		private static bool _roundActive;

		private static bool _applied;

		private static readonly List<Light> _disabledLights = new List<Light>();

		private static readonly List<GameObject> _lootLights = new List<GameObject>();

		private static readonly List<Light> _playerLights = new List<Light>();

		private static float _flickerTimer;

		private static int _flickerState;

		private static float _burstUntil;

		public static bool On
		{
			get
			{
				if (Plugin.Enabled)
				{
					return Plugin.CfgBlackout.Value;
				}
				return false;
			}
		}

		public static void HostRoundSetup()
		{
			if (Net.IsAuthority)
			{
				_roundActive = true;
				_nextTimer = (TestMode.On ? 30f : Random.Range(120f, 180f));
				_endTimer = 0f;
			}
		}

		public static void HostRoundEnd()
		{
			_roundActive = false;
			if (Net.IsAuthority && Net.State.BlackoutActive)
			{
				Net.State.BlackoutActive = false;
				Net.MarkDirty();
			}
		}

		public static void HostTick()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!On || !Net.IsAuthority || !_roundActive)
			{
				return;
			}
			if (Net.State.BlackoutActive)
			{
				_endTimer -= Time.deltaTime;
				_huntTimer -= Time.deltaTime;
				if (_huntTimer <= 0f)
				{
					_huntTimer = 5f;
					PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
					if (array.Length != 0)
					{
						PlayerAvatar val = array[Random.Range(0, array.Length)];
						try
						{
							SemiFunc.EnemyInvestigate(((Component)val).transform.position, 30f, false);
						}
						catch
						{
						}
					}
				}
				if (_endTimer <= 0f)
				{
					Net.State.BlackoutActive = false;
					Net.MarkDirty();
					_nextTimer = Plugin.CfgBlackoutInterval.Value;
				}
			}
			else
			{
				_nextTimer -= Time.deltaTime;
				if (_nextTimer <= 0f)
				{
					_endTimer = Plugin.CfgBlackoutDuration.Value;
					Net.State.BlackoutActive = true;
					Net.MarkDirty();
					Net.Broadcast("⚡ BLACKOUT PROTOCOL — the lights are OUT!", 5f);
				}
			}
		}

		public static void Tick()
		{
			if (!On)
			{
				if (_applied)
				{
					Restore();
				}
				return;
			}
			bool blackoutActive = Net.State.BlackoutActive;
			if (blackoutActive && !_applied)
			{
				Apply();
			}
			else if (!blackoutActive && _applied)
			{
				Restore();
			}
			if (!_applied || _playerLights.Count <= 0)
			{
				return;
			}
			_flickerTimer -= Time.deltaTime;
			if (!(_flickerTimer <= 0f))
			{
				return;
			}
			switch (_flickerState)
			{
			case 0:
				if (Random.value < 0.65f)
				{
					_flickerState = 1;
					_burstUntil = Time.time + Random.Range(0.25f, 1.3f);
				}
				else
				{
					_flickerState = 2;
					_flickerTimer = Random.Range(0.15f, 0.9f);
					SetPlayerLights(on: false);
				}
				break;
			case 1:
				SetPlayerLights(Random.value > 0.45f);
				_flickerTimer = Random.Range(0.03f, 0.16f);
				if (Time.time > _burstUntil)
				{
					_flickerState = 0;
					SetPlayerLights(on: true);
					_flickerTimer = Random.Range(0.8f, 4.5f);
				}
				break;
			case 2:
				_flickerState = 0;
				SetPlayerLights(on: true);
				_flickerTimer = Random.Range(0.8f, 4.5f);
				break;
			}
		}

		private static void SetPlayerLights(bool on)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			foreach (Light playerLight in _playerLights)
			{
				if ((Object)playerLight != (Object)null)
				{
					((Behaviour)playerLight).enabled = on;
				}
			}
		}

		private static void Apply()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			_applied = true;
			_disabledLights.Clear();
			_lootLights.Clear();
			try