Decompiled source of The Company Cinema v1.0.9

CinemaMod.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CinemaMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CinemaMod")]
[assembly: AssemblyTitle("CinemaMod")]
[assembly: AssemblyVersion("1.0.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 CinemaMod
{
	internal static class CinemaGlasses
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnMessage;
		}

		private const string Msg = "ben.cinemamod.glasses";

		private static ulong _wearing;

		private static readonly GameObject[] Worn = (GameObject[])(object)new GameObject[64];

		private static GameObject _rackPair;

		private static Material _white;

		private static Material _red;

		private static Material _cyan;

		private static InteractTrigger _rackTrigger;

		public static bool LocalWearing
		{
			get
			{
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if ((Object)(object)val != (Object)null)
				{
					return (_wearing & (ulong)(1L << (int)val.playerClientId)) != 0;
				}
				return false;
			}
		}

		public static void Register(CustomMessagingManager mm)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			object obj = <>O.<0>__OnMessage;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = OnMessage;
				<>O.<0>__OnMessage = val;
				obj = (object)val;
			}
			mm.RegisterNamedMessageHandler("ben.cinemamod.glasses", (HandleNamedMessageDelegate)obj);
		}

		public static void Unregister(CustomMessagingManager mm)
		{
			if (mm != null)
			{
				mm.UnregisterNamedMessageHandler("ben.cinemamod.glasses");
			}
			_wearing = 0uL;
			for (int i = 0; i < Worn.Length; i++)
			{
				if ((Object)(object)Worn[i] != (Object)null)
				{
					Object.Destroy((Object)(object)Worn[i]);
				}
				Worn[i] = null;
			}
		}

		public unsafe static void ToggleLocal()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			int num = (int)val.playerClientId;
			bool flag = (_wearing & (ulong)(1L << num)) == 0;
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.IsServer)
			{
				HostSet(num, flag);
				return;
			}
			FastBufferWriter val2 = default(FastBufferWriter);
			((FastBufferWriter)(ref val2))..ctor(16, (Allocator)2, -1);
			try
			{
				byte b = 0;
				((FastBufferWriter)(ref val2)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("ben.cinemamod.glasses", 0uL, val2, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void HostSet(int idx, bool on)
		{
			if (on)
			{
				_wearing |= (ulong)(1L << idx);
			}
			else
			{
				_wearing &= (ulong)(~(1L << idx));
			}
			Broadcast();
			Apply();
		}

		public unsafe static void Broadcast(ulong? onlyTo = null)
		{
			//IL_0083: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || !singleton.IsServer)
			{
				return;
			}
			ulong[] array = ((!onlyTo.HasValue) ? singleton.ConnectedClientsIds.Where((ulong id) => id != 0).ToArray() : new ulong[1] { onlyTo.Value });
			if (array.Length == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				byte b = 1;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref _wearing, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("ben.cinemamod.glasses", (IReadOnlyList<ulong>)array, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnMessage(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			if (b == 0)
			{
				int num = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
				bool flag = default(bool);
				((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				if (NetworkManager.Singleton.IsServer && num >= 0 && num < 64)
				{
					HostSet(num, flag);
				}
			}
			else
			{
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref _wearing, default(ForPrimitives));
				Apply();
			}
		}

		private static void Apply()
		{
			PlayerControllerB[] array = StartOfRound.Instance?.allPlayerScripts;
			if (array == null)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			bool flag = (Object)(object)singleton != (Object)null && singleton.IsServer;
			bool flag2 = false;
			for (int i = 0; i < array.Length && i < 64; i++)
			{
				if (flag && (_wearing & (ulong)(1L << i)) != 0L && (Object)(object)array[i] != (Object)null && !array[i].isPlayerControlled && !array[i].isPlayerDead)
				{
					_wearing &= (ulong)(~(1L << i));
					flag2 = true;
				}
				bool flag3 = (_wearing & (ulong)(1L << i)) != 0L && (Object)(object)array[i] != (Object)null && (array[i].isPlayerControlled || array[i].isPlayerDead);
				if (flag3 && (Object)(object)Worn[i] == (Object)null)
				{
					Worn[i] = PutOn(array[i]);
				}
				else if (!flag3 && (Object)(object)Worn[i] != (Object)null)
				{
					Object.Destroy((Object)(object)Worn[i]);
					Worn[i] = null;
				}
			}
			if (flag2)
			{
				Broadcast();
			}
			UpdateRackLabel();
		}

		private static GameObject PutOn(PlayerControllerB p)
		{
			//IL_0046: 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_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_005e: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (((Object)(object)p.headCostumeContainer != (Object)null) ? p.headCostumeContainer : p.playerGlobalHead);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = BuildGlasses("3DGlasses");
			val2.transform.SetParent(val, true);
			Vector3 forward = ((Component)p).transform.forward;
			Vector3 value = Plugin.GlassesOffset.Value;
			val2.transform.position = val.position + forward * value.z + Vector3.up * value.y + ((Component)p).transform.right * value.x;
			val2.transform.rotation = Quaternion.LookRotation(forward, Vector3.up);
			Transform transform = val2.transform;
			transform.localScale *= Plugin.GlassesScale.Value;
			int layer = (((Object)(object)p.thisPlayerModel != (Object)null) ? ((Component)p.thisPlayerModel).gameObject.layer : val2.layer);
			Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = layer;
			}
			return val2;
		}

		private static GameObject BuildGlasses(string name)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0095: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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)
			GameObject root = new GameObject(name);
			if ((Object)(object)_white == (Object)null)
			{
				_white = CinemaScreen.CreateFlatMaterial(new Color(0.92f, 0.92f, 0.9f));
				_red = CinemaScreen.CreateFlatMaterial(new Color(0.85f, 0.08f, 0.1f));
				_cyan = CinemaScreen.CreateFlatMaterial(new Color(0.05f, 0.6f, 0.85f));
			}
			Material white = _white;
			Material red = _red;
			Material cyan = _cyan;
			Part(new Vector3(0f, 0.022f, 0f), new Vector3(0.15f, 0.012f, 0.004f), white);
			Part(new Vector3(0f, -0.022f, 0f), new Vector3(0.15f, 0.012f, 0.004f), white);
			Part(new Vector3(-0.071f, 0f, 0f), new Vector3(0.008f, 0.056f, 0.004f), white);
			Part(new Vector3(0.071f, 0f, 0f), new Vector3(0.008f, 0.056f, 0.004f), white);
			Part(new Vector3(0f, 0.004f, 0f), new Vector3(0.022f, 0.036f, 0.004f), white);
			Part(new Vector3(-0.039f, 0f, 0.001f), new Vector3(0.056f, 0.032f, 0.002f), red);
			Part(new Vector3(0.039f, 0f, 0.001f), new Vector3(0.056f, 0.032f, 0.002f), cyan);
			Part(new Vector3(-0.074f, 0.012f, -0.06f), new Vector3(0.004f, 0.012f, 0.12f), white);
			Part(new Vector3(0.074f, 0.012f, -0.06f), new Vector3(0.004f, 0.012f, 0.12f), white);
			return root;
			void Part(Vector3 pos, Vector3 size, Material m)
			{
				//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)
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
				Object.Destroy((Object)(object)obj.GetComponent<Collider>());
				obj.transform.SetParent(root.transform, false);
				obj.transform.localPosition = pos;
				obj.transform.localScale = size;
				obj.GetComponent<Renderer>().sharedMaterial = m;
				obj.GetComponent<Renderer>().shadowCastingMode = (ShadowCastingMode)0;
			}
		}

		public static void Tick()
		{
			if (Time.frameCount % 60 == 0)
			{
				Apply();
			}
		}

		public static void PlaceOnTable(Transform room, Vector3 tableTopLocal, float yaw = 180f)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_01da: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Expected O, but got Unknown
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Expected O, but got Unknown
			_rackPair = BuildGlasses("TableGlasses");
			_rackPair.transform.SetParent(room, false);
			_rackPair.transform.localPosition = tableTopLocal + new Vector3(0f, 0.03f, 0f);
			_rackPair.transform.localRotation = Quaternion.Euler(0f, yaw, 0f);
			_rackPair.transform.localScale = Vector3.one * 2f;
			try
			{
				GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
				((Object)val).name = "GlassesTrigger";
				Object.Destroy((Object)(object)val.GetComponent<Renderer>());
				val.GetComponent<Collider>().isTrigger = true;
				val.transform.SetParent(room, false);
				val.transform.localPosition = tableTopLocal + new Vector3(0f, 0.15f, 0f);
				val.transform.localScale = new Vector3(0.8f, 0.35f, 0.6f);
				int num = LayerMask.NameToLayer("InteractableObject");
				if (num >= 0)
				{
					val.layer = num;
				}
				val.tag = "InteractTrigger";
				_rackTrigger = val.AddComponent<InteractTrigger>();
				Terminal obj = Object.FindObjectOfType<Terminal>();
				InteractTrigger val2 = ((obj != null) ? ((Component)obj).GetComponent<InteractTrigger>() : null) ?? ((IEnumerable<InteractTrigger>)Object.FindObjectsOfType<InteractTrigger>()).FirstOrDefault((Func<InteractTrigger, bool>)((InteractTrigger t) => (Object)(object)t != (Object)(object)_rackTrigger));
				if ((Object)(object)val2 != (Object)null)
				{
					_rackTrigger.hoverIcon = val2.hoverIcon;
					_rackTrigger.disabledHoverIcon = val2.disabledHoverIcon;
				}
				_rackTrigger.interactable = true;
				_rackTrigger.oneHandedItemAllowed = true;
				_rackTrigger.twoHandedItemAllowed = true;
				_rackTrigger.holdInteraction = false;
				_rackTrigger.interactCooldown = false;
				_rackTrigger.onInteract = new InteractEvent();
				((UnityEvent<PlayerControllerB>)(object)_rackTrigger.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate
				{
					ToggleLocal();
				});
				_rackTrigger.onInteractEarly = new InteractEvent();
				_rackTrigger.onStopInteract = new InteractEvent();
				_rackTrigger.onCancelAnimation = new InteractEvent();
				_rackTrigger.holdingInteractEvent = new InteractEventFloat();
				UpdateRackLabel();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("3D glasses table trigger failed (use 'cinema glasses'): " + ex.Message));
			}
		}

		public static void KeyFallback(PlayerControllerB p)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_rackPair == (Object)null || CinemaMenu.IsOpen || p.inTerminalMenu || p.quickMenuManager.isMenuOpen || (Object)(object)p.hoveringOverTrigger != (Object)null)
			{
				return;
			}
			Vector3 val = ((Component)p).transform.position - _rackPair.transform.position;
			if (!(((Vector3)(ref val)).sqrMagnitude > 2.5600002f))
			{
				Keyboard current = Keyboard.current;
				if (current != null && ((ButtonControl)current.eKey).wasPressedThisFrame)
				{
					ToggleLocal();
				}
			}
		}

		private static void UpdateRackLabel()
		{
			if ((Object)(object)_rackTrigger != (Object)null)
			{
				_rackTrigger.hoverTip = (LocalWearing ? "Take off 3D glasses : [E]" : "Wear 3D glasses : [E]");
			}
		}

		public static void DrawTint()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (LocalWearing && Plugin.GlassesTint.Value)
			{
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && !val.inTerminalMenu)
				{
					Color color = GUI.color;
					GUI.color = new Color(1f, 0f, 0f, 0.1f);
					GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width / 2f, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
					GUI.color = new Color(0f, 0.8f, 1f, 0.1f);
					GUI.DrawTexture(new Rect((float)Screen.width / 2f, 0f, (float)Screen.width / 2f, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
					GUI.color = color;
				}
			}
		}
	}
	public class PopcornBucket : GrabbableObject
	{
		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && !((Object)(object)base.playerHeldBy == (Object)null) && ((NetworkBehaviour)this).IsOwner)
			{
				CinemaPopcorn.ThrowFrom(base.playerHeldBy);
			}
		}
	}
	internal static class CinemaItem
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Item, bool> <>9__5_0;

			public static HandleNamedMessageDelegate <>9__8_0;

			public static Func<PopcornBucket, bool> <>9__12_0;

			internal bool <RegisterItem>b__5_0(Item i)
			{
				if ((Object)(object)i != (Object)null && (Object)(object)i != (Object)(object)BucketItem && !i.twoHanded && (Object)(object)i.grabSFX != (Object)null)
				{
					return (Object)(object)i.dropSFX != (Object)null;
				}
				return false;
			}

			internal void <Register>b__8_0(ulong s, FastBufferReader r)
			{
				HostSpawn();
			}

			internal bool <HostSpawn>b__12_0(PopcornBucket b)
			{
				if (!((GrabbableObject)b).isHeld && !((GrabbableObject)b).isInShipRoom)
				{
					return (Object)(object)((GrabbableObject)b).playerHeldBy == (Object)null;
				}
				return false;
			}
		}

		private const string Msg = "ben.cinemamod.bucket";

		public static Item BucketItem;

		public static GameObject BucketPrefab;

		private static GameObject _prefabHolder;

		private static Vector3 _spawnPoint;

		private static float _lastSpawn;

		public static void CreatePrefab()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0089: 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_00bd: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_01a6: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: 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_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)BucketPrefab != (Object)null))
			{
				_prefabHolder = new GameObject("CinemaModPrefabs");
				_prefabHolder.SetActive(false);
				((Object)_prefabHolder).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)_prefabHolder);
				GameObject val = new GameObject("PopcornBucket");
				val.transform.SetParent(_prefabHolder.transform, false);
				val.layer = Layer("Props");
				val.tag = "PhysicsProp";
				Material m = CinemaScreen.CreateFlatMaterial(new Color(0.8f, 0.06f, 0.06f));
				Material m2 = CinemaScreen.CreateFlatMaterial(new Color(0.96f, 0.95f, 0.9f));
				Material m3 = CinemaScreen.CreateFlatMaterial(new Color(1f, 0.88f, 0.45f));
				MeshRenderer val2 = null;
				val2 = Part(val, "Body", Vector3.zero, new Vector3(0.2f, 0.26f, 0.2f), m2);
				Part(val, "StripeF", new Vector3(0f, 0f, 0.101f), new Vector3(0.07f, 0.26f, 0.002f), m);
				Part(val, "StripeB", new Vector3(0f, 0f, -0.101f), new Vector3(0.07f, 0.26f, 0.002f), m);
				Part(val, "StripeL", new Vector3(-0.101f, 0f, 0f), new Vector3(0.002f, 0.26f, 0.07f), m);
				Part(val, "StripeR", new Vector3(0.101f, 0f, 0f), new Vector3(0.002f, 0.26f, 0.07f), m);
				Part(val, "Corn", new Vector3(0f, 0.15f, 0f), new Vector3(0.21f, 0.06f, 0.21f), m3);
				Part(val, "Corn2", new Vector3(0.02f, 0.19f, -0.01f), new Vector3(0.14f, 0.05f, 0.14f), m3);
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = new Vector3(0f, 0.03f, 0f);
				obj.size = new Vector3(0.24f, 0.36f, 0.24f);
				((Collider)obj).isTrigger = true;
				AudioSource obj2 = val.AddComponent<AudioSource>();
				obj2.playOnAwake = false;
				obj2.spatialBlend = 1f;
				obj2.rolloffMode = (AudioRolloffMode)1;
				obj2.maxDistance = 15f;
				NetworkObject obj3 = val.AddComponent<NetworkObject>();
				uint num = 0u;
				string text = "ben.cinemamod.PopcornBucket";
				foreach (char c in text)
				{
					num = num * 31 + c;
				}
				AccessTools.Field(typeof(NetworkObject), "GlobalObjectIdHash")?.SetValue(obj3, num);
				BucketItem = ScriptableObject.CreateInstance<Item>();
				((Object)BucketItem).name = "PopcornBucketItem";
				BucketItem.itemName = "Popcorn";
				BucketItem.isScrap = false;
				BucketItem.creditsWorth = 0;
				BucketItem.weight = 1.01f;
				BucketItem.canBeGrabbedBeforeGameStart = true;
				BucketItem.twoHanded = false;
				BucketItem.twoHandedAnimation = false;
				BucketItem.holdButtonUse = false;
				BucketItem.requiresBattery = false;
				BucketItem.isConductiveMetal = false;
				BucketItem.itemSpawnsOnGround = true;
				BucketItem.syncUseFunction = false;
				BucketItem.syncDiscardFunction = false;
				BucketItem.grabAnim = "HoldLung";
				BucketItem.toolTips = new string[1] { "Throw popcorn : [LMB]" };
				BucketItem.verticalOffset = 0.13f;
				BucketItem.restingRotation = Vector3.zero;
				BucketItem.rotationOffset = new Vector3(0f, 0f, 0f);
				BucketItem.positionOffset = new Vector3(0f, 0.05f, 0.05f);
				BucketItem.itemIcon = MakeIcon();
				BucketItem.spawnPrefab = val;
				PopcornBucket popcornBucket = val.AddComponent<PopcornBucket>();
				((GrabbableObject)popcornBucket).itemProperties = BucketItem;
				((GrabbableObject)popcornBucket).grabbable = true;
				((GrabbableObject)popcornBucket).grabbableToEnemies = false;
				((GrabbableObject)popcornBucket).mainObjectRenderer = val2;
				NetworkManager.Singleton.AddNetworkPrefab(val);
				BucketPrefab = val;
				Plugin.Log.LogInfo((object)$"Popcorn bucket item registered (hash {num})");
			}
		}

		public static void RegisterItem(StartOfRound sor)
		{
			if ((Object)(object)BucketItem == (Object)null || (Object)(object)sor.allItemsList == (Object)null)
			{
				return;
			}
			List<Item> itemsList = sor.allItemsList.itemsList;
			if (!itemsList.Contains(BucketItem))
			{
				itemsList.Add(BucketItem);
			}
			Item val = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && (Object)(object)i != (Object)(object)BucketItem && !i.twoHanded && (Object)(object)i.grabSFX != (Object)null && (Object)(object)i.dropSFX != (Object)null));
			if ((Object)(object)val != (Object)null)
			{
				BucketItem.grabSFX = val.grabSFX;
				BucketItem.dropSFX = val.dropSFX;
				BucketItem.pocketSFX = (((Object)(object)val.pocketSFX != (Object)null) ? val.pocketSFX : val.grabSFX);
				if (!string.IsNullOrEmpty(val.grabAnim) && BucketItem.grabAnim == "HoldLung")
				{
					BucketItem.grabAnim = val.grabAnim;
				}
			}
		}

		public static void SetSpawnPoint(Vector3 world)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			_spawnPoint = world;
		}

		public static void Register(CustomMessagingManager mm)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			object obj = <>c.<>9__8_0;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = delegate
				{
					HostSpawn();
				};
				<>c.<>9__8_0 = val;
				obj = (object)val;
			}
			mm.RegisterNamedMessageHandler("ben.cinemamod.bucket", (HandleNamedMessageDelegate)obj);
		}

		public static void Unregister(CustomMessagingManager mm)
		{
			if (mm != null)
			{
				mm.UnregisterNamedMessageHandler("ben.cinemamod.bucket");
			}
		}

		public unsafe static void RequestBucket()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				return;
			}
			if (singleton.IsServer)
			{
				HostSpawn();
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				singleton.CustomMessagingManager.SendNamedMessage("ben.cinemamod.bucket", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void HostSpawn()
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_011a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)BucketPrefab == (Object)null || !NetworkManager.Singleton.IsServer || Time.unscaledTime - _lastSpawn < 0.5f)
			{
				return;
			}
			_lastSpawn = Time.unscaledTime;
			PopcornBucket[] array = Object.FindObjectsOfType<PopcornBucket>();
			if (array.Length >= 12)
			{
				PopcornBucket popcornBucket = array.FirstOrDefault((PopcornBucket b) => !((GrabbableObject)b).isHeld && !((GrabbableObject)b).isInShipRoom && (Object)(object)((GrabbableObject)b).playerHeldBy == (Object)null);
				if ((Object)(object)popcornBucket == (Object)null)
				{
					CinemaScreen.Tip("Popcorn", "There are already enough buckets around!");
					return;
				}
				((Component)popcornBucket).GetComponent<NetworkObject>().Despawn(true);
			}
			Transform val = (((Object)(object)RoundManager.Instance != (Object)null && (Object)(object)RoundManager.Instance.spawnedScrapContainer != (Object)null) ? RoundManager.Instance.spawnedScrapContainer : null);
			Vector3 val2 = _spawnPoint + new Vector3(Random.Range(-0.15f, 0.15f), 0.2f, Random.Range(-0.1f, 0.1f));
			GameObject obj = Object.Instantiate<GameObject>(BucketPrefab, val2, Quaternion.identity, val);
			PopcornBucket component = obj.GetComponent<PopcornBucket>();
			((GrabbableObject)component).fallTime = 0f;
			((GrabbableObject)component).startFallingPosition = val2;
			((GrabbableObject)component).targetFloorPosition = val2;
			obj.GetComponent<NetworkObject>().Spawn(false);
		}

		private static int Layer(string name)
		{
			int num = LayerMask.NameToLayer(name);
			if (num >= 0)
			{
				return num;
			}
			return 0;
		}

		private static MeshRenderer Part(GameObject parent, string name, Vector3 pos, Vector3 size, Material m)
		{
			//IL_003c: 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((PrimitiveType)3);
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = name;
			obj.layer = parent.layer;
			obj.transform.SetParent(parent.transform, false);
			obj.transform.localPosition = pos;
			obj.transform.localScale = size;
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = m;
			return component;
		}

		private static Sprite MakeIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_007b: 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)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					Color val3 = val2;
					float num = 14f + (float)(i - 8) * 0.12f;
					if (i >= 8 && i < 44 && (float)Mathf.Abs(j - 32) < num)
					{
						val3 = (Color)(((int)(((float)(j - 32) + num) / 6f) % 2 == 0) ? new Color(0.85f, 0.1f, 0.1f) : Color.white);
					}
					else if (i >= 44 && i < 58 && (j - 32) * (j - 32) + (i - 44) * (i - 44) * 3 < 300)
					{
						((Color)(ref val3))..ctor(1f, 0.9f, 0.5f);
					}
					val.SetPixel(j, i, val3);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}
	}
	internal static class CinemaLinks
	{
		private static readonly string[] DirectExtensions = new string[4] { ".mp4", ".webm", ".mov", ".m4v" };

		private const string YtDlpUrl = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe";

		private static bool _busy;

		private static Process _process;

		private static readonly Queue<Action> MainThread = new Queue<Action>();

		private const string FfmpegUrl = "https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip";

		public static bool Busy => _busy;

		public static string Status { get; private set; } = "";

		public static string ToolsDir => Path.Combine(Plugin.VideoDir, "_tools");

		private static string TempDir => Path.Combine(Plugin.VideoDir, "_tmp");

		public static bool IsUrl(string s)
		{
			if (!string.IsNullOrEmpty(s))
			{
				if (!s.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
				{
					return s.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
				}
				return true;
			}
			return false;
		}

		public static bool IsDirectMedia(string url)
		{
			if (!Uri.TryCreate(url, UriKind.Absolute, out Uri result))
			{
				return false;
			}
			string value = Path.GetExtension(result.AbsolutePath).ToLowerInvariant();
			return Array.IndexOf(DirectExtensions, value) >= 0;
		}

		public static string Display(string file)
		{
			if (!IsUrl(file))
			{
				return file;
			}
			if (Uri.TryCreate(file, UriKind.Absolute, out Uri result))
			{
				string fileName = Path.GetFileName(result.AbsolutePath);
				if (!string.IsNullOrEmpty(fileName))
				{
					return fileName + " (" + result.Host + ")";
				}
				return result.Host;
			}
			if (file.Length <= 60)
			{
				return file;
			}
			return file.Substring(0, 57) + "...";
		}

		public static void HostPlay(string url, int hall = 0)
		{
			url = url.Trim();
			if (!Plugin.AllowLinks.Value)
			{
				CinemaScreen.Tip("Cinema", "Links are turned off in the host's config.", warning: true);
			}
			else if (!IsUrl(url))
			{
				CinemaScreen.Tip("Cinema", "That doesn't look like a link (it should start with https://).", warning: true);
			}
			else if (IsDirectMedia(url))
			{
				CinemaNet.ServerSetState(hall, url, playing: true, 0.0);
			}
			else if (_busy)
			{
				CinemaScreen.Tip("Cinema", "Still downloading the previous link, wait a moment.", warning: true);
			}
			else if (!((Object)(object)CinemaScreen.Instance == (Object)null))
			{
				_busy = true;
				Status = "Getting ready...";
				((MonoBehaviour)CinemaScreen.Instance).StartCoroutine(DownloadRoutine(url, hall));
			}
		}

		public static void Tick()
		{
			lock (MainThread)
			{
				while (MainThread.Count > 0)
				{
					MainThread.Dequeue()?.Invoke();
				}
			}
		}

		private static void Post(Action a)
		{
			lock (MainThread)
			{
				MainThread.Enqueue(a);
			}
		}

		private static IEnumerator DownloadRoutine(string url, int hall)
		{
			string ytdlp = FindTool("yt-dlp");
			if (ytdlp == null)
			{
				if (!Plugin.AutoDownloadYtDlp.Value || (int)Application.platform != 2)
				{
					Fail("yt-dlp not found. Put yt-dlp.exe in " + ToolsDir);
					yield break;
				}
				CinemaScreen.Tip("Cinema", "First link: downloading the YouTube helper (yt-dlp), one moment...");
				Status = "Downloading yt-dlp...";
				Directory.CreateDirectory(ToolsDir);
				string target = Path.Combine(ToolsDir, "yt-dlp.exe");
				UnityWebRequest req = UnityWebRequest.Get("https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe");
				try
				{
					req.downloadHandler = (DownloadHandler)new DownloadHandlerFile(target + ".part")
					{
						removeFileOnAbort = true
					};
					req.timeout = 120;
					yield return req.SendWebRequest();
					if ((int)req.result != 1)
					{
						Fail("Could not download yt-dlp: " + req.error);
						yield break;
					}
				}
				finally
				{
					((IDisposable)req)?.Dispose();
				}
				try
				{
					if (File.Exists(target))
					{
						File.Delete(target);
					}
					File.Move(target + ".part", target);
				}
				catch (Exception ex)
				{
					Fail("Could not save yt-dlp: " + ex.Message);
					yield break;
				}
				ytdlp = target;
			}
			if (FindTool("ffmpeg") == null && Plugin.LinkMaxHeight.Value > 360 && Plugin.AutoDownloadYtDlp.Value && (int)Application.platform == 2)
			{
				yield return EnsureFfmpeg();
			}
			Status = "Starting download...";
			CinemaScreen.Tip("Cinema", "Downloading the video, it starts as soon as it's done.");
			try
			{
				StartYtDlp(ytdlp, url, hall);
			}
			catch (Exception ex2)
			{
				Fail("Could not start yt-dlp: " + ex2.Message);
			}
		}

		private static IEnumerator EnsureFfmpeg()
		{
			Directory.CreateDirectory(ToolsDir);
			string zip = Path.Combine(ToolsDir, "ffmpeg.zip");
			string tmp = Path.Combine(ToolsDir, "ffmpeg_tmp");
			CinemaScreen.Tip("Cinema", "First link: downloading ffmpeg for 720p (one time, about 200 MB)...");
			UnityWebRequest req = UnityWebRequest.Get("https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip");
			try
			{
				req.downloadHandler = (DownloadHandler)new DownloadHandlerFile(zip)
				{
					removeFileOnAbort = true
				};
				UnityWebRequestAsyncOperation op = req.SendWebRequest();
				int lastTip = 0;
				while (!((AsyncOperation)op).isDone)
				{
					int num = (int)(req.downloadProgress * 100f);
					Status = $"Downloading ffmpeg: {num}%";
					if (num / 25 != lastTip / 25 && num < 100)
					{
						lastTip = num;
						CinemaScreen.Tip("Cinema", $"Downloading ffmpeg: {num}%");
					}
					yield return null;
				}
				if ((int)req.result != 1)
				{
					Plugin.Log.LogWarning((object)("ffmpeg download failed: " + req.error));
					CinemaScreen.Tip("Cinema", "Couldn't get ffmpeg, playing in 360p instead.", warning: true);
					yield break;
				}
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
			Status = "Unpacking ffmpeg...";
			try
			{
				if (Directory.Exists(tmp))
				{
					Directory.Delete(tmp, recursive: true);
				}
				Directory.CreateDirectory(tmp);
			}
			catch
			{
			}
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
			List<(string, string)> list = new List<(string, string)>();
			list.Add((Path.Combine(folderPath, "tar.exe"), "-xf \"" + zip + "\" -C \"" + tmp + "\""));
			list.Add(("powershell.exe", "-NoProfile -NonInteractive -Command \"Expand-Archive -LiteralPath '" + zip + "' -DestinationPath '" + tmp + "' -Force\""));
			List<(string, string)> list2 = list;
			string found = null;
			foreach (var item3 in list2)
			{
				string item = item3.Item1;
				string item2 = item3.Item2;
				Process proc = null;
				try
				{
					proc = Process.Start(new ProcessStartInfo(item, item2)
					{
						UseShellExecute = false,
						CreateNoWindow = true
					});
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Unzip with " + item + " failed: " + ex.Message));
				}
				if (proc != null)
				{
					float until = Time.realtimeSinceStartup + 180f;
					while (!proc.HasExited && Time.realtimeSinceStartup < until)
					{
						yield return null;
					}
					proc.Dispose();
					try
					{
						found = Directory.GetFiles(tmp, "ffmpeg.exe", SearchOption.AllDirectories).FirstOrDefault();
					}
					catch
					{
					}
					if (found != null)
					{
						break;
					}
				}
			}
			try
			{
				if (found != null)
				{
					string directoryName = Path.GetDirectoryName(found);
					string[] array = new string[2] { "ffmpeg.exe", "ffprobe.exe" };
					foreach (string path in array)
					{
						string text = Path.Combine(directoryName, path);
						string text2 = Path.Combine(ToolsDir, path);
						if (File.Exists(text))
						{
							if (File.Exists(text2))
							{
								File.Delete(text2);
							}
							File.Move(text, text2);
						}
					}
					Plugin.Log.LogInfo((object)("ffmpeg installed in " + ToolsDir));
				}
				Directory.Delete(tmp, recursive: true);
				File.Delete(zip);
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("ffmpeg cleanup: " + ex2.Message));
			}
			if (found == null)
			{
				CinemaScreen.Tip("Cinema", "Couldn't unpack ffmpeg, playing in 360p instead.", warning: true);
			}
		}

		private static void StartYtDlp(string exe, string url, int hall)
		{
			Directory.CreateDirectory(Plugin.VideoDir);
			Directory.CreateDirectory(TempDir);
			string text = FindTool("ffmpeg");
			int num = Mathf.Clamp(Plugin.LinkMaxHeight.Value, 144, 2160);
			string text2 = ((text != null) ? $"bv*[vcodec^=avc1][height<={num}]+ba[ext=m4a]/b[ext=mp4][vcodec^=avc1]/b[ext=mp4]" : "b[ext=mp4][vcodec^=avc1]/b[ext=mp4]");
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("--no-playlist --newline --progress --no-simulate --restrict-filenames --encoding utf-8 ");
			stringBuilder.Append("-f \"" + text2 + "\" ");
			string text3 = FindTool("deno");
			if (text3 != null)
			{
				stringBuilder.Append("--js-runtimes \"deno:" + text3 + "\" ");
			}
			if (text != null)
			{
				stringBuilder.Append("--merge-output-format mp4 --ffmpeg-location \"" + Path.GetDirectoryName(text) + "\" ");
			}
			string videoDir = Plugin.VideoDir.TrimEnd('\\', '/');
			stringBuilder.Append("-P \"" + videoDir + "\" -P \"temp:" + TempDir.TrimEnd('\\', '/') + "\" ");
			stringBuilder.Append("-o \"%(title).70B-%(id)s.%(ext)s\" ");
			stringBuilder.Append("--print after_move:filepath ");
			stringBuilder.Append('"').Append(url.Replace("\"", "")).Append('"');
			ProcessStartInfo processStartInfo = new ProcessStartInfo(exe, stringBuilder.ToString())
			{
				UseShellExecute = false,
				CreateNoWindow = true,
				RedirectStandardOutput = true,
				RedirectStandardError = true,
				StandardOutputEncoding = Encoding.UTF8,
				StandardErrorEncoding = Encoding.UTF8,
				WorkingDirectory = Plugin.VideoDir
			};
			Plugin.Log.LogInfo((object)("yt-dlp " + processStartInfo.Arguments));
			string finalPath = null;
			string lastError = null;
			int lastTip = -1;
			Regex progress = new Regex("\\[download\\]\\s+(\\d+(?:\\.\\d+)?)%");
			Regex already = new Regex("\\[download\\]\\s+(.+) has already been downloaded");
			Process p = new Process
			{
				StartInfo = processStartInfo,
				EnableRaisingEvents = true
			};
			p.OutputDataReceived += delegate(object _, DataReceivedEventArgs e)
			{
				OnLine(e.Data);
			};
			p.ErrorDataReceived += delegate(object _, DataReceivedEventArgs e)
			{
				OnLine(e.Data);
			};
			string videoId = YouTubeId(url);
			p.Exited += delegate
			{
				try
				{
					p.WaitForExit();
				}
				catch
				{
				}
				int code = -1;
				try
				{
					code = p.ExitCode;
				}
				catch
				{
				}
				string path = finalPath;
				string err = lastError;
				if ((path == null || !File.Exists(path)) && code == 0 && videoId != null)
				{
					try
					{
						path = Directory.GetFiles(videoDir, "*-" + videoId + ".mp4").FirstOrDefault();
					}
					catch
					{
					}
				}
				Post(delegate
				{
					_process = null;
					p.Dispose();
					if (code == 0 && path != null && File.Exists(path))
					{
						Done(path, hall);
					}
					else
					{
						Fail(err ?? $"yt-dlp failed (code {code}). See the BepInEx log.");
					}
				});
			};
			p.Start();
			_process = p;
			p.BeginOutputReadLine();
			p.BeginErrorReadLine();
			void OnLine(string data)
			{
				if (!string.IsNullOrEmpty(data))
				{
					string text4 = data.Trim();
					if (text4.StartsWith("ERROR"))
					{
						lastError = text4.Replace("ERROR:", "").Trim();
						Plugin.Log.LogWarning((object)("yt-dlp: " + text4));
					}
					else if (text4.StartsWith("WARNING"))
					{
						Plugin.Log.LogWarning((object)("yt-dlp: " + text4));
					}
					else
					{
						Match match = progress.Match(text4);
						if (match.Success)
						{
							int pct = (int)float.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
							Status = $"Downloading: {pct}%";
							if (pct / 25 != lastTip / 25 && pct < 100)
							{
								lastTip = pct;
								Post(delegate
								{
									CinemaScreen.Tip("Cinema", $"Downloading the video: {pct}%");
								});
							}
						}
						else
						{
							Match match2 = already.Match(text4);
							if (match2.Success)
							{
								finalPath = match2.Groups[1].Value.Trim();
							}
							else if (!text4.StartsWith("[") && text4.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase))
							{
								finalPath = text4;
							}
						}
					}
				}
			}
		}

		private static string YouTubeId(string url)
		{
			Match match = Regex.Match(url, "(?:v=|youtu\\.be/|shorts/|embed/|live/)([A-Za-z0-9_-]{11})");
			if (!match.Success)
			{
				return null;
			}
			return match.Groups[1].Value;
		}

		private static void Done(string path, int hall)
		{
			_busy = false;
			Status = "";
			string fileName = Path.GetFileName(path);
			if (!string.Equals(Path.GetDirectoryName(Path.GetFullPath(path)), Path.GetFullPath(Plugin.VideoDir).TrimEnd('\\', '/'), StringComparison.OrdinalIgnoreCase))
			{
				Fail("Downloaded to an unexpected folder: " + path);
				return;
			}
			Plugin.Log.LogInfo((object)("Link downloaded: " + fileName));
			CinemaScreen.ListVideos(forceRefresh: true);
			CinemaTransfer.BroadcastCatalog();
			CinemaNet.ServerSetState(hall, fileName, playing: true, 0.0);
		}

		private static void Fail(string message)
		{
			_busy = false;
			Status = "";
			Plugin.Log.LogError((object)("Link: " + message));
			CinemaScreen.Tip("Cinema", (message.Length > 120) ? (message.Substring(0, 117) + "...") : message, warning: true);
		}

		private static string FindTool(string name)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			string path = (((int)Application.platform == 2) ? (name + ".exe") : name);
			List<string> list = new List<string>
			{
				ToolsDir,
				Plugin.VideoDir
			};
			string environmentVariable = Environment.GetEnvironmentVariable("PATH");
			if (!string.IsNullOrEmpty(environmentVariable))
			{
				list.AddRange(environmentVariable.Split(Path.PathSeparator));
			}
			foreach (string item in list)
			{
				try
				{
					if (!string.IsNullOrWhiteSpace(item))
					{
						string text = Path.Combine(item.Trim().Trim('"'), path);
						if (File.Exists(text))
						{
							return text;
						}
					}
				}
				catch
				{
				}
			}
			return null;
		}

		public static void Cancel()
		{
			try
			{
				if (_process != null && !_process.HasExited)
				{
					_process.Kill();
				}
			}
			catch
			{
			}
			_process = null;
			_busy = false;
			Status = "";
		}
	}
	public class CinemaMenu : MonoBehaviour
	{
		private bool _open;

		private Vector2 _scroll;

		private string _seek = "";

		private string _link = "";

		private float _lightSlider = -1f;

		private float _nextLightSend;

		private GUIStyle _title;

		private GUIStyle _button;

		private GUIStyle _label;

		private GUIStyle _box;

		private int _hall;

		public static CinemaMenu Instance { get; private set; }

		public static bool IsOpen
		{
			get
			{
				if ((Object)(object)Instance != (Object)null)
				{
					return Instance._open;
				}
				return false;
			}
		}

		public int Hall => _hall;

		public static void Ensure(GameObject host)
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = host.AddComponent<CinemaMenu>();
			}
		}

		public void Open(int hall = 0)
		{
			_hall = Mathf.Clamp(hall, 0, 3);
			_lightSlider = -1f;
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && !val.inTerminalMenu && !val.quickMenuManager.isMenuOpen)
			{
				_open = true;
				val.quickMenuManager.isMenuOpen = true;
			}
		}

		public void Close()
		{
			if (_open)
			{
				_open = false;
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if ((Object)(object)val != (Object)null)
				{
					val.quickMenuManager.isMenuOpen = false;
				}
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}

		private void Update()
		{
			if (!_open)
			{
				return;
			}
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || val.isPlayerDead)
			{
				Close();
				return;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			Keyboard current = Keyboard.current;
			if (current != null && (((ButtonControl)current.escapeKey).wasPressedThisFrame || ((ButtonControl)current.tabKey).wasPressedThisFrame))
			{
				Close();
			}
		}

		private void OnDestroy()
		{
			Close();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Styles()
		{
			//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_0021: 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_0034: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_008e: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			if (_title == null)
			{
				_title = new GUIStyle(GUI.skin.label)
				{
					fontSize = 26,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_title.normal.textColor = new Color(1f, 0.8f, 0.2f);
				_label = new GUIStyle(GUI.skin.label)
				{
					fontSize = 17,
					wordWrap = true,
					richText = true
				};
				_label.normal.textColor = Color.white;
				_button = new GUIStyle(GUI.skin.button)
				{
					fontSize = 18,
					fixedHeight = 38f
				};
				Texture2D val = new Texture2D(1, 1);
				val.SetPixel(0, 0, new Color(0.08f, 0.02f, 0.03f, 0.94f));
				val.Apply();
				_box = new GUIStyle(GUI.skin.box);
				_box.normal.background = val;
			}
		}

		private void OnGUI()
		{
			//IL_006d: 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_08e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f4: Unknown result type (might be due to invalid IL or missing references)
			CinemaGlasses.DrawTint();
			if (!_open)
			{
				return;
			}
			Styles();
			CinemaScreen cinemaScreen = CinemaScreen.Get(_hall);
			float num = Mathf.Min(620, Screen.width - 40);
			float num2 = Mathf.Min(640, Screen.height - 40);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
			GUI.Box(val, GUIContent.none, _box);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 20f, ((Rect)(ref val)).y + 14f, num - 40f, num2 - 28f));
			GUILayout.Label($"CINEMA  -  HALL {_hall + 1}", _title, Array.Empty<GUILayoutOption>());
			string text = (((Object)(object)cinemaScreen == (Object)null || string.IsNullOrEmpty(cinemaScreen.CurrentFile)) ? "Nothing playing" : ((cinemaScreen.IsPlaying ? "Playing" : "Paused") + ": " + CinemaLinks.Display(cinemaScreen.CurrentFile) + "   " + Format(cinemaScreen.ExpectedPosition)));
			if (CinemaLinks.Busy)
			{
				text = text + "\n" + CinemaLinks.Status;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < 4; i++)
			{
				if (i != _hall)
				{
					CinemaScreen cinemaScreen2 = CinemaScreen.Get(i);
					stringBuilder.Append(string.Format("   Hall {0}: {1}", i + 1, ((Object)(object)cinemaScreen2 == (Object)null || string.IsNullOrEmpty(cinemaScreen2.CurrentFile)) ? "-" : CinemaLinks.Display(cinemaScreen2.CurrentFile)));
				}
			}
			text = text + "\n<size=13>" + stringBuilder.ToString().Trim() + "</size>";
			GUILayout.Label(text, _label, Array.Empty<GUILayoutOption>());
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsListening && !singleton.IsServer)
			{
				string pendingOffer = CinemaTransfer.PendingOffer;
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (!string.IsNullOrEmpty(pendingOffer))
				{
					GUILayout.Label($"<color=#ffcc55>Host wants to play \"{pendingOffer}\" ({CinemaTransfer.OfferSizeMB} MB)</color>", _label, Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("Accept", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }))
					{
						CinemaTransfer.AcceptPending();
					}
					if (GUILayout.Button("Always accept", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
					{
						Plugin.ReceiveVideos.Value = true;
						CinemaTransfer.AcceptPending();
					}
				}
				else
				{
					GUILayout.Label("Videos from the host:", _label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					if (GUILayout.Button(Plugin.ReceiveVideos.Value ? "Always accept: ON" : "Always accept: OFF", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) }))
					{
						Plugin.ReceiveVideos.Value = !Plugin.ReceiveVideos.Value;
					}
					GUILayout.FlexibleSpace();
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.Space(6f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("|<  Prev", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("prev", _hall);
			}
			if ((Object)(object)cinemaScreen != (Object)null && cinemaScreen.IsPlaying)
			{
				if (GUILayout.Button("||  Pause", _button, Array.Empty<GUILayoutOption>()))
				{
					CinemaNet.Request(CinemaAction.Pause, "", 0.0, _hall);
				}
			}
			else if (GUILayout.Button(">  Play", _button, Array.Empty<GUILayoutOption>()))
			{
				CinemaNet.Request(CinemaAction.Resume, "", 0.0, _hall);
			}
			if (GUILayout.Button("Next  >|", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("next", _hall);
			}
			if (GUILayout.Button("Stop", _button, Array.Empty<GUILayoutOption>()))
			{
				CinemaNet.Request(CinemaAction.Stop, "", 0.0, _hall);
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("-30s", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("seek -30", _hall);
			}
			if (GUILayout.Button("-10s", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("seek -10", _hall);
			}
			if (GUILayout.Button("+10s", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("seek +10", _hall);
			}
			if (GUILayout.Button("+30s", _button, Array.Empty<GUILayoutOption>()))
			{
				TerminalPatch.RunCommand("seek +30", _hall);
			}
			GUILayout.Label("Go to:", _label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			_seek = GUILayout.TextField(_seek, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(80f),
				GUILayout.Height(34f)
			});
			if (GUILayout.Button("Go", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }) && _seek.Length > 0)
			{
				TerminalPatch.RunCommand("seek " + _seek, _hall);
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Link:", _label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			_link = GUILayout.TextField(_link, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) });
			if (GUILayout.Button("Paste", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				_link = (GUIUtility.systemCopyBuffer ?? "").Trim();
			}
			if (GUILayout.Button("Play link", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }) && _link.Trim().Length > 0)
			{
				CinemaNet.Request(CinemaAction.Url, _link.Trim(), 0.0, _hall);
				_link = "";
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Your volume: {Mathf.RoundToInt(Plugin.Volume.Value * 100f)}", _label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) });
			Plugin.Volume.Value = GUILayout.HorizontalSlider(Plugin.Volume.Value, 0f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			GUILayout.EndHorizontal();
			if (_lightSlider < 0f)
			{
				_lightSlider = CinemaMoon.LightLevelOf(_hall);
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Lights: {Mathf.RoundToInt(_lightSlider * 100f)}%", _label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) });
			float num3 = GUILayout.HorizontalSlider(_lightSlider, 0.02f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			if (GUILayout.Button("Dark", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				num3 = 0.02f;
			}
			if (GUILayout.Button("Full", _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				num3 = 1f;
			}
			GUILayout.EndHorizontal();
			if (!Mathf.Approximately(num3, _lightSlider))
			{
				_lightSlider = num3;
				_nextLightSend = Time.unscaledTime + 0.12f;
			}
			if (_nextLightSend > 0f && Time.unscaledTime >= _nextLightSend)
			{
				_nextLightSend = 0f;
				CinemaMoon.RequestLights(_hall, _lightSlider);
			}
			else if (_nextLightSend <= 0f)
			{
				_lightSlider = CinemaMoon.LightLevelOf(_hall);
			}
			if (GUILayout.Button(CinemaGlasses.LocalWearing ? "Take off 3D glasses" : "Put on 3D glasses", _button, Array.Empty<GUILayoutOption>()))
			{
				CinemaGlasses.ToggleLocal();
			}
			GUILayout.Space(8f);
			GUILayout.Label("Movies (click to play for everyone):", _label, Array.Empty<GUILayoutOption>());
			_scroll = GUILayout.BeginScrollView(_scroll, Array.Empty<GUILayoutOption>());
			string[] array = TerminalPatch.AvailableVideos();
			if (array.Length == 0)
			{
				GUILayout.Label("No videos found. Put .mp4 files in:\n" + Plugin.VideoDir, _label, Array.Empty<GUILayoutOption>());
			}
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (GUILayout.Button((((Object)(object)cinemaScreen != (Object)null && string.Equals(text2, cinemaScreen.CurrentFile, StringComparison.OrdinalIgnoreCase)) ? "> " : "") + text2, _button, Array.Empty<GUILayoutOption>()))
				{
					CinemaNet.Request(CinemaAction.Play, text2, 0.0, _hall);
				}
			}
			GUILayout.EndScrollView();
			GUILayout.Space(6f);
			if (GUILayout.Button("Close  (Esc)", _button, Array.Empty<GUILayoutOption>()))
			{
				Close();
			}
			GUILayout.EndArea();
		}

		private static string Format(double t)
		{
			TimeSpan timeSpan = TimeSpan.FromSeconds(Math.Max(0.0, t));
			if (!(timeSpan.TotalHours >= 1.0))
			{
				return timeSpan.ToString("m\\:ss");
			}
			return timeSpan.ToString("h\\:mm\\:ss");
		}
	}
	internal static class CinemaMoon
	{
		private struct Dimmed
		{
			public Material Mat;

			public Color Base;

			public float Min;

			public int Hall;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Func<string, bool> <0>__IsImage;

			public static HandleNamedMessageDelegate <1>__OnLights;
		}

		public const string MoonName = "Theater";

		public const string Keyword = "theater";

		public static SelectableLevel Level;

		private static GameObject _room;

		private static Vector3 _seatSpawn;

		private static Vector3 _exitPad;

		private static bool _onGround;

		private static float _rampDrop;

		private static bool _terrainFailed;

		private const int Halls = 4;

		private const float HW = 15f;

		private const int GroundHalls = 3;

		private const float BW = 45f;

		private const float LD = 10f;

		private const float HD = 20f;

		private const float D = 30f;

		private const float H = 9f;

		private const float Base = 0.4f;

		private const float P = 1.6f;

		private const float RampLen = 6f;

		private const float TerraceD = 6f;

		private const float ZE = -15f;

		private const float ZW = -5f;

		private const float Up = 9.9f;

		private const float Top = 18.9f;

		private const float StairX0 = -3f;

		private const float StairX1 = -21f;

		private const float StairW = 2.2f;

		private const float HoleX0 = -21f;

		private const float HoleX1 = -11f;

		private const float HoleZ = -12.6f;

		private static readonly Transform[] _anchors = (Transform[])(object)new Transform[4];

		private static readonly Vector3[] _deskPos = (Vector3[])(object)new Vector3[4];

		private static int _roomLayer;

		private static readonly Color FacadeCream = new Color(0.93f, 0.86f, 0.72f);

		private static readonly Color NeonBlue = new Color(0.35f, 0.72f, 1f);

		private static readonly List<Texture2D> PosterTextures = new List<Texture2D>();

		private static string _posterKey;

		private static readonly Dictionary<int, Material> PosterMats = new Dictionary<int, Material>();

		private static string _posterReport = "Posters not loaded yet (they load when the cinema is built).";

		private static Dictionary<Color, Material> _matCache = new Dictionary<Color, Material>();

		private static readonly List<Object> RoomAssets = new List<Object>();

		private static readonly List<Dimmed> DimMats = new List<Dimmed>();

		private static readonly List<(HDAdditionalLightData light, float lumen, int hall)> DimLights = new List<(HDAdditionalLightData, float, int)>();

		private const string LightsMsg = "ben.cinemamod.lights2";

		public const float MinLights = 0.02f;

		private static readonly float[] LightLevels = Enumerable.Repeat(1f, 4).ToArray();

		public static bool IsCurrent
		{
			get
			{
				if ((Object)(object)Level != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null)
				{
					return (Object)(object)StartOfRound.Instance.currentLevel == (Object)(object)Level;
				}
				return false;
			}
		}

		public static bool LocalPlayerInRoom
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				if (LocalPos(out var l) && Mathf.Abs(l.x) < 23f && l.z > -15.5f && l.z < 15.5f && l.y > -1f)
				{
					return l.y < 19.9f;
				}
				return false;
			}
		}

		public static int LocalHall
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: 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_003f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
				if (!LocalPos(out var l) || l.z < -5.2f || l.z > 15.5f || l.y < -1f || l.y > 19.9f)
				{
					return -1;
				}
				if (l.y > 9.599999f)
				{
					if (!(Mathf.Abs(l.x - HallX(3)) < 7.5f))
					{
						return -1;
					}
					return 3;
				}
				for (int i = 0; i < 3; i++)
				{
					if (Mathf.Abs(l.x - HallX(i)) < 7.5f)
					{
						return i;
					}
				}
				return -1;
			}
		}

		internal static string PosterDir => Path.Combine(Plugin.VideoDir, "Posters");

		internal static string PosterReport => _posterReport;

		private static float ScreenWidth => Mathf.Clamp(Plugin.TheaterScreenWidth.Value, 6f, 14f);

		private static float HallX(int i)
		{
			if (i >= 3)
			{
				return 0f;
			}
			return ((float)i - 1f) * 15f;
		}

		private static float HallY(int i)
		{
			if (i >= 3)
			{
				return 9.5f;
			}
			return 0f;
		}

		private static bool LocalPos(out Vector3 l)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			l = default(Vector3);
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)_room == (Object)null || (Object)(object)val == (Object)null || val.isPlayerDead)
			{
				return false;
			}
			l = _room.transform.InverseTransformPoint(((Component)val).transform.position);
			return true;
		}

		public static bool MuteFor(int hall)
		{
			if ((Object)(object)_room != (Object)null)
			{
				return LocalHall != hall;
			}
			return false;
		}

		public static void RegisterLevel(StartOfRound sor)
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (sor.levels.Any((SelectableLevel l) => (Object)(object)l != (Object)null && l.PlanetName.EndsWith("Theater")))
			{
				Level = sor.levels.First((SelectableLevel l) => l.PlanetName.EndsWith("Theater"));
				return;
			}
			SelectableLevel val = ((IEnumerable<SelectableLevel>)sor.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel l) => (Object)(object)l != (Object)null && l.sceneName == "CompanyBuilding"));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Company moon not found; Theater moon not added.");
				return;
			}
			Level = Object.Instantiate<SelectableLevel>(val);
			((Object)Level).name = "TheaterLevel";
			Level.PlanetName = "00 Theater";
			Level.riskLevel = "Safe";
			Level.levelID = sor.levels.Length;
			Level.planetHasTime = false;
			Level.spawnEnemiesAndScrap = false;
			Level.currentWeather = (LevelWeatherType)(-1);
			Level.overrideWeather = false;
			Level.randomWeathers = (RandomWeatherWithVariables[])(object)new RandomWeatherWithVariables[0];
			Level.Enemies = new List<SpawnableEnemyWithRarity>();
			Level.OutsideEnemies = new List<SpawnableEnemyWithRarity>();
			Level.DaytimeEnemies = new List<SpawnableEnemyWithRarity>();
			Level.maxEnemyPowerCount = 0;
			Level.maxOutsideEnemyPowerCount = 0;
			Level.maxDaytimeEnemyPowerCount = 0;
			Level.spawnableScrap = new List<SpawnableItemWithRarity>();
			Level.minScrap = 0;
			Level.maxScrap = 0;
			Level.LevelDescription = "POPULATION: Just you and your crew.\nCONDITIONS: Comfortable seating, big screen.\nFAUNA: None. No time limit.";
			sor.levels = sor.levels.Append(Level).ToArray();
			Plugin.Log.LogInfo((object)$"Theater moon added as level {Level.levelID}");
		}

		public static void RegisterTerminal(Terminal terminal)
		{
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Expected O, but got Unknown
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Expected O, but got Unknown
			if ((Object)(object)Level == (Object)null || (Object)(object)terminal == (Object)null)
			{
				return;
			}
			TerminalNodesList terminalNodes = terminal.terminalNodes;
			if (terminal.moonsCatalogueList != null && !terminal.moonsCatalogueList.Contains(Level))
			{
				terminal.moonsCatalogueList = terminal.moonsCatalogueList.Where((SelectableLevel l) => (Object)(object)l == (Object)null || !l.PlanetName.EndsWith("Theater")).Append(Level).ToArray();
			}
			AddToMoonsList(terminalNodes);
			if (terminalNodes.allKeywords.Any((TerminalKeyword k) => k.word == "theater"))
			{
				return;
			}
			TerminalKeyword val = ((IEnumerable<TerminalKeyword>)terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "route"));
			TerminalKeyword val2 = ((IEnumerable<TerminalKeyword>)terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "info"));
			CompatibleNoun val3 = val?.compatibleNouns?.FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun n) => (Object)(object)n.noun != (Object)null && n.noun.word == "company"));
			if ((Object)(object)val == (Object)null || val3 == null)
			{
				Plugin.Log.LogError((object)"Terminal route keyword not found; Theater not added to terminal.");
				return;
			}
			TerminalKeyword val4 = ScriptableObject.CreateInstance<TerminalKeyword>();
			((Object)val4).name = "Theater";
			val4.word = "theater";
			val4.isVerb = false;
			val4.defaultVerb = val;
			TerminalNode val5 = Object.Instantiate<TerminalNode>(val3.result);
			((Object)val5).name = "theaterRoute";
			val5.displayText = "The cost to route to " + Level.PlanetName + " is [totalCost]. It is currently [currentPlanetTime] on this moon.\n\nPlease CONFIRM or DENY.\n\n";
			val5.itemCost = 0;
			val5.displayPlanetInfo = Level.levelID;
			val5.buyRerouteToMoon = -2;
			List<CompatibleNoun> list = new List<CompatibleNoun>();
			CompatibleNoun[] terminalOptions = val3.result.terminalOptions;
			foreach (CompatibleNoun val6 in terminalOptions)
			{
				CompatibleNoun val7 = new CompatibleNoun(val6.noun, val6.result);
				if ((Object)(object)val6.result != (Object)null && val6.result.buyRerouteToMoon >= 0)
				{
					TerminalNode val8 = Object.Instantiate<TerminalNode>(val6.result);
					((Object)val8).name = "theaterRouteConfirm";
					val8.buyRerouteToMoon = Level.levelID;
					val8.itemCost = 0;
					val8.displayPlanetInfo = Level.levelID;
					val8.displayText = "Routing autopilot to " + Level.PlanetName + ".\nYour new balance is [playerCredits].\n\nGrab some popcorn.\n\n";
					val7.result = val8;
				}
				list.Add(val7);
			}
			val5.terminalOptions = list.ToArray();
			val.compatibleNouns = val.compatibleNouns.Append(new CompatibleNoun(val4, val5)).ToArray();
			if ((Object)(object)val2 != (Object)null)
			{
				TerminalNode val9 = ScriptableObject.CreateInstance<TerminalNode>();
				((Object)val9).name = "theaterInfo";
				val9.displayText = Level.PlanetName + "\n----------------------\n\nA quiet moon with nothing on it but a cinema. No monsters, no clock: stay as long as you like.\n\nAfter landing, walk from the ship to the cinema building next to it. Inside: a control desk for the movies and lights, 3D glasses and a popcorn corner.\n\n";
				val9.clearPreviousText = true;
				val2.compatibleNouns = val2.compatibleNouns.Append(new CompatibleNoun(val4, val9)).ToArray();
			}
			terminalNodes.allKeywords = terminalNodes.allKeywords.Append(val4).ToArray();
			Plugin.Log.LogInfo((object)"Theater moon added to the terminal");
		}

		private static void AddToMoonsList(TerminalNodesList nodes)
		{
			TerminalNode val = ((IEnumerable<TerminalKeyword>)nodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "moons"))?.specialKeywordResult;
			if (!((Object)(object)val == (Object)null) && val.displayText != null && !val.displayText.Contains("Theater"))
			{
				string displayText = val.displayText;
				string text = "* Theater [Cinema safe]\n";
				int num = displayText.LastIndexOf("* ");
				int num2 = ((num >= 0) ? displayText.IndexOf('\n', num) : (-1));
				val.displayText = ((num2 >= 0) ? displayText.Insert(num2 + 1, "\n" + text) : (displayText.TrimEnd() + "\n\n" + text + "\n"));
				Plugin.Log.LogInfo((object)"Theater added to the moons list");
			}
		}

		public static void Tick()
		{
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			bool flag = IsCurrent && !instance.inShipPhase && CinemaTerrain.MoonSceneLoaded(Level);
			if (flag && !CinemaTerrain.Built && !_terrainFailed)
			{
				_terrainFailed = !CinemaTerrain.Build(Level);
			}
			else if (!flag && (CinemaTerrain.Built || _terrainFailed))
			{
				CinemaTerrain.Destroy();
				_terrainFailed = false;
			}
			if (CinemaTerrain.Built && instance.shipHasLanded)
			{
				CinemaTerrain.CorrectAfterLanding();
			}
			CinemaTerrain.EnsureSolid();
			CinemaNight.Tick();
			CinemaTerrain.UpdateAmbience((Object)(object)_room != (Object)null && LocalPlayerInRoom);
			bool flag2 = ((!CinemaTerrain.Built) ? (IsCurrent && instance.shipHasLanded && !instance.shipIsLeaving && !instance.inShipPhase) : (flag && !instance.shipIsLeaving));
			if (flag2 && (Object)(object)_room == (Object)null)
			{
				BuildRoom();
			}
			else if (!flag2 && (Object)(object)_room != (Object)null)
			{
				DestroyRoom();
			}
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val != (Object)null)
			{
				CinemaPopcorn.Tick(val);
			}
			if ((Object)(object)_room == (Object)null)
			{
				return;
			}
			PlayerControllerB val2 = val;
			if ((Object)(object)val2 == (Object)null || val2.isPlayerDead)
			{
				return;
			}
			DeskKeyFallback(val2);
			CinemaGlasses.KeyFallback(val2);
			if (!_onGround)
			{
				Vector3 val3 = ((Component)val2).transform.position - _exitPad;
				if (Mathf.Abs(val3.x) < 1.2f && Mathf.Abs(val3.z) < 1.2f && val3.y > -0.5f && val3.y < 2f)
				{
					ReturnToShip(val2);
				}
			}
		}

		public static string Enter()
		{
			if (!IsCurrent)
			{
				return "You need to land on Theater first.\n\nType ROUTE " + "theater".ToUpper() + ", then pull the lever.";
			}
			if ((Object)(object)_room == (Object)null)
			{
				return "The theater opens once the ship has landed.";
			}
			if (_onGround)
			{
				return "The cinema is a building next to the ship. Walk out of the door and look for the yellow sign!";
			}
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return "No player.";
			}
			CinemaScreen instance = CinemaScreen.Instance;
			if (instance != null)
			{
				((MonoBehaviour)instance).StartCoroutine(EnterAfterTerminal(val));
			}
			return "Enjoy the show! You'll be taken to the lobby when you leave the terminal.\n\nThe green pad by the entrance takes you back to the ship.";
		}

		private static IEnumerator EnterAfterTerminal(PlayerControllerB p)
		{
			while (p.inTerminalMenu)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(0.3f);
			if (!((Object)(object)_room == (Object)null))
			{
				Teleport(p, _seatSpawn + new Vector3(Random.Range(-3f, 3f), 0f, 0f), inShip: false);
				CinemaScreen.Tip("Theater", "Pick a hall: each one has its own movie. Green pad by the entrance = back to ship.");
			}
		}

		private static void ReturnToShip(PlayerControllerB p)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = StartOfRound.Instance.playerSpawnPositions[0].position;
			Teleport(p, position, inShip: true);
		}

		private static void Teleport(PlayerControllerB p, Vector3 pos, bool inShip)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			p.isInElevator = inShip;
			p.isInHangarShipRoom = inShip;
			p.isInsideFactory = false;
			p.TeleportPlayer(pos, false, 0f, false, true);
		}

		private static bool FindGroundSpot(out Vector3 origin, out Quaternion rotation, out float rampDrop, out string where)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_025d: 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_0264: 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_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: 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_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_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: 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_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			origin = default(Vector3);
			rotation = Quaternion.identity;
			where = "";
			rampDrop = 1.6f;
			StartOfRound instance = StartOfRound.Instance;
			Vector3 val = (((Object)(object)instance.outsideShipSpawnPosition != (Object)null) ? instance.outsideShipSpawnPosition.position : instance.elevatorTransform.position);
			Vector3 val2 = (((Object)(object)instance.middleOfShipNode != (Object)null) ? instance.middleOfShipNode.position : instance.elevatorTransform.position);
			Vector3 val3 = Vector3.ProjectOnPlane(val - val2, Vector3.up);
			if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
			{
				val3 = instance.elevatorTransform.forward;
			}
			((Vector3)(ref val3)).Normalize();
			int num = -1;
			string[] array = new string[11]
			{
				"Player", "PlayerRagdoll", "Enemies", "Props", "PhysicsObject", "ScanNode", "Triggers", "MapRadar", "UI", "HelmetVisor",
				"LineOfSight"
			};
			for (int i = 0; i < array.Length; i++)
			{
				int num2 = LayerMask.NameToLayer(array[i]);
				if (num2 >= 0)
				{
					num &= ~(1 << num2);
				}
			}
			List<Vector3> list = new List<Vector3>();
			for (int j = -2; j <= 2; j++)
			{
				for (int k = -2; k <= 2; k++)
				{
					list.Add(new Vector3((float)j * 45f / 4f, 0f, (float)k * 30f / 4f));
				}
			}
			float[] array2 = new float[16]
			{
				0f, 20f, -20f, 40f, -40f, 60f, -60f, 80f, -80f, 100f,
				-100f, 125f, -125f, 150f, -150f, 180f
			};
			float[] array3 = new float[8] { 25f, 31f, 38f, 46f, 56f, 68f, 82f, 100f };
			Vector3 val7 = default(Vector3);
			foreach (float num3 in array3)
			{
				float[] array4 = array2;
				foreach (float num4 in array4)
				{
					Vector3 val4 = Quaternion.Euler(0f, num4, 0f) * val3;
					Vector3 val5 = val + val4 * num3;
					Quaternion val6 = Quaternion.LookRotation(val4, Vector3.up);
					if (!Ground(val5, val.y, num, out var y) || Mathf.Abs(y - val.y) > 8f)
					{
						continue;
					}
					float num5 = y;
					float num6 = y;
					bool flag = true;
					foreach (Vector3 item in list)
					{
						if (!Ground(val5 + val6 * item, y, num, out var y2))
						{
							flag = false;
							break;
						}
						num5 = Mathf.Min(num5, y2);
						num6 = Mathf.Max(num6, y2);
					}
					if (!flag || num6 - num5 > 3.5f || !Ground(val5 + val6 * new Vector3(0f, 0f, -27.5f), y, num, out var y3))
					{
						continue;
					}
					float num7 = 1.6f + (num6 - y3);
					if (!(num7 < 0.3f) && !(num7 > 3.6f))
					{
						((Vector3)(ref val7))..ctor(23.1f, 9.3f, 15.6f);
						if (!Physics.CheckBox(new Vector3(val5.x, num6 + 0.4f + 0.4f + val7.y, val5.z), val7, val6, num, (QueryTriggerInteraction)1) && !Physics.CheckBox(new Vector3(val5.x, y3 + 1.6f, val5.z) + val6 * new Vector3(0f, 0f, -24.5f), new Vector3(2.6f, 1.2f, 3f), val6, num, (QueryTriggerInteraction)1))
						{
							origin = new Vector3(val5.x, num6, val5.z);
							rotation = val6;
							rampDrop = num7;
							where = ((Mathf.Abs(num4) <= 30f) ? "straight out of the ship door" : ((Mathf.Abs(num4) >= 150f) ? "behind the ship" : ((num4 > 0f) ? "to the right when you walk out of the door" : "to the left when you walk out of the door")));
							Plugin.Log.LogInfo((object)$"Theater: found a spot {num3} m from the door at angle {num4} (ground spread {num6 - num5:0.0} m)");
							return true;
						}
					}
				}
			}
			return false;
		}

		private static bool Ground(Vector3 at, float refY, int mask, out float y)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			y = 0f;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(new Vector3(at.x, refY + 30f, at.z), Vector3.down, ref val, 90f, mask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			y = ((RaycastHit)(ref val)).point.y;
			return true;
		}

		private static void BuildRoom()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_00bf: Expected O, but got Unknown
			//IL_00c9: 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_00e4: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: 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_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: 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_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_065b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0671: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_072d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0816: Unknown result type (might be due to invalid IL or missing references)
			//IL_082a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0853: Unknown result type (might be due to invalid IL or missing references)
			//IL_0867: Unknown result type (might be due to invalid IL or missing references)
			//IL_0999: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1b: Unknown result type (might be due to invalid IL or missing references)
			//IL_089b: Unknown result type (might be due to invalid IL or missing references)
			//IL_08af: Unknown result type (might be due to invalid IL or missing references)
			//IL_094a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0961: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a61: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a72: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a77: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b54: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b7d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c04: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d4e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ccc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ddb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dfe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e03: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e28: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e3c: Unknown result type (might be due to invalid IL or missing references)
			Transform elevatorTransform = StartOfRound.Instance.elevatorTransform;
			Vector3 origin;
			Quaternion rotation;
			string where;
			if (CinemaTerrain.Built)
			{
				_