Decompiled source of JailCellMod v0.4.0

plugins/JailCellMod/7up.JailCellMod.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using 7up.JailCellMod.NetcodePatcher;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LobbyCompatibility.Attributes;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("7up.JailCellMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
[assembly: AssemblyProduct("JailCellMod")]
[assembly: AssemblyTitle("7up.JailCellMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 JailCellMod
{
	internal static class Helper
	{
		public static PlayerControllerB[] ActivePlayers()
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] array = allPlayerScripts;
			foreach (PlayerControllerB val in array)
			{
				if (val.isPlayerControlled)
				{
					list.Add(val);
				}
			}
			return list.ToArray();
		}

		public static PlayerControllerB[] ActivePlayerInShip()
		{
			List<PlayerControllerB> list = ActivePlayers().ToList();
			list.RemoveAll((PlayerControllerB player) => !player.isInHangarShipRoom);
			return list.ToArray();
		}

		public static List<PlayerControllerB> DetectPlayersInCell(Vector3 position)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(1.8f, 2.8f, 1.8f);
			Collider[] array = Physics.OverlapBox(position, val / 2f, Quaternion.identity);
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			Collider[] array2 = array;
			PlayerControllerB item = default(PlayerControllerB);
			foreach (Collider val2 in array2)
			{
				if (((Component)val2).TryGetComponent<PlayerControllerB>(ref item) && !list.Contains(item))
				{
					list.Add(item);
				}
			}
			return list;
		}

		public static int RoundUp(int value, int factor)
		{
			return (value + factor - 1) / factor;
		}
	}
	internal class JailCellController : MonoBehaviour
	{
		public TextMeshProUGUI PlayerNameText;

		public TextMeshProUGUI VoteAmountText;

		public Animator DoorAnimator;

		public AudioSource DoorAudio;

		public InteractTrigger DoorButton;

		public InteractTrigger VoteButton;

		public InteractTrigger SwitchButton;

		private int playerVoteDataIndex;

		private JailCellNetcodeManager jailCellNetcodeManager;

		private float cooldownAmount = 30f;

		private float cooldownTimer = 30f;

		private bool coolingDown;

		private bool canVote = true;

		private Collider voteButtonCollider;

		private Collider doorButtonCollider;

		private Collider switchButtonCollider;

		private void Awake()
		{
			string disabledHoverTip = "Disabled : [In Jail]";
			VoteButton.disabledHoverTip = disabledHoverTip;
			DoorButton.disabledHoverTip = disabledHoverTip;
			SwitchButton.disabledHoverTip = disabledHoverTip;
			voteButtonCollider = ((Component)VoteButton).GetComponent<Collider>();
			doorButtonCollider = ((Component)DoorButton).GetComponent<Collider>();
			switchButtonCollider = ((Component)SwitchButton).GetComponent<Collider>();
		}

		private void Update()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)jailCellNetcodeManager == (Object)null)
			{
				jailCellNetcodeManager = GameObject.Find("JailCellNetcodeManager(Clone)").GetComponent<JailCellNetcodeManager>();
				Debug.LogError((object)"JailCellNetcodeManager instance is null.");
				return;
			}
			List<PlayerControllerB> list = Helper.DetectPlayersInCell(((Component)this).transform.position);
			bool flag = list.Contains(GameNetworkManager.Instance.localPlayerController);
			voteButtonCollider.enabled = !flag;
			doorButtonCollider.enabled = !flag;
			switchButtonCollider.enabled = !flag;
			PlayerVoteData[] playerVoteData = jailCellNetcodeManager.playerVoteData;
			if (playerVoteDataIndex > playerVoteData.Length - 1)
			{
				playerVoteDataIndex = 0;
			}
			if (!VoteButton.interactable && coolingDown)
			{
				cooldownTimer -= Time.deltaTime;
				VoteButton.disabledHoverTip = $"[Cooldown: {(int)cooldownTimer} sec.]";
				if (cooldownTimer <= 0f)
				{
					cooldownTimer = cooldownAmount;
					VoteButton.interactable = true;
					coolingDown = false;
				}
			}
			if (playerVoteData == null || playerVoteData.Length == 0)
			{
				Debug.LogError((object)"playerVoteData is null or empty.");
				return;
			}
			if (flag)
			{
				ShipBuildModeManager.Instance.CancelBuildMode(true);
			}
			if (list.Count >= jailCellNetcodeManager.capacity)
			{
				((Graphic)PlayerNameText).color = Color.red;
				((TMP_Text)PlayerNameText).text = "Maximum Capacity";
				((TMP_Text)VoteAmountText).text = "";
				canVote = false;
				VoteButton.interactable = false;
				VoteButton.disabledHoverTip = "Voting disabled : Maximum capacity";
				return;
			}
			if (!coolingDown)
			{
				VoteButton.interactable = true;
			}
			canVote = true;
			((Graphic)PlayerNameText).color = Color.green;
			string text = $"votes {playerVoteData[playerVoteDataIndex].votes}/{jailCellNetcodeManager.requiredVotes}";
			if (jailCellNetcodeManager.voteTimerEnabled)
			{
				text += $" ({(int)jailCellNetcodeManager.voteResetTimer})";
			}
			((TMP_Text)PlayerNameText).text = playerVoteData[playerVoteDataIndex].playerName ?? "Unknown Player";
			((TMP_Text)VoteAmountText).text = text;
		}

		public void OpenDoor()
		{
			jailCellNetcodeManager.OpenDoorServerRpc();
		}

		public void SwitchPlayer()
		{
			PlayerVoteData[] playerVoteData = jailCellNetcodeManager.playerVoteData;
			if (playerVoteData != null && playerVoteData.Length != 0)
			{
				playerVoteDataIndex = (playerVoteDataIndex + 1) % playerVoteData.Length;
			}
		}

		public void Vote(PlayerControllerB playerPressed)
		{
			if (canVote)
			{
				jailCellNetcodeManager.VoteServerRpc(playerVoteDataIndex);
				VoteButton.interactable = false;
				coolingDown = true;
			}
		}
	}
	[BepInPlugin("7up.JailCellMod", "JailCellMod", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
	public class JailCellMod : BaseUnityPlugin
	{
		public GameObject jailcellNetcodePrefab;

		public static JailCellMod Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			RegisterJailCell();
			NetcodePatcher();
			Patch();
			Logger.LogInfo((object)"7up.JailCellMod v0.4.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("7up.JailCellMod");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			jailcellNetcodePrefab = NetworkPrefabs.CreateNetworkPrefab("JailCellNetcodeManager");
			jailcellNetcodePrefab.AddComponent<JailCellNetcodeManager>();
			((Object)jailcellNetcodePrefab).hideFlags = (HideFlags)0;
		}

		private void RegisterJailCell()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "jailcell");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			UnlockableItem val2 = val.LoadAsset<UnlockablesList>("Assets/JailCell/JailCellList.asset").unlockables[0];
			NetworkPrefabs.RegisterNetworkPrefab(val2.prefabObject);
			Unlockables.RegisterUnlockable(val2, 0, (StoreType)2);
		}
	}
	public class JailCellNetcodeManager : NetworkBehaviour
	{
		private int activePlayersCount;

		private int previousActivePlayersCount;

		private int activePlayersInShipCount;

		private int playersInCellCount;

		private int selectedPlayerIndex;

		private JailCellController jailCellController;

		public int capacity = 1;

		private bool cellFull;

		public PlayerControllerB[] activePlayers { get; private set; }

		public PlayerControllerB selectedPlayer { get; private set; }

		public int requiredVotes { get; private set; }

		public PlayerVoteData[] playerVoteData { get; private set; }

		public bool voteTimerEnabled { get; private set; }

		public float voteResetTimer { get; private set; }

		private void Awake()
		{
			voteResetTimer = 30f;
		}

		private void Update()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)jailCellController == (Object)null)
			{
				jailCellController = GameObject.Find("Jail Cell(Clone)").GetComponent<JailCellController>();
				Debug.LogError((object)"JailCellController instance is null.");
				return;
			}
			activePlayers = Helper.ActivePlayers();
			activePlayersCount = Helper.ActivePlayers().Length;
			activePlayersInShipCount = Helper.ActivePlayerInShip().Length;
			playersInCellCount = Helper.DetectPlayersInCell(((Component)jailCellController).transform.position).Count;
			CalculateRequiredVotes();
			if (playersInCellCount >= activePlayersCount && !cellFull)
			{
				cellFull = true;
				OpenCellDoor();
				((MonoBehaviour)this).StopAllCoroutines();
			}
			if (cellFull && playersInCellCount < activePlayersCount)
			{
				cellFull = false;
				CloseCellDoor();
				((MonoBehaviour)this).StopAllCoroutines();
			}
			if (activePlayers == null || activePlayers.Length == 0)
			{
				Debug.LogError((object)"activePlayers is null or empty.");
				return;
			}
			if (playerVoteData == null || playerVoteData.Length != activePlayersCount)
			{
				InitializePlayerVoteData();
			}
			else
			{
				UpdatePlayerVoteData();
			}
			VoteResetTimer();
		}

		private void UpdatePlayerVoteData()
		{
			for (int i = 0; i < activePlayersCount; i++)
			{
				if ((Object)(object)activePlayers[i] != (Object)null)
				{
					playerVoteData[i].playerName = activePlayers[i].playerUsername ?? "Unknown Player";
				}
			}
		}

		private void CalculateRequiredVotes()
		{
			requiredVotes = activePlayers.Length;
			if (activePlayers.Length > 2)
			{
				requiredVotes = Helper.RoundUp(activePlayers.Length, 2);
			}
		}

		private void VoteResetTimer()
		{
			int num = playerVoteData.Sum((PlayerVoteData data) => data.votes);
			float num2 = 30f;
			if (num > 0 && !voteTimerEnabled)
			{
				voteTimerEnabled = true;
				voteResetTimer = num2;
			}
			if (num <= 0 && voteTimerEnabled)
			{
				ResetVotes();
				voteTimerEnabled = false;
				voteResetTimer = num2;
			}
			if (voteTimerEnabled)
			{
				voteResetTimer -= Time.deltaTime;
				if (voteResetTimer <= 0f)
				{
					ResetVotes();
					voteTimerEnabled = false;
					voteResetTimer = num2;
				}
			}
		}

		private void ResetVotes()
		{
			for (int i = 0; i < playerVoteData.Length; i++)
			{
				playerVoteData[i].votes = 0;
			}
			for (int j = 0; j < playerVoteData.Length; j++)
			{
				VoteClientRpc(j, playerVoteData[j].votes);
			}
		}

		public void InitializePlayerVoteData()
		{
			playerVoteData = new PlayerVoteData[activePlayersCount];
			for (int i = 0; i < activePlayersCount; i++)
			{
				if ((Object)(object)activePlayers[i] != (Object)null)
				{
					playerVoteData[i] = new PlayerVoteData
					{
						playerName = (activePlayers[i].playerUsername ?? "Unknown Player"),
						votes = 0
					};
				}
				else
				{
					Debug.LogWarning((object)$"Active player at index {i} is null.");
					playerVoteData[i] = new PlayerVoteData
					{
						playerName = "Unknown Player",
						votes = 0
					};
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void OpenDoorServerRpc()
		{
			//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)
			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(1788706654u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1788706654u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					OpenDoorClientRpc();
				}
			}
		}

		[ClientRpc]
		private void OpenDoorClientRpc()
		{
			//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)
			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(3569567996u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3569567996u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((Object)(object)jailCellController == (Object)null))
				{
					((MonoBehaviour)this).StartCoroutine(CellDoorCoroutine());
				}
			}
		}

		private IEnumerator CellDoorCoroutine()
		{
			OpenCellDoor();
			yield return (object)new WaitForSeconds(5f);
			CloseCellDoor();
		}

		private void OpenCellDoor()
		{
			if (!((Object)(object)jailCellController == (Object)null))
			{
				jailCellController.DoorAnimator.Play("cell_door_open");
				jailCellController.DoorAudio.pitch = Random.Range(0.8f, 1.2f);
				jailCellController.DoorAudio.Play();
			}
		}

		private void CloseCellDoor()
		{
			if (!((Object)(object)jailCellController == (Object)null))
			{
				jailCellController.DoorAnimator.Play("cell_door_close");
				jailCellController.DoorAudio.pitch = Random.Range(0.8f, 1.2f);
				jailCellController.DoorAudio.Play();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void VoteServerRpc(int playerDataIndex)
		{
			//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)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(113287373u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerDataIndex);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 113287373u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			if (playerDataIndex < 0 || playerDataIndex >= playerVoteData.Length)
			{
				Debug.LogError((object)$"Invalid playerDataIndex: {playerDataIndex}");
				return;
			}
			Debug.Log((object)$"VoteServerRpc called for index: {playerDataIndex}");
			playerVoteData[playerDataIndex].votes++;
			Debug.Log((object)$"Votes after increment: {playerVoteData[playerDataIndex].votes}");
			VoteClientRpc(playerDataIndex, playerVoteData[playerDataIndex].votes);
			if (playerVoteData[playerDataIndex].votes >= requiredVotes)
			{
				ResetVotes();
				TeleportClientRpc(playerDataIndex);
			}
		}

		[ClientRpc]
		private void VoteClientRpc(int playerDataIndex, int votes)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			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(3910042479u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerDataIndex);
					BytePacker.WriteValueBitPacked(val2, votes);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3910042479u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					Debug.Log((object)$"VoteClientRpc received for index: {playerDataIndex}, votes: {votes}");
					playerVoteData[playerDataIndex].votes = votes;
				}
			}
		}

		[ClientRpc]
		public void TeleportClientRpc(int id)
		{
			//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_015f: 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(550850672u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, id);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 550850672u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			PlayerControllerB[] array = Helper.ActivePlayers();
			Debug.Log((object)$"Active Players Count: {array.Length}");
			Debug.Log((object)$"Requested Player ID: {id}");
			if (id < 0 || id >= array.Length)
			{
				Debug.LogError((object)"Player ID is out of range!");
				return;
			}
			PlayerControllerB val3 = array[id];
			if ((Object)(object)val3 == (Object)null)
			{
				Debug.LogError((object)$"Player at index {id} is null!");
				return;
			}
			if ((Object)(object)jailCellController == (Object)null)
			{
				Debug.LogError((object)"jailCellController is null!");
				return;
			}
			val3.DropAllHeldItems(true, false);
			val3.TeleportPlayer(((Component)jailCellController).transform.position, true, 180f, false, true);
			val3.beamUpParticle.Play();
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_JailCellNetcodeManager()
		{
			//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
			NetworkManager.__rpc_func_table.Add(1788706654u, new RpcReceiveHandler(__rpc_handler_1788706654));
			NetworkManager.__rpc_func_table.Add(3569567996u, new RpcReceiveHandler(__rpc_handler_3569567996));
			NetworkManager.__rpc_func_table.Add(113287373u, new RpcReceiveHandler(__rpc_handler_113287373));
			NetworkManager.__rpc_func_table.Add(3910042479u, new RpcReceiveHandler(__rpc_handler_3910042479));
			NetworkManager.__rpc_func_table.Add(550850672u, new RpcReceiveHandler(__rpc_handler_550850672));
		}

		private static void __rpc_handler_1788706654(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)1;
				((JailCellNetcodeManager)(object)target).OpenDoorServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3569567996(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;
				((JailCellNetcodeManager)(object)target).OpenDoorClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_113287373(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 playerDataIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerDataIndex);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((JailCellNetcodeManager)(object)target).VoteServerRpc(playerDataIndex);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3910042479(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerDataIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerDataIndex);
				int votes = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref votes);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((JailCellNetcodeManager)(object)target).VoteClientRpc(playerDataIndex, votes);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_550850672(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 id = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref id);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((JailCellNetcodeManager)(object)target).TeleportClientRpc(id);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "JailCellNetcodeManager";
		}
	}
	public struct PlayerVoteData
	{
		public string playerName;

		public int votes;
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void SpawnNetcodeManager(StartOfRound __instance)
		{
			if (((NetworkBehaviour)__instance).IsHost)
			{
				GameObject val = Object.Instantiate<GameObject>(JailCellMod.Instance.jailcellNetcodePrefab);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "7up.JailCellMod";

		public const string PLUGIN_NAME = "JailCellMod";

		public const string PLUGIN_VERSION = "0.4.0";
	}
}
namespace 7up.JailCellMod.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}