Decompiled source of Spookdivers v1.0.4

cheese.spookdivers.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
using Photon.Pun;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("cheese.spookdivers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("Spookdivers")]
[assembly: AssemblyTitle("cheese.spookdivers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Spookdivers
{
	[BepInPlugin("cheese.spookdivers", "Spookdivers", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		internal static readonly ushort ModID;

		private static int _day;

		private const int ButtonCountFactory = 4;

		private static readonly Vector3[] ButtonPositionsFactory;

		private static readonly Quaternion[] ButtonRotationsFactory;

		private const int ButtonCountHarbor = 4;

		private static readonly Vector3[] ButtonPositionsHarbor;

		private static readonly Quaternion[] ButtonRotationsHarbor;

		private const int ButtonCountMines = 4;

		private static readonly Vector3[] ButtonPositionsMines;

		private static readonly Quaternion[] ButtonRotationsMines;

		internal ConfigEntry<float> ReadyTime = null;

		internal ConfigEntry<bool> ForceScene = null;

		internal ConfigEntry<string> SceneName = null;

		internal ConfigEntry<bool> FakeBellsConfig = null;

		internal ConfigEntry<float> LoweringSpeedConfig = null;

		private int _playerCount = 1;

		internal DivingBell[] DivingBells = Array.Empty<DivingBell>();

		private bool _isInPhaseState = false;

		private bool _isInReadyState = false;

		internal bool CalledBellButtonClicked = false;

		internal bool CalledFakeBellButtonClicked = false;

		private bool _evening = false;

		public static Plugin Instance { get; private set; } = null;


		private static ManualLogSource Logger { get; set; } = null;


		private static Harmony? Harmony { get; set; }

		private static int PlayerCountReady
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<int>("ReadyPlayers");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("ReadyPlayers", (object)value);
			}
		}

		private bool IsHost => PhotonNetwork.IsMasterClient;

		private static bool StartedWithoutDivingBell
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<bool>("StartedWithoutDivingBell");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("StartedWithoutDivingBell", (object)value);
			}
		}

		internal static bool FakeBells
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<bool>("FakeBells");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("FakeBells", (object)value);
			}
		}

		internal static int RandomID
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<int>("RandomID");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("RandomID", (object)value);
			}
		}

		internal static int FakeBellRandomID
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<int>("FakeBellRandomID");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("FakeBellRandomID", (object)value);
			}
		}

		internal static float LoweringSpeed
		{
			get
			{
				return MyceliumNetwork.GetLobbyData<float>("LoweringSpeed");
			}
			set
			{
				MyceliumNetwork.SetLobbyData("LoweringSpeed", (object)value);
			}
		}

		private void Start()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
			MyceliumNetwork.RegisterNetworkObject((object)this, (uint)ModID, 0);
			MyceliumNetwork.RegisterLobbyDataKey("ReadyPlayers");
			MyceliumNetwork.RegisterLobbyDataKey("StartedWithoutDivingBell");
			MyceliumNetwork.RegisterLobbyDataKey("RandomID");
			MyceliumNetwork.RegisterLobbyDataKey("FakeBells");
			MyceliumNetwork.RegisterLobbyDataKey("FakeBellRandomID");
			MyceliumNetwork.RegisterLobbyDataKey("LoweringSpeed");
			MyceliumNetwork.PlayerEntered += delegate
			{
				_playerCount++;
			};
			MyceliumNetwork.PlayerLeft += delegate
			{
				_playerCount--;
			};
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Instance.ReadyTime = ((BaseUnityPlugin)this).Config.Bind<float>("SETTINGS", "ReadyTime", 30f, "Time to wait for all players to be ready.");
			Instance.ForceScene = ((BaseUnityPlugin)this).Config.Bind<bool>("SETTINGS", "ForceScene", false, "Forces the scene to change. (HOST ONLY)");
			Instance.SceneName = ((BaseUnityPlugin)this).Config.Bind<string>("SETTINGS", "SceneName", "FactoryScene", "Scene to force change to [FactoryScene, HarbourScene, MinesScene] (HOST ONLY)");
			Instance.FakeBellsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("SETTINGS", "FakeBells", false, "Enables fake diving bells, they are somewhat distinguishable from the real ones. (HOST ONLY)");
			Instance.LoweringSpeedConfig = ((BaseUnityPlugin)this).Config.Bind<float>("SETTINGS", "LoweringSpeed", 2f, "Speed at which the diving bell will lower. (HOST ONLY)");
			Patch();
			Logger.LogInfo((object)"cheese.spookdivers v1.0.4 has loaded!");
		}

		private static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("cheese.spookdivers");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "SurfaceScene")
			{
				return;
			}
			if (SurfaceNetworkHandler.RoomStats.CurrentQuotaDay != _day)
			{
				_day = SurfaceNetworkHandler.RoomStats.CurrentQuotaDay;
				CheckForEvening();
			}
			if (!_evening)
			{
				if (Player.localPlayer.refs.headPos.position.y < -50f && !_isInPhaseState)
				{
					_isInPhaseState = true;
					BlackScreen.instance.SetBlackScreen(60f);
					Logger.LogInfo((object)"Waiting for other players to join!");
				}
				if (Player.localPlayer.refs.headPos.position.y < -90f && !_isInReadyState)
				{
					FreezePlayer();
					Ready();
					Logger.LogInfo((object)"Player is ready");
					((MonoBehaviour)this).StartCoroutine(ReadyState("FactoryScene", ReadyTime.Value));
				}
			}
		}

		private IEnumerator ReadyState(string sceneName, float time)
		{
			for (float secondsWaited = 0f; secondsWaited < time; secondsWaited += 1f)
			{
				if (IsHost && _playerCount == PlayerCountReady)
				{
					Logger.LogInfo((object)"All players are ready! Starting the game!");
					yield return (object)new WaitForSeconds(3f);
					string levelName = new List<string> { "FactoryScene", "MinesScene", "HarbourScene" }[SurfaceNetworkHandler.RoomStats.LevelToPlay];
					if (ForceScene.Value)
					{
						levelName = SceneName.Value;
					}
					PhotonNetwork.LoadLevel(levelName);
					StartedWithoutDivingBell = true;
					yield break;
				}
				yield return (object)new WaitForSeconds(1f);
			}
			UnfreezePlayer();
			yield return (object)new WaitForSeconds(1f);
			NotReady();
		}

		[CustomRPC]
		public void DivingBellButtonClicked(int randomID, RPCInfo info)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0061: 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)
			CSteamID senderSteamID = info.SenderSteamID;
			string friendPersonaName = SteamFriends.GetFriendPersonaName(senderSteamID);
			Debug.Log((object)(friendPersonaName + " called the diving bell!"));
			CalledBellButtonClicked = true;
			HelmetText.Instance.SetHelmetText("The Diving Bell has been called!", 2f);
			DivingBell divingBell = DivingBells[randomID];
			Vector3 oldPosition = ((Component)divingBell).transform.position;
			((Component)divingBell).transform.position = new Vector3(oldPosition.x, 150f, oldPosition.z);
			((MonoBehaviour)this).StartCoroutine(MoveBellDown(LoweringSpeed));
			Logger.LogInfo((object)("Activated Diving Bell: " + randomID));
			IEnumerator MoveBellDown(float speed)
			{
				yield return (object)new WaitForSeconds(5f);
				((Component)divingBell).gameObject.SetActive(true);
				while (((Component)divingBell).transform.position.y > oldPosition.y)
				{
					Transform transform = ((Component)divingBell).transform;
					transform.position -= new Vector3(0f, speed * Time.deltaTime, 0f);
					yield return null;
				}
				divingBell.RPC_Open();
			}
		}

		[CustomRPC]
		public void FakeDivingBellButtonClicked(int randomID, int randomMod, RPCInfo info)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			CSteamID senderSteamID = info.SenderSteamID;
			string friendPersonaName = SteamFriends.GetFriendPersonaName(senderSteamID);
			Debug.Log((object)(friendPersonaName + " called the diving bell!"));
			CalledFakeBellButtonClicked = true;
			HelmetText.Instance.SetHelmetText("The Diving Bell has been called!", 2f);
			DivingBell divingBell = DivingBells[randomID];
			Vector3 oldPosition = ((Component)divingBell).transform.position;
			((Component)divingBell).transform.position = new Vector3(oldPosition.x, 150f, oldPosition.z);
			((MonoBehaviour)this).StartCoroutine(MoveBellDown(LoweringSpeed));
			Logger.LogInfo((object)("Activated Diving Bell: " + randomID));
			IEnumerator MoveBellDown(float speed)
			{
				yield return (object)new WaitForSeconds(5f);
				((Component)divingBell).gameObject.SetActive(true);
				while (((Component)divingBell).transform.position.y > oldPosition.y)
				{
					Transform transform2 = ((Component)divingBell).transform;
					transform2.position -= new Vector3(0f, speed * Time.deltaTime, 0f);
					yield return null;
				}
				GameObject light;
				switch (randomMod)
				{
				case 0:
				{
					TMP_Text osText = ((Component)((Component)((Component)((Component)((Component)((Component)((Component)divingBell).transform.GetChild(2)).transform.GetChild(2)).transform.GetChild(0)).transform.GetChild(1)).transform.GetChild(0)).transform).GetComponent<TMP_Text>();
					osText.text = "DiveOS   V0.00rc";
					break;
				}
				case 1:
				{
					TMP_Text suitsText = ((Component)((Component)((Component)((Component)((Component)((Component)((Component)divingBell).transform.GetChild(2)).transform.GetChild(2)).transform.GetChild(0)).transform.GetChild(1)).transform.GetChild(2)).transform).GetComponent<TMP_Text>();
					suitsText.text = "You are being watched";
					break;
				}
				case 2:
				{
					GameObject travelButton = ((Component)((Component)((Component)divingBell).transform.GetChild(2)).transform.GetChild(1)).gameObject;
					travelButton.SetActive(false);
					break;
				}
				case 3:
				{
					GameObject doorButton = ((Component)((Component)((Component)divingBell).transform.GetChild(2)).transform.GetChild(1)).gameObject;
					doorButton.SetActive(false);
					break;
				}
				case 4:
					light = ((Component)((Component)((Component)divingBell).transform.GetChild(1)).transform.GetChild(8)).gameObject;
					((MonoBehaviour)this).StartCoroutine(FlickerLight());
					break;
				}
				divingBell.RPC_Open();
				((MonoBehaviour)this).StartCoroutine(WaitForPlayer());
				IEnumerator FlickerLight()
				{
					while (((Component)divingBell).gameObject.activeSelf)
					{
						light.SetActive(true);
						yield return (object)new WaitForSeconds(Random.Range(5f, 15f));
						light.SetActive(false);
						yield return (object)new WaitForSeconds(Random.Range(0.1f, 0.5f));
					}
				}
			}
			IEnumerator WaitForPlayer()
			{
				while (divingBell.playerDetector.CheckForPlayers().Count == 0)
				{
					yield return (object)new WaitForSeconds(1f);
				}
				ICollection<Player> players = divingBell.playerDetector.CheckForPlayers();
				((MonoBehaviour)this).StartCoroutine(divingBell.door.Close());
				divingBell.LockDoors();
				((MonoBehaviour)this).StartCoroutine(CheckAndKill());
				yield return (object)new WaitForSeconds(3f);
				while (((Component)divingBell).transform.position.y < 150f)
				{
					Transform transform = ((Component)divingBell).transform;
					transform.position += new Vector3(0f, 1f * Time.deltaTime, 0f);
					yield return null;
				}
				((Component)divingBell).gameObject.SetActive(false);
				IEnumerator CheckAndKill()
				{
					while (true)
					{
						bool allAlive = false;
						foreach (Player player in players)
						{
							if (!divingBell.playerDetector.CheckForPlayers().Contains(player))
							{
								player.Die();
							}
							if (!player.data.dead)
							{
								allAlive = true;
							}
						}
						if (!allAlive)
						{
							break;
						}
						yield return (object)new WaitForSeconds(1f);
					}
				}
			}
		}

		[CustomRPC]
		public void RPC_MakeStaticSeed(int seed, RPCInfo info)
		{
			Random.InitState(seed);
		}

		public void Ready()
		{
			_isInReadyState = true;
			_isInPhaseState = true;
			MyceliumNetwork.RPC((uint)ModID, "ReadyStatusReceived", (ReliableType)1, new object[1] { "ready" });
		}

		public void NotReady()
		{
			_isInReadyState = false;
			_isInPhaseState = false;
			BlackScreen.instance.blackScreenForSeconds = 0f;
			MyceliumNetwork.RPC((uint)ModID, "ReadyStatusReceived", (ReliableType)1, new object[1] { "not ready" });
		}

		[CustomRPC]
		public void ReadyStatusReceived(string message, RPCInfo info)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			CSteamID senderSteamID = info.SenderSteamID;
			string friendPersonaName = SteamFriends.GetFriendPersonaName(senderSteamID);
			if (message == "ready")
			{
				Debug.Log((object)(friendPersonaName + " is Ready!"));
				PlayerCountReady++;
			}
			else
			{
				Debug.Log((object)(friendPersonaName + " is not Ready!"));
				PlayerCountReady--;
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			Random.InitState((int)DateTime.Now.Ticks);
			RandomID = -1;
			FakeBellRandomID = -1;
			PlayerCountReady = 0;
			_isInReadyState = false;
			_isInPhaseState = false;
			DivingBells = Array.Empty<DivingBell>();
			CalledBellButtonClicked = false;
			CalledFakeBellButtonClicked = false;
			_playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
			if (((Scene)(ref scene)).name == "SurfaceScene")
			{
				StartedWithoutDivingBell = false;
				if (IsHost)
				{
					FakeBells = FakeBellsConfig.Value;
					LoweringSpeed = LoweringSpeedConfig.Value;
				}
				((MonoBehaviour)this).StartCoroutine(Check());
			}
			bool flag;
			switch (((Scene)(ref scene)).name)
			{
			case "FactoryScene":
			case "HarbourScene":
			case "MinesScene":
				flag = true;
				break;
			default:
				flag = false;
				break;
			}
			if (!flag || !StartedWithoutDivingBell)
			{
				return;
			}
			int num = 0;
			switch (((Scene)(ref scene)).name)
			{
			case "FactoryScene":
				num = 4;
				break;
			case "HarbourScene":
				num = 4;
				break;
			case "MinesScene":
				num = 4;
				break;
			}
			if (RandomID == -1)
			{
				RandomID = Random.RandomRangeInt(0, num);
			}
			if (FakeBells && FakeBellRandomID == -1)
			{
				do
				{
					FakeBellRandomID = Random.RandomRangeInt(0, num);
				}
				while (FakeBellRandomID == RandomID);
			}
			GameObject val = null;
			if (((Scene)(ref scene)).name == "FactoryScene")
			{
				val = GameObject.Find("Spawns");
			}
			else if (((Scene)(ref scene)).name == "HarbourScene")
			{
				val = GameObject.Find("DiveBells");
			}
			else if (((Scene)(ref scene)).name == "MinesScene")
			{
				val = ((Component)GameObject.Find("Misc").transform.GetChild(3)).gameObject;
			}
			DivingBells = val.GetComponentsInChildren<DivingBell>();
			DivingBell[] divingBells = DivingBells;
			foreach (DivingBell val2 in divingBells)
			{
				if (((Component)val2).gameObject.activeSelf)
				{
					if (((Scene)(ref scene)).name == "MinesScene")
					{
						((Component)((Component)val2).transform.Find("Spawns")).gameObject.transform.position = new Vector3(140f, 80f, 80f);
					}
					else
					{
						((Component)((Component)val2).transform.Find("Spawns")).gameObject.transform.position = new Vector3(0f, 70f, 0f);
					}
				}
			}
			GameObject button = ((Component)((Component)((Component)val.transform.GetChild(0)).transform.GetChild(2)).transform.GetChild(1)).gameObject;
			((MonoBehaviour)this).StartCoroutine(Async());
			IEnumerator Async()
			{
				while ((Object)(object)Player.localPlayer == (Object)null)
				{
					yield return null;
				}
				DivingBell[] divingBells2 = DivingBells;
				foreach (DivingBell divingBell in divingBells2)
				{
					((Component)divingBell).gameObject.SetActive(false);
				}
				GameObject spawnFixBell = ((Component)DivingBells[^1]).gameObject;
				((Object)spawnFixBell).name = "SpawnFixBell";
				spawnFixBell.transform.position = new Vector3(0f, 1000f, 0f);
				spawnFixBell.SetActive(true);
				Array.Resize(ref DivingBells, DivingBells.Length + 1);
				FreezePlayer();
				if (((Scene)(ref scene)).name == "FactoryScene")
				{
					FactoryTeleportRandom();
				}
				else if (((Scene)(ref scene)).name == "HarbourScene")
				{
					HarborTeleportRandom();
				}
				else if (((Scene)(ref scene)).name == "MinesScene")
				{
					MinesTeleportRandom();
				}
				UnfreezePlayer();
				yield return (object)new WaitForSeconds(8f);
				switch (_day)
				{
				case 1:
					HelmetText.Instance.SetHelmetText("What have you done?", 2f);
					yield return (object)new WaitForSeconds(4f);
					HelmetText.Instance.SetHelmetText("You need to find a way back...", 2f);
					break;
				case 2:
					HelmetText.Instance.SetHelmetText("Now this is more than just a \"slip\"...", 2f);
					break;
				default:
					HelmetText.Instance.SetHelmetText("Well you know the drill...", 2f);
					break;
				}
				Vector3[] positions = (Vector3[])(object)new Vector3[0];
				Quaternion[] rotations = (Quaternion[])(object)new Quaternion[0];
				if (((Scene)(ref scene)).name == "FactoryScene")
				{
					positions = ButtonPositionsFactory;
					rotations = ButtonRotationsFactory;
				}
				else if (((Scene)(ref scene)).name == "HarbourScene")
				{
					positions = ButtonPositionsHarbor;
					rotations = ButtonRotationsHarbor;
				}
				else if (((Scene)(ref scene)).name == "MinesScene")
				{
					positions = ButtonPositionsMines;
					rotations = ButtonRotationsMines;
				}
				GameObject newButton = Object.Instantiate<GameObject>(button, positions[RandomID], rotations[RandomID]);
				newButton.transform.localScale = new Vector3(10f, 10f, 5f);
				((Object)newButton).name = "CallDivingBellButton";
				Object.Destroy((Object)(object)newButton.GetComponent<UseDivingBellButton>());
				newButton.AddComponent<CustomButton>();
				newButton.SetActive(true);
				if (FakeBells)
				{
					GameObject newFakeButton = Object.Instantiate<GameObject>(button, positions[FakeBellRandomID], rotations[FakeBellRandomID]);
					newFakeButton.transform.localScale = new Vector3(10f, 10f, 5f);
					((Object)newFakeButton).name = "CallFakeDivingBellButton";
					Object.Destroy((Object)(object)newFakeButton.GetComponent<UseDivingBellButton>());
					newFakeButton.AddComponent<FakeCustomButton>();
					newFakeButton.SetActive(true);
					if (IsHost)
					{
						MyceliumNetwork.RPC((uint)ModID, "RPC_MakeStaticSeed", (ReliableType)1, new object[1] { Random.state.s0 });
					}
				}
			}
			IEnumerator Check()
			{
				yield return (object)new WaitForSeconds(3f);
				CheckForEvening();
			}
		}

		private void TeleportPlayer(Vector3 newPosition, Vector3 newForward)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.localPlayer == (Object)null)
			{
				Logger.LogInfo((object)"Player object is null");
				return;
			}
			MethodInfo method = typeof(Player).GetMethod("Teleport", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				method.Invoke(Player.localPlayer, new object[2] { newPosition, newForward });
			}
			else
			{
				Logger.LogInfo((object)"Teleport method not found");
			}
		}

		private void FactoryTeleportRandom()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((float)Random.Range(-120, 60), 80f, (float)Random.Range(-120, 60));
			Vector3 newForward = default(Vector3);
			((Vector3)(ref newForward))..ctor(val.x, 0f, val.z);
			TeleportPlayer(val, newForward);
		}

		private void HarborTeleportRandom()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((float)Random.Range(-48, 45), 80f, (float)Random.Range(0, 12));
			Vector3 newForward = default(Vector3);
			((Vector3)(ref newForward))..ctor(val.x, 0f, val.z);
			TeleportPlayer(val, newForward);
		}

		private void MinesTeleportRandom()
		{
			//IL_0025: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				new Vector3((float)Random.Range(126, 140), 80f, (float)Random.Range(80, 100)),
				new Vector3((float)Random.Range(4, 20), 60f, (float)Random.Range(62, 65)),
				new Vector3((float)Random.Range(60, 80), 50f, (float)Random.Range(111, 130)),
				new Vector3((float)Random.Range(0, 10), 56f, (float)Random.Range(-3, 8))
			};
			Vector3 val = array[Random.Range(0, 4)];
			Vector3 newForward = default(Vector3);
			((Vector3)(ref newForward))..ctor(val.x, 0f, val.z);
			TeleportPlayer(val, newForward);
		}

		protected void CheckForEvening()
		{
			GameObject val = GameObject.Find("Misc");
			GameObject gameObject = ((Component)val.transform.GetChild(4)).gameObject;
			_evening = gameObject.activeSelf;
		}

		private void FreezePlayer()
		{
			MyceliumNetwork.RPC((uint)ModID, "RPC_FreezePlayer", (ReliableType)1, new object[1] { Player.localPlayer.refs.view.ViewID });
		}

		private void UnfreezePlayer()
		{
			MyceliumNetwork.RPC((uint)ModID, "RPC_UnFreezePlayer", (ReliableType)1, new object[1] { Player.localPlayer.refs.view.ViewID });
		}

		[CustomRPC]
		private void RPC_FreezePlayer(int viewID, RPCInfo info)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(PlayerHandler);
			MethodInfo method = typeFromHandle.GetMethod("TryGetPlayerFromViewID", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = method.Invoke(PlayerHandler.instance, new object[1] { viewID });
			Player val = (Player)((obj is Player) ? obj : null);
			val.data.gravityDirection = Vector3.zero;
		}

		[CustomRPC]
		private void RPC_UnFreezePlayer(int viewID, RPCInfo info)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(PlayerHandler);
			MethodInfo method = typeFromHandle.GetMethod("TryGetPlayerFromViewID", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = method.Invoke(PlayerHandler.instance, new object[1] { viewID });
			Player val = (Player)((obj is Player) ? obj : null);
			val.data.gravityDirection = new Vector3(0f, -1f, 0f);
		}

		static Plugin()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			Hash128 val = Hash128.Compute("cheese.spookdivers");
			ModID = (ushort)((object)(Hash128)(ref val)).GetHashCode();
			_day = 0;
			ButtonPositionsFactory = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-123.3f, 0.4f, -45.7f),
				new Vector3(34.8f, 2.6f, -5.16f),
				new Vector3(34.5f, 5.5f, 19f),
				new Vector3(3.5f, -19.9f, -9.22f)
			};
			ButtonRotationsFactory = (Quaternion[])(object)new Quaternion[4]
			{
				Quaternion.Euler(270f, 0f, 0f),
				Quaternion.Euler(0f, 0f, 0f),
				Quaternion.Euler(0f, 90f, 0f),
				Quaternion.Euler(270f, 0f, 0f)
			};
			ButtonPositionsHarbor = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-22.7f, -1.6f, 29.1f),
				new Vector3(-51.6f, -2f, 17.55f),
				new Vector3(27.2f, -3.6f, 13.8f),
				new Vector3(-1f, -7f, 10.6f)
			};
			ButtonRotationsHarbor = (Quaternion[])(object)new Quaternion[4]
			{
				Quaternion.Euler(357f, 22f, 0f),
				Quaternion.Euler(272f, 180f, 180f),
				Quaternion.Euler(348f, 200f, 0f),
				Quaternion.Euler(0f, 295f, 0f)
			};
			ButtonPositionsMines = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(12f, -6f, 67.9f),
				new Vector3(134.2f, 25.2f, 2.9f),
				new Vector3(165.8f, 11f, 55.75f),
				new Vector3(152.4f, 7f, 44f)
			};
			ButtonRotationsMines = (Quaternion[])(object)new Quaternion[4]
			{
				Quaternion.Euler(0f, 22f, 0f),
				Quaternion.Euler(0f, 0f, 0f),
				Quaternion.Euler(0f, 0f, 0f),
				Quaternion.Euler(0f, 90f, 0f)
			};
		}
	}
	public class CustomButton : Interactable
	{
		private static bool Clicked
		{
			get
			{
				return Plugin.Instance.CalledBellButtonClicked;
			}
			set
			{
				Plugin.Instance.CalledBellButtonClicked = value;
			}
		}

		private static DivingBell[] DivingBells => Plugin.Instance.DivingBells;

		private void Update()
		{
			base.hoverText = "Call the Diving Bell";
		}

		public override void Interact(Player player)
		{
			if (!Clicked)
			{
				Clicked = true;
				int num = 0;
				do
				{
					num = Random.Range(0, DivingBells.Length);
				}
				while (((Component)DivingBells[num]).gameObject.activeSelf);
				MyceliumNetwork.RPC((uint)Plugin.ModID, "DivingBellButtonClicked", (ReliableType)1, new object[1] { num });
			}
		}

		public override bool IsValid(Player player)
		{
			if (Clicked)
			{
				return false;
			}
			base.hoverText = "Call the Diving Bell";
			return true;
		}
	}
	public class FakeCustomButton : Interactable
	{
		private static bool Clicked
		{
			get
			{
				return Plugin.Instance.CalledFakeBellButtonClicked;
			}
			set
			{
				Plugin.Instance.CalledFakeBellButtonClicked = value;
			}
		}

		private static DivingBell[] DivingBells => Plugin.Instance.DivingBells;

		private void Update()
		{
			base.hoverText = "Call the Diving Bell";
		}

		public override void Interact(Player player)
		{
			if (!Clicked)
			{
				Clicked = true;
				int num = 0;
				do
				{
					num = Random.Range(0, DivingBells.Length);
				}
				while (((Component)DivingBells[num]).gameObject.activeSelf);
				int num2 = Random.Range(0, 5);
				MyceliumNetwork.RPC((uint)Plugin.ModID, "FakeDivingBellButtonClicked", (ReliableType)1, new object[2] { num, num2 });
			}
		}

		public override bool IsValid(Player player)
		{
			if (Clicked)
			{
				return false;
			}
			base.hoverText = "Call the Diving Bell";
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "cheese.spookdivers";

		public const string PLUGIN_NAME = "Spookdivers";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}