Decompiled source of Regions Expanded v0.1.0

RegionsExpanded.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DbsContentApi;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using RegionsExpanded;
using RegionsExpanded.CustomContent;
using RegionsExpanded.Net;
using RegionsExpanded.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RegionsExpanded")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+afdb3ebe6374dcaa0e1a00addcf6cd0cb036f554")]
[assembly: AssemblyProduct("Regions Expanded")]
[assembly: AssemblyTitle("RegionsExpanded")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
public class MapIconInteractable : Interactable
{
	private int _buyInDollars;

	private int _depthMeters;

	private int _mapIndex;

	private bool _configured;

	public void Setup(MapInstance entry, int mapIndex)
	{
		_buyInDollars = entry.BuyInDollars;
		_depthMeters = entry.DepthMeters;
		_mapIndex = mapIndex;
		_configured = true;
	}

	public override bool IsValid(Player player)
	{
		if (!_configured)
		{
			return false;
		}
		bool mapPaidEffective = MapSelectionRoomProps.IsMapBuyInPaidFromSources();
		if (MapScreenVisualCoordinator.IsMapIconInteractionGloballyLocked(mapPaidEffective))
		{
			return false;
		}
		return true;
	}

	public override void Interact(Player player)
	{
		if (!_configured)
		{
			Logger.LogError("RegionsExpanded: MapIconInteractable.Interact: not configured (Setup not called).");
		}
		else if ((Object)(object)player == (Object)null)
		{
			Logger.LogError("RegionsExpanded: MapIconInteractable.Interact: player is null (unexpected).");
		}
		else if (player.refs == null || (Object)(object)player.refs.view == (Object)null || !player.refs.view.IsMine)
		{
			Logger.LogError("RegionsExpanded: MapIconInteractable.Interact ignored — refs/view missing or not local. refsNull=" + (player.refs == null) + " viewNull=" + ((Object)(object)player.refs?.view == (Object)null) + " IsMine=" + ((Object)(object)player.refs?.view != (Object)null && player.refs.view.IsMine));
		}
		else if (_depthMeters > CustomContent.MAX_DEPTH)
		{
			Logger.LogError("RegionsExpanded: Map buy-in interact blocked — depth " + _depthMeters + "m >= MAX_DEPTH " + CustomContent.MAX_DEPTH + ".");
			MapBuyInRouting.PlayNoMoneySfxSynced();
		}
		else
		{
			MapBuyInRouting.RequestDeductMapBuyIn(_buyInDollars, _mapIndex);
		}
	}
}
public class TestButton : Interactable
{
	public override void Interact(Player player)
	{
		Logger.Log("TestButton: Interact");
	}
}
public class UpgradeDropBox : MonoBehaviourPunCallbacks
{
	public const int PhotonViewId = 996;

	private const float DelayBeforeEvaluate = 0.3f;

	private const float MaxWaitAfterClosed = 1.5f;

	private const float ProcessingDuration = 3f;

	public UpgradeDropBoxItemDetector Detector;

	public UpgradeDropBoxLid Lid;

	public GameObject Particles;

	private PhotonView m_photonView;

	private ParticleSystem[] m_particleSystems = Array.Empty<ParticleSystem>();

	private bool m_checkingContents;

	private bool m_ejecting;

	private bool m_processing;

	private float m_elapsedSinceFullyClosed;

	private float m_processingElapsed;

	private DivingBellUpgrade? m_pendingUpgrade;

	private float m_ignoreNewInteractionsUntilRealtime;

	private void Awake()
	{
		m_photonView = ((Component)this).GetComponent<PhotonView>();
		if ((Object)(object)m_photonView == (Object)null)
		{
			Logger.LogError("UpgradeDropBox: PhotonView not found on Awake! Ensure it is added before this script.");
		}
		Transform val = ((Component)this).transform.Find("Particles/Left");
		Transform val2 = ((Component)this).transform.Find("Particles/Right");
		ParticleSystem val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ParticleSystem>() : null);
		ParticleSystem val4 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<ParticleSystem>() : null);
		if ((Object)(object)val3 == (Object)null)
		{
			Logger.LogError("UpgradeDropBox: ParticleSystem not found on Particles/Left");
		}
		if ((Object)(object)val4 == (Object)null)
		{
			Logger.LogError("UpgradeDropBox: ParticleSystem not found on Particles/Right");
		}
		m_particleSystems = (ParticleSystem[])((!((Object)(object)val3 != (Object)null) || !((Object)(object)val4 != (Object)null)) ? ((!((Object)(object)val3 != (Object)null)) ? ((!((Object)(object)val4 != (Object)null)) ? ((Array)Array.Empty<ParticleSystem>()) : ((Array)new ParticleSystem[1] { val4 })) : new ParticleSystem[1] { val3 }) : new ParticleSystem[2] { val3, val4 });
	}

	private void FixedUpdate()
	{
		//IL_0093: 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_00b0: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsMasterClient || !m_ejecting)
		{
			return;
		}
		if (!Lid.m_opened)
		{
			Lid.Open();
		}
		List<(Item, Pickup)> list = Detector.CheckForItems();
		if (list.Count == 0)
		{
			m_ejecting = false;
		}
		else
		{
			if (!Lid.IsHalfwayOpenForEject())
			{
				return;
			}
			Transform transform = ((Component)this).transform;
			foreach (var item2 in list)
			{
				Pickup item = item2.Item2;
				if (!((Object)(object)item == (Object)null) && !((Object)(object)item.Rigidbody == (Object)null))
				{
					Rigidbody rigidbody = item.Rigidbody;
					if (!(rigidbody.linearVelocity.y > 0.1f))
					{
						rigidbody.AddTorque(Vector3.right * 3f, (ForceMode)1);
						rigidbody.AddForce(Vector3.up * 25f + -transform.forward * 6f, (ForceMode)1);
					}
				}
			}
		}
	}

	private void Update()
	{
		if (PhotonNetwork.IsMasterClient)
		{
			UpdateLogic();
		}
	}

	private static bool TryGetBellUpgrade(Pickup pickup, out DivingBellUpgrade upgrade)
	{
		upgrade = DivingBellUpgrade.Radar;
		if ((Object)(object)pickup?.itemInstance == (Object)null)
		{
			return false;
		}
		DivingBellUpgradeItemBehaviour component = ((Component)pickup.itemInstance).GetComponent<DivingBellUpgradeItemBehaviour>();
		if ((Object)(object)component == (Object)null)
		{
			return false;
		}
		upgrade = component.BellUpgrade;
		return true;
	}

	private void UpdateLogic()
	{
		if (m_processing)
		{
			m_processingElapsed += Time.deltaTime;
			if (m_processingElapsed >= 3f)
			{
				EndProcessing();
			}
			return;
		}
		List<(Item, Pickup)> list = Detector.CheckForItems();
		bool flag = list.Count > 0;
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (realtimeSinceStartup < m_ignoreNewInteractionsUntilRealtime)
		{
			if (!flag)
			{
				m_ignoreNewInteractionsUntilRealtime = 0f;
			}
			return;
		}
		if (!m_checkingContents && !m_ejecting)
		{
			if (!flag && !Lid.m_opened)
			{
				Lid.Open();
			}
			else if (flag && Lid.m_opened)
			{
				Lid.Close();
			}
		}
		if (!m_checkingContents && !m_ejecting && flag && !Lid.m_opened && Lid.IsFullyClosed())
		{
			m_checkingContents = true;
			m_elapsedSinceFullyClosed = 0f;
		}
		if (!m_checkingContents)
		{
			return;
		}
		list = Detector.CheckForItems();
		if (list.Count == 0)
		{
			m_checkingContents = false;
			m_elapsedSinceFullyClosed = 0f;
			if (!Lid.m_opened)
			{
				Lid.Open();
			}
			return;
		}
		m_elapsedSinceFullyClosed += Time.deltaTime;
		if (m_elapsedSinceFullyClosed < 0.3f)
		{
			return;
		}
		if (m_elapsedSinceFullyClosed <= 1.5f)
		{
			if (!TryConsumeSingleBellUpgrade(list))
			{
				BeginEject();
			}
		}
		else
		{
			BeginEject();
		}
	}

	private bool TryConsumeSingleBellUpgrade(List<(Item item, Pickup pickup)> items)
	{
		if (items.Count != 1 || (Object)(object)items[0].pickup == (Object)null)
		{
			return false;
		}
		Pickup item = items[0].pickup;
		if (!TryGetBellUpgrade(item, out var upgrade))
		{
			return false;
		}
		item.m_photonView.RPC("RPC_Remove", (RpcTarget)2, Array.Empty<object>());
		m_checkingContents = false;
		m_elapsedSinceFullyClosed = 0f;
		BeginProcessing(upgrade);
		return true;
	}

	private void BeginProcessing(DivingBellUpgrade upgradeKind)
	{
		if (PhotonNetwork.InRoom && (Object)(object)m_photonView != (Object)null)
		{
			m_photonView.RPC("RPC_BeginProcessing", (RpcTarget)0, new object[2]
			{
				(int)upgradeKind,
				true
			});
		}
		else
		{
			StartProcessingState(upgradeKind, 0f);
			PlayProcessingVisuals(playSfx: true);
		}
	}

	private void StartProcessingState(DivingBellUpgrade upgradeKind, float elapsed)
	{
		m_processing = true;
		m_processingElapsed = elapsed;
		m_pendingUpgrade = upgradeKind;
	}

	private void PlayProcessingVisuals(bool playSfx)
	{
		if ((Object)(object)Particles != (Object)null)
		{
			if (!Particles.activeSelf)
			{
				Particles.SetActive(true);
			}
			ParticleSystem[] particleSystems = m_particleSystems;
			foreach (ParticleSystem val in particleSystems)
			{
				val.Clear();
				val.Play();
			}
		}
		else
		{
			Logger.LogError("UpgradeDropBox: Particles reference is null");
		}
		if (!playSfx)
		{
			return;
		}
		Transform val2 = ((Component)this).transform.Find("SFX/Construction");
		if ((Object)(object)val2 != (Object)null)
		{
			SFX_PlayOneShot component = ((Component)val2).GetComponent<SFX_PlayOneShot>();
			if ((Object)(object)component != (Object)null)
			{
				component.Play();
			}
			else
			{
				Logger.LogError("UpgradeDropBox: SFX_PlayOneShot not found on SFX/Construction");
			}
		}
		else
		{
			Logger.LogError("UpgradeDropBox: child SFX/Construction not found");
		}
	}

	private void StopProcessingVisuals(ParticleSystemStopBehavior stopBehavior)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystem[] particleSystems = m_particleSystems;
		foreach (ParticleSystem val in particleSystems)
		{
			val.Stop(true, stopBehavior);
		}
	}

	private void EndProcessing()
	{
		m_processing = false;
		m_processingElapsed = 0f;
		if (m_pendingUpgrade.HasValue)
		{
			BellUpgradeRoomProps.MasterAddUpgrade(m_pendingUpgrade.Value);
			m_pendingUpgrade = null;
		}
		else
		{
			Logger.LogError("UpgradeDropBox: EndProcessing called but m_pendingUpgrade is null (unexpected).");
		}
		if (PhotonNetwork.InRoom && (Object)(object)m_photonView != (Object)null)
		{
			m_photonView.RPC("RPC_EndProcessingVisuals", (RpcTarget)0, Array.Empty<object>());
		}
		else
		{
			StopProcessingVisuals((ParticleSystemStopBehavior)1);
		}
		m_ignoreNewInteractionsUntilRealtime = Time.realtimeSinceStartup + 0.65f;
		Lid.Open();
	}

	private void BeginEject()
	{
		m_checkingContents = false;
		m_elapsedSinceFullyClosed = 0f;
		m_ejecting = true;
		if (!Lid.m_opened)
		{
			Lid.Open();
		}
	}

	public void SyncHatchState()
	{
		if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && (Object)(object)m_photonView != (Object)null)
		{
			m_photonView.RPC("RPC_SyncLid", (RpcTarget)1, new object[1] { Lid.m_opened });
		}
	}

	[PunRPC]
	public void RPC_SyncLid(bool state)
	{
		Lid.SetOpenState(state, playSfx: true, syncIfMaster: false);
	}

	[PunRPC]
	private void RPC_BeginProcessing(int upgradeKind, bool playSfx)
	{
		StartProcessingState((DivingBellUpgrade)upgradeKind, 0f);
		PlayProcessingVisuals(playSfx);
	}

	[PunRPC]
	private void RPC_EndProcessingVisuals()
	{
		m_processing = false;
		m_processingElapsed = 0f;
		m_pendingUpgrade = null;
		StopProcessingVisuals((ParticleSystemStopBehavior)1);
	}

	public override void OnPlayerEnteredRoom(Player newPlayer)
	{
		((MonoBehaviourPunCallbacks)this).OnPlayerEnteredRoom(newPlayer);
		if (PhotonNetwork.IsMasterClient && !((Object)(object)m_photonView == (Object)null))
		{
			int num = (int)(m_pendingUpgrade.HasValue ? m_pendingUpgrade.Value : ((DivingBellUpgrade)(-1)));
			m_photonView.RPC("RPC_SyncState", newPlayer, new object[4] { Lid.m_opened, m_processing, num, m_processingElapsed });
		}
	}

	[PunRPC]
	private void RPC_SyncState(bool lidOpened, bool processing, int pendingUpgrade, float processingElapsed)
	{
		Lid.SetOpenState(lidOpened, playSfx: false, syncIfMaster: false);
		if (processing)
		{
			if (pendingUpgrade >= 0)
			{
				StartProcessingState((DivingBellUpgrade)pendingUpgrade, processingElapsed);
			}
			PlayProcessingVisuals(playSfx: false);
		}
		else
		{
			m_processing = false;
			m_processingElapsed = 0f;
			m_pendingUpgrade = null;
			StopProcessingVisuals((ParticleSystemStopBehavior)0);
		}
	}
}
public class UpgradeDropBoxItemDetector : MonoBehaviour
{
	private Collider[] results = (Collider[])(object)new Collider[10];

	public List<(Item item, Pickup pickup)> CheckForItems()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		HashSet<Pickup> hashSet = new HashSet<Pickup>();
		List<(Item, Pickup)> list = new List<(Item, Pickup)>();
		int num = Physics.OverlapBoxNonAlloc(((Component)this).transform.position, ((Component)this).transform.lossyScale * 0.5f, results, ((Component)this).transform.rotation);
		for (int i = 0; i < num; i++)
		{
			Collider val = results[i];
			Pickup componentInParent = ((Component)val).GetComponentInParent<Pickup>();
			if (Object.op_Implicit((Object)(object)componentInParent) && (Object)(object)componentInParent.itemInstance != (Object)null && (Object)(object)componentInParent.itemInstance.item != (Object)null)
			{
				Item item = componentInParent.itemInstance.item;
				if (hashSet.Add(componentInParent))
				{
					list.Add((item, componentInParent));
				}
			}
		}
		return list;
	}

	private void OnDrawGizmos()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 matrix = Gizmos.matrix;
		Gizmos.matrix = ((Component)this).transform.localToWorldMatrix;
		Gizmos.color = new Color(0f, 1f, 0f, 0.5f);
		Gizmos.DrawCube(Vector3.zero, Vector3.one);
		Gizmos.matrix = matrix;
	}
}
public class UpgradeDropBoxLid : MonoBehaviour
{
	public UpgradeDropBox Machine;

	public bool m_opened = true;

	public float Spring = 70f;

	public float Drag = 0.15f;

	public float m_openedRotation;

	public float m_closedRotation = 90f;

	private OneDPhysicsSpring m_spring;

	private void Awake()
	{
		//IL_0003: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		OneDPhysicsSpring spring = default(OneDPhysicsSpring);
		((OneDPhysicsSpring)(ref spring)).Spring = Spring;
		((OneDPhysicsSpring)(ref spring)).Drag = Drag;
		m_spring = spring;
	}

	private void Update()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		((OneDPhysicsSpring)(ref m_spring)).Drag = Drag;
		((OneDPhysicsSpring)(ref m_spring)).Spring = Spring;
		((OneDPhysicsSpring)(ref m_spring)).Update();
		((Component)this).transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, ((OneDPhysicsSpring)(ref m_spring)).Current));
	}

	private void FixedUpdate()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		((OneDPhysicsSpring)(ref m_spring)).Target = (m_opened ? m_openedRotation : m_closedRotation);
		((OneDPhysicsSpring)(ref m_spring)).FixedUpdate();
		m_spring = SpringClamp.BounceClamp<OneDPhysicsSpring>(m_spring, Mathf.Min(m_openedRotation, m_closedRotation) - 5f, Mathf.Max(m_openedRotation, m_closedRotation) + 5f, 0.6f);
	}

	public bool IsFullyClosed()
	{
		if (m_opened)
		{
			return false;
		}
		if (Mathf.Abs(((OneDPhysicsSpring)(ref m_spring)).Current - m_closedRotation) < 3f)
		{
			return Mathf.Abs(((OneDPhysicsSpring)(ref m_spring)).Velocity) < 0.25f;
		}
		return false;
	}

	public bool IsHalfwayOpenForEject()
	{
		if (!m_opened)
		{
			return false;
		}
		float num = (m_closedRotation + m_openedRotation) * 0.5f;
		return ((OneDPhysicsSpring)(ref m_spring)).Current <= num + 5f;
	}

	public void Close()
	{
		SetOpenState(opened: false, playSfx: true, syncIfMaster: true);
	}

	public void Open()
	{
		SetOpenState(opened: true, playSfx: true, syncIfMaster: true);
	}

	public void SetOpenState(bool opened, bool playSfx, bool syncIfMaster)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (m_opened == opened)
		{
			return;
		}
		m_opened = opened;
		if (syncIfMaster && PhotonNetwork.IsMasterClient)
		{
			Machine.SyncHatchState();
		}
		if (playSfx)
		{
			SFX_Instance val = (opened ? CustomContent.hatchOpenSfx : CustomContent.hatchCloseSfx);
			if ((Object)(object)val != (Object)null)
			{
				val.Play(((Component)this).transform.position, false, 1f, (Transform)null);
			}
		}
	}
}
namespace RegionsExpanded
{
	public sealed class PlatingVisualRoot : MonoBehaviour
	{
	}
	public sealed class RadarVisualRoot : MonoBehaviour
	{
	}
	public enum ElevatorButtonDirection
	{
		Up,
		Down
	}
	public class ElevatorCabinButton : Interactable
	{
		public ElevatorController? elevator;

		public ElevatorButtonDirection direction;

		private bool m_onCooldown;

		public override bool IsValid(Player player)
		{
			((Interactable)this).hoverText = ((direction == ElevatorButtonDirection.Up) ? "Ascend" : "Descend");
			if ((Object)(object)elevator == (Object)null)
			{
				return false;
			}
			if (direction != ElevatorButtonDirection.Up)
			{
				return elevator.CanDescend;
			}
			return elevator.CanAscend;
		}

		public override void Interact(Player player)
		{
			if (!m_onCooldown && !((Object)(object)elevator == (Object)null))
			{
				if (direction == ElevatorButtonDirection.Up)
				{
					elevator.AttemptAscend();
				}
				else
				{
					elevator.AttemptDescend();
				}
				((MonoBehaviour)this).StartCoroutine(Cooldown());
			}
		}

		private IEnumerator Cooldown()
		{
			m_onCooldown = true;
			yield return (object)new WaitForSeconds(0.5f);
			m_onCooldown = false;
		}
	}
	public enum ElevatorState
	{
		DoorClosed,
		DoorOpening,
		DoorOpen,
		DoorClosing,
		Ascending,
		Descending,
		Crashing
	}
	public class ElevatorController : MonoBehaviourPunCallbacks
	{
		public const float BottomY = 88.2f;

		public const float TopY = 177.4f;

		public const float MoveSpeed = 6f;

		public const int ElevatorViewId = 997;

		private const float CrashChance = 0.2f;

		private const float CrashMinHeightProgress = 0.5f;

		private const float CrashMaxHeightProgress = 0.9f;

		private const float CrashGravity = 9.81f;

		private const float CrashWarningDelay = 0.4f;

		private const float MoveGamefeelInterval = 0.21f;

		private const float MoveGamefeelAmount = 2f;

		private const float MoveGamefeelDuration = 0.2f;

		private const float MoveGamefeelScale = 10f;

		private const float MechanicalJoltGamefeelAmount = 6f;

		private const float MechanicalJoltGamefeelDuration = 0.2f;

		private const float CrashWarningGamefeelAmount = 14f;

		private const float CrashWarningGamefeelDuration = 0.65f;

		private const float CrashStartGamefeelAmount = 10f;

		private const float CrashStartGamefeelDuration = 0.5f;

		private const float CrashImpactGamefeelAmount = 36f;

		private const float CrashImpactGamefeelDuration = 0.6f;

		private const float HardGamefeelScale = 30f;

		public ElevatorDoor? door;

		public ElevatorSFX? sfx;

		private PhotonView? m_photonView;

		private Rigidbody m_rigidbody;

		private ElevatorState m_state;

		private bool m_isAtTop;

		public bool CanAscend
		{
			get
			{
				if (m_state == ElevatorState.DoorClosed)
				{
					return !m_isAtTop;
				}
				return false;
			}
		}

		public bool CanDescend
		{
			get
			{
				if (m_state == ElevatorState.DoorClosed)
				{
					return m_isAtTop;
				}
				return false;
			}
		}

		public bool CanToggleDoor
		{
			get
			{
				if (m_state != ElevatorState.DoorOpen)
				{
					return m_state == ElevatorState.DoorClosed;
				}
				return true;
			}
		}

		public bool IsDoorOpen
		{
			get
			{
				if (m_state != ElevatorState.DoorOpen)
				{
					return m_state == ElevatorState.DoorOpening;
				}
				return true;
			}
		}

		public ElevatorState CurrentState => m_state;

		private void Start()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			m_photonView = ((Component)this).GetComponent<PhotonView>();
			m_rigidbody = ((Component)this).GetComponent<Rigidbody>();
			m_isAtTop = ((Component)this).transform.localPosition.y > 132.79999f;
			m_state = ElevatorState.DoorClosed;
			if ((Object)(object)door != (Object)null)
			{
				door.Init(isOpen: false);
			}
			else
			{
				Debug.LogError((object)"[ElevatorController] 'door' reference is null — did CustomContent.cs wire it?");
			}
			if (!((Object)(object)sfx == (Object)null))
			{
				return;
			}
			Transform val = ((Component)this).transform.Find("SFX");
			if ((Object)(object)val != (Object)null)
			{
				sfx = ((Component)val).GetComponent<ElevatorSFX>();
				if ((Object)(object)sfx == (Object)null)
				{
					sfx = ((Component)val).gameObject.AddComponent<ElevatorSFX>();
				}
			}
			else
			{
				Debug.LogWarning((object)"[ElevatorController] cabin/SFX not found — movement sounds disabled.");
			}
		}

		public void AttemptToggleDoor()
		{
			if (!((Object)(object)m_photonView == (Object)null))
			{
				if (m_state == ElevatorState.DoorOpen)
				{
					m_photonView.RPC("RPC_Close", (RpcTarget)0, Array.Empty<object>());
				}
				else if (m_state == ElevatorState.DoorClosed)
				{
					m_photonView.RPC("RPC_Open", (RpcTarget)0, Array.Empty<object>());
				}
			}
		}

		[PunRPC]
		public void RPC_Open()
		{
			if (m_state == ElevatorState.DoorClosed && !((Object)(object)door == (Object)null))
			{
				m_state = ElevatorState.DoorOpening;
				((MonoBehaviour)this).StartCoroutine(RunDoorAnimation(door.Open(), ElevatorState.DoorOpen));
			}
		}

		[PunRPC]
		public void RPC_Close()
		{
			if (m_state == ElevatorState.DoorOpen && !((Object)(object)door == (Object)null))
			{
				m_state = ElevatorState.DoorClosing;
				((MonoBehaviour)this).StartCoroutine(RunDoorAnimation(door.Close(), ElevatorState.DoorClosed));
			}
		}

		private IEnumerator RunDoorAnimation(IEnumerator doorRoutine, ElevatorState stateAfter)
		{
			yield return doorRoutine;
			m_state = stateAfter;
		}

		public void AttemptAscend()
		{
			if (CanAscend && !((Object)(object)m_photonView == (Object)null))
			{
				float crashLocalY;
				bool flag = RollCrash(out crashLocalY);
				m_photonView.RPC("RPC_StartAscend", (RpcTarget)0, new object[2] { flag, crashLocalY });
			}
		}

		public void AttemptDescend()
		{
			if (CanDescend && !((Object)(object)m_photonView == (Object)null))
			{
				float crashLocalY;
				bool flag = RollCrash(out crashLocalY);
				m_photonView.RPC("RPC_StartDescend", (RpcTarget)0, new object[2] { flag, crashLocalY });
			}
		}

		[PunRPC]
		public void RPC_StartAscend(bool shouldCrash, float crashLocalY)
		{
			if (m_state == ElevatorState.DoorClosed && !m_isAtTop)
			{
				m_state = ElevatorState.Ascending;
				BeginMovementSfx();
				((MonoBehaviour)this).StartCoroutine(MoveCabin(177.4f, shouldCrash, crashLocalY, delegate
				{
					m_isAtTop = true;
					m_state = ElevatorState.DoorClosed;
					EndMovementSfx();
				}));
			}
		}

		[PunRPC]
		public void RPC_StartDescend(bool shouldCrash, float crashLocalY)
		{
			if (m_state == ElevatorState.DoorClosed && m_isAtTop)
			{
				m_state = ElevatorState.Descending;
				BeginMovementSfx();
				((MonoBehaviour)this).StartCoroutine(MoveCabin(88.2f, shouldCrash, crashLocalY, delegate
				{
					m_isAtTop = false;
					m_state = ElevatorState.DoorClosed;
					EndMovementSfx();
				}));
			}
		}

		private static bool RollCrash(out float crashLocalY)
		{
			crashLocalY = Mathf.Lerp(88.2f, 177.4f, Random.Range(0.5f, 0.9f));
			return Random.value < 0.2f;
		}

		private void BeginMovementSfx()
		{
			sfx?.PlayStartMove();
			sfx?.StartMoveLoop();
			AddMechanicalJoltGamefeel();
		}

		private void EndMovementSfx()
		{
			sfx?.PlayArrive();
			AddMechanicalJoltGamefeel();
		}

		private void AddMoveGamefeel()
		{
			GamefeelHandler instance = GamefeelHandler.instance;
			if (instance != null)
			{
				PerlinShake perlin = instance.perlin;
				if (perlin != null)
				{
					perlin.AddShake(2f, 0.2f, 10f);
				}
			}
		}

		private void AddMechanicalJoltGamefeel()
		{
			GamefeelHandler instance = GamefeelHandler.instance;
			if (instance != null)
			{
				PerlinShake perlin = instance.perlin;
				if (perlin != null)
				{
					perlin.AddShake(6f, 0.2f, 30f);
				}
			}
		}

		private void AddCrashWarningGamefeel()
		{
			GamefeelHandler instance = GamefeelHandler.instance;
			if (instance != null)
			{
				PerlinShake perlin = instance.perlin;
				if (perlin != null)
				{
					perlin.AddShake(14f, 0.65f, 30f);
				}
			}
		}

		private void AddCrashStartGamefeel()
		{
			GamefeelHandler instance = GamefeelHandler.instance;
			if (instance != null)
			{
				PerlinShake perlin = instance.perlin;
				if (perlin != null)
				{
					perlin.AddShake(10f, 0.5f, 30f);
				}
			}
		}

		private void AddCrashImpactGamefeel()
		{
			GamefeelHandler instance = GamefeelHandler.instance;
			if (instance != null)
			{
				PerlinShake perlin = instance.perlin;
				if (perlin != null)
				{
					perlin.AddShake(36f, 0.6f, 30f);
				}
			}
		}

		private IEnumerator MoveCabin(float targetLocalY, bool shouldCrash, float crashLocalY, Action onArrived)
		{
			float nextMoveGamefeelTime = Time.time;
			while (true)
			{
				float y = ((Component)this).transform.localPosition.y;
				if (Mathf.Abs(y - targetLocalY) <= 0.01f)
				{
					break;
				}
				if (Time.time >= nextMoveGamefeelTime)
				{
					AddMoveGamefeel();
					nextMoveGamefeelTime = Time.time + 0.21f;
				}
				float num = Mathf.MoveTowards(y, targetLocalY, 6f * Time.fixedDeltaTime);
				m_rigidbody.MovePosition(GetWorldPositionForLocalY(num));
				if (shouldCrash && HasReachedCrashHeight(num, targetLocalY, crashLocalY))
				{
					yield return (object)new WaitForFixedUpdate();
					yield return RunCrashWarning();
					yield return CrashToBottom();
					yield break;
				}
				yield return (object)new WaitForFixedUpdate();
			}
			m_rigidbody.MovePosition(GetWorldPositionForLocalY(targetLocalY));
			onArrived?.Invoke();
		}

		private bool HasReachedCrashHeight(float nextLocalY, float targetLocalY, float crashLocalY)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!(targetLocalY > ((Component)this).transform.localPosition.y))
			{
				return nextLocalY <= crashLocalY;
			}
			return nextLocalY >= crashLocalY;
		}

		private IEnumerator CrashToBottom()
		{
			m_state = ElevatorState.Crashing;
			m_isAtTop = false;
			sfx?.StartCrashLoop();
			AddCrashStartGamefeel();
			float fallSpeed = 0f;
			while (((Component)this).transform.localPosition.y > 88.21f)
			{
				fallSpeed += 9.81f * Time.fixedDeltaTime;
				float localY = Mathf.Max(88.2f, ((Component)this).transform.localPosition.y - fallSpeed * Time.fixedDeltaTime);
				m_rigidbody.MovePosition(GetWorldPositionForLocalY(localY));
				yield return (object)new WaitForFixedUpdate();
			}
			Vector3 worldPositionForLocalY = GetWorldPositionForLocalY(88.2f);
			m_rigidbody.MovePosition(worldPositionForLocalY);
			sfx?.StopCrashLoop();
			AddCrashImpactGamefeel();
			SpawnCrashExplosion(worldPositionForLocalY);
			m_state = ElevatorState.DoorClosed;
		}

		private IEnumerator RunCrashWarning()
		{
			sfx?.PlayArrive();
			AddCrashWarningGamefeel();
			yield return (object)new WaitForSeconds(0.4f);
			sfx?.PlayStartMove();
			AddCrashWarningGamefeel();
		}

		private Vector3 GetWorldPositionForLocalY(float localY)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)this).transform.parent;
			if (!((Object)(object)parent != (Object)null))
			{
				return new Vector3(((Component)this).transform.position.x, localY, ((Component)this).transform.position.z);
			}
			return parent.TransformPoint(new Vector3(((Component)this).transform.localPosition.x, localY, ((Component)this).transform.localPosition.z));
		}

		private void SpawnCrashExplosion(Vector3 worldPosition)
		{
			//IL_001c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			GameObject elevatorCrashExplosionPrefab = global::RegionsExpanded.CustomContent.CustomContent.ElevatorCrashExplosionPrefab;
			if ((Object)(object)elevatorCrashExplosionPrefab == (Object)null)
			{
				Debug.LogError((object)"[ElevatorController] ElevatorCrashExplosion.prefab is null; did the RegionsExpanded asset bundle load?");
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(worldPosition.x, 3.36f, worldPosition.z);
			Object.Instantiate<GameObject>(elevatorCrashExplosionPrefab, val, Quaternion.identity);
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			((MonoBehaviourPunCallbacks)this).OnPlayerEnteredRoom(newPlayer);
			if (PhotonNetwork.IsMasterClient)
			{
				float num = (m_isAtTop ? 177.4f : 88.2f);
				bool isDoorOpen = IsDoorOpen;
				m_photonView.RPC("RPC_SyncState", newPlayer, new object[2] { num, isDoorOpen });
			}
		}

		[PunRPC]
		public void RPC_SyncState(float cabinLocalY, bool doorOpen)
		{
			//IL_0074: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			((MonoBehaviour)this).StopAllCoroutines();
			sfx?.StopMoveLoop();
			sfx?.StopCrashLoop();
			Transform parent = ((Component)this).transform.parent;
			Vector3 val = default(Vector3);
			if ((Object)(object)parent != (Object)null)
			{
				val = parent.TransformPoint(new Vector3(((Component)this).transform.localPosition.x, cabinLocalY, ((Component)this).transform.localPosition.z));
			}
			else
			{
				((Vector3)(ref val))..ctor(((Component)this).transform.position.x, cabinLocalY, ((Component)this).transform.position.z);
			}
			m_rigidbody.MovePosition(val);
			m_isAtTop = Mathf.Approximately(cabinLocalY, 177.4f);
			if (doorOpen)
			{
				m_state = ElevatorState.DoorOpen;
				door?.Init(isOpen: true);
			}
			else
			{
				m_state = ElevatorState.DoorClosed;
				door?.Init(isOpen: false);
			}
		}
	}
	public class ElevatorDoor : MonoBehaviour
	{
		public AnimationClip? openedClip;

		public AnimationClip? closedClip;

		public AnimationClip? openClip;

		public AnimationClip? closeClip;

		private Optionable<PlayableGraph> m_playableGraph;

		private Animator m_animator;

		private AnimationClip? m_currentClip;

		private void Awake()
		{
			m_animator = ((Component)this).GetComponent<Animator>();
			m_animator.runtimeAnimatorController = null;
		}

		public void Init(bool isOpen)
		{
			PlayClip(isOpen ? openedClip : closedClip);
		}

		public IEnumerator Open()
		{
			if (!((Object)(object)openClip == (Object)null))
			{
				PlayClip(openClip);
				yield return (object)new WaitForSeconds(openClip.length);
				PlayClip(openedClip);
			}
		}

		public IEnumerator Close()
		{
			if (!((Object)(object)closeClip == (Object)null))
			{
				PlayClip(closeClip);
				yield return (object)new WaitForSeconds(closeClip.length);
				PlayClip(closedClip);
			}
		}

		public bool IsFullyClosed()
		{
			return (Object)(object)m_currentClip == (Object)(object)closedClip;
		}

		private void PlayClip(AnimationClip? clip)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)clip == (Object)null)
			{
				Debug.LogWarning((object)"[ElevatorDoor] Attempted to play a null clip — has it been assigned in CustomContent.cs?");
				return;
			}
			if (m_playableGraph.IsSome)
			{
				PlayableGraph value = m_playableGraph.Value;
				((PlayableGraph)(ref value)).Destroy();
			}
			m_currentClip = clip;
			PlayableGraph val = PlayableGraph.Create("ElevatorDoor: " + ((Object)clip).name);
			((PlayableGraph)(ref val)).SetTimeUpdateMode((DirectorUpdateMode)1);
			AnimationPlayableOutput val2 = AnimationPlayableOutput.Create(val, "Animation", m_animator);
			PlayableOutputExtensions.SetSourcePlayable<AnimationPlayableOutput, AnimationClipPlayable>(val2, AnimationClipPlayable.Create(val, clip));
			((PlayableGraph)(ref val)).Play();
			m_playableGraph = Optionable<PlayableGraph>.Some(val);
		}

		private void OnDestroy()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (m_playableGraph.IsSome)
			{
				PlayableGraph value = m_playableGraph.Value;
				((PlayableGraph)(ref value)).Destroy();
			}
		}
	}
	public class ElevatorInnerZone : MonoBehaviour
	{
		private ElevatorController m_controller;

		private BoxCollider? m_collider;

		private readonly Collider[] m_overlapBuffer = (Collider[])(object)new Collider[64];

		private readonly HashSet<Player> m_playersInZone = new HashSet<Player>();

		public float ascendForce = 30f;

		public float descendForce = 30f;

		private void Awake()
		{
			m_controller = ((Component)this).GetComponentInParent<ElevatorController>();
			m_collider = ((Component)this).GetComponent<BoxCollider>();
			if ((Object)(object)m_controller == (Object)null)
			{
				Debug.LogError((object)"[ElevatorInnerZone] ElevatorController not found in parent hierarchy!");
			}
		}

		private void FixedUpdate()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: 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_00a4: 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)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_controller == (Object)null)
			{
				return;
			}
			bool flag = m_controller.CurrentState == ElevatorState.Ascending;
			bool flag2 = m_controller.CurrentState == ElevatorState.Descending;
			if (!flag && !flag2)
			{
				return;
			}
			Vector3 val;
			Vector3 val2;
			if ((Object)(object)m_collider != (Object)null)
			{
				val = ((Component)this).transform.TransformPoint(m_collider.center);
				val2 = Vector3.Scale(m_collider.size * 0.5f, ((Component)this).transform.lossyScale);
			}
			else
			{
				val = ((Component)this).transform.position;
				val2 = ((Component)this).transform.lossyScale * 0.5f;
			}
			int num = Physics.OverlapBoxNonAlloc(val, val2, m_overlapBuffer, ((Component)this).transform.rotation);
			m_playersInZone.Clear();
			for (int i = 0; i < num; i++)
			{
				Player componentInParent = ((Component)m_overlapBuffer[i]).GetComponentInParent<Player>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					m_playersInZone.Add(componentInParent);
				}
			}
			Vector3 val3 = Vector3.zero;
			if (flag)
			{
				val3 = Vector3.up * ascendForce;
			}
			else if (flag2)
			{
				val3 = Vector3.down * descendForce;
			}
			foreach (Player item in m_playersInZone)
			{
				if ((Object)(object)item.refs.ragdoll != (Object)null)
				{
					item.refs.ragdoll.AddForce(val3, (ForceMode)5);
				}
			}
		}
	}
	public class ElevatorInsideDoorButton : Interactable
	{
		public ElevatorController? elevator;

		public Transform? lever;

		private bool m_onCooldown;

		private bool m_isOpen;

		private float m_sinceSwitch = 10f;

		private float m_currentAngle = 50f;

		private string m_openText = "Open";

		private string m_closeText = "Close";

		private void Start()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			m_openText = LocalizationKeys.GetLocalizedString((Keys)42);
			m_closeText = LocalizationKeys.GetLocalizedString((Keys)43);
			if ((Object)(object)elevator != (Object)null)
			{
				m_isOpen = elevator.IsDoorOpen;
				m_currentAngle = (m_isOpen ? (-50f) : 50f);
				if ((Object)(object)lever != (Object)null)
				{
					lever.localEulerAngles = new Vector3(m_currentAngle, 0f, 0f);
				}
			}
		}

		private void ToggleSwitch()
		{
			if (!((Object)(object)elevator == (Object)null))
			{
				bool isDoorOpen = elevator.IsDoorOpen;
				if (m_isOpen != isDoorOpen)
				{
					m_isOpen = isDoorOpen;
					m_sinceSwitch = 0f;
				}
			}
		}

		public override bool IsValid(Player player)
		{
			if ((Object)(object)elevator == (Object)null)
			{
				return false;
			}
			((Interactable)this).hoverText = (elevator.IsDoorOpen ? m_closeText : m_openText);
			return elevator.CanToggleDoor;
		}

		public override void Interact(Player player)
		{
			if (!m_onCooldown && !((Object)(object)elevator == (Object)null))
			{
				elevator.AttemptToggleDoor();
				((MonoBehaviour)this).StartCoroutine(Cooldown());
			}
		}

		private IEnumerator Cooldown()
		{
			m_onCooldown = true;
			yield return (object)new WaitForSeconds(0.5f);
			m_onCooldown = false;
		}

		private void Update()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)elevator == (Object)null || (Object)(object)lever == (Object)null)
			{
				return;
			}
			ToggleSwitch();
			m_sinceSwitch += Time.deltaTime;
			if (m_sinceSwitch < 5f)
			{
				if (m_isOpen)
				{
					m_currentAngle = Mathf.Lerp(m_currentAngle, -50f, Time.deltaTime * 10f);
				}
				else
				{
					m_currentAngle = Mathf.Lerp(m_currentAngle, 50f, Time.deltaTime * 10f);
				}
				lever.localEulerAngles = new Vector3(m_currentAngle, 0f, 0f);
			}
		}
	}
	public class ElevatorOutsideDoorButton : Interactable
	{
		public ElevatorController? elevator;

		private bool m_onCooldown;

		private string m_openText = "Open";

		private string m_closeText = "Close";

		private void Start()
		{
			m_openText = LocalizationKeys.GetLocalizedString((Keys)42);
			m_closeText = LocalizationKeys.GetLocalizedString((Keys)43);
		}

		public override bool IsValid(Player player)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)elevator == (Object)null)
			{
				return false;
			}
			((Interactable)this).hoverText = (elevator.IsDoorOpen ? m_closeText : m_openText);
			if (Vector3.Angle(-((Component)MainCamera.instance).transform.forward, ((Component)this).transform.forward) > 90f)
			{
				return false;
			}
			return elevator.CanToggleDoor;
		}

		public override void Interact(Player player)
		{
			if (!m_onCooldown && !((Object)(object)elevator == (Object)null))
			{
				elevator.AttemptToggleDoor();
				((MonoBehaviour)this).StartCoroutine(Cooldown());
			}
		}

		private IEnumerator Cooldown()
		{
			m_onCooldown = true;
			yield return (object)new WaitForSeconds(0.5f);
			m_onCooldown = false;
		}
	}
	public class ElevatorSFX : MonoBehaviour
	{
		private const float BaseMoveVolume = 1f;

		private AudioLoop? m_moveLoop;

		private AudioLoop? m_crashLoop;

		private SFX_PlayOneShot? m_startMove;

		private SFX_PlayOneShot? m_arrive;

		private Coroutine? m_fadeCoroutine;

		private void Awake()
		{
			Transform val = ((Component)this).transform.Find("SFX_MOVE");
			Transform val2 = ((Component)this).transform.Find("SFX_MOVE_CRASH");
			Transform val3 = ((Component)this).transform.Find("SFX_StartMove");
			Transform val4 = ((Component)this).transform.Find("SFX_Arrive");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_MOVE' not found.", (Object)(object)this);
			}
			else if (!((Component)val).TryGetComponent<AudioLoop>(ref m_moveLoop))
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_MOVE' has no AudioLoop component.", (Object)(object)this);
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_MOVE_CRASH' not found.", (Object)(object)this);
			}
			else if (!((Component)val2).TryGetComponent<AudioLoop>(ref m_crashLoop))
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_MOVE_CRASH' has no AudioLoop component.", (Object)(object)this);
			}
			if ((Object)(object)val3 == (Object)null)
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_StartMove' not found.", (Object)(object)this);
			}
			else if (!((Component)val3).TryGetComponent<SFX_PlayOneShot>(ref m_startMove))
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_StartMove' has no SFX_PlayOneShot component.", (Object)(object)this);
			}
			if ((Object)(object)val4 == (Object)null)
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_Arrive' not found.", (Object)(object)this);
			}
			else if (!((Component)val4).TryGetComponent<SFX_PlayOneShot>(ref m_arrive))
			{
				Debug.LogError((object)"[ElevatorSFX] Child 'SFX_Arrive' has no SFX_PlayOneShot component.", (Object)(object)this);
			}
			StopMoveLoop();
			StopCrashLoop();
		}

		public void PlayStartMove()
		{
			SFX_PlayOneShot? startMove = m_startMove;
			if (startMove != null)
			{
				startMove.Play();
			}
		}

		public void StartMoveLoop()
		{
			if (!((Object)(object)m_moveLoop == (Object)null))
			{
				CancelFade();
				m_moveLoop.volume = 1f;
				((Behaviour)m_moveLoop).enabled = true;
			}
		}

		public void StartCrashLoop()
		{
			StopMoveLoop();
			if (!((Object)(object)m_crashLoop == (Object)null))
			{
				m_crashLoop.volume = 1f;
				((Behaviour)m_crashLoop).enabled = true;
			}
		}

		public void StopMoveLoop()
		{
			if (!((Object)(object)m_moveLoop == (Object)null))
			{
				CancelFade();
				((Behaviour)m_moveLoop).enabled = false;
				m_moveLoop.volume = 1f;
			}
		}

		public void StopCrashLoop()
		{
			if (!((Object)(object)m_crashLoop == (Object)null))
			{
				((Behaviour)m_crashLoop).enabled = false;
				m_crashLoop.volume = 1f;
			}
		}

		public void PlayArrive()
		{
			SFX_PlayOneShot? arrive = m_arrive;
			if (arrive != null)
			{
				arrive.Play();
			}
			if (!((Object)(object)m_moveLoop == (Object)null) && ((Behaviour)m_moveLoop).enabled)
			{
				CancelFade();
				m_fadeCoroutine = ((MonoBehaviour)this).StartCoroutine(FadeOutMoveLoop());
			}
		}

		private void CancelFade()
		{
			if (m_fadeCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(m_fadeCoroutine);
				m_fadeCoroutine = null;
			}
		}

		private IEnumerator FadeOutMoveLoop()
		{
			float startVolume = m_moveLoop.volume;
			float t = 0f;
			while (t < 1f)
			{
				t += Time.deltaTime;
				m_moveLoop.volume = Mathf.Lerp(startVolume, 0.02f, t);
				yield return null;
			}
			((Behaviour)m_moveLoop).enabled = false;
			m_moveLoop.volume = 1f;
			m_fadeCoroutine = null;
		}
	}
	public static class MapScreenCursorState
	{
		private static MeshRenderer? _cursorRenderer;

		private static int _mapScreenInteractableHoverDepth;

		public static Transform? MapScreenRoot { get; private set; }

		public static Material? VanillaCursorMaterial { get; private set; }

		public static Material? CustomHandPointerMaterial { get; private set; }

		public static void Register(Transform mapScreenRoot, MeshRenderer mapScreenCursor, Material vanilla, Material? customWithHandPointer)
		{
			MapScreenRoot = mapScreenRoot;
			_cursorRenderer = mapScreenCursor;
			VanillaCursorMaterial = vanilla;
			CustomHandPointerMaterial = customWithHandPointer;
			_mapScreenInteractableHoverDepth = 0;
			ApplyToRenderer(vanilla);
		}

		public static bool IsMapScreenInteractable(Interactable interactable)
		{
			if ((Object)(object)MapScreenRoot == (Object)null || (Object)(object)interactable == (Object)null)
			{
				return false;
			}
			return ((Component)interactable).transform.IsChildOf(MapScreenRoot);
		}

		public static void OnMapScreenInteractableHoverBegin()
		{
			if (!((Object)(object)CustomHandPointerMaterial == (Object)null) && !((Object)(object)_cursorRenderer == (Object)null))
			{
				_mapScreenInteractableHoverDepth++;
				if (_mapScreenInteractableHoverDepth == 1)
				{
					ApplyToRenderer(CustomHandPointerMaterial);
				}
			}
		}

		public static void OnMapScreenInteractableHoverEnd()
		{
			if (!((Object)(object)VanillaCursorMaterial == (Object)null) && !((Object)(object)_cursorRenderer == (Object)null))
			{
				if (_mapScreenInteractableHoverDepth > 0)
				{
					_mapScreenInteractableHoverDepth--;
				}
				if (_mapScreenInteractableHoverDepth == 0)
				{
					ApplyToRenderer(VanillaCursorMaterial);
				}
			}
		}

		private static void ApplyToRenderer(Material m)
		{
			if (!((Object)(object)_cursorRenderer == (Object)null))
			{
				((Renderer)_cursorRenderer).sharedMaterials = (Material[])(object)new Material[1] { m };
			}
		}
	}
	public static class MapScreenVisualCoordinator
	{
		private static readonly Color TitleMapSelection = new Color(1f, 0.2784314f, 0.2784314f);

		private static readonly Color TitleMapSelected = new Color(0.14901961f, 0.81960785f, 0f);

		private static readonly Color TitleSelectInDays = new Color(1f, 0.99607843f, 0.29411766f);

		private const string TextMapSelection = "MAP SELECTION";

		private const string TextMapSelected = "MAP SELECTED";

		public const float YStartRight = 0f;

		public const float YEndRight = -166.6f;

		public const float BellIconRightYOffset = 47.7f;

		public static bool ShouldShowMaxDepthIndicator(int maxDepthMeters, MapInstance[]? maps)
		{
			if (maps == null || maps.Length < 2)
			{
				return false;
			}
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < maps.Length; i++)
			{
				if (maps[i].DepthMeters <= maxDepthMeters)
				{
					flag = true;
				}
				else
				{
					flag2 = true;
				}
			}
			return flag && flag2;
		}

		public static bool IsDayTwoOrThreeWithinQuota()
		{
			if (SurfaceNetworkHandler.RoomStats == null)
			{
				return false;
			}
			int currentQuotaDay = SurfaceNetworkHandler.RoomStats.CurrentQuotaDay;
			if (currentQuotaDay <= 0)
			{
				return false;
			}
			return currentQuotaDay % 3 != 1;
		}

		public static bool IsScreenInteractible(bool mapPaidEffective)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (mapPaidEffective)
			{
				return false;
			}
			if (IsDayTwoOrThreeWithinQuota())
			{
				return false;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "SurfaceScene")
			{
				return false;
			}
			return IsMorning();
		}

		private static bool IsMorning()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			TimeOfDayHandler val = Object.FindFirstObjectByType<TimeOfDayHandler>();
			if ((Object)(object)val != (Object)null)
			{
				return (int)val.timeOfDay == 0;
			}
			return false;
		}

		public static bool IsMapIconInteractionGloballyLocked(bool mapPaidEffective)
		{
			return !IsScreenInteractible(mapPaidEffective);
		}

		public static void RefreshAll(bool newQuotaJustStarted = false, bool? mapPaidOverride = null)
		{
			MapScreenVisualRoot[] array = Object.FindObjectsByType<MapScreenVisualRoot>((FindObjectsSortMode)0);
			if (array.Length == 0 && SurfaceNetworkHandler.RoomStats != null && SurfaceNetworkHandler.HasStarted)
			{
				Logger.LogError("RegionsExpanded: MapScreenVisualCoordinator.RefreshAll: no MapScreenVisualRoot in scene while run active (MapScreen not spawned or component missing).");
			}
			bool flag = !newQuotaJustStarted && ((!mapPaidOverride.HasValue) ? MapSelectionRoomProps.IsMapBuyInPaidFromSources() : mapPaidOverride.Value);
			bool flag2 = IsScreenInteractible(flag);
			bool locked = !flag2;
			int selectedMapUiIndex = GetSelectedMapUiIndex(newQuotaJustStarted);
			MapScreenVisualRoot[] array2 = array;
			foreach (MapScreenVisualRoot mapScreenVisualRoot in array2)
			{
				if ((Object)(object)mapScreenVisualRoot == (Object)null)
				{
					Logger.LogError("RegionsExpanded: Map screen refresh: MapScreenVisualRoot entry is null (unexpected).");
					continue;
				}
				ApplyTitle(((Component)mapScreenVisualRoot).transform, flag);
				ApplyMapIcons(((Component)mapScreenVisualRoot).transform, locked);
				ApplyMaxDepth(((Component)mapScreenVisualRoot).transform);
				ApplySubTitleDepth(((Component)mapScreenVisualRoot).transform);
				ApplyLineColors(((Component)mapScreenVisualRoot).transform, flag2);
				bool revealSelection = !flag2 || RegionsExpanded.DEBUG_MODE;
				ApplySelectedMapCircles(((Component)mapScreenVisualRoot).transform, selectedMapUiIndex, revealSelection);
				ApplyBellIconY(((Component)mapScreenVisualRoot).transform, selectedMapUiIndex, revealSelection);
			}
			RefreshRadarVisual();
			RefreshPlatingVisual();
		}

		public static void RefreshMaxDepth()
		{
			bool interactible = IsScreenInteractible(MapSelectionRoomProps.IsMapBuyInPaidFromSources());
			MapScreenVisualRoot[] array = Object.FindObjectsByType<MapScreenVisualRoot>((FindObjectsSortMode)0);
			MapScreenVisualRoot[] array2 = array;
			foreach (MapScreenVisualRoot mapScreenVisualRoot in array2)
			{
				if ((Object)(object)mapScreenVisualRoot != (Object)null)
				{
					ApplyMaxDepth(((Component)mapScreenVisualRoot).transform);
					ApplySubTitleDepth(((Component)mapScreenVisualRoot).transform);
					ApplyLineColors(((Component)mapScreenVisualRoot).transform, interactible);
				}
			}
			RefreshRadarVisual();
			RefreshPlatingVisual();
		}

		public static void RefreshRadarVisual()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			bool flag = global::RegionsExpanded.CustomContent.CustomContent.CurrentUpgrades.Contains(DivingBellUpgrade.Radar);
			RadarVisualRoot[] array = Object.FindObjectsByType<RadarVisualRoot>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			if (flag && array.Length == 0)
			{
				Logger.LogError("RegionsExpanded: RefreshRadarVisual: radar upgrade is equipped but no RadarVisualRoot instances exist (unexpected; bell visual may not have spawned).");
			}
			Logger.Log($"RegionsExpanded: RefreshRadarVisual: radarEquipped={flag}, instanceCount={array.Length}.");
			RadarVisualRoot[] array2 = array;
			foreach (RadarVisualRoot radarVisualRoot in array2)
			{
				if ((Object)(object)radarVisualRoot == (Object)null)
				{
					Logger.LogError("RegionsExpanded: RefreshRadarVisual: RadarVisualRoot entry is null (unexpected).");
					continue;
				}
				bool activeSelf = ((Component)radarVisualRoot).gameObject.activeSelf;
				((Component)radarVisualRoot).gameObject.SetActive(flag);
				if (flag && !activeSelf)
				{
					SpawnUpgradeAddedExplosion(((Component)radarVisualRoot).transform.position);
				}
			}
		}

		private static void SpawnUpgradeAddedExplosion(Vector3 worldPosition)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject upgradeAddedExplosionPrefab = global::RegionsExpanded.CustomContent.CustomContent.UpgradeAddedExplosionPrefab;
			if ((Object)(object)upgradeAddedExplosionPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SpawnUpgradeAddedExplosion: UpgradeAddedExplosionPrefab is null; explosion not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(upgradeAddedExplosionPrefab, worldPosition, Quaternion.identity);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SpawnUpgradeAddedExplosion: Instantiate returned null (unexpected).");
			}
			else
			{
				Logger.Log($"RegionsExpanded: UpgradeAddedExplosion spawned at {worldPosition}.");
			}
		}

		public static void RefreshPlatingVisual()
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			bool flag = global::RegionsExpanded.CustomContent.CustomContent.CurrentUpgrades.Contains(DivingBellUpgrade.HighPressureArmorPlatings);
			PlatingVisualRoot[] array = Object.FindObjectsByType<PlatingVisualRoot>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			if (flag && array.Length == 0)
			{
				Logger.LogError("RegionsExpanded: RefreshPlatingVisual: plating upgrade is equipped but no PlatingVisualRoot instances exist (unexpected; bell visual may not have spawned).");
			}
			Logger.Log($"RegionsExpanded: RefreshPlatingVisual: platingEquipped={flag}, instanceCount={array.Length}.");
			PlatingVisualRoot[] array2 = array;
			foreach (PlatingVisualRoot platingVisualRoot in array2)
			{
				if ((Object)(object)platingVisualRoot == (Object)null)
				{
					Logger.LogError("RegionsExpanded: RefreshPlatingVisual: PlatingVisualRoot entry is null (unexpected).");
					continue;
				}
				bool activeSelf = ((Component)platingVisualRoot).gameObject.activeSelf;
				((Component)platingVisualRoot).gameObject.SetActive(flag);
				if (flag && !activeSelf)
				{
					Transform parent = ((Component)platingVisualRoot).transform.parent;
					Vector3 worldPosition = (((Object)(object)parent != (Object)null) ? parent.TransformPoint(new Vector3(0f, 0.93f, 0f)) : ((Component)platingVisualRoot).transform.position);
					if ((Object)(object)parent == (Object)null)
					{
						Logger.LogError("RegionsExpanded: RefreshPlatingVisual: PlatingVisualRoot has no parent; explosion will spawn at visual root position.");
					}
					SpawnUpgradeAddedExplosionPlatings(worldPosition);
				}
			}
		}

		private static void SpawnUpgradeAddedExplosionPlatings(Vector3 worldPosition)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject upgradeAddedExplosionPlatingsPrefab = global::RegionsExpanded.CustomContent.CustomContent.UpgradeAddedExplosionPlatingsPrefab;
			if ((Object)(object)upgradeAddedExplosionPlatingsPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SpawnUpgradeAddedExplosionPlatings: UpgradeAddedExplosionPlatingsPrefab is null; explosion not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(upgradeAddedExplosionPlatingsPrefab, worldPosition, Quaternion.identity);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SpawnUpgradeAddedExplosionPlatings: Instantiate returned null (unexpected).");
			}
			else
			{
				Logger.Log($"RegionsExpanded: UpgradeAddedExplosionPlatings spawned at {worldPosition}.");
			}
		}

		private static void ApplySubTitleDepth(Transform mapScreenRoot)
		{
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas/SubTitleDepth");
			if ((Object)(object)val != (Object)null)
			{
				TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = $"Max depth: {global::RegionsExpanded.CustomContent.CustomContent.MAX_DEPTH} meters";
				}
			}
		}

		private static void ApplyLineColors(Transform mapScreenRoot, bool interactible)
		{
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
			for (int i = 0; i < mapInstances.Length; i++)
			{
				MapInstance entry = mapInstances[i];
				Transform val2 = val.Find("MapLine_" + entry.DisplayName);
				if ((Object)(object)val2 != (Object)null)
				{
					MapScreenLineBindings.ApplyToLine(val2, entry, i, interactible);
				}
			}
		}

		private static void ApplyMaxDepth(Transform mapScreenRoot)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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)
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform val2 = val.Find("MaxDepthIndicator");
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
			int mAX_DEPTH = global::RegionsExpanded.CustomContent.CustomContent.MAX_DEPTH;
			bool flag = ShouldShowMaxDepthIndicator(mAX_DEPTH, mapInstances);
			((Component)val2).gameObject.SetActive(flag);
			if (flag)
			{
				RectTransform val3 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
				if (val3 != null)
				{
					float maxDepthRightYAlignToMaps = GetMaxDepthRightYAlignToMaps(mAX_DEPTH, mapInstances, 0f, -166.6f);
					Vector2 anchoredPosition = val3.anchoredPosition;
					float num = maxDepthRightYAlignToMaps + 51.4f;
					val3.anchoredPosition = new Vector2(anchoredPosition.x, num);
				}
			}
		}

		public static float GetMaxDepthRightYAlignToMaps(int maxDepthMeters, MapInstance[] maps, float yStartRight, float yEndRight)
		{
			int n = maps.Length;
			if (n == 0)
			{
				return (yStartRight + yEndRight) * 0.5f;
			}
			int num = -1;
			int num2 = -1;
			for (int i = 0; i < n; i++)
			{
				if (maps[i].DepthMeters <= maxDepthMeters)
				{
					num = i;
				}
				else if (num2 < 0)
				{
					num2 = i;
				}
			}
			if (num >= 0 && num2 >= 0)
			{
				return (RightYForIndex(num) + RightYForIndex(num2)) * 0.5f;
			}
			if (num < 0)
			{
				return RightYForIndex(0);
			}
			return RightYForIndex(n - 1);
			float RightYForIndex(int num4)
			{
				if (n == 1)
				{
					return Mathf.Lerp(yStartRight, yEndRight, 0.5f);
				}
				float num3 = (float)num4 / (float)(n - 1);
				return Mathf.Lerp(yStartRight, yEndRight, num3);
			}
		}

		private static void ApplyTitle(Transform mapScreenRoot, bool paid)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas/Title");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: Map screen: ScreenPivot/Canvas/Title not found under " + ((Object)mapScreenRoot).name + ".");
				return;
			}
			TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogError("RegionsExpanded: Map screen: Title has no TMP_Text on " + ((Object)mapScreenRoot).name + ".");
			}
			else if (!paid && !IsScreenInteractible(paid))
			{
				int selectInDaysCountdown = GetSelectInDaysCountdown();
				component.text = FormatSelectInDays(selectInDaysCountdown);
				((Graphic)component).color = TitleSelectInDays;
			}
			else if (paid)
			{
				component.text = "MAP SELECTED";
				((Graphic)component).color = TitleMapSelected;
			}
			else
			{
				component.text = "MAP SELECTION";
				((Graphic)component).color = TitleMapSelection;
			}
		}

		private static int GetSelectInDaysCountdown()
		{
			if (SurfaceNetworkHandler.RoomStats == null)
			{
				Logger.LogError("RegionsExpanded: GetSelectInDaysCountdown: RoomStats is null during yellow title path (unexpected).");
				return 0;
			}
			return Mathf.Max(0, SurfaceNetworkHandler.RoomStats.GetDaysLeft() + 1);
		}

		private static string FormatSelectInDays(int n)
		{
			if (n == 1)
			{
				return "SELECT IN 1 DAY";
			}
			return $"SELECT IN {n} DAYS";
		}

		public static void PlaySFX(string path)
		{
			MapScreenVisualRoot[] array = Object.FindObjectsByType<MapScreenVisualRoot>((FindObjectsSortMode)0);
			MapScreenVisualRoot[] array2 = array;
			foreach (MapScreenVisualRoot mapScreenVisualRoot in array2)
			{
				if ((Object)(object)mapScreenVisualRoot == (Object)null)
				{
					continue;
				}
				Transform val = ((Component)mapScreenVisualRoot).transform.Find(path);
				if ((Object)(object)val != (Object)null)
				{
					SFX_PlayOneShot component = ((Component)val).GetComponent<SFX_PlayOneShot>();
					if ((Object)(object)component != (Object)null)
					{
						component.Play();
					}
					else
					{
						Logger.LogError("RegionsExpanded: MapScreenVisualCoordinator.PlaySFX: SFX_PlayOneShot component not found on " + path);
					}
				}
				else
				{
					Logger.LogError("RegionsExpanded: MapScreenVisualCoordinator.PlaySFX: child not found: " + path);
				}
			}
		}

		private static void ApplyMapIcons(Transform mapScreenRoot, bool locked)
		{
			MapIconInteractable[] componentsInChildren = ((Component)mapScreenRoot).GetComponentsInChildren<MapIconInteractable>(true);
			MapIconInteractable[] array = componentsInChildren;
			foreach (MapIconInteractable mapIconInteractable in array)
			{
				if ((Object)(object)mapIconInteractable == (Object)null)
				{
					Logger.LogError("RegionsExpanded: Map screen: null MapIconInteractable in children of " + ((Object)mapScreenRoot).name + ".");
				}
				else
				{
					((Behaviour)mapIconInteractable).enabled = !locked;
				}
			}
		}

		public static int GetSelectedMapUiIndex(bool newQuotaJustStarted = false)
		{
			if (SurfaceNetworkHandler.RoomStats == null)
			{
				return -1;
			}
			if (!newQuotaJustStarted)
			{
				int selectedMapIndex = MapSelectionRoomProps.GetSelectedMapIndex();
				if (selectedMapIndex >= 0)
				{
					return selectedMapIndex;
				}
			}
			int levelToPlay = SurfaceNetworkHandler.RoomStats.LevelToPlay;
			MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
			for (int i = 0; i < mapInstances.Length; i++)
			{
				if (MapLevelRouting.UiIndexToLevelToPlay(i) == levelToPlay)
				{
					return i;
				}
			}
			return -1;
		}

		private static void ApplySelectedMapCircles(Transform mapScreenRoot, int selectedUiIndex, bool revealSelection)
		{
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: ApplySelectedMapCircles: ScreenPivot/Canvas not found.");
				return;
			}
			MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
			for (int i = 0; i < mapInstances.Length; i++)
			{
				Transform val2 = val.Find("MapLine_" + mapInstances[i].DisplayName);
				if ((Object)(object)val2 != (Object)null)
				{
					Transform val3 = val2.Find("MapSelectedCircle");
					if ((Object)(object)val3 != (Object)null)
					{
						((Component)val3).gameObject.SetActive(revealSelection && i == selectedUiIndex);
					}
				}
			}
		}

		private static void ApplyBellIconY(Transform mapScreenRoot, int selectedUiIndex, bool revealSelection)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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)
			if (!revealSelection)
			{
				return;
			}
			Transform val = mapScreenRoot.Find("ScreenPivot/Canvas/BellIcon");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
			if (val2 != null)
			{
				MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
				int num = mapInstances.Length;
				if (selectedUiIndex >= 0 && selectedUiIndex < num)
				{
					float num2 = ((num > 1) ? ((float)selectedUiIndex / (float)(num - 1)) : 0.5f);
					float num3 = Mathf.Lerp(0f, -166.6f, num2);
					Vector2 anchoredPosition = val2.anchoredPosition;
					val2.anchoredPosition = new Vector2(anchoredPosition.x, num3 + 47.7f);
				}
			}
		}
	}
	public sealed class MapScreenVisualRoot : MonoBehaviour
	{
	}
	public static class Logger
	{
		private const string Prefix = "[RegionsExpanded]";

		public static void Log(string message)
		{
			Debug.Log((object)("[RegionsExpanded] " + message));
		}

		public static void LogWarning(string message)
		{
			Debug.LogWarning((object)("[RegionsExpanded] " + message));
		}

		public static void LogError(string message)
		{
			Debug.LogError((object)("[RegionsExpanded] " + message));
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "db.regionsexpanded";

		public const string PLUGIN_NAME = "Regions Expanded";

		public const string PLUGIN_VERSION = "0.3.0";

		public const bool VANILLA_COMPATIBLE = false;
	}
	[ContentWarningPlugin("db.regionsexpanded", "0.3.0", false)]
	[BepInPlugin("db.regionsexpanded", "Regions Expanded", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class RegionsExpanded : BaseUnityPlugin
	{
		private bool _isPatched;

		public static bool DEBUG_MODE;

		private Harmony? Harmony { get; set; }

		public static RegionsExpanded Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Log("RegionsExpanded constructor called. IntroScreenSlideshow.Request()");
			global::RegionsExpanded.CustomContent.CustomContent.Init();
			BellUpgradePersistence.Register();
			if (DEBUG_MODE)
			{
				DbsContentApiPlugin.SetAllItemsFree(true);
			}
			PatchAll();
			Logger.Log("Plugin db.regionsexpanded is loaded!");
		}

		private void PatchAll()
		{
			//IL_002b: 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_0032: Expected O, but got Unknown
			//IL_0037: Expected O, but got Unknown
			if (_isPatched)
			{
				Logger.LogError("Already patched!");
				return;
			}
			Logger.Log("Patching...");
			if (Harmony == null)
			{
				Harmony val = new Harmony("db.regionsexpanded");
				Harmony val2 = val;
				Harmony = val;
			}
			try
			{
				Harmony.PatchAll();
				_isPatched = true;
				Logger.Log("Patched!");
			}
			catch (Exception arg)
			{
				Logger.LogError($"Failed to patch: {arg}");
			}
		}

		public void UnpatchAll()
		{
			if (!_isPatched)
			{
				Logger.LogError("Already unpatched!");
				return;
			}
			Logger.Log("Unpatching...");
			try
			{
				Harmony? harmony = Harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
				_isPatched = false;
				Logger.Log("Unpatched!");
			}
			catch (Exception arg)
			{
				Logger.LogError($"Failed to unpatch: {arg}");
			}
		}
	}
}
namespace RegionsExpanded.Patches
{
	[HarmonyPatch(typeof(PlayerRagdoll), "GroundRaycast")]
	internal static class GroundRaycastStandableRigPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PlayerRagdoll __instance, bool justChecking, bool justTryingToGetTheRaycastHit, bool ignoreAngle, ref RaycastHit __result)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//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_005c: 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_00bb: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			Dictionary<BodypartType, Bodypart> value = val.Field<Dictionary<BodypartType, Bodypart>>("bodypartDict").Value;
			Player value2 = val.Field<Player>("player").Value;
			RaycastHit groundPosRaycast = HelperFunctions.GetGroundPosRaycast(((Component)value[(BodypartType)4]).transform.position, (LayerType)1, value2.data.gravityDirection);
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref groundPosRaycast)).transform))
			{
				__result = default(RaycastHit);
				return false;
			}
			if ((Object)(object)((RaycastHit)(ref groundPosRaycast)).rigidbody != (Object)null && (Object)(object)((Component)((RaycastHit)(ref groundPosRaycast)).rigidbody).GetComponent<StandableRig>() == (Object)null)
			{
				__result = default(RaycastHit);
				return false;
			}
			float num = value2.data.targetHeight + 0.25f;
			if (justChecking)
			{
				num = 2f;
			}
			if (((RaycastHit)(ref groundPosRaycast)).distance > num)
			{
				__result = default(RaycastHit);
				return false;
			}
			if (!ignoreAngle && Vector3.Angle(Vector3.up, ((RaycastHit)(ref groundPosRaycast)).normal) > 60f)
			{
				__result = default(RaycastHit);
				return false;
			}
			if (justTryingToGetTheRaycastHit)
			{
				__result = groundPosRaycast;
				return false;
			}
			if (justChecking)
			{
				value2.data.groundBelow = true;
			}
			else
			{
				val.Method("RegisterGroundRaycast", new object[2]
				{
					groundPosRaycast,
					value[(BodypartType)0]
				}).GetValue();
			}
			__result = groundPosRaycast;
			return false;
		}
	}
	[HarmonyPatch(typeof(Interactable), "OnStartHover")]
	public static class InteractableMapScreenOnStartCursorPatch
	{
		[HarmonyPostfix]
		public static void Postfix(Interactable __instance)
		{
			if (MapScreenCursorState.IsMapScreenInteractable(__instance))
			{
				MapScreenCursorState.OnMapScreenInteractableHoverBegin();
			}
		}
	}
	[HarmonyPatch(typeof(Interactable), "OnEndHover")]
	public static class InteractableMapScreenOnEndCursorPatch
	{
		[HarmonyPostfix]
		public static void Postfix(Interactable __instance)
		{
			if (MapScreenCursorState.IsMapScreenInteractable(__instance))
			{
				MapScreenCursorState.OnMapScreenInteractableHoverEnd();
			}
		}
	}
	public static class MapScreenLineBindings
	{
		private static readonly Color MapUiShallowerThanMaxDepthTint = new Color(0.14901961f, 0.81960785f, 0f, 1f);

		private static readonly Color MapUiAtOrDeeperThanMaxDepthTint = new Color(38f / 51f, 0.23529412f, 19f / 85f, 1f);

		public static void ApplyToLine(Transform lineRoot, MapInstance entry, int mapIndex, bool interactible)
		{
			//IL_0029: 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_0033: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = entry.DepthMeters <= global::RegionsExpanded.CustomContent.CustomContent.MAX_DEPTH;
			Color color = (Color)((!interactible) ? new Color(0.58431375f, 0.58431375f, 0.58431375f, 1f) : (flag ? MapUiShallowerThanMaxDepthTint : MapUiAtOrDeeperThanMaxDepthTint));
			Transform val = lineRoot.Find("PriceTag");
			if ((Object)(object)val != (Object)null)
			{
				TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = entry.BuyInDollars + "$";
				}
			}
			Transform val2 = lineRoot.Find("DepthTag");
			if ((Object)(object)val2 != (Object)null)
			{
				TMP_Text component2 = ((Component)val2).GetComponent<TMP_Text>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.text = entry.DepthMeters + "m";
				}
			}
			Transform subtreeRoot = lineRoot.Find("MapSelectedCircle");
			TMP_Text[] componentsInChildren = ((Component)lineRoot).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val3 in componentsInChildren)
			{
				if (!IsInSubtree(val3.transform, subtreeRoot))
				{
					((Graphic)val3).color = color;
				}
			}
			Image[] componentsInChildren2 = ((Component)lineRoot).GetComponentsInChildren<Image>(true);
			foreach (Image val4 in componentsInChildren2)
			{
				if (!IsInSubtree(((Component)val4).transform, subtreeRoot))
				{
					((Graphic)val4).color = color;
				}
			}
			Transform val5 = lineRoot.Find("MapIcon");
			if ((Object)(object)val5 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: MapIcon not found on " + ((Object)lineRoot).name);
				return;
			}
			Image component3 = ((Component)val5).GetComponent<Image>();
			if ((Object)(object)component3 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: MapIcon has no Image on " + ((Object)lineRoot).name);
				return;
			}
			Sprite sprite = CustomItems.GetSprite(entry.IconBundleName);
			if ((Object)(object)sprite == (Object)null)
			{
				Logger.LogError("RegionsExpanded: No Sprite in bundle for icon key: " + entry.IconBundleName);
				return;
			}
			component3.sprite = sprite;
			MapIconInteractable mapIconInteractable = ((Component)val5).GetComponent<MapIconInteractable>();
			if ((Object)(object)mapIconInteractable == (Object)null)
			{
				mapIconInteractable = ((Component)val5).gameObject.AddComponent<MapIconInteractable>();
			}
			mapIconInteractable.Setup(entry, mapIndex);
		}

		private static bool IsInSubtree(Transform t, Transform? subtreeRoot)
		{
			if ((Object)(object)subtreeRoot == (Object)null)
			{
				return false;
			}
			Transform val = t;
			while ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)val == (Object)(object)subtreeRoot)
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(RoomStatsHolder), "NewMapToPlay")]
	[HarmonyPriority(200)]
	internal static class NewMapToPlayPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(RoomStatsHolder __instance)
		{
			int num = ((__instance.CurrentQuotaDay > 0) ? MapSelectionRoomProps.GetSelectedMapIndex() : (-1));
			if (num >= 0 && num < global::RegionsExpanded.CustomContent.CustomContent.MapInstances.Length)
			{
				Logger.Log($"RegionsExpanded: NewMapToPlayPatch: Map was bought: {num}");
				ApplyMapSelection(__instance, num);
				return false;
			}
			List<int> list = new List<int>();
			for (int i = 0; i < global::RegionsExpanded.CustomContent.CustomContent.MapInstances.Length; i++)
			{
				if (global::RegionsExpanded.CustomContent.CustomContent.MapInstances[i].DepthMeters <= global::RegionsExpanded.CustomContent.CustomContent.MAX_DEPTH)
				{
					list.Add(i);
				}
			}
			if (list.Count == 0)
			{
				Logger.Log("RegionsExpanded: NewMapToPlayPatch: No accessible maps");
				return false;
			}
			int num2 = 0;
			int num3;
			do
			{
				Logger.Log($"RegionsExpanded: NewMapToPlayPatch Trying to pick a map ({num2})");
				num3 = list[Random.Range(0, list.Count)];
			}
			while (++num2 < 100 && MapLevelRouting.UiIndexToLevelToPlay(num3) == __instance.LevelToPlay && list.Count > 1);
			Logger.Log($"RegionsExpanded: NewMapToPlayPatch Picked map: {num3}");
			ApplyMapSelection(__instance, num3);
			return false;
		}

		private static void ApplyMapSelection(RoomStatsHolder roomStats, int uiIndex)
		{
			int num = MapLevelRouting.UiIndexToLevelToPlay(uiIndex);
			if (num >= 3)
			{
				Maps.SetSelectedMapId(global::RegionsExpanded.CustomContent.CustomContent.MapIdForScene(global::RegionsExpanded.CustomContent.CustomContent.MapInstances[uiIndex].SceneName));
			}
			else
			{
				Maps.SetSelectedMapId((string)null);
			}
			roomStats.LevelToPlay = num;
		}
	}
	[HarmonyPatch(typeof(DivingBell), "Awake")]
	public static class SpawnMapScreenPatch
	{
		private static bool firstSetupDone;

		private static Material blueprintMaterial;

		private static Material frontTextMaterial;

		private static Material platingMaterial;

		[HarmonyPostfix]
		public static void Postfix(DivingBell __instance)
		{
			//IL_0023: 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)
			Logger.Log("RegionsExpanded: DivingBell Awake postfix started.");
			Transform transform = ((Component)__instance).transform;
			SetupMapScreen(transform);
			SetupRadarVisual(transform);
			SetupPlatingVisual(transform);
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "SurfaceScene")
			{
				Logger.Log("RegionsExpanded: Dropbox setup skipped; not in SurfaceScene.");
			}
			else
			{
				SetupUpgradeDropbox(transform);
			}
		}

		private static void SetupRadarVisual(Transform parent)
		{
			//IL_007b: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			Logger.Log("RegionsExpanded: SetupRadarVisual started.");
			if ((Object)(object)parent == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SetupRadarVisual: parent transform is null (unexpected); radar visual not spawned.");
				return;
			}
			GameObject upgradeRadarVisualPrefab = global::RegionsExpanded.CustomContent.CustomContent.UpgradeRadarVisualPrefab;
			if ((Object)(object)upgradeRadarVisualPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: UpgradeRadarVisualPrefab is null; radar visual not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(upgradeRadarVisualPrefab, parent);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SetupRadarVisual: Instantiate returned null (unexpected); radar visual not spawned.");
				return;
			}
			((Object)val).name = "UpgradeRadarVisual";
			val.AddComponent<RadarVisualRoot>();
			val.transform.localPosition = new Vector3(-1.022857f, 2.788571f, 0.7314284f);
			val.transform.localEulerAngles = new Vector3(-90f, -32.71f, 0f);
			val.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogError("RegionsExpanded: UpgradeRadarVisual root has no MeshRenderer; applying material swap skipped (unexpected prefab layout).");
			}
			else
			{
				((Renderer)component).materials = (Material[])(object)new Material[7]
				{
					GameMaterials.GetMaterial((GameMaterial)285),
					GameMaterials.GetMaterial((GameMaterial)324),
					GameMaterials.GetMaterial((GameMaterial)324),
					GameMaterials.GetMaterial((GameMaterial)324),
					GameMaterials.GetMaterial((GameMaterial)8),
					GameMaterials.GetMaterial((GameMaterial)8),
					GameMaterials.GetMaterial((GameMaterial)283)
				};
			}
			ObjectHelper.FixShadersForCurrentScene(val);
			bool flag = global::RegionsExpanded.CustomContent.CustomContent.CurrentUpgrades.Contains(DivingBellUpgrade.Radar);
			val.SetActive(flag);
			Logger.Log($"RegionsExpanded: UpgradeRadarVisual spawned under DivingBell; initial active={flag}.");
		}

		private static void SetupPlatingVisual(Transform parent)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			Logger.Log("RegionsExpanded: SetupPlatingVisual started.");
			if ((Object)(object)parent == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SetupPlatingVisual: parent transform is null (unexpected); plating visual not spawned.");
				return;
			}
			GameObject upgradePlatingVisualPrefab = global::RegionsExpanded.CustomContent.CustomContent.UpgradePlatingVisualPrefab;
			if ((Object)(object)upgradePlatingVisualPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: UpgradePlatingVisualPrefab is null; plating visual not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(upgradePlatingVisualPrefab, parent);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: SetupPlatingVisual: Instantiate returned null (unexpected); plating visual not spawned.");
				return;
			}
			((Object)val).name = "UpgradePlatingVisual";
			val.AddComponent<PlatingVisualRoot>();
			val.transform.localPosition = new Vector3(0f, -0.44f, 0f);
			val.transform.localEulerAngles = Vector3.zero;
			val.transform.localScale = new Vector3(1.43f, 1.43f, 1.43f);
			Transform val2 = val.transform.Find("Bolts");
			Transform val3 = val.transform.Find("Plates");
			Transform val4 = val.transform.Find("PlatingScrews");
			if ((Object)(object)val2 != (Object)null)
			{
				GameMaterials.ApplyMaterial(((Component)val2).gameObject, (GameMaterial)283, true);
			}
			else
			{
				Logger.LogError("RegionsExpanded: UpgradePlatingVisual.Bolts child not found.");
			}
			if ((Object)(object)val4 != (Object)null)
			{
				GameMaterials.ApplyMaterial(((Component)val4).gameObject, (GameMaterial)283, true);
			}
			else
			{
				Logger.LogError("RegionsExpanded: UpgradePlatingVisual.PlatingScrews child not found.");
			}
			if ((Object)(object)val3 != (Object)null)
			{
				GameMaterials.ApplyMaterial(((Component)val3).gameObject, (GameMaterial)285, true);
			}
			else
			{
				Logger.LogError("RegionsExpanded: UpgradePlatingVisual.Plates child not found.");
			}
			ObjectHelper.FixShadersForCurrentScene(val);
			bool flag = global::RegionsExpanded.CustomContent.CustomContent.CurrentUpgrades.Contains(DivingBellUpgrade.HighPressureArmorPlatings);
			val.SetActive(flag);
			Logger.Log($"RegionsExpanded: UpgradePlatingVisual spawned under DivingBell; initial active={flag}.");
		}

		private static void SetupMapScreen(Transform parent)
		{
			//IL_0049: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			//IL_01bf: 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)
			GameObject divingBellMapScreenPrefab = global::RegionsExpanded.CustomContent.CustomContent.DivingBellMapScreenPrefab;
			if ((Object)(object)divingBellMapScreenPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: DivingBellMapScreenPrefab is null; map screen not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(divingBellMapScreenPrefab, parent);
			((Object)val).name = "MapScreen";
			val.AddComponent<MapScreenVisualRoot>();
			val.transform.localPosition = new Vector3(-0.8342857f, 1.078f, 0.015f);
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			Transform val2 = val.transform.Find("DoorFrame");
			if ((Object)(object)val2 != (Object)null)
			{
				GameMaterials.ApplyMaterial(((Component)val2).gameObject, (GameMaterial)286, true);
			}
			else
			{
				Logger.LogError("RegionsExpanded: MapScreen.DoorFrame not found.");
			}
			Transform val3 = val.transform.Find("ScreenPivot/Screen");
			if ((Object)(object)val3 != (Object)null)
			{
				GameMaterials.ApplyMaterial(((Component)val3).gameObject, (GameMaterial)236, true);
			}
			else
			{
				Logger.LogError("RegionsExpanded: MapScreen.Screen not found.");
			}
			Transform val4 = val.transform.Find("ScreenPivot/Canvas");
			if ((Object)(object)val4 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: MapScreen.ScreenPivot/Canvas not found.");
				return;
			}
			GameObject gameObject = ((Component)((Component)val4).transform.Find("Cursor/Cursor/Quad")).gameObject;
			MeshRenderer component = gameObject.GetComponent<MeshRenderer>();
			Material val5 = Resources.Load<Material>("M_Cursor") ?? GameMaterials.GetMaterial((GameMaterial)158);
			if ((Object)(object)val5 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: Cursor material not found.");
				return;
			}
			Material vanilla = new Material(val5)
			{
				name = "M_Cursor_MapScreen_Vanilla"
			};
			Texture2D texture = CustomItems.GetTexture("HandPointer");
			Material val6 = null;
			if ((Object)(object)texture != (Object)null)
			{
				val6 = new Material(val5)
				{
					name = "M_Cursor_MapScreen_Hand"
				};
				ApplyUrpUnlitAlbedoTexture(val6, (Texture)(object)texture);
			}
			else
			{
				Logger.LogError("RegionsExpanded: HandPointer texture not found in bundle; map cursor will stay vanilla on hover too.");
			}
			MapScreenCursorState.Register(val.transform, component, vanilla, val6);
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "SurfaceScene")
			{
				GameObject gameObject2 = ((Component)val.transform.Find("DoorFrame")).gameObject;
				GameObject gameObject3 = ((Component)val.transform.Find("ScreenPivot/Screen")).gameObject;
				MeshRenderer component2 = gameObject2.GetComponent<MeshRenderer>();
				MeshRenderer component3 = gameObject3.GetComponent<MeshRenderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					Logger.Log("RegionsExpanded: Fixing shaders for " + ((Object)gameObject2).name);
					((Renderer)component2).material = GameMaterials.GetMaterial((GameMaterial)120);
				}
				else
				{
					Logger.LogError("RegionsExpanded: " + ((Object)gameObject2).name + " not found.");
				}
				if ((Object)(object)component3 != (Object)null)
				{
					Logger.Log("RegionsExpanded: Fixing shaders for " + ((Object)gameObject3).name);
					Transform val7 = val.gameObject.transform.parent.Find("Tools/Screen/ScreenPivot/Cube");
					if ((Object)(object)val7 != (Object)null)
					{
						MeshRenderer component4 = ((Component)val7).GetComponent<MeshRenderer>();
						if ((Object)(object)component4 != (Object)null)
						{
							((Renderer)component3).material = ((Renderer)component4).material;
						}
						else
						{
							Logger.LogError("RegionsExpanded: " + ((Object)val7).name + " not found.");
						}
					}
					else
					{
						Logger.LogError("RegionsExpanded: Diving bell vanilla screen not found.");
					}
				}
				else
				{
					Logger.LogError("RegionsExpanded: " + ((Object)gameObject3).name + " not found.");
				}
			}
			PopulateMapSelectionRows(val4);
			MapScreenVisualCoordinator.RefreshAll();
		}

		private static void PopulateMapSelectionRows(Transform canvas)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			MapInstance[] mapInstances = global::RegionsExpanded.CustomContent.CustomContent.MapInstances;
			if (mapInstances == null || mapInstances.Length == 0)
			{
				Logger.Log("RegionsExpanded: No MapInstances defined; map lines skipped.");
				return;
			}
			Transform val = canvas.Find("RightLineMap");
			Transform val2 = canvas.Find("LeftLineMap");
			Transform val3 = canvas.Find("MaxDepthIndicator");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: RightLineMap and/or LeftLineMap not found; map lines skipped.");
				return;
			}
			ApplyInvisMaterialToLineOutlineCube(val);
			ApplyInvisMaterialToLineOutlineCube(val2);
			int num = mapInstances.Length;
			for (int i = 0; i < num; i++)
			{
				float num2 = ((num > 1) ? ((float)i / (float)(num - 1)) : 0.5f);
				float num3 = Mathf.Lerp(0f, -166.6f, num2);
				bool flag = (i & 1) != 0;
				float num4 = (flag ? (num3 + -25.7f) : num3);
				MapInstance entry = mapInstances[i];
				Transform val4 = (flag ? val2 : val);
				Transform val5 = Object.Instantiate<Transform>(val4, canvas, false);
				((Object)val5).name = "MapLine_" + entry.DisplayName;
				((Component)val5).gameObject.SetActive(true);
				RectTransform val6 = (RectTransform)(object)((val5 is RectTransform) ? val5 : null);
				if (val6 != null)
				{
					Vector2 anchoredPosition = val6.anchoredPosition;
					val6.anchoredPosition = new Vector2(anchoredPosition.x, num4);
				}
				MapScreenLineBindings.ApplyToLine(val5, entry, i, interactible: false);
			}
			if ((Object)(object)val3 != (Object)null)
			{
				MapScreenVisualCoordinator.RefreshMaxDepth();
			}
			Transform val7 = canvas.Find("BellIcon");
			if ((Object)(object)val7 != (Object)null)
			{
				val7.SetAsLastSibling();
			}
			if ((Object)(object)val3 != (Object)null)
			{
				val3.SetAsLastSibling();
			}
		}

		private static void ApplyInvisMaterialToLineOutlineCube(Transform lineRoot)
		{
			Transform val = lineRoot.Find("MapIcon/Outline/OutlineCube");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("RegionsExpanded: " + ((Object)lineRoot).name + ".MapIcon/Outline/OutlineCube not found.");
				return;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogError("RegionsExpanded: OutlineCube has no MeshRenderer on " + ((Object)lineRoot).name + ".");
				return;
			}
			Material val2 = Resources.Load<Material>("M_Invis") ?? GameMaterials.GetMaterial((GameMaterial)298);
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: Invisible material not found.");
				return;
			}
			Material[] materials = ((Renderer)component).materials;
			for (int i = 0; i < materials.Length; i++)
			{
				materials[i] = val2;
			}
			((Renderer)component).materials = materials;
			Logger.Log("RegionsExpanded: Applied invisible material to " + ((Object)lineRoot).name + ".MapIcon/Outline/OutlineCube.");
		}

		private static void SetupUpgradeDropbox(Transform parent)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_052b: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Expected O, but got Unknown
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Expected O, but got Unknown
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			GameObject divingBellUpgradeDropboxPrefab = global::RegionsExpanded.CustomContent.CustomContent.DivingBellUpgradeDropboxPrefab;
			if ((Object)(object)divingBellUpgradeDropboxPrefab == (Object)null)
			{
				Logger.LogError("RegionsExpanded: DivingBellUpgradeDropboxPrefab is null; dropbox not spawned.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(divingBellUpgradeDropboxPrefab);
			val.transform.localPosition = new Vector3(-3.49f, 0.81f, -15.46f);
			val.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
			val.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
			GameObject gameObject = ((Component)val.transform.Find("Dropbox")).gameObject;
			GameObject gameObject2 = ((Component)val.transform.Find("DropboxFrontText")).gameObject;
			GameObject gameObject3 = ((Component)val.transform.Find("InsulatingTape")).gameObject;
			GameObject gameObject4 = ((Component)val.transform.Find("Blueprint")).gameObject;
			GameObject gameObject5 = ((Component)val.transform.Find("Pliers")).gameObject;
			GameObject gameObject6 = ((Component)val.transform.Find("MeasuringTape")).gameObject;
			GameObject gameObject7 = ((Component)val.transform.Find("Screwdriver")).gameObject;
			GameObject gameObject8 = ((Component)val.transform.Find("Vents")).gameObject;
			GameObject gameObject9 = ((Component)val.transform.Find("Wheels")).gameObject;
			GameObject gameObject10 = ((Component)val.transform.Find("Wrench")).gameObject;
			GameObject gameObject11 = ((Component)val.transform.Find("LidPivot")).gameObject;
			GameObject gameObject12 = ((Component)gameObject11.transform.Find("Lid")).gameObject;
			GameObject gameObject13 = ((Component)gameObject11.transform.Find("WrenchLogo")).gameObject;
			GameObject gameObject14 = ((Component)val.transform.Find("UpgradeDetectionZone")).gameObject;
			PhotonView val2 = val.AddComponent<PhotonView>();
			val2.ViewID = 996;
			UpgradeDropBox upgradeDropBox = val.AddComponent<UpgradeDropBox>();
			upgradeDropBox.Particles = ((Component)val.transform.Find("Particles")).gameObject;
			UpgradeDropBoxItemDetector detector = gameObject14.AddComponent<UpgradeDropBoxItemDetector>();
			UpgradeDropBoxLid upgradeDropBoxLid = gameObject11.AddComponent<UpgradeDropBoxLid>();
			upgradeDropBox.Detector = detector;
			upgradeDropBox.Lid = upgradeDropBoxLid;
			upgradeDropBoxLid.Machine = upgradeDropBox;
			if ((Object)(object)gameObject == (Object)null)
			{
				Logger.LogError("RegionsExpanded: DivingBellUpgradeDropbox.Dropbox not found.");
				return;
			}
			if ((Object)(object)gameObject2 == (Object)null)
			{
				Logger.LogError("RegionsExpanded: DivingBellUpgradeDropbox.Dro