Decompiled source of Prize O Matic v0.2.4

BepInEx/plugins/Nagrodomad/Nagrodomad.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Prize-O-Matic")]
[assembly: AssemblyFileVersion("0.2.4.0")]
[assembly: InternalsVisibleTo("NagrodomadQa")]
[assembly: AssemblyVersion("0.2.4.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 Nagrodomad
{
	internal sealed class MachineAudio : IDisposable
	{
		private const int Rate = 44100;

		private static readonly double[] Notes = new double[4] { 523.251, 659.255, 783.991, 1046.502 };

		internal readonly AudioSource Motor;

		internal readonly AudioSource Effects;

		internal readonly AudioClip Spin;

		internal readonly AudioClip Coin;

		internal readonly AudioClip Pull;

		internal readonly AudioClip Win;

		internal MachineAudio(GameObject root)
		{
			Motor = Source(root);
			Motor.loop = true;
			Effects = Source(root);
			Spin = Make("Prize-O-Matic mechanical draw", 1f, delegate(double t, double noise)
			{
				double num = Math.Exp((0.0 - t * 18.0 % 1.0) * 24.0) * (Math.Sin(t * Math.PI * 2.0 * 1350.0) * 0.55 + noise * 0.45);
				return Math.Sin(t * Math.PI * 2.0 * 88.0) * 0.24 + Math.Sin(t * Math.PI * 2.0 * 176.0) * 0.12 + num * 0.62;
			});
			Coin = Make("Prize-O-Matic token clink", 0.42f, (double t, double noise) => (Math.Sin(t * Math.PI * 2.0 * 2150.0) + Math.Sin(t * Math.PI * 2.0 * 3280.0) * 0.6) * Math.Exp((0.0 - t) * 15.0) * 0.45 + noise * Math.Exp((0.0 - t) * 75.0) * 0.55);
			Pull = Make("Prize-O-Matic lever ratchet", 0.72f, delegate(double t, double noise)
			{
				double num = Math.Exp((0.0 - t * 13.0 % 1.0) * 35.0) * (noise * 0.65 + Math.Sin(t * Math.PI * 2.0 * 450.0) * 0.35);
				double num2 = Math.Exp((0.0 - Math.Max(0.0, t - 0.54)) * 26.0) * (Math.Sin(t * Math.PI * 2.0 * 105.0) * 0.65 + noise * 0.3);
				return (!(t < 0.54)) ? num2 : (num * 0.7);
			});
			Win = Make("Prize-O-Matic reward fanfare", 1.65f, delegate(double t, double noise)
			{
				double num = 0.0;
				for (int i = 0; i < Notes.Length; i++)
				{
					double num2 = t - (double)i * 0.15;
					if (!(num2 < 0.0))
					{
						double num3 = Math.Min(1.0, num2 * 140.0) * Math.Exp((0.0 - num2) * (double)((i == 3) ? 3 : 7));
						num += (Math.Sin(num2 * Math.PI * 2.0 * Notes[i]) + Math.Sin(num2 * Math.PI * 4.0 * Notes[i]) * 0.22) * num3 * 0.32;
					}
				}
				return num + noise * Math.Exp((0.0 - t) * 30.0) * 0.12;
			});
			Motor.clip = Spin;
		}

		private static AudioSource Source(GameObject root)
		{
			AudioSource obj = root.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.minDistance = 4f;
			obj.maxDistance = 32f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.dopplerLevel = 0f;
			obj.priority = 80;
			return obj;
		}

		private static AudioClip Make(string name, float seconds, Func<double, double, double> wave)
		{
			float[] array = new float[(int)(seconds * 44100f)];
			Random random = new Random(14893);
			double num = 0.0;
			for (int i = 0; i < array.Length; i++)
			{
				double arg = (double)i / 44100.0;
				double num2 = Math.Min(1.0, (double)i / 80.0) * Math.Min(1.0, (double)(array.Length - 1 - i) / 220.0);
				array[i] = (float)(wave(arg, random.NextDouble() * 2.0 - 1.0) * num2);
				num = Math.Max(num, Math.Abs(array[i]));
			}
			float num3 = ((num > 0.0) ? ((float)(0.92 / num)) : 1f);
			for (int j = 0; j < array.Length; j++)
			{
				array[j] *= num3;
			}
			AudioClip obj = AudioClip.Create(name, array.Length, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		internal void Play(AudioClip clip, float volume)
		{
			Effects.volume = volume;
			Effects.PlayOneShot(clip);
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)Motor))
			{
				Motor.Stop();
			}
			if (Object.op_Implicit((Object)(object)Effects))
			{
				Effects.Stop();
			}
			AudioClip[] array = (AudioClip[])(object)new AudioClip[4] { Spin, Coin, Pull, Win };
			foreach (AudioClip val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
	}
	internal sealed class MachineCabinet : IDisposable
	{
		internal const float Center = -0.475f;

		internal const float Height = 2.9f;

		internal const float Width = 2.05f;

		internal const float WheelX = -0.63f;

		internal const float WheelY = 1.55f;

		internal static readonly int[] Fields = new int[8] { 1, 0, 2, 1, -1, 4, 1, 2 };

		internal readonly Transform Drum;

		internal readonly Transform Hatch;

		internal readonly Transform Lever;

		internal readonly Transform Coin;

		internal readonly TextMesh Screen;

		private readonly Transform[] symbols = (Transform[])(object)new Transform[Fields.Length];

		private readonly GameObject[] normalMultipliers = (GameObject[])(object)new GameObject[Fields.Length];

		private readonly GameObject[] superMultipliers = (GameObject[])(object)new GameObject[Fields.Length];

		private readonly MeshRenderer[] rims = (MeshRenderer[])(object)new MeshRenderer[Fields.Length];

		private readonly MeshRenderer statusLamp;

		private readonly MeshRenderer marquee;

		private readonly Material trim;

		private readonly Material light;

		private readonly Material goldLight;

		private readonly Material idleLamp;

		private bool superLabels;

		private readonly List<Mesh> combinedMeshes = new List<Mesh>();

		private static Mesh star;

		private static Mesh triangle;

		private static Material Glow(string name, Color color, float intensity = 2.5f)
		{
			//IL_0001: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			Material val = Models.Finish(name, color, 0f);
			if (val.HasProperty("_EmissiveColor"))
			{
				val.SetColor("_EmissiveColor", color * intensity);
			}
			return val;
		}

		internal MachineCabinet(Transform root)
		{
			//IL_006d: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c2b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c4c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d29: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d63: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d77: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d99: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0deb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e8c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0edf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f34: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f3a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f69: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f95: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fa9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fcf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fe3: Unknown result type (might be due to invalid IL or missing references)
			//IL_1005: Unknown result type (might be due to invalid IL or missing references)
			//IL_102e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1042: Unknown result type (might be due to invalid IL or missing references)
			//IL_106d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1086: Unknown result type (might be due to invalid IL or missing references)
			//IL_10a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_10ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0801: Unknown result type (might be due to invalid IL or missing references)
			//IL_081e: Unknown result type (might be due to invalid IL or missing references)
			//IL_10fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_1110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0875: Unknown result type (might be due to invalid IL or missing references)
			//IL_0889: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0901: Unknown result type (might be due to invalid IL or missing references)
			//IL_0929: Unknown result type (might be due to invalid IL or missing references)
			//IL_097b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ace: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b45: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b50: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1153: Unknown result type (might be due to invalid IL or missing references)
			//IL_1167: Unknown result type (might be due to invalid IL or missing references)
			Material material = Models.Finish("Machine enamel", new Color(0.3f, 0.33f, 0.29f));
			Material material2 = Models.Finish("Machine ivory", new Color(0.71f, 0.68f, 0.54f));
			Material material3 = Models.Finish("Machine steel", new Color(0.14f, 0.16f, 0.15f), 0.75f);
			Material material4 = Models.Finish("Machine recess", new Color(0.018f, 0.023f, 0.021f), 0.1f);
			Material material5 = Models.Finish("Machine red grip", new Color(0.44f, 0.075f, 0.035f));
			trim = Models.Finish("Machine bronze", new Color(0.52f, 0.38f, 0.19f), 0.65f);
			light = Glow("Machine ready light", new Color(0.45f, 0.8f, 0.59f), 0.8f);
			goldLight = Glow("Machine result light", new Color(1f, 0.64f, 0.12f), 1.2f);
			idleLamp = Models.Finish("Machine inactive lamp", new Color(0.08f, 0.13f, 0.1f));
			Material val = PrizeSymbols.Ink("Pictogram ivory", new Color(0.93f, 0.92f, 0.77f));
			Material val2 = PrizeSymbols.Ink("Pictogram charcoal", new Color(0.025f, 0.031f, 0.025f));
			Material val3 = PrizeSymbols.Ink("Cash sector", new Color(0.075f, 0.17f, 0.12f));
			Material val4 = PrizeSymbols.Ink("Cash sector alternate", new Color(0.1f, 0.21f, 0.15f));
			Material val5 = PrizeSymbols.Ink("Mystery sector", new Color(0.19f, 0.17f, 0.13f));
			Material val6 = PrizeSymbols.Ink("Unique gold sector", new Color(0.88f, 0.57f, 0.12f));
			Box(root, "Foundation", new Vector3(-0.475f, 0.1f, -0.02f), new Vector3(2.05f, 0.2f, 0.96f), material3);
			Box(root, "Cabinet body", new Vector3(-0.475f, 1.45f, -0.06f), new Vector3(2.05f, 2.66f, 0.84f), material);
			Box(root, "Canopy", new Vector3(-0.475f, 2.8100002f, -0.02f), new Vector3(2.05f, 0.18f, 0.96f), material3);
			Box(root, "Front inset", new Vector3(-0.475f, 1.68f, 0.385f), new Vector3(1.93f, 2.17f, 0.09f), material4);
			float[] array = new float[2] { 0.49f, -1.44f };
			foreach (float num in array)
			{
				Box(root, "Folded upright", new Vector3(num, 1.43f, 0.43f), new Vector3(0.085f, 2.63f, 0.1f), material2);
				for (int j = 0; j < 4; j++)
				{
					Disc(root, "Fastener", new Vector3(num, 0.3f + (float)j * 0.78f, 0.492f), 0.025f, 0.014f, material3);
				}
			}
			Box(root, "Marquee frame", new Vector3(-0.475f, 2.655f, 0.46f), new Vector3(1.84f, 0.29f, 0.1f), trim);
			Box(root, "Marquee glass", new Vector3(-0.475f, 2.655f, 0.516f), new Vector3(1.75f, 0.215f, 0.025f), material4);
			Models.Text(root, "Brand", "PRIZE-O-MATIC", new Vector3(-0.475f, 2.66f, 0.535f), 0.043f, new Color(1f, 0.91f, 0.66f));
			marquee = Box(root, "Marquee lamp", new Vector3(-0.475f, 2.855f, 0.48f), new Vector3(1.72f, 0.025f, 0.02f), light);
			Box(root, "Display bezel", new Vector3(-0.63f, 2.385f, 0.48f), new Vector3(1.48f, 0.18f, 0.055f), material3);
			Box(root, "Display glass", new Vector3(-0.63f, 2.385f, 0.514f), new Vector3(1.39f, 0.125f, 0.025f), material4);
			Screen = Models.Text(root, "Screen", "INSERT TOKEN", new Vector3(-0.63f, 2.385f, 0.535f), 0.032f, new Color(0.7f, 0.96f, 0.76f));
			Box(root, "Wheel well frame", new Vector3(-0.63f, 1.55f, 0.465f), new Vector3(1.49f, 1.5f, 0.085f), material3);
			Box(root, "Wheel well", new Vector3(-0.63f, 1.55f, 0.508f), new Vector3(1.43f, 1.44f, 0.018f), material4);
			Vector3 val7 = default(Vector3);
			((Vector3)(ref val7))..ctor(-0.63f, 1.55f, 0.54f);
			Disc(root, "Recessed wheel bed", val7, 1.31f, 0.012f, material4);
			Drum = Pivot(root, "Prize wheel", val7 + Vector3.forward * 0.015f);
			Disc(Drum, "Wheel backing", Vector3.zero, 1.225f, 0.007f, material3);
			for (int k = 0; k < Fields.Length; k++)
			{
				float num2 = (float)k * 360f / (float)Fields.Length;
				Transform val8 = Pivot(Drum, "Prize field " + k, Vector3.forward * 0.008f);
				val8.localRotation = Quaternion.Euler(0f, 0f, 0f - num2);
				PrizeSymbols.Sector(val8, "Prize face", 0.1f, 0.608f, (Fields[k] < 0) ? val6 : ((Fields[k] == 0) ? val5 : ((k % 2 == 0) ? val3 : val4)));
				rims[k] = PrizeSymbols.Sector(val8, "Prize rim", 0.594f, 0.608f, trim);
				((Component)rims[k]).transform.localPosition = Vector3.forward * 0.002f;
				Transform icon = Pivot(val8, "Prize pictogram", new Vector3(0f, 0.42f, 0.009f));
				icon.localScale = Vector3.one * 0.85f;
				icon.localRotation = Quaternion.Euler(0f, 0f, num2);
				symbols[k] = icon;
				if (Fields[k] > 0)
				{
					Box(icon, "Banknote bundle", new Vector3(0.08f, -0.01f, 0f), new Vector3(0.154f, 0.088f, 0.004f), val);
					Box(icon, "Banknote", new Vector3(0.091f, 0.009f, 0.005f), new Vector3(0.154f, 0.088f, 0.004f), val);
					Box(icon, "Banknote ink", new Vector3(0.091f, 0.009f, 0.008f), new Vector3(0.128f, 0.063f, 0.003f), val3);
					Disc(icon, "Banknote seal", new Vector3(0.091f, 0.009f, 0.011f), 0.043f, 0.002f, val);
					Transform val9 = Pivot(icon, "Multiplier x" + Fields[k], new Vector3(-0.091f, 0f, 0.004f));
					PrizeSymbols.Multiplier(val9, Fields[k], val);
					normalMultipliers[k] = ((Component)val9).gameObject;
					Transform val10 = Pivot(icon, "Multiplier x" + Fields[k] * 2, new Vector3(-0.091f, 0f, 0.004f));
					PrizeSymbols.Multiplier(val10, Fields[k] * 2, val);
					superMultipliers[k] = ((Component)val10).gameObject;
					Batch(val9, (MeshRenderer _) => true);
					Batch(val10, (MeshRenderer _) => true);
					((Component)val10).gameObject.SetActive(false);
				}
				else if (Fields[k] == 0)
				{
					Box(icon, "Mystery box", new Vector3(0f, 0f, 0.004f), new Vector3(0.18f, 0.155f, 0.008f), val);
					Box(icon, "Parcel lid", new Vector3(0f, 0.064f, 0.011f), new Vector3(0.197f, 0.02f, 0.006f), material2);
					Transform obj = Pivot(icon, "Mystery symbol", new Vector3(0f, -0.003f, 0.02f));
					obj.localScale = Vector3.one * 0.8f;
					PrizeSymbols.Question(obj, val2);
				}
				else
				{
					Polygon(icon, "Unique star", ref star, 10, new Vector3(0f, 0f, 0.008f), 0.108f, 0.048f, val2);
				}
				Batch(icon, (MeshRenderer r) => !((Component)r).transform.IsChildOf(Object.op_Implicit((Object)(object)normalMultipliers[k]) ? normalMultipliers[k].transform : icon) && !((Component)r).transform.IsChildOf(Object.op_Implicit((Object)(object)superMultipliers[k]) ? superMultipliers[k].transform : icon));
			}
			((Component)PrizeSymbols.Sector(root, "Recess lip", 0.615f, 0.672f, trim, 360f)).transform.localPosition = new Vector3(-0.63f, 1.55f, 0.595f);
			Transform parent = Pivot(root, "Wheel hub", val7 + Vector3.forward * 0.044f);
			Disc(parent, "Hub collar", Vector3.zero, 0.215f, 0.014f, trim);
			Disc(parent, "Hub cap", Vector3.forward * 0.012f, 0.166f, 0.025f, material3);
			((Component)Polygon(root, "Selection arrow", ref triangle, 3, new Vector3(-0.63f, 2.21f, 0.612f), 0.063f, 0.063f, goldLight)).transform.localRotation = Quaternion.Euler(0f, 0f, 180f);
			Box(root, "Token control panel", new Vector3(0.267f, 1.79f, 0.475f), new Vector3(0.24f, 1.02f, 0.075f), material3);
			Box(root, "Coin slot surround", new Vector3(0.267f, 2.065f, 0.53f), new Vector3(0.105f, 0.22f, 0.035f), trim);
			Box(root, "Coin aperture", new Vector3(0.267f, 2.065f, 0.554f), new Vector3(0.026f, 0.175f, 0.018f), material4);
			statusLamp = Disc(root, "Ready lamp", new Vector3(0.267f, 1.87f, 0.53f), 0.065f, 0.014f, idleLamp);
			Models.Text(root, "Token key", "[E]", new Vector3(0.267f, 1.7f, 0.535f), 0.024f, new Color(0.9f, 0.86f, 0.69f));
			Coin = Pivot(root, "Inserted coin", new Vector3(0.267f, 2.065f, 0.76f));
			Models.Part(Coin, "Token", (PrimitiveType)2, Vector3.zero, new Vector3(0.12f, 0.009f, 0.12f), trim, Quaternion.Euler(90f, 0f, 90f));
			((Component)Coin).gameObject.SetActive(false);
			Lever = Pivot(root, "Lever", new Vector3(0.55f, 1.41f, 0.24f));
			Models.Part(root, "Lever bearing", (PrimitiveType)2, new Vector3(0.52f, 1.41f, 0.24f), new Vector3(0.19f, 0.085f, 0.19f), trim, Quaternion.Euler(0f, 0f, 90f));
			Vector3 val11 = default(Vector3);
			((Vector3)(ref val11))..ctor(0f, 0.43f, 0.22f);
			Models.Part(Lever, "Lever arm", (PrimitiveType)2, val11 * 0.5f, new Vector3(0.043f, ((Vector3)(ref val11)).magnitude * 0.5f, 0.043f), material3, Quaternion.FromToRotation(Vector3.up, val11));
			Models.Part(Lever, "Lever grip", (PrimitiveType)0, val11, Vector3.one * 0.16f, material5);
			Box(root, "Prize surround", new Vector3(-0.475f, 0.44f, 0.46f), new Vector3(1.74f, 0.48f, 0.075f), trim);
			Box(root, "Prize well", new Vector3(-0.475f, 0.43f, 0.505f), new Vector3(1.6f, 0.35f, 0.035f), material4);
			Hatch = Pivot(root, "Prize hatch", new Vector3(-0.475f, 0.265f, 0.54f));
			Box(Hatch, "Hatch plate", new Vector3(0f, 0.165f, 0f), new Vector3(1.56f, 0.32f, 0.035f), material);
			Models.Text(Hatch, "Hatch marking", "COLLECT", new Vector3(0f, 0.165f, 0.026f), 0.03f, new Color(0.83f, 0.81f, 0.65f));
			Box(root, "Reward shelf", new Vector3(-0.475f, 0.24f, 0.67f), new Vector3(1.72f, 0.06f, 0.55f), material3);
			array = new float[2] { -1.3149999f, 0.36499998f };
			foreach (float num3 in array)
			{
				Box(root, "Tray side", new Vector3(num3, 0.3f, 0.67f), new Vector3(0.045f, 0.12f, 0.55f), trim);
			}
			for (int num4 = 0; num4 < 6; num4++)
			{
				Box(root, "Side vent", new Vector3(-1.507f, 0.8f + (float)num4 * 0.085f, -0.04f), new Vector3(0.018f, 0.025f, 0.48f), material4);
			}
			Batch(root, (MeshRenderer r) => !((Component)r).transform.IsChildOf(Drum) && !((Component)r).transform.IsChildOf(Hatch) && !((Component)r).transform.IsChildOf(Lever) && !((Component)r).transform.IsChildOf(Coin));
			Batch(Drum, (MeshRenderer r) => !rims.Contains(r) && !symbols.Any((Transform s) => ((Component)r).transform.IsChildOf(s)));
			Batch(Hatch, (MeshRenderer _) => true);
			Batch(Lever, (MeshRenderer _) => true);
		}

		internal static int Winner(DrawRecord draw)
		{
			int field = ((draw.Prize.Kind == PrizeKind.Unique) ? (-1) : ((draw.Prize.Kind != PrizeKind.CompanyItem) ? (draw.Prize.Multiplier / ((draw.TokenKind != GearKind.SuperToken) ? 1 : 2)) : 0));
			int[] array = (from i in Enumerable.Range(0, Fields.Length)
				where Fields[i] == field
				select i).ToArray();
			if (array.Length != 0)
			{
				return array[draw.Token % array.Length];
			}
			return 0;
		}

		internal void State(bool super, bool ready, bool spinning, bool reveal, int winner, double now)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (superLabels != super)
			{
				superLabels = super;
				for (int i = 0; i < Fields.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)normalMultipliers[i]))
					{
						normalMultipliers[i].SetActive(!super);
						superMultipliers[i].SetActive(super);
					}
				}
			}
			((Renderer)marquee).sharedMaterial = (super ? goldLight : light);
			((Renderer)statusLamp).sharedMaterial = (ready ? light : (spinning ? goldLight : idleLamp));
			int num = (reveal ? winner : (spinning ? ((int)(now * 14.0) % Fields.Length) : (-1)));
			for (int j = 0; j < rims.Length; j++)
			{
				((Renderer)rims[j]).sharedMaterial = ((j == num) ? goldLight : trim);
				symbols[j].localRotation = Quaternion.Euler(0f, 0f, (float)j * 360f / (float)Fields.Length - Drum.localEulerAngles.z);
			}
		}

		private void Batch(Transform parent, Func<MeshRenderer, bool> include)
		{
			//IL_007e: 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_00af: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			foreach (IGrouping<Material, MeshRenderer> item in from r in (from r in ((Component)parent).GetComponentsInChildren<MeshRenderer>()
					where !Object.op_Implicit((Object)(object)((Component)r).GetComponent<TextMesh>()) && (Object)(object)r != (Object)(object)marquee && (Object)(object)r != (Object)(object)statusLamp && include(r)
					select r).ToArray()
				group r by ((Renderer)r).sharedMaterial)
			{
				if (item.Count() < 2)
				{
					continue;
				}
				Mesh val = new Mesh
				{
					name = "Nagrodomad " + ((Object)parent).name + " " + ((Object)item.Key).name
				};
				val.CombineMeshes(item.Select(delegate(MeshRenderer r)
				{
					//IL_0002: 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_002d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0032: Unknown result type (might be due to invalid IL or missing references)
					//IL_003c: Unknown result type (might be due to invalid IL or missing references)
					CombineInstance result = default(CombineInstance);
					((CombineInstance)(ref result)).mesh = ((Component)r).GetComponent<MeshFilter>().sharedMesh;
					((CombineInstance)(ref result)).transform = parent.worldToLocalMatrix * ((Component)r).transform.localToWorldMatrix;
					return result;
				}).ToArray(), true, true);
				combinedMeshes.Add(val);
				Transform obj = Pivot(parent, ((Object)val).name, Vector3.zero);
				((Component)obj).gameObject.AddComponent<MeshFilter>().sharedMesh = val;
				((Renderer)((Component)obj).gameObject.AddComponent<MeshRenderer>()).sharedMaterial = item.Key;
				foreach (MeshRenderer item2 in item)
				{
					Object.DestroyImmediate((Object)(object)((Component)item2).GetComponent<MeshFilter>());
					Object.DestroyImmediate((Object)(object)item2);
				}
			}
		}

		public void Dispose()
		{
			foreach (Mesh combinedMesh in combinedMeshes)
			{
				if (Object.op_Implicit((Object)(object)combinedMesh))
				{
					Object.Destroy((Object)(object)combinedMesh);
				}
			}
			combinedMeshes.Clear();
		}

		private static Transform Pivot(Transform parent, string name, Vector3 position)
		{
			//IL_0001: 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)
			Transform transform = new GameObject(name).transform;
			transform.SetParent(parent, false);
			transform.localPosition = position;
			return transform;
		}

		private static MeshRenderer Box(Transform parent, string name, Vector3 position, Vector3 scale, Material material)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return Models.Part(parent, name, (PrimitiveType)3, position, scale, material);
		}

		private static MeshRenderer Disc(Transform parent, string name, Vector3 position, float diameter, float depth, Material material)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			return Models.Part(parent, name, (PrimitiveType)2, position, new Vector3(diameter, depth * 0.5f, diameter), material, Quaternion.Euler(90f, 0f, 0f));
		}

		private static MeshRenderer Polygon(Transform parent, string name, ref Mesh mesh, int count, Vector3 position, float radius, float inner, Material material)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_009e: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_0068: 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)
			if (!Object.op_Implicit((Object)(object)mesh))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[count + 1];
				int[] array2 = new int[count * 3];
				for (int i = 0; i < count; i++)
				{
					float num = (float)i * (float)Math.PI * 2f / (float)count;
					float num2 = ((count == 10 && i % 2 == 1) ? (inner / radius) : 1f);
					array[i + 1] = new Vector3(Mathf.Sin(num) * num2, Mathf.Cos(num) * num2, 0f);
					array2[i * 3] = 0;
					array2[i * 3 + 1] = (i + 1) % count + 1;
					array2[i * 3 + 2] = i + 1;
				}
				mesh = new Mesh
				{
					name = name,
					vertices = array,
					triangles = array2
				};
				mesh.RecalculateNormals();
				mesh.RecalculateBounds();
			}
			Transform obj = Pivot(parent, name, position);
			obj.localScale = Vector3.one * radius;
			((Component)obj).gameObject.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj2 = ((Component)obj).gameObject.AddComponent<MeshRenderer>();
			((Renderer)obj2).sharedMaterial = material;
			((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
			return obj2;
		}
	}
	[BepInPlugin("saltanis.nagrodomad", "Prize-O-Matic", "0.2.4")]
	[BepInDependency("evaisa.lethallib", "1.2.0")]
	public sealed class NagroPlugin : BaseUnityPlugin
	{
		private sealed class KitChannel
		{
			internal int Item;

			internal ulong Target;

			internal double Since;
		}

		[HarmonyPatch]
		private static class CounterPickupPatch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(PlayerControllerB), "BeginGrabObject", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger", (Type[])null, (Type[])null);
			}

			private static void Prefix(PlayerControllerB __instance)
			{
				if (Object.op_Implicit((Object)(object)Instance) && (Object)(object)__instance == (Object)(object)Local)
				{
					Instance.UpdateCounterPickup();
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static class RegisterPatch
		{
			private static void Prefix()
			{
				Instance?.RegisterItems();
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "GetItemDataToSave")]
		private static class SaveGearPatch
		{
			private static bool Prefix(GrabbableObject __instance, ref int __result)
			{
				NagroItem component = ((Component)__instance).GetComponent<NagroItem>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return true;
				}
				__result = component.Serial;
				return false;
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "LoadItemSaveData")]
		private static class LoadGearPatch
		{
			private static bool Prefix(GrabbableObject __instance, int __0)
			{
				NagroItem component = ((Component)__instance).GetComponent<NagroItem>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return true;
				}
				component.Serial = __0;
				if (Object.op_Implicit((Object)(object)Instance) && Instance.Server && __0 > 0)
				{
					Instance.live[__0] = __instance;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "EquipItem")]
		private static class EquipPatch
		{
			private static void Postfix(GrabbableObject __instance)
			{
				NagroItem component = ((Component)__instance).GetComponent<NagroItem>();
				if (Object.op_Implicit((Object)(object)component) && ((NetworkBehaviour)__instance).IsOwner && Object.op_Implicit((Object)(object)__instance.playerHeldBy))
				{
					__instance.playerHeldBy.equippedUsableItemQE = component.Kind == GearKind.GravityVault || component.Kind == GearKind.FreightRift;
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
		private static class ActivatePatch
		{
			private static void Postfix(GrabbableObject __instance, bool __1)
			{
				NagroItem component = ((Component)__instance).GetComponent<NagroItem>();
				if (Object.op_Implicit((Object)(object)Instance) && Object.op_Implicit((Object)(object)component) && ((NetworkBehaviour)__instance).IsOwner && component.Kind > GearKind.SuperToken)
				{
					Instance.Send(new Request
					{
						Op = "gear",
						Object = ((NetworkBehaviour)__instance).NetworkObjectId,
						Release = !__1
					});
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "ItemInteractLeftRightOnClient")]
		private static class SecondaryPatch
		{
			private static void Postfix(GrabbableObject __instance, bool __0)
			{
				NagroItem component = ((Component)__instance).GetComponent<NagroItem>();
				if (!__0 && Object.op_Implicit((Object)(object)Instance) && Object.op_Implicit((Object)(object)component) && ((NetworkBehaviour)__instance).IsOwner)
				{
					Instance.Send(new Request
					{
						Op = "secondary",
						Object = ((NetworkBehaviour)__instance).NetworkObjectId
					});
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ItemTertiaryUse_performed")]
		private static class PreserveInteractionKeyPatch
		{
			private static bool Prefix(PlayerControllerB __instance)
			{
				GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
				NagroItem nagroItem = ((currentlyHeldObjectServer != null) ? ((Component)currentlyHeldObjectServer).GetComponent<NagroItem>() : null);
				if (Object.op_Implicit((Object)(object)nagroItem))
				{
					if (nagroItem.Kind != GearKind.GravityVault)
					{
						return nagroItem.Kind != GearKind.FreightRift;
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ActivateItem_canceled")]
		private static class CancelKitPatch
		{
			private static void Prefix(PlayerControllerB __instance)
			{
				GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
				NagroItem nagroItem = (Object.op_Implicit((Object)(object)currentlyHeldObjectServer) ? ((Component)currentlyHeldObjectServer).GetComponent<NagroItem>() : null);
				if (Object.op_Implicit((Object)(object)Instance) && (Object)(object)__instance == (Object)(object)Local && Object.op_Implicit((Object)(object)nagroItem) && nagroItem.Kind == GearKind.LastShiftKit)
				{
					Instance.Send(new Request
					{
						Op = "gear",
						Object = ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObjectId,
						Release = true
					});
				}
			}
		}

		[HarmonyPatch(typeof(DepositItemsDesk), "PlaceItemOnCounter")]
		private static class RefuseTokenPatch
		{
			private static bool Prefix(PlayerControllerB __0)
			{
				object obj;
				if (__0 == null)
				{
					obj = null;
				}
				else
				{
					GrabbableObject currentlyHeldObjectServer = __0.currentlyHeldObjectServer;
					obj = ((currentlyHeldObjectServer != null) ? ((Component)currentlyHeldObjectServer).GetComponent<NagroItem>() : null);
				}
				NagroItem nagroItem = (NagroItem)obj;
				if (Object.op_Implicit((Object)(object)nagroItem))
				{
					return nagroItem.Kind > GearKind.SuperToken;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(DepositItemsDesk), "AddObjectToDeskServerRpc")]
		private static class RefuseTokenServerPatch
		{
			private static bool Prefix(NetworkObjectReference __0)
			{
				NetworkObject val = default(NetworkObject);
				if (!((NetworkObjectReference)(ref __0)).TryGet(ref val, (NetworkManager)null))
				{
					return true;
				}
				NagroItem component = ((Component)val).GetComponent<NagroItem>();
				if (Object.op_Implicit((Object)(object)component))
				{
					return component.Kind > GearKind.SuperToken;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(DepositItemsDesk), "SellAndDisplayItemProfits")]
		private static class SalePatch
		{
			private static void Prefix(out int[] __state)
			{
				TimeOfDay instance = TimeOfDay.Instance;
				__state = ((!Object.op_Implicit((Object)(object)instance)) ? null : new int[3] { instance.timesFulfilledQuota, instance.profitQuota, instance.quotaFulfilled });
			}

			private static void Postfix(int __0, int[] __state)
			{
				if (Object.op_Implicit((Object)(object)Instance) && Instance.Server && __state != null && __0 > 0)
				{
					Instance.Sale(__state[0], __state[1], (int)Math.Min(2147483647L, (long)__state[2] + (long)__0));
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
		private static class SaveCampaignPatch
		{
			private static void Prefix()
			{
				if (Object.op_Implicit((Object)(object)Instance) && Instance.Server)
				{
					Instance.Save();
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")]
		private static class ResetCampaignPatch
		{
			private static void Postfix()
			{
				if (Object.op_Implicit((Object)(object)Instance) && Instance.Server)
				{
					Instance.campaign = new Campaign();
					Instance.Save();
				}
			}
		}

		[HarmonyPatch]
		private static class CarryPatch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				string[] array = new string[6] { "BeginGrabObject", "GrabObjectClientRpc", "DespawnHeldObjectOnClient", "SetObjectAsNoLongerHeld", "PlaceGrabbableObject", "DestroyItemInSlot" };
				foreach (string text in array)
				{
					yield return AccessTools.Method(typeof(PlayerControllerB), text, (Type[])null, (Type[])null);
				}
				yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "GrabObject", (Type[])null, (Type[])null));
			}

			[HarmonyPriority(800)]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> original)
			{
				List<CodeInstruction> list = original.ToList();
				FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "itemProperties");
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(Item), "weight");
				for (int i = 1; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false) && CodeInstructionExtensions.LoadsField(list[i - 1], fieldInfo, false))
					{
						list[i - 1].opcode = OpCodes.Nop;
						list[i - 1].operand = null;
						list[i].opcode = OpCodes.Call;
						list[i].operand = AccessTools.Method(typeof(NagroPlugin), "CarryWeight", (Type[])null, (Type[])null);
					}
				}
				return list;
			}
		}

		private static readonly FieldInfo giftValue = AccessTools.Field(typeof(GiftBoxItem), "objectInPresentValue");

		private readonly Dictionary<ulong, double> lastGearUse = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, double> lastTravel = new Dictionary<ulong, double>();

		private readonly Dictionary<string, PortalView> gates = new Dictionary<string, PortalView>();

		private readonly Dictionary<ulong, GrabbableObject> restoredCargo = new Dictionary<ulong, GrabbableObject>();

		private readonly Dictionary<ulong, GrabbableObject> cargoMetadata = new Dictionary<ulong, GrabbableObject>();

		private readonly Dictionary<GameObject, int> counterLayers = new Dictionary<GameObject, int>();

		private static Func<GrabbableObject, float> companyWeight;

		private const string RequestMessage = "saltanis.nagrodomad/1/request";

		private const string StateMessage = "saltanis.nagrodomad/1/state";

		private const string EventMessage = "saltanis.nagrodomad/1/event";

		private CustomMessagingManager messages;

		private long revision;

		public const string Id = "saltanis.nagrodomad";

		public const string Version = "0.2.4";

		internal const string SaveKey = "saltanis.nagrodomad.campaign.v1";

		internal static NagroPlugin Instance;

		internal static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings
		{
			TypeNameHandling = (TypeNameHandling)0,
			MetadataPropertyHandling = (MetadataPropertyHandling)2,
			MaxDepth = 24
		};

		internal Campaign campaign;

		internal NetworkManager net;

		internal MachineWorld world;

		internal Snapshot snapshot;

		internal readonly Dictionary<int, GrabbableObject> live = new Dictionary<int, GrabbableObject>();

		private readonly Dictionary<ulong, string> identities = new Dictionary<ulong, string>();

		private readonly Dictionary<ulong, double> holds = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, double> leverHolds = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, double> lastRequest = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, KitChannel> kitChannels = new Dictionary<ulong, KitChannel>();

		private readonly Item[] definitions = (Item[])(object)new Item[6];

		private string slot;

		private string localIdentity;

		private Harmony harmony;

		private bool quitting;

		private bool invalidSave;

		private float nextTick;

		private float nextHello;

		private ConfigEntry<float> angerChance;

		private ConfigEntry<float> soundVolume;

		internal double freezeUntil;

		internal static PlayerControllerB Local
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		internal static StartOfRound Round => StartOfRound.Instance;

		internal double Now
		{
			get
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)net) || !net.IsListening)
				{
					return Time.unscaledTime;
				}
				NetworkTime serverTime = net.ServerTime;
				return ((NetworkTime)(ref serverTime)).Time;
			}
		}

		internal bool Server
		{
			get
			{
				if (Object.op_Implicit((Object)(object)net) && net.IsListening)
				{
					return net.IsServer;
				}
				return false;
			}
		}

		internal bool Company
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Round) && Object.op_Implicit((Object)(object)Round.currentLevel))
				{
					return Round.currentLevel.sceneName == "CompanyBuilding";
				}
				return false;
			}
		}

		internal bool Landed
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Round) && Round.shipHasLanded && !Round.inShipPhase)
				{
					return !Round.shipIsLeaving;
				}
				return false;
			}
		}

		internal float SoundVolume => soundVolume.Value;

		internal bool Frozen
		{
			get
			{
				if (Object.op_Implicit((Object)(object)net) && net.IsListening)
				{
					return Now < freezeUntil;
				}
				return false;
			}
		}

		internal string DayKey => TimeOfDay.Instance.timesFulfilledQuota + ":" + TimeOfDay.Instance.daysUntilDeadline + ":" + Round.currentLevelID + ":" + Round.randomMapSeed;

		private static Cargo CaptureCargo(GrabbableObject prop)
		{
			Item itemProperties = prop.itemProperties;
			float weight = itemProperties.weight;
			return new Cargo
			{
				Item = ((Object)itemProperties).name,
				Prefab = (Object.op_Implicit((Object)(object)itemProperties.spawnPrefab) ? ((Object)itemProperties.spawnPrefab).name : ""),
				Value = prop.scrapValue,
				Weight = ((float.IsNaN(weight) || float.IsInfinity(weight)) ? 1f : Mathf.Max(1f, weight)),
				Data = (itemProperties.saveItemVariable ? prop.GetItemDataToSave() : 0),
				Battery = ((prop.insertedBattery != null) ? Mathf.Clamp01(prop.insertedBattery.charge) : (-1f)),
				GiftValue = ((prop is GiftBoxItem && giftValue != null) ? ((int?)giftValue.GetValue(prop)) : ((int?)null)),
				LungPowered = ((LungProp)(((prop is LungProp) ? prop : null)?)).isLungPowered
			};
		}

		private static void RestoreCargo(GrabbableObject prop, Cargo cargo)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if (prop.itemProperties.saveItemVariable)
			{
				prop.LoadItemSaveData(cargo.Data);
			}
			if (cargo.Battery >= 0f)
			{
				prop.insertedBattery = new Battery(cargo.Battery <= 0f, cargo.Battery);
			}
			if (prop is GiftBoxItem && cargo.GiftValue.HasValue && giftValue != null)
			{
				giftValue.SetValue(prop, cargo.GiftValue.Value);
			}
			LungProp val = (LungProp)(object)((prop is LungProp) ? prop : null);
			if (val != null)
			{
				val.isLungDocked = (val.isLungDockedInElevator = false);
				if (cargo.LungPowered.HasValue)
				{
					val.isLungPowered = cargo.LungPowered.Value;
				}
			}
			prop.SetScrapValue(cargo.Value);
		}

		private Item CargoDefinition(Cargo cargo)
		{
			return ((IEnumerable<Item>)Round.allItemsList.itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && Object.op_Implicit((Object)(object)i.spawnPrefab) && ((Object)i).name == cargo.Item && (string.IsNullOrEmpty(cargo.Prefab) || ((Object)i.spawnPrefab).name == cargo.Prefab)));
		}

		private void UseGear(PlayerControllerB player, ulong objectId, bool secondary, bool release)
		{
			if (release)
			{
				kitChannels.Remove(player.actualClientId);
			}
			else
			{
				if (lastGearUse.TryGetValue(player.actualClientId, out var value) && Now - value < 0.15)
				{
					return;
				}
				lastGearUse[player.actualClientId] = Now;
				GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer;
				NagroItem nagroItem = (Object.op_Implicit((Object)(object)currentlyHeldObjectServer) ? ((Component)currentlyHeldObjectServer).GetComponent<NagroItem>() : null);
				if (!Object.op_Implicit((Object)(object)nagroItem) || !((NetworkBehaviour)currentlyHeldObjectServer).IsSpawned || ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObjectId != objectId || currentlyHeldObjectServer.isPocketed || nagroItem.Kind <= GearKind.SuperToken)
				{
					return;
				}
				if (nagroItem.Serial == 0 && RegisterExternalGear(nagroItem))
				{
					Broadcast();
					CheckpointShip();
				}
				GearRecord gearRecord = campaign.Find(nagroItem.Serial);
				if (gearRecord == null || gearRecord.Kind != nagroItem.Kind || gearRecord.Status == TokenStatus.Consumed || gearRecord.Status == TokenStatus.Lost)
				{
					Notice(player.actualClientId, "This equipment has no valid saved record.");
					return;
				}
				switch (gearRecord.Kind)
				{
				case GearKind.GravityVault:
					Vault(player, gearRecord, secondary);
					break;
				case GearKind.FreightRift:
					Rift(player, gearRecord, secondary);
					break;
				case GearKind.LastShiftKit:
					if (!secondary)
					{
						BeginKit(player, gearRecord);
					}
					break;
				case GearKind.OvertimeCore:
					if (!secondary)
					{
						Core(player, gearRecord);
					}
					break;
				}
			}
		}

		private void Vault(PlayerControllerB player, GearRecord record, bool secondary)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			if (secondary)
			{
				if (record.Open)
				{
					if (record.Cargo.Count == 0)
					{
						Notice(player.actualClientId, "Pack scrap before sealing the vault.");
					}
					else if (record.Charges > 0 && Change(delegate
					{
						record.Open = false;
						record.Charges--;
					}))
					{
						Broadcast();
						CheckpointShip();
						Notice(player.actualClientId, "Vault sealed. Reduced cargo weight active.");
					}
					return;
				}
				Item[] array = record.Cargo.Select(CargoDefinition).ToArray();
				if (array.Any((Item d) => !Object.op_Implicit((Object)(object)d) || !Object.op_Implicit((Object)(object)d.spawnPrefab)))
				{
					Notice(player.actualClientId, "A stored item is unavailable. Cargo remains secured.");
					return;
				}
				List<GrabbableObject> list = new List<GrabbableObject>();
				try
				{
					for (int num = 0; num < record.Cargo.Count; num++)
					{
						Cargo cargo = record.Cargo[num];
						Vector3 val = ((Component)player).transform.position + ((Component)player).transform.forward * 1f + ((Component)player).transform.right * ((float)(num % 3 - 1) * 0.26f) + Vector3.up * (0.18f + (float)(num / 3) * 0.12f);
						GameObject obj = Object.Instantiate<GameObject>(array[num].spawnPrefab, val, Quaternion.Euler(array[num].restingRotation), player.isInHangarShipRoom ? Round.elevatorTransform : null);
						((Object)obj).hideFlags = (HideFlags)0;
						GrabbableObject component = obj.GetComponent<GrabbableObject>();
						list.Add(component);
						component.isInShipRoom = (component.isInElevator = player.isInHangarShipRoom);
						component.isInFactory = player.isInsideFactory;
						RestoreCargo(component, cargo);
						((NetworkBehaviour)component).NetworkObject.Spawn(false);
						restoredCargo[((NetworkBehaviour)component).NetworkObjectId] = component;
					}
					if (!Change(delegate
					{
						record.Cargo.Clear();
						record.Open = true;
					}))
					{
						foreach (GrabbableObject item in list)
						{
							if (Object.op_Implicit((Object)(object)item))
							{
								if (((NetworkBehaviour)item).IsSpawned)
								{
									((NetworkBehaviour)item).NetworkObject.Despawn(true);
								}
								else
								{
									Object.Destroy((Object)(object)((Component)item).gameObject);
								}
							}
						}
						return;
					}
					Broadcast();
					CheckpointShip();
					Notice(player.actualClientId, "Cargo unpacked.");
					return;
				}
				catch (Exception ex)
				{
					foreach (GrabbableObject item2 in list)
					{
						if (Object.op_Implicit((Object)(object)item2))
						{
							if (((NetworkBehaviour)item2).IsSpawned)
							{
								((NetworkBehaviour)item2).NetworkObject.Despawn(true);
							}
							else
							{
								Object.Destroy((Object)(object)((Component)item2).gameObject);
							}
						}
					}
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not unpack cargo: " + ex));
					Notice(player.actualClientId, "Unable to unpack this scrap. Cargo remains secured.");
					return;
				}
			}
			if (!record.Open)
			{
				Notice(player.actualClientId, "Press Q to unpack the sealed vault.");
				return;
			}
			if (record.Charges <= 0)
			{
				Notice(player.actualClientId, "The vault has no packing cycles left.");
				return;
			}
			if (record.Cargo.Count >= 6)
			{
				Notice(player.actualClientId, "Vault full. Press Q to seal it.");
				return;
			}
			GrabbableObject val2 = VaultTarget(player);
			if (!Object.op_Implicit((Object)(object)val2) || !((NetworkBehaviour)val2).IsSpawned || val2.isHeld || val2.isHeldByEnemy || val2.isPocketed || !Object.op_Implicit((Object)(object)val2.itemProperties) || !val2.itemProperties.isScrap)
			{
				Notice(player.actualClientId, "Aim at loose scrap within reach.");
				return;
			}
			DepositItemsDesk val3 = (Company ? Object.FindObjectOfType<DepositItemsDesk>() : null);
			if (Object.op_Implicit((Object)(object)val3) && (val3.itemsOnCounter.Contains(val2) || ((Component)val2).transform.IsChildOf(((Component)val3.deskObjectsContainer).transform)))
			{
				Notice(player.actualClientId, "Items submitted for sale cannot be packed.");
				return;
			}
			Cargo packed;
			try
			{
				packed = CaptureCargo(val2);
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not save scrap state: " + ex2));
				Notice(player.actualClientId, "Unable to save this scrap's state. The item was not removed.");
				return;
			}
			if (Change(delegate
			{
				record.Cargo.Add(packed);
			}))
			{
				((NetworkBehaviour)val2).NetworkObject.Despawn(true);
				Broadcast();
				CheckpointShip();
				Notice(player.actualClientId, "Packed " + record.Cargo.Count + "/6. Press Q to seal.");
			}
		}

		private static GrabbableObject VaultTarget(PlayerControllerB player)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)player.gameplayCamera).transform;
			int num = Round.collidersAndRoomMaskAndDefault | LayerMask.GetMask(new string[3] { "Props", "PhysicsObject", "Default" });
			foreach (RaycastHit item in from h in Physics.RaycastAll(transform.position, transform.forward, 4f, num, (QueryTriggerInteraction)2)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (!((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)player).transform) && (!((RaycastHit)(ref current)).collider.isTrigger || !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<ScanNodeProperties>())))
				{
					GrabbableObject componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<GrabbableObject>();
					if (!((Object)(object)componentInParent == (Object)(object)player.currentlyHeldObjectServer) && (!((RaycastHit)(ref current)).collider.isTrigger || Object.op_Implicit((Object)(object)componentInParent)))
					{
						return componentInParent;
					}
				}
			}
			return null;
		}

		private void Rift(PlayerControllerB player, GearRecord record, bool secondary)
		{
			//IL_0051: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			if (record.Charges <= 0)
			{
				return;
			}
			if (secondary)
			{
				if (Change(delegate
				{
					record.A = (record.B = null);
				}))
				{
					Broadcast();
				}
				return;
			}
			Vector3 val = ((Component)player).transform.position + Vector3.up * 1.3f + ((Component)player).transform.forward * 1.2f;
			int num = Round.collidersAndRoomMaskAndDefault | LayerMask.GetMask(new string[2] { "Terrain", "MiscLevelGeometry" });
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, Vector3.down, ref val2, 3f, num, (QueryTriggerInteraction)1) || ((RaycastHit)(ref val2)).normal.y < 0.65f)
			{
				Notice(player.actualClientId, "Find clear, stable ground for the portal.");
				return;
			}
			Vector3 val3 = ((RaycastHit)(ref val2)).point + Vector3.up * 0.04f;
			bool flag = InShip(val3);
			Point point = P(flag ? Round.elevatorTransform.InverseTransformPoint(val3) : val3, ((Component)player).transform.eulerAngles.y + 180f - (flag ? Round.elevatorTransform.eulerAngles.y : 0f), (player.isInsideFactory ? 1 : 0) | (flag ? 2 : 0));
			point.Level = Round.currentLevelID;
			point.Seed = Round.randomMapSeed;
			if (!Fits(player, val3))
			{
				Notice(player.actualClientId, "Not enough space for a portal.");
			}
			else if (record.A == null || !record.A.Valid || record.A.Level != point.Level || record.A.Seed != point.Seed)
			{
				if (Change(delegate
				{
					record.A = point;
					record.B = null;
				}))
				{
					Broadcast();
					Notice(player.actualClientId, "First anchor placed. Place the second anywhere on this map.");
				}
			}
			else if (Change(delegate
			{
				record.B = point;
				record.Charges = 0;
				record.Status = TokenStatus.Consumed;
				record.RiftUntil = Now + 90.0;
			}))
			{
				Consume(player, player.currentlyHeldObjectServer);
				Broadcast();
				CheckpointShip();
				Notice(player.actualClientId, "Freight Rift active for 90 seconds.");
			}
		}

		private static bool InShip(Vector3 point)
		{
			//IL_0031: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			object obj = AccessTools.Field(typeof(StartOfRound), "shipInnerRoomBounds")?.GetValue(Round);
			Collider val = (Collider)((obj is Collider) ? obj : null);
			if (val != null)
			{
				Bounds bounds = val.bounds;
				return ((Bounds)(ref bounds)).Contains(point);
			}
			if (obj is Bounds val2)
			{
				return ((Bounds)(ref val2)).Contains(point);
			}
			return false;
		}

		internal Point Resolve(Point point)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			if (point == null)
			{
				return null;
			}
			Vector3 val = V(point);
			float num = point.Yaw;
			if ((point.Flags & 2) != 0 && Object.op_Implicit((Object)(object)Round) && Object.op_Implicit((Object)(object)Round.elevatorTransform))
			{
				val = Round.elevatorTransform.TransformPoint(val);
				num += Round.elevatorTransform.eulerAngles.y;
			}
			return P(val, num, point.Flags);
		}

		private static bool Fits(PlayerControllerB player, Vector3 feet)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			CharacterController thisController = player.thisController;
			if (!Object.op_Implicit((Object)(object)thisController))
			{
				return false;
			}
			float num = Mathf.Max(0f, thisController.height * 0.5f - thisController.radius);
			Vector3 val = feet + ((Component)player).transform.rotation * thisController.center;
			int num2 = Round.collidersAndRoomMaskAndDefault | LayerMask.GetMask(new string[2] { "Terrain", "MiscLevelGeometry" });
			return !Physics.OverlapCapsule(val + Vector3.up * num, val - Vector3.up * num, Mathf.Max(0.02f, thisController.radius - 0.045f), num2, (QueryTriggerInteraction)1).Any((Collider c) => Object.op_Implicit((Object)(object)c) && !((Component)c).transform.IsChildOf(((Component)player).transform));
		}

		private void UseGate(PlayerControllerB player, int serial, int side)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			GearRecord gearRecord = campaign.Find(serial);
			if (gearRecord == null || gearRecord.Kind != GearKind.FreightRift || gearRecord.RiftUntil <= Now || gearRecord.A == null || gearRecord.B == null || side < 0 || side > 1 || gearRecord.A.Level != Round.currentLevelID || gearRecord.A.Seed != Round.randomMapSeed)
			{
				return;
			}
			Point p = Resolve((side == 0) ? gearRecord.A : gearRecord.B);
			Point point = Resolve((side == 0) ? gearRecord.B : gearRecord.A);
			Vector3 val = V(point) + Quaternion.Euler(0f, point.Yaw, 0f) * Vector3.forward * 0.8f;
			Vector3 val2 = ((Component)player).transform.position - V(p);
			if (!(((Vector3)(ref val2)).sqrMagnitude > 16f) && (!lastTravel.TryGetValue(player.actualClientId, out var value) || !(Now - value < 1.0)))
			{
				if (!Fits(player, val))
				{
					Notice(player.actualClientId, "The other portal is obstructed.");
					return;
				}
				lastTravel[player.actualClientId] = Now;
				Event(new NetEvent
				{
					Op = "Travel",
					Player = player.actualClientId,
					Point = P(val, point.Yaw, point.Flags)
				});
			}
		}

		private void UpdateRifts()
		{
			bool flag = false;
			foreach (GearRecord item in campaign.Gear)
			{
				if (item.Kind == GearKind.FreightRift && item.RiftUntil > 0.0 && (!Landed || item.RiftUntil <= Now || item.A == null || item.A.Level != Round.currentLevelID || item.A.Seed != Round.randomMapSeed))
				{
					item.RiftUntil = 0.0;
					item.A = (item.B = null);
					flag = true;
				}
			}
			if (flag)
			{
				Save();
				Broadcast();
			}
		}

		private void UpdateGateModels()
		{
			HashSet<string> wanted = new HashSet<string>();
			if (snapshot != null && Landed)
			{
				foreach (RiftState rift in snapshot.Rifts)
				{
					if (rift.A == null || rift.A.Level != Round.currentLevelID || rift.A.Seed != Round.randomMapSeed)
					{
						continue;
					}
					for (int i = 0; i < 2; i++)
					{
						Point point = ((i == 0) ? rift.A : rift.B);
						if (point != null && point.Valid && (i != 1 || !(rift.Until <= Now)))
						{
							string text = rift.Serial + ":" + i;
							wanted.Add(text);
							if (!gates.ContainsKey(text))
							{
								gates[text] = new PortalView(this, rift.Serial, i, point);
							}
							gates[text].Anchor = point;
							gates[text].SetLink(rift.B != null, rift.Until);
						}
					}
				}
			}
			string[] array = gates.Keys.Where((string k) => !wanted.Contains(k)).ToArray();
			foreach (string key in array)
			{
				gates[key].Dispose();
				gates.Remove(key);
			}
			foreach (PortalView value in gates.Values)
			{
				value.Follow();
			}
		}

		internal static void Travel(PlayerControllerB player, Point point)
		{
			//IL_0097: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (point.Flags & 1) != 0;
			bool flag2 = (point.Flags & 2) != 0;
			player.physicsParent = (player.overridePhysicsParent = (player.lastSyncedPhysicsParent = null));
			if (((NetworkBehaviour)player).IsOwner)
			{
				Round.CurrentPlayerPhysicsRegions.Clear();
			}
			Transform val = (flag2 ? Round.elevatorTransform : Round.playersContainer);
			((Component)player).transform.SetParent(val, true);
			player.parentedToElevatorLastFrame = flag2;
			player.isInsideFactory = flag;
			player.isInElevator = (player.isInHangarShipRoom = flag2);
			player.ResetFallGravity();
			player.TeleportPlayer(V(point), true, point.Yaw - val.eulerAngles.y, false, true);
			player.serverPlayerPosition = player.thisPlayerBody.localPosition;
			GrabbableObject[] itemSlots = player.ItemSlots;
			foreach (GrabbableObject val2 in itemSlots)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					val2.isInFactory = flag;
					player.SetItemInElevator(flag2, flag2, val2);
				}
			}
			if (Object.op_Implicit((Object)(object)player.ItemOnlySlot))
			{
				player.ItemOnlySlot.isInFactory = flag;
				player.SetItemInElevator(flag2, flag2, player.ItemOnlySlot);
			}
		}

		private void Core(PlayerControllerB player, GearRecord record)
		{
			//IL_008b: 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_00a0: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (record.Charges > 0)
			{
				if (Frozen || campaign.CoreDay == DayKey)
				{
					Notice(player.actualClientId, "Time Stop has already been used on this landing.");
				}
				else if (Change(delegate
				{
					record.Charges = 0;
					record.Status = TokenStatus.Consumed;
					campaign.CoreDay = DayKey;
					campaign.FreezeUtc = DateTime.UtcNow.AddSeconds(30.0).Ticks;
				}))
				{
					freezeUntil = Now + 30.0;
					Vector3 p = ((Component)player.gameplayCamera).transform.position + ((Component)player.gameplayCamera).transform.forward;
					Consume(player, player.currentlyHeldObjectServer);
					FreezeController.Tick();
					Event(new NetEvent
					{
						Op = "CorePulse",
						Point = P(p)
					});
					Broadcast();
					CheckpointShip();
					BroadcastNotice("Time Stop active. The day and all creatures are frozen for 30 seconds.");
				}
			}
		}

		private bool CorpseReady(PlayerControllerB player, PlayerControllerB dead)
		{
			//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)
			//IL_0064: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)dead) || !dead.isPlayerDead || !Object.op_Implicit((Object)(object)dead.deadBody) || !net.ConnectedClients.ContainsKey(dead.actualClientId))
			{
				return false;
			}
			DeadBodyInfo body = dead.deadBody;
			Vector3 val = ((Component)player).transform.position - ((Component)body).transform.position;
			if (((Vector3)(ref val)).sqrMagnitude > 16f)
			{
				return false;
			}
			object? obj = AccessTools.Field(((object)body).GetType(), "attachedTo")?.GetValue(body);
			if (Object.op_Implicit((Object)((obj is Object) ? obj : null)))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)body.grabBodyObject) && body.grabBodyObject.isHeld)
			{
				return false;
			}
			if (Physics.Linecast(((Component)player).transform.position + Vector3.up, ((Component)body).transform.position + Vector3.up * 0.4f, Round.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				return false;
			}
			return !Object.FindObjectsOfType<EnemyAI>().Any((EnemyAI e) => Object.op_Implicit((Object)(object)e) && !e.isEnemyDead && (((object)e).GetType().Name == "CadaverBloomAI" || ((object)e).GetType().Name == "AssimilatedEmployee") && Vector3.Distance(((Component)e).transform.position, ((Component)body).transform.position) < 2.5f);
		}

		private void BeginKit(PlayerControllerB player, GearRecord record)
		{
			if (record.Charges > 0)
			{
				PlayerControllerB val = (from p in Round.allPlayerScripts
					where CorpseReady(player, p)
					orderby Vector3.Distance(((Component)p.deadBody).transform.position, ((Component)player).transform.position)
					select p).FirstOrDefault();
				if (!Object.op_Implicit((Object)(object)val))
				{
					Notice(player.actualClientId, "Hold use near an available crewmate's body.");
					return;
				}
				kitChannels[player.actualClientId] = new KitChannel
				{
					Item = record.Serial,
					Target = val.actualClientId,
					Since = Now
				};
				Notice(player.actualClientId, "Charging Last Shift Kit. Keep holding use for five seconds.");
			}
		}

		private void UpdateKitChannels()
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			if (!Landed)
			{
				kitChannels.Clear();
				return;
			}
			KeyValuePair<ulong, KitChannel>[] array = kitChannels.ToArray();
			RaycastHit val4 = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<ulong, KitChannel> keyValuePair = array[i];
				PlayerControllerB val = Player(keyValuePair.Key);
				PlayerControllerB val2 = Player(keyValuePair.Value.Target, deadAllowed: true);
				object obj;
				if (val == null)
				{
					obj = null;
				}
				else
				{
					GrabbableObject currentlyHeldObjectServer = val.currentlyHeldObjectServer;
					obj = ((currentlyHeldObjectServer != null) ? ((Component)currentlyHeldObjectServer).GetComponent<NagroItem>() : null);
				}
				NagroItem nagroItem = (NagroItem)obj;
				if (!Object.op_Implicit((Object)(object)val) || val.isPlayerDead || val.inTerminalMenu || val.inVehicleAnimation || val.isClimbingLadder || val.inSpecialInteractAnimation || !Object.op_Implicit((Object)(object)nagroItem) || nagroItem.Serial != keyValuePair.Value.Item || !CorpseReady(val, val2))
				{
					kitChannels.Remove(keyValuePair.Key);
				}
				else
				{
					if (Now - keyValuePair.Value.Since < 5.0)
					{
						continue;
					}
					GearRecord record = campaign.Find(nagroItem.Serial);
					kitChannels.Remove(keyValuePair.Key);
					if (record != null && record.Charges > 0)
					{
						Vector3 val3 = ((Component)val2.deadBody).transform.position;
						if (Physics.Raycast(val3 + Vector3.up, Vector3.down, ref val4, 3f, Round.collidersAndRoomMaskAndDefault))
						{
							val3 = ((RaycastHit)(ref val4)).point + Vector3.up * 0.05f;
						}
						if (!Fits(val2, val3))
						{
							Notice(keyValuePair.Key, "No safe space to revive this crewmate.");
						}
						else if (Change(delegate
						{
							record.Charges = 0;
							record.Status = TokenStatus.Consumed;
						}))
						{
							Consume(val, val.currentlyHeldObjectServer);
							Event(new NetEvent
							{
								Op = "Revive",
								Player = val2.actualClientId,
								Point = P(val3, ((Component)val).transform.eulerAngles.y, (val.isInsideFactory ? 1 : 0) | (InShip(val3) ? 2 : 0))
							});
							Broadcast();
							CheckpointShip();
						}
					}
				}
			}
		}

		private static void Revive(PlayerControllerB player, Point point)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (!player.isPlayerDead)
			{
				return;
			}
			DeadBodyInfo deadBody = player.deadBody;
			player.ResetPlayerBloodObjects(true);
			player.isPlayerDead = false;
			player.isPlayerControlled = true;
			player.enemyWaitingForBodyRagdoll = null;
			player.setPositionOfDeadPlayer = false;
			player.isClimbingLadder = false;
			player.clampLooking = false;
			player.inVehicleAnimation = false;
			player.overridePoisonValue = false;
			player.disableMoveInput = (player.disableLookInput = (player.disableInteract = false));
			((Collider)player.thisController).enabled = true;
			player.health = 40;
			player.hasBeenCriticallyInjured = (player.criticallyInjured = (player.bleedingHeavily = false));
			player.isSinking = (player.isUnderwater = false);
			player.sinkingValue = 0f;
			player.activatingItem = (player.twoHanded = (player.inShockingMinigame = false));
			player.inSpecialInteractAnimation = (player.freeRotationInInteractAnimation = (player.disableSyncInAnimation = false));
			player.inAnimationWithEnemy = null;
			player.voiceMuffledByEnemy = false;
			player.holdingWalkieTalkie = (player.speakingToWalkieTalkie = false);
			player.externalForceAutoFade = Vector3.zero;
			player.carryWeight = 1f;
			player.overrideGameOverSpectatePivot = null;
			player.parentedToElevatorLastFrame = false;
			player.statusEffectAudio.Stop();
			player.DisableJetpackControlsLocally();
			player.DisablePlayerModel(((Component)player).gameObject, true, true);
			((Behaviour)player.helmetLight).enabled = false;
			player.mapRadarDotAnimator.SetBool("dead", false);
			player.playerBodyAnimator.SetBool("Limp", false);
			player.Crouch(false);
			Travel(player, point);
			if (Object.op_Implicit((Object)(object)deadBody))
			{
				if (Object.op_Implicit((Object)(object)deadBody.grabBodyObject) && ((NetworkBehaviour)deadBody.grabBodyObject).IsServer && ((NetworkBehaviour)deadBody.grabBodyObject).IsSpawned)
				{
					((NetworkBehaviour)deadBody.grabBodyObject).NetworkObject.Despawn(true);
				}
				Object.Destroy((Object)(object)((Component)deadBody).gameObject);
			}
			player.deadBody = null;
			Round.livingPlayers = Round.allPlayerScripts.Count((PlayerControllerB p) => Object.op_Implicit((Object)(object)p) && p.isPlayerControlled && !p.isPlayerDead);
			Round.allPlayersDead = false;
			if (((NetworkBehaviour)player).IsOwner)
			{
				player.hasBegunSpectating = false;
				player.spectatedPlayerScript = null;
				player.hinderedMultiplier = 1f;
				player.isMovementHindered = 0;
				player.sourcesCausingSinking = 0;
				HUDManager.Instance.RemoveSpectateUI();
				HUDManager.Instance.gameOverAnimator.SetTrigger("revive");
				HUDManager.Instance.UpdateHealthUI(40, false);
				HUDManager.Instance.SetCracksOnVisor(40f);
				HUDManager.Instance.cadaverFilter = 0f;
				((Behaviour)HUDManager.Instance.audioListenerLowPass).enabled = false;
				Round.SetSpectateCameraToGameOverMode(false, player);
			}
			AccessTools.Method(typeof(StartOfRound), "UpdatePlayerVoiceEffects", (Type[])null, (Type[])null)?.Invoke(Round, null);
		}

		private void RestoreCounterLayers()
		{
			foreach (KeyValuePair<GameObject, int> counterLayer in counterLayers)
			{
				if (Object.op_Implicit((Object)(object)counterLayer.Key))
				{
					counterLayer.Key.layer = counterLayer.Value;
				}
			}
			counterLayers.Clear();
		}

		private void UpdateCounterPickup()
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			RestoreCounterLayers();
			PlayerControllerB player = Local;
			if (!Object.op_Implicit((Object)(object)player) || player.isPlayerDead || Object.op_Implicit((Object)(object)player.currentlyHeldObjectServer) || !Company || !Landed || snapshot == null || !Object.op_Implicit((Object)(object)net) || net.SpawnManager == null)
			{
				return;
			}
			Transform camera = ((Component)player.gameplayCamera).transform;
			if (!snapshot.Gear.Any((GearState g) => g.Kind <= 1 && net.SpawnManager.SpawnedObjects.TryGetValue(g.Object, out var value) && Object.op_Implicit((Object)(object)value) && Vector3.Distance(camera.position, ((Component)value).transform.position) < player.grabDistance + 0.5f))
			{
				return;
			}
			DepositItemsDesk val = Object.FindObjectOfType<DepositItemsDesk>();
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.triggerScript))
			{
				return;
			}
			Collider[] deskColliders = ((Component)val.triggerScript).GetComponentsInChildren<Collider>().Concat((IEnumerable<Collider>)(object)new Collider[1] { (Collider)val.triggerCollider }).ToArray();
			int num = 0x40000340 | Round.collidersAndRoomMaskAndDefault;
			RaycastHit val2 = ((IEnumerable<RaycastHit>)(from h in Physics.RaycastAll(camera.position, camera.forward, player.grabDistance, num, (QueryTriggerInteraction)2)
				orderby ((RaycastHit)(ref h)).distance
				select h)).FirstOrDefault((Func<RaycastHit, bool>)((RaycastHit h) => !deskColliders.Contains(((RaycastHit)(ref h)).collider) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref h)).collider).GetComponent<ScanNodeProperties>())));
			NagroItem nagroItem = (Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider) ? ((Component)((RaycastHit)(ref val2)).collider).GetComponent<NagroItem>() : null);
			if (!Object.op_Implicit((Object)(object)nagroItem) || nagroItem.Kind > GearKind.SuperToken || !Object.op_Implicit((Object)(object)nagroItem.Prop) || nagroItem.Prop.isHeld)
			{
				return;
			}
			Collider[] array = deskColliders;
			foreach (Collider val3 in array)
			{
				if (Object.op_Implicit((Object)(object)val3) && !counterLayers.ContainsKey(((Component)val3).gameObject))
				{
					counterLayers.Add(((Component)val3).gameObject, ((Component)val3).gameObject.layer);
					((Component)val3).gameObject.layer = 2;
				}
			}
		}

		internal void RegisterItems()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)definitions[0]))
			{
				FreezeController.Install(harmony);
				Item val = ((IEnumerable<Item>)Resources.FindObjectsOfTypeAll<Item>()).FirstOrDefault((Func<Item, bool>)((Item x) => Object.op_Implicit((Object)(object)x) && ((Object)x).name == "MetalSheet" && Object.op_Implicit((Object)(object)x.spawnPrefab) && Object.op_Implicit((Object)(object)x.spawnPrefab.GetComponent<PhysicsProp>())));
				if (!Object.op_Implicit((Object)(object)val))
				{
					throw new InvalidOperationException("Vanilla PhysicsProp template is missing.");
				}
				for (int num = 0; num < definitions.Length; num++)
				{
					GearKind gearKind = (GearKind)num;
					string text = "Nagrodomad" + gearKind;
					GameObject val2 = NetworkPrefabs.CloneNetworkPrefab(val.spawnPrefab, text);
					((Object)val2).hideFlags = (HideFlags)0;
					val2.transform.localScale = Vector3.one;
					Item val3 = Object.Instantiate<Item>(val);
					((Object)val3).name = text;
					val3.itemName = Rules.GearNames[num];
					val3.spawnPrefab = val2;
					val3.itemId = 62000 + num;
					val3.isScrap = false;
					val3.creditsWorth = (val3.minValue = (val3.maxValue = 0));
					val3.requiresBattery = false;
					val3.itemIsTrigger = false;
					val3.automaticallySetUsingPower = gearKind == GearKind.LastShiftKit;
					val3.weight = ((gearKind == GearKind.GravityVault) ? 1.1f : 1.005f);
					val3.twoHanded = (val3.twoHandedAnimation = false);
					val3.disallowUtilitySlot = true;
					val3.itemSpawnsOnGround = true;
					val3.canBeGrabbedBeforeGameStart = true;
					val3.usableInSpecialAnimations = false;
					val3.holdButtonUse = gearKind == GearKind.LastShiftKit;
					val3.syncUseFunction = false;
					val3.syncInteractLRFunction = false;
					val3.saveItemVariable = true;
					val3.meshVariants = Array.Empty<Mesh>();
					val3.materialVariants = Array.Empty<Material>();
					val3.positionOffset = new Vector3(0.02f, -0.02f, 0.07f);
					val3.rotationOffset = new Vector3(0f, 0f, 0f);
					val3.toolTips = ((gearKind <= GearKind.SuperToken) ? new string[1] { "Insert into Prize-O-Matic : [E]" } : (gearKind switch
					{
						GearKind.LastShiftKit => new string[1] { "Revive crewmate : [Hold LMB]" }, 
						GearKind.FreightRift => new string[2] { "Place portal anchor : [LMB]", "Clear first anchor : [Q]" }, 
						GearKind.GravityVault => new string[2] { "Pack scrap : [LMB]", "Seal / unpack : [Q]" }, 
						_ => new string[1] { "Stop time for 30 seconds : [LMB]" }, 
					}));
					GrabbableObject component = val2.GetComponent<GrabbableObject>();
					component.itemProperties = val3;
					component.grabbable = true;
					component.useCooldown = 0.2f;
					val2.tag = "PhysicsProp";
					NagroItem nagroItem = val2.AddComponent<NagroItem>();
					nagroItem.Kind = gearKind;
					nagroItem.Weight = val3.weight;
					Models.BuildItem(val2, gearKind, val3);
					Texture2D val4 = Models.Texture((num < 2) ? (((num == 0) ? "RewardToken" : "SuperToken") + "-Icon.png") : (gearKind.ToString() + "-Icon.png"));
					val3.itemIcon = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f));
					Items.RegisterItem(val3);
					definitions[num] = val3;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered " + val3.itemName));
				}
			}
		}

		internal GrabbableObject Spawn(GearRecord record, Vector3 position, bool ship, bool inside)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			Item val = ((record.Kind == GearKind.CompanyReward) ? CompanyItem(record.External) : definitions[(int)record.Kind]);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.spawnPrefab))
			{
				throw new InvalidOperationException("Reward definition unavailable.");
			}
			GameObject obj = Object.Instantiate<GameObject>(val.spawnPrefab, position, Quaternion.Euler(val.restingRotation), ship ? Round.elevatorTransform : null);
			((Object)obj).hideFlags = (HideFlags)0;
			GrabbableObject component = obj.GetComponent<GrabbableObject>();
			NagroItem component2 = obj.GetComponent<NagroItem>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.Serial = record.Serial;
			}
			component.isInShipRoom = (component.isInElevator = ship);
			component.isInFactory = inside;
			component.SetScrapValue(0);
			if (val.requiresBattery)
			{
				component.insertedBattery = new Battery(false, 1f);
			}
			((NetworkBehaviour)component).NetworkObject.Spawn(false);
			live[record.Serial] = component;
			return component;
		}

		private bool RegisterExternalGear(NagroItem item)
		{
			if (!Object.op_Implicit((Object)(object)item) || item.Serial != 0 || item.Kind < GearKind.GravityVault || item.Kind > GearKind.OvertimeCore || !Object.op_Implicit((Object)(object)item.Prop) || !((NetworkBehaviour)item.Prop).IsSpawned || !Object.op_Implicit((Object)(object)definitions[(int)item.Kind]) || !Object.op_Implicit((Object)(object)item.Prop.itemProperties) || (Object)(object)item.Prop.itemProperties.spawnPrefab != (Object)(object)definitions[(int)item.Kind].spawnPrefab)
			{
				return false;
			}
			GearRecord record = null;
			if (!Change(delegate
			{
				record = campaign.Add(item.Kind);
				record.Claimed = true;
			}))
			{
				return false;
			}
			item.Serial = record.Serial;
			live[record.Serial] = item.Prop;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered externally spawned equipment: " + item.Kind.ToString() + ", serial " + item.Serial));
			return true;
		}

		private Item CompanyItem(string name)
		{
			return ((IEnumerable<Item>)Round?.allItemsList?.itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && i.itemName == name && Object.op_Implicit((Object)(object)i.spawnPrefab) && ((Object)i.spawnPrefab).name.StartsWith("Saltanis", StringComparison.Ordinal)));
		}

		internal void Consume(PlayerControllerB player, GrabbableObject prop)
		{
			int num = Array.IndexOf(player.ItemSlots, prop);
			if (num < 0)
			{
				throw new InvalidOperationException("Reward item is not in the player's inventory.");
			}
			NetEvent value = new NetEvent
			{
				Op = "Consume",
				Player = player.actualClientId,
				Object = ((NetworkBehaviour)prop).NetworkObjectId,
				Slot = num,
				Weight = CarryWeight(prop)
			};
			SendEvent(value);
			RemoveFromHands(player, value);
		}

		private static void RemoveFromHands(PlayerControllerB player, NetEvent value)
		{
			if (player.ItemSlots == null || value.Slot < 0 || value.Slot >= player.ItemSlots.Length)
			{
				return;
			}
			GrabbableObject val = player.ItemSlots[value.Slot];
			if (Object.op_Implicit((Object)(object)val) && ((NetworkBehaviour)val).NetworkObjectId != value.Object)
			{
				return;
			}
			if (player.currentItemSlot == value.Slot)
			{
				player.isHoldingObject = false;
				player.twoHanded = false;
				player.activatingItem = false;
				if (Object.op_Implicit((Object)(object)val) && ((NetworkBehaviour)player).IsOwner)
				{
					val.DiscardItemOnClient();
				}
				player.currentlyHeldObjectServer = null;
				if (Object.op_Implicit((Object)(object)player.playerBodyAnimator))
				{
					player.playerBodyAnimator.SetBool("cancelHolding", true);
					player.playerBodyAnimator.SetTrigger("Throw");
				}
				if (((NetworkBehaviour)player).IsOwner && Object.op_Implicit((Object)(object)HUDManager.Instance))
				{
					((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
					HUDManager.Instance.ClearControlTips();
				}
			}
			player.ItemSlots[value.Slot] = null;
			player.carryWeight = Mathf.Clamp(player.carryWeight - (value.Weight - 1f), 1f, 10f);
			if (((NetworkBehaviour)player).IsOwner && Object.op_Implicit((Object)(object)HUDManager.Instance))
			{
				((Behaviour)HUDManager.Instance.itemSlotIcons[value.Slot]).enabled = false;
			}
			if (Object.op_Implicit((Object)(object)val) && ((NetworkBehaviour)val).IsServer && ((NetworkBehaviour)val).IsSpawned)
			{
				((NetworkBehaviour)val).NetworkObject.Despawn(true);
			}
		}

		internal void CheckpointShip()
		{
			if (!Server || !Object.op_Implicit((Object)(object)GameNetworkManager.Instance) || !Object.op_Implicit((Object)(object)Round))
			{
				return;
			}
			List<GrabbableObject> list = new List<GrabbableObject>();
			try
			{
				GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
				foreach (GrabbableObject val in array)
				{
					if (!val.isInShipRoom && (!Object.op_Implicit((Object)(object)val.playerHeldBy) || !val.playerHeldBy.isInHangarShipRoom) && !val.deactivated)
					{
						val.deactivated = true;
						list.Add(val);
					}
				}
				AccessTools.Method(typeof(GameNetworkManager), "SaveItemsInShip", (Type[])null, (Type[])null).Invoke(GameNetworkManager.Instance, null);
			}
			finally
			{
				foreach (GrabbableObject item in list)
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						item.deactivated = false;
					}
				}
			}
		}

		internal static float CarryWeight(GrabbableObject prop)
		{
			if (!Object.op_Implicit((Object)(object)prop))
			{
				return 1f;
			}
			NagroItem component = ((Component)prop).GetComponent<NagroItem>();
			if (Object.op_Implicit((Object)(object)component) && component.Kind == GearKind.GravityVault)
			{
				return Mathf.Max(1.1f, component.Weight);
			}
			if (companyWeight == null)
			{
				Type type = (from a in AppDomain.CurrentDomain.GetAssemblies()
					select a.GetType("PrzedmiotyKompanii.CompanyItemsPlugin", throwOnError: false)).FirstOrDefault((Type t) => t != null);
				MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "CarryWeight", (Type[])null, (Type[])null));
				if (methodInfo != null)
				{
					companyWeight = (Func<GrabbableObject, float>)Delegate.CreateDelegate(typeof(Func<GrabbableObject, float>), methodInfo);
				}
			}
			if (companyWeight == null)
			{
				return prop.itemProperties.weight;
			}
			return companyWeight(prop);
		}

		private static float VaultWeight(GearRecord record)
		{
			if (record.Kind != GearKind.GravityVault)
			{
				return 1.005f;
			}
			return 1.1f + record.Cargo.Sum((Cargo c) => Mathf.Max(0f, c.Weight - 1f)) * (record.Open ? 1f : 0.25f);
		}

		private void Bind()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			messages = net.CustomMessagingManager;
			if (Server)
			{
				messages.RegisterNamedMessageHandler("saltanis.nagrodomad/1/request", new HandleNamedMessageDelegate(ReceiveRequest));
				return;
			}
			messages.RegisterNamedMessageHandler("saltanis.nagrodomad/1/state", new HandleNamedMessageDelegate(ReceiveState));
			messages.RegisterNamedMessageHandler("saltanis.nagrodomad/1/event", new HandleNamedMessageDelegate(ReceiveEvent));
		}

		private void Unbind()
		{
			GearEffects.Clear();
			restoredCargo.Clear();
			cargoMetadata.Clear();
			RestoreCounterLayers();
			if (messages != null)
			{
				messages.UnregisterNamedMessageHandler("saltanis.nagrodomad/1/request");
				messages.UnregisterNamedMessageHandler("saltanis.nagrodomad/1/state");
				messages.UnregisterNamedMessageHandler("saltanis.nagrodomad/1/event");
				messages = null;
				lastRequest.Clear();
				holds.Clear();
				leverHolds.Clear();
			}
		}

		private static string Read(FastBufferReader reader, int max)
		{
			if (((FastBufferReader)(ref reader)).Length < 4 || ((FastBufferReader)(ref reader)).Length > max * 2 + 16)
			{
				return null;
			}
			try
			{
				string text = default(string);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				return (text != null && text.Length <= max) ? text : null;
			}
			catch
			{
				return null;
			}
		}

		private unsafe void Packet(string name, object value, ulong? target = null)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (messages == null || !Object.op_Implicit((Object)(object)net) || !net.IsListening)
			{
				return;
			}
			string text = JsonConvert.SerializeObject(value, JsonSettings);
			if (text.Length > 60000)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Reward network snapshot exceeded its limit.");
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(text.Length * 2 + 16, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
				if (target.HasValue)
				{
					messages.SendNamedMessage(name, target.Value, val, (NetworkDelivery)4);
					return;
				}
				foreach (ulong connectedClientsId in net.ConnectedClientsIds)
				{
					if (connectedClientsId != net.LocalClientId)
					{
						messages.SendNamedMessage(name, connectedClientsId, val, (NetworkDelivery)4);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal void Send(Request request)
		{
			if (Server)
			{
				HandleRequest(net.LocalClientId, request);
			}
			else
			{
				Packet("saltanis.nagrodomad/1/request", request, 0uL);
			}
		}

		private void ReceiveRequest(ulong sender, FastBufferReader reader)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!Server || !net.ConnectedClients.ContainsKey(sender))
			{
				return;
			}
			string text = Read(reader, 1024);
			if (text == null)
			{
				return;
			}
			try
			{
				Request request = JsonConvert.DeserializeObject<Request>(text, JsonSettings);
				if (request != null && request.Protocol == 1)
				{
					HandleRequest(sender, request);
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Rejected malformed request: " + ex.Message));
			}
		}

		internal void Han