Decompiled source of Vault v0.1.0

Vault.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModMenu;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("VaultTest")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Vault")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+51c4fd97f2af5b7c20b5981c46416bd39242f3ca")]
[assembly: AssemblyProduct("Vault")]
[assembly: AssemblyTitle("Vault")]
[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 Vault
{
	internal static class Assets
	{
		private static readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		internal static Material Paint;

		internal static Material Steel;

		internal static Material Dark;

		internal static bool Loaded => Prefabs.Count > 0;

		public static void Load()
		{
			try
			{
				using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Vault.vault"))
				{
					AssetBundle val = ((stream != null) ? AssetBundle.LoadFromStream(stream) : null);
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Log.LogWarning((object)"the embedded model bundle is missing: grey-box models");
						return;
					}
					GameObject[] array = val.LoadAllAssets<GameObject>();
					foreach (GameObject val2 in array)
					{
						Prefabs[((Object)val2).name] = val2;
					}
					Paint = val.LoadAsset<Material>("M_VaultPaint");
					Steel = val.LoadAsset<Material>("M_VaultSteel");
					Dark = val.LoadAsset<Material>("M_VaultDark");
				}
				Plugin.Log.LogInfo((object)("models loaded: " + string.Join(", ", Prefabs.Keys)));
			}
			catch (Exception arg)
			{
				Prefabs.Clear();
				Plugin.Log.LogError((object)$"models failed to load, grey-box models: {arg}");
			}
		}

		internal static GameObject Spawn(string prefab, Transform parent, string name, Vector3 local, float scale = 1f, int layer = -1)
		{
			//IL_0030: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (!Prefabs.TryGetValue(prefab, out var value) || (Object)(object)value == (Object)null)
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(value, parent, false);
			((Object)val).name = name;
			val.transform.localPosition = local;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one * scale;
			if (layer >= 0)
			{
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Component)componentsInChildren[i]).gameObject.layer = layer;
				}
			}
			return val;
		}

		internal static void ShowOnly(Transform root, string prefix, int keep)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name.Length > prefix.Length && ((Object)val).name.StartsWith(prefix) && char.IsDigit(((Object)val).name[prefix.Length]))
				{
					bool flag = ((Object)val).name == prefix + keep;
					if (((Component)val).gameObject.activeSelf != flag)
					{
						((Component)val).gameObject.SetActive(flag);
					}
				}
			}
		}

		internal static Renderer Find(Transform root, string path)
		{
			if (!((Object)(object)root != (Object)null))
			{
				return null;
			}
			Transform obj = root.Find(path);
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).GetComponent<Renderer>();
		}
	}
	internal class DoorFit
	{
		private const float DoorBottomMin = 0.62f;

		private const float PanelY = 1.75f;

		public GameObject Root;

		public Vector2 Socket;

		public Vector2 Leaf;

		public Vector2 Frame;

		public Vector2 Plug;

		public Vector2 Face;

		public float Diameter;

		public bool Hatch;

		public float Ceiling;

		public string Source = "";

		public string Hidden = "";

		public Vector3 Centre;

		public Vector3 Out;

		public Vector3 PanelLocal;

		public Transform Wheel;

		public Vector3 WheelAxis = Vector3.forward;

		private const float Trim = 0.1f;

		private const float RoundDoor = 1.9f;

		private const float MinRoundH = 2.1f;

		private const float MinRoundW = 1.6f;

		public Vector3 PanelPos
		{
			get
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Root != (Object)null))
				{
					return Centre;
				}
				return Root.transform.TransformPoint(PanelLocal);
			}
		}

		private static void L(string s)
		{
			Plugin.Log.LogInfo((object)s);
		}

		internal static DoorFit Build(Candidate v)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0028: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0063: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Expected O, but got Unknown
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0648: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0710: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_0746: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a4a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a64: Unknown result type (might be due to invalid IL or missing references)
			//IL_0780: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0add: Unknown result type (might be due to invalid IL or missing references)
			//IL_0afd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b14: Unknown result type (might be due to invalid IL or missing references)
			//IL_086e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0902: Unknown result type (might be due to invalid IL or missing references)
			//IL_0921: Unknown result type (might be due to invalid IL or missing references)
			//IL_0942: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b6a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0baa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bfb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cbf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c20: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c34: Unknown result type (might be due to invalid IL or missing references)
			DoorFit doorFit = new DoorFit
			{
				Out = v.Out
			};
			Vector3 val = v.Out;
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			Vector3 up = Vector3.up;
			Vector3 doorPos = v.DoorPos;
			doorFit.Socket = (((Object)(object)v.Door.Socket != (Object)null) ? v.Door.Socket.Size : Vector2.zero);
			List<Renderer> list = (((Object)(object)v.DoorObject != (Object)null) ? Renderers(v.DoorObject) : new List<Renderer>());
			Rect rect = default(Rect);
			if (list.Count > 0 && Measure(list, doorPos, normalized, up, val, out rect, out var midDepth, out var maxDepth))
			{
				doorFit.Source = $"{list.Count} renderers of {Placement.Clean(((Object)v.DoorObject).name)}";
			}
			else
			{
				float num = ((doorFit.Socket.x > 0.5f) ? doorFit.Socket.x : 1.5f);
				float num2 = ((doorFit.Socket.y > 0.5f) ? doorFit.Socket.y : 2.2f);
				((Rect)(ref rect))..ctor((0f - num) / 2f, 0f, num, num2);
				midDepth = 0f;
				doorFit.Source = "socket size (no door renderers)";
			}
			doorFit.Leaf = ((Rect)(ref rect)).size;
			object obj = v.Door.UsedDoorPrefabInstance;
			if (obj == null)
			{
				Doorway connectedDoorway = v.Door.ConnectedDoorway;
				obj = ((connectedDoorway != null) ? connectedDoorway.UsedDoorPrefabInstance : null);
			}
			GameObject val3 = (GameObject)obj;
			float num3 = midDepth;
			if ((Object)(object)val3 != (Object)null)
			{
				List<Renderer> list2 = Renderers(val3).Except(list).ToList();
				if (list2.Count > 0 && Measure(list2, doorPos, normalized, up, val, out var rect2, out maxDepth, out var maxDepth2))
				{
					doorFit.Frame = ((Rect)(ref rect2)).size;
					num3 = Mathf.Max(num3, maxDepth2);
				}
			}
			Rect val4 = default(Rect);
			((Rect)(ref val4))..ctor(((Rect)(ref rect)).xMin - 0.05f, ((Rect)(ref rect)).yMin - 0.05f, ((Rect)(ref rect)).width + 0.1f, ((Rect)(ref rect)).height + 0.1f);
			doorFit.Plug = ((Rect)(ref val4)).size;
			doorFit.Hatch = ((Rect)(ref val4)).height < 2.1f || ((Rect)(ref val4)).width < 1.6f;
			int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
			Vector3 val5 = doorPos + val * (num3 + 0.06f);
			RaycastHit val6 = default(RaycastHit);
			doorFit.Ceiling = (Physics.Raycast(val5 + val * 0.3f + up * 0.5f, up, ref val6, 8f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) ? (((RaycastHit)(ref val6)).point.y - doorPos.y) : 4f);
			float num4 = 3f;
			Vector3[] array = (Vector3[])(object)new Vector3[2]
			{
				normalized,
				-normalized
			};
			RaycastHit val8 = default(RaycastHit);
			foreach (Vector3 val7 in array)
			{
				if (Physics.Raycast(val5 + val * 0.15f + up * 1.2f, val7, ref val8, 3f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					num4 = Mathf.Min(num4, ((RaycastHit)(ref val8)).distance);
				}
			}
			float num5;
			float num6;
			if (!doorFit.Hatch)
			{
				doorFit.Diameter = Mathf.Min(1.9f, doorFit.Ceiling - 0.25f);
				num5 = Mathf.Max(((Rect)(ref val4)).width + 0.3f, doorFit.Diameter * 1.07f + 1f);
				num6 = Mathf.Max(((Rect)(ref val4)).height + 0.15f, doorFit.Diameter + 0.3f);
			}
			else
			{
				num5 = ((Rect)(ref val4)).width + 0.9f;
				num6 = ((Rect)(ref val4)).height + 0.15f;
			}
			num5 = Mathf.Min(num5, 2f * num4 - 0.05f);
			if (!doorFit.Hatch)
			{
				doorFit.Diameter = Mathf.Max(1.2f, Mathf.Min(doorFit.Diameter, (num5 - 1f) / 1.07f));
			}
			num6 = Mathf.Min(num6, doorFit.Ceiling - 0.02f);
			doorFit.Face = new Vector2(num5, num6);
			GameObject root = new GameObject("VaultDoor (grey box)");
			doorFit.Root = root;
			root.transform.SetParent(((Component)v.Tile).transform, true);
			root.transform.SetPositionAndRotation(doorPos, Quaternion.LookRotation(val, up));
			int roomLayer = LayerMask.NameToLayer("Room");
			bool loaded = Assets.Loaded;
			Material val9 = ((loaded && (Object)(object)Assets.Steel != (Object)null) ? Assets.Steel : Mat(list, new Color(0.42f, 0.44f, 0.46f)));
			Material paint = ((loaded && (Object)(object)Assets.Paint != (Object)null) ? Assets.Paint : val9);
			Material val10 = Mat(list, new Color(0.22f, 0.23f, 0.24f));
			Material val11 = Mat(null, new Color(0.85f, 0.65f, 0.1f));
			float num7 = Mathf.Max(0.25f, num3 - midDepth + 0.1f);
			GameObject val12 = Box(root, "Plug", new Vector3(((Rect)(ref val4)).center.x, ((Rect)(ref val4)).center.y, midDepth + (num3 - midDepth) / 2f), new Vector3(((Rect)(ref val4)).width, ((Rect)(ref val4)).height, num7), val9, roomLayer, collide: true);
			doorFit.Centre = val12.transform.position;
			NavMeshObstacle obj2 = val12.AddComponent<NavMeshObstacle>();
			obj2.shape = (NavMeshObstacleShape)1;
			obj2.size = new Vector3(1f, 1f, 1f + 1.2f / num7);
			obj2.carving = true;
			obj2.carveOnlyStationary = false;
			float num8 = midDepth + (num3 - midDepth) / 2f + num7 / 2f;
			float fz = num3 + 0.04f;
			float num9 = Mathf.Max(fz + 0.03f, num8 + 0.005f);
			float x = ((Rect)(ref val4)).center.x - num5 / 2f;
			float x2 = ((Rect)(ref val4)).center.x + num5 / 2f;
			Strip("Face", x, ((Rect)(ref val4)).xMin, 0f, num6);
			Strip("Face", ((Rect)(ref val4)).xMax, x2, 0f, num6);
			Strip("Face", ((Rect)(ref val4)).xMin, ((Rect)(ref val4)).xMax, ((Rect)(ref val4)).yMax, num6);
			Box(root, "PlugFace", new Vector3(((Rect)(ref val4)).center.x, ((Rect)(ref val4)).center.y, fz), new Vector3(((Rect)(ref val4)).width, ((Rect)(ref val4)).height, 0.06f), paint, roomLayer, collide: false);
			float num10 = -1f;
			float num11 = ((Rect)(ref val4)).center.x;
			float num12 = 1.75f;
			float num13 = ((Rect)(ref val4)).center.x + num5 / 2f - 0.25f;
			if (!doorFit.Hatch)
			{
				float num14 = Mathf.Max(0.62f + doorFit.Diameter / 2f, ((Rect)(ref val4)).center.y);
				num14 = Mathf.Min(num14, ((Rect)(ref val4)).yMax - 0.08f - doorFit.Diameter / 2f);
				num10 = num14 - doorFit.Diameter / 2f;
				float num15 = num13 - 0.2f - 0.05f;
				float num16 = num11 + doorFit.Diameter / 2f - num15;
				if (num16 > 0f)
				{
					float num17 = Mathf.Max(0f, num11 - doorFit.Diameter / 2f - (((Rect)(ref val4)).xMin + 0.03f));
					num11 -= Mathf.Min(num16, num17);
					if (num16 > num17)
					{
						num12 = Mathf.Min(num6 - 0.3f, num14 + doorFit.Diameter / 2f + 0.33f);
					}
				}
				GameObject val13 = Assets.Spawn("VaultRoundDoor", root.transform, "RoundDoor", new Vector3(num11, num14, num9), doorFit.Diameter / 1.9f, roomLayer);
				if ((Object)(object)val13 != (Object)null)
				{
					doorFit.Wheel = val13.transform.Find("Wheel");
					doorFit.WheelAxis = Vector3.forward;
				}
				else
				{
					GameObject obj3 = GameObject.CreatePrimitive((PrimitiveType)2);
					Object.Destroy((Object)(object)obj3.GetComponent<Collider>());
					((Object)obj3).name = "RoundDoor";
					obj3.transform.SetParent(root.transform, false);
					obj3.transform.localPosition = new Vector3(num11, num14, num9 + 0.07f);
					obj3.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
					obj3.transform.localScale = new Vector3(doorFit.Diameter, 0.07f, doorFit.Diameter);
					obj3.GetComponent<Renderer>().sharedMaterial = val10;
					GameObject val14 = GameObject.CreatePrimitive((PrimitiveType)2);
					Object.Destroy((Object)(object)val14.GetComponent<Collider>());
					((Object)val14).name = "Handwheel";
					val14.transform.SetParent(root.transform, false);
					val14.transform.localPosition = new Vector3(num11, num14, num9 + 0.17f);
					val14.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
					val14.transform.localScale = new Vector3(0.6f, 0.04f, 0.6f);
					val14.GetComponent<Renderer>().sharedMaterial = val11;
					doorFit.Wheel = val14.transform;
					doorFit.WheelAxis = Vector3.up;
				}
			}
			else
			{
				float num18 = Mathf.Min(((Rect)(ref val4)).width, ((Rect)(ref val4)).height) - 0.25f;
				if ((Object)(object)Assets.Spawn("VaultHatch", root.transform, "Hatch", new Vector3(((Rect)(ref val4)).center.x, 0.1f + num18 / 2f, num9), num18, roomLayer) == (Object)null)
				{
					Box(root, "Hatch", new Vector3(((Rect)(ref val4)).center.x, 0.1f + num18 / 2f, num9 + 0.03f), new Vector3(num18, num18, 0.06f), val10, roomLayer, collide: false);
					Box(root, "HatchBar", new Vector3(((Rect)(ref val4)).center.x, 0.1f + num18 / 2f, num9 + 0.08f), new Vector3(num18 * 0.7f, 0.08f, 0.05f), val11, roomLayer, collide: false);
				}
			}
			float num19 = ((num10 > 0f) ? Mathf.Max(0.32f, num10 - 0.2f) : (num6 - 0.14f));
			Assets.Spawn("VaultSign", root.transform, "Sign", new Vector3(num11, num19, num9), Mathf.Min(1f, (num5 - 0.1f) / 1.45f), roomLayer);
			GameObject val15 = Assets.Spawn("VaultStripes", root.transform, "Stripes", new Vector3(((Rect)(ref val4)).center.x, 0.002f, num9 + 0.55f), 1f, roomLayer);
			if ((Object)(object)val15 != (Object)null)
			{
				val15.transform.localScale = new Vector3(num5 / 2f, 1f, 1f);
			}
			if (!loaded)
			{
				Box(root, "Panel", new Vector3(num13, num12, num9 + 0.05f), new Vector3(0.4f, 0.55f, 0.08f), val11, roomLayer, collide: false);
			}
			doorFit.PanelLocal = new Vector3(num13, num12, num9 + 0.05f);
			doorFit.Hidden = HideOldDoor(v.DoorObject);
			L($"door fit: socket {doorFit.Socket}, leaf {doorFit.Leaf} ({doorFit.Source}), frame {doorFit.Frame}, plug {doorFit.Plug}, face {doorFit.Face}, " + string.Format("{0}, ceiling {1:F2}, side room {2:F2}; hid {3}", doorFit.Hatch ? "hatch" : ("round door " + doorFit.Diameter.ToString("F2") + " m"), doorFit.Ceiling, num4, doorFit.Hidden));
			return doorFit;
			void Strip(string n, float num21, float num20, float y0, float y1)
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				if (num20 - num21 > 0.01f && y1 - y0 > 0.01f)
				{
					Box(root, n, new Vector3((num21 + num20) / 2f, (y0 + y1) / 2f, fz), new Vector3(num20 - num21, y1 - y0, 0.06f), paint, roomLayer, collide: true);
				}
			}
		}

		private static List<Renderer> Renderers(GameObject g)
		{
			return (from r in g.GetComponentsInChildren<Renderer>(false)
				where r.enabled && (r is MeshRenderer || r is SkinnedMeshRenderer)
				select r).ToList();
		}

		private static bool Measure(List<Renderer> rs, Vector3 origin, Vector3 right, Vector3 up, Vector3 o, out Rect rect, out float midDepth, out float maxDepth)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005f: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			float num5 = float.MaxValue;
			float num6 = float.MinValue;
			foreach (Renderer r in rs)
			{
				Bounds bounds = r.bounds;
				for (int i = 0; i < 8; i++)
				{
					Vector3 val = new Vector3(((i & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((i & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((i & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z) - origin;
					float num7 = Vector3.Dot(val, right);
					float num8 = Vector3.Dot(val, up);
					float num9 = Vector3.Dot(val, o);
					num = Mathf.Min(num, num7);
					num2 = Mathf.Max(num2, num7);
					num3 = Mathf.Min(num3, num8);
					num4 = Mathf.Max(num4, num8);
					num5 = Mathf.Min(num5, num9);
					num6 = Mathf.Max(num6, num9);
				}
			}
			rect = new Rect(num, num3, num2 - num, num4 - num3);
			midDepth = (num5 + num6) / 2f;
			maxDepth = num6;
			if (((Rect)(ref rect)).width > 0.3f && ((Rect)(ref rect)).height > 0.5f && ((Rect)(ref rect)).width < 8f)
			{
				return ((Rect)(ref rect)).height < 8f;
			}
			return false;
		}

		private static GameObject Box(GameObject parent, string name, Vector3 local, Vector3 size, Material m, int layer, bool collide)
		{
			//IL_0035: 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)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = name;
			if (!collide)
			{
				Object.Destroy((Object)(object)val.GetComponent<Collider>());
			}
			val.transform.SetParent(parent.transform, false);
			val.transform.localPosition = local;
			val.transform.localScale = size;
			val.GetComponent<Renderer>().sharedMaterial = m;
			if (layer >= 0)
			{
				val.layer = layer;
			}
			return val;
		}

		internal static Material Mat(List<Renderer> like, Color c)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("HDRP/Lit");
			if ((Object)(object)val == (Object)null)
			{
				return like?.Select((Renderer r) => r.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material x) => (Object)(object)x != (Object)null));
			}
			Material val2 = new Material(val);
			if (val2.HasProperty("_BaseColor"))
			{
				val2.SetColor("_BaseColor", c);
			}
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", 0.6f);
			}
			if (val2.HasProperty("_Smoothness"))
			{
				val2.SetFloat("_Smoothness", 0.45f);
			}
			return val2;
		}

		private static string HideOldDoor(GameObject door)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			if ((Object)(object)door == (Object)null)
			{
				return "nothing (no door object)";
			}
			if ((Object)(object)door.GetComponent<NetworkObject>() == (Object)null)
			{
				door.SetActive(false);
				return Placement.Clean(((Object)door).name) + " (deactivated)";
			}
			int num = 0;
			foreach (Transform item in door.transform)
			{
				Transform val = item;
				if (((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(false);
					num++;
				}
			}
			int num2 = 0;
			Renderer[] components = door.GetComponents<Renderer>();
			for (int i = 0; i < components.Length; i++)
			{
				components[i].enabled = false;
				num2++;
			}
			Collider[] components2 = door.GetComponents<Collider>();
			for (int i = 0; i < components2.Length; i++)
			{
				components2[i].enabled = false;
				num2++;
			}
			Behaviour[] components3 = door.GetComponents<Behaviour>();
			foreach (Behaviour val2 in components3)
			{
				if (val2 is NetworkBehaviour || val2 is NavMeshObstacle || val2 is InteractTrigger)
				{
					val2.enabled = false;
					num2++;
				}
			}
			return $"{Placement.Clean(((Object)door).name)} ({num} children off, {num2} root components off)";
		}
	}
	internal class Junction : MonoBehaviour
	{
		internal int Index;

		internal InteractTrigger Holder;

		internal InteractTrigger Dial;

		private GameObject _fuse;

		private Transform _pointer;

		private Renderer _lamp;

		private BoxState _state;

		internal Vector3 HolderPos
		{
			get
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Holder != (Object)null))
				{
					return ((Component)this).transform.position;
				}
				return ((Component)Holder).transform.position;
			}
		}

		internal Vector3 DialPos
		{
			get
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)Dial != (Object)null))
				{
					return ((Component)this).transform.position;
				}
				return ((Component)Dial).transform.position;
			}
		}

		internal static Junction Build(int index, Vector3 pos, Vector3 normal, Transform parent)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0039: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Vault.Junction " + Puzzle.Names[index]);
			if ((Object)(object)parent != (Object)null)
			{
				val.transform.SetParent(parent, true);
			}
			val.transform.SetPositionAndRotation(pos, Quaternion.LookRotation(normal, Vector3.up));
			int num = LayerMask.NameToLayer("Room");
			Junction j = val.AddComponent<Junction>();
			j.Index = index;
			GameObject val2 = Assets.Spawn("VaultJunction", val.transform, "Model", Vector3.zero);
			if ((Object)(object)val2 != (Object)null)
			{
				Transform transform = val2.transform;
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = new Vector3(0f, 0f, 0.09f);
				obj.size = new Vector3(0.5f, 0.7f, 0.18f);
				if (num >= 0)
				{
					val.layer = num;
				}
				Junction junction = j;
				Transform obj2 = transform.Find("Fuse");
				junction._fuse = ((obj2 != null) ? ((Component)obj2).gameObject : null);
				j._pointer = transform.Find("Pointer");
				j._lamp = Assets.Find(transform, "Lamp");
				if ((Object)(object)j._lamp != (Object)null)
				{
					j._lamp.sharedMaterial = Registry.Glow(Color.black);
				}
				Renderer val3 = Assets.Find(transform, "Band");
				if ((Object)(object)val3 != (Object)null)
				{
					val3.sharedMaterial = Registry.Glow(Puzzle.Colours[index] * 0.8f);
				}
				Assets.ShowOnly(transform, "Label", index);
			}
			else
			{
				j.GreyBox(val, num);
			}
			j.Holder = Trigger(val.transform, "HolderTrigger", new Vector3(-0.12f, -0.05f, 0.24f), new Vector3(0.2f, 0.32f, 0.14f));
			((UnityEvent<PlayerControllerB>)(object)j.Holder.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB p)
			{
				if (IsMe(p))
				{
					Puzzle.LocalHolder(j.Index);
				}
			});
			j.Dial = Trigger(val.transform, "DialTrigger", new Vector3(0.12f, -0.05f, 0.24f), new Vector3(0.2f, 0.22f, 0.14f));
			((UnityEvent<PlayerControllerB>)(object)j.Dial.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB p)
			{
				if (IsMe(p))
				{
					Net.SendAct(Act.Dial, j.Index, 0uL);
				}
			});
			return j;
		}

		private void GreyBox(GameObject go, int room)
		{
			//IL_0018: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			int index = Index;
			Material m = Registry.Mat(new Color(0.34f, 0.37f, 0.36f));
			Material m2 = Registry.Mat(new Color(0.12f, 0.12f, 0.13f));
			GameObject val = Registry.Part(go.transform, (PrimitiveType)3, "Body", new Vector3(0f, 0f, 0.09f), new Vector3(0.5f, 0.7f, 0.18f), Quaternion.identity, m, collider: true);
			if (room >= 0)
			{
				val.layer = room;
			}
			Registry.Part(go.transform, (PrimitiveType)3, "Band", new Vector3(0f, 0.3f, 0.182f), new Vector3(0.5f, 0.06f, 0.01f), Quaternion.identity, Registry.Glow(Puzzle.Colours[index] * 0.8f));
			Registry.Part(go.transform, (PrimitiveType)3, "HolderSocket", new Vector3(-0.12f, -0.05f, 0.19f), new Vector3(0.14f, 0.26f, 0.025f), Quaternion.identity, m2);
			_fuse = Registry.Part(go.transform, (PrimitiveType)2, "Fuse", new Vector3(-0.12f, -0.05f, 0.235f), new Vector3(0.07f, 0.09f, 0.07f), Quaternion.identity, Registry.Mat(new Color(0.85f, 0.7f, 0.15f)));
			Registry.Part(go.transform, (PrimitiveType)2, "Dial", new Vector3(0.12f, -0.05f, 0.2f), new Vector3(0.15f, 0.02f, 0.15f), Quaternion.Euler(90f, 0f, 0f), m2);
			GameObject val2 = new GameObject("Pointer");
			val2.transform.SetParent(go.transform, false);
			val2.transform.localPosition = new Vector3(0.12f, -0.05f, 0.225f);
			Registry.Part(val2.transform, (PrimitiveType)3, "Needle", new Vector3(0f, 0.04f, 0f), new Vector3(0.02f, 0.07f, 0.01f), Quaternion.identity, Registry.Mat(new Color(0.9f, 0.9f, 0.85f)));
			_pointer = val2.transform;
			for (int i = 0; i < 4; i++)
			{
				Quaternion val3 = Quaternion.Euler(0f, 0f, 90f * (float)i);
				Registry.Part(go.transform, (PrimitiveType)3, "Tick" + i, new Vector3(0.12f, -0.05f, 0.212f) + val3 * new Vector3(0f, 0.095f, 0f), new Vector3(0.012f, 0.025f, 0.01f), val3, m2);
			}
			_lamp = Registry.Part(go.transform, (PrimitiveType)0, "Lamp", new Vector3(0f, 0.22f, 0.19f), Vector3.one * 0.06f, Quaternion.identity, Registry.Glow(Color.black)).GetComponent<Renderer>();
		}

		internal void Show(BoxState b, bool live)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			_state = b;
			if ((Object)(object)_fuse != (Object)null && _fuse.activeSelf != b.HasFuse)
			{
				_fuse.SetActive(b.HasFuse);
			}
			if ((Object)(object)_pointer != (Object)null)
			{
				_pointer.localRotation = Quaternion.Euler(0f, 0f, 90f * (float)(int)b.Dial);
			}
			Registry.SetGlow(_lamp, live ? new Color(0.2f, 1f, 0.3f) : (b.HasFuse ? new Color(0.9f, 0.55f, 0.05f) : new Color(0.25f, 0.03f, 0.02f)));
		}

		private void Update()
		{
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			BoxState state = _state;
			if (!((Object)(object)val == (Object)null) && state != null && !((Object)(object)Holder == (Object)null))
			{
				string text = Puzzle.Names[Index];
				if (state.HasFuse)
				{
					Holder.interactable = true;
					Holder.hoverTip = text + "\nPull the fuse : [E]";
				}
				else if (Registry.IsFuse(val.currentlyHeldObjectServer))
				{
					Holder.interactable = true;
					Holder.hoverTip = text + "\nInsert fuse : [E]";
				}
				else
				{
					Holder.interactable = false;
					Holder.disabledHoverTip = text + ": no fuse";
				}
				Dial.hoverTip = text + "  dial [ " + Puzzle.Sym(state.Dial) + " ]\nTurn : [E]";
			}
		}

		internal static bool IsMe(PlayerControllerB p)
		{
			if ((Object)(object)p != (Object)null)
			{
				return (Object)(object)p == (Object)(object)GameNetworkManager.Instance?.localPlayerController;
			}
			return false;
		}

		internal static InteractTrigger Trigger(Transform parent, string name, Vector3 at, Vector3 size)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = at;
			int num = LayerMask.NameToLayer("InteractableObject");
			val.layer = ((num >= 0) ? num : 9);
			val.tag = "InteractTrigger";
			BoxCollider obj = val.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.size = size;
			InteractTrigger t = val.AddComponent<InteractTrigger>();
			t.hoverTip = "";
			t.disabledHoverTip = "";
			t.interactable = true;
			t.oneHandedItemAllowed = true;
			t.twoHandedItemAllowed = false;
			t.interactCooldown = true;
			t.cooldownTime = 0.4f;
			t.onInteract = new InteractEvent();
			t.onInteractEarly = new InteractEvent();
			t.onInteractEarlyOtherClients = new InteractEvent();
			t.onStopInteract = new InteractEvent();
			t.onCancelAnimation = new InteractEvent();
			t.holdingInteractEvent = new InteractEventFloat();
			InteractTrigger val2 = ((IEnumerable<InteractTrigger>)Object.FindObjectsOfType<InteractTrigger>()).FirstOrDefault((Func<InteractTrigger, bool>)((InteractTrigger x) => (Object)(object)x != (Object)(object)t && (Object)(object)x.hoverIcon != (Object)null));
			if ((Object)(object)val2 != (Object)null)
			{
				t.hoverIcon = val2.hoverIcon;
				t.disabledHoverIcon = (((Object)(object)val2.disabledHoverIcon != (Object)null) ? val2.disabledHoverIcon : val2.hoverIcon);
			}
			return t;
		}
	}
	internal class Panel : MonoBehaviour
	{
		internal InteractTrigger Lever;

		private readonly Renderer[] _lamps = (Renderer[])(object)new Renderer[3];

		private Transform _handle;

		private Transform _model;

		private Snapshot _s;

		internal static Panel Build(DoorFit fit)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_002b: 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_010d: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = fit.Root.transform;
			GameObject val = new GameObject("Vault.Panel");
			val.transform.SetParent(transform, false);
			val.transform.localPosition = fit.PanelLocal;
			Panel panel = val.AddComponent<Panel>();
			GameObject val2 = Assets.Spawn("VaultPanel", val.transform, "Model", Vector3.zero);
			if ((Object)(object)val2 != (Object)null)
			{
				panel._model = val2.transform;
				for (int i = 0; i < 3; i++)
				{
					panel._lamps[i] = Assets.Find(panel._model, "Lamp" + i);
					if ((Object)(object)panel._lamps[i] != (Object)null)
					{
						panel._lamps[i].sharedMaterial = Registry.Glow(Color.black);
					}
				}
				panel._handle = panel._model.Find("LeverPivot");
			}
			else
			{
				panel.GreyBox(val);
			}
			panel.Lever = Junction.Trigger(val.transform, "LeverTrigger", new Vector3(0f, 0f, 0.1f), new Vector3(0.45f, 0.6f, 0.2f));
			((UnityEvent<PlayerControllerB>)(object)panel.Lever.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB pl)
			{
				if (Junction.IsMe(pl))
				{
					Net.SendAct(Act.Lever, -1, 0uL);
				}
			});
			return panel;
		}

		private void GreyBox(GameObject go)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00d8: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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)
			for (int i = 0; i < 3; i++)
			{
				_lamps[i] = Registry.Part(go.transform, (PrimitiveType)0, "Lamp" + i, new Vector3(-0.12f + 0.12f * (float)i, 0.18f, 0.05f), Vector3.one * 0.07f, Quaternion.identity, Registry.Glow(Color.black)).GetComponent<Renderer>();
			}
			Registry.Part(go.transform, (PrimitiveType)3, "Screen", new Vector3(0f, 0.05f, 0.045f), new Vector3(0.3f, 0.1f, 0.01f), Quaternion.identity, Registry.Glow(new Color(0.05f, 0.3f, 0.1f)));
			GameObject val = new GameObject("LeverPivot");
			val.transform.SetParent(go.transform, false);
			val.transform.localPosition = new Vector3(0f, -0.12f, 0.06f);
			Registry.Part(val.transform, (PrimitiveType)3, "Handle", new Vector3(0f, 0.07f, 0.02f), new Vector3(0.04f, 0.16f, 0.04f), Quaternion.identity, Registry.Mat(new Color(0.75f, 0.1f, 0.08f)));
			_handle = val.transform;
		}

		internal void Show(Snapshot s)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			_s = s;
			for (int i = 0; i < 3; i++)
			{
				Registry.SetGlow(_lamps[i], (s.Live(i) || s.Door != DoorState.Sealed) ? (Puzzle.Colours[i] * 1.6f) : (Puzzle.Colours[i] * 0.08f));
			}
			if ((Object)(object)_handle != (Object)null)
			{
				_handle.localRotation = Quaternion.Euler((s.Door == DoorState.Sealed) ? 0f : 150f, 0f, 0f);
			}
			for (int j = 0; j < 3; j++)
			{
				if (!((Object)(object)_model != (Object)null))
				{
					break;
				}
				Assets.ShowOnly(_model, $"Sym{j}_", s.Sym[j] & 3);
			}
		}

		private void Update()
		{
			Snapshot s = _s;
			if (s == null || (Object)(object)Lever == (Object)null)
			{
				return;
			}
			string text = Puzzle.Sym(s.Sym[0]) + "  " + Puzzle.Sym(s.Sym[1]) + "  " + Puzzle.Sym(s.Sym[2]);
			switch (s.Door)
			{
			case DoorState.Sealed:
				if (s.AllLit)
				{
					Lever.interactable = true;
					Lever.hoverTip = "VAULT: power 3/3   screen " + text + "\nPull lever : [E]";
				}
				else
				{
					Lever.interactable = false;
					Lever.disabledHoverTip = $"VAULT: needs power ({s.LitCount}/3)\nscreen  {text}";
				}
				break;
			case DoorState.Unsealing:
				Lever.interactable = false;
				Lever.disabledHoverTip = "VAULT: unsealing...";
				break;
			default:
				Lever.interactable = false;
				Lever.disabledHoverTip = "VAULT: open";
				break;
			}
		}
	}
	internal static class MenuHooks
	{
		internal const string ModMenuGuid = "daniel.lethalcompany.modmenu";

		private const string Tab = "Vault";

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			MenuApi.Toggle("Vault", "Placement overlay", (Func<bool>)(() => (Object)(object)Overlay.Instance != (Object)null && Overlay.Instance.Visible), (Func<bool, string>)delegate(bool on)
			{
				Overlay.Instance.SetVisible(on);
				return (!on) ? "overlay hidden" : "overlay shown";
			}, false, false, (Func<string>)(() => Plugin.DebugOverlay.Value ? ((!((Object)(object)Overlay.Instance == (Object)null) && Overlay.Instance.HasOverlay) ? null : "no vault placed yet") : "turn on Testing › DebugOverlay"), "only you see it");
		}
	}
	internal static class Net
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static HandleNamedMessageDelegate <>9__11_0;

			public static HandleNamedMessageDelegate <>9__11_1;

			public static HandleNamedMessageDelegate <>9__11_2;

			public static HandleNamedMessageDelegate <>9__11_3;

			internal void <Register>b__11_0(ulong s, FastBufferReader r)
			{
				if (IsHost)
				{
					SendState(s);
				}
			}

			internal void <Register>b__11_1(ulong s, FastBufferReader r)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_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)
				if (IsHost && ((FastBufferReader)(ref r)).TryBeginRead(10))
				{
					byte kind = default(byte);
					((FastBufferReader)(ref r)).ReadValue<byte>(ref kind, default(ForPrimitives));
					byte box = default(byte);
					((FastBufferReader)(ref r)).ReadValue<byte>(ref box, default(ForPrimitives));
					ulong item = default(ulong);
					((FastBufferReader)(ref r)).ReadValue<ulong>(ref item, default(ForPrimitives));
					Puzzle.HostAct(PlayerOf(s), (Act)kind, box, item);
				}
			}

			internal void <Register>b__11_2(ulong s, FastBufferReader r)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				if (!IsHost && s == 0L)
				{
					Snapshot snapshot = Snapshot.Read(r);
					if (snapshot != null)
					{
						Puzzle.Receive(snapshot);
					}
				}
			}

			internal void <Register>b__11_3(ulong s, FastBufferReader r)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				if (!IsHost && s == 0L && ((FastBufferReader)(ref r)).TryBeginRead(2))
				{
					byte fx = default(byte);
					((FastBufferReader)(ref r)).ReadValue<byte>(ref fx, default(ForPrimitives));
					byte box = default(byte);
					((FastBufferReader)(ref r)).ReadValue<byte>(ref box, default(ForPrimitives));
					Puzzle.PlayFx((Fx)fx, box);
				}
			}
		}

		internal const string MState = "Vault.State";

		internal const string MHello = "Vault.Hello";

		internal const string MAct = "Vault.Act";

		internal const string MFx = "Vault.Fx";

		private static CustomMessagingManager _registeredOn;

		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 => (int)(GameNetworkManager.Instance?.localPlayerController?.playerClientId).GetValueOrDefault();

		internal static void Register()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//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_007a: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			NetworkManager nM = NM;
			if ((Object)(object)nM == (Object)null || nM.CustomMessagingManager == null || _registeredOn == nM.CustomMessagingManager)
			{
				return;
			}
			CustomMessagingManager customMessagingManager = nM.CustomMessagingManager;
			object obj = <>c.<>9__11_0;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = delegate(ulong s, FastBufferReader r)
				{
					if (IsHost)
					{
						SendState(s);
					}
				};
				<>c.<>9__11_0 = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("Vault.Hello", (HandleNamedMessageDelegate)obj);
			object obj2 = <>c.<>9__11_1;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = delegate(ulong s, FastBufferReader r)
				{
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0020: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_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)
					if (IsHost && ((FastBufferReader)(ref r)).TryBeginRead(10))
					{
						byte kind = default(byte);
						((FastBufferReader)(ref r)).ReadValue<byte>(ref kind, default(ForPrimitives));
						byte box = default(byte);
						((FastBufferReader)(ref r)).ReadValue<byte>(ref box, default(ForPrimitives));
						ulong item = default(ulong);
						((FastBufferReader)(ref r)).ReadValue<ulong>(ref item, default(ForPrimitives));
						Puzzle.HostAct(PlayerOf(s), (Act)kind, box, item);
					}
				};
				<>c.<>9__11_1 = val2;
				obj2 = (object)val2;
			}
			customMessagingManager.RegisterNamedMessageHandler("Vault.Act", (HandleNamedMessageDelegate)obj2);
			object obj3 = <>c.<>9__11_2;
			if (obj3 == null)
			{
				HandleNamedMessageDelegate val3 = delegate(ulong s, FastBufferReader r)
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					if (!IsHost && s == 0L)
					{
						Snapshot snapshot = Snapshot.Read(r);
						if (snapshot != null)
						{
							Puzzle.Receive(snapshot);
						}
					}
				};
				<>c.<>9__11_2 = val3;
				obj3 = (object)val3;
			}
			customMessagingManager.RegisterNamedMessageHandler("Vault.State", (HandleNamedMessageDelegate)obj3);
			object obj4 = <>c.<>9__11_3;
			if (obj4 == null)
			{
				HandleNamedMessageDelegate val4 = delegate(ulong s, FastBufferReader r)
				{
					//IL_001c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0022: Unknown result type (might be due to invalid IL or missing references)
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0034: Unknown result type (might be due to invalid IL or missing references)
					if (!IsHost && s == 0L && ((FastBufferReader)(ref r)).TryBeginRead(2))
					{
						byte fx = default(byte);
						((FastBufferReader)(ref r)).ReadValue<byte>(ref fx, default(ForPrimitives));
						byte box = default(byte);
						((FastBufferReader)(ref r)).ReadValue<byte>(ref box, default(ForPrimitives));
						Puzzle.PlayFx((Fx)fx, box);
					}
				};
				<>c.<>9__11_3 = val4;
				obj4 = (object)val4;
			}
			customMessagingManager.RegisterNamedMessageHandler("Vault.Fx", (HandleNamedMessageDelegate)obj4);
			_registeredOn = customMessagingManager;
			Plugin.Log.LogInfo((object)"messages registered");
		}

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

		internal unsafe static void SendAct(Act kind, int box, ulong item = 0uL)
		{
			//IL_0030: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost)
			{
				Puzzle.HostAct(LocalIdx, kind, box, item);
			}
			else if (Online)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
				try
				{
					byte b = (byte)kind;
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
					b = (byte)box;
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref item, default(ForPrimitives));
					NM.CustomMessagingManager.SendNamedMessage("Vault.Act", 0uL, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}

		internal unsafe static void SendHello()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost || !Online)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				NM.CustomMessagingManager.SendNamedMessage("Vault.Hello", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal unsafe static void SendState(ulong? target = null)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHost)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, -1);
			try
			{
				Puzzle.Current.Write(val);
				foreach (ulong connectedClientsId in NM.ConnectedClientsIds)
				{
					if (connectedClientsId != 0L && (!target.HasValue || target == connectedClientsId))
					{
						NM.CustomMessagingManager.SendNamedMessage("Vault.State", connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		internal unsafe static void BroadcastFx(Fx kind, int box)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHost)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				byte b = (byte)kind;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				b = (byte)box;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				foreach (ulong connectedClientsId in NM.ConnectedClientsIds)
				{
					if (connectedClientsId != 0L)
					{
						NM.CustomMessagingManager.SendNamedMessage("Vault.Fx", connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}
	}
	internal enum Act : byte
	{
		Insert,
		Pull,
		Dial,
		Lever
	}
	internal enum Fx : byte
	{
		Inserted,
		Pulled,
		Dialled,
		Blown,
		Unsealing,
		Opened
	}
	internal class Overlay : MonoBehaviour
	{
		internal static Overlay Instance;

		private GameObject root;

		private Result shown;

		private bool visible = true;

		private readonly List<(Vector3 pos, string text, Color col)> labels = new List<(Vector3, string, Color)>();

		private readonly Dictionary<Color, Material> mats = new Dictionary<Color, Material>();

		private GUIStyle style;

		private GUIStyle panel;

		internal static readonly Color Magenta = new Color(1f, 0.1f, 0.9f);

		internal static readonly Color Green = new Color(0.2f, 1f, 0.3f);

		internal static readonly Color Yellow = new Color(1f, 0.9f, 0.1f);

		internal static readonly Color Red = new Color(1f, 0.15f, 0.1f);

		internal static readonly Color Orange = new Color(1f, 0.5f, 0f);

		internal static readonly Color Gold = new Color(1f, 0.75f, 0.2f);

		internal static readonly Color Purple = new Color(0.6f, 0.2f, 1f);

		internal static readonly Color White = Color.white;

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

		internal static readonly Color BoxG = new Color(0.1f, 1f, 0.2f);

		internal static readonly Color BoxB = new Color(0.2f, 0.4f, 1f);

		internal bool Visible => visible;

		internal bool HasOverlay => (Object)(object)root != (Object)null;

		private void Awake()
		{
			Instance = this;
			Placement.Placed += delegate(Result r)
			{
				if (Plugin.DebugOverlay.Value)
				{
					Show(r);
				}
			};
		}

		internal void Clear()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			shown = null;
			labels.Clear();
		}

		private void Update()
		{
			if (shown != null && (Object)(object)root == (Object)null)
			{
				Clear();
			}
		}

		internal void SetVisible(bool v)
		{
			visible = v;
			if ((Object)(object)root != (Object)null)
			{
				root.SetActive(v);
			}
		}

		internal void Show(Result r)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_00b2: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			Clear();
			shown = r;
			RoundManager instance = RoundManager.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				RuntimeDungeon dungeonGenerator = instance.dungeonGenerator;
				if (dungeonGenerator == null)
				{
					obj = null;
				}
				else
				{
					DungeonGenerator generator = dungeonGenerator.Generator;
					obj = ((generator != null) ? generator.CurrentDungeon : null);
				}
			}
			Dungeon val = (Dungeon)obj;
			root = new GameObject("Vault.DebugOverlay");
			if ((Object)(object)val != (Object)null)
			{
				root.transform.SetParent(((Component)val).transform, true);
			}
			foreach (Candidate candidate in r.Candidates)
			{
				Color val2 = ((candidate == r.Chosen) ? Magenta : (candidate.Passes ? Green : (candidate.Eligible ? Yellow : Red)));
				WireBox(candidate.Bounds, val2, (candidate == r.Chosen) ? 0.12f : 0.05f);
				Beam(candidate.DoorPos, val2, 0.08f, 3f);
				string arg = ((candidate == r.Chosen) ? "VAULT" : (candidate.Passes ? "candidate" : (candidate.Eligible ? "near" : "no")));
				labels.Add((((Bounds)(ref candidate.Bounds)).center + Vector3.up * 1f, $"T{candidate.TileIndex} {arg}\n{Short(candidate)}", val2));
			}
			if (r.Entrance != Vector3.zero)
			{
				Beam(r.Entrance, White, 0.25f, 40f);
				labels.Add((r.Entrance + Vector3.up * 2f, "MAIN ENTRANCE", White));
			}
			Color[] array = (Color[])(object)new Color[3] { BoxR, BoxG, BoxB };
			string[] array2 = new string[3] { "J-1 RED", "J-2 GREEN", "J-3 BLUE" };
			for (int i = 0; i < r.Boxes.Count; i++)
			{
				Spot spot = r.Boxes[i];
				Prim((PrimitiveType)3, spot.Pos + spot.Normal * 0.08f, new Vector3(0.5f, 0.6f, 0.16f), array[i]).transform.rotation = Quaternion.LookRotation(spot.Normal);
				Beam(spot.Pos + spot.Normal * 0.3f, array[i], 0.25f, 40f);
				labels.Add((spot.Pos + Vector3.up * 0.6f, $"{array2[i]}\n{spot.Key} {spot.TileName}\n{spot.PathLen:F0} m", array[i]));
			}
			foreach (Fuse fuse in r.Fuses)
			{
				Prim((PrimitiveType)0, fuse.Pos + Vector3.up * 0.25f, Vector3.one * 0.35f, Yellow);
				Beam(fuse.Pos, Yellow, 0.12f, 30f);
				labels.Add((fuse.Pos + Vector3.up * 0.8f, string.Format("FUSE {0}\n{1:F0} m", (fuse.Third < 3) ? (fuse.Third + 1).ToString() : "spare", fuse.PathLen), Yellow));
			}
			foreach (Vector3 removedNode in r.RemovedNodes)
			{
				Prim((PrimitiveType)0, removedNode + Vector3.up * 0.5f, Vector3.one * 0.4f, Red);
			}
			foreach (Vector3 removedVent in r.RemovedVents)
			{
				Prim((PrimitiveType)3, removedVent, Vector3.one * 0.6f, Orange);
			}
			foreach (Vector3 lootSpot in r.LootSpots)
			{
				Prim((PrimitiveType)3, lootSpot + Vector3.up * 0.15f, Vector3.one * 0.3f, Gold);
			}
			foreach (Vector3 removedHazard in r.RemovedHazards)
			{
				Prim((PrimitiveType)3, removedHazard + Vector3.up * 0.2f, Vector3.one * 0.4f, Purple);
			}
			root.SetActive(visible);
		}

		private static string Short(Candidate c)
		{
			return string.Format("door {0} floor {1:F0}m2 {2} {3} ", c.HasDoor ? "Y" : "N", c.FloorArea, c.FloorOk ? "Y" : "N", c.Excluded ?? "") + "path " + ((c.PathLen < 0f) ? "-" : c.PathLen.ToString("F0")) + (c.Far ? " far" : "");
		}

		private Material Mat(Color c)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (mats.TryGetValue(c, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Shader val = Shader.Find("HDRP/Unlit");
			if ((Object)(object)val != (Object)null)
			{
				value = new Material(val);
				value.SetColor("_UnlitColor", c);
				if (value.HasProperty("_BaseColor"))
				{
					value.SetColor("_BaseColor", c);
				}
			}
			else
			{
				value = DoorFit.Mat(null, c);
			}
			mats[c] = value;
			return value;
		}

		private GameObject Prim(PrimitiveType t, Vector3 pos, Vector3 scale, Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(t);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			obj.transform.SetParent(root.transform, false);
			obj.transform.position = pos;
			obj.transform.localScale = scale;
			Renderer component = obj.GetComponent<Renderer>();
			component.sharedMaterial = Mat(c);
			component.shadowCastingMode = (ShadowCastingMode)0;
			return obj;
		}

		private void Beam(Vector3 foot, Color c, float width, float height)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			Prim((PrimitiveType)3, foot + Vector3.up * height / 2f, new Vector3(width, height, width), c);
		}

		private void WireBox(Bounds b, Color c, float w)
		{
			//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_000a: 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_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)
			//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_002f: 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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0132: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			Vector3 min = ((Bounds)(ref b)).min;
			Vector3 max = ((Bounds)(ref b)).max;
			Vector3[] array = (Vector3[])(object)new Vector3[8]
			{
				new Vector3(min.x, min.y, min.z),
				new Vector3(max.x, min.y, min.z),
				new Vector3(max.x, min.y, max.z),
				new Vector3(min.x, min.y, max.z),
				new Vector3(min.x, max.y, min.z),
				new Vector3(max.x, max.y, min.z),
				new Vector3(max.x, max.y, max.z),
				new Vector3(min.x, max.y, max.z)
			};
			int[,] array2 = new int[12, 2]
			{
				{ 0, 1 },
				{ 1, 2 },
				{ 2, 3 },
				{ 3, 0 },
				{ 4, 5 },
				{ 5, 6 },
				{ 6, 7 },
				{ 7, 4 },
				{ 0, 4 },
				{ 1, 5 },
				{ 2, 6 },
				{ 3, 7 }
			};
			for (int i = 0; i < 12; i++)
			{
				Vector3 val = array[array2[i, 0]];
				Vector3 val2 = array[array2[i, 1]];
				GameObject obj = Prim((PrimitiveType)3, (val + val2) / 2f, Vector3.one, c);
				obj.transform.rotation = Quaternion.LookRotation(val2 - val);
				Transform transform = obj.transform;
				Vector3 val3 = val2 - val;
				transform.localScale = new Vector3(w, w, ((Vector3)(ref val3)).magnitude + w);
			}
		}

		private void OnGUI()
		{
			//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_005e: 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_0071: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			if (shown == null || !visible || !Plugin.DebugOverlay.Value)
			{
				return;
			}
			float num = Mathf.Max(1f, (float)Screen.height / 1080f);
			if (style == null)
			{
				style = new GUIStyle(GUI.skin.label)
				{
					fontSize = Mathf.RoundToInt(15f * num),
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)1
				};
				panel = new GUIStyle(GUI.skin.box)
				{
					fontSize = Mathf.RoundToInt(15f * num),
					alignment = (TextAnchor)0,
					wordWrap = true
				};
				panel.normal.textColor = Color.white;
			}
			Result result = shown;
			string text = $"VAULT PLACEMENT   {result.Flow} on {result.Moon}, seed {result.MapSeed}\n" + $"dead ends {result.DeadEnds}, behind doors {result.Candidates.Count((Candidate c) => c.HasDoor)}, eligible {result.Candidates.Count((Candidate c) => c.Eligible)}, far {result.Candidates.Count((Candidate c) => c.Passes)}\n" + result.Message + "\n";
			if (result.Chosen != null)
			{
				DoorFit fit = result.Fit;
				text = text + $"vault T{result.Chosen.TileIndex} {Placement.Clean(((Object)result.Chosen.Tile).name)}  {result.Chosen.PathLen:F0} m\n" + ((fit == null) ? "" : string.Format("door: leaf {0:F2}x{1:F2}  socket {2:F2}x{3:F2}  plug {4:F2}x{5:F2}  {6}\n", fit.Leaf.x, fit.Leaf.y, fit.Socket.x, fit.Socket.y, fit.Plug.x, fit.Plug.y, fit.Hatch ? "HATCH" : ("round " + fit.Diameter.ToString("F2")))) + $"AI nodes {result.NodesBefore}->{result.NodesAfter}  vents -{result.RemovedVents.Count}  loot spots {result.LootSpots.Count}  hazards -{result.RemovedHazards.Count}\n" + "boxes: " + result.BoxNote;
			}
			GUI.Box(new Rect(10f * num, 10f * num, 640f * num, (float)((result.Chosen != null) ? 160 : 70) * num), text, panel);
			Camera val = GameNetworkManager.Instance?.localPlayerController?.gameplayCamera;
			if ((Object)(object)val == (Object)null || !((Behaviour)val).isActiveAndEnabled)
			{
				val = Camera.main;
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Rect val3 = default(Rect);
			foreach (var label in labels)
			{
				Vector3 item = label.pos;
				string item2 = label.text;
				Color item3 = label.col;
				Vector3 val2 = val.WorldToScreenPoint(item);
				if (!(val2.z < 0.5f) && !(val2.z > 60f))
				{
					float num2 = val2.x * (float)Screen.width / (float)Mathf.Max(1, val.pixelWidth);
					float num3 = val2.y * (float)Screen.height / (float)Mathf.Max(1, val.pixelHeight);
					((Rect)(ref val3))..ctor(num2 - 170f * num, (float)Screen.height - num3, 340f * num, 70f * num);
					style.normal.textColor = Color.black;
					GUI.Label(new Rect(((Rect)(ref val3)).x + 1f, ((Rect)(ref val3)).y + 1f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), item2, style);
					style.normal.textColor = item3;
					GUI.Label(val3, item2, style);
				}
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal static class RoundManagerPatches
	{
		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPrefix]
		private static void NewFloor()
		{
			Placement.Last = null;
			Puzzle.Reset();
			Overlay.Instance?.Clear();
		}

		[HarmonyPatch("GeneratedFloorPostProcessing")]
		[HarmonyPrefix]
		private static void BeforeScrap(RoundManager __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			try
			{
				Placement.Run();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("vault placement failed: " + ex));
			}
			try
			{
				Puzzle.HostSetup(Placement.Last);
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogError((object)("vault puzzle setup failed: " + ex2));
			}
		}

		[HarmonyPatch("SetLockedDoors")]
		[HarmonyPrefix]
		private static void BeforeLocks()
		{
			try
			{
				Puzzle.TryApply();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("vault apply failed: " + ex));
			}
		}

		[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void LevelReady(RoundManager __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer && Puzzle.Current == null)
			{
				Net.SendHello();
			}
		}

		[HarmonyPatch("RefreshEnemyVents")]
		[HarmonyPostfix]
		private static void Vents(RoundManager __instance)
		{
			if (Placement.Last?.Chosen != null && __instance.allEnemyVents != null)
			{
				__instance.allEnemyVents = __instance.allEnemyVents.Where((EnemyVent v) => (Object)(object)v != (Object)null && !Placement.InVault(((Component)v).transform.position)).ToArray();
			}
		}
	}
	[HarmonyPatch]
	internal static class SetupPatches
	{
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void GnmStart()
		{
			Build("GameNetworkManager.Start");
		}

		[HarmonyPatch(typeof(MenuManager), "Start")]
		[HarmonyPostfix]
		private static void MenuStart()
		{
			Build("MenuManager.Start");
		}

		private static void Build(string from)
		{
			if ((Object)(object)Registry.FusePrefab != (Object)null)
			{
				return;
			}
			try
			{
				Registry.Build();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"building the fuse failed ({from}): {arg}");
			}
		}

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

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void SorStart()
		{
			Puzzle.Reset();
			Net.Register();
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPostfix]
		private static void SorDestroy()
		{
			Puzzle.Reset();
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DespawnHeldObjectServerRpc")]
		[HarmonyPrefix]
		private static void Despawn(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && Registry.IsFuse(__instance.currentlyHeldObjectServer))
			{
				Puzzle.NoteDespawn((int)__instance.playerClientId, ((NetworkBehaviour)__instance.currentlyHeldObjectServer).NetworkObjectId);
			}
		}
	}
	internal class Candidate
	{
		public int TileIndex;

		public Tile Tile;

		public Doorway Door;

		public Bounds Bounds;

		public Vector3 DoorPos;

		public Vector3 Out;

		public bool HasDoor;

		public string DoorKind = "";

		public GameObject DoorObject;

		public float FloorArea;

		public float MinSide;

		public bool FloorOk;

		public string Excluded;

		public float PathLen = -1f;

		public bool Far;

		public int Weight;

		public bool Eligible
		{
			get
			{
				if (HasDoor && FloorOk && Excluded == null)
				{
					return PathLen >= 0f;
				}
				return false;
			}
		}

		public bool Passes
		{
			get
			{
				if (Eligible)
				{
					return Far;
				}
				return false;
			}
		}

		public bool Inside(Vector3 p)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			Bounds bounds = Bounds;
			((Bounds)(ref bounds)).Expand(0.2f);
			if (((Bounds)(ref bounds)).Contains(p))
			{
				return Vector3.Dot(p - DoorPos, Out) < -0.05f;
			}
			return false;
		}

		public string Rules()
		{
			return string.Format("door {0} ({1}) | floor {2:F0} m2, min side {3:F1} {4} | ", HasDoor ? "ok" : "NO", DoorKind, FloorArea, MinSide, FloorOk ? "ok" : "NO") + ((Excluded == null) ? "no exclusions" : ("EXCLUDED " + Excluded)) + " | path " + ((PathLen < 0f) ? "unreachable" : (PathLen.ToString("F0") + " m")) + " " + (Far ? "far" : "near");
		}
	}
	internal class Spot
	{
		public Vector3 Pos;

		public Vector3 Normal;

		public Vector3 Node;

		public string Key;

		public int TileIndex;

		public string TileName;

		public float PathLen;
	}
	internal class Fuse
	{
		public Vector3 Pos;

		public int Third;

		public float PathLen;
	}
	internal class Result
	{
		public int MapSeed;

		public string Flow = "";

		public string Moon = "";

		public double Roll;

		public bool VaultDay;

		public int DeadEnds;

		public Vector3 Entrance;

		public readonly List<Candidate> Candidates = new List<Candidate>();

		public Candidate Chosen;

		public DoorFit Fit;

		public readonly List<Spot> Boxes = new List<Spot>();

		public string BoxNote = "";

		public readonly List<Fuse> Fuses = new List<Fuse>();

		public int NodesBefore;

		public int NodesAfter;

		public int VentsBefore;

		public readonly List<Vector3> RemovedNodes = new List<Vector3>();

		public readonly List<Vector3> RemovedVents = new List<Vector3>();

		public readonly List<Vector3> LootSpots = new List<Vector3>();

		public readonly List<Vector3> RemovedHazards = new List<Vector3>();

		public int ScrapSpots;

		public byte[] Symbols = new byte[3];

		public string Message = "";
	}
	internal static class Placement
	{
		internal static Result Last;

		private const float MinFloorSide = 5f;

		private const float MinFloorArea = 25f;

		private const float FarShare = 0.4f;

		private const float BoxApart = 25f;

		private const float BoxFromVault = 20f;

		internal static event Action<Result> Placed;

		private static void L(string s)
		{
			Plugin.Log.LogInfo((object)s);
		}

		internal static void Run()
		{
			//IL_0136: 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_0152: 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_04c8: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			StartOfRound instance2 = StartOfRound.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				RuntimeDungeon dungeonGenerator = instance.dungeonGenerator;
				if (dungeonGenerator == null)
				{
					obj = null;
				}
				else
				{
					DungeonGenerator generator = dungeonGenerator.Generator;
					obj = ((generator != null) ? generator.CurrentDungeon : null);
				}
			}
			Dungeon val = (Dungeon)obj;
			Result result = (Last = new Result());
			if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || (Object)(object)val == (Object)null)
			{
				result.Message = "no dungeon";
				Plugin.Log.LogWarning((object)"no dungeon: no vault today");
				return;
			}
			result.MapSeed = instance2.randomMapSeed;
			result.Flow = (Object.op_Implicit((Object)(object)instance.dungeonGenerator.Generator.DungeonFlow) ? ((Object)instance.dungeonGenerator.Generator.DungeonFlow).name : "?");
			result.Moon = (Object.op_Implicit((Object)(object)instance2.currentLevel) ? instance2.currentLevel.PlanetName : "?");
			Random random = new Random(result.MapSeed + 9113);
			result.Roll = random.NextDouble();
			result.VaultDay = result.Roll < (double)Plugin.DayChance.Value || Plugin.ForceVault.Value;
			EntranceTeleport val2 = RoundManager.FindMainEntranceScript(false);
			result.Entrance = ((!((Object)(object)val2 != (Object)null)) ? Vector3.zero : (Object.op_Implicit((Object)(object)val2.entrancePoint) ? val2.entrancePoint.position : ((Component)val2).transform.position));
			FindCandidates(val, instance, result);
			List<Candidate> list = (from c in result.Candidates
				where c.Eligible
				orderby c.PathLen
				select c).ToList();
			int num = ((list.Count != 0) ? Mathf.Max(1, Mathf.CeilToInt((flo