Decompiled source of PoisonMysteryPizza v1.0.1

BepInEx/plugins/PoisonMysteryPizza/PoisonMysteryPizza.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PoisonMysteryPizza")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("PoisonMysteryPizza")]
[assembly: AssemblyTitle("PoisonMysteryPizza")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PoisonMysteryPizza
{
	internal static class Blood
	{
		private const int MaxDecals = 400;

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

		public static int Count => Spawned.Count;

		public static void Splatter(Vector3 centre, int seed)
		{
			//IL_0010: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_014c: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PizzaManager.PlayAt(centre, instance.bloodGoreSFX, 1f);
			int value = PizzaConfig.BloodDecals.Value;
			GameObject playerBloodPrefab = instance.playerBloodPrefab;
			if (value <= 0 || (Object)(object)playerBloodPrefab == (Object)null)
			{
				return;
			}
			Random random = new Random(seed);
			float value2 = PizzaConfig.BloodRadius.Value;
			float value3 = PizzaConfig.BloodSize.Value;
			int collidersAndRoomMaskAndDefault = instance.collidersAndRoomMaskAndDefault;
			PlayerControllerB localPlayerController = instance.localPlayerController;
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < value; i++)
			{
				double num = random.NextDouble() * Math.PI * 2.0;
				float num2 = ((i == 0) ? 0f : (value2 * (float)Math.Pow(random.NextDouble(), 1.4)));
				if (!Physics.Raycast(centre + new Vector3((float)Math.Cos(num) * num2, 0.6f, (float)Math.Sin(num) * num2), Vector3.down, ref val, 4f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					continue;
				}
				try
				{
					GameObject val2 = (((Object)(object)instance.bloodObjectsContainer != (Object)null) ? Object.Instantiate<GameObject>(playerBloodPrefab, instance.bloodObjectsContainer) : Object.Instantiate<GameObject>(playerBloodPrefab));
					Transform transform = val2.transform;
					float num3 = (float)(random.NextDouble() * 360.0);
					transform.rotation = Quaternion.LookRotation(Vector3.down, Quaternion.Euler(0f, num3, 0f) * Vector3.forward);
					transform.position = ((RaycastHit)(ref val)).point + Vector3.up * 0.45f;
					if ((Object)(object)localPlayerController != (Object)null)
					{
						localPlayerController.RandomizeBloodRotationAndScale(transform);
					}
					float num4 = value3 * ((i == 0) ? 1.8f : (0.7f + (float)random.NextDouble() * 0.8f));
					Vector3 localScale = transform.localScale;
					transform.localScale = new Vector3(localScale.x * num4, localScale.y * num4, localScale.z);
					val2.SetActive(true);
					Spawned.Add(val2);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not place blood: " + ex.Message));
					break;
				}
			}
			while (Spawned.Count > 400)
			{
				if ((Object)(object)Spawned[0] != (Object)null)
				{
					Object.Destroy((Object)(object)Spawned[0]);
				}
				Spawned.RemoveAt(0);
			}
		}

		public static void Clear()
		{
			for (int i = 0; i < Spawned.Count; i++)
			{
				if ((Object)(object)Spawned[i] != (Object)null)
				{
					Object.Destroy((Object)(object)Spawned[i]);
				}
			}
			Spawned.Clear();
		}

		public static void Forget()
		{
			Spawned.Clear();
		}
	}
	internal static class HudMessage
	{
		private const float FadeSeconds = 0.35f;

		private static GameObject _go;

		private static Component _text;

		private static PropertyInfo _textProp;

		private static PropertyInfo _alphaProp;

		private static bool _useFallback;

		private static string _current = "";

		private static float _until;

		private static GUIStyle _style;

		private static GUIStyle _shadow;

		public static void Show(string message, float seconds)
		{
			_current = message ?? "";
			_until = Time.realtimeSinceStartup + Mathf.Max(0.5f, seconds);
			if (_useFallback)
			{
				return;
			}
			try
			{
				Ensure();
				_textProp.SetValue(_text, _current, null);
				SetAlpha(1f);
				_go.transform.SetAsLastSibling();
				_go.SetActive(true);
			}
			catch (Exception ex)
			{
				_useFallback = true;
				if ((Object)(object)_go != (Object)null)
				{
					Object.Destroy((Object)(object)_go);
				}
				_go = null;
				Plugin.Log.LogWarning((object)("HUD text unavailable, using plain text instead: " + ex.Message));
			}
		}

		public static void Tick()
		{
			if (!((Object)(object)_go == (Object)null) && _go.activeSelf)
			{
				float num = _until - Time.realtimeSinceStartup;
				if (num <= 0f)
				{
					_go.SetActive(false);
				}
				else if (num < 0.35f)
				{
					SetAlpha(num / 0.35f);
				}
			}
		}

		private static void SetAlpha(float a)
		{
			try
			{
				if (_alphaProp != null && (Object)(object)_text != (Object)null)
				{
					_alphaProp.SetValue(_text, Mathf.Clamp01(a), null);
				}
			}
			catch
			{
			}
		}

		private static void Ensure()
		{
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_go != (Object)null && (Object)(object)_text != (Object)null)
			{
				return;
			}
			HUDManager instance = HUDManager.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.HUDContainer == (Object)null)
			{
				throw new InvalidOperationException("HUD not ready");
			}
			FieldInfo field = typeof(HUDManager).GetField("controlTipLines", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			Array array = ((field != null) ? (field.GetValue(instance) as Array) : null);
			if (array == null || array.Length == 0)
			{
				throw new InvalidOperationException("no HUD text to copy");
			}
			object? value = array.GetValue(0);
			Component val = (Component)((value is Component) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("HUD text is missing");
			}
			Transform val2 = (((Object)(object)instance.HUDContainer.transform.parent != (Object)null) ? instance.HUDContainer.transform.parent : instance.HUDContainer.transform);
			_go = Object.Instantiate<GameObject>(val.gameObject, val2, false);
			((Object)_go).name = "PoisonMysteryPizzaMessage";
			_text = _go.GetComponent(((object)val).GetType());
			if ((Object)(object)_text == (Object)null)
			{
				throw new InvalidOperationException("copied HUD text has no text component");
			}
			Component text = _text;
			Behaviour val3 = (Behaviour)(object)((text is Behaviour) ? text : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.enabled = true;
			}
			Type type = ((object)_text).GetType();
			_textProp = type.GetProperty("text");
			_alphaProp = type.GetProperty("alpha");
			if (_textProp == null)
			{
				throw new InvalidOperationException("text property not found");
			}
			float num = 16f;
			PropertyInfo property = type.GetProperty("fontSize");
			try
			{
				if (property != null)
				{
					num = (float)property.GetValue(val, null);
				}
			}
			catch
			{
			}
			TrySet(type, "enableAutoSizing", false);
			TrySet(type, "fontSize", Mathf.Clamp(num * 1.5f, 14f, 40f));
			TrySet(type, "enableWordWrapping", true);
			TrySet(type, "richText", false);
			TrySet(type, "raycastTarget", false);
			TrySet(type, "color", (object)new Color(1f, 0.93f, 0.35f, 1f));
			TrySetEnum(type, "alignment", "Center");
			TrySetEnum(type, "overflowMode", "Overflow");
			RectTransform component = _go.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(0.5f, 0.5f);
				component.anchorMax = val4;
				component.anchorMin = val4;
				component.pivot = new Vector2(0.5f, 0.5f);
				component.sizeDelta = new Vector2(520f, 90f);
				component.anchoredPosition3D = new Vector3(0f, 70f, 0f);
				((Transform)component).localRotation = Quaternion.identity;
				((Transform)component).localScale = Vector3.one;
			}
		}

		private static void TrySet(Type t, string name, object value)
		{
			try
			{
				PropertyInfo property = t.GetProperty(name);
				if (property != null && property.CanWrite)
				{
					property.SetValue(_text, value, null);
				}
			}
			catch
			{
			}
		}

		private static void TrySetEnum(Type t, string name, string value)
		{
			try
			{
				PropertyInfo property = t.GetProperty(name);
				if (property != null && property.CanWrite && property.PropertyType.IsEnum)
				{
					property.SetValue(_text, Enum.Parse(property.PropertyType, value), null);
				}
			}
			catch
			{
			}
		}

		public static void OnGUI()
		{
			//IL_00b7: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			if (!_useFallback || string.IsNullOrEmpty(_current))
			{
				return;
			}
			float num = _until - Time.realtimeSinceStartup;
			if (!(num <= 0f))
			{
				if (_style == null)
				{
					_style = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontStyle = (FontStyle)1,
						wordWrap = true
					};
					_shadow = new GUIStyle(_style);
				}
				GUIStyle style = _style;
				int fontSize = (_shadow.fontSize = Mathf.Max(16, Screen.height / 30));
				style.fontSize = fontSize;
				float num3 = Mathf.Clamp01(num / 0.35f);
				_style.normal.textColor = new Color(1f, 0.93f, 0.35f, num3);
				_shadow.normal.textColor = new Color(0f, 0f, 0f, num3);
				float num4 = (float)Screen.width * 0.7f;
				float num5 = (float)Screen.height * 0.12f;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((float)Screen.width - num4) * 0.5f, (float)Screen.height * 0.36f, num4, num5);
				GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _current, _shadow);
				GUI.Label(val, _current, _style);
			}
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void StartOfRoundAwake(StartOfRound __instance)
		{
			PizzaAssets.LateSetup(__instance);
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void BeforeSpawnScrap(RoundManager __instance)
		{
			try
			{
				PizzaAssets.ApplyValueRange(__instance.scrapValueMultiplier);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not set the pizza value range: " + ex.Message));
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPostfix]
		private static void ItemStarted(GrabbableObject __instance)
		{
			if ((Object)(object)__instance.itemProperties != (Object)(object)PizzaAssets.ItemDef || (Object)(object)PizzaManager.Instance == (Object)null)
			{
				return;
			}
			try
			{
				PizzaManager.Instance.RegisterPizza(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not register a pizza: " + ex.Message));
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
		[HarmonyPostfix]
		private static void ItemUsed(GrabbableObject __instance, bool buttonDown)
		{
			if (!buttonDown || (Object)(object)__instance.itemProperties != (Object)(object)PizzaAssets.ItemDef || (Object)(object)PizzaManager.Instance == (Object)null)
			{
				return;
			}
			try
			{
				PizzaManager.Instance.RequestEat(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Eating the pizza failed: " + ex));
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "LateUpdate")]
		[HarmonyPostfix]
		private static void ItemLateUpdate(GrabbableObject __instance)
		{
			//IL_0071: 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_0087: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			if (!PizzaManager.AnyShrunk)
			{
				return;
			}
			PlayerControllerB playerHeldBy = __instance.playerHeldBy;
			if (!((Object)(object)playerHeldBy == (Object)null) && !((Object)(object)__instance.parentObject == (Object)null) && !((Object)(object)__instance.itemProperties == (Object)null) && !((Object)(object)PizzaManager.Instance == (Object)null) && PizzaManager.Instance.IsScaledItem(__instance))
			{
				float num = PizzaManager.Instance.ScaleOf(playerHeldBy);
				if (!(num > 0.999f))
				{
					((Component)__instance).transform.position = __instance.parentObject.position + __instance.parentObject.rotation * (__instance.itemProperties.positionOffset * num);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void PlayerUpdated(PlayerControllerB __instance)
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)__instance != (Object)(object)instance.localPlayerController) && !((Object)(object)PizzaManager.Instance == (Object)null))
			{
				PizzaManager.Instance.LocalPlayerUpdated(__instance);
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
		[HarmonyPrefix]
		private static void BeforeJump(PlayerControllerB __instance, out bool __state)
		{
			__state = __instance.isJumping;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
		[HarmonyPostfix]
		private static void AfterJump(PlayerControllerB __instance, bool __state)
		{
			if (__state || __instance.isJumping)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)__instance != (Object)(object)instance.localPlayerController || (Object)(object)PizzaManager.Instance == (Object)null)
			{
				return;
			}
			try
			{
				PizzaManager.Instance.TryAirJump(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Double jump failed: " + ex.Message));
			}
		}
	}
	internal static class PizzaAssets
	{
		public const string ItemName = "Poison mystery pizza";

		public static Item ItemDef;

		public static GameObject Prefab;

		public static AudioClip Chimp;

		public static AudioClip TinyScream;

		public static AudioClip Regrow;

		public static AudioClip YeahBaby;

		public static AudioClip Barf;

		private static Mesh _mesh;

		private static Texture2D _texture;

		private static Material _material;

		private static bool _lateSetupDone;

		public static void Build(string pluginDllPath)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			_mesh = BuildMesh();
			_texture = LoadTexture("pizza.png", mipmaps: true);
			Prefab = NetworkPrefabs.CreateNetworkPrefab("PoisonMysteryPizzaItem");
			Prefab.layer = 6;
			Prefab.tag = "PhysicsProp";
			Prefab.AddComponent<MeshFilter>().sharedMesh = _mesh;
			MeshRenderer mainObjectRenderer = Prefab.AddComponent<MeshRenderer>();
			BoxCollider obj = Prefab.AddComponent<BoxCollider>();
			obj.center = new Vector3(0f, 0.017f, 0f);
			obj.size = new Vector3(0.344f, 0.054f, 0.344f);
			AudioSource obj2 = Prefab.AddComponent<AudioSource>();
			obj2.playOnAwake = false;
			obj2.spatialBlend = 1f;
			obj2.rolloffMode = (AudioRolloffMode)1;
			obj2.minDistance = 1f;
			obj2.maxDistance = 14f;
			obj2.dopplerLevel = 0f;
			GameObject val = new GameObject("ScanNode")
			{
				layer = 22
			};
			val.transform.SetParent(Prefab.transform, false);
			val.transform.localPosition = new Vector3(0f, 0.017f, 0f);
			val.AddComponent<BoxCollider>().size = new Vector3(0.45f, 0.3f, 0.45f);
			ScanNodeProperties obj3 = val.AddComponent<ScanNodeProperties>();
			obj3.headerText = "Poison mystery pizza";
			obj3.subText = "Value: ";
			obj3.maxRange = 13;
			obj3.minRange = 1;
			obj3.requiresLineOfSight = true;
			obj3.nodeType = 2;
			obj3.creatureScanID = -1;
			ItemDef = ScriptableObject.CreateInstance<Item>();
			((Object)ItemDef).name = "PoisonMysteryPizza";
			((Object)ItemDef).hideFlags = (HideFlags)61;
			ItemDef.itemName = "Poison mystery pizza";
			ItemDef.itemId = 7300420;
			ItemDef.isScrap = true;
			ItemDef.creditsWorth = PizzaConfig.Price.Value;
			ItemDef.weight = 1f + Mathf.Max(0f, PizzaConfig.WeightLb.Value) / 105f;
			ItemDef.twoHanded = false;
			ItemDef.twoHandedAnimation = false;
			ItemDef.canBeGrabbedBeforeGameStart = true;
			ItemDef.itemSpawnsOnGround = true;
			ItemDef.isConductiveMetal = false;
			ItemDef.requiresBattery = false;
			ItemDef.holdButtonUse = false;
			ItemDef.syncUseFunction = false;
			ItemDef.syncGrabFunction = false;
			ItemDef.syncDiscardFunction = false;
			ItemDef.saveItemVariable = false;
			ItemDef.allowDroppingAheadOfPlayer = true;
			ItemDef.highestSalePercentage = 80;
			ItemDef.grabAnim = "";
			ItemDef.restingRotation = Vector3.zero;
			ItemDef.verticalOffset = 0.01f;
			ItemDef.positionOffset = PizzaConfig.ParseVector(PizzaConfig.HeldPositionOffset.Value, new Vector3(0.02f, 0.1f, -0.1f));
			ItemDef.rotationOffset = PizzaConfig.ParseVector(PizzaConfig.HeldRotationOffset.Value, new Vector3(-90f, 0f, 0f));
			ItemDef.toolTips = new string[1] { "Eat pizza : [LMB]" };
			ItemDef.spawnPositionTypes = new List<ItemGroup>();
			ItemDef.spawnPrefab = Prefab;
			ApplyValueRange(0.4f);
			Texture2D val2 = LoadTexture("hudicon.png", mipmaps: false);
			if ((Object)(object)val2 != (Object)null)
			{
				Sprite val3 = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)val3).name = "PoisonMysteryPizzaIcon";
				((Object)val3).hideFlags = (HideFlags)61;
				ItemDef.itemIcon = val3;
			}
			PhysicsProp obj4 = Prefab.AddComponent<PhysicsProp>();
			((GrabbableObject)obj4).itemProperties = ItemDef;
			((GrabbableObject)obj4).grabbable = true;
			((GrabbableObject)obj4).grabbableToEnemies = true;
			((GrabbableObject)obj4).mainObjectRenderer = mainObjectRenderer;
			string? pluginDir = Path.GetDirectoryName(pluginDllPath) ?? ".";
			Chimp = LoadSound(pluginDir, "chimp.wav");
			TinyScream = LoadSound(pluginDir, "TinyScream.wav");
			Regrow = LoadSound(pluginDir, "ohhellyeahglrop.wav");
			YeahBaby = LoadSound(pluginDir, "yeahbaby.wav");
			Barf = LoadSound(pluginDir, "barf.wav");
		}

		public static void Register()
		{
			Items.RegisterScrap(ItemDef, Mathf.Max(0, PizzaConfig.ScrapRarity.Value), (LevelTypes)(-1));
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)val).name = "PoisonMysteryPizzaInfo";
			((Object)val).hideFlags = (HideFlags)61;
			val.clearPreviousText = true;
			val.maxCharactersToType = 25;
			val.displayText = "POISON MYSTERY PIZZA\n\nA pizza of doubtful origin. Hold it and eat it to find out what it does: it may make you faster, heal you, make you tiny, send you somewhere else, or worse. The Company accepts no liability.\n\nCan also be sold as scrap.\n\n";
			Items.RegisterShopItem(ItemDef, (TerminalNode)null, (TerminalNode)null, val, Mathf.Max(0, PizzaConfig.Price.Value));
		}

		public static void ApplyValueRange(float scrapValueMultiplier)
		{
			if (!((Object)(object)ItemDef == (Object)null))
			{
				PizzaLogic.RawValueRange(PizzaConfig.MinValue.Value, PizzaConfig.MaxValue.Value, scrapValueMultiplier, out var rawMin, out var rawMaxExclusive);
				ItemDef.minValue = rawMin;
				ItemDef.maxValue = rawMaxExclusive;
			}
		}

		public static void LateSetup(StartOfRound round)
		{
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Expected O, but got Unknown
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ItemDef == (Object)null || (Object)(object)Prefab == (Object)null || (Object)(object)round == (Object)null)
			{
				return;
			}
			try
			{
				Item val = null;
				Material val2 = null;
				AudioMixerGroup val3 = null;
				List<Item> list = (((Object)(object)round.allItemsList != (Object)null) ? round.allItemsList.itemsList : null);
				if (list != null)
				{
					string[] array = new string[4] { "Toy cube", "Rubber Ducky", "Mug", "Plastic fish" };
					foreach (string text in array)
					{
						foreach (Item item in list)
						{
							if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)ItemDef && item.itemName == text && (Object)(object)item.grabSFX != (Object)null && (Object)(object)item.dropSFX != (Object)null)
							{
								val = item;
								break;
							}
						}
						if ((Object)(object)val != (Object)null)
						{
							break;
						}
					}
					foreach (Item item2 in list)
					{
						if ((Object)(object)item2 == (Object)null || (Object)(object)item2 == (Object)(object)ItemDef || (Object)(object)item2.spawnPrefab == (Object)null)
						{
							continue;
						}
						if ((Object)(object)val == (Object)null && !item2.twoHanded && (Object)(object)item2.grabSFX != (Object)null && (Object)(object)item2.dropSFX != (Object)null)
						{
							val = item2;
						}
						if ((Object)(object)val3 == (Object)null)
						{
							AudioSource component = item2.spawnPrefab.GetComponent<AudioSource>();
							if ((Object)(object)component != (Object)null && (Object)(object)component.outputAudioMixerGroup != (Object)null)
							{
								val3 = component.outputAudioMixerGroup;
							}
						}
						if ((Object)(object)val2 == (Object)null)
						{
							MeshRenderer componentInChildren = item2.spawnPrefab.GetComponentInChildren<MeshRenderer>(true);
							Material val4 = (((Object)(object)componentInChildren != (Object)null) ? ((Renderer)componentInChildren).sharedMaterial : null);
							if ((Object)(object)val4 != (Object)null && (Object)(object)val4.shader != (Object)null && ((Object)val4.shader).name == "HDRP/Lit" && IsOpaque(val4))
							{
								val2 = val4;
							}
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					ItemDef.grabSFX = val.grabSFX;
					ItemDef.dropSFX = val.dropSFX;
					ItemDef.pocketSFX = val.pocketSFX;
					ItemDef.throwSFX = val.throwSFX;
				}
				if ((Object)(object)val3 != (Object)null)
				{
					AudioSource component2 = Prefab.GetComponent<AudioSource>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.outputAudioMixerGroup = val3;
					}
				}
				if ((Object)(object)_material == (Object)null)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						_material = new Material(val2);
					}
					else
					{
						Shader val5 = Shader.Find("HDRP/Lit");
						if ((Object)(object)val5 != (Object)null)
						{
							_material = new Material(val5);
						}
					}
					if ((Object)(object)_material != (Object)null)
					{
						((Object)_material).name = "PoisonMysteryPizzaMaterial";
						((Object)_material).hideFlags = (HideFlags)61;
						SetTexture(_material, "_BaseColorMap", (Texture)(object)_texture);
						SetTexture(_material, "_MainTex", (Texture)(object)_texture);
						SetColor(_material, "_BaseColor", Color.white);
						SetColor(_material, "_Color", Color.white);
						SetTexture(_material, "_NormalMap", null);
						SetTexture(_material, "_MaskMap", null);
						SetTexture(_material, "_DetailMap", null);
						SetTexture(_material, "_EmissiveColorMap", null);
						SetColor(_material, "_EmissiveColor", Color.black);
						SetFloat(_material, "_Metallic", 0f);
						SetFloat(_material, "_Smoothness", 0.22f);
						_material.DisableKeyword("_NORMALMAP");
						_material.DisableKeyword("_MASKMAP");
						_material.DisableKeyword("_DETAIL_MAP");
						_material.DisableKeyword("_EMISSIVE_COLOR_MAP");
					}
					else
					{
						Plugin.Log.LogWarning((object)"No HDRP/Lit material found; the pizza will use the default material.");
					}
				}
				if ((Object)(object)_material != (Object)null)
				{
					MeshRenderer component3 = Prefab.GetComponent<MeshRenderer>();
					if ((Object)(object)component3 != (Object)null)
					{
						((Renderer)component3).sharedMaterial = _material;
					}
				}
				if (!_lateSetupDone)
				{
					_lateSetupDone = true;
					Plugin.Log.LogInfo((object)("Pizza set up (sounds from: " + (((Object)(object)val != (Object)null) ? val.itemName : "none") + ", material from: " + (((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "Shader.Find") + ")."));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Pizza late setup failed: " + ex));
			}
		}

		private static bool IsOpaque(Material m)
		{
			if (m.HasProperty("_SurfaceType") && m.GetFloat("_SurfaceType") > 0.5f)
			{
				return false;
			}
			if (m.HasProperty("_AlphaCutoffEnable") && m.GetFloat("_AlphaCutoffEnable") > 0.5f)
			{
				return false;
			}
			return true;
		}

		private static void SetTexture(Material m, string prop, Texture t)
		{
			if (m.HasProperty(prop))
			{
				m.SetTexture(prop, t);
			}
		}

		private static void SetColor(Material m, string prop, Color c)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(prop))
			{
				m.SetColor(prop, c);
			}
		}

		private static void SetFloat(Material m, string prop, float f)
		{
			if (m.HasProperty(prop))
			{
				m.SetFloat(prop, f);
			}
		}

		private static Mesh BuildMesh()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00e2: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			PizzaGeometry.MeshData meshData = PizzaGeometry.Build();
			int vertexCount = meshData.VertexCount;
			Vector3[] array = (Vector3[])(object)new Vector3[vertexCount];
			Vector3[] array2 = (Vector3[])(object)new Vector3[vertexCount];
			Vector2[] array3 = (Vector2[])(object)new Vector2[vertexCount];
			for (int i = 0; i < vertexCount; i++)
			{
				array[i] = new Vector3(meshData.Positions[i * 3], meshData.Positions[i * 3 + 1], meshData.Positions[i * 3 + 2]);
				array2[i] = new Vector3(meshData.Normals[i * 3], meshData.Normals[i * 3 + 1], meshData.Normals[i * 3 + 2]);
				array3[i] = new Vector2(meshData.Uvs[i * 2], meshData.Uvs[i * 2 + 1]);
			}
			Mesh val = new Mesh
			{
				name = "PoisonMysteryPizzaMesh",
				hideFlags = (HideFlags)61,
				vertices = array,
				normals = array2,
				uv = array3,
				triangles = meshData.Triangles
			};
			val.RecalculateBounds();
			val.RecalculateTangents();
			return val;
		}

		private static Texture2D LoadTexture(string resource, bool mipmaps)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
				if (stream == null)
				{
					Plugin.Log.LogError((object)("Embedded resource missing: " + resource));
					return null;
				}
				byte[] array = new byte[stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num <= 0)
					{
						break;
					}
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, mipmaps);
				((Object)val).name = "PoisonMysteryPizza_" + resource;
				((Object)val).hideFlags = (HideFlags)61;
				if (!ImageConversion.LoadImage(val, array, true))
				{
					Plugin.Log.LogError((object)("Could not decode " + resource));
					return null;
				}
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)2;
				((Texture)val).anisoLevel = 4;
				return val;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not load " + resource + ": " + ex.Message));
				return null;
			}
		}

		private static AudioClip LoadSound(string pluginDir, string fileName)
		{
			try
			{
				string path = Path.Combine(pluginDir, "Audio", fileName);
				if (!File.Exists(path))
				{
					path = Path.Combine(pluginDir, fileName);
				}
				if (!File.Exists(path))
				{
					string[] files = Directory.GetFiles(pluginDir, fileName, SearchOption.AllDirectories);
					if (files.Length != 0)
					{
						path = files[0];
					}
				}
				if (!File.Exists(path))
				{
					Plugin.Log.LogWarning((object)("Sound not found: " + fileName + " (looked in " + pluginDir + "). That sound will be silent."));
					return null;
				}
				WavFile.Data data = WavFile.Read(File.ReadAllBytes(path));
				int num = data.Samples.Length / data.Channels;
				if (num <= 0)
				{
					return null;
				}
				AudioClip obj = AudioClip.Create(Path.GetFileNameWithoutExtension(fileName), num, data.Channels, data.SampleRate, false);
				((Object)obj).hideFlags = (HideFlags)61;
				obj.SetData(data.Samples, 0);
				return obj;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not load sound " + fileName + ": " + ex.Message));
				return null;
			}
		}
	}
	internal static class PizzaConfig
	{
		public static ConfigEntry<int> Price;

		public static ConfigEntry<int> MinValue;

		public static ConfigEntry<int> MaxValue;

		public static ConfigEntry<int> ScrapRarity;

		public static ConfigEntry<float> WeightLb;

		public static ConfigEntry<string> HeldPositionOffset;

		public static ConfigEntry<string> HeldRotationOffset;

		public static ConfigEntry<int>[] Weights;

		public static ConfigEntry<float> SpeedMultiplier;

		public static ConfigEntry<float> SpeedSeconds;

		public static ConfigEntry<float> ShrinkScale;

		public static ConfigEntry<float> ShrinkSeconds;

		public static ConfigEntry<float> StaminaSeconds;

		public static ConfigEntry<int> PoisonDamage;

		public static ConfigEntry<bool> PoisonCanKill;

		public static ConfigEntry<bool> TeleportAnywhere;

		public static ConfigEntry<bool> StompEnabled;

		public static ConfigEntry<float> StompRadius;

		public static ConfigEntry<float> StompGraceSeconds;

		public static ConfigEntry<int> BloodDecals;

		public static ConfigEntry<float> BloodSize;

		public static ConfigEntry<float> BloodRadius;

		public static ConfigEntry<float> TinyVoicePitch;

		public static ConfigEntry<float> MessageSeconds;

		public static ConfigEntry<float> SoundVolume;

		public static void Bind(ConfigFile cfg)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Expected O, but got Unknown
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Expected O, but got Unknown
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Expected O, but got Unknown
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Expected O, but got Unknown
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Expected O, but got Unknown
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Expected O, but got Unknown
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Expected O, but got Unknown
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Expected O, but got Unknown
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Expected O, but got Unknown
			Price = cfg.Bind<int>("Item", "Price", 300, new ConfigDescription("Store price in credits.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			MinValue = cfg.Bind<int>("Item", "MinValue", 100, new ConfigDescription("Lowest scrap value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			MaxValue = cfg.Bind<int>("Item", "MaxValue", 200, new ConfigDescription("Highest scrap value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			ScrapRarity = cfg.Bind<int>("Item", "ScrapRarity", 25, new ConfigDescription("Spawn weight as scrap on every moon. Common vanilla scrap is around 20-60. 0 = never found as scrap.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
			WeightLb = cfg.Bind<float>("Item", "WeightLb", 2f, new ConfigDescription("Carry weight in pounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			HeldPositionOffset = cfg.Bind<string>("Item", "HeldPositionOffset", "0.02,0.1,-0.1", "Position of the pizza in the hand (x,y,z).");
			HeldRotationOffset = cfg.Bind<string>("Item", "HeldRotationOffset", "-90,0,0", "Rotation of the pizza in the hand (x,y,z degrees).");
			string[] array = new string[8] { "Speed", "Teleport", "Shrink", "DoubleJump", "Heal", "Poison", "Stamina", "Mimic" };
			Weights = new ConfigEntry<int>[8];
			for (int i = 0; i < array.Length; i++)
			{
				Weights[i] = cfg.Bind<int>("Effect chances", array[i] + "Weight", 1, new ConfigDescription("Relative chance of the " + array[i] + " effect. All equal = equal chances. 0 = never. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			}
			SpeedMultiplier = cfg.Bind<float>("Effects", "SpeedMultiplier", 1.3f, new ConfigDescription("Movement speed multiplier (1.3 = +30%). Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			SpeedSeconds = cfg.Bind<float>("Effects", "SpeedSeconds", 600f, new ConfigDescription("Length of the speed effect. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 36000f), Array.Empty<object>()));
			ShrinkScale = cfg.Bind<float>("Effects", "ShrinkScale", 0.1f, new ConfigDescription("Size while shrunk (0.1 = 10%). Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 0.9f), Array.Empty<object>()));
			ShrinkSeconds = cfg.Bind<float>("Effects", "ShrinkSeconds", 120f, new ConfigDescription("Length of the shrink effect. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 36000f), Array.Empty<object>()));
			StaminaSeconds = cfg.Bind<float>("Effects", "StaminaSeconds", 300f, new ConfigDescription("Length of the unlimited stamina effect. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 36000f), Array.Empty<object>()));
			PoisonDamage = cfg.Bind<int>("Effects", "PoisonDamage", 50, new ConfigDescription("Damage of the poison effect, in percent of full health. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			PoisonCanKill = cfg.Bind<bool>("Effects", "PoisonCanKill", true, "If true the poison effect kills a player who has no more health than the damage. If false it leaves 1 health. Host only.");
			TeleportAnywhere = cfg.Bind<bool>("Effects", "TeleportAnywhere", true, "If true the teleport effect can send you anywhere on the moon, inside or outside. If false you stay on the side you are on. Host only.");
			StompEnabled = cfg.Bind<bool>("Tiny", "StompEnabled", true, "A shrunk player dies when a normal-sized player steps on them.");
			StompRadius = cfg.Bind<float>("Tiny", "StompRadius", 0.45f, new ConfigDescription("How close (metres, horizontally) a walking player's feet must come to squash a shrunk player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 2f), Array.Empty<object>()));
			StompGraceSeconds = cfg.Bind<float>("Tiny", "StompGraceSeconds", 2f, new ConfigDescription("Time after shrinking during which you cannot be squashed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
			BloodDecals = cfg.Bind<int>("Tiny", "BloodDecals", 30, new ConfigDescription("Number of blood splatters left when a shrunk player is squashed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 80), Array.Empty<object>()));
			BloodSize = cfg.Bind<float>("Tiny", "BloodSize", 2.2f, new ConfigDescription("Size of those splatters compared with the game's normal blood drops.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 6f), Array.Empty<object>()));
			BloodRadius = cfg.Bind<float>("Tiny", "BloodRadius", 1.8f, new ConfigDescription("How far (metres) the blood spreads.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 6f), Array.Empty<object>()));
			TinyVoicePitch = cfg.Bind<float>("Tiny", "TinyVoicePitch", 1.35f, new ConfigDescription("Voice chat pitch of a shrunk player. 1 = unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), Array.Empty<object>()));
			MessageSeconds = cfg.Bind<float>("General", "MessageSeconds", 3f, new ConfigDescription("How long the effect text stays on screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
			SoundVolume = cfg.Bind<float>("General", "SoundVolume", 1f, new ConfigDescription("Volume of the pizza effect sounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
		}

		public static Vector3 ParseVector(string text, Vector3 fallback)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(text))
			{
				return fallback;
			}
			string[] array = text.Split(',');
			if (array.Length != 3)
			{
				return fallback;
			}
			float[] array2 = new float[3];
			for (int i = 0; i < 3; i++)
			{
				if (!float.TryParse(array[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i]))
				{
					return fallback;
				}
			}
			return new Vector3(array2[0], array2[1], array2[2]);
		}
	}
	public static class PizzaGeometry
	{
		public sealed class MeshData
		{
			public float[] Positions;

			public float[] Normals;

			public float[] Uvs;

			public int[] Triangles;

			public int VertexCount => Positions.Length / 3;
		}

		public const float Radius = 0.172f;

		public const float Height = 0.034f;

		public const int Segments = 40;

		private static readonly float[][] TopProfile = new float[8][]
		{
			new float[2] { 0f, 0.014f },
			new float[2] { 0.07f, 0.014f },
			new float[2] { 0.132f, 0.014f },
			new float[2] { 0.141f, 0.019f },
			new float[2] { 0.15f, 0.03f },
			new float[2] { 0.159f, 0.034f },
			new float[2] { 0.167f, 0.029f },
			new float[2] { 0.172f, 0.017f }
		};

		private static readonly float[][] BottomProfile = new float[5][]
		{
			new float[2] { 0.172f, 0.017f },
			new float[2] { 0.167f, 0.005f },
			new float[2] { 0.152f, 0f },
			new float[2] { 0.075f, 0f },
			new float[2]
		};

		public static MeshData Build()
		{
			List<float> list = new List<float>();
			List<float> list2 = new List<float>();
			List<float> list3 = new List<float>();
			List<int> list4 = new List<int>();
			AddStrip(TopProfile, 0.25f, list, list2, list3, list4);
			AddStrip(BottomProfile, 0.75f, list, list2, list3, list4);
			return new MeshData
			{
				Positions = list.ToArray(),
				Normals = list2.ToArray(),
				Uvs = list3.ToArray(),
				Triangles = list4.ToArray()
			};
		}

		private static void AddStrip(float[][] profile, float uCentre, List<float> pos, List<float> nrm, List<float> uv, List<int> tri)
		{
			int num = profile.Length;
			int num2 = pos.Count / 3;
			int num3 = 41;
			float[][] array = new float[num][];
			for (int i = 0; i < num; i++)
			{
				float nx = 0f;
				float ny = 0f;
				if (i > 0)
				{
					Accumulate(profile[i - 1], profile[i], ref nx, ref ny);
				}
				if (i < num - 1)
				{
					Accumulate(profile[i], profile[i + 1], ref nx, ref ny);
				}
				float num4 = (float)Math.Sqrt(nx * nx + ny * ny);
				if (num4 < 1E-06f)
				{
					nx = 0f;
					ny = 1f;
					num4 = 1f;
				}
				array[i] = new float[2]
				{
					nx / num4,
					ny / num4
				};
			}
			for (int j = 0; j < num; j++)
			{
				float num5 = profile[j][0];
				float item = profile[j][1];
				for (int k = 0; k <= 40; k++)
				{
					double num6 = Math.PI * 2.0 * (double)k / 40.0;
					float num7 = (float)Math.Cos(num6);
					float num8 = (float)Math.Sin(num6);
					pos.Add(num5 * num7);
					pos.Add(item);
					pos.Add(num5 * num8);
					nrm.Add(array[j][0] * num7);
					nrm.Add(array[j][1]);
					nrm.Add(array[j][0] * num8);
					uv.Add(uCentre + num5 * num7 / 0.172f * 0.245f);
					uv.Add(0.5f + num5 * num8 / 0.172f * 0.49f);
				}
			}
			for (int l = 0; l < num - 1; l++)
			{
				for (int m = 0; m < 40; m++)
				{
					int num9 = num2 + l * num3 + m;
					int item2 = num9 + 1;
					int num10 = num2 + (l + 1) * num3 + m;
					int item3 = num10 + 1;
					if (profile[l][0] > 1E-06f)
					{
						tri.Add(num9);
						tri.Add(item2);
						tri.Add(num10);
					}
					if (profile[l + 1][0] > 1E-06f)
					{
						tri.Add(item2);
						tri.Add(item3);
						tri.Add(num10);
					}
				}
			}
		}

		private static void Accumulate(float[] p, float[] q, ref float nx, ref float ny)
		{
			float num = q[0] - p[0];
			float num2 = q[1] - p[1];
			float num3 = (float)Math.Sqrt(num * num + num2 * num2);
			if (!(num3 < 1E-06f))
			{
				nx += (0f - num2) / num3;
				ny += num / num3;
			}
		}
	}
	public enum PizzaEffect : byte
	{
		Speed,
		Teleport,
		Shrink,
		DoubleJump,
		Heal,
		Poison,
		Stamina,
		Mimic
	}
	public static class PizzaLogic
	{
		public const int EffectCount = 8;

		public static int PickWeighted(int[] weights, bool[] available, double roll01)
		{
			long num = 0L;
			for (int i = 0; i < weights.Length; i++)
			{
				if (available[i] && weights[i] > 0)
				{
					num += weights[i];
				}
			}
			if (num <= 0)
			{
				return -1;
			}
			double num2 = Math.Min(Math.Max(roll01, 0.0), 0.999999999) * (double)num;
			long num3 = 0L;
			int result = -1;
			for (int j = 0; j < weights.Length; j++)
			{
				if (available[j] && weights[j] > 0)
				{
					num3 += weights[j];
					result = j;
					if (num2 < (double)num3)
					{
						return j;
					}
				}
			}
			return result;
		}

		public static void RawValueRange(int wantedMin, int wantedMax, float multiplier, out int rawMin, out int rawMaxExclusive)
		{
			if (wantedMax < wantedMin)
			{
				wantedMax = wantedMin;
			}
			if (multiplier < 0.01f)
			{
				multiplier = 0.4f;
			}
			rawMin = (int)Math.Ceiling((double)wantedMin / (double)multiplier);
			while ((int)((float)rawMin * multiplier) < wantedMin)
			{
				rawMin++;
			}
			int num = (int)Math.Floor((double)(wantedMax + 1) / (double)multiplier);
			while (num > rawMin && (int)((float)num * multiplier) > wantedMax)
			{
				num--;
			}
			if (num < rawMin)
			{
				num = rawMin;
			}
			rawMaxExclusive = num + 1;
		}

		public static string Duration(float seconds)
		{
			if (seconds < 0f)
			{
				seconds = 0f;
			}
			if (seconds < 60f)
			{
				int num = (int)Math.Round(seconds);
				if (num != 1)
				{
					return num + " seconds";
				}
				return "1 second";
			}
			double num2 = Math.Round((double)seconds / 60.0, 1);
			if (Math.Abs(num2 - Math.Round(num2)) < 0.05)
			{
				int num3 = (int)Math.Round(num2);
				if (num3 != 1)
				{
					return num3 + " minutes";
				}
				return "1 minute";
			}
			return num2.ToString("0.0", CultureInfo.InvariantCulture) + " minutes";
		}

		private static string Percent(float fraction)
		{
			return ((int)Math.Round(fraction * 100f)).ToString(CultureInfo.InvariantCulture);
		}

		public static string Describe(PizzaEffect effect, float duration, float magnitude)
		{
			return effect switch
			{
				PizzaEffect.Speed => "You have +" + Percent(magnitude - 1f) + "% speed for " + Duration(duration), 
				PizzaEffect.Teleport => "You were teleported to a random location", 
				PizzaEffect.Shrink => "You shrank to " + Percent(magnitude) + "% size for " + Duration(duration), 
				PizzaEffect.DoubleJump => "You can now double jump", 
				PizzaEffect.Heal => "You are fully healed", 
				PizzaEffect.Poison => "You took " + ((int)Math.Round(magnitude)).ToString(CultureInfo.InvariantCulture) + "% damage", 
				PizzaEffect.Stamina => "You have unlimited stamina for " + Duration(duration), 
				PizzaEffect.Mimic => "You became a mimic", 
				_ => "Something happened", 
			};
		}
	}
	internal sealed class PizzaManager : MonoBehaviour
	{
		private sealed class State
		{
			public float SpeedMult;

			public float SpeedUntil;

			public float StaminaUntil;

			public bool DoubleJump;

			public bool AirJumpUsed;

			public bool Shrunk;

			public float Scale = 1f;

			public float ShrinkUntil;

			public float ShrinkStart;

			public Vector3 OriginalScale = Vector3.one;

			public float OriginalNearClip = -1f;

			public float OriginalStepOffset = -1f;

			public Vector3 LastPos;

			public bool Active
			{
				get
				{
					if (!(SpeedMult > 0f) && !(StaminaUntil > 0f) && !DoubleJump)
					{
						return Shrunk;
					}
					return true;
				}
			}

			public void Reset()
			{
				SpeedMult = 0f;
				SpeedUntil = 0f;
				StaminaUntil = 0f;
				DoubleJump = false;
				AirJumpUsed = false;
				Shrunk = false;
				Scale = 1f;
				ShrinkUntil = 0f;
				OriginalNearClip = -1f;
				OriginalStepOffset = -1f;
			}
		}

		private struct EffectMessage
		{
			public int Player;

			public PizzaEffect Effect;

			public float Duration;

			public float Magnitude;

			public Vector3 Position;

			public bool Flag;

			public int Extra;
		}

		private const byte OpEat = 1;

		private const byte OpEffect = 2;

		private const byte OpMimicLink = 3;

		private const byte OpSquashReport = 4;

		private const byte OpSquash = 5;

		private const byte OpValue = 6;

		private const byte OpSyncRequest = 7;

		private const byte OpSyncState = 8;

		private readonly Dictionary<int, State> _states = new Dictionary<int, State>();

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

		private readonly HashSet<ulong> _knownPizzas = new HashSet<ulong>();

		private readonly HashSet<ulong> _eaten = new HashSet<ulong>();

		private readonly HashSet<ulong> _requested = new HashSet<ulong>();

		private readonly Dictionary<GrabbableObject, Vector3> _scaledItems = new Dictionary<GrabbableObject, Vector3>();

		private readonly List<GrabbableObject> _scaledScratch = new List<GrabbableObject>();

		private readonly Dictionary<int, Vector3> _stompSamples = new Dictionary<int, Vector3>();

		private readonly Dictionary<int, Vector3> _stompVelocity = new Dictionary<int, Vector3>();

		private float _stompSampleTime;

		private bool _hadRound;

		private EnemyType _maskedType;

		public static PizzaManager Instance { get; private set; }

		public static bool AnyShrunk { get; private set; }

		private static float Now => Time.realtimeSinceStartup;

		private void Awake()
		{
			Instance = this;
		}

		private void OnGUI()
		{
			HudMessage.OnGUI();
		}

		private void Update()
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			HudMessage.Tick();
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				if (_hadRound)
				{
					ForgetSession();
				}
				return;
			}
			_hadRound = true;
			if (PizzaNet.EnsureRegistered() && !PizzaNet.IsServer)
			{
				PizzaNet.ToServer(PizzaNet.Build(7));
			}
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			PlayerControllerB localPlayerController = instance.localPlayerController;
			float now = Now;
			bool flag = false;
			_stateKeys.Clear();
			_stateKeys.AddRange(_states.Keys);
			for (int i = 0; i < _stateKeys.Count; i++)
			{
				int num = _stateKeys[i];
				State state = _states[num];
				if (!state.Active)
				{
					continue;
				}
				PlayerControllerB val = ((num >= 0 && num < allPlayerScripts.Length) ? allPlayerScripts[num] : null);
				if ((Object)(object)val == (Object)null)
				{
					state.Reset();
					continue;
				}
				bool isLocal = (Object)(object)val == (Object)(object)localPlayerController;
				if (val.isPlayerDead || !val.isPlayerControlled)
				{
					ClearEffects(val, state, isLocal);
					continue;
				}
				state.LastPos = ((Component)val).transform.position;
				if (state.SpeedMult > 0f && now >= state.SpeedUntil)
				{
					EndSpeed(val, state, isLocal);
				}
				if (state.StaminaUntil > 0f && now >= state.StaminaUntil)
				{
					state.StaminaUntil = 0f;
				}
				if (!state.Shrunk)
				{
					continue;
				}
				if (now >= state.ShrinkUntil)
				{
					Unshrink(val, state, isLocal, playSound: true);
					continue;
				}
				flag = true;
				Vector3 val2 = state.OriginalScale * state.Scale;
				if (((Component)val).transform.localScale != val2)
				{
					((Component)val).transform.localScale = val2;
				}
				SetVoicePitch(num, PizzaConfig.TinyVoicePitch.Value);
			}
			AnyShrunk = flag;
			UpdateHeldItemScales(allPlayerScripts);
			if (flag && (Object)(object)localPlayerController != (Object)null && PizzaConfig.StompEnabled.Value)
			{
				CheckStomp(allPlayerScripts, localPlayerController, now);
			}
			if (instance.inShipPhase && Blood.Count > 0)
			{
				Blood.Clear();
			}
		}

		private void ForgetSession()
		{
			_hadRound = false;
			_states.Clear();
			_knownPizzas.Clear();
			_eaten.Clear();
			_requested.Clear();
			RestoreScaledItems();
			_stompSamples.Clear();
			_stompVelocity.Clear();
			_maskedType = null;
			AnyShrunk = false;
			Blood.Forget();
			PizzaNet.Forget();
			((MonoBehaviour)this).StopAllCoroutines();
		}

		private State GetState(int index)
		{
			if (!_states.TryGetValue(index, out var value))
			{
				value = new State();
				_states[index] = value;
			}
			return value;
		}

		private bool IsShrunk(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)null)
			{
				return false;
			}
			if (_states.TryGetValue((int)p.playerClientId, out var value))
			{
				return value.Shrunk;
			}
			return false;
		}

		public float ScaleOf(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)null)
			{
				return 1f;
			}
			if (!_states.TryGetValue((int)p.playerClientId, out var value) || !value.Shrunk)
			{
				return 1f;
			}
			return value.Scale;
		}

		public void RequestEat(GrabbableObject item)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)item == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || (Object)(object)item.playerHeldBy != (Object)(object)localPlayerController || localPlayerController.isPlayerDead || !((NetworkBehaviour)item).IsOwner)
			{
				return;
			}
			ulong id = ((NetworkBehaviour)item).NetworkObjectId;
			if (!_requested.Add(id))
			{
				return;
			}
			localPlayerController.DespawnHeldObject();
			if (PizzaNet.IsServer)
			{
				HostHandleEat(localPlayerController, id);
				return;
			}
			PizzaNet.ToServer(PizzaNet.Build(1, delegate(BinaryWriter w)
			{
				w.Write(id);
			}));
		}

		public void RegisterPizza(GrabbableObject item)
		{
			if (!((Object)(object)item == (Object)null))
			{
				if ((Object)(object)((NetworkBehaviour)item).NetworkObject != (Object)null && ((NetworkBehaviour)item).NetworkObject.IsSpawned)
				{
					_knownPizzas.Add(((NetworkBehaviour)item).NetworkObjectId);
				}
				if (PizzaNet.IsServer)
				{
					((MonoBehaviour)this).StartCoroutine(HostAssignValue(item));
				}
			}
		}

		private void HostHandleEat(PlayerControllerB player, ulong itemId)
		{
			if ((Object)(object)player == (Object)null || player.isPlayerDead || !player.isPlayerControlled)
			{
				return;
			}
			bool flag = _knownPizzas.Contains(itemId);
			if (!flag)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(itemId, out var value) && (Object)(object)value != (Object)null)
				{
					GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>();
					flag = (Object)(object)component != (Object)null && (Object)(object)component.itemProperties == (Object)(object)PizzaAssets.ItemDef;
				}
			}
			if (flag && _eaten.Add(itemId))
			{
				HostRollEffect(player);
			}
		}

		private void HostRollEffect(PlayerControllerB player)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			int num = (int)player.playerClientId;
			bool[] array = new bool[8];
			int[] array2 = new int[8];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = true;
				array2[i] = PizzaConfig.Weights[i].Value;
			}
			bool flag = !instance.inShipPhase && !instance.shipIsLeaving;
			Vector3 position = Vector3.zero;
			bool inside = false;
			array[1] = flag && array2[1] > 0 && PickTeleport(player, out position, out inside);
			array[7] = flag && (Object)(object)GetMaskedType() != (Object)null;
			int num2 = PizzaLogic.PickWeighted(array2, array, Random.value);
			if (num2 < 0)
			{
				num2 = 4;
			}
			EffectMessage m = new EffectMessage
			{
				Player = num,
				Effect = (PizzaEffect)num2
			};
			switch (m.Effect)
			{
			case PizzaEffect.Speed:
				m.Duration = PizzaConfig.SpeedSeconds.Value;
				m.Magnitude = PizzaConfig.SpeedMultiplier.Value;
				break;
			case PizzaEffect.Teleport:
				m.Position = position;
				m.Flag = inside;
				break;
			case PizzaEffect.Shrink:
				m.Duration = PizzaConfig.ShrinkSeconds.Value;
				m.Magnitude = PizzaConfig.ShrinkScale.Value;
				break;
			case PizzaEffect.Poison:
				m.Magnitude = PizzaConfig.PoisonDamage.Value;
				m.Flag = PizzaConfig.PoisonCanKill.Value;
				break;
			case PizzaEffect.Stamina:
				m.Duration = PizzaConfig.StaminaSeconds.Value;
				break;
			case PizzaEffect.Mimic:
				m.Flag = player.isInsideFactory;
				m.Extra = ((Random.value < 0.5f) ? 4 : 5);
				break;
			}
			Plugin.Log.LogInfo((object)(player.playerUsername + " ate a pizza: " + m.Effect));
			Vector3 position2 = ((Component)player).transform.position;
			float y = ((Component)player).transform.eulerAngles.y;
			PizzaNet.ToClients(Write(m));
			ApplyEffect(m);
			if (m.Effect == PizzaEffect.Mimic)
			{
				((MonoBehaviour)this).StartCoroutine(HostSpawnMimic(player, num, m.Flag, m.Extra, position2, y));
			}
		}

		private static byte[] Write(EffectMessage m)
		{
			return PizzaNet.Build(2, delegate(BinaryWriter w)
			{
				w.Write(m.Player);
				w.Write((byte)m.Effect);
				w.Write(m.Duration);
				w.Write(m.Magnitude);
				w.Write(m.Position.x);
				w.Write(m.Position.y);
				w.Write(m.Position.z);
				w.Write(m.Flag);
				w.Write(m.Extra);
			});
		}

		private static Vector3 ReadVector(BinaryReader r)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float num = r.ReadSingle();
			float num2 = r.ReadSingle();
			float num3 = r.ReadSingle();
			return new Vector3(num, num2, num3);
		}

		public void HandleMessage(ulong sender, byte[] data)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			bool isServer = PizzaNet.IsServer;
			using MemoryStream input = new MemoryStream(data);
			using BinaryReader binaryReader = new BinaryReader(input);
			byte b = binaryReader.ReadByte();
			bool flag = sender == 0;
			switch (b)
			{
			case 1:
				if (isServer)
				{
					HostHandleEat(FindPlayer(sender), binaryReader.ReadUInt64());
				}
				break;
			case 2:
				if (!isServer && flag)
				{
					ApplyEffect(new EffectMessage
					{
						Player = binaryReader.ReadInt32(),
						Effect = (PizzaEffect)binaryReader.ReadByte(),
						Duration = binaryReader.ReadSingle(),
						Magnitude = binaryReader.ReadSingle(),
						Position = ReadVector(binaryReader),
						Flag = binaryReader.ReadBoolean(),
						Extra = binaryReader.ReadInt32()
					});
				}
				break;
			case 3:
				if (!isServer && flag)
				{
					ulong enemyId = binaryReader.ReadUInt64();
					int index = binaryReader.ReadInt32();
					bool inFactory = binaryReader.ReadBoolean();
					int maskType = binaryReader.ReadInt32();
					((MonoBehaviour)this).StartCoroutine(LinkMimic(enemyId, index, inFactory, maskType));
				}
				break;
			case 4:
				if (isServer)
				{
					PlayerControllerB val = FindPlayer(sender);
					Vector3 pos = ReadVector(binaryReader);
					int seed = binaryReader.ReadInt32();
					if ((Object)(object)val != (Object)null)
					{
						HostSquash((int)val.playerClientId, pos, seed);
					}
				}
				break;
			case 5:
				if (!isServer && flag)
				{
					int player = binaryReader.ReadInt32();
					Vector3 pos2 = ReadVector(binaryReader);
					int seed2 = binaryReader.ReadInt32();
					DoSquash(player, pos2, seed2);
				}
				break;
			case 6:
				if (!isServer && flag)
				{
					ulong itemId = binaryReader.ReadUInt64();
					int value = binaryReader.ReadInt32();
					ApplyValue(itemId, value);
				}
				break;
			case 7:
				if (isServer)
				{
					HostSendSync(sender);
				}
				break;
			case 8:
			{
				if (!(!isServer && flag))
				{
					break;
				}
				int num = binaryReader.ReadInt32();
				for (int i = 0; i < num && i < 64; i++)
				{
					int num2 = binaryReader.ReadInt32();
					float duration = binaryReader.ReadSingle();
					float scale = binaryReader.ReadSingle();
					PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
					if (num2 >= 0 && num2 < allPlayerScripts.Length && !((Object)(object)allPlayerScripts[num2] == (Object)null))
					{
						ApplyShrink(allPlayerScripts[num2], GetState(num2), (Object)(object)allPlayerScripts[num2] == (Object)(object)StartOfRound.Instance.localPlayerController, scale, duration, announce: false);
					}
				}
				break;
			}
			}
		}

		private static PlayerControllerB FindPlayer(ulong clientId)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val != (Object)null && val.actualClientId == clientId && (val.isPlayerControlled || val.isPlayerDead))
				{
					return val;
				}
			}
			return null;
		}

		private void HostSendSync(ulong clientId)
		{
			List<KeyValuePair<int, State>> list = new List<KeyValuePair<int, State>>();
			foreach (KeyValuePair<int, State> state in _states)
			{
				if (state.Value.Shrunk)
				{
					list.Add(state);
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			float now = Now;
			PizzaNet.ToClient(clientId, PizzaNet.Build(8, delegate(BinaryWriter w)
			{
				w.Write(list.Count);
				foreach (KeyValuePair<int, State> item in list)
				{
					w.Write(item.Key);
					w.Write(Mathf.Max(0.1f, item.Value.ShrinkUntil - now));
					w.Write(item.Value.Scale);
				}
			}));
		}

		private void ApplyEffect(EffectMessage m)
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			if (m.Player < 0 || m.Player >= allPlayerScripts.Length)
			{
				return;
			}
			PlayerControllerB val = allPlayerScripts[m.Player];
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !val.isPlayerControlled)
			{
				return;
			}
			bool flag = (Object)(object)val == (Object)(object)instance.localPlayerController;
			State state = GetState(m.Player);
			float now = Now;
			if (flag)
			{
				HudMessage.Show(PizzaLogic.Describe(m.Effect, m.Duration, m.Magnitude), PizzaConfig.MessageSeconds.Value);
			}
			try
			{
				switch (m.Effect)
				{
				case PizzaEffect.Speed:
					if (flag)
					{
						if (state.SpeedMult > 0f)
						{
							val.movementSpeed /= state.SpeedMult;
						}
						state.SpeedMult = Mathf.Max(1.0001f, m.Magnitude);
						val.movementSpeed *= state.SpeedMult;
						state.SpeedUntil = now + m.Duration;
					}
					break;
				case PizzaEffect.Teleport:
					DoTeleport(val, m.Position, m.Flag, flag);
					break;
				case PizzaEffect.Shrink:
					ApplyShrink(val, state, flag, m.Magnitude, m.Duration, announce: true);
					break;
				case PizzaEffect.DoubleJump:
					if (flag)
					{
						state.DoubleJump = true;
						state.AirJumpUsed = false;
					}
					break;
				case PizzaEffect.Heal:
					val.health = 100;
					val.criticallyInjured = false;
					val.bleedingHeavily = false;
					if ((Object)(object)val.playerBodyAnimator != (Object)null)
					{
						val.playerBodyAnimator.SetBool("Limp", false);
					}
					if (flag)
					{
						val.MakeCriticallyInjured(false);
						if ((Object)(object)HUDManager.Instance != (Object)null)
						{
							HUDManager.Instance.UpdateHealthUI(100, false);
						}
					}
					PlayOnPlayer(val, PizzaAssets.YeahBaby);
					break;
				case PizzaEffect.Poison:
					PlayOnPlayer(val, PizzaAssets.Barf);
					if (flag)
					{
						int num = Mathf.RoundToInt(m.Magnitude);
						if (!m.Flag)
						{
							num = Mathf.Min(num, val.health - 1);
						}
						if (num > 0)
						{
							val.DamagePlayer(num, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
						}
					}
					break;
				case PizzaEffect.Stamina:
					if (flag)
					{
						state.StaminaUntil = now + m.Duration;
					}
					break;
				case PizzaEffect.Mimic:
					if (flag && val.AllowPlayerDeath())
					{
						val.KillPlayer(Vector3.zero, true, (CauseOfDeath)5, m.Extra, default(Vector3), false);
					}
					break;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Pizza effect " + m.Effect.ToString() + " failed: " + ex));
			}
		}

		private void EndSpeed(PlayerControllerB p, State s, bool isLocal)
		{
			if (isLocal && s.SpeedMult > 0f && (Object)(object)p != (Object)null)
			{
				p.movementSpeed /= s.SpeedMult;
			}
			s.SpeedMult = 0f;
			s.SpeedUntil = 0f;
		}

		private void ClearEffects(PlayerControllerB p, State s, bool isLocal)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			bool shrunk = s.Shrunk;
			Vector3 lastPos = s.LastPos;
			EndSpeed(p, s, isLocal);
			if (shrunk)
			{
				Unshrink(p, s, isLocal, playSound: false);
			}
			s.Reset();
			if (shrunk && (Object)(object)p != (Object)null && p.isPlayerDead)
			{
				if (isLocal && (Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.UIAudio != (Object)null && (Object)(object)PizzaAssets.TinyScream != (Object)null)
				{
					HUDManager.Instance.UIAudio.PlayOneShot(PizzaAssets.TinyScream, PizzaConfig.SoundVolume.Value);
				}
				else
				{
					PlayAt(lastPos, PizzaAssets.TinyScream, PizzaConfig.SoundVolume.Value);
				}
			}
		}

		private void ApplyShrink(PlayerControllerB p, State s, bool isLocal, float scale, float duration, bool announce)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			scale = Mathf.Clamp(scale, 0.05f, 1f);
			if (!s.Shrunk)
			{
				Vector3 localScale = ((Component)p).transform.localScale;
				s.OriginalScale = ((((Vector3)(ref localScale)).sqrMagnitude > 0.0001f) ? localScale : Vector3.one);
				if (isLocal)
				{
					if ((Object)(object)p.gameplayCamera != (Object)null)
					{
						s.OriginalNearClip = p.gameplayCamera.nearClipPlane;
					}
					if ((Object)(object)p.thisController != (Object)null)
					{
						s.OriginalStepOffset = p.thisController.stepOffset;
					}
				}
			}
			s.Shrunk = true;
			s.Scale = scale;
			s.ShrinkStart = Now;
			s.ShrinkUntil = Now + Mathf.Max(0.1f, duration);
			s.LastPos = ((Component)p).transform.position;
			((Component)p).transform.localScale = s.OriginalScale * scale;
			AnyShrunk = true;
			if (isLocal)
			{
				if ((Object)(object)p.gameplayCamera != (Object)null && s.OriginalNearClip > 0f)
				{
					p.gameplayCamera.nearClipPlane = Mathf.Max(0.01f, s.OriginalNearClip * scale);
				}
				if ((Object)(object)p.thisController != (Object)null && s.OriginalStepOffset > 0f)
				{
					p.thisController.stepOffset = Mathf.Min(s.OriginalStepOffset / scale, p.thisController.height * 0.9f);
				}
			}
			if (announce)
			{
				PlayOnPlayer(p, PizzaAssets.Chimp);
			}
		}

		private void Unshrink(PlayerControllerB p, State s, bool isLocal, bool playSound)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			s.Shrunk = false;
			if ((Object)(object)p != (Object)null)
			{
				((Component)p).transform.localScale = s.OriginalScale;
				if (isLocal)
				{
					if ((Object)(object)p.gameplayCamera != (Object)null && s.OriginalNearClip > 0f)
					{
						p.gameplayCamera.nearClipPlane = s.OriginalNearClip;
					}
					if ((Object)(object)p.thisController != (Object)null && s.OriginalStepOffset > 0f)
					{
						p.thisController.stepOffset = s.OriginalStepOffset;
					}
				}
				SetVoicePitch((int)p.playerClientId, 1f);
				if (playSound)
				{
					PlayOnPlayer(p, PizzaAssets.Regrow);
				}
			}
			s.Scale = 1f;
			s.OriginalNearClip = -1f;
			s.OriginalStepOffset = -1f;
		}

		private static void SetVoicePitch(int index, float pitch)
		{
			if (!Mathf.Approximately(PizzaConfig.TinyVoicePitch.Value, 1f))
			{
				SoundManager instance = SoundManager.Instance;
				if (!((Object)(object)instance == (Object)null) && instance.playerVoicePitchTargets != null && index >= 0 && index < instance.playerVoicePitchTargets.Length)
				{
					instance.playerVoicePitchTargets[index] = pitch;
				}
			}
		}

		private void UpdateHeldItemScales(PlayerControllerB[] players)
		{
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (AnyShrunk)
			{
				foreach (KeyValuePair<int, State> state in _states)
				{
					if (!state.Value.Shrunk || state.Key < 0 || state.Key >= players.Length)
					{
						continue;
					}
					PlayerControllerB val = players[state.Key];
					if ((Object)(object)val == (Object)null || val.ItemSlots == null)
					{
						continue;
					}
					for (int i = 0; i < val.ItemSlots.Length; i++)
					{
						GrabbableObject val2 = val.ItemSlots[i];
						if ((Object)(object)val2 == (Object)null || (Object)(object)val2.playerHeldBy != (Object)(object)val)
						{
							continue;
						}
						if (!_scaledItems.TryGetValue(val2, out var value))
						{
							value = ((Component)val2).transform.localScale;
							if (((Vector3)(ref value)).sqrMagnitude < 1E-08f)
							{
								continue;
							}
							_scaledItems[val2] = value;
						}
						Vector3 val3 = value * state.Value.Scale;
						if (((Component)val2).transform.localScale != val3)
						{
							((Component)val2).transform.localScale = val3;
						}
					}
				}
			}
			if (_scaledItems.Count == 0)
			{
				return;
			}
			_scaledScratch.Clear();
			foreach (KeyValuePair<GrabbableObject, Vector3> scaledItem in _scaledItems)
			{
				GrabbableObject key = scaledItem.Key;
				if ((Object)(object)key == (Object)null)
				{
					_scaledScratch.Add(key);
				}
				else if ((Object)(object)key.playerHeldBy == (Object)null || !IsShrunk(key.playerHeldBy))
				{
					((Component)key).transform.localScale = scaledItem.Value;
					_scaledScratch.Add(key);
				}
			}
			for (int j = 0; j < _scaledScratch.Count; j++)
			{
				_scaledItems.Remove(_scaledScratch[j]);
			}
			_scaledScratch.Clear();
		}

		public bool IsScaledItem(GrabbableObject item)
		{
			if ((Object)(object)item != (Object)null)
			{
				return _scaledItems.ContainsKey(item);
			}
			return false;
		}

		private void RestoreScaledItems()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<GrabbableObject, Vector3> scaledItem in _scaledItems)
			{
				if ((Object)(object)scaledItem.Key != (Object)null)
				{
					((Component)scaledItem.Key).transform.localScale = scaledItem.Value;
				}
			}
			_scaledItems.Clear();
		}

		private void CheckStomp(PlayerControllerB[] players, PlayerControllerB local, float now)
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_0091: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			if (!_states.TryGetValue((int)local.playerClientId, out var value) || !value.Shrunk || local.isPlayerDead)
			{
				return;
			}
			float num = now - _stompSampleTime;
			if (num >= 0.1f)
			{
				for (int i = 0; i < players.Length; i++)
				{
					PlayerControllerB val = players[i];
					if (!((Object)(object)val == (Object)null) && val.isPlayerControlled)
					{
						Vector3 position = ((Component)val).transform.position;
						_stompVelocity[i] = ((_stompSamples.TryGetValue(i, out var value2) && num < 1f) ? ((position - value2) / num) : Vector3.zero);
						_stompSamples[i] = position;
					}
				}
				_stompSampleTime = now;
			}
			if (now - value.ShrinkStart < PizzaConfig.StompGraceSeconds.Value)
			{
				return;
			}
			Vector3 position2 = ((Component)local).transform.position;
			float value3 = PizzaConfig.StompRadius.Value;
			for (int j = 0; j < players.Length; j++)
			{
				PlayerControllerB val2 = players[j];
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)local) && val2.isPlayerControlled && !val2.isPlayerDead && !IsShrunk(val2))
				{
					Vector3 val3 = ((Component)val2).transform.position - position2;
					if (!(val3.y < -0.35f) && !(val3.y > 0.7f) && !(val3.x * val3.x + val3.z * val3.z > value3 * value3) && _stompVelocity.TryGetValue(j, out var value4) && (value4.x * value4.x + value4.z * value4.z > 0.36f || value4.y < -1.5f))
					{
						Squash(local, value);
						break;
					}
				}
			}
		}

		private void Squash(PlayerControllerB local, State mine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!local.AllowPlayerDeath())
			{
				return;
			}
			Vector3 pos = ((Component)local).transform.position;
			local.KillPlayer(Vector3.zero, true, (CauseOfDeath)8, 0, default(Vector3), false);
			if (!local.isPlayerDead)
			{
				return;
			}
			int seed = Random.Range(1, int.MaxValue);
			int player = (int)local.playerClientId;
			if (PizzaNet.IsServer)
			{
				HostSquash(player, pos, seed);
				return;
			}
			PizzaNet.ToServer(PizzaNet.Build(4, delegate(BinaryWriter w)
			{
				w.Write(pos.x);
				w.Write(pos.y);
				w.Write(pos.z);
				w.Write(seed);
			}));
		}

		private void HostSquash(int player, Vector3 pos, int seed)
		{
			//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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			PizzaNet.ToClients(PizzaNet.Build(5, delegate(BinaryWriter w)
			{
				w.Write(player);
				w.Write(pos.x);
				w.Write(pos.y);
				w.Write(pos.z);
				w.Write(seed);
			}));
			DoSquash(player, pos, seed);
		}

		private void DoSquash(int player, Vector3 pos, int seed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Blood.Splatter(pos, seed);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Blood splatter failed: " + ex.Message));
			}
			((MonoBehaviour)this).StartCoroutine(BloodyCorpse(player));
		}

		private IEnumerator BloodyCorpse(int player)
		{
			float start = Now;
			PlayerControllerB p = null;
			while (Now - start < 4f)
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					yield break;
				}
				if (player >= 0 && player < instance.allPlayerScripts.Length)
				{
					p = instance.allPlayerScripts[player];
				}
				if ((Object)(object)p != (Object)null && (Object)(object)p.deadBody != (Object)null)
				{
					break;
				}
				yield return null;
			}
			if ((Object)(object)p == (Object)null || (Object)(object)p.deadBody == (Object)null)
			{
				yield break;
			}
			try
			{
				p.deadBody.MakeCorpseBloody();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not bloody the corpse: " + ex.Message));
			}
		}

		private static bool PickTeleport(PlayerControllerB player, out Vector3 position, out bool inside)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			inside = false;
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			bool value = PizzaConfig.TeleportAnywhere.Value;
			List<KeyValuePair<Vector3, bool>> list = new List<KeyValuePair<Vector3, bool>>();
			if (instance.insideAINodes != null && (value || player.isInsideFactory))
			{
				GameObject[] insideAINodes = instance.insideAINodes;
				foreach (GameObject val in insideAINodes)
				{
					if ((Object)(object)val != (Object)null)
					{
						list.Add(new KeyValuePair<Vector3, bool>(val.transform.position, value: true));
					}
				}
			}
			if (instance.outsideAINodes != null && (value || !player.isInsideFactory))
			{
				GameObject[] insideAINodes = instance.outsideAINodes;
				foreach (GameObject val2 in insideAINodes)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						list.Add(new KeyValuePair<Vector3, bool>(val2.transform.position, value: false));
					}
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			KeyValuePair<Vector3, bool> keyValuePair = list[Random.Range(0, list.Count)];
			Vector3 key = keyValuePair.Key;
			try
			{
				key = instance.GetRandomNavMeshPositionInRadius(keyValuePair.Key, 8f, default(NavMeshHit));
			}
			catch
			{
				key = keyValuePair.Key;
			}
			position = key;
			inside = keyValuePair.Value;
			return true;
		}

		private static void DoTeleport(PlayerControllerB p, Vector3 position, bool inside, bool isLocal)
		{
			//IL_00cf: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AudioReverbPresets val = Object.FindObjectOfType<AudioReverbPresets>();
				if ((Object)(object)val != (Object)null && val.audioPresets != null)
				{
					int num = (inside ? 2 : (-1));
					EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>();
					foreach (EntranceTeleport val2 in array)
					{
						if ((Object)(object)val2 != (Object)null && val2.isEntranceToBuilding == inside && val2.audioReverbPreset >= 0)
						{
							num = val2.audioReverbPreset;
							break;
						}
					}
					if (num >= 0 && num < val.audioPresets.Length && (Object)(object)val.audioPresets[num] != (Object)null)
					{
						val.audioPresets[num].ChangeAudioReverbForPlayer(p);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Reverb change skipped: " + ex.Message));
			}
			p.isInElevator = false;
			p.isInHangarShipRoom = false;
			p.isInsideFactory = inside;
			p.averageVelocity = 0f;
			p.velocityLastFrame = Vector3.zero;
			p.TeleportPlayer(position, false, 0f, false, true);
			if ((Object)(object)p.beamOutParticle != (Object)null)
			{
				p.beamOutParticle.Play();
			}
			if (isLocal && (Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
		}

		private EnemyType GetMaskedType()
		{
			if ((Object)(object)_maskedType != (Object)null)
			{
				return _maskedType;
			}
			EnemyType[] array = Resources.FindObjectsOfTypeAll<EnemyType>();
			foreach (EnemyType val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.enemyPrefab != (Object)null && (Object)(object)val.enemyPrefab.GetComponent<MaskedPlayerEnemy>() != (Object)null)
				{
					_maskedType = val;
					break;
				}
			}
			return _maskedType;
		}

		private IEnumerator HostSpawnMimic(PlayerControllerB p, int index, bool inFactory, int maskType, Vector3 position, float yaw)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			float start = Now;
			while ((Object)(object)p != (Object)null && !p.isPlayerDead && Now - start < 3f)
			{
				yield return null;
			}
			StartOfRound instance = StartOfRound.Instance;
			RoundManager instance2 = RoundManager.Instance;
			if ((Object)(object)p == (Object)null || !p.isPlayerDead || (Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || instance.inShipPhase)
			{
				Plugin.Log.LogInfo((object)"Mimic not spawned (the player did not die or the round ended).");
				yield break;
			}
			EnemyType maskedType = GetMaskedType();
			if ((Object)(object)maskedType == (Object)null)
			{
				yield break;
			}
			Vector3 navMeshPosition = instance2.GetNavMeshPosition(position, default(NavMeshHit), 10f, -1);
			if (!instance2.GotNavMeshPositionResult)
			{
				Plugin.Log.LogInfo((object)"Mimic not spawned (no walkable ground near the player).");
				yield break;
			}
			NetworkObjectReference val = instance2.SpawnEnemyGameObject(navMeshPosition, yaw, -1, maskedType);
			NetworkObject val2 = default(NetworkObject);
			if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null) && !((Object)(object)val2 == (Object)null))
			{
				ulong id = val2.NetworkObjectId;
				PizzaNet.ToClients(PizzaNet.Build(3, delegate(BinaryWriter w)
				{
					w.Write(id);
					w.Write(index);
					w.Write(inFactory);
					w.Write(maskType);
				}));
				((MonoBehaviour)this).StartCoroutine(LinkMimic(id, index, inFactory, maskType));
			}
		}

		private IEnumerator LinkMimic(ulong enemyId, int index, bool inFactory, int maskType)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || index < 0 || index >= instance.allPlayerScripts.Length)
			{
				yield break;
			}
			PlayerControllerB p = instance.allPlayerScripts[index];
			if ((Object)(object)p == (Object)null)
			{
				yield break;
			}
			NetworkObject enemy = null;
			float start = Now;
			while (Now - start < 20f)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null)
				{
					yield break;
				}
				if (singleton.SpawnManager.SpawnedObjects.TryGetValue(enemyId, out enemy) && (Object)(object)enemy != (Object)null)
				{
					break;
				}
				yield return null;
			}
			start = Now;
			while ((Object)(object)p != (Object)null && (Object)(object)p.deadBody == (Object)null && Now - start < 20f)
			{
				yield return null;
			}
			if ((Object)(object)p == (Object)null)
			{
				yield break;
			}
			try
			{
				if ((Object)(object)p.deadBody != (Object)null)
				{
					p.deadBody.DeactivateBody(false);
				}
				if ((Object)(object)enemy != (Object)null)
				{
					MaskedPlayerEnemy component = ((Component)enemy).GetComponent<MaskedPlayerEnemy>();
					if ((Object)(object)component != (Object)null)
					{
						component.mimickingPlayer = p;
						component.SetSuit(p.currentSuitID);
						((EnemyAI)component).SetEnemyOutside(!inFactory);
						component.SetVisibilityOfMaskedEnemy();
						component.SetMaskType(maskType);
						p.redirectToEnemy = (EnemyAI)(object)component;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not finish the mimic: " + ex.Message));
			}
		}

		private IEnumerator HostAssignValue(GrabbableObject item)
		{
			yield return (object)new WaitForSeconds(1.5f);
			if ((Object)(object)item == (Object)null || item.scrapValue != 0)
			{
				yield break;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.spawnedScrapContainer != (Object)null && (Object)(object)((Component)item).transform.parent == (Object)(object)instance.spawnedScrapContainer)
			{
				yield return (object)new WaitForSeconds(14f);
				if ((Object)(object)item == (Object)null || item.scrapValue != 0)
				{
					yield break;
				}
			}
			if ((Object)(object)((NetworkBehaviour)item).NetworkObject == (Object)null || !((NetworkBehaviour)item).NetworkObject.IsSpawned)
			{
				yield break;
			}
			int value = PizzaConfig.MinValue.Value;
			int num = Mathf.Max(PizzaConfig.MinValue.Value, PizzaConfig.MaxValue.Value);
			int value2 = Random.Range(value, num + 1);
			if (value2 > 0)
			{
				ulong id = ((NetworkBehaviour)item).NetworkObjectId;
				item.SetScrapValue(value2);
				PizzaNet.ToClients(PizzaNet.Build(6, delegate(BinaryWriter w)
				{
					w.Write(id);
					w.Write(value2);
				}));
			}
		}

		private static void ApplyValue(ulong itemId, int value)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(itemId, out var value2) && !((Object)(object)value2 == (Object)null))
			{
				GrabbableObject component = ((Component)value2).GetComponent<GrabbableObject>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.itemProperties == (Object)(object)PizzaAssets.ItemDef)
				{
					component.SetScrapValue(value);
				}
			}
		}

		public void LocalPlayerUpdated(PlayerControllerB p)
		{
			if (_states.TryGetValue((int)p.playerClientId, out var value) && value.Active)
			{
				if (value.StaminaUntil > 0f)
				{
					p.sprintMeter = 1f;
					p.isExhausted = false;
				}
				if (value.DoubleJump && value.AirJumpUsed && (Object)(object)p.thisController != (Object)null && p.thisController.isGrounded)
				{
					value.AirJumpUsed = false;
				}
			}
		}

		public void TryAirJump(PlayerControllerB p)
		{
			if (!_states.TryGetValue((int)p.playerClientId, out var value) || !value.DoubleJump || value.AirJumpUsed || p.isPlayerDead || !p.isPlayerControlled || (Object)(object)p.thisController == (Object)null || p.thisController.isGrounded || p.inSpecialInteractAnimation || p.isTypingChat || p.isClimbingLadder || p.inTerminalMenu || ((Object)(object)p.quickMenuManager != (Object)null && p.quickMenuManager.isMenuOpen))
			{
				return;
			}
			value.AirJumpUsed = true;
			p.fallValue = p.jumpForce;
			p.fallValueUncapped = p.jumpForce;
			try
			{
				p.PlayJumpAudio();
			}
			catch
			{
			}
		}

		public static void PlayOnPlayer(PlayerControllerB p, AudioClip clip)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)clip == (Object)null || (Object)(object)p == (Object)null)
			{
				return;
			}
			float value = PizzaConfig.SoundVolume.Value;
			if (!(value <= 0f))
			{
				if ((Object)(object)p.movementAudio != (Object)null)
				{
					p.movementAudio.PlayOneShot(clip, value);
				}
				else
				{
					PlayAt(((Component)p).transform.position, clip, value);
				}
			}
		}

		public static void PlayAt(Vector3 position, AudioClip clip, float volume)
		{
			//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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			if (!((Object)(object)clip == (Object)null) && !(volume <= 0f))
			{
				GameObject val = new GameObject("PoisonMysteryPizzaSound");
				val.transform.position = position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = clip;
				val2.volume = Mathf.Clamp01(volume);
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.minDistance = 2f;
				val2.maxDistance = 30f;
				val2.dopplerLevel = 0f;
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.localPlayerController != (Object)null && (Object)(object)instance.localPlayerController.movementAudio != (Object)null)
				{
					val2.outputAudioMixerGroup = instance.localPlayerController.movementAudio.outputAudioMixerGroup;
				}
				val2.Play();
				Object.Destroy((Object)val, clip.length + 0.5f);
			}
		}
	}
	internal static class PizzaNet
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnMessage;
		}

		public const string Channel = "PoisonMysteryPizza.v1";

		private const ulong ServerId = 0uL;

		private static CustomMessagingManager _registered;

		public static bool IsServer
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null)
				{
					return singleton.IsServer;
				}
				return false;
			}
		}

		public static void Forget()
		{
			_registered = null;
		}

		public static bool EnsureRegistered()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				return false;
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			if (customMessagingManager == null || customMessagingManager == _registered)
			{
				return false;
			}
			object obj = <>O.<0>__OnMessage;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = OnMessage;
				<>O.<0>__OnMessage = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("PoisonMysteryPizza.v1", (HandleNamedMessageDelegate)obj);
			_registered = customMessagingManager;
			Plugin.Log.LogInfo((object)("Network channel ready (" + (singleton.IsServer ? "host" : "client") + ")."));
			ret