Decompiled source of NaughtyOrNice v0.1.0

Presents.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.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using HolidayShared;
using Microsoft.CodeAnalysis;
using ModMenu;
using Presents.Rules;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HolidayShared
{
	internal enum ChristmasMode
	{
		Auto,
		On,
		Off
	}
	internal static class Season
	{
		internal static bool IsChristmas(DateTime day)
		{
			if (day.Month != 12)
			{
				if (day.Month == 1)
				{
					return day.Day <= 6;
				}
				return false;
			}
			return true;
		}

		internal static bool Decide(ChristmasMode mode, DateTime today)
		{
			return mode switch
			{
				ChristmasMode.Auto => IsChristmas(today), 
				ChristmasMode.On => true, 
				_ => false, 
			};
		}

		internal static DateTime Today(string testDate, DateTime now, out bool overridden)
		{
			overridden = TryParse(testDate, now, out var day);
			if (!overridden)
			{
				return now.Date;
			}
			return day;
		}

		internal static bool TryParse(string testDate, DateTime now, out DateTime day)
		{
			day = default(DateTime);
			string text = (testDate ?? "").Trim();
			if (text.Length == 0)
			{
				return false;
			}
			if (DateTime.TryParseExact(text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out day))
			{
				return true;
			}
			if (DateTime.TryParseExact(now.Year + "-" + text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out day))
			{
				return true;
			}
			return false;
		}

		internal static string Why(ChristmasMode mode, DateTime today, bool overridden)
		{
			switch (mode)
			{
			case ChristmasMode.On:
				return "set to On";
			case ChristmasMode.Off:
				return "set to Off";
			default:
			{
				string text = today.ToString("d MMM", CultureInfo.InvariantCulture) + (overridden ? " (test date)" : "");
				if (!IsChristmas(today))
				{
					return "Auto, " + text + " is outside 1 Dec to 6 Jan";
				}
				return "Auto, " + text + " is in 1 Dec to 6 Jan";
			}
			}
		}
	}
	internal sealed class Holiday
	{
		internal readonly ConfigEntry<ChristmasMode> Mode;

		internal readonly ConfigEntry<string> TestDate;

		private readonly string _tag;

		private readonly ManualLogSource _log;

		private readonly Action _broadcast;

		private readonly string _msgAsk;

		private readonly string _msgState;

		private NetworkManager _nm;

		private bool _ownRegistered;

		private bool _decided;

		private bool _hostOn;

		private bool _hostKnown;

		private bool _hostWord;

		private bool _last;

		private string _why = "not in a lobby";

		private float _nextDateCheck;

		private float _nextAsk;

		private int _asks;

		private bool _wasLanded;

		internal bool On
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
				{
					return false;
				}
				if (singleton.IsServer)
				{
					if (!_decided)
					{
						Decide("lobby opened");
					}
					return _hostOn;
				}
				if (_hostKnown)
				{
					return _hostWord;
				}
				return false;
			}
		}

		internal string Why
		{
			get
			{
				if (!IsClient)
				{
					return _why;
				}
				if (!_hostKnown)
				{
					return "no word from the host";
				}
				return "the host's word";
			}
		}

		internal bool IsClient
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening)
				{
					return !singleton.IsServer;
				}
				return false;
			}
		}

		internal bool IsHost
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening)
				{
					return singleton.IsServer;
				}
				return false;
			}
		}

		internal byte Field => On ? ((byte)1) : ((byte)0);

		internal event Action<bool> Changed;

		internal Holiday(ConfigFile config, ManualLogSource log, string tag, Action broadcast = null)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			_tag = tag;
			_log = log;
			_broadcast = broadcast;
			_msgAsk = tag + ".Xmas.Ask";
			_msgState = tag + ".Xmas";
			Mode = config.Bind<ChristmasMode>("Holiday", "Christmas", ChristmasMode.Auto, "Christmas decorations. Auto: on from 1 December to 6 January by the host's date. On or Off: always. The host's setting counts for everyone; a client follows the host, and stays off when the host doesn't have it.");
			TestDate = config.Bind<string>("Holiday", "ChristmasTestDate", "", "Testing: the date Auto pretends it is, as 2026-12-24 or 12-24 (this year). Blank uses the real date.");
			Mode.SettingChanged += delegate
			{
				Decide("Christmas set to " + Mode.Value);
			};
			TestDate.SettingChanged += delegate
			{
				Decide("test date " + (string.IsNullOrWhiteSpace(TestDate.Value) ? "cleared" : TestDate.Value));
			};
			GameObject val = new GameObject("HolidayRunner." + tag)
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<HolidayRunner>().Holiday = this;
		}

		internal void WriteField(FastBufferWriter w)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			byte field = Field;
			((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref field, default(ForPrimitives));
		}

		internal void ReadField(FastBufferReader r)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref r)).Position + 1 <= ((FastBufferReader)(ref r)).Length)
			{
				byte b = default(byte);
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
				FromHost((b & 1) != 0);
			}
			else
			{
				FromHost(null);
			}
		}

		internal void FromHost(bool? on)
		{
			if (IsClient)
			{
				bool num = _hostKnown != on.HasValue || _hostWord != (on == true);
				_hostKnown = on.HasValue;
				_hostWord = on == true;
				if (num)
				{
					_log.LogInfo((object)(_tag + ": Christmas " + ((on == true) ? "on" : "off") + ", " + (on.HasValue ? "the host's word" : "the host sends no Christmas field") + "."));
				}
				Refresh();
			}
		}

		internal void Decide(string reason)
		{
			if (!IsHost)
			{
				return;
			}
			bool overridden;
			DateTime today = Season.Today(TestDate.Value, DateTime.Now, out overridden);
			bool flag = Season.Decide(Mode.Value, today);
			_why = Season.Why(Mode.Value, today, overridden);
			bool flag2 = !_decided;
			bool num = flag2 || flag != _hostOn;
			_decided = true;
			_hostOn = flag;
			if (num)
			{
				_log.LogInfo((object)(_tag + ": Christmas " + (flag ? "on" : "off") + " (" + _why + "; " + reason + ")."));
				Refresh();
				if (!flag2)
				{
					Broadcast();
				}
			}
		}

		internal void Broadcast()
		{
			if (!IsHost)
			{
				return;
			}
			if (_broadcast != null)
			{
				try
				{
					_broadcast();
					return;
				}
				catch (Exception ex)
				{
					_log.LogWarning((object)(_tag + ": Christmas broadcast: " + ex.Message));
					return;
				}
			}
			foreach (ulong connectedClientsId in NetworkManager.Singleton.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L)
				{
					SendState(connectedClientsId);
				}
			}
		}

		internal void Tick()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				if ((Object)(object)_nm != (Object)null)
				{
					EndSession();
				}
				Refresh();
				return;
			}
			if ((Object)(object)singleton != (Object)(object)_nm)
			{
				if ((Object)(object)_nm != (Object)null)
				{
					EndSession();
				}
				_nm = singleton;
			}
			if (_broadcast == null)
			{
				TickOwnMessage(singleton);
			}
			if (singleton.IsServer)
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					bool shipHasLanded = instance.shipHasLanded;
					if (shipHasLanded && !_wasLanded)
					{
						Decide("landing");
					}
					else if (instance.inShipPhase && Time.unscaledTime >= _nextDateCheck)
					{
						_nextDateCheck = Time.unscaledTime + 10f;
						Decide("in orbit");
					}
					_wasLanded = shipHasLanded;
				}
				else if (!_decided)
				{
					Decide("lobby opened");
				}
			}
			Refresh();
		}

		private void EndSession()
		{
			if (_ownRegistered && (Object)(object)_nm != (Object)null && _nm.CustomMessagingManager != null)
			{
				try
				{
					_nm.CustomMessagingManager.UnregisterNamedMessageHandler(_msgAsk);
				}
				catch
				{
				}
				try
				{
					_nm.CustomMessagingManager.UnregisterNamedMessageHandler(_msgState);
				}
				catch
				{
				}
			}
			_nm = null;
			_ownRegistered = false;
			_decided = false;
			_hostOn = false;
			_hostKnown = false;
			_hostWord = false;
			_why = "not in a lobby";
			_nextDateCheck = 0f;
			_nextAsk = 0f;
			_asks = 0;
			_wasLanded = false;
		}

		private void Refresh()
		{
			bool flag = On;
			if (flag == _last)
			{
				return;
			}
			_last = flag;
			Action<bool> action = this.Changed;
			if (action == null)
			{
				return;
			}
			Delegate[] invocationList = action.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<bool> action2 = (Action<bool>)invocationList[i];
				try
				{
					action2(flag);
				}
				catch (Exception arg)
				{
					_log.LogError((object)string.Format("{0}: Christmas {1} handler: {2}", _tag, flag ? "on" : "off", arg));
				}
			}
		}

		private void TickOwnMessage(NetworkManager nm)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (!_ownRegistered)
			{
				CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
				if (nm.IsServer)
				{
					customMessagingManager.RegisterNamedMessageHandler(_msgAsk, (HandleNamedMessageDelegate)delegate(ulong sender, FastBufferReader r)
					{
						SendState(sender);
					});
				}
				else
				{
					customMessagingManager.RegisterNamedMessageHandler(_msgState, (HandleNamedMessageDelegate)delegate(ulong sender, FastBufferReader r)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						ReadField(r);
					});
				}
				_ownRegistered = true;
			}
			if (!nm.IsServer && nm.IsConnectedClient && !_hostKnown && !(Time.unscaledTime < _nextAsk))
			{
				_nextAsk = Time.unscaledTime + ((_asks < 10) ? 3f : 15f);
				_asks++;
				Send(_msgAsk, 0uL, null);
			}
		}

		private void SendState(ulong to)
		{
			Send(_msgState, to, WriteField);
		}

		private static void Send(string name, ulong to, Action<FastBufferWriter> write)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, 64);
			try
			{
				write?.Invoke(val);
				singleton.CustomMessagingManager.SendNamedMessage(name, to, val, (NetworkDelivery)3);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}
	}
	internal sealed class HolidayRunner : MonoBehaviour
	{
		internal Holiday Holiday;

		private float _next;

		private void Update()
		{
			if (Holiday == null || Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 0.25f;
			try
			{
				Holiday.Tick();
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Holiday tick: " + ex.Message));
			}
		}
	}
	internal static class HolidayMenu
	{
		private static readonly ChristmasMode[] Modes = new ChristmasMode[3]
		{
			ChristmasMode.Auto,
			ChristmasMode.On,
			ChristmasMode.Off
		};

		private static readonly string[] ModeNames = new string[3] { "Auto", "On", "Off" };

		private static readonly string[] DateNames = new string[3] { "real date", "24 Dec", "1 Feb" };

		private static readonly string[] Dates = new string[3] { "", "12-24", "02-01" };

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register(string tab, Holiday holiday)
		{
			MenuApi.Choice(tab, "Christmas", ModeNames, (Func<int, string>)((int i) => SetMode(holiday, Modes[i])), true, false, (Func<string>)(() => NotHosting(holiday)), "Auto: 1 Dec to 6 Jan by your date. The host's pick counts for everyone and swaps the decorations now");
			MenuApi.Choice(tab, "Christmas test date", DateNames, (Func<int, string>)((int i) => SetDate(holiday, i)), true, false, (Func<string>)(() => NotHosting(holiday)), "testing: the date Auto pretends it is (ChristmasTestDate), for everyone");
		}

		private static string NotHosting(Holiday h)
		{
			if (!h.IsClient)
			{
				return null;
			}
			return "the host decides";
		}

		private static string SetMode(Holiday h, ChristmasMode mode)
		{
			bool num = h.Mode.Value == mode;
			h.Mode.Value = mode;
			if (num)
			{
				h.Decide("F6 row");
			}
			return Said(h, "Christmas " + mode);
		}

		private static string SetDate(Holiday h, int i)
		{
			bool num = h.TestDate.Value == Dates[i];
			h.TestDate.Value = Dates[i];
			if (num)
			{
				h.Decide("F6 row");
			}
			return Said(h, (i == 0) ? "test date cleared" : ("test date " + DateNames[i]));
		}

		private static string Said(Holiday h, string what)
		{
			if (!h.IsHost)
			{
				return what + ": saved; it counts when you host";
			}
			return what + ": " + (h.On ? "on" : "off") + " for everyone (" + h.Why + ")";
		}
	}
}
namespace Presents
{
	internal static class Assets
	{
		private static AssetBundle _bundle;

		private static Material[] _colours = (Material[])(object)new Material[0];

		private static readonly List<MeshRenderer> Found = new List<MeshRenderer>();

		internal static void Load()
		{
			if ((Object)(object)_bundle != (Object)null)
			{
				return;
			}
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Presents.presents"))
			{
				if (stream == null)
				{
					Plugin.Log.LogWarning((object)"No art bundle in this build: plain boxes.");
					return;
				}
				byte[] array = new byte[stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					if ((num = stream.Read(array, i, array.Length - i)) <= 0)
					{
						break;
					}
				}
				_bundle = AssetBundle.LoadFromMemory(array);
			}
			if ((Object)(object)_bundle == (Object)null)
			{
				Plugin.Log.LogError((object)"The art bundle didn't load: plain boxes.");
				return;
			}
			FxAssets.Bundle = _bundle;
			List<Material> list = new List<Material>();
			while (_bundle.Contains("colours/" + (list.Count + 1)))
			{
				Material val = _bundle.LoadAsset<Material>("colours/" + (list.Count + 1));
				if ((Object)(object)val == (Object)null)
				{
					break;
				}
				list.Add(val);
			}
			_colours = list.ToArray();
			Plugin.V($"Art bundle loaded, {_colours.Length} colourways.");
		}

		internal static Sprite Icon(ItemDef def)
		{
			if (!((Object)(object)_bundle != (Object)null))
			{
				return null;
			}
			return _bundle.LoadAsset<Sprite>("icons/" + def.Model);
		}

		internal static void Colour(Transform model, int lookSeed)
		{
			if ((Object)(object)model == (Object)null || _colours.Length == 0)
			{
				return;
			}
			Material sharedMaterial = _colours[lookSeed % _colours.Length];
			((Component)model).GetComponentsInChildren<MeshRenderer>(true, Found);
			foreach (MeshRenderer item in Found)
			{
				((Renderer)item).sharedMaterial = sharedMaterial;
			}
			Found.Clear();
		}

		internal static void Hold(Vector3 size, bool twoHanded, out Vector3 at, out Vector3 rotation)
		{
			//IL_0007: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ff: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, size.y / 2f, 0f);
			if (twoHanded)
			{
				rotation = new Vector3(0f, 90f, 0f);
				at = -val;
				return;
			}
			Quaternion val2 = Quaternion.Euler(3.72f, 108.4f, 0.29f) * Quaternion.Euler(90f, 0f, 0f);
			if (size.x > size.z)
			{
				val2 *= Quaternion.Euler(0f, 90f, 0f);
			}
			rotation = ((Quaternion)(ref val2)).eulerAngles;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(0f, 0.13f, 0f);
			at = Vector3.Lerp(val3, new Vector3(-0.01f, 0.23f, -0.21f), Mathf.Min(size.x, size.z) / 0.5f) - val2 * val;
		}

		internal static Renderer BuildModel(ItemDef def, Transform parent, out Vector3 size)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			size = def.Size;
			GameObject val = (((Object)(object)_bundle != (Object)null) ? _bundle.LoadAsset<GameObject>("models/" + def.Model) : null);
			if ((Object)(object)val != (Object)null)
			{
				Transform transform = Object.Instantiate<GameObject>(val, parent, false).transform;
				((Object)transform).name = def.Model;
				if (def == Catalog.Socks)
				{
					transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
					transform.localPosition = new Vector3(0f, size.y / 2f, (0f - size.z) / 2f);
				}
				return (Renderer)(object)((Component)transform).GetComponentInChildren<MeshRenderer>(true);
			}
			MeshRenderer result = Box(parent, "Body", new Vector3(0f, size.y * 0.4f, 0f), new Vector3(size.x, size.y * 0.8f, size.z), def.Grey);
			if (def.Kind.HasValue)
			{
				Box(parent, "Lid", new Vector3(0f, size.y * 0.9f, 0f), new Vector3(size.x * 1.04f, size.y * 0.2f, size.z * 1.04f), def.Grey * 1.2f);
			}
			return (Renderer)(object)result;
		}

		private static MeshRenderer Box(Transform parent, string name, Vector3 at, Vector3 size, Color c)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = at;
			obj.transform.localScale = size;
			Material val = new Material(Shader.Find("HDRP/Lit"));
			val.SetColor("_BaseColor", c);
			val.SetFloat("_Smoothness", 0.3f);
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = val;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)1;
			return component;
		}
	}
	public static class Debug
	{
		public static Outcome? ForcedOutcome { get; internal set; }

		public static string ForcedEnemy { get; internal set; }

		public static string Unavailable()
		{
			if (!((Object)(object)StartOfRound.Instance == (Object)null))
			{
				if (!Net.IsHost)
				{
					return "the host decides";
				}
				return null;
			}
			return "join a lobby first";
		}

		public static string UnavailableOffMoon()
		{
			object obj = Unavailable();
			if (obj == null)
			{
				if (!HostSide.OnMoon())
				{
					return "land on a moon first";
				}
				obj = null;
			}
			return (string)obj;
		}

		public static string SpawnPresent(PresentKind kind)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			//IL_005b: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			string text = Unavailable();
			if (text != null)
			{
				return text;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			bool flag = localPlayerController.isInElevator || StartOfRound.Instance.inShipPhase;
			Vector3 at = ((Component)localPlayerController).transform.position + ((Component)localPlayerController).transform.forward * 1.2f + Vector3.up * 0.6f;
			PresentItem presentItem = Spawner.Spawn(kind, at, ((Component)localPlayerController).transform.eulerAngles.y, Random.Range(1, int.MaxValue), flag ? StartOfRound.Instance.elevatorTransform : null);
			if ((Object)(object)presentItem == (Object)null)
			{
				return "that present didn't build";
			}
			((GrabbableObject)presentItem).isInFactory = localPlayerController.isInsideFactory;
			return Catalog.Name(kind) + " spawned";
		}

		public static string ForceOutcome(Outcome? outcome)
		{
			string text = Unavailable();
			if (text != null)
			{
				return text;
			}
			ForcedOutcome = outcome;
			if (!outcome.HasValue)
			{
				return "off";
			}
			return "the next present opened gives " + outcome.Value;
		}

		public static string[] EnemyNames()
		{
			return Enemies.Names();
		}

		public static string ForceEnemy(string enemyType)
		{
			string text = Unavailable();
			if (text != null)
			{
				return text;
			}
			ForcedEnemy = enemyType;
			if (enemyType == null)
			{
				return "off";
			}
			return "hostile presents spawn " + enemyType;
		}

		public static string OpenHeld()
		{
			string text = Unavailable() ?? HostSide.WhyNotOpen();
			if (text != null)
			{
				return text;
			}
			PresentItem presentItem = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer as PresentItem;
			if ((Object)(object)presentItem == (Object)null || presentItem.Opened)
			{
				return "hold a present first";
			}
			HostSide.Accept(presentItem, Net.LocalIdx);
			return "opened";
		}

		public static string FillMoon()
		{
			string text = UnavailableOffMoon();
			if (text != null)
			{
				return text;
			}
			return Spawner.Place((from _ in Enumerable.Range(0, 3)
				select (PresentKind)Random.Range(0, 6)).ToList(), Random.Range(0, int.MaxValue)) + " presents placed";
		}

		public static string ResetHostile()
		{
			string text = Unavailable();
			if (text != null)
			{
				return text;
			}
			HostSide.HostileToday = 0;
			return "hostile count back to 0";
		}

		public static string ShipPresentsToGifts()
		{
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			string text = Unavailable();
			if (text != null)
			{
				return text;
			}
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			Item val = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && (Object)(object)i.spawnPrefab != (Object)null && (Object)(object)i.spawnPrefab.GetComponent<GiftBoxItem>() != (Object)null));
			if ((Object)(object)val == (Object)null)
			{
				return "the game has no Gift box";
			}
			List<int> list = new List<int>();
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			for (int num = 0; num < levels.Length; num++)
			{
				foreach (SpawnableItemWithRarity item in levels[num].spawnableScrap)
				{
					int num2 = itemsList.IndexOf(item.spawnableItem);
					if (num2 >= 0 && item.rarity > 0 && (Object)(object)item.spawnableItem != (Object)(object)val && !Ours(item.spawnableItem))
					{
						list.Add(num2);
					}
				}
			}
			if (list.Count == 0)
			{
				return "no scrap to put inside";
			}
			int num3 = 0;
			int num4 = 0;
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val2 in array)
			{
				if (Ours(val2.itemProperties) && ((NetworkBehaviour)val2).IsSpawned && !val2.deactivated && (val2.isInShipRoom || val2.isInElevator))
				{
					if (val2.isHeld)
					{
						num4++;
						continue;
					}
					Vector3 val3 = ((Component)val2).transform.position + Vector3.up * 0.1f;
					GameObject val4 = Object.Instantiate<GameObject>(val.spawnPrefab, val3, ((Component)val2).transform.rotation, StartOfRound.Instance.elevatorTransform);
					GrabbableObject component = val4.GetComponent<GrabbableObject>();
					component.fallTime = 0f;
					component.isInElevator = (component.isInShipRoom = true);
					component.scrapPersistedThroughRounds = true;
					component.LoadItemSaveData(list[Random.Range(0, list.Count)]);
					component.SetScrapValue(val2.scrapValue);
					val4.GetComponent<NetworkObject>().Spawn(false);
					OutcomeNet.BroadcastKept(component, val2.scrapValue, val3);
					((NetworkBehaviour)val2).NetworkObject.Despawn(true);
					num3++;
				}
			}
			return $"{num3} turned into Gifts" + ((num4 > 0) ? $"; put down the {num4} being held first" : "");
		}

		internal static bool Ours(Item item)
		{
			return Catalog.Items.Any((ItemDef d) => (Object)(object)d.Item != (Object)null && (Object)(object)d.Item == (Object)(object)item);
		}
	}
	internal struct OpenedInfo
	{
		internal PresentItem Item;

		internal PresentKind Kind;

		internal Outcome Outcome;

		internal int LookSeed;

		internal Vector3 Position;

		internal Quaternion Rotation;

		internal PlayerControllerB Opener;
	}
	internal struct RevealInfo
	{
		internal PresentKind Kind;

		internal Outcome Outcome;

		internal int LookSeed;

		internal Vector3 Position;

		internal PlayerControllerB Opener;
	}
	internal struct WarningInfo
	{
		internal int LookSeed;

		internal Vector3 From;

		internal Vector3 Toward;

		internal float Seconds;
	}
	internal struct BuffInfo
	{
		internal Outcome Buff;

		internal PlayerControllerB Player;

		internal float Seconds;
	}
	internal struct HazardInfo
	{
		internal Outcome Hazard;

		internal Vector3 Position;

		internal float Seconds;
	}
	internal static class FxHooks
	{
		internal static event Action<PresentItem> IdleStart;

		internal static event Action<PresentItem> IdleStop;

		internal static event Action<PresentItem, ShakeHint> Shake;

		internal static event Action<PresentItem, float> OpeningProgress;

		internal static event Action<PresentItem> OpeningCancelled;

		internal static event Action<OpenedInfo> Opened;

		internal static event Action<RevealInfo> Revealed;

		internal static event Action<WarningInfo> EnemyWarning;

		internal static event Action<BuffInfo> BuffStart;

		internal static event Action<BuffInfo> BuffEnd;

		internal static event Action<HazardInfo> HazardStart;

		internal static event Action<HazardInfo> HazardEnd;

		internal static void RaiseIdle(PresentItem p, bool on)
		{
			if (on)
			{
				Run(FxHooks.IdleStart, p);
			}
			else
			{
				Run(FxHooks.IdleStop, p);
			}
		}

		internal static void RaiseShake(PresentItem p, ShakeHint h)
		{
			Run(FxHooks.Shake, p, h);
		}

		internal static void RaiseProgress(PresentItem p, float t)
		{
			Run(FxHooks.OpeningProgress, p, t);
		}

		internal static void RaiseCancelled(PresentItem p)
		{
			Run(FxHooks.OpeningCancelled, p);
		}

		internal static void RaiseOpened(OpenedInfo i)
		{
			Run(FxHooks.Opened, i);
		}

		internal static void RaiseRevealed(RevealInfo i)
		{
			Run(FxHooks.Revealed, i);
		}

		internal static void RaiseWarning(WarningInfo i)
		{
			Run(FxHooks.EnemyWarning, i);
		}

		internal static void RaiseBuff(BuffInfo i, bool on)
		{
			if (on)
			{
				Run(FxHooks.BuffStart, i);
			}
			else
			{
				Run(FxHooks.BuffEnd, i);
			}
		}

		internal static void RaiseHazard(HazardInfo i, bool on)
		{
			if (on)
			{
				Run(FxHooks.HazardStart, i);
			}
			else
			{
				Run(FxHooks.HazardEnd, i);
			}
		}

		private static void Run<T>(Action<T> e, T a)
		{
			try
			{
				e?.Invoke(a);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Effect failed: {arg}");
			}
		}

		private static void Run<T, U>(Action<T, U> e, T a, U b)
		{
			try
			{
				e?.Invoke(a, b);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Effect failed: {arg}");
			}
		}
	}
	internal sealed class Opening
	{
		internal PresentKind Kind;

		internal int Seed;

		internal int LookSeed;

		internal Outcome Outcome;

		internal Vector3 Position;

		internal PlayerControllerB Opener;

		internal bool InShip;

		internal bool OnShip;

		internal bool Outside;

		internal Vector3 ShipLocal;

		internal List<Enemies.Plan> Plans;
	}
	internal static class HostSide
	{
		internal static int HostileToday;

		internal static void NewLobby()
		{
			NewDay();
			Debug.ForcedOutcome = null;
			Debug.ForcedEnemy = null;
		}

		internal static void NewDay()
		{
			HostileToday = 0;
			OutcomeHost.Reset();
		}

		internal static bool OnMoon()
		{
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				return WhyNotOpen() == null;
			}
			return false;
		}

		private static bool AtCompany()
		{
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			if (!((Object)(object)currentLevel == (Object)null) && !(currentLevel.sceneName == "CompanyBuilding"))
			{
				return !currentLevel.spawnEnemiesAndScrap;
			}
			return true;
		}

		internal static string WhyNotOpen()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || !instance.shipHasLanded || instance.inShipPhase || instance.shipIsLeaving)
			{
				return "The ribbon won't budge up here.";
			}
			if (!AtCompany())
			{
				return null;
			}
			return "The Company only takes it wrapped.";
		}

		internal static Gates CurrentGates()
		{
			return new Gates(HostileToday < Options.MaxHostilePerDay, Options.EnemiesEnabled, Options.Disabled);
		}

		private static bool Holds(PresentItem p, int player)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = Net.Player(player);
			if ((Object)(object)p != (Object)null && !p.Opened && ((NetworkBehaviour)p).IsSpawned && (Object)(object)val != (Object)null && val.isPlayerControlled && !val.isPlayerDead && ((GrabbableObject)p).isHeld && !((GrabbableObject)p).isPocketed && (Object)(object)((GrabbableObject)p).playerHeldBy == (Object)(object)val)
			{
				return Vector3.Distance(((Component)p).transform.position, ((Component)val).transform.position) < 6f;
			}
			return false;
		}

		internal static void Shake(PresentItem p, int player)
		{
			if (Holds(p, player) && p.Opener < 0 && !p.Shaken)
			{
				p.Shaken = true;
				Net.BroadcastHint(p, player, PresentRules.Hint(p.Kind, p.Seed, CurrentGates(), Options.ShakeAccuracy));
			}
		}

		internal static void OpenStart(PresentItem p, int player)
		{
			if (Holds(p, player) && p.Opener < 0 && WhyNotOpen() == null)
			{
				p.HostStart = Time.realtimeSinceStartup;
				Net.BroadcastOpening(p, player, on: true);
			}
		}

		internal static void OpenCancel(PresentItem p, int player)
		{
			if ((Object)(object)p != (Object)null && !p.Opened && p.Opener == player)
			{
				Net.BroadcastOpening(p, player, on: false);
			}
		}

		internal static void Open(PresentItem p, int player)
		{
			if (!((Object)(object)p == (Object)null) && !p.Opened && p.Opener == player)
			{
				if (!Holds(p, player) || WhyNotOpen() != null || Time.realtimeSinceStartup - p.HostStart < Options.HoldSeconds * 0.9f)
				{
					Net.BroadcastOpening(p, player, on: false);
				}
				else
				{
					Accept(p, player);
				}
			}
		}

		internal static void Accept(PresentItem p, int player)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0199: 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)
			PlayerControllerB val = Net.Player(player);
			bool hasValue = Debug.ForcedOutcome.HasValue;
			Outcome outcome = (hasValue ? Debug.ForcedOutcome.Value : PresentRules.Roll(p.Kind, p.Seed, CurrentGates()));
			Debug.ForcedOutcome = null;
			if (!hasValue && Table.IsHostile(outcome))
			{
				HostileToday++;
			}
			Opening opening = new Opening
			{
				Kind = p.Kind,
				Seed = p.Seed,
				LookSeed = p.LookSeed,
				Outcome = outcome,
				Opener = val,
				Position = ((Component)p).transform.position,
				InShip = (((Object)(object)val != (Object)null) ? val.isInHangarShipRoom : ((GrabbableObject)p).isInShipRoom),
				OnShip = (((Object)(object)val != (Object)null) ? val.isInElevator : ((GrabbableObject)p).isInElevator),
				Outside = (((Object)(object)val != (Object)null) ? (!val.isInsideFactory) : (!((GrabbableObject)p).isInFactory))
			};
			opening.ShipLocal = StartOfRound.Instance.elevatorTransform.InverseTransformPoint(opening.Position);
			OutcomeHost.Prepare(opening);
			p.HostOpenedAt = Time.realtimeSinceStartup;
			Plugin.V(string.Format("{0} opened by player {1}: {2}{3}, hostile today {4}.", p.Kind, player, opening.Outcome, hasValue ? " (forced)" : "", HostileToday));
			Net.BroadcastResult(p, opening.Outcome, opening.Position, ((Component)p).transform.rotation, player);
			OutcomeHost.Begin(opening);
		}

		internal static void Tick()
		{
			OutcomeHost.Tick();
			for (int num = PresentItem.All.Count - 1; num >= 0; num--)
			{
				PresentItem presentItem = PresentItem.All[num];
				if ((Object)(object)presentItem == (Object)null)
				{
					PresentItem.All.RemoveAt(num);
				}
				else if (presentItem.Opened)
				{
					if (Time.realtimeSinceStartup - presentItem.HostOpenedAt > 1f && ((NetworkBehaviour)presentItem).IsSpawned && (!((GrabbableObject)presentItem).isHeld || (Object)(object)((GrabbableObject)presentItem).playerHeldBy == (Object)null) && !((GrabbableObject)presentItem).isHeldByEnemy)
					{
						((NetworkBehaviour)presentItem).NetworkObject.Despawn(true);
					}
				}
				else if (presentItem.Opener >= 0 && (!Holds(presentItem, presentItem.Opener) || WhyNotOpen() != null))
				{
					Net.BroadcastOpening(presentItem, presentItem.Opener, on: false);
				}
			}
		}
	}
	internal static class Net
	{
		private struct State
		{
			internal int Look;

			internal int Value;

			internal int Opener;

			internal float Already;
		}

		private const string P = "Presents.";

		private const string MHello = "Presents.Hello";

		private const string MShake = "Presents.Shake";

		private const string MOpenStart = "Presents.OpenStart";

		private const string MOpenCancel = "Presents.OpenCancel";

		private const string MOpen = "Presents.Open";

		private const string MConfig = "Presents.Config";

		private const string MState = "Presents.State";

		private const string MHint = "Presents.Hint";

		private const string MOpening = "Presents.Opening";

		private const string MResult = "Presents.Result";

		private static CustomMessagingManager _on;

		private static float _nextHello;

		private static readonly Dictionary<ulong, State> _early = new Dictionary<ulong, State>();

		internal static NetworkManager NM => NetworkManager.Singleton;

		internal static bool Online
		{
			get
			{
				if ((Object)(object)NM != (Object)null && NM.IsListening)
				{
					return NM.CustomMessagingManager != null;
				}
				return false;
			}
		}

		internal static bool IsHost
		{
			get
			{
				if (Online)
				{
					return NM.IsServer;
				}
				return false;
			}
		}

		internal static int LocalIdx => IndexOf(((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);

		internal static void Tick()
		{
			if (!Online)
			{
				_on = null;
				_early.Clear();
				Options.HostKnown = false;
				return;
			}
			if (_on != NM.CustomMessagingManager)
			{
				Register();
			}
			if (!NM.IsServer && !Options.HostKnown && NM.IsConnectedClient && (Object)(object)StartOfRound.Instance != (Object)null && Time.realtimeSinceStartup > _nextHello)
			{
				_nextHello = Time.realtimeSinceStartup + 3f;
				ToHost("Presents.Hello", 1, delegate(FastBufferWriter w)
				{
					//IL_0008: 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)
					byte b = 1;
					((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				});
			}
		}

		private static void Register()
		{
			_on = NM.CustomMessagingManager;
			_early.Clear();
			Options.HostKnown = false;
			_nextHello = 0f;
			FromClient("Presents.Hello", delegate(ulong s, FastBufferReader r)
			{
				Hello(s);
			});
			FromClient("Presents.Shake", delegate(ulong s, FastBufferReader r)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				HostSide.Shake(ReadItem(r), PlayerOf(s));
			});
			FromClient("Presents.OpenStart", delegate(ulong s, FastBufferReader r)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				HostSide.OpenStart(ReadItem(r), PlayerOf(s));
			});
			FromClient("Presents.OpenCancel", delegate(ulong s, FastBufferReader r)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				HostSide.OpenCancel(ReadItem(r), PlayerOf(s));
			});
			FromClient("Presents.Open", delegate(ulong s, FastBufferReader r)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				HostSide.Open(ReadItem(r), PlayerOf(s));
			});
			FromHost("Presents.Config", delegate(FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				float hold = default(float);
				((FastBufferReader)(ref r)).ReadValueSafe<float>(ref hold, default(ForPrimitives));
				float warning = default(float);
				((FastBufferReader)(ref r)).ReadValueSafe<float>(ref warning, default(ForPrimitives));
				Options.FromHost(hold, warning);
			});
			FromHost("Presents.State", delegate(FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				ulong num = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref num, default(ForPrimitives));
				ushort look = default(ushort);
				((FastBufferReader)(ref r)).ReadValueSafe<ushort>(ref look, default(ForPrimitives));
				int value = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref value, default(ForPrimitives));
				int opener = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref opener, default(ForPrimitives));
				float already = default(float);
				((FastBufferReader)(ref r)).ReadValueSafe<float>(ref already, default(ForPrimitives));
				State state = new State
				{
					Look = look,
					Value = value,
					Opener = opener,
					Already = already
				};
				PresentItem presentItem = Find(num);
				if ((Object)(object)presentItem != (Object)null)
				{
					Apply(presentItem, state);
				}
				else
				{
					_early[num] = state;
				}
			});
			FromHost("Presents.Hint", delegate(FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				ulong id = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
				int player = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref player, default(ForPrimitives));
				byte hint = default(byte);
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref hint, default(ForPrimitives));
				PresentItem presentItem = Find(id);
				if ((Object)(object)presentItem != (Object)null)
				{
					presentItem.ApplyHint(player, (ShakeHint)hint);
				}
			});
			FromHost("Presents.Opening", delegate(FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				ulong id = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
				int player = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref player, default(ForPrimitives));
				bool flag = default(bool);
				((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				PresentItem presentItem = Find(id);
				if ((Object)(object)presentItem != (Object)null)
				{
					presentItem.ApplyOpening(player, flag, 0f);
				}
			});
			FromHost("Presents.Result", delegate(FastBufferReader r)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: 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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				ulong id = default(ulong);
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
				byte outcome = default(byte);
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref outcome, default(ForPrimitives));
				Vector3 at = default(Vector3);
				((FastBufferReader)(ref r)).ReadValueSafe(ref at);
				Quaternion rot = default(Quaternion);
				((FastBufferReader)(ref r)).ReadValueSafe(ref rot);
				int idx = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref idx, default(ForPrimitives));
				PresentItem presentItem = Find(id);
				if ((Object)(object)presentItem != (Object)null)
				{
					presentItem.ApplyOpened((Outcome)outcome, at, rot, Player(idx));
				}
			});
			OutcomeNet.Register();
		}

		internal static void FromClient(string name, Action<ulong, FastBufferReader> handle)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			_on.RegisterNamedMessageHandler(name, (HandleNamedMessageDelegate)delegate(ulong s, FastBufferReader r)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (IsHost)
				{
					handle(s, r);
				}
			});
		}

		internal static void FromHost(string name, Action<FastBufferReader> handle)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			_on.RegisterNamedMessageHandler(name, (HandleNamedMessageDelegate)delegate(ulong s, FastBufferReader r)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				if (!IsHost && s == 0L)
				{
					handle(r);
				}
			});
		}

		internal static PlayerControllerB Player(int idx)
		{
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array == null || idx < 0 || idx >= array.Length)
			{
				return null;
			}
			return array[idx];
		}

		internal static int IndexOf(PlayerControllerB p)
		{
			if (!((Object)(object)p != (Object)null))
			{
				return -1;
			}
			return (int)p.playerClientId;
		}

		private static int PlayerOf(ulong clientId)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return -1;
			}
			if (clientId == 0L)
			{
				return LocalIdx;
			}
			if (instance.ClientPlayerList == null || !instance.ClientPlayerList.TryGetValue(clientId, out var value))
			{
				return -1;
			}
			return value;
		}

		private static PresentItem Find(ulong id)
		{
			if (!Online || !NM.SpawnManager.SpawnedObjects.TryGetValue(id, out var value) || !((Object)(object)value != (Object)null))
			{
				return null;
			}
			return ((Component)value).GetComponent<PresentItem>();
		}

		private static PresentItem ReadItem(FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ulong id = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			return Find(id);
		}

		internal static void Arrived(PresentItem item)
		{
			if (_early.TryGetValue(((NetworkBehaviour)item).NetworkObjectId, out var value))
			{
				_early.Remove(((NetworkBehaviour)item).NetworkObjectId);
				Apply(item, value);
			}
		}

		private static void Apply(PresentItem item, State st)
		{
			item.ApplyState(st.Look, st.Value);
			if (st.Opener >= 0)
			{
				item.ApplyOpening(st.Opener, on: true, st.Already);
			}
		}

		internal static void SendShake(PresentItem i)
		{
			if (IsHost)
			{
				HostSide.Shake(i, LocalIdx);
			}
			else
			{
				SendId("Presents.Shake", i);
			}
		}

		internal static void SendOpenStart(PresentItem i)
		{
			if (IsHost)
			{
				HostSide.OpenStart(i, LocalIdx);
			}
			else
			{
				SendId("Presents.OpenStart", i);
			}
		}

		internal static void SendOpenCancel(PresentItem i)
		{
			if (IsHost)
			{
				HostSide.OpenCancel(i, LocalIdx);
			}
			else
			{
				SendId("Presents.OpenCancel", i);
			}
		}

		internal static void SendOpen(PresentItem i)
		{
			if (IsHost)
			{
				HostSide.Open(i, LocalIdx);
			}
			else
			{
				SendId("Presents.Open", i);
			}
		}

		private static void SendId(string msg, PresentItem i)
		{
			ulong id = ((NetworkBehaviour)i).NetworkObjectId;
			ToHost(msg, 8, delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
			});
		}

		internal unsafe static void ToHost(string msg, int size, Action<FastBufferWriter> fill)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!Online || IsHost)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(size, (Allocator)2, 4096);
			try
			{
				fill(val);
				NM.CustomMessagingManager.SendNamedMessage(msg, 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal static void ToClients(string msg, int size, Action<FastBufferWriter> fill)
		{
			if (!IsHost)
			{
				return;
			}
			foreach (ulong connectedClientsId in NM.ConnectedClientsIds)
			{
				ToClient(connectedClientsId, msg, size, fill);
			}
		}

		internal unsafe static void ToClient(ulong cid, string msg, int size, Action<FastBufferWriter> fill)
		{
			//IL_001a: 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 (!IsHost || cid == 0L)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(size, (Allocator)2, 4096);
			try
			{
				fill(val);
				NM.CustomMessagingManager.SendNamedMessage(msg, cid, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Hello(ulong cid)
		{
			SendConfig(cid);
			foreach (PresentItem p in PresentItem.All)
			{
				if ((Object)(object)p != (Object)null && ((NetworkBehaviour)p).IsSpawned && !p.Opened)
				{
					ToClient(cid, "Presents.State", 24, delegate(FastBufferWriter w)
					{
						//IL_0000: Unknown result type (might be due to invalid IL or missing references)
						WriteState(w, p);
					});
				}
			}
		}

		private static void SendConfig(ulong cid)
		{
			ToClient(cid, "Presents.Config", 8, delegate(FastBufferWriter w)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: 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)
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref Options.HoldSeconds, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref Options.WarningSeconds, default(ForPrimitives));
			});
		}

		internal static void BroadcastConfig()
		{
			if (!IsHost)
			{
				return;
			}
			foreach (ulong connectedClientsId in NM.ConnectedClientsIds)
			{
				SendConfig(connectedClientsId);
			}
		}

		private static void WriteState(FastBufferWriter w, PresentItem p)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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)
			ulong networkObjectId = ((NetworkBehaviour)p).NetworkObjectId;
			((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
			ushort num = (ushort)p.LookSeed;
			((FastBufferWriter)(ref w)).WriteValueSafe<ushort>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref ((GrabbableObject)p).scrapValue, default(ForPrimitives));
			int opener = p.Opener;
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref opener, default(ForPrimitives));
			float num2 = ((p.Opener >= 0) ? (Time.realtimeSinceStartup - p.HostStart) : 0f);
			((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref num2, default(ForPrimitives));
		}

		internal static void BroadcastState(PresentItem p)
		{
			ToClients("Presents.State", 24, delegate(FastBufferWriter w)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				WriteState(w, p);
			});
		}

		internal static void BroadcastHint(PresentItem p, int player, ShakeHint hint)
		{
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			ToClients("Presents.Hint", 16, delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref player, default(ForPrimitives));
				byte b = (byte)hint;
				((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
			});
			p.ApplyHint(player, hint);
		}

		internal static void BroadcastOpening(PresentItem p, int player, bool on)
		{
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			ToClients("Presents.Opening", 16, delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: 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)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref player, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref on, default(ForPrimitives));
			});
			p.ApplyOpening(player, on, 0f);
		}

		internal static void BroadcastResult(PresentItem p, Outcome outcome, Vector3 at, Quaternion rot, int player)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			ulong id = ((NetworkBehaviour)p).NetworkObjectId;
			ToClients("Presents.Result", 48, delegate(FastBufferWriter w)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				byte b = (byte)outcome;
				((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe(ref at);
				((FastBufferWriter)(ref w)).WriteValueSafe(ref rot);
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref player, default(ForPrimitives));
			});
			p.ApplyOpened(outcome, at, rot, Player(player));
		}
	}
	internal static class Options
	{
		internal static bool YearRound = false;

		internal static double AmountMultiplier = 1.0;

		internal static int[] Weights = Table.DefaultWeights();

		internal static int MaxPerDay = 3;

		internal static float HoldSeconds = 2f;

		internal static double ShakeAccuracy = 0.75;

		internal static double ValueMultiplier = 1.0;

		internal static readonly HashSet<Outcome> Disabled = new HashSet<Outcome>();

		internal static bool EnemiesEnabled = true;

		internal static string Blocklist = "";

		internal static string ExtraTypes = "";

		internal static int MaxHostilePerDay = 3;

		internal static float WarningSeconds = 4f;

		internal static bool ReducedFlash = false;

		internal static bool IdleEffects = true;

		internal static float Volume = 1f;

		internal static bool Verbose = false;

		private static float _hostHold = 2f;

		private static float _hostWarning = 4f;

		internal static bool HostKnown;

		internal static float Hold
		{
			get
			{
				if (!Net.IsHost)
				{
					return _hostHold;
				}
				return HoldSeconds;
			}
		}

		internal static float Warning
		{
			get
			{
				if (!Net.IsHost)
				{
					return _hostWarning;
				}
				return WarningSeconds;
			}
		}

		internal static void Changed()
		{
			Net.BroadcastConfig();
		}

		internal static void FromHost(float hold, float warning)
		{
			_hostHold = hold;
			_hostWarning = warning;
			HostKnown = true;
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void GnmStart()
		{
			try
			{
				Registry.Build();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Presents failed to build: {arg}");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void SorAwake(StartOfRound __instance)
		{
			Registry.AddToItemList(__instance);
			HostSide.NewLobby();
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPostfix]
		private static void ScrapSpawned()
		{
			if (!Net.IsHost)
			{
				return;
			}
			try
			{
				HostSide.NewDay();
				Spawner.PlaceDay();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Placing the presents failed: {arg}");
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "SetScrapValue")]
		[HarmonyPostfix]
		private static void ValueSet(GrabbableObject __instance)
		{
			if (__instance is PresentItem presentItem)
			{
				presentItem.RefreshScan();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesServerRpc")]
		[HarmonyPrefix]
		private static void SyncBegins()
		{
			PresentItem.SyncingToClients = true;
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesServerRpc")]
		[HarmonyFinalizer]
		private static void SyncEnds()
		{
			PresentItem.SyncingToClients = false;
		}
	}
	internal static class Registry
	{
		private static GameObject _container;

		internal static void Build()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			if ((Object)(object)_container != (Object)null)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				Plugin.Log.LogError((object)"No NetworkManager at GameNetworkManager.Start.");
				return;
			}
			List<GrabbableObject> source = (from p in singleton.NetworkConfig.Prefabs.Prefabs
				select (!((Object)(object)p.Prefab != (Object)null)) ? null : p.Prefab.GetComponent<GrabbableObject>() into g
				where (Object)(object)g != (Object)null && (Object)(object)g.itemProperties != (Object)null && (Object)(object)((Component)g).GetComponentInChildren<ScanNodeProperties>(true) != (Object)null && (Object)(object)((Component)g).GetComponent<AudioSource>() != (Object)null
				select g).ToList();
			GrabbableObject val = ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g is GiftBoxItem)) ?? ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g.itemProperties.isScrap));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"No vanilla Gift to base the presents on.");
				return;
			}
			GrabbableObject big = ((IEnumerable<GrabbableObject>)source).FirstOrDefault((Func<GrabbableObject, bool>)((GrabbableObject g) => g is LungProp)) ?? (from g in source
				where g.itemProperties.isScrap && g.itemProperties.twoHanded
				orderby g.itemProperties.weight descending
				select g).FirstOrDefault() ?? val;
			_container = new GameObject("Presents.Prefabs")
			{
				hideFlags = (HideFlags)61
			};
			_container.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)_container);
			ItemDef[] items = Catalog.Items;
			foreach (ItemDef itemDef in items)
			{
				try
				{
					BuildOne(itemDef, val, big, singleton);
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"{itemDef.Key} failed to build: {arg}");
				}
			}
		}

		private static void BuildOne(ItemDef def, GrabbableObject gift, GrabbableObject big, NetworkManager nm)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Presents." + def.Key);
			val.transform.SetParent(_container.transform, false);
			val.layer = ((Component)gift).gameObject.layer;
			val.tag = ((Component)gift).gameObject.tag;
			NetworkObject val2 = val.AddComponent<NetworkObject>();
			val2.AutoObjectParentSync = false;
			val2.DontDestroyWithOwner = true;
			AccessTools.Field(typeof(NetworkObject), "GlobalObjectIdHash").SetValue(val2, StableHash("lukecripwalker.naughtyornice." + def.Key));
			CopyAudio(((Component)gift).GetComponent<AudioSource>(), val);
			GameObject val3 = new GameObject("Model");
			val3.transform.SetParent(val.transform, false);
			Vector3 size;
			Renderer val4 = Assets.BuildModel(def, val3.transform, out size);
			Transform[] componentsInChildren = val3.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = val.layer;
			}
			BoxCollider val5 = val.AddComponent<BoxCollider>();
			val5.center = new Vector3(0f, size.y / 2f, 0f);
			val5.size = size + Vector3.one * 0.04f;
			Collider component = ((Component)gift).GetComponent<Collider>();
			((Collider)val5).isTrigger = (Object)(object)component != (Object)null && component.isTrigger;
			ScanNodeProperties component2 = Object.Instantiate<GameObject>(((Component)((Component)gift).GetComponentInChildren<ScanNodeProperties>(true)).gameObject, val.transform, false).GetComponent<ScanNodeProperties>();
			((Component)component2).transform.localPosition = val5.center;
			component2.headerText = def.Name;
			component2.subText = "Value: $0";
			component2.scrapValue = 0;
			component2.nodeType = 2;
			Item val6 = Object.Instantiate<Item>(gift.itemProperties);
			((Object)val6).name = "Presents" + def.Key;
			val6.itemName = def.Name;
			val6.itemId = def.ItemId;
			val6.spawnPrefab = val;
			val6.isScrap = true;
			val6.twoHanded = def.TwoHanded;
			val6.twoHandedAnimation = def.TwoHanded;
			Assets.Hold(size, def.TwoHanded, out var at, out var rotation);
			val6.positionOffset = at;
			val6.rotationOffset = rotation;
			if (def.TwoHanded)
			{
				val6.grabAnim = big.itemProperties.grabAnim;
				val6.grabAnimationTime = big.itemProperties.grabAnimationTime;
			}
			val6.weight = 1f + def.Pounds / 105f;
			ValueRange valueRange = (def.Kind.HasValue ? Table.ShutRange(def.Kind.Value) : Table.LootRange((def == Catalog.Coal) ? Outcome.P2 : Outcome.P4));
			val6.minValue = Raw(valueRange.Min);
			val6.maxValue = Raw(valueRange.Max);
			val6.creditsWorth = 0;
			val6.canBeGrabbedBeforeGameStart = true;
			val6.itemSpawnsOnGround = true;
			val6.isConductiveMetal = false;
			val6.isDefensiveWeapon = false;
			val6.requiresBattery = false;
			val6.itemIsTrigger = false;
			val6.automaticallySetUsingPower = true;
			val6.holdButtonUse = def.Kind.HasValue;
			val6.syncUseFunction = false;
			val6.syncInteractLRFunction = false;
			val6.saveItemVariable = def.Kind.HasValue;
			val6.meshVariants = (Mesh[])(object)new Mesh[0];
			val6.materialVariants = (Material[])(object)new Material[0];
			val6.spawnPositionTypes = new List<ItemGroup>();
			val6.restingRotation = Vector3.zero;
			val6.floorYOffset = 0;
			val6.verticalOffset = 0.01f;
			val6.toolTips = ((!def.Kind.HasValue) ? new string[0] : new string[2] { "Open (hold) : [LMB]", "Shake : [Q/E]" });
			Sprite val7 = Assets.Icon(def);
			if ((Object)(object)val7 != (Object)null)
			{
				val6.itemIcon = val7;
			}
			GrabbableObject val8;
			if (def.Kind.HasValue)
			{
				PresentItem presentItem = val.AddComponent<PresentItem>();
				presentItem.Kind = def.Kind.Value;
				presentItem.Model = val3.transform;
				val8 = (GrabbableObject)(object)presentItem;
			}
			else
			{
				val8 = (GrabbableObject)(object)val.AddComponent<PhysicsProp>();
			}
			val8.itemProperties = val6;
			val8.grabbable = true;
			val8.grabbableToEnemies = true;
			val8.isInFactory = true;
			val8.mainObjectRenderer = (MeshRenderer)(object)((val4 is MeshRenderer) ? val4 : null);
			def.Prefab = val;
			def.Item = val6;
			nm.AddNetworkPrefab(val);
		}

		private static int Raw(int dollars)
		{
			return Mathf.RoundToInt((float)dollars / 0.4f);
		}

		internal static void AddToItemList(StartOfRound sor)
		{
			if ((Object)(object)sor == (Object)null || (Object)(object)sor.allItemsList == (Object)null || sor.allItemsList.itemsList == null)
			{
				return;
			}
			ItemDef[] items = Catalog.Items;
			foreach (ItemDef itemDef in items)
			{
				if ((Object)(object)itemDef.Item != (Object)null && !sor.allItemsList.itemsList.Contains(itemDef.Item))
				{
					sor.allItemsList.itemsList.Add(itemDef.Item);
				}
			}
		}

		private static void CopyAudio(AudioSource src, GameObject go)
		{
			//IL_0027: 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_005c: Invalid comparison between Unknown and I4
			AudioSource val = go.AddComponent<AudioSource>();
			val.playOnAwake = false;
			val.outputAudioMixerGroup = src.outputAudioMixerGroup;
			val.spatialBlend = 1f;
			val.rolloffMode = src.rolloffMode;
			val.minDistance = src.minDistance;
			val.maxDistance = src.maxDistance;
			val.dopplerLevel = src.dopplerLevel;
			if ((int)src.rolloffMode == 2)
			{
				val.SetCustomCurve((AudioSourceCurveType)0, src.GetCustomCurve((AudioSourceCurveType)0));
			}
		}

		private static uint StableHash(string s)
		{
			using MD5 mD = MD5.Create();
			return BitConverter.ToUInt32(mD.ComputeHash(Encoding.UTF8.GetBytes(s)), 0);
		}
	}
	internal sealed class Runner : MonoBehaviour
	{
		internal static Runner Instance;

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			Net.Tick();
			if (Net.IsHost)
			{
				HostSide.Tick();
			}
			OutcomeLocal.Tick();
		}
	}
	internal static class Spawner
	{
		internal static void PlaceDay()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!Options.YearRound && !Plugin.Xmas.On)
			{
				Plugin.V("No presents: out of season (" + Plugin.Xmas.Why + ").");
				return;
			}
			PresentKind[] array = PresentRules.PlanDay(RoundManager.Instance.currentLevel.maxScrap, instance.randomMapSeed, Options.Weights, Options.AmountMultiplier, Options.MaxPerDay);
			int num = Place(array, instance.randomMapSeed);
			Plugin.Log.LogInfo((object)string.Format("{0} of {1} presents placed ({2}).", num, array.Length, string.Join(", ", array)));
		}

		internal static int Place(IList<PresentKind> kinds, int placeSeed)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			Random random = new Random(placeSeed + 41700);
			List<Vector3> list = (from g in Object.FindObjectsOfType<GrabbableObject>()
				where !g.isHeld
				select ((Component)g).transform.position).ToList();
			List<RandomScrapSpawn> list2 = (from s in Object.FindObjectsOfType<RandomScrapSpawn>()
				where !s.spawnUsed
				orderby s.spawnedItemsCopyPosition
				select s).ThenBy((RandomScrapSpawn _) => random.Next()).ToList();
			int num = 0;
			foreach (PresentKind kind in kinds)
			{
				while (list2.Count > 0)
				{
					RandomScrapSpawn val = list2[0];
					list2.RemoveAt(0);
					Vector3 at = ((Component)val).transform.position;
					if (!val.spawnedItemsCopyPosition)
					{
						at = instance.GetRandomNavMeshPositionInBoxPredictable(at, val.itemSpawnRange, default(NavMeshHit), random, -8193, 1f) + Vector3.up * 0.1f;
					}
					if (!list.Any(delegate(Vector3 t)
					{
						//IL_0000: Unknown result type (might be due to invalid IL or missing references)
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						Vector3 val2 = t - at;
						return ((Vector3)(ref val2)).sqrMagnitude < 0.8f;
					}))
					{
						if (val.spawnedItemsCopyPosition)
						{
							val.spawnUsed = true;
						}
						if (!((Object)(object)Spawn(kind, at, random.Next(360), Random.Range(1, int.MaxValue), null) == (Object)null))
						{
							list.Add(at);
							num++;
						}
						break;
					}
				}
			}
			return num;
		}

		internal static PresentItem Spawn(PresentKind kind, Vector3 at, float yaw, int seed, Transform parent)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			ItemDef itemDef = Catalog.Of(kind);
			if ((Object)(object)itemDef.Prefab == (Object)null)
			{
				return null;
			}
			GameObject obj = Object.Instantiate<GameObject>(itemDef.Prefab, at, Quaternion.Euler(0f, yaw, 0f), parent);
			PresentItem component = obj.GetComponent<PresentItem>();
			((GrabbableObject)component).fallTime = 0f;
			component.SetSeed(seed);
			((GrabbableObject)component).SetScrapValue(PresentRules.ShutValue(kind, seed, RoundManager.Instance.scrapValueMultiplier, Options.ValueMultiplier));
			if ((Object)(object)parent != (Object)null)
			{
				((GrabbableObject)component).isInElevator = true;
				((GrabbableObject)component).isInShipRoom = true;
				((GrabbableObject)component).isInFactory = false;
			}
			obj.GetComponent<NetworkObject>().Spawn(false);
			return component;
		}
	}
	internal struct FxRand
	{
		private uint _s;

		internal static FxRand Any = new FxRand(Environment.TickCount);

		internal float Value => (float)(Next() & 0xFFFFFF) / 16777216f;

		internal FxRand(int seed)
		{
			_s = (uint)(seed * -1640531535 + -1640531527);
			if (_s == 0)
			{
				_s = 1u;
			}
			Next();
			Next();
		}

		internal uint Next()
		{
			_s ^= _s << 13;
			_s ^= _s >> 17;
			_s ^= _s << 5;
			return _s;
		}

		internal float Range(float a, float b)
		{
			return a + (b - a) * Value;
		}

		internal int Below(int n)
		{
			return (int)(Next() % (uint)n);
		}

		internal Vector3 Ball()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			float num = Range(-1f, 1f);
			float num2 = Range(0f, 6.2832f);
			float num3 = Mathf.Sqrt(1f - num * num);
			return new Vector3(num3 * Mathf.Cos(num2), num, num3 * Mathf.Sin(num2)) * Mathf.Pow(Value, 0.333f);
		}
	}
	internal static class FxAssets
	{
		internal const string SheetName = "fx/presents_fx_sheet";

		private const int Cells = 8;

		internal static AssetBundle Bundle;

		private static int _ways = -1;

		private static bool _looked;

		private static Texture2D _sheet;

		private static readonly Color[] Confetti = (Color[])(object)new Color[8]
		{
			new Color(0.78f, 0.06f, 0.18f),
			new Color(0.12f, 0.48f, 0.24f),
			new Color(0.91f, 0.71f, 0.23f),
			new Color(0.18f, 0.38f, 0.72f),
			new Color(0.95f, 0.92f, 0.88f),
			new Color(0.88f, 0.45f, 0.16f),
			new Color(0.56f, 0.25f, 0.66f),
			new Color(0.22f, 0.7f, 0.72f)
		};

		private static Mesh[] _scraps;

		private static Mesh[] _confetti;

		private static readonly float[][] Outline = new float[6][]
		{
			new float[12]
			{
				1f, 0.82f, 0.5f, 0.42f, 0.47f, 0.86f, 0.97f, 0.8f, 0.44f, 0.5f,
				0.4f, 0.78f
			},
			new float[12]
			{
				1f, 0.6f, 0.42f, 0.5f, 0.96f, 0.63f, 0.46f, 0.41f, 0.9f, 0.7f,
				0.48f, 0.55f
			},
			new float[12]
			{
				1f, 0.85f, 0.7f, 0.6f, 0.62f, 0.8f, 0.94f, 0.75f, 0.66f, 0.58f,
				0.7f, 0.8f
			},
			new float[12]
			{
				0.8f, 1f, 0.72f, 0.77f, 0.97f, 0.74f, 0.8f, 0.95f, 0.7f, 0.82f,
				1f, 0.76f
			},
			new float[12]
			{
				1f, 0.9f, 0.4f, 0.3f, 0.55f, 0.9f, 0.85f, 0.95f, 0.9f, 0.6f,
				0.35f, 0.7f
			},
			new float[12]
			{
				1f, 0.55f, 0.28f, 0.22f, 0.26f, 0.6f, 0.92f, 0.5f, 0.3f, 0.2f,
				0.28f, 0.45f
			}
		};

		private static Mesh _link;

		private static readonly Dictionary<string, AudioClip> _clips = new Dictionary<string, AudioClip>();

		internal static int Colourways
		{
			get
			{
				if (_ways >= 0)
				{
					return _ways;
				}
				if ((Object)(object)Bundle == (Object)null)
				{
					Load<Texture2D>("fx/presents_fx_sheet");
				}
				if ((Object)(object)Bundle == (Object)null)
				{
					return 0;
				}
				int i;
				for (i = 0; Bundle.Contains("colours/" + (i + 1)); i++)
				{
				}
				return _ways = i;
			}
		}

		internal static Texture2D Sheet
		{
			get
			{
				if ((Object)(object)_sheet != (Object)null)
				{
					return _sheet;
				}
				_sheet = Load<Texture2D>("fx/presents_fx_sheet");
				if ((Object)(object)_sheet == (Object)null)
				{
					Plugin.V("No effect sheet in the bundle: plain shapes.");
					_sheet = PlainSheet();
				}
				((Texture)_sheet).wrapMode = (TextureWrapMode)1;
				return _sheet;
			}
		}

		internal static Mesh[] Scraps => _scraps ?? (_scraps = Shapes(0, 6));

		internal static Mesh[] ConfettiShapes => _confetti ?? (_confetti = Shapes(7, 8));

		internal static Mesh Link
		{
			get
			{
				//IL_0145: 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_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Expected O, but got Unknown
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: 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)
				if ((Object)(object)_link != (Object)null)
				{
					return _link;
				}
				Vector3[] array = (Vector3[])(object)new Vector3[40];
				Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
				List<int> list = new List<int>();
				for (int i = 0; i < 10; i++)
				{
					for (int j = 0; j < 4; j++)
					{
						float num = (float)i * MathF.PI * 2f / 10f;
						float num2 = (float)j * MathF.PI * 2f / 4f;
						float num3 = 0.38f + 0.11f * Mathf.Cos(num2);
						array[i * 4 + j] = new Vector3(Mathf.Cos(num) * num3 * 1.35f, Mathf.Sin(num) * num3, 0.11f * Mathf.Sin(num2));
						array2[i * 4 + j] = new Vector2(0.9375f, 0.9375f);
						int num4 = (i + 1) % 10;
						int num5 = (j + 1) % 4;
						int item = i * 4 + j;
						int item2 = num4 * 4 + j;
						int item3 = num4 * 4 + num5;
						int item4 = i * 4 + num5;
						list.Add(item);
						list.Add(item2);
						list.Add(item3);
						list.Add(item);
						list.Add(item3);
						list.Add(item4);
					}
				}
				return _link = Finish(new Mesh
				{
					name = "Presents.Link",
					vertices = array,
					uv = array2,
					triangles = list.ToArray()
				});
			}
		}

		private static T Load<T>(string name) where T : Object
		{
			if ((Object)(object)Bundle == (Object)null && !_looked)
			{
				_looked = true;
				foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
				{
					if ((Object)(object)allLoadedAssetBundle != (Object)null && !allLoadedAssetBundle.isStreamedSceneAssetBundle && allLoadedAssetBundle.Contains("fx/presents_fx_sheet"))
					{
						Bundle = allLoadedAssetBundle;
						break;
					}
				}
			}
			if (!((Object)(object)Bundle != (Object)null))
			{
				return default(T);
			}
			return Bundle.LoadAsset<T>(name);
		}

		private static Texture2D PlainSheet()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				name = "Presents.PlainSheet"
			};
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					int num = 7 - i / 16;
					int num2 = j / 16;
					float num3 = ((float)(j % 16) + 0.5f) / 16f * 2f - 1f;
					float num4 = ((float)(i % 16) + 0.5f) / 16f * 2f - 1f;
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
					float num6 = (float)num2 / 7f;
					Color val2 = Color.white;
					float a = 1f;
					if (num >= 1 && num <= 3)
					{
						a = Mathf.Clamp01(1f - num5) * (1f - num6);
					}
					else
					{
						switch (num)
						{
						case 4:
						case 5:
							a = Mathf.Pow(Mathf.Clamp01(1f - num5), 2f) * ((num == 5) ? (1f - num6) : 1f);
							break;
						case 6:
							a = Mathf.Pow(Mathf.Clamp01(1f - num5), 3f) * Mathf.Sin(MathF.PI * ((float)num2 + 0.5f) / 8f);
							break;
						case 7:
							val2 = Confetti[num2];
							break;
						}
					}
					val2.a = a;
					array[i * 128 + j] = val2;
				}
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		internal static Material Unlit(string name, bool additive, Color tint, int row, int rows)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("HDRP/Unlit");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = "Presents." + name
			};
			val2.SetFloat("_SurfaceType", 1f);
			val2.SetFloat("_BlendMode", additive ? 1f : 0f);
			val2.SetFloat("_ZWrite", 0f);
			val2.SetFloat("_CullMode", 0f);
			val2.SetFloat("_CullModeForward", 0f);
			val2.SetFloat("_DoubleSidedEnable", 1f);
			val2.SetColor("_UnlitColor", tint);
			val2.SetTexture("_UnlitColorMap", (Texture)(object)Sheet);
			val2.SetTextureScale("_UnlitColorMap", new Vector2(1f, (float)rows / 8f));
			val2.SetTextureOffset("_UnlitColorMap", new Vector2(0f, 1f - (float)(row + rows) / 8f));
			try
			{
				HDMaterial.ValidateMaterial(val2);
			}
			catch (Exception ex)
			{
				Plugin.V(name + ": " + ex.Message);
			}
			return val2;
		}

		internal static Material Paper(string name, Color tint, float smooth, float metal = 0f)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			Shader val = Shader.Find("HDRP/Lit");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val)
			{
				name = "Presents." + name
			};
			val2.SetTexture("_BaseColorMap", (Texture)(object)Sheet);
			val2.SetColor("_BaseColor", tint);
			val2.SetFloat("_Smoothness", smooth);
			val2.SetFloat("_Metallic", metal);
			return val2;
		}

		internal static Material Ribbon(string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Material val = Paper(name, Color.white, 0.5f);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			val.SetTextureScale("_BaseColorMap", new Vector2(0.02f, 0.02f));
			val.SetTextureOffset("_BaseColorMap", new Vector2(0.925f, 0.925f));
			return val;
		}

		private static Mesh[] Shapes(int row, int count)
		{
			//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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			Mesh[] array = (Mesh[])(object)new Mesh[count];
			for (int i = 0; i < count; i++)
			{
				float[] array2 = Outline[i % Outline.Length];
				int num = array2.Length;
				int num2 = 1 + num * 2;
				FxRand fxRand = new FxRand(900 + i + row * 31);
				float num3 = fxRand.Range(0.35f, 0.9f) * ((i % 2 == 0) ? 1f : (-1f));
				float num4 = fxRand.Range(-0.5f, 0.5f);
				Vector3[] array3 = (Vector3[])(object)new Vector3[num2 * 2];
				Vector2[] array4 = (Vector2[])(object)new Vector2[num2 * 2];
				for (int j = 0; j < num2; j++)
				{
					Vector2 zero = Vector2.zero;
					if (j > 0)
					{
						int num5 = (j - 1) % num;
						float num6 = (float)num5 * MathF.PI * 2f / (float)num;
						float num7 = array2[num5] * ((j <= num) ? 0.5f : 1f);
						((Vector2)(ref zero))..ctor(Mathf.Cos(num6) * num7, Mathf.Sin(num6) * num7);
					}
					array3[j] = (array3[j + num2] = new Vector3(zero.x * 0.5f, zero.y * 0.5f, 0.5f * (num3 * zero.x * zero.x + num4 * zero.x * zero.y)));
					array4[j] = (array4[j + num2] = new Vector2(((float)i + 0.5f + zero.x * 0.44f) / 8f, 1f - ((float)row + 0.5f + zero.y * 0.44f) / 8f));
				}
				List<int> list = new List<int>();
				for (int k = 0; k < num; k++)
				{
					int num8 = 1 + k;
					int num9 = 1 + (k + 1) % num;
					int b = num8 + num;
					int num10 = num9 + num;
					Both(list, num2, 0, num8, num9);
					Both(list, num2, num8, b, num10);
					Both(list, num2, num8, num10, num9);
				}
				array[i] = Finish(new Mesh
				{
					name = "Presents.Scrap" + row + i,
					vertices = array3,
					uv = array4,
					triangles = list.ToArray()
				});
			}
			return array;
		}

		private static void Both(List<int> t, int back, int a, int b, int c)
		{
			t.Add(a);
			t.Add(b);
			t.Add(c);
			t.Add(a + back);
			t.Add(c + back);
			t.Add(b + back);
		}

		private static Mesh Finish(Mesh m)
		{
			m.RecalculateNormals();
			m.RecalculateBounds();
			return m;
		}

		internal static AudioClip Clip(string name)
		{
			if (_clips.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = Load<AudioClip>("audio/presents_" + name);
			if ((Object)(object)value == (Object)null)
			{
				Plugin.V("No sound " + name + " in the bundle: a plain one.");
				value = PlainClip(name);
			}
			_clips[name] = value;
			return value;
		}

		private static AudioClip PlainClip(string name)
		{
			float num = 0f;
			float num2 = 0.6f;
			switch (name)
			{
			case "growl":
				num = 48f;
				num2 = 4f;
				break;
			case "shake_growl":
				num = 55f;
				num2 = 1.4f;
				break;
			case "shake_thud":
				num = 85f;
				break;
			case "shake_jingle":
				num = 4200f;
				break;
			case "choir":
				num = 440f;
				num2 = 2.5f;
				break;
			case "horn":
				num = 420f;
				num2 = 1f;
				break;
			case "alarm":
				num = 900f;
				num2 = 2f;
				break;
			case "musicbox":
				num = 1318f;
				num2 = 1f;
				break;
			case "bell":
				num = 1318f;
				num2 = 1.2f;
				break;
			case "cocoa":
				num = 520f;
				num2 = 0.9f;
				break;
			case "wind_down":
				num = 110f;
				num2 = 1.8f;
				break;
			case "chain":
				num = 1400f;
				break;
			case "fuse":
				num2 = 3f;
				break;
			case "pop":
				num2 = 0.15f;
				break;
			}
			bool flag = name == "alarm" || name == "fuse" || name == "growl";
			bool flag2 = name == "alarm" || name.EndsWith("growl");
			FxRand fxRand = new FxRand(name.Length * 77);
			float[] array = new float[(int)(22050f * num2)];
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = (float)i / 22050f;
				float num4 = num3 / num2;
				float num5 = Mathf.Min(1f, num3 / 0.005f) * (flag ? Mathf.Min(1f, (1f - num4) * 20f) : (Mathf.Exp(-4f * num4) * Mathf.Min(1f, (1f - num4) * 10f)));
				float num6 = ((num > 0f) ? (Mathf.Sin(6.2832f * num * num3) + 0.3f * Mathf.Sin(6.2832f * num * 2.01f * num3)) : fxRand.Range(-1f, 1f));
				if (flag2)
				{
					num6 *= 0.6f + 0.4f * Mathf.Sin(6.2832f * ((name == "alarm") ? 9f : 23f) * num3);
				}
				array[i] = 0.4f * num6 * num5;
			}
			AudioClip obj = AudioClip.Create("Presents.Plain." + name, array.Length, 1, 22050, false);
			obj.SetData(array, 0);
			return obj;
		}
	}
	internal static class FxAudio
	{
		internal sealed class Voice
		{
			internal AudioSource Src;

			internal AudioLowPassFilter Muffle;

			internal Transform Follow;

			internal float Base;

			internal float Until;

			internal int Stamp;
		}

		private const int Count = 28;

		private static readonly Voice[] _voices = new Voice[28];

		private static int _stamp;

		internal static void Build(Transform root)
		{
			//IL_0009: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 28; i++)
			{
				GameObject val = new GameObject("Voice");
				val.transform.SetParent(root, false);
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.playOnAwake = false;
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.dopplerLevel = 0f;
				AudioLowPassFilter val3 = val.AddComponent<AudioLowPassFilter>();
				val3.cutoffFrequency = 1500f;
				((Behaviour)val3).enabled = false;
				_voices[i] = new Voice
				{
					Src = val2,
					Muffle = val3
				};
			}
		}

		private static Voice Free()
		{
			Voice voice = null;
			for (int i = 0; i < 28; i++)
			{
				Voice voice2 = _voices[i];
				if (voice2.Until <= Time.time)
				{
					return voice2;
				}
				if (!voice2.Src.loop && (voice == null || voice2.Until < voice.Until))
				{
					voice = voice2;
				}
			}
			return voice;
		}

		internal static Voice Play(string clip, Vector3 at, float volume, float range, float pitch = 1f, float delay = 0f, Transform follow = null, bool loop = false, bool muffled = false)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			AudioClip val = FxAssets.Clip(clip);
			Voice voice = Free();
			if ((Object)(object)val == (Object)null || voice == null)
			{
				return null;
			}
			AudioSource src = voice.Src;
			src.Stop();
			src.clip = val;
			src.loop = loop;
			src.pitch = pitch;
			src.minDistance = Mathf.Min(1.5f, range * 0.15f);
			src.maxDistance = range;
			((Component)src).transform.position = at;
			voice.Follow = follow;
			voice.Base = volume;
			voice.Until = (loop ? float.MaxValue : (Time.time + delay + val.length / Mathf.Max(0.05f, pitch) + 0.1f));
			voice.Stamp = ++_stamp;
			((Behaviour)voice.Muffle).enabled = muffled;
			src.volume = volume * Options.Volume;
			PlayerControllerB val2 = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.itemAudio != (Object)null)
			{
				src.outputAudioMixerGroup = val2.itemAudio.outputAudioMixerGroup;
			}
			if (delay > 0f)
			{
				src.PlayDelayed(delay);
			}
			else
			{
				src.Play();
			}
			return voice;
		}

		internal static bool Mine(Voice v, int stamp)
		{
			if (v != null && v.Stamp == stamp)
			{
				return v.Until > Time.time;
			}
			return false;
		}

		internal static void Stop(Voice v, int stamp)
		{
			if (Mine(v, stamp))
			{
				v.Src.Stop();
				v.Src.loop = false;
				v.Until = 0f;
				v.Follow = null;
			}
		}

		internal static void StopAll()
		{
			for (int i = 0; i < 28; i++)
			{
				Stop(_voices[i], _voices[i].Stamp);
			}
		}

		internal static void Tick()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			float volume = Options.Volume;
			for (int i = 0; i < 28; i++)
			{
				Voice voice = _voices[i];
				if (!(voice.Until <= Time.time))
				{
					voice.Src.volume = voice.Base * volume;
					if ((Object)(object)voice.Follow != (Object)null)
					{
						((Component)voice.Src).transform.position = voice.Follow.position;
					}
				}
			}
		}
	}
	internal static class FxBuffs
	{
		private struct Ring
		{
			internal PlayerControllerB Who;

			internal float Start;

			internal int Sent;
		}

		private const int PerRing = 12;

		private const int MaxFlakes = 36;

		private static readonly Ring[] _rings = new Ring[8];

		private static ParticleSystem _flakes;

		private static GameObject _canvas;

		private static RawImage _frost;

		private static float _frostStart = -100f;

		private static float _frostUntil;

		private static float _alpha;

		private static int _mine;

		private static PlayerControllerB Me
		{
			get
			{
				if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		internal static void Build(Transform root)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_007b: Unknown resu