Decompiled source of Backrooms v0.1.3

plugins/backrooms/Backrooms.dll

Decompiled 5 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using DunGen.Graph;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.AI.Navigation;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<float>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<float>();
	}
}
[RequireComponent(typeof(SphereCollider))]
public class KillBox : MonoBehaviour
{
	private void OnTriggerEnter(Collider other)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
		if ((Object)(object)component != (Object)null)
		{
			component.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0);
		}
	}
}
public class LightFlickerEffect : MonoBehaviour
{
	[Tooltip("External light to flicker; you can leave this null if you attach script to a light")]
	public Light light;

	[Tooltip("Minimum random light intensity")]
	public float minIntensity;

	[Tooltip("Maximum random light intensity")]
	public float maxIntensity = 1f;

	[Tooltip("How much to smooth out the randomness; lower values = sparks, higher = lantern")]
	[Range(1f, 50f)]
	public int smoothing = 5;

	private Queue<float> smoothQueue;

	private float lastSum;

	public void Reset()
	{
		smoothQueue.Clear();
		lastSum = 0f;
	}

	private void Start()
	{
		smoothQueue = new Queue<float>(smoothing);
		if ((Object)(object)light == (Object)null)
		{
			light = ((Component)this).GetComponent<Light>();
		}
	}

	private void Update()
	{
		if (!((Object)(object)light == (Object)null))
		{
			while (smoothQueue.Count >= smoothing)
			{
				lastSum -= smoothQueue.Dequeue();
			}
			float num = Random.Range(minIntensity, maxIntensity);
			smoothQueue.Enqueue(num);
			lastSum += num;
			light.intensity = lastSum / (float)smoothQueue.Count;
		}
	}
}
public class LookAtPlayer : MonoBehaviour
{
	private void Update()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).gameObject.transform.LookAt(((Component)GameNetworkManager.Instance.localPlayerController).transform.position + Vector3.up);
	}
}
public class SpawnPosition : MonoBehaviour
{
	private void Start()
	{
	}

	private void Update()
	{
	}
}
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Never)]
[GeneratedCode("Unity.MonoScriptGenerator.MonoScriptInfoGenerator", null)]
internal class UnitySourceGeneratedAssemblyMonoScriptTypes_v1
{
	private struct MonoScriptData
	{
		public byte[] FilePathsData;

		public byte[] TypesData;

		public int TotalTypes;

		public int TotalFiles;

		public bool IsEditorOnly;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private static MonoScriptData Get()
	{
		MonoScriptData result = default(MonoScriptData);
		result.FilePathsData = new byte[506]
		{
			0, 0, 0, 1, 0, 0, 0, 42, 92, 65,
			115, 115, 101, 116, 115, 92, 66, 97, 99, 107,
			114, 111, 111, 109, 115, 92, 83, 99, 114, 105,
			112, 116, 115, 92, 65, 114, 101, 89, 111, 117,
			87, 97, 116, 99, 104, 101, 100, 46, 99, 115,
			0, 0, 0, 1, 0, 0, 0, 38, 92, 65,
			115, 115, 101, 116, 115, 92, 66, 97, 99, 107,
			114, 111, 111, 109, 115, 92, 83, 99, 114, 105,
			112, 116, 115, 92, 66, 97, 99, 107, 114, 111,
			111, 109, 115, 46, 99, 115, 0, 0, 0, 1,
			0, 0, 0, 33, 92, 65, 115, 115, 101, 116,
			115, 92, 66, 97, 99, 107, 114, 111, 111, 109,
			115, 92, 83, 99, 114, 105, 112, 116, 115, 92,
			69, 120, 105, 116, 46, 99, 115, 0, 0, 0,
			1, 0, 0, 0, 33, 92, 65, 115, 115, 101,
			116, 115, 92, 66, 97, 99, 107, 114, 111, 111,
			109, 115, 92, 83, 99, 114, 105, 112, 116, 115,
			92, 72, 111, 111, 107, 46, 99, 115, 0, 0,
			0, 1, 0, 0, 0, 36, 92, 65, 115, 115,
			101, 116, 115, 92, 66, 97, 99, 107, 114, 111,
			111, 109, 115, 92, 83, 99, 114, 105, 112, 116,
			115, 92, 75, 105, 108, 108, 66, 111, 120, 46,
			99, 115, 0, 0, 0, 1, 0, 0, 0, 47,
			92, 65, 115, 115, 101, 116, 115, 92, 66, 97,
			99, 107, 114, 111, 111, 109, 115, 92, 83, 99,
			114, 105, 112, 116, 115, 92, 76, 105, 103, 104,
			116, 70, 108, 105, 99, 107, 101, 114, 69, 102,
			102, 101, 99, 116, 46, 99, 115, 0, 0, 0,
			1, 0, 0, 0, 35, 92, 65, 115, 115, 101,
			116, 115, 92, 66, 97, 99, 107, 114, 111, 111,
			109, 115, 92, 83, 99, 114, 105, 112, 116, 115,
			92, 76, 111, 97, 100, 101, 114, 46, 99, 115,
			0, 0, 0, 1, 0, 0, 0, 41, 92, 65,
			115, 115, 101, 116, 115, 92, 66, 97, 99, 107,
			114, 111, 111, 109, 115, 92, 83, 99, 114, 105,
			112, 116, 115, 92, 76, 111, 111, 107, 65, 116,
			80, 108, 97, 121, 101, 114, 46, 99, 115, 0,
			0, 0, 1, 0, 0, 0, 36, 92, 65, 115,
			115, 101, 116, 115, 92, 66, 97, 99, 107, 114,
			111, 111, 109, 115, 92, 83, 99, 114, 105, 112,
			116, 115, 92, 83, 107, 105, 98, 105, 100, 105,
			46, 99, 115, 0, 0, 0, 1, 0, 0, 0,
			35, 92, 65, 115, 115, 101, 116, 115, 92, 66,
			97, 99, 107, 114, 111, 111, 109, 115, 92, 83,
			99, 114, 105, 112, 116, 115, 92, 83, 109, 105,
			108, 101, 114, 46, 99, 115, 0, 0, 0, 1,
			0, 0, 0, 42, 92, 65, 115, 115, 101, 116,
			115, 92, 66, 97, 99, 107, 114, 111, 111, 109,
			115, 92, 83, 99, 114, 105, 112, 116, 115, 92,
			83, 112, 97, 119, 110, 80, 111, 115, 105, 116,
			105, 111, 110, 46, 99, 115
		};
		result.TypesData = new byte[233]
		{
			0, 0, 0, 0, 25, 66, 97, 99, 107, 114,
			111, 111, 109, 115, 124, 66, 97, 99, 107, 114,
			111, 111, 109, 115, 72, 101, 108, 112, 101, 114,
			0, 0, 0, 0, 19, 66, 97, 99, 107, 114,
			111, 111, 109, 115, 124, 66, 97, 99, 107, 114,
			111, 111, 109, 115, 0, 0, 0, 0, 14, 66,
			97, 99, 107, 114, 111, 111, 109, 115, 124, 69,
			120, 105, 116, 0, 0, 0, 0, 14, 66, 97,
			99, 107, 114, 111, 111, 109, 115, 124, 72, 111,
			111, 107, 0, 0, 0, 0, 8, 124, 75, 105,
			108, 108, 66, 111, 120, 0, 0, 0, 0, 19,
			124, 76, 105, 103, 104, 116, 70, 108, 105, 99,
			107, 101, 114, 69, 102, 102, 101, 99, 116, 0,
			0, 0, 0, 16, 66, 97, 99, 107, 114, 111,
			111, 109, 115, 124, 76, 111, 97, 100, 101, 114,
			0, 0, 0, 0, 13, 124, 76, 111, 111, 107,
			65, 116, 80, 108, 97, 121, 101, 114, 0, 0,
			0, 0, 20, 66, 97, 99, 107, 114, 111, 111,
			109, 115, 124, 83, 111, 117, 110, 100, 80, 97,
			116, 99, 104, 0, 0, 0, 0, 16, 66, 97,
			99, 107, 114, 111, 111, 109, 115, 124, 83, 109,
			105, 108, 101, 114, 0, 0, 0, 0, 14, 124,
			83, 112, 97, 119, 110, 80, 111, 115, 105, 116,
			105, 111, 110
		};
		result.TotalFiles = 11;
		result.TotalTypes = 11;
		result.IsEditorOnly = false;
		return result;
	}
}
namespace Backrooms;

public class BackroomsHelper : MonoBehaviour
{
	public bool HasBeenInTheBackrooms;

	private void Start()
	{
	}

	private void Update()
	{
	}
}
public class Backrooms : NetworkBehaviour
{
	public static Backrooms Instance;

	public GameObject Floor;

	public GameObject Wall;

	public GameObject Ceiling;

	public GameObject LightlessCeiling;

	public GameObject Pillar;

	public GameObject Room;

	public static float Offset = -500f;

	private int Width = 30;

	private int Height = 30;

	public List<Vector2> PossibleSpawnPoint;

	public List<PlayerControllerB> playerInBackrooms;

	public NetworkVariable<float> SharedOdds = new NetworkVariable<float>(0f, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

	private float initialValue;

	public DungeonFlow Flow;

	public GameObject Child;

	public override void OnNetworkSpawn()
	{
		if (((NetworkBehaviour)this).IsServer)
		{
			initialValue = Loader.TeleportationOdds.Value;
			SharedOdds.Value = initialValue;
			((NetworkBehaviour)this).NetworkManager.OnClientConnectedCallback += NetworkManager_OnClientConnectedCallback;
			return;
		}
		if (SharedOdds.Value != initialValue)
		{
			Debug.LogWarning((object)($"NetworkVariable was {SharedOdds.Value} upon being spawned" + $" when it should have been {initialValue}"));
		}
		else
		{
			Debug.Log((object)$"NetworkVariable is {SharedOdds.Value} when spawned.");
		}
		NetworkVariable<float> sharedOdds = SharedOdds;
		sharedOdds.OnValueChanged = (OnValueChangedDelegate<float>)(object)Delegate.Combine((Delegate?)(object)sharedOdds.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<float>(OnSomeValueChanged));
	}

	private void NetworkManager_OnClientConnectedCallback(ulong obj)
	{
		StartChangingNetworkVariable();
	}

	private void OnSomeValueChanged(float previous, float current)
	{
		Debug.Log((object)$"Detected NetworkVariable Change: Previous: {previous} | Current: {current}");
	}

	private void StartChangingNetworkVariable()
	{
		((NetworkBehaviour)this).NetworkManager.OnClientConnectedCallback -= NetworkManager_OnClientConnectedCallback;
	}

	private void Awake()
	{
		PossibleSpawnPoint = new List<Vector2>();
		playerInBackrooms = new List<PlayerControllerB>();
	}

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

	private IEnumerator Teleport()
	{
		yield return (object)new WaitForSeconds(10f);
		for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
		{
			if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled)
			{
				TeleportToBackroomsClientRpc(i);
			}
		}
	}

	public void ServerGenerate()
	{
		int seed = Random.Range(0, 1000000);
		GenerateClientRpc(seed);
	}

	public void ServerClean()
	{
		Smiler[] array = Object.FindObjectsOfType<Smiler>();
		for (int i = 0; i < array.Length; i++)
		{
			((Component)array[i]).GetComponent<NetworkObject>().Despawn(true);
		}
		playerInBackrooms.Clear();
		CleanBackroomsClientRpc();
	}

	[ClientRpc]
	public void CleanBackroomsClientRpc()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2180494496u, val, (RpcDelivery)0);
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2180494496u, val, (RpcDelivery)0);
		}
		if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
		{
			return;
		}
		foreach (Transform item in ((Component)this).transform)
		{
			Object.Destroy((Object)(object)((Component)item).gameObject);
		}
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		for (int i = 0; i < allPlayerScripts.Length; i++)
		{
			((Component)allPlayerScripts[i]).GetComponent<BackroomsHelper>().HasBeenInTheBackrooms = false;
		}
	}

	[ServerRpc(RequireOwnership = false)]
	public void TeleportToBackroomsServerRpc(int client)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2541916904u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, client);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2541916904u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				TeleportToBackroomsClientRpc(client);
			}
		}
	}

	[ClientRpc]
	public void TeleportToBackroomsClientRpc(int client)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3078584200u, val, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val2, client);
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3078584200u, val, (RpcDelivery)0);
		}
		if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
		{
			PlayerControllerB val3 = StartOfRound.Instance.allPlayerScripts[client];
			Random.InitState(client);
			Vector2 val4 = PossibleSpawnPoint[Random.Range(0, PossibleSpawnPoint.Count)];
			val3.TeleportPlayer(new Vector3(val4.x, Offset, val4.y), false, 0f, false, true);
			val3.isInsideFactory = true;
			val3.ResetFallGravity();
			((Component)val3).GetComponent<BackroomsHelper>().HasBeenInTheBackrooms = true;
			if (((NetworkBehaviour)this).IsServer)
			{
				playerInBackrooms.Add(val3);
			}
		}
	}

	[ClientRpc]
	public void TeleportOutOfBackroomsClientRpc(int client)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: 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_0089: 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)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1623403188u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, client);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1623403188u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				PlayerControllerB obj = StartOfRound.Instance.allPlayerScripts[client];
				obj.TeleportPlayer(StartOfRound.Instance.playerSpawnPositions[0].position, false, 0f, false, true);
				obj.isInsideFactory = false;
			}
		}
	}

	[ClientRpc]
	public void GenerateClientRpc(int seed)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_054a: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_0560: Unknown result type (might be due to invalid IL or missing references)
		//IL_0565: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0458: Unknown result type (might be due to invalid IL or missing references)
		//IL_046c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(890432861u, val, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val2, seed);
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 890432861u, val, (RpcDelivery)0);
		}
		if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
		{
			return;
		}
		PossibleSpawnPoint.Clear();
		playerInBackrooms.Clear();
		Random random = new Random(seed);
		Debug.Log((object)"Generate floor and ceiling");
		for (int i = -Width / 2; i < Width / 2; i++)
		{
			for (int j = -Height / 2; j < Height / 2; j++)
			{
				Object.Instantiate<GameObject>(Floor, new Vector3((float)(i * 6), Offset, (float)(j * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
				if (random.Next(100) < 85)
				{
					Object.Instantiate<GameObject>(LightlessCeiling, new Vector3((float)(i * 6), Offset + 5f, (float)(j * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
				}
				else
				{
					Object.Instantiate<GameObject>(Ceiling, new Vector3((float)(i * 6), Offset + 5f, (float)(j * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
				}
			}
		}
		Debug.Log((object)"Generate walls");
		for (int k = -Width / 2; k < Width / 2; k++)
		{
			Object.Instantiate<GameObject>(Wall, new Vector3((float)(-Width / 2 * 6 - 3), Offset, (float)(k * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
			if (k != 0)
			{
				Object.Instantiate<GameObject>(Wall, new Vector3((float)(Width / 2 * 6 - 3), Offset, (float)(k * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
				continue;
			}
			Debug.Log((object)"Generate room");
			Object.Instantiate<GameObject>(Room, new Vector3((float)(Width / 2 * 6 - 3), Offset, (float)(k * 6)), Quaternion.Euler(0f, 90f, 0f), ((Component)this).transform);
		}
		Debug.Log((object)"Generate walls 2");
		for (int l = -Width / 2; l < Width / 2; l++)
		{
			Object.Instantiate<GameObject>(Wall, new Vector3((float)(l * 6), Offset, (float)(-Height / 2 * 6 - 3)), Quaternion.Euler(-90f, 90f, 0f), ((Component)this).transform);
			Object.Instantiate<GameObject>(Wall, new Vector3((float)(l * 6), Offset, (float)(Height / 2 * 6 - 3)), Quaternion.Euler(-90f, 90f, 0f), ((Component)this).transform);
		}
		Debug.Log((object)"Generate inside 2");
		for (int m = -Width / 2; m < Width / 2; m++)
		{
			for (int n = -Height / 2; n < Height / 2; n++)
			{
				if (m == 0 && n == 0)
				{
					continue;
				}
				int num = random.Next(20);
				if (num < 15)
				{
					if (random.Next(10) < 5)
					{
						Object.Instantiate<GameObject>(Wall, new Vector3((float)(m * 6 - 3), Offset, (float)(n * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
					}
					else
					{
						Object.Instantiate<GameObject>(Wall, new Vector3((float)(m * 6), Offset, (float)(n * 6 - 3)), Quaternion.Euler(-90f, 90f, 0f), ((Component)this).transform);
					}
				}
				else if (num == 16)
				{
					Object.Instantiate<GameObject>(Pillar, new Vector3((float)(m * 6), Offset, (float)(n * 6)), Quaternion.Euler(-90f, 0f, 0f), ((Component)this).transform);
				}
				else
				{
					PossibleSpawnPoint.Add(new Vector2((float)(m * 6), (float)(n * 6)));
				}
			}
		}
		if (((NetworkBehaviour)this).IsServer)
		{
			((Component)this).GetComponent<NavMeshSurface>().BuildNavMesh();
			GameObject val3 = Loader.AssetBundle.LoadAsset<GameObject>("assets/backrooms/smile.prefab");
			for (int num2 = 0; num2 < Loader.NumberOfSmilers.Value; num2++)
			{
				Vector2 val4 = PossibleSpawnPoint[Random.Range(0, PossibleSpawnPoint.Count)];
				Object.Instantiate<GameObject>(val3, new Vector3(val4.x, Offset, val4.y), Quaternion.identity, ((Component)this).transform).GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}

	[ServerRpc(RequireOwnership = false)]
	public void TeleportOutOfBackroomsServerRpc(ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: 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_006d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3409688981u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3409688981u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				TeleportOutOfBackroomsClientRpc((int)clientId);
			}
		}
	}

	protected override void __initializeVariables()
	{
		if (SharedOdds == null)
		{
			throw new Exception("Backrooms.SharedOdds cannot be null. All NetworkVariableBase instances must be initialized.");
		}
		((NetworkVariableBase)SharedOdds).Initialize((NetworkBehaviour)(object)this);
		((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)SharedOdds, "SharedOdds");
		base.NetworkVariableFields.Add((NetworkVariableBase)(object)SharedOdds);
		((NetworkBehaviour)this).__initializeVariables();
	}

	[RuntimeInitializeOnLoadMethod]
	internal static void InitializeRPCS_Backrooms()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		NetworkManager.__rpc_func_table.Add(2180494496u, new RpcReceiveHandler(__rpc_handler_2180494496));
		NetworkManager.__rpc_func_table.Add(2541916904u, new RpcReceiveHandler(__rpc_handler_2541916904));
		NetworkManager.__rpc_func_table.Add(3078584200u, new RpcReceiveHandler(__rpc_handler_3078584200));
		NetworkManager.__rpc_func_table.Add(1623403188u, new RpcReceiveHandler(__rpc_handler_1623403188));
		NetworkManager.__rpc_func_table.Add(890432861u, new RpcReceiveHandler(__rpc_handler_890432861));
		NetworkManager.__rpc_func_table.Add(3409688981u, new RpcReceiveHandler(__rpc_handler_3409688981));
	}

	private static void __rpc_handler_2180494496(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0029: 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)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((Backrooms)(object)target).CleanBackroomsClientRpc();
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_2541916904(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int client = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref client);
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((Backrooms)(object)target).TeleportToBackroomsServerRpc(client);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3078584200(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int client = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref client);
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((Backrooms)(object)target).TeleportToBackroomsClientRpc(client);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_1623403188(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int client = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref client);
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((Backrooms)(object)target).TeleportOutOfBackroomsClientRpc(client);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_890432861(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int seed = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref seed);
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((Backrooms)(object)target).GenerateClientRpc(seed);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3409688981(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			ulong clientId = default(ulong);
			ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((Backrooms)(object)target).TeleportOutOfBackroomsServerRpc(clientId);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	protected internal override string __getTypeName()
	{
		return "Backrooms";
	}
}
public class Exit : MonoBehaviour
{
	private void Start()
	{
	}

	private IEnumerator Teleport(ulong playerClientId)
	{
		StartOfRound.Instance.allPlayerScripts[playerClientId].beamOutParticle.Play();
		yield return (object)new WaitForSeconds(3f);
		Backrooms.Instance.TeleportOutOfBackroomsServerRpc(playerClientId);
	}

	private void OnTriggerEnter(Collider other)
	{
		PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
		if ((Object)(object)component != (Object)null)
		{
			((MonoBehaviour)this).StartCoroutine(Teleport(component.playerClientId));
			Backrooms.Instance.TeleportOutOfBackroomsServerRpc(component.playerClientId);
		}
	}
}
public static class Hook
{
	[HarmonyPatch(typeof(KillLocalPlayer), "KillPlayer")]
	[HarmonyPrefix]
	private static bool BeforeKilling(PlayerControllerB playerWhoTriggered)
	{
		if (playerWhoTriggered.isPlayerDead || !playerWhoTriggered.AllowPlayerDeath())
		{
			return true;
		}
		if (((Component)playerWhoTriggered).GetComponent<BackroomsHelper>().HasBeenInTheBackrooms)
		{
			return true;
		}
		Debug.Log((object)$"Killzone {Backrooms.Instance.SharedOdds.Value}");
		if ((float)Random.Range(0, 100) < Backrooms.Instance.SharedOdds.Value)
		{
			Backrooms.Instance.TeleportToBackroomsServerRpc((int)playerWhoTriggered.playerClientId);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
	[HarmonyPrefix]
	private static bool BeforeDamage(PlayerControllerB __instance)
	{
		if (__instance.isPlayerDead || !__instance.AllowPlayerDeath())
		{
			return true;
		}
		if (((Component)__instance).GetComponent<BackroomsHelper>().HasBeenInTheBackrooms)
		{
			return true;
		}
		Debug.Log((object)$"Damage taken {Backrooms.Instance.SharedOdds.Value}");
		if ((float)Random.Range(0, 100) < Backrooms.Instance.SharedOdds.Value)
		{
			Backrooms.Instance.TeleportToBackroomsServerRpc((int)__instance.playerClientId);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Start")]
	[HarmonyPostfix]
	private static void AddComponents(PlayerControllerB __instance)
	{
		((Component)__instance).gameObject.AddComponent<BackroomsHelper>();
	}

	[HarmonyPatch(typeof(RoundManager), "Start")]
	[HarmonyPostfix]
	private static void SpawnBackrooms(RoundManager __instance)
	{
		//IL_0031: 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)
		if (((NetworkBehaviour)__instance).IsServer)
		{
			Debug.Log((object)"Spawning backrooms");
			Object.Instantiate<GameObject>(Loader.AssetBundle.LoadAsset<GameObject>("assets/backrooms/backrooms.prefab"), new Vector3(0f, Backrooms.Offset, 0f), Quaternion.identity).GetComponent<NetworkObject>().Spawn(false);
		}
	}

	[HarmonyPatch(typeof(RoundManager), "UnloadSceneObjectsEarly")]
	[HarmonyPostfix]
	public static void DeleteBackrooms(RoundManager __instance)
	{
		if (((NetworkBehaviour)__instance).IsServer)
		{
			Backrooms.Instance.ServerClean();
		}
	}

	[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
	[HarmonyPrefix]
	public static void GenerateBackrooms(RoundManager __instance)
	{
		if (((NetworkBehaviour)__instance).IsServer)
		{
			Backrooms.Instance.ServerGenerate();
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
	[HarmonyPostfix]
	public static void BackroomsPlayerNote(StartOfRound __instance)
	{
		for (int i = 0; i < __instance.gameStats.allPlayerStats.Length; i++)
		{
			if (__instance.gameStats.allPlayerStats[i].isActivePlayer && ((Component)__instance.allPlayerScripts[i]).GetComponent<BackroomsHelper>().HasBeenInTheBackrooms)
			{
				if (__instance.allPlayerScripts[i].isPlayerDead)
				{
					__instance.gameStats.allPlayerStats[i].playerNotes.Add("Should have been more careful in the Backrooms.");
				}
				else
				{
					__instance.gameStats.allPlayerStats[i].playerNotes.Add("Had a blast in the Backrooms.");
				}
			}
		}
	}

	[HarmonyPatch(typeof(MenuManager), "Start")]
	[HarmonyPostfix]
	public static void NetworkManagerPatch(MenuManager __instance)
	{
		if (!NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs.Select((NetworkPrefab pref) => ((Object)pref.Prefab).name).Contains("backrooms"))
		{
			Debug.Log((object)"Load prefabs to Network Manager");
			string[] array = new string[2] { "assets/backrooms/backrooms.prefab", "assets/backrooms/smile.prefab" };
			foreach (string text in array)
			{
				GameObject val = Loader.AssetBundle.LoadAsset<GameObject>(text);
				NetworkManager.Singleton.AddNetworkPrefab(val);
			}
		}
	}
}
[BepInPlugin("Neekhaulas.Backrooms", "Backrooms", "0.1.3")]
public class Loader : BaseUnityPlugin
{
	public static AssetBundle AssetBundle { get; private set; }

	public static ConfigEntry<float> TeleportationOdds { get; private set; }

	public static ConfigEntry<int> NumberOfSmilers { get; private set; }

	private void Awake()
	{
		TeleportationOdds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Teleportation odds", 3f, "Odds to be teleported (in %) - This settings has to be changed by the host");
		NumberOfSmilers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Number of smilers", 1, "Number of smilers to spawn in the Backrooms - This settings has to be changed by the host");
		AssetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "backrooms"));
		Harmony.CreateAndPatchAll(typeof(Hook), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Backrooms is loaded!");
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		for (int i = 0; i < types.Length; i++)
		{
			MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
				{
					methodInfo.Invoke(null, null);
				}
			}
		}
	}
}
public class SoundPatch : MonoBehaviour
{
	private void Start()
	{
		((Component)this).gameObject.AddComponent<OccludeAudio>();
		((Component)this).GetComponent<AudioSource>().Play();
	}
}
public class Smiler : NetworkBehaviour
{
	private NavMeshAgent NavMeshAgent;

	private PlayerControllerB Target;

	private void Start()
	{
		NavMeshAgent = ((Component)this).GetComponent<NavMeshAgent>();
	}

	private void Update()
	{
		//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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		if (!((NetworkBehaviour)this).IsServer)
		{
			return;
		}
		if ((Object)(object)Target != (Object)null && Target.isPlayerDead)
		{
			Target = null;
			NavMeshAgent.speed = 2f;
		}
		if (!NavMeshAgent.pathPending && NavMeshAgent.remainingDistance <= NavMeshAgent.stoppingDistance)
		{
			if (NavMeshAgent.hasPath)
			{
				Vector3 velocity = NavMeshAgent.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude != 0f)
				{
					goto IL_00f0;
				}
			}
			if ((Object)(object)Target != (Object)null)
			{
				NavMeshAgent.SetDestination(((Component)Target).transform.position);
			}
			else
			{
				int index = Random.Range(0, Backrooms.Instance.PossibleSpawnPoint.Count);
				NavMeshAgent.SetDestination(Vector2.op_Implicit(Backrooms.Instance.PossibleSpawnPoint[index]));
			}
		}
		goto IL_00f0;
		IL_00f0:
		for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
			if (val.isPlayerControlled && !val.isPlayerDead)
			{
				if (val.HasLineOfSightToPosition(((Component)this).transform.position + Vector3.up, 45f, 15, -1f))
				{
					Target = val;
					NavMeshAgent.SetDestination(((Component)val).transform.position);
					NavMeshAgent.speed = 7f;
					break;
				}
				bool flag = false;
				if ((Object)(object)val.currentlyHeldObjectServer != (Object)null && ((object)val.currentlyHeldObjectServer).GetType() == typeof(FlashlightItem) && val.currentlyHeldObjectServer.isBeingUsed)
				{
					flag = true;
				}
				if ((Object)(object)val.pocketedFlashlight != (Object)null && ((object)val.pocketedFlashlight).GetType() == typeof(FlashlightItem) && val.pocketedFlashlight.isBeingUsed)
				{
					flag = true;
				}
				if (flag && val.HasLineOfSightToPosition(((Component)this).transform.position + Vector3.up, 45f, 100, -1f))
				{
					Target = val;
					NavMeshAgent.SetDestination(((Component)val).transform.position);
					NavMeshAgent.speed = 7f;
				}
			}
		}
	}

	protected override void __initializeVariables()
	{
		((NetworkBehaviour)this).__initializeVariables();
	}

	protected internal override string __getTypeName()
	{
		return "Smiler";
	}
}