Decompiled source of HotPotato v0.1.0

HotPotato.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using ModMenu;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HotPotato")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+58db367b0fdc1aa52440e843899845b9a675ef69")]
[assembly: AssemblyProduct("HotPotato")]
[assembly: AssemblyTitle("HotPotato")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HotPotato
{
	internal static class DebugTools
	{
		private static readonly Dictionary<SpawnableItemWithRarity, int> BaseRarity = new Dictionary<SpawnableItemWithRarity, int>();

		internal static string NotInGame()
		{
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null))
			{
				if (!val.isPlayerDead)
				{
					if (!((Object)(object)Registry.Prefab == (Object)null))
					{
						return null;
					}
					return "item not built";
				}
				return "you're dead";
			}
			return "not in a game";
		}

		internal static string Spawn()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00e5: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || !Net.IsHost || (Object)(object)Registry.Prefab == (Object)null)
			{
				return null;
			}
			Vector3 val2 = ((Component)val).transform.forward;
			val2.y = 0f;
			val2 = ((((Vector3)(ref val2)).sqrMagnitude < 0.01f) ? Vector3.forward : ((Vector3)(ref val2)).normalized);
			Vector3 val3 = ((Component)val).transform.position + val2 * 2f;
			Vector3 val4 = val3 + Vector3.up * 0.5f;
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(val3 + Vector3.up * 1.5f, Vector3.down, ref val5, 6f, 268437760, (QueryTriggerInteraction)1))
			{
				val4 = ((RaycastHit)(ref val5)).point + Vector3.up * 0.15f;
			}
			GameObject obj = Object.Instantiate<GameObject>(Registry.Prefab, val4, Quaternion.identity);
			obj.GetComponent<NetworkObject>().Spawn(false);
			PotatoItem component = obj.GetComponent<PotatoItem>();
			int num = Random.Range(Mathf.Max(1, Plugin.MinValue.Value), Mathf.Max(Plugin.MinValue.Value, Plugin.MaxValue.Value) + 1);
			((GrabbableObject)component).SetScrapValue(num);
			RoundManager instance = RoundManager.Instance;
			if (instance != null)
			{
				instance.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { NetworkObjectReference.op_Implicit(((NetworkBehaviour)component).NetworkObject) }, new int[1] { num });
			}
			return $"spawned a hot potato (${num})";
		}

		private static PotatoItem Nearest()
		{
			PlayerControllerB me = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)me == (Object)null)
			{
				return null;
			}
			return Net.Potatoes.Where((PotatoItem p) => (Object)(object)p != (Object)null && !p.Gone).OrderBy(delegate(PotatoItem p)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//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_0020: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = ((Component)p).transform.position - ((Component)me).transform.position;
				return ((Vector3)(ref val)).sqrMagnitude;
			}).FirstOrDefault();
		}

		internal static string NoneNear()
		{
			object obj = NotInGame();
			if (obj == null)
			{
				if (!((Object)(object)Nearest() == (Object)null))
				{
					return null;
				}
				obj = "no hot potato around";
			}
			return (string)obj;
		}

		internal static string ShortFuse()
		{
			PotatoItem potatoItem = Nearest();
			if ((Object)(object)potatoItem == (Object)null)
			{
				return null;
			}
			potatoItem.Armed = true;
			potatoItem.Remaining = 5f;
			if (potatoItem.LastHolder == ulong.MaxValue && ((GrabbableObject)potatoItem).isHeld && (Object)(object)((GrabbableObject)potatoItem).playerHeldBy != (Object)null)
			{
				potatoItem.LastHolder = ((GrabbableObject)potatoItem).playerHeldBy.playerClientId;
			}
			Net.SendState(potatoItem, 1);
			return "nearest hot potato: 5 s left";
		}

		internal static string BlowNow()
		{
			PotatoItem potatoItem = Nearest();
			if ((Object)(object)potatoItem == (Object)null)
			{
				return null;
			}
			Net.HostExplode(potatoItem);
			return "nearest hot potato blew";
		}

		internal static string FlashNow()
		{
			PotatoItem potatoItem = Nearest();
			if ((Object)(object)potatoItem == (Object)null)
			{
				return null;
			}
			Net.HostFlash(potatoItem, GameNetworkManager.Instance.localPlayerController.playerClientId);
			return "nearest hot potato flashed";
		}

		internal static void ApplySpawnRate(SelectableLevel level)
		{
			if (level?.spawnableScrap == null || (Object)(object)Registry.Item == (Object)null)
			{
				return;
			}
			foreach (SpawnableItemWithRarity item in level.spawnableScrap)
			{
				if (!((Object)(object)item?.spawnableItem != (Object)(object)Registry.Item))
				{
					if (!BaseRarity.TryGetValue(item, out var value))
					{
						value = (BaseRarity[item] = item.rarity);
					}
					item.rarity = Mathf.RoundToInt((float)value * Mathf.Max(0f, Plugin.SpawnMultiplier.Value));
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class SpawnRatePatch
	{
		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void Prefix(RoundManager __instance)
		{
			try
			{
				DebugTools.ApplySpawnRate(__instance.currentLevel);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("HotPotato: spawn rate: " + ex.Message));
			}
		}
	}
	internal static class Fx
	{
		private static Material _sparkMat;

		private static Material _hotMat;

		private static Material _whiteMat;

		private static Texture2D _dot;

		private static ParticleSystem _blastSparks;

		private static ParticleSystem _blastEmbers;

		private static ParticleSystem _flashSparks;

		private static readonly AnimationCurve Shrink = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 1f),
			new Keyframe(0.6f, 0.7f),
			new Keyframe(1f, 0f)
		});

		private static Material SparkMat => _sparkMat ?? (_sparkMat = Unlit("Spark", new Color(1f, 0.55f, 0.15f) * 2f));

		private static Material HotMat => _hotMat ?? (_hotMat = Unlit("Ember", new Color(1f, 0.3f, 0.05f) * 1.5f));

		private static Material WhiteMat => _whiteMat ?? (_whiteMat = Unlit("White", new Color(0.8f, 0.9f, 1f) * 2.5f));

		private static Texture2D Dot()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_dot != (Object)null)
			{
				return _dot;
			}
			_dot = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				name = "HotPotatoDot",
				wrapMode = (TextureWrapMode)1
			};
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = ((float)j + 0.5f) / 32f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 32f * 2f - 1f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
					num3 = num3 * num3 * (3f - 2f * num3);
					_dot.SetPixel(j, i, new Color(num3, num3, num3, num3));
				}
			}
			_dot.Apply();
			return _dot;
		}

		private static Material Unlit(string name, Color tint)
		{
			//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_002e: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("HDRP/Unlit");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = "HotPotato." + name
			};
			val2.SetFloat("_SurfaceType", 1f);
			val2.SetFloat("_BlendMode", 1f);
			val2.SetFloat("_ZWrite", 0f);
			val2.SetFloat("_CullMode", 0f);
			val2.SetFloat("_CullModeForward", 0f);
			val2.SetFloat("_DoubleSidedEnable", 1f);
			val2.SetColor("_UnlitColor", tint);
			val2.SetTexture("_UnlitColorMap", (Texture)(object)Dot());
			try
			{
				HDMaterial.ValidateMaterial(val2);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("HotPotato: " + name + ": " + ex.Message));
			}
			return val2;
		}

		private static ParticleSystem Make(Transform parent, string name, Material mat, int max, float gravity, float life, float size, bool stretch)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002c: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			if ((Object)(object)parent != (Object)null)
			{
				val.transform.SetParent(parent, false);
			}
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = obj.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).maxParticles = max;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(gravity);
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(life * 0.5f, life);
			((MainModule)(ref main)).startSize = new MinMaxCurve(size * 0.6f, size);
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).enabled = false;
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).enabled = false;
			SizeOverLifetimeModule sizeOverLifetime = obj.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, Shrink);
			LimitVelocityOverLifetimeModule limitVelocityOverLifetime = obj.limitVelocityOverLifetime;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).enabled = true;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit = MinMaxCurve.op_Implicit(100f);
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).drag = MinMaxCurve.op_Implicit(1.2f);
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).multiplyDragByParticleSize = false;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).multiplyDragByParticleVelocity = false;
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = mat;
			((Renderer)component).enabled = (Object)(object)mat != (Object)null;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			if (stretch)
			{
				component.renderMode = (ParticleSystemRenderMode)1;
				component.velocityScale = 0.035f;
				component.lengthScale = 1.5f;
			}
			obj.Play();
			return obj;
		}

		internal static ParticleSystem ItemSparks(Transform item)
		{
			return Make(null, "HotPotato.Sparks." + ((Object)item).GetInstanceID(), SparkMat, 64, 0.6f, 0.45f, 0.018f, stretch: true);
		}

		internal static void Burst(ParticleSystem ps, Vector3 at, int count)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ps == (Object)null))
			{
				for (int i = 0; i < count; i++)
				{
					Vector3 onUnitSphere = Random.onUnitSphere;
					EmitParams val = default(EmitParams);
					((EmitParams)(ref val)).position = at + onUnitSphere * 0.07f;
					((EmitParams)(ref val)).velocity = (onUnitSphere + Vector3.up * 0.4f) * Random.Range(1.2f, 3f);
					((EmitParams)(ref val)).applyShapeToPosition = false;
					EmitParams val2 = val;
					ps.Emit(val2, 1);
				}
			}
		}

		private static ParticleSystem Pool(ref ParticleSystem ps, string name, Material mat, int max, float gravity, float life, float size, bool stretch)
		{
			if ((Object)(object)ps != (Object)null)
			{
				return ps;
			}
			ps = Make(null, name, mat, max, gravity, life, size, stretch);
			Object.DontDestroyOnLoad((Object)(object)((Component)ps).gameObject);
			return ps;
		}

		private static void Spray(ParticleSystem ps, Vector3 at, int count, float speedLo, float speedHi, float up)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < count; i++)
			{
				Vector3 val = Random.onUnitSphere + Vector3.up * up;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				EmitParams val2 = default(EmitParams);
				((EmitParams)(ref val2)).position = at;
				((EmitParams)(ref val2)).velocity = normalized * Random.Range(speedLo, speedHi);
				((EmitParams)(ref val2)).applyShapeToPosition = false;
				ps.Emit(val2, 1);
			}
		}

		internal static void Explosion(Vector3 at)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			StartOfRound instance = StartOfRound.Instance;
			RoundManager instance2 = RoundManager.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.explosionPrefab != (Object)null)
			{
				Transform val = (((Object)(object)instance2 != (Object)null && (Object)(object)instance2.mapPropsContainer != (Object)null) ? instance2.mapPropsContainer.transform : null);
				Object.Instantiate<GameObject>(instance.explosionPrefab, at, Quaternion.Euler(-90f, 0f, 0f), val).SetActive(true);
			}
			Spray(Pool(ref _blastSparks, "HotPotato.BlastSparks", SparkMat, 256, 1f, 1.1f, 0.035f, stretch: true), at + Vector3.up * 0.1f, 120, 5f, 15f, 0.5f);
			Spray(Pool(ref _blastEmbers, "HotPotato.BlastEmbers", HotMat, 96, 0.25f, 2.2f, 0.06f, stretch: false), at + Vector3.up * 0.2f, 40, 1f, 4f, 0.8f);
			FlashLight(at, Registry.GlowColor, 9000f, 14f, 0.6f);
			PlayAt(Registry.Explode, at, 70f, 1f);
			Shake(at, 14f, 30f);
		}

		internal static void Flash(Vector3 at)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_003e: 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)
			if ((Object)(object)Registry.FlashEffect != (Object)null)
			{
				RoundManager instance = RoundManager.Instance;
				Transform val = (((Object)(object)instance != (Object)null && (Object)(object)instance.mapPropsContainer != (Object)null) ? instance.mapPropsContainer.transform : null);
				Object.Instantiate<GameObject>(Registry.FlashEffect, at, Quaternion.identity, val);
			}
			Spray(Pool(ref _flashSparks, "HotPotato.FlashSparks", WhiteMat, 160, 0.8f, 0.8f, 0.03f, stretch: true), at + Vector3.up * 0.1f, 80, 4f, 11f, 0.4f);
			FlashLight(at, new Color(0.85f, 0.92f, 1f), 12000f, 16f, 0.35f);
			PlayAt(Registry.FlashBang, at, 60f, 1f);
			PlayAt(Registry.Handoff, at, 25f, 0.5f);
		}

		private static void FlashLight(Vector3 at, Color c, float lumen, float range, float seconds)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("HotPotato.Flash");
			val.transform.position = at + Vector3.up * 0.4f;
			Light obj = val.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = c;
			obj.range = range;
			obj.shadows = (LightShadows)0;
			HDAdditionalLightData val2 = val.AddComponent<HDAdditionalLightData>();
			val2.SetIntensity(lumen, (LightUnit)0);
			val2.SetRange(range);
			val2.SetColor(c, -1f);
			val2.EnableShadows(false);
			val.AddComponent<FadeLight>().Init(val2, lumen, seconds);
		}

		private static void PlayAt(AudioClip clip, Vector3 at, float range, float volume)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)clip == (Object)null))
			{
				GameObject val = new GameObject("HotPotato.Sound");
				val.transform.position = at;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.minDistance = 4f;
				val2.maxDistance = range;
				val2.dopplerLevel = 0f;
				if ((Object)(object)Registry.Mixer != (Object)null)
				{
					val2.outputAudioMixerGroup = Registry.Mixer;
				}
				val2.PlayOneShot(clip, Mathf.Clamp01(Plugin.Volume.Value) * volume);
				Object.Destroy((Object)val, clip.length + 0.2f);
				WalkieTalkie.TransmitOneShotAudio(val2, clip, volume);
				RoundManager instance = RoundManager.Instance;
				if (instance != null)
				{
					instance.PlayAudibleNoise(at, range * 0.4f, 0.9f, 0, false, 0);
				}
			}
		}

		private static void Shake(Vector3 at, float big, float small)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null) && !((Object)(object)HUDManager.Instance == (Object)null))
			{
				float num = Vector3.Distance(((Component)val).transform.position, at);
				if (num < big)
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
				}
				else if (num < small)
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				}
			}
		}
	}
	internal class FadeLight : MonoBehaviour
	{
		private HDAdditionalLightData _hd;

		private float _lumen;

		private float _len;

		private float _t;

		internal void Init(HDAdditionalLightData hd, float lumen, float seconds)
		{
			_hd = hd;
			_lumen = lumen;
			_len = Mathf.Max(0.05f, seconds);
		}

		private void Update()
		{
			_t += Time.deltaTime;
			float num = 1f - _t / _len;
			if (num <= 0f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				_hd.SetIntensity(_lumen * num * num, (LightUnit)0);
			}
		}
	}
	internal static class MenuHooks
	{
		internal const string ModMenuGuid = "daniel.lethalcompany.modmenu";

		private const string Tab = "Hot Potato";

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.MonsterFlash, "Monster flash", true, "thrown at a monster it stuns instead", (Func<string>)null);
			MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.Lethal, "Blast can kill", true, (string)null, (Func<string>)null);
			MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.PauseInShip, "Pause in ship", true, (string)null, (Func<string>)null);
			MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.SpawnMultiplier, "Spawn rate", true, "x the moon weights, next landing", (Func<string>)null);
			MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.Volume, "Volume", false, (string)null, (Func<string>)null);
			MenuApi.Button("Hot Potato", "Spawn hot potato", (Func<string>)DebugTools.Spawn, true, true, (Func<string>)DebugTools.NotInGame, (string)null);
			MenuApi.Button("Hot Potato", "Nearest: 5 s left", (Func<string>)DebugTools.ShortFuse, true, true, (Func<string>)DebugTools.NoneNear, (string)null);
			MenuApi.Button("Hot Potato", "Nearest: blow now", (Func<string>)DebugTools.BlowNow, true, true, (Func<string>)DebugTools.NoneNear, (string)null);
			MenuApi.Button("Hot Potato", "Nearest: monster flash", (Func<string>)DebugTools.FlashNow, true, true, (Func<string>)DebugTools.NoneNear, (string)null);
			MenuApi.Tuning((Action)delegate
			{
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.FuseMin, "Fuse min (s)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.FuseMax, "Fuse max (s)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.HandoffSeconds, "Handoff bonus (s)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.FuseCap, "Fuse cap (s)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.HandoffValuePercent, "Handoff value %", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.ValueCap, "Value cap (x)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.ExplosionDamage, "Blast damage", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.ExplosionRadius, "Blast radius (m)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.MonsterRange, "Monster hit range (m)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.StunSeconds, "Stun (s)", true, (string)null, (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.MinValue, "Min value", true, "restart", (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.MaxValue, "Max value", true, "restart", (Func<string>)null);
				MenuApi.Setting("Hot Potato", (ConfigEntryBase)(object)Plugin.SpawnRarity, "Spawn rarity", true, "restart", (Func<string>)null);
			});
		}
	}
	internal static class Net
	{
		internal struct Boom
		{
			public Vector3 Pos;

			public int Damage;

			public float Radius;

			public bool Lethal;

			public void Write(FastBufferWriter w)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe(ref Pos);
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref Damage, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref Radius, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref Lethal, default(ForPrimitives));
			}

			public static Boom Read(FastBufferReader r)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				Boom result = default(Boom);
				((FastBufferReader)(ref r)).ReadValueSafe(ref result.Pos);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref result.Damage, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<float>(ref result.Radius, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref result.Lethal, default(ForPrimitives));
				return result;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnThrown;

			public static HandleNamedMessageDelegate <1>__OnState;

			public static HandleNamedMessageDelegate <2>__OnBoom;

			public static HandleNamedMessageDelegate <3>__OnFlash;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static HandleNamedMessageDelegate <>9__18_0;

			internal void <Register>b__18_0(ulong sender, FastBufferReader r)
			{
				foreach (PotatoItem value in Live.Values)
				{
					SendState(value, 0, sender);
				}
			}
		}

		private const string MsgState = "DanielLC.HotPotato.State";

		private const string MsgBoom = "DanielLC.HotPotato.Boom";

		private const string MsgFlash = "DanielLC.HotPotato.Flash";

		private const string MsgThrown = "DanielLC.HotPotato.Thrown";

		private const string MsgHello = "DanielLC.HotPotato.Hello";

		private static readonly string[] All = new string[5] { "DanielLC.HotPotato.State", "DanielLC.HotPotato.Boom", "DanielLC.HotPotato.Flash", "DanielLC.HotPotato.Thrown", "DanielLC.HotPotato.Hello" };

		internal const byte EvArmed = 1;

		internal const byte EvHandoff = 2;

		internal const byte EvPause = 4;

		private static readonly Dictionary<ulong, PotatoItem> Live = new Dictionary<ulong, PotatoItem>();

		private static readonly Dictionary<ulong, (bool, bool, float, int, ulong)> Pending = new Dictionary<ulong, (bool, bool, float, int, ulong)>();

		private static bool _registered;

		private static readonly Collider[] Hits = (Collider[])(object)new Collider[32];

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

		internal static IEnumerable<PotatoItem> Potatoes => Live.Values;

		internal static void Track(PotatoItem p)
		{
			if (!((Object)(object)((NetworkBehaviour)p).NetworkObject == (Object)null))
			{
				Live[((NetworkBehaviour)p).NetworkObjectId] = p;
				if (Pending.TryGetValue(((NetworkBehaviour)p).NetworkObjectId, out var value))
				{
					Pending.Remove(((NetworkBehaviour)p).NetworkObjectId);
					p.ApplyState(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, 0);
				}
			}
		}

		internal static void Untrack(PotatoItem p)
		{
			foreach (KeyValuePair<ulong, PotatoItem> item in Live)
			{
				if ((Object)(object)item.Value == (Object)(object)p)
				{
					Live.Remove(item.Key);
					break;
				}
			}
		}

		public static void Register()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00e2: 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_00ed: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (_registered || (Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			if (singleton.IsServer)
			{
				object obj = <>O.<0>__OnThrown;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnThrown;
					<>O.<0>__OnThrown = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.HotPotato.Thrown", (HandleNamedMessageDelegate)obj);
				object obj2 = <>c.<>9__18_0;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = delegate(ulong sender, FastBufferReader r)
					{
						foreach (PotatoItem value in Live.Values)
						{
							SendState(value, 0, sender);
						}
					};
					<>c.<>9__18_0 = val2;
					obj2 = (object)val2;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.HotPotato.Hello", (HandleNamedMessageDelegate)obj2);
			}
			else
			{
				object obj3 = <>O.<1>__OnState;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnState;
					<>O.<1>__OnState = val3;
					obj3 = (object)val3;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.HotPotato.State", (HandleNamedMessageDelegate)obj3);
				object obj4 = <>O.<2>__OnBoom;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnBoom;
					<>O.<2>__OnBoom = val4;
					obj4 = (object)val4;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.HotPotato.Boom", (HandleNamedMessageDelegate)obj4);
				object obj5 = <>O.<3>__OnFlash;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val5 = OnFlash;
					<>O.<3>__OnFlash = val5;
					obj5 = (object)val5;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.HotPotato.Flash", (HandleNamedMessageDelegate)obj5);
				Send("DanielLC.HotPotato.Hello", 0uL, null);
			}
			_registered = true;
		}

		public static void Unregister()
		{
			CustomMessagingManager val = (((Object)(object)NetworkManager.Singleton != (Object)null) ? NetworkManager.Singleton.CustomMessagingManager : null);
			if (val != null)
			{
				string[] all = All;
				foreach (string text in all)
				{
					try
					{
						val.UnregisterNamedMessageHandler(text);
					}
					catch (Exception)
					{
					}
				}
			}
			_registered = false;
			Pending.Clear();
			Live.Clear();
		}

		internal static void SendState(PotatoItem p, byte events, ulong? only = null)
		{
			if (IsHost && !((Object)(object)p == (Object)null) && !((Object)(object)((NetworkBehaviour)p).NetworkObject == (Object)null) && ((NetworkBehaviour)p).NetworkObject.IsSpawned)
			{
				p.ApplyState(p.Armed, p.Paused, p.Remaining, p.Handoffs, p.LastHolder, events);
				Action<FastBufferWriter> write = delegate(FastBufferWriter w)
				{
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_002d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: Unknown result type (might be due to invalid IL or missing references)
					//IL_004e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0063: Unknown result type (might be due to invalid IL or missing references)
					//IL_0069: Unknown result type (might be due to invalid IL or missing references)
					//IL_007e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0084: 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_009f: Unknown result type (might be due to invalid IL or missing references)
					//IL_00af: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
					ulong networkObjectId = ((NetworkBehaviour)p).NetworkObjectId;
					((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref p.Armed, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref p.Paused, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref p.Remaining, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref p.Handoffs, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref p.LastHolder, default(ForPrimitives));
					((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref events, default(ForPrimitives));
				};
				if (only.HasValue)
				{
					Send("DanielLC.HotPotato.State", only.Value, write);
				}
				else
				{
					SendAll("DanielLC.HotPotato.State", write);
				}
			}
		}

		internal static void HostExplode(PotatoItem p)
		{
			//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_0086: Unknown result type (might be due to invalid IL or missing references)
			Boom b = new Boom
			{
				Pos = ((Component)p).transform.position,
				Damage = Mathf.Max(0, Plugin.ExplosionDamage.Value),
				Radius = Mathf.Max(0.5f, Plugin.ExplosionRadius.Value),
				Lethal = Plugin.Lethal.Value
			};
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			Plugin.Log.LogInfo((object)$"HotPotato: fuse ran out at {b.Pos} after {p.Handoffs} handoffs.");
			SendAll("DanielLC.HotPotato.Boom", delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				b.Write(w);
			});
			DoBoom(p, b);
		}

		internal static void HostFlash(PotatoItem p, ulong thrower)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 pos = ((Component)p).transform.position;
			float stun = Mathf.Max(0f, Plugin.StunSeconds.Value);
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			Plugin.Log.LogInfo((object)$"HotPotato: thrown into a monster at {pos}: stun flash.");
			SendAll("DanielLC.HotPotato.Flash", delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe(ref pos);
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref stun, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref thrower, default(ForPrimitives));
			});
			DoFlash(p, pos, stun, thrower);
		}

		internal static void SendThrown(PotatoItem p, PlayerControllerB by)
		{
			if (IsHost)
			{
				p.HostThrown(by.playerClientId);
				return;
			}
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			ulong who = by.playerClientId;
			Send("DanielLC.HotPotato.Thrown", 0uL, delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: 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)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref who, default(ForPrimitives));
			});
		}

		private static void OnThrown(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			ulong byClient = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref byClient, default(ForPrimitives));
			if (Live.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				value.HostThrown(byClient);
			}
		}

		private static void OnState(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			bool flag = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			bool flag2 = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
			float num = default(float);
			((FastBufferReader)(ref r)).ReadValueSafe<float>(ref num, default(ForPrimitives));
			int num2 = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			ulong num3 = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref num3, default(ForPrimitives));
			byte events = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref events, default(ForPrimitives));
			if (Live.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				value.ApplyState(flag, flag2, num, num2, num3, events);
			}
			else
			{
				Pending[key] = (flag, flag2, num, num2, num3);
			}
		}

		private static void OnBoom(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			Boom b = Boom.Read(r);
			Live.TryGetValue(key, out var value);
			DoBoom(value, b);
		}

		private static void OnFlash(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			Vector3 pos = default(Vector3);
			((FastBufferReader)(ref r)).ReadValueSafe(ref pos);
			float stun = default(float);
			((FastBufferReader)(ref r)).ReadValueSafe<float>(ref stun, default(ForPrimitives));
			ulong thrower = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref thrower, default(ForPrimitives));
			Live.TryGetValue(key, out var value);
			DoFlash(value, pos, stun, thrower);
		}

		private static void DoBoom(PotatoItem p, Boom b)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)p != (Object)null)
			{
				p.Vanish();
			}
			try
			{
				Fx.Explosion(b.Pos);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("HotPotato: blast effect: " + ex.Message));
			}
			HurtLocalPlayer(b);
			HurtOwnedEnemies(b);
		}

		private static void HurtLocalPlayer(Boom b)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || val.isPlayerDead || (b.Damage <= 0 && !b.Lethal))
			{
				return;
			}
			Vector3 val2 = ((Component)val).transform.position + Vector3.up * 1f;
			float num = Vector3.Distance(val2, b.Pos);
			if (num > b.Radius || Physics.Linecast(b.Pos + Vector3.up * 0.2f, val2, 256, (QueryTriggerInteraction)1))
			{
				return;
			}
			Vector3 val3 = val2 - b.Pos;
			Vector3 val4 = ((Vector3)(ref val3)).normalized * 30f / Mathf.Max(1f, num);
			if (b.Lethal && num < 1f)
			{
				val3 = default(Vector3);
				val.KillPlayer(val4, true, (CauseOfDeath)3, 0, val3, false);
				return;
			}
			int num2 = Mathf.RoundToInt(Mathf.Lerp((float)b.Damage, (float)b.Damage * 0.5f, num / b.Radius));
			if (!b.Lethal)
			{
				num2 = Mathf.Min(num2, val.health - 1);
			}
			if (num2 > 0)
			{
				val.DamagePlayer(num2, true, true, (CauseOfDeath)3, 0, false, val4);
			}
		}

		private static void HurtOwnedEnemies(Boom b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(b.Pos, b.Radius, Hits, 524288, (QueryTriggerInteraction)2);
			HashSet<EnemyAI> hashSet = new HashSet<EnemyAI>();
			for (int i = 0; i < num; i++)
			{
				EnemyAICollisionDetect componentInChildren = ((Component)Hits[i]).GetComponentInChildren<EnemyAICollisionDetect>();
				EnemyAI val = (((Object)(object)componentInChildren != (Object)null) ? componentInChildren.mainScript : null);
				if ((Object)(object)val == (Object)null || val.isEnemyDead || !((NetworkBehaviour)val).IsOwner || !hashSet.Add(val))
				{
					continue;
				}
				float num2 = Vector3.Distance(b.Pos, ((Component)val).transform.position);
				if (!Physics.Linecast(b.Pos + Vector3.up * 0.2f, ((Component)val).transform.position + Vector3.up * 0.5f, 256, (QueryTriggerInteraction)1))
				{
					try
					{
						val.HitEnemyOnLocalClient((!(num2 < b.Radius * 0.5f)) ? 1 : 3, default(Vector3), (PlayerControllerB)null, false, -1);
						val.HitFromExplosion(num2);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("HotPotato: hitting " + val.enemyType?.enemyName + ": " + ex.Message));
					}
				}
			}
		}

		private static void DoFlash(PotatoItem p, Vector3 pos, float stun, ulong thrower)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)p != (Object)null)
			{
				p.Vanish();
			}
			PlayerControllerB val = null;
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if ((Object)(object)val2 != (Object)null && val2.playerClientId == thrower)
					{
						val = val2;
						break;
					}
				}
			}
			try
			{
				Fx.Flash(pos);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("HotPotato: flash effect: " + ex.Message));
			}
			try
			{
				StunGrenadeItem.StunExplosion(pos, true, 1f, stun, 1f, false, (PlayerControllerB)null, val, 0f);
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("HotPotato: stun flash: " + ex2.Message));
			}
		}

		private static void Send(string msg, ulong to, Action<FastBufferWriter> write)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, 4096);
			try
			{
				write?.Invoke(val);
				singleton.CustomMessagingManager.SendNamedMessage(msg, to, val, (NetworkDelivery)3);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void SendAll(string msg, Action<FastBufferWriter> write)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || !singleton.IsServer)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, 4096);
			try
			{
				write(val);
				foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
				{
					if (connectedClientsId != 0L)
					{
						singleton.CustomMessagingManager.SendNamedMessage(msg, connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}
	}
	[HarmonyPatch]
	internal static class NetPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void StartOfRoundStart()
		{
			Net.Register();
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPrefix]
		private static void StartOfRoundDestroy()
		{
			Net.Unregister();
		}
	}
	public static class PluginInfo
	{
		public const string Guid = "daniel.lethalcompany.hotpotato";

		public const string Name = "Hot Potato";

		public const string Version = "0.1.0";
	}
	[BepInPlugin("daniel.lethalcompany.hotpotato", "Hot Potato", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<string> SpawnRarity;

		internal static ConfigEntry<float> SpawnMultiplier;

		internal static ConfigEntry<int> MinValue;

		internal static ConfigEntry<int> MaxValue;

		internal static ConfigEntry<float> FuseMin;

		internal static ConfigEntry<float> FuseMax;

		internal static ConfigEntry<float> HandoffSeconds;

		internal static ConfigEntry<float> FuseCap;

		internal static ConfigEntry<int> HandoffValuePercent;

		internal static ConfigEntry<float> ValueCap;

		internal static ConfigEntry<bool> PauseInShip;

		internal static ConfigEntry<int> ExplosionDamage;

		internal static ConfigEntry<float> ExplosionRadius;

		internal static ConfigEntry<bool> Lethal;

		internal static ConfigEntry<bool> MonsterFlash;

		internal static ConfigEntry<float> MonsterRange;

		internal static ConfigEntry<float> StunSeconds;

		internal static ConfigEntry<float> Volume;

		private readonly Harmony _harmony = new Harmony("daniel.lethalcompany.hotpotato");

		private void Awake()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			SpawnRarity = ((BaseUnityPlugin)this).Config.Bind<string>("Spawning (host)", "Spawn rarity", "Experimentation:10,Assurance:14,Vow:14,Offense:16,March:14,Adamance:16,Rend:20,Dine:20,Titan:22,Artifice:22,Embrion:18,Modded:14", "Moon:weight pairs (vanilla names, Modded, or a modded moon's name). Bigger is more common; most vanilla scrap sits between 5 and 60. Restart to apply.");
			SpawnMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning (host)", "Spawn rate", 1f, new ConfigDescription("Multiplies every Spawn rarity weight, live (takes effect on the next landing). 0 stops it spawning as scrap.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			MinValue = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning (host)", "Min value", 75, "Lowest sell value in credits, as found (before handoff bonuses). Restart to apply.");
			MaxValue = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning (host)", "Max value", 130, "Highest sell value in credits, as found. Restart to apply.");
			FuseMin = ((BaseUnityPlugin)this).Config.Bind<float>("Fuse (host)", "Fuse min seconds", 15f, "The hidden fuse is a random length between min and max, set on the first grab.");
			FuseMax = ((BaseUnityPlugin)this).Config.Bind<float>("Fuse (host)", "Fuse max seconds", 30f, "See Fuse min seconds.");
			HandoffSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Fuse (host)", "Handoff bonus seconds", 5f, "Seconds added each time a different player takes it.");
			FuseCap = ((BaseUnityPlugin)this).Config.Bind<float>("Fuse (host)", "Fuse cap seconds", 30f, "Handoffs never push the time left above this.");
			HandoffValuePercent = ((BaseUnityPlugin)this).Config.Bind<int>("Fuse (host)", "Handoff value percent", 15, "Sell value added per handoff, as a percent of its found value.");
			ValueCap = ((BaseUnityPlugin)this).Config.Bind<float>("Fuse (host)", "Value cap", 2f, "Handoffs never raise the value above this multiple of its found value.");
			PauseInShip = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuse (host)", "Pause in ship", true, "The fuse holds while the core sits in the ship (not in a hand) or on the Company counter, and in orbit.");
			ExplosionDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Explosion (host)", "Damage", 45, "Damage to a player at the core; half that at the edge of the radius.");
			ExplosionRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Explosion (host)", "Radius", 5f, "Metres. Walls block it.");
			Lethal = ((BaseUnityPlugin)this).Config.Bind<bool>("Explosion (host)", "Can kill", false, "Off: the blast never takes a player below 1 health. On: it can kill, and anyone within a metre dies.");
			MonsterFlash = ((BaseUnityPlugin)this).Config.Bind<bool>("Monster flash (host)", "Enabled", true, "Thrown at a monster, the core goes off as a stun flash instead (and is gone).");
			MonsterRange = ((BaseUnityPlugin)this).Config.Bind<float>("Monster flash (host)", "Hit range", 2.5f, "Metres from a monster that counts as a hit while it flies or where it lands.");
			StunSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Monster flash (host)", "Stun seconds", 5f, "How long the flash stuns monsters.");
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Local", "Volume", 1f, "Beep and blast volume for you (0-1).");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Registry.Load();
			if (Chainloader.PluginInfos.ContainsKey("daniel.lethalcompany.modmenu"))
			{
				try
				{
					MenuHooks.Register();
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("HotPotato: no F6 tab (needs ModMenu 0.3.6 or newer): " + ex.GetType().Name));
				}
			}
			Log.LogInfo((object)"Hot Potato 0.1.0 loaded.");
		}
	}
	public class PotatoItem : GrabbableObject
	{
		internal bool Armed;

		internal bool Paused;

		internal float Remaining;

		internal int Handoffs;

		internal ulong LastHolder = ulong.MaxValue;

		internal bool Gone;

		private int _baseValue;

		private float _resyncTimer;

		private bool _thrown;

		private float _thrownAt;

		private ulong _thrownBy;

		private bool _loadedFromSave;

		private AudioSource _audio;

		private Material _coreMat;

		private Color _coreEmissive;

		private HDAdditionalLightData _light;

		private ParticleSystem _sparks;

		private float _beepTimer;

		private float _pulse;

		private static readonly Collider[] Hits = (Collider[])(object)new Collider[16];

		public override void Start()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Start();
			_audio = ((Component)this).GetComponent<AudioSource>();
			MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				if (((Object)val).name == "Core")
				{
					_coreMat = ((Renderer)val).material;
					break;
				}
			}
			if ((Object)(object)_coreMat != (Object)null)
			{
				_coreEmissive = (_coreMat.HasProperty("_EmissiveColor") ? (_coreMat.GetColor("_EmissiveColor") / 6f) : Registry.GlowColor);
			}
			_light = ((Component)this).GetComponentInChildren<HDAdditionalLightData>(true);
			_sparks = Fx.ItemSparks(((Component)this).transform);
			Net.Track(this);
		}

		public override void OnDestroy()
		{
			Net.Untrack(this);
			if ((Object)(object)_sparks != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_sparks).gameObject);
			}
			((GrabbableObject)this).OnDestroy();
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && ((NetworkBehaviour)this).IsOwner && !((Object)(object)base.playerHeldBy == (Object)null) && !Gone)
			{
				Vector3 val = ThrowDestination(base.playerHeldBy);
				Net.SendThrown(this, base.playerHeldBy);
				base.playerHeldBy.DiscardHeldObject(true, (NetworkObject)null, val, true);
			}
		}

		private static Vector3 ThrowDestination(PlayerControllerB p)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)p.gameplayCamera).transform.position, ((Component)p.gameplayCamera).transform.forward);
			RaycastHit val3 = default(RaycastHit);
			Vector3 val2 = (Physics.Raycast(val, ref val3, 12f, 268437761, (QueryTriggerInteraction)1) ? ((Ray)(ref val)).GetPoint(((RaycastHit)(ref val3)).distance - 0.05f) : ((Ray)(ref val)).GetPoint(10f));
			Ray val4 = default(Ray);
			((Ray)(ref val4))..ctor(val2, Vector3.down);
			if (!Physics.Raycast(val4, ref val3, 30f, 268437761, (QueryTriggerInteraction)1))
			{
				return ((Ray)(ref val4)).GetPoint(30f);
			}
			return ((RaycastHit)(ref val3)).point + Vector3.up * 0.05f;
		}

		public override void FallWithCurve()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = base.startFallingPosition - base.targetFloorPosition;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (Registry.FallCurve == null || magnitude < 1.2f)
			{
				((GrabbableObject)this).FallWithCurve();
				return;
			}
			((Component)this).transform.rotation = Quaternion.Lerp(((Component)this).transform.rotation, Quaternion.Euler(base.itemProperties.restingRotation.x, ((Component)this).transform.eulerAngles.y, base.itemProperties.restingRotation.z), 14f * Time.deltaTime / magnitude);
			Vector3 localPosition = Vector3.Lerp(base.startFallingPosition, base.targetFloorPosition, Registry.FallCurve.Evaluate(base.fallTime));
			AnimationCurve val2 = ((magnitude > 5f) ? Registry.VerticalCurveNoBounce : Registry.VerticalCurve);
			localPosition.y = Mathf.Lerp(base.startFallingPosition.y, base.targetFloorPosition.y, val2.Evaluate(base.fallTime));
			((Component)this).transform.localPosition = localPosition;
			base.fallTime += Mathf.Abs(Time.deltaTime * 12f / magnitude);
		}

		public override int GetItemDataToSave()
		{
			int num = Mathf.Clamp(Mathf.RoundToInt(Remaining * 10f), 0, 4095);
			return (int)((Armed ? 1u : 0u) | (uint)(Mathf.Clamp(Handoffs, 0, 255) << 1)) | (num << 9);
		}

		public override void LoadItemSaveData(int saveData)
		{
			Armed = (saveData & 1) != 0;
			Handoffs = (saveData >> 1) & 0xFF;
			Remaining = (float)((saveData >> 9) & 0xFFF) / 10f;
			if (Armed && Remaining <= 0.5f)
			{
				Remaining = Random.Range(Plugin.FuseMin.Value, Plugin.FuseMax.Value);
			}
			_loadedFromSave = true;
		}

		internal void HostThrown(ulong byClient)
		{
			_thrown = true;
			_thrownAt = Time.time;
			_thrownBy = byClient;
		}

		private float ValueMultiplier(int handoffs)
		{
			return Mathf.Min(Mathf.Max(1f, Plugin.ValueCap.Value), 1f + (float)Mathf.Max(0, Plugin.HandoffValuePercent.Value) / 100f * (float)handoffs);
		}

		private bool ShouldPause()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!Plugin.PauseInShip.Value)
			{
				return false;
			}
			if ((Object)(object)instance != (Object)null && instance.inShipPhase)
			{
				return true;
			}
			if (base.isHeld)
			{
				return false;
			}
			if (base.isInShipRoom)
			{
				return true;
			}
			Transform parent = ((Component)this).transform.parent;
			if ((Object)(object)parent != (Object)null)
			{
				return (Object)(object)((Component)parent).GetComponentInParent<DepositItemsDesk>() != (Object)null;
			}
			return false;
		}

		private void HostUpdate()
		{
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if (Gone || !((NetworkBehaviour)this).NetworkObject.IsSpawned)
			{
				return;
			}
			if (_loadedFromSave)
			{
				_loadedFromSave = false;
				_baseValue = Mathf.Max(1, Mathf.RoundToInt((float)base.scrapValue / ValueMultiplier(Handoffs)));
				Net.SendState(this, 0);
			}
			byte b = 0;
			PlayerControllerB val = (base.isHeld ? base.playerHeldBy : null);
			if ((Object)(object)val != (Object)null)
			{
				if (!Armed)
				{
					Armed = true;
					float num = Mathf.Max(1f, Mathf.Min(Plugin.FuseMin.Value, Plugin.FuseMax.Value));
					Remaining = Random.Range(num, Mathf.Max(num, Plugin.FuseMax.Value));
					_baseValue = Mathf.Max(1, base.scrapValue);
					LastHolder = val.playerClientId;
					b |= 1;
					Plugin.Log.LogInfo((object)$"HotPotato: armed by {val.playerUsername}, {Remaining:F1} s.");
				}
				else if (val.playerClientId != LastHolder)
				{
					if (LastHolder != ulong.MaxValue)
					{
						Handoffs++;
						Remaining = Mathf.Max(Remaining, Mathf.Min(Remaining + Plugin.HandoffSeconds.Value, Plugin.FuseCap.Value));
						if (_baseValue <= 0)
						{
							_baseValue = Mathf.Max(1, base.scrapValue);
						}
						int num2 = Mathf.RoundToInt((float)_baseValue * ValueMultiplier(Handoffs));
						if (num2 != base.scrapValue)
						{
							((GrabbableObject)this).SetScrapValue(num2);
							RoundManager instance = RoundManager.Instance;
							if (instance != null)
							{
								instance.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { NetworkObjectReference.op_Implicit(((NetworkBehaviour)this).NetworkObject) }, new int[1] { num2 });
							}
						}
						b |= 2;
						Plugin.Log.LogInfo((object)$"HotPotato: handoff {Handoffs} to {val.playerUsername}: ${num2}, {Remaining:F1} s left.");
					}
					LastHolder = val.playerClientId;
				}
				_thrown = false;
			}
			if (!Armed)
			{
				return;
			}
			bool flag = ShouldPause();
			if (flag != Paused)
			{
				Paused = flag;
				b |= 4;
			}
			if (!Paused)
			{
				Remaining -= Time.deltaTime;
			}
			if (_thrown && Plugin.MonsterFlash.Value && CheckMonsterHit())
			{
				Net.HostFlash(this, _thrownBy);
				return;
			}
			if (_thrown && !base.isHeld && base.fallTime >= 1f && Time.time - _thrownAt > 0.3f)
			{
				_thrown = false;
			}
			if (Remaining <= 0f)
			{
				Net.HostExplode(this);
				return;
			}
			_resyncTimer -= Time.deltaTime;
			if (b != 0 || _resyncTimer <= 0f)
			{
				_resyncTimer = 3f;
				Net.SendState(this, b);
			}
		}

		private bool CheckMonsterHit()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, Mathf.Max(0.5f, Plugin.MonsterRange.Value), Hits, 524288, (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				EnemyAICollisionDetect component = ((Component)Hits[i]).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.mainScript != (Object)null && !component.mainScript.isEnemyDead)
				{
					return true;
				}
			}
			return false;
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (!Gone)
			{
				if (((NetworkBehaviour)this).IsServer)
				{
					HostUpdate();
				}
				else if (Armed && !Paused)
				{
					Remaining -= Time.deltaTime;
				}
				Visuals();
			}
		}

		private void Visuals()
		{
			//IL_01cc: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			float num;
			if (!Armed)
			{
				num = 0.6f + Mathf.Sin(Time.time * 1.3f) * 0.15f;
			}
			else if (Paused)
			{
				num = 1.2f + Mathf.Sin(Time.time * 2f) * 0.5f;
			}
			else
			{
				_beepTimer -= Time.deltaTime;
				if (_beepTimer <= 0f)
				{
					float num2 = Mathf.Max(0f, Remaining);
					_beepTimer = Mathf.Clamp(num2 * 0.065f, 0.1f, 1.3f);
					_pulse = 1f;
					if ((Object)(object)_audio != (Object)null && (Object)(object)Registry.Beep != (Object)null)
					{
						_audio.pitch = Mathf.Lerp(1.35f, 1f, Mathf.Clamp01(num2 / 20f));
						_audio.PlayOneShot(Registry.Beep, Mathf.Clamp01(Plugin.Volume.Value) * 0.8f);
					}
					if ((Object)(object)_sparks != (Object)null && !base.isPocketed)
					{
						Fx.Burst(_sparks, ((Component)this).transform.position, (num2 < 5f) ? 6 : 2);
					}
				}
				_pulse = Mathf.MoveTowards(_pulse, 0f, Time.deltaTime * 6f);
				float num3 = Mathf.Clamp01(1f - Remaining / 20f);
				num = 1.6f + num3 * 3f + _pulse * (6f + num3 * 10f);
			}
			bool flag = !base.isPocketed;
			if ((Object)(object)_coreMat != (Object)null)
			{
				_coreMat.SetColor("_EmissiveColor", _coreEmissive * num * 2.5f);
			}
			if ((Object)(object)_light != (Object)null)
			{
				if (((Component)_light).gameObject.activeSelf != flag)
				{
					((Component)_light).gameObject.SetActive(flag);
				}
				if (flag)
				{
					_light.SetIntensity(8f + num * 14f, (LightUnit)0);
				}
			}
		}

		internal void ApplyState(bool armed, bool paused, float remaining, int handoffs, ulong lastHolder, byte events)
		{
			if (!((NetworkBehaviour)this).IsServer)
			{
				Armed = armed;
				Paused = paused;
				Remaining = remaining;
				Handoffs = handoffs;
				LastHolder = lastHolder;
			}
			if (!((Object)(object)_audio == (Object)null))
			{
				float num = Mathf.Clamp01(Plugin.Volume.Value);
				if ((events & 1) != 0 && (Object)(object)Registry.Arm != (Object)null)
				{
					_audio.pitch = 1f;
					_audio.PlayOneShot(Registry.Arm, num);
					_beepTimer = 0.8f;
				}
				if ((events & 2) != 0 && (Object)(object)Registry.Handoff != (Object)null)
				{
					_audio.pitch = 1f;
					_audio.PlayOneShot(Registry.Handoff, num * 0.9f);
					_pulse = 1f;
				}
			}
		}

		internal void Vanish()
		{
			if (Gone)
			{
				return;
			}
			Gone = true;
			base.grabbable = false;
			base.grabbableToEnemies = false;
			base.deactivated = true;
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Collider[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
			if ((Object)(object)_light != (Object)null)
			{
				((Component)_light).gameObject.SetActive(false);
			}
			if ((Object)(object)base.radarIcon != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)base.radarIcon).gameObject);
			}
			StartOfRound instance = StartOfRound.Instance;
			bool flag = false;
			if ((Object)(object)instance != (Object)null)
			{
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if ((Object)(object)val == (Object)null || val.ItemSlots == null)
					{
						continue;
					}
					for (int j = 0; j < val.ItemSlots.Length; j++)
					{
						if ((Object)(object)val.ItemSlots[j] == (Object)(object)this)
						{
							flag = true;
							try
							{
								val.DestroyItemInSlot(j);
							}
							catch (Exception ex)
							{
								Plugin.Log.LogWarning((object)$"HotPotato: clearing {val.playerUsername}'s slot {j}: {ex.Message}");
							}
						}
					}
				}
			}
			if (!flag && ((NetworkBehaviour)this).IsServer && (Object)(object)((NetworkBehaviour)this).NetworkObject != (Object)null && ((NetworkBehaviour)this).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)this).NetworkObject.Despawn(true);
			}
		}
	}
	internal static class Registry
	{
		internal const string ItemName = "Hot potato";

		internal static readonly Color GlowColor = new Color(1f, 0.42f, 0.1f);

		internal const float ValueScale = 0.4f;

		internal static AudioClip Beep;

		internal static AudioClip Arm;

		internal static AudioClip Handoff;

		internal static AudioClip Explode;

		internal static AudioClip FlashBang;

		internal static GameObject FlashEffect;

		internal static AnimationCurve FallCurve;

		internal static AnimationCurve VerticalCurve;

		internal static AnimationCurve VerticalCurveNoBounce;

		internal static Sprite Icon;

		internal static AudioMixerGroup Mixer;

		private static GameObject _container;

		internal static GameObject ModelAsset { get; private set; }

		public static GameObject Prefab { get; private set; }

		public static Item Item { get; private set; }

		public static void Load()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using (Stream stream = Res("hot_potato"))
				{
					AssetBundle val = ((stream != null) ? AssetBundle.LoadFromStream(stream) : null);
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Log.LogError((object)"HotPotato: the embedded bundle is missing.");
						return;
					}
					ModelAsset = val.LoadAsset<GameObject>("HotPotatoModel");
				}
				using (Stream stream2 = Res("icon_item.png"))
				{
					if (stream2 != null)
					{
						MemoryStream memoryStream = new MemoryStream();
						stream2.CopyTo(memoryStream);
						Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false)
						{
							name = "HotPotatoIcon"
						};
						if (ImageConversion.LoadImage(val2, memoryStream.ToArray()))
						{
							Icon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
						}
					}
				}
				Beep = Wav.Load(Res("beep.wav"), "HotPotatoBeep");
				Arm = Wav.Load(Res("arm.wav"), "HotPotatoArm");
				Handoff = Wav.Load(Res("handoff.wav"), "HotPotatoHandoff");
				Explode = Wav.Load(Res("explode.wav"), "HotPotatoExplode");
				Plugin.Log.LogInfo((object)$"HotPotato: assets loaded (model {(Object)(object)ModelAsset != (Object)null}, icon {(Object)(object)Icon != (Object)null}).");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"HotPotato: assets failed to load: {arg}");
			}
		}

		private static Stream Res(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("HotPotato." + name);
		}

		internal static void BuildPrefab()
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_02d8: 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_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Prefab != (Object)null)
			{
				return;
			}
			if ((Object)(object)ModelAsset == (Object)null)
			{
				Plugin.Log.LogError((object)"HotPotato: no model, so no item.");
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				Plugin.Log.LogError((object)"HotPotato: no NetworkManager at GameNetworkManager.Start.");
				return;
			}
			List<GrabbableObject> source = (from p in singleton.NetworkConfig.Prefabs.Prefabs
				select (!((Object)(object)p.Prefab != (Object)null)) ? null : p.Prefab.GetComponent<GrabbableObject>() into g
				where (Object)(object)g != (Object)null && (Object)(object)g.itemProperties != (Object)null
				select g).ToList();
			GrabbableObject val = ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g is StunGrenadeItem && g.itemProperties.itemName == "Stun grenade")) ?? ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => !g.itemProperties.twoHanded));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"HotPotato: no vanilla item to base the core on.");
				return;
			}
			StunGrenadeItem val2 = (StunGrenadeItem)(object)((val is StunGrenadeItem) ? val : null);
			if (val2 != null)
			{
				FallCurve = val2.grenadeFallCurve;
				VerticalCurve = val2.grenadeVerticalFallCurve;
				VerticalCurveNoBounce = val2.grenadeVerticalFallCurveNoBounce;
				FlashEffect = val2.stunGrenadeExplosion;
				FlashBang = val2.explodeSFX;
			}
			_container = new GameObject("HotPotato.Prefabs");
			_container.SetActive(false);
			((Object)_container).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)_container);
			GameObject val3 = new GameObject("HotPotato");
			val3.transform.SetParent(_container.transform, false);
			val3.layer = ((Component)val).gameObject.layer;
			val3.tag = ((Component)val).gameObject.tag;
			NetworkObject obj = val3.AddComponent<NetworkObject>();
			AccessTools.Field(typeof(NetworkObject), "GlobalObjectIdHash").SetValue(obj, StableHash("daniel.lethalcompany.hotpotato.HotPotato"));
			AudioSource component = ((Component)val).GetComponent<AudioSource>();
			AudioSource val4 = val3.AddComponent<AudioSource>();
			val4.playOnAwake = false;
			val4.spatialBlend = 1f;
			val4.rolloffMode = (AudioRolloffMode)1;
			val4.minDistance = 2f;
			val4.maxDistance = 30f;
			val4.dopplerLevel = 0f;
			if ((Object)(object)component != (Object)null)
			{
				Mixer = component.outputAudioMixerGroup;
				val4.outputAudioMixerGroup = Mixer;
			}
			GameObject val5 = Object.Instantiate<GameObject>(ModelAsset, val3.transform, false);
			((Object)val5).name = "Model";
			Transform[] componentsInChildren = val5.GetComponentsInChildren<Transform>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				((Component)componentsInChildren[num]).gameObject.layer = val3.layer;
			}
			BoxCollider obj2 = val3.AddComponent<BoxCollider>();
			obj2.center = new Vector3(0f, 0.01f, 0f);
			obj2.size = new Vector3(0.2f, 0.24f, 0.2f);
			((Collider)obj2).isTrigger = (Object)(object)((Component)val).GetComponent<Collider>() != (Object)null && ((Component)val).GetComponent<Collider>().isTrigger;
			ScanNodeProperties componentInChildren = ((Component)val).GetComponentInChildren<ScanNodeProperties>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				ScanNodeProperties component2 = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, val3.transform, false).GetComponent<ScanNodeProperties>();
				((Component)component2).transform.localPosition = Vector3.zero;
				component2.headerText = "Hot potato";
				component2.subText = "Value: ";
				component2.scrapValue = 0;
				component2.nodeType = 2;
				component2.minRange = 1;
				component2.maxRange = 13;
			}
			GameObject val6 = new GameObject("Glow");
			val6.transform.SetParent(val5.transform, false);
			val6.layer = val3.layer;
			Light obj3 = val6.AddComponent<Light>();
			obj3.type = (LightType)2;
			obj3.color = GlowColor;
			obj3.range = 3f;
			obj3.shadows = (LightShadows)0;
			HDAdditionalLightData obj4 = val6.AddComponent<HDAdditionalLightData>();
			obj4.SetIntensity(20f, (LightUnit)0);
			obj4.SetRange(3f);
			obj4.SetColor(GlowColor, -1f);
			obj4.EnableShadows(false);
			Item itemProperties = val.itemProperties;
			Item = Object.Instantiate<Item>(itemProperties);
			((Object)Item).name = "HotPotatoItem";
			Item.itemName = "Hot potato";
			if ((Object)(object)Icon != (Object)null)
			{
				Item.itemIcon = Icon;
			}
			Item.spawnPrefab = val3;
			Item.isScrap = true;
			Item.minValue = Mathf.RoundToInt((float)Mathf.Max(1, Plugin.MinValue.Value) / 0.4f);
			Item.maxValue = Mathf.RoundToInt((float)Mathf.Max(Plugin.MinValue.Value, Plugin.MaxValue.Value) / 0.4f);
			Item.creditsWorth = 0;
			Item.twoHanded = false;
			Item.requiresBattery = false;
			Item.isConductiveMetal = true;
			Item.isDefensiveWeapon = false;
			Item.holdButtonUse = false;
			Item.syncUseFunction = false;
			Item.saveItemVariable = true;
			Item.canBeGrabbedBeforeGameStart = true;
			Item.itemSpawnsOnGround = true;
			Item.itemIsTrigger = false;
			Item.automaticallySetUsingPower = false;
			Item.meshVariants = (Mesh[])(object)new Mesh[0];
			Item.materialVariants = (Material[])(object)new Material[0];
			Item.spawnPositionTypes = new List<ItemGroup>();
			Item.toolTips = new string[1] { "Throw : [LMB]" };
			Item.verticalOffset = 0.11f;
			Item.restingRotation = Vector3.zero;
			Item.positionOffset = new Vector3(0.02f, 0.11f, 0.02f);
			Item.rotationOffset = new Vector3(0f, 0f, -90f);
			Item.weight = 1.12f;
			PotatoItem potatoItem = val3.AddComponent<PotatoItem>();
			((GrabbableObject)potatoItem).itemProperties = Item;
			((GrabbableObject)potatoItem).grabbable = true;
			((GrabbableObject)potatoItem).grabbableToEnemies = false;
			((GrabbableObject)potatoItem).isInFactory = true;
			Transform obj5 = val5.transform.Find("Body");
			((GrabbableObject)potatoItem).mainObjectRenderer = ((obj5 != null) ? ((Component)obj5).GetComponentInChildren<MeshRenderer>() : null) ?? val5.GetComponentInChildren<MeshRenderer>();
			Prefab = val3;
			singleton.AddNetworkPrefab(val3);
			Rarities.Parse(Plugin.SpawnRarity.Value, out var vanilla, out var custom);
			Items.RegisterScrap(Item, vanilla, custom);
			Plugin.Log.LogInfo((object)($"HotPotato: item built from \"{itemProperties.itemName}\" (value {Item.minValue}-{Item.maxValue} raw, " + $"{vanilla.Count} vanilla rarities, {custom.Count} named moons)."));
		}

		internal static uint StableHash(string s)
		{
			using MD5 mD = MD5.Create();
			return BitConverter.ToUInt32(mD.ComputeHash(Encoding.UTF8.GetBytes(s)), 0);
		}
	}
	internal static class Rarities
	{
		private static readonly Dictionary<string, LevelTypes> Vanilla = new Dictionary<string, LevelTypes>(StringComparer.OrdinalIgnoreCase)
		{
			{
				"Experimentation",
				(LevelTypes)4
			},
			{
				"Assurance",
				(LevelTypes)8
			},
			{
				"Vow",
				(LevelTypes)16
			},
			{
				"Offense",
				(LevelTypes)32
			},
			{
				"March",
				(LevelTypes)64
			},
			{
				"Adamance",
				(LevelTypes)2048
			},
			{
				"Rend",
				(LevelTypes)128
			},
			{
				"Dine",
				(LevelTypes)256
			},
			{
				"Titan",
				(LevelTypes)512
			},
			{
				"Artifice",
				(LevelTypes)4096
			},
			{
				"Embrion",
				(LevelTypes)8192
			},
			{
				"Modded",
				(LevelTypes)1024
			}
		};

		internal static void Parse(string s, out Dictionary<LevelTypes, int> vanilla, out Dictionary<string, int> custom)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			vanilla = new Dictionary<LevelTypes, int>();
			custom = new Dictionary<string, int>();
			string[] array = (s ?? "").Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(':');
				if (array2.Length != 2 || !int.TryParse(array2[1].Trim(), out var result) || result < 0)
				{
					continue;
				}
				string text = array2[0].Trim();
				if (text.Length != 0)
				{
					if (Vanilla.TryGetValue(text, out var value))
					{
						vanilla[value] = result;
					}
					else
					{
						custom[text] = result;
					}
				}
			}
		}
	}
	internal static class Wav
	{
		public static AudioClip Load(Stream s, string name)
		{
			if (s == null)
			{
				Plugin.Log.LogError((object)("HotPotato: sound " + name + " is missing."));
				return null;
			}
			using (s)
			{
				using BinaryReader binaryReader = new BinaryReader(s);
				binaryReader.ReadBytes(12);
				int num = 1;
				int num2 = 44100;
				int num3 = 16;
				byte[] array = null;
				while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length - 8)
				{
					string text = Encoding.ASCII.GetString(binaryReader.ReadBytes(4));
					int num4 = binaryReader.ReadInt32();
					if (text == "fmt ")
					{
						binaryReader.ReadInt16();
						num = binaryReader.ReadInt16();
						num2 = binaryReader.ReadInt32();
						binaryReader.ReadInt32();
						binaryReader.ReadInt16();
						num3 = binaryReader.ReadInt16();
						if (num4 > 16)
						{
							binaryReader.ReadBytes(num4 - 16);
						}
					}
					else
					{
						if (text == "data")
						{
							array = binaryReader.ReadBytes(num4);
							break;
						}
						binaryReader.ReadBytes(num4);
					}
				}
				if (array == null || num3 != 16)
				{
					Plugin.Log.LogError((object)("HotPotato: sound " + name + " isn't 16-bit PCM."));
					return null;
				}
				int num5 = array.Length / 2;
				float[] array2 = new float[num5];
				for (int i = 0; i < num5; i++)
				{
					array2[i] = (float)BitConverter.ToInt16(array, i * 2) / 32768f;
				}
				AudioClip obj = AudioClip.Create(name, num5 / num, num, num2, false);
				obj.SetData(array2, 0);
				return obj;
			}
		}
	}
	[HarmonyPatch]
	internal static class RegistryPatches
	{
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void GameNetworkManagerStart()
		{
			if ((Object)(object)Registry.Prefab != (Object)null)
			{
				return;
			}
			try
			{
				Registry.BuildPrefab();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"HotPotato: building the item failed: {arg}");
			}
		}
	}
}