Decompiled source of ChaosCarnival v1.0.49

BepInEx\plugins\ChaosCarnival\ChaosCarnival.dll

Decompiled a month 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 System.Security;
using System.Security.Permissions;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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.49.0")]
[assembly: AssemblyInformationalVersion("1.0.49")]
[assembly: AssemblyProduct("ChaosCarnival")]
[assembly: AssemblyTitle("ChaosCarnival")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.49.0")]
[module: UnverifiableCode]
[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 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 int DoppelgangerViewID = -1;

		public string StolenIdentityName = "";

		public int DoppelgangerTargetViewID = -1;

		public int DoppelgangerPhase;

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

		public int CursedViewID2 = -1;

		public int CurseType2;

		public int CursedHolderViewID2 = -1;

		public object[] Pack()
		{
			return new object[32]
			{
				CursedViewID, CursedHolderViewID, GoblinViewIDs, KlutzName, LotteryViewID, LotteryValue, ToiletViewID, MeltdownViewID, MeltdownValue, MeltdownLocked,
				CurseType, InfectedViewIDs, TallyNames, TallyDamage, ToiletPos, BlackoutActive, PortalExit, PortalEntry, PowerUpViewID, PowerUpPhase,
				TokenViewID, PossessedPlayerViewID, RouletteOutbreak, PortalData, DoppelgangerViewID, StolenIdentityName, DoppelgangerTargetViewID, DoppelgangerPhase, WeenieBoxViewIDs, CursedViewID2,
				CurseType2, CursedHolderViewID2
			};
		}

		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),
				PortalExit = ToFloatArray(16),
				PortalEntry = ToFloatArray(17),
				PowerUpViewID = ToInt(18),
				PowerUpPhase = ToInt(19, 0),
				TokenViewID = ToInt(20),
				PossessedPlayerViewID = ToInt(21),
				RouletteOutbreak = ToInt(22, 0),
				PortalData = ToFloatArray(23),
				DoppelgangerViewID = ToInt(24),
				StolenIdentityName = ToString(25),
				DoppelgangerTargetViewID = ToInt(26),
				DoppelgangerPhase = ToInt(27, 0),
				WeenieBoxViewIDs = ToIntArray(28),
				CursedViewID2 = ToInt(29),
				CurseType2 = ToInt(30, 0),
				CursedHolderViewID2 = ToInt(31)
			};
			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_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0053: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00fd: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			if ((Object)PlayerAvatar.instance != (Object)null && (Object)obj == (Object)((Component)PlayerAvatar.instance).gameObject)
			{
				return;
			}
			try
			{
				GameObject val = new GameObject("ChaosCarnival.Aura");
				val.transform.SetParent(obj.transform, false);
				val.transform.localPosition = Vector3.up * 0.1f;
				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);
			}
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), field);
				if (fieldInfo != null)
				{
					object value = fieldInfo.GetValue(obj);
					if (value is T)
					{
						return (T)value;
					}
				}
			}
			catch
			{
			}
			return default(T);
		}

		public static T GetPropertyOrField<T>(object obj, string name)
		{
			if (obj == null)
			{
				return default(T);
			}
			try
			{
				Type type = obj.GetType();
				FieldInfo fieldInfo = AccessTools.Field(type, name);
				if (fieldInfo != null && fieldInfo.GetValue(obj) is T result)
				{
					return result;
				}
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && property.CanRead && property.GetValue(obj, null) is T result2)
				{
					return result2;
				}
			}
			catch
			{
			}
			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 GUIStyle _timer;

		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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Enabled)
			{
				return;
			}
			DrawBanner();
			DrawPossessionTimer();
			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 void DrawPossessionTimer()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			if (Net.State.PossessedPlayerViewID == -1)
			{
				return;
			}
			EnsureStyles();
			float num = Time.time - Curses.PossessionStartTime;
			if (!(Curses.PossessionStartTime <= 0f) && !(num < 0f))
			{
				float num2 = Mathf.Max(0f, 300f - num);
				int num3 = Mathf.FloorToInt(num2 / 60f);
				string text = string.Format(arg1: Mathf.FloorToInt(num2 % 60f), format: "⏰ POSSESSION  {0}:{1:D2}", arg0: num3);
				bool num4 = num2 < 60f;
				Color color = GUI.color;
				if (num4)
				{
					float num5 = 0.6f + 0.4f * Mathf.Sin(Time.time * 4f);
					GUI.color = new Color(1f, num5 * 0.3f, 0.2f, 0.95f);
				}
				else
				{
					GUI.color = new Color(1f, 1f, 1f, 0.9f);
				}
				Rect val = new Rect((float)Screen.width * 0.5f - 160f, (float)Screen.height * 0.06f, 320f, 38f);
				GUI.DrawTexture(val, (Texture)_bg, (ScaleMode)0);
				GUI.Label(val, text, _timer);
				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
			//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_0130: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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;
				GUIStyle val5 = new GUIStyle
				{
					fontSize = 20,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				val5.normal.textColor = new Color(1f, 0.6f, 0.2f);
				_timer = val5;
			}
		}
	}
	public static class Net
	{
		private const byte EventCode = 180;

		private const int Magic = 1128481585;

		private const byte MsgState = 1;

		private const byte MsgPoof = 2;

		private const byte MsgPing = 3;

		private const byte MsgText = 4;

		private const byte MsgVibeCheck = 5;

		private const byte MsgVibeAck = 6;

		private static bool _subscribed;

		private static bool _dirty;

		private static float _heartbeat;

		private const float HeartbeatSeconds = 2f;

		private static bool _loggedFirstReceive;

		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()
		{
		}

		public static void EnsureReady()
		{
			if (!_subscribed && PhotonNetwork.NetworkingClient != null && PhotonNetwork.InRoom)
			{
				PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;
				_subscribed = true;
				Plugin.Log.LogInfo((object)$"[Net] Subscribed to Photon events on fixed code {(byte)180}.");
			}
		}

		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()
		{
			if (IsAuthority)
			{
				_heartbeat -= Time.deltaTime;
				if (_dirty || _heartbeat <= 0f)
				{
					_dirty = false;
					_heartbeat = 2f;
					Raise(1, State.Pack());
				}
			}
		}

		public static void SendPoof(Vector3[] positions)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (IsAuthority && positions != null && positions.Length != 0)
			{
				object[] array = new object[positions.Length];
				for (int i = 0; i < positions.Length; i++)
				{
					array[i] = positions[i];
				}
				Raise(2, array);
			}
		}

		public static void SendPing(int type, Vector3 position)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (IsAuthority)
			{
				Raise(3, new object[2] { type, position });
			}
		}

		public static void Broadcast(string text, float seconds = 4f)
		{
			if (IsAuthority && !string.IsNullOrEmpty(text))
			{
				Raise(4, new object[2] { text, seconds });
			}
		}

		private static void Raise(byte msgType, object payload)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object[] array = new object[3] { 1128481585, msgType, payload };
				if (SemiFunc.IsMultiplayer())
				{
					EnsureReady();
					if (PhotonNetwork.InRoom)
					{
						PhotonNetwork.RaiseEvent((byte)180, (object)array, ToAll, SendOptions.SendReliable);
					}
				}
				else
				{
					Dispatch(msgType, payload);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)$"[Net] Raise({msgType}) failed: {ex.Message}");
			}
		}

		private static void OnPhotonEvent(EventData e)
		{
			if (e.Code != 180)
			{
				return;
			}
			try
			{
				if (e.CustomData is object[] array && array.Length >= 3 && Convert.ToInt32(array[0]) == 1128481585)
				{
					byte msgType = Convert.ToByte(array[1]);
					if (!_loggedFirstReceive && !IsAuthority)
					{
						_loggedFirstReceive = true;
						Plugin.Log.LogInfo((object)"[Net] First host event received — client sync is live.");
					}
					Dispatch(msgType, array[2]);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] Bad event payload: " + ex.Message));
			}
		}

		private static void Dispatch(byte msgType, object payload)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			switch (msgType)
			{
			case 1:
				State = CarnivalState.Unpack((object[])payload);
				Net.OnStateChanged?.Invoke();
				break;
			case 2:
			{
				object[] array2 = (object[])payload;
				Vector3[] array3 = (Vector3[])(object)new Vector3[array2.Length];
				for (int i = 0; i < array2.Length; i++)
				{
					array3[i] = (Vector3)array2[i];
				}
				Net.OnPoof?.Invoke(array3);
				break;
			}
			case 3:
			{
				object[] array4 = (object[])payload;
				Net.OnPing?.Invoke(Convert.ToInt32(array4[0]), (Vector3)array4[1]);
				break;
			}
			case 4:
			{
				object[] array = (object[])payload;
				Net.OnBroadcast?.Invoke((string)array[0], Convert.ToSingle(array[1]));
				break;
			}
			case 5:
				HandleVibeCheck(payload);
				break;
			case 6:
				HandleVibeAck(payload);
				break;
			}
		}

		public static void TriggerVibeCheck()
		{
			Plugin.Log.LogInfo((object)"[Net] Triggering Lobby Vibe Check...");
			Broadcast("[VIBE CHECK] Initiating network sync check across lobby...");
			Raise(5, new object[1] { DateTime.UtcNow.Ticks });
		}

		private static void HandleVibeCheck(object payload)
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = ((PhotonNetwork.LocalPlayer != null && !string.IsNullOrEmpty(PhotonNetwork.NickName)) ? PhotonNetwork.NickName : "LocalPlayer");
				string text2 = "1.0.49";
				string text3 = (string.IsNullOrEmpty(State.KlutzName) ? "None" : State.KlutzName);
				int num = ((State.PortalData != null) ? (State.PortalData.Length / 7) : 0);
				bool flag = true;
				object prefabPool = PhotonNetwork.PrefabPool;
				if (prefabPool != null)
				{
					FieldInfo field = prefabPool.GetType().GetField("ResourceCache", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.GetValue(prefabPool) is IDictionary dictionary)
					{
						string[] array = new string[4] { "Items/Item Jumper Cables", "Items/Item Portal Gun", "Items/Item Chaos Power-Up", "Items/Item Weenie Box" };
						foreach (string key in array)
						{
							if (!dictionary.Contains(key))
							{
								flag = false;
								break;
							}
						}
					}
				}
				PlayerAvatar instance = PlayerAvatar.instance;
				if ((Object)instance != (Object)null)
				{
					SendPoof((Vector3[])(object)new Vector3[1] { ((Component)instance).transform.position + Vector3.up * 0.2f });
					AudioClip val = SoundBank.RandomFart();
					if ((Object)val != (Object)null)
					{
						AudioSource.PlayClipAtPoint(val, ((Component)instance).transform.position, 1f);
					}
				}
				object[] payload2 = new object[5] { text, text2, text3, num, flag };
				Raise(6, payload2);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] HandleVibeCheck error: " + ex.Message));
			}
		}

		private static void HandleVibeAck(object payload)
		{
			try
			{
				object[] obj = (object[])payload;
				string text = Convert.ToString(obj[0]);
				string text2 = Convert.ToString(obj[1]);
				string text3 = Convert.ToString(obj[2]);
				int num = Convert.ToInt32(obj[3]);
				bool flag = Convert.ToBoolean(obj[4]);
				string text4 = string.Format("\ud83d\udc9a [VIBE CHECK PASS] {0} (v{1}) | Klutz: {2} | Portals: {3} | Prefabs: {4}", text, text2, text3, num, flag ? "OK" : "MISSING");
				Plugin.Log.LogInfo((object)("[VibeCheck] " + text4));
				Broadcast(text4, 6f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("[Net] HandleVibeAck error: " + ex.Message));
			}
		}

		public static PlayerAvatar FindAvatar(int avatarViewID)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			if (avatarViewID <= 0)
			{
				return null;
			}
			PhotonView val = PhotonView.Find(avatarViewID);
			if ((Object)val != (Object)null)
			{
				PlayerAvatar val2 = ((Component)val).GetComponent<PlayerAvatar>() ?? ((Component)val).GetComponentInChildren<PlayerAvatar>(true) ?? ((Component)val).GetComponentInParent<PlayerAvatar>();
				if ((Object)val2 != (Object)null)
				{
					return val2;
				}
			}
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			foreach (PlayerAvatar val3 in array)
			{
				if ((Object)val3 != (Object)null)
				{
					PhotonView val4 = val3.photonView ?? ((Component)val3).GetComponent<PhotonView>() ?? ((Component)val3).GetComponentInParent<PhotonView>() ?? ((Component)val3).GetComponentInChildren<PhotonView>(true);
					if ((Object)val4 != (Object)null && val4.ViewID == avatarViewID)
					{
						return val3;
					}
				}
			}
			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);
				Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule") ?? Type.GetType("UnityEngine.ImageConversion, UnityEngine");
				if (type != null)
				{
					MethodInfo method = type.GetMethod("LoadImage", new Type[2]
					{
						typeof(Texture2D),
						typeof(byte[])
					});
					if (method != null && (bool)method.Invoke(null, new object[2] { val, array }))
					{
						return val;
					}
				}
				MethodInfo method2 = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
				if (method2 != null && (bool)method2.Invoke(val, new object[1] { 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");

		private static readonly FieldInfo TotalMaxValueField = AccessTools.Field(typeof(ValuableDirector), "totalMaxValue");

		private static float _doubledLevelTotalMax = -1f;

		[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();
					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(ValuableDirector), "SetupHost")]
		[HarmonyPostfix]
		public static void OnValuableDirectorSetupHost(ValuableDirector __instance)
		{
			try
			{
				if (Plugin.Enabled)
				{
					float field = Fx.GetField<float>(__instance, "totalMaxValue");
					if (field > 0f && field < 999999f)
					{
						_doubledLevelTotalMax = field * 2f;
						Fx.SetField(__instance, "totalMaxValue", _doubledLevelTotalMax);
						Plugin.Log.LogInfo((object)$"[Loot Cap] Doubled level loot cap to ${_doubledLevelTotalMax:F0} (original cap: ${field:F0}).");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[Loot Cap] SetupHost patch error: " + ex.Message));
			}
		}

		[HarmonyPatch(typeof(ValuableDirector), "SpawnValuable")]
		[HarmonyPrefix]
		public static void OnSpawnValuable(ValuableDirector __instance)
		{
			try
			{
				if (Plugin.Enabled && _doubledLevelTotalMax > 0f)
				{
					Fx.SetField(__instance, "totalMaxValue", _doubledLevelTotalMax);
				}
			}
			catch
			{
			}
		}

		[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 bool 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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)
					{
						return true;
					}
				}
				if (!Plugin.Enabled || !Net.IsAuthority || valueLost <= 0f)
				{
					return true;
				}
				string text = null;
				if ((Object)___physGrabObject != (Object)null)
				{
					if (___physGrabObject.playerGrabbing != null && ___physGrabObject.playerGrabbing.Count > 0)
					{
						foreach (PhysGrabber item in ___physGrabObject.playerGrabbing)
						{
							if ((Object)item != (Object)null && (Object)item.playerAvatar != (Object)null)
							{
								string field = Fx.GetField<string>(item.playerAvatar, "playerName");
								if (!string.IsNullOrEmpty(field))
								{
									text = field;
									break;
								}
							}
						}
					}
					if (string.IsNullOrEmpty(text) && LastPlayerGrabbing != null)
					{
						object value = LastPlayerGrabbing.GetValue(___physGrabObject);
						PlayerAvatar val = (PlayerAvatar)((value is PlayerAvatar) ? value : null);
						if ((Object)val != (Object)null)
						{
							text = Fx.GetField<string>(val, "playerName");
						}
					}
				}
				if (string.IsNullOrEmpty(text))
				{
					return true;
				}
				Klutz.HostRecordBreak(text, valueLost);
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnItemBreak: {arg}");
				return true;
			}
		}

		[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(ItemAttributes), "Awake")]
		[HarmonyPostfix]
		public static void OnItemAttributesAwake(ItemAttributes __instance)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			try
			{
				if (Plugin.Enabled && (Object)__instance != (Object)null && (Object)((Component)__instance).gameObject != (Object)null)
				{
					string name = ((Object)((Component)__instance).gameObject).name;
					if ((name.Contains("Item Portal Gun") || name.Contains("Item Jumper Cables") || name.Contains("Item Chaos Power-Up") || name.Contains("Item Weenie Box")) && !((Component)__instance).gameObject.activeSelf)
					{
						((Component)__instance).gameObject.SetActive(true);
						Plugin.Log.LogInfo((object)("[CustomItems] Activated purchased shop item: " + name));
					}
				}
			}
			catch
			{
			}
		}

		[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(LightManager), "HandleLightActivation")]
		[HarmonyPrefix]
		public static bool OnHandleLightActivationPrefix(PropLight propLight, LightManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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
			try
			{
				if ((Object)propLight == (Object)null || (Object)__instance == (Object)null || (Object)__instance.lightCullTarget == (Object)null)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(LightManager), "Setup")]
		[HarmonyPrefix]
		public static void OnLightManagerSetupPrefix(LightManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			try
			{
				if ((Object)__instance != (Object)null)
				{
					Fx.GetField<List<PropLight>>(__instance, "propLights")?.RemoveAll((PropLight l) => (Object)l == (Object)null);
					Fx.GetField<List<PropLightEmission>>(__instance, "propEmissions")?.RemoveAll((PropLightEmission e) => (Object)e == (Object)null);
					if ((Object)__instance.lightCullTarget == (Object)null && (Object)Camera.main != (Object)null)
					{
						__instance.lightCullTarget = ((Component)Camera.main).transform;
					}
				}
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInHaulList")]
		[HarmonyPrefix]
		public static void OnExtractionItemSucked()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			try
			{
				List<GameObject> list = (((Object)RoundDirector.instance != (Object)null) ? Fx.GetField<List<GameObject>>(RoundDirector.instance, "dollarHaulList") : null);
				if (list == null || list.Count <= 0)
				{
					return;
				}
				GameObject val = list[0];
				if (!((Object)val != (Object)null))
				{
					return;
				}
				PhotonView component = val.GetComponent<PhotonView>();
				if (!((Object)component != (Object)null))
				{
					return;
				}
				int viewID = component.ViewID;
				if (Net.State.PossessedPlayerViewID != -1 && Net.State.CursedViewID != -1 && viewID == Net.State.CursedViewID)
				{
					Curses.RestorePossession();
					if (Net.IsAuthority)
					{
						Curses.HostClearPossession();
						int field = Fx.GetField<int>(RoundDirector.instance, "currentHaul");
						Fx.SetField(RoundDirector.instance, "currentHaul", field + 30000);
						Net.Broadcast("[POSSESSION] EXTRACTED A TEAMMATE?! Secret bonus: +$30,000!", 8f);
					}
				}
				if (Net.IsAuthority && Net.State.TokenViewID != -1 && viewID == Net.State.TokenViewID)
				{
					Roulette.HostOnTokenExtracted();
				}
				if (Net.IsAuthority && Net.State.LotteryViewID != -1 && viewID == Net.State.LotteryViewID)
				{
					Lottery.HostOnExtractionCashout();
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OnExtractionItemSucked: {arg}");
			}
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInHaulList")]
		[HarmonyPrefix]
		public static void OnExtractionCashout()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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();
								int field = Fx.GetField<int>(RoundDirector.instance, "currentHaul");
								Fx.SetField(RoundDirector.instance, "currentHaul", field + 30000);
								Net.Broadcast("[POSSESSION] EXTRACTED A TEAMMATE?! Secret bonus: +$30,000!", 8f);
							}
						}
					}
				}
				Roulette.ForceResolvePendingSpin();
				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(MultiplayerPool), "Instantiate")]
		[HarmonyPrefix]
		public static bool OnMultiplayerPoolInstantiate(MultiplayerPool __instance, string prefabId, Vector3 position, Quaternion rotation)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			try
			{
				if (string.IsNullOrEmpty(prefabId))
				{
					return true;
				}
				if (__instance.ResourceCache != null && __instance.ResourceCache.ContainsKey(prefabId))
				{
					return true;
				}
				if (NetworkPrefabs.Prefabs != null && NetworkPrefabs.Prefabs.TryGetValue(prefabId, out var value) && (Object)value != (Object)null)
				{
					if (__instance.ResourceCache != null)
					{
						__instance.ResourceCache[prefabId] = value;
						Plugin.Log.LogInfo((object)("[MultiplayerPool] Cached REPOLib custom network prefab: \"" + prefabId + "\""));
					}
					return true;
				}
				string text = (prefabId.StartsWith("Items/") ? prefabId.Substring(6) : ("Items/" + prefabId));
				if (NetworkPrefabs.Prefabs != null && NetworkPrefabs.Prefabs.TryGetValue(text, out var value2) && (Object)value2 != (Object)null)
				{
					if (__instance.ResourceCache != null)
					{
						__instance.ResourceCache[prefabId] = value2;
						__instance.ResourceCache[text] = value2;
						Plugin.Log.LogInfo((object)("[MultiplayerPool] Cached REPOLib custom network prefab: \"" + text + "\" (mapped from \"" + prefabId + "\")"));
					}
					return true;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[MultiplayerPool] Prefix error for \"" + prefabId + "\": " + ex.Message));
			}
			return true;
		}

		[HarmonyPatch(typeof(SteamManager), "SendSteamAuthTicket")]
		[HarmonyPostfix]
		public static void OnSendSteamAuthTicket()
		{
			EnsureClient2UserId();
		}

		[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
		[HarmonyPrefix]
		public static void OnTryJoiningRoom()
		{
			EnsureClient2UserId();
		}

		public static void EnsureClient2UserId()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			try
			{
				if (!Plugin.Enabled)
				{
					return;
				}
				string[] commandLineArgs = Environment.GetCommandLineArgs();
				bool flag = false;
				string[] array = commandLineArgs;
				foreach (string text in array)
				{
					if (text.Equals("--alt-user", StringComparison.OrdinalIgnoreCase) || text.Equals("--client2", StringComparison.OrdinalIgnoreCase) || text.Equals("-client2", StringComparison.OrdinalIgnoreCase))
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					Process currentProcess = Process.GetCurrentProcess();
					Process[] processesByName = Process.GetProcessesByName("REPO");
					if (processesByName.Length > 1)
					{
						Process process = currentProcess;
						Process[] array2 = processesByName;
						foreach (Process process2 in array2)
						{
							try
							{
								if (process2.StartTime < process.StartTime)
								{
									process = process2;
								}
							}
							catch
							{
							}
						}
						if (process.Id != currentProcess.Id)
						{
							flag = true;
						}
					}
				}
				if (flag)
				{
					if (PhotonNetwork.AuthValues == null)
					{
						PhotonNetwork.AuthValues = new AuthenticationValues();
					}
					string text2 = PhotonNetwork.AuthValues.UserId;
					if (string.IsNullOrEmpty(text2))
					{
						text2 = "Client2_" + Guid.NewGuid().ToString().Substring(0, 8);
					}
					if (!text2.EndsWith("_2"))
					{
						PhotonNetwork.AuthValues.UserId = text2 + "_2";
						Plugin.Log.LogInfo((object)("[MultiInstance] Secondary client detected! Adjusted Photon UserId to \"" + PhotonNetwork.AuthValues.UserId + "\". Dual-client multiplayer enabled!"));
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[MultiInstance] Error in EnsureClient2UserId: " + ex.Message));
			}
		}
	}
	[BepInPlugin("com.chaoscarnival.repo", "ChaosCarnival", "1.0.49")]
	[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> 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> CfgUncapLoot;

		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> 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Expected O, but got Unknown
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Expected O, but got Unknown
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Expected O, but got Unknown
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Expected O, but got Unknown
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Expected O, but got Unknown
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Expected O, but got Unknown
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: 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_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: 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.");
			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>()));
			CfgUncapLoot = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "RemoveValueCap", false, "Remove R.E.P.O.'s per-level loot value budget. Vanilla stops spawning valuables once their combined value hits the level cap, so one big item can leave a level with only 1-2 valuables. With this on, levels fill their loot spots normally and ChaosCarnival's curse/lottery/contraband bonuses are pure extra reward. NOTE: default OFF while we confirm it doesn't affect multiplayer level loading — turn on once verified.");
			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>()));
			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.36", 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;
		}

		public static bool IsMainMenu()
		{
			//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_0025: Expected O, but got Unknown
			RunManager instance = RunManager.instance;
			if ((Object)instance == (Object)null || (Object)instance.levelCurrent == (Object)null)
			{
				return true;
			}
			string text = (((Object)instance.levelCurrent).name ?? "").ToLowerInvariant();
			if (!text.Contains("menu"))
			{
				return text.Contains("title");
			}
			return true;
		}

		public static bool IsInPlayableLevel()
		{
			if (IsMainMenu())
			{
				return false;
			}
			return true;
		}

		private void Update()
		{
			if (!Enabled)
			{
				return;
			}
			try
			{
				CustomItems.TryRegister();
			}
			catch
			{
			}
			try
			{
				Net.EnsureReady();
			}
			catch
			{
			}
			if (!IsInPlayableLevel())
			{
				return;
			}
			try
			{
				Net.Tick();
				Curses.Tick();
				Curses.HostTick();
				Klutz.Tick();
				Lottery.Tick();
				Lottery.HostTick();
				WeenieBox.Tick();
				Meltdown.Tick();
				Meltdown.HostTick();
				Blackout.Tick();
				Blackout.HostTick();
				Roulette.Tick();
				Roulette.HostTick();
				Portals.Tick();
				Portals.HostTick();
				PowerUp.Tick();
				PowerUp.HostTick();
				TestMode.Tick();
				if (Input.GetKeyDown((KeyCode)289))
				{
					Net.TriggerVibeCheck();
				}
			}
			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.28";
	}
	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 <