Decompiled source of VeryLateCompany v0.1.4

VeryLateCompany.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using McBowie.VeryLateCompany.VeryLateCompany.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using VeryLateCompany;

[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("VeryLateCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dca9e6e28013239de13a70a82b5822dca5b7e868")]
[assembly: AssemblyProduct("VeryLateCompany")]
[assembly: AssemblyTitle("VeryLateCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
[HarmonyPatch(typeof(GameNetworkManager), "ConnectionApproval")]
[HarmonyWrapSafe]
internal static class ConnectionApproval_patch
{
	[HarmonyPostfix]
	private static void Postfix(ref ConnectionApprovalRequest request, ref ConnectionApprovalResponse response)
	{
		if (request.ClientNetworkId != NetworkManager.Singleton.LocalClientId && response.Reason == "Game has already started!")
		{
			response.Reason = "";
			response.Approved = true;
		}
	}
}
[HarmonyPatch(typeof(QuickMenuManager), "DisableInviteFriendsButton")]
internal static class DisableInviteFriendsButton_patch
{
	[HarmonyPrefix]
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(QuickMenuManager), "InviteFriendsButton")]
internal static class InviteFriendsButton_patch
{
	[HarmonyPrefix]
	private static bool Prefix()
	{
		if (Plugin.LobbyJoinable && !GameNetworkManager.Instance.disableSteam)
		{
			GameNetworkManager.Instance.InviteFriendsUI();
		}
		return false;
	}
}
[HarmonyPatch(typeof(GameNetworkManager), "LeaveLobbyAtGameStart")]
[HarmonyWrapSafe]
internal static class LeaveLobbyAtGameStart_patch
{
	[HarmonyPrefix]
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")]
internal static class OnShipLandedMiscEvents_patch
{
	[HarmonyPostfix]
	private static void Postfix()
	{
		if (Plugin.AllowJoiningWhileLanded && StartOfRound.Instance.connectedPlayersAmount + 1 < StartOfRound.Instance.allPlayerScripts.Length)
		{
			Plugin.SetLobbyJoinable(joinable: true);
		}
	}
}
internal class RpcEnum : NetworkBehaviour
{
	public static int None => 0;

	public static int Client => 2;

	public static int Server => 1;

	public static int Execute => 1;
}
[HarmonyPatch(typeof(RoundManager), "SetToCurrentLevelWeather")]
internal static class SetToCurrentLevelWeather_patch
{
	[HarmonyPrefix]
	private static void Prefix()
	{
		//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)
		if (WeatherSync.DoOverride)
		{
			RoundManager.Instance.currentLevel.currentWeather = WeatherSync.CurrentWeather;
			WeatherSync.DoOverride = false;
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "StartGame")]
internal static class StartGame_patch
{
	[HarmonyPrefix]
	private static void Prefix()
	{
		Plugin.SetLobbyJoinable(joinable: false);
	}

	[HarmonyPostfix]
	private static void Postfix()
	{
		Plugin.SetLobbyJoinable(joinable: true);
	}
}
internal static class WeatherSync
{
	public static bool DoOverride = false;

	public static LevelWeatherType CurrentWeather = (LevelWeatherType)(-1);
}
[HarmonyDebug]
[HarmonyPatch(typeof(RoundManager), "__rpc_handler_3073943002")]
[HarmonyWrapSafe]
internal static class __rpc_handler_3073943002_patch
{
	public static FieldInfo RPCExecStage = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic);

	public static long lastTime = 0L;

	[HarmonyPrefix]
	private static bool Prefix(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_003f: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if ((Object)(object)networkManager != (Object)null && networkManager.IsListening && !networkManager.IsHost && RoundManager_Patch.isMidSessionJoiningRound)
		{
			try
			{
				Debug.Log((object)"Reading level info...");
				int num = 0;
				ByteUnpacker.ReadValueBitPacked(reader, ref num);
				int num2 = 0;
				ByteUnpacker.ReadValueBitPacked(reader, ref num2);
				int num3 = 0;
				ByteUnpacker.ReadValueBitPacked(reader, ref num3);
				int num4 = 0;
				ByteUnpacker.ReadValueBitPacked(reader, ref num4);
				bool flag = false;
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				Debug.Log((object)$"Read end! Level info: Seed: {num},ID: {num2}, MoldIterations: {num3}, ModStartPosition: {num4}, Value5(Unknown value): {flag}");
				int[] array = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array, default(ForPrimitives));
				}
				if (((FastBufferReader)(ref reader)).Position < ((FastBufferReader)(ref reader)).Length)
				{
					int num5 = 0;
					ByteUnpacker.ReadValueBitPacked(reader, ref num5);
					Debug.Log((object)$"Current weather: {num5}");
					num5 -= 255;
					if (num5 < 0)
					{
						num5 = -1;
					}
					WeatherSync.CurrentWeather = (LevelWeatherType)num5;
					WeatherSync.DoOverride = true;
				}
				RoundManager.Instance.currentLevel.currentWeather = WeatherSync.CurrentWeather;
				RPCExecStage.SetValue(target, RpcEnum.Execute);
				((RoundManager)((target is RoundManager) ? target : null)).GenerateNewLevelClientRpc(num, num2, num3, num4, array);
				RPCExecStage.SetValue(target, RpcEnum.None);
				return false;
			}
			catch (Exception e)
			{
				Plugin.LogException(e);
				WeatherSync.DoOverride = false;
				((FastBufferReader)(ref reader)).Seek(0);
				return true;
			}
		}
		return true;
	}
}
namespace McBowie.VeryLateCompany.VeryLateCompany.Patches
{
	internal class RoundManager_Patch
	{
		public static bool isMidSessionJoiningRound;
	}
}
namespace VeryLateCompany
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "McBowie.VeryLateCompany";

		public const string PLUGIN_NAME = "VeryLateCompany";

		public const string PLUGIN_VERSION = "0.1.4";
	}
	[HarmonyDebug]
	[BepInPlugin("McBowie.VeryLateCompany", "VeryLateCompany", "0.1.0")]
	internal class Plugin : BaseUnityPlugin
	{
		public static bool AllowJoiningWhileLanded = true;

		public static bool LobbyJoinable = true;

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


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


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Harmony.DEBUG = true;
			Logger = Logger.CreateLogSource(MetadataHelper.GetMetadata((object)this).Name);
			Instance = this;
			new Harmony("McBowie.VeryLateCompany").PatchAll(typeof(Plugin).Assembly);
			Logger.LogInfo((object)" VeryLateCompany v0.1.0 v73 Fixed has loaded! Restorer : LT_GVE");
			Logger.LogWarning((object)"\n——————————————————————————————————————————\nVeryLateCompany v0.1.4 v73 Fixed by LT_GVE\nThis mod is Decompiled from  McBowie/VeryLateCompany Mod then fixed and re-built it.\n\nJust for fun\nIt maybe has some bugs, but it works fine for me and my friends.\nIf you have any problems, please create an issue on GitHub to let me know.\nDon't forget upload logs and your mod list,so that I can solve the problem more better.\nLink\nhttps://github.com/LTGVE/LC-VeryLateCompany/issues\n—————————————————————————————————————————");
		}

		public static void SetLobbyJoinable(bool joinable)
		{
			LobbyJoinable = joinable;
			GameNetworkManager.Instance.SetLobbyJoinable(joinable);
			QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
			if ((Object)(object)val != (Object)null)
			{
				val.inviteFriendsTextAlpha.alpha = (joinable ? 1f : 0.2f);
			}
		}

		public static void LogException(Exception e)
		{
			Logger.LogError((object)e);
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
}
namespace VeryLateCompany.VeryLateCompany.Patches
{
	public class NetcodeConnectionManager_patch
	{
		public static FieldInfo f_LocalClient = typeof(NetworkConnectionManager).GetField("LocalClient", BindingFlags.Instance | BindingFlags.NonPublic);

		public static MethodInfo m_SetRole = typeof(NetworkClient).GetMethod("SetRole", BindingFlags.Instance | BindingFlags.NonPublic);

		public static FieldInfo f_NetworkManager = typeof(NetworkConnectionManager).GetField("NetworkManager", BindingFlags.Instance | BindingFlags.NonPublic);

		public static FieldInfo f_ConnectedClients = typeof(NetworkConnectionManager).GetField("ConnectedClients", BindingFlags.Instance | BindingFlags.NonPublic);

		public static FieldInfo f_ConnectedClientIds = typeof(NetworkConnectionManager).GetField("ConnectedClientIds", BindingFlags.Instance | BindingFlags.NonPublic);

		public static FieldInfo f_ConnectedClientsList = typeof(NetworkConnectionManager).GetField("ConnectedClientsList", BindingFlags.Instance | BindingFlags.NonPublic);

		public static Type t_clientConnectedMessage = AccessTools.TypeByName("Unity.Netcode.ClientConnectedMessage");

		public static FieldInfo f_MessageManager = typeof(NetworkManager).GetField("MessageManager", BindingFlags.Instance | BindingFlags.NonPublic);

		[HarmonyPatch("AddClient")]
		[HarmonyPrefix]
		public static bool AddClient(NetworkConnectionManager __instance, ulong clientId, ref NetworkClient __result)
		{
			return true;
		}
	}
}
namespace VeryLateCompany.Patches
{
	[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
	internal class ChatCommands
	{
		private static List<string> commands = new List<string> { "allowJoin", "openLobby", "return", "leave", "entrance", "noclip", "help" };

		private static string msg;

		private static bool noClipState = false;

		private static float noClipSpeed = 0.1f;

		[HarmonyPrefix]
		private static void Prefix()
		{
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			string text = HUDManager.Instance.chatTextField.text.Split(' ')[0];
			if (!text.StartsWith("!") || !((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				return;
			}
			text = text.Trim('!');
			if (!commands.Contains(text) || text == null)
			{
				return;
			}
			switch (text.Length)
			{
			case 9:
				switch (text[0])
				{
				default:
					return;
				case 'a':
					if (!(text == "allowJoin"))
					{
						return;
					}
					break;
				case 'o':
					if (!(text == "openLobby"))
					{
						return;
					}
					break;
				}
				msg = "Opening the lobby for joining";
				Plugin.SetLobbyJoinable(joinable: true);
				break;
			case 6:
				switch (text[0])
				{
				default:
					return;
				case 'r':
					break;
				case 'n':
					if (text == "noclip")
					{
						if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
						{
							HUDManager.Instance.DisplayTip("Warning", "Only the host can use this command.", true, false, "LC_Tip1");
							return;
						}
						msg = (noClipState ? "Disabling" : "Enabling") + " noclip for " + StartOfRound.Instance.localPlayerController.playerUsername;
						noClipState = !noClipState;
						StartOfRound.Instance.localPlayerController.playerCollider.enabled = !noClipState;
					}
					return;
				}
				if (!(text == "return"))
				{
					break;
				}
				goto IL_0118;
			case 5:
				if (!(text == "leave"))
				{
					break;
				}
				goto IL_0118;
			case 8:
			{
				if (!(text == "entrance"))
				{
					break;
				}
				string[] array = HUDManager.Instance.chatTextField.text.Split(' ');
				if (array.Length != 2)
				{
					break;
				}
				string name = array[1];
				PlayerControllerB val = Array.Find(StartOfRound.Instance.allPlayerScripts, (PlayerControllerB x) => x.playerUsername == name);
				if ((Object)(object)val == (Object)null)
				{
					HUDManager.Instance.AddTextToChatOnServer("Can't find player: " + name, -1);
					break;
				}
				msg = "Teleporting " + name + " to the building's entrace";
				EntranceTeleport[] array2 = Object.FindObjectsByType<EntranceTeleport>((FindObjectsSortMode)0);
				foreach (EntranceTeleport val2 in array2)
				{
					if (val2.entranceId == 0 && val2.isEntranceToBuilding)
					{
						GameNetworkManager.Instance.localPlayerController.TeleportPlayer(val2.entrancePoint.position, false, 0f, false, true);
						GameNetworkManager.Instance.localPlayerController.isInElevator = false;
						GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom = false;
						GameNetworkManager.Instance.localPlayerController.isInsideFactory = false;
						val2.TeleportPlayerServerRpc((int)val.playerClientId);
						break;
					}
				}
				break;
			}
			case 4:
				if (text == "help")
				{
					msg = StartOfRound.Instance.localPlayerController.playerUsername + " needs a teleport";
				}
				break;
			case 7:
				break;
				IL_0118:
				msg = "Sending the ship out into orbit";
				StartOfRound.Instance.ShipLeaveAutomatically(false);
				break;
			}
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			if (!(msg == string.Empty))
			{
				HUDManager.Instance.AddTextToChatOnServer(msg, -1);
				msg = string.Empty;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(PlayerControllerB __instance)
		{
			if (noClipState)
			{
				NoClipMovement();
			}
		}

		private static void NoClipMovement()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			try
			{
				if (((ButtonControl)Keyboard.current.wKey).isPressed)
				{
					Vector3 val = ((Component)localPlayerController).transform.rotation * Vector3.forward;
					Transform transform = ((Component)localPlayerController).transform;
					transform.position += val * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.aKey).isPressed)
				{
					Quaternion rotation = ((Component)localPlayerController).transform.rotation;
					Vector3 val2 = Quaternion.AngleAxis(-90f, Vector3.up) * rotation * Vector3.forward;
					Transform transform2 = ((Component)localPlayerController).transform;
					transform2.position += val2 * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.dKey).isPressed)
				{
					Quaternion rotation2 = ((Component)localPlayerController).transform.rotation;
					Vector3 val3 = Quaternion.AngleAxis(90f, Vector3.up) * rotation2 * Vector3.forward;
					Transform transform3 = ((Component)localPlayerController).transform;
					transform3.position += val3 * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.sKey).isPressed)
				{
					Vector3 val4 = ((Component)localPlayerController).transform.rotation * Vector3.back;
					Transform transform4 = ((Component)localPlayerController).transform;
					transform4.position += val4 * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.spaceKey).isPressed)
				{
					Vector3 up = Vector3.up;
					Transform transform5 = ((Component)localPlayerController).transform;
					transform5.position += up * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (Keyboard.current.ctrlKey.isPressed)
				{
					Vector3 val5 = -Vector3.up;
					Transform transform6 = ((Component)localPlayerController).transform;
					transform6.position += val5 * noClipSpeed;
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyDebug]
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerConnectedClientRpc")]
	[HarmonyWrapSafe]
	internal class OnPlayerConnectedClientRpc_patch
	{
		[CompilerGenerated]
		private sealed class <KillPlayer>d__17 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PlayerControllerB playerControllerB;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <KillPlayer>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Expected O, but got Unknown
				//IL_0058: 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_0068: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					HUDManager.Instance.DisplayTip("Mid-game join", "You were not alive before reconnecting and will be killed in 5 seconds", true, false, "LC_Tip1");
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					playerControllerB.KillPlayer(Vector3.zero, false, (CauseOfDeath)0, 0, default(Vector3));
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <TeleportToPreviousLocation>d__18 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PlayerControllerB playerControllerB;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <TeleportToPreviousLocation>d__18(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Expected O, but got Unknown
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					Debug.Log((object)("Waiting to teleport player: [" + playerControllerB.playerUsername + "]"));
					HUDManager.Instance.DisplayTip("Mid-game join", "You will be teleported back to your disconnect position in 5 seconds", true, false, "LC_Tip1");
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					playerControllerB.TeleportPlayer(PreviousLocation, false, 0f, false, true);
					Debug.Log((object)("Teleporting player [" + playerControllerB.playerUsername + "]"));
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static FieldInfo RPCExecStage = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo beginSendClientRpcMethod = typeof(NetworkBehaviour).GetMethod("__beginSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo endSendClientRpcMethod = typeof(NetworkBehaviour).GetMethod("__endSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);

		internal static Vector3 PreviousLocation = Vector3.zero;

		private static PlayerControllerB playerControllerB;

		private static GameObject playerObject;

		private static bool isPlayerDead = false;

		private static int playerObjectID = 1;

		private static StartOfRound startOfRound;

		private static bool wasPresentAtGameStart = false;

		public static StartOfRound StartOfRoundInstance = null;

		public static bool isClient = false;

		public static ulong currentClientId = 0uL;

		internal static void UpdateControlledState()
		{
			for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++)
			{
				if ((i == 0 || !((NetworkBehaviour)StartOfRound.Instance.allPlayerScripts[i]).IsOwnedByServer) && !StartOfRound.Instance.allPlayerScripts[i].isPlayerDead)
				{
					StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled = true;
				}
			}
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (!flag3)
				{
					if (!flag && instruction.opcode == OpCodes.Call && instruction.operand != null && instruction.operand.ToString() == "System.Collections.IEnumerator setPlayerToSpawnPosition(UnityEngine.Transform, UnityEngine.Vector3)")
					{
						flag = true;
					}
					else
					{
						if (flag && instruction.opcode == OpCodes.Ldc_I4_0)
						{
							flag2 = true;
							continue;
						}
						if (flag2 && instruction.opcode == OpCodes.Ldloc_0)
						{
							flag2 = false;
							flag3 = true;
							list.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OnPlayerConnectedClientRpc_patch), "UpdateControlledState", new Type[0], (Type[])null)));
						}
					}
				}
				if (!flag2)
				{
					list.Add(instruction);
				}
			}
			if (!flag3)
			{
				Debug.LogError((object)"Failed to transpile StartOfRound::OnPlayerConnectedClientRpc");
			}
			return list.AsEnumerable();
		}

		[HarmonyPrefix]
		private static void Prefix(StartOfRound __instance, ulong clientId, int connectedPlayers, ulong[] connectedPlayerIdsOrdered, int assignedPlayerObjectId, int serverMoneyAmount, int levelID, int profitQuota, int timeUntilDeadline, int quotaFulfilled, int randomSeed)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			PreviousLocation = __instance.allPlayerObjects[assignedPlayerObjectId].transform.position;
			Debug.Log((object)$"Player joined. last location: {PreviousLocation}");
		}

		[HarmonyPostfix]
		private static void Postfix(StartOfRound __instance, ulong clientId, int connectedPlayers, ulong[] connectedPlayerIdsOrdered, int assignedPlayerObjectId, int serverMoneyAmount, int levelID, int profitQuota, int timeUntilDeadline, int quotaFulfilled, int randomSeed)
		{
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected I4, but got Unknown
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Expected I4, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Debug.Log((object)$"Player is connected with ID: {clientId} has connected players: {connectedPlayers} and assigned player object ID: {assignedPlayerObjectId}");
				StartOfRoundInstance = __instance;
				startOfRound = __instance;
				playerObjectID = assignedPlayerObjectId;
				if (__instance.connectedPlayersAmount + 1 >= __instance.allPlayerScripts.Length)
				{
					Plugin.SetLobbyJoinable(joinable: false);
				}
				playerControllerB = __instance.allPlayerScripts[assignedPlayerObjectId];
				playerObject = __instance.allPlayerObjects[assignedPlayerObjectId];
				playerControllerB.DisablePlayerModel(__instance.allPlayerObjects[assignedPlayerObjectId], true, true);
				__instance.livingPlayers = __instance.connectedPlayersAmount + 1;
				for (int i = 0; i < __instance.allPlayerScripts.Length; i++)
				{
					PlayerControllerB val = __instance.allPlayerScripts[i];
					if (val.isPlayerControlled && val.isPlayerDead)
					{
						__instance.livingPlayers--;
					}
				}
				Debug.Log((object)$"inShipPhase: {__instance.inShipPhase}");
				if (((NetworkBehaviour)__instance).IsServer && !__instance.inShipPhase)
				{
					RoundManager instance = RoundManager.Instance;
					ClientRpcParams val2 = default(ClientRpcParams);
					val2.Send = new ClientRpcSendParams
					{
						TargetClientIds = new List<ulong> { clientId }
					};
					ClientRpcParams val3 = val2;
					uint num = 3073943002u;
					FastBufferWriter val4 = (FastBufferWriter)beginSendClientRpcMethod.Invoke(instance, new object[3] { num, val3, 0 });
					BytePacker.WriteValueBitPacked(val4, __instance.randomMapSeed);
					BytePacker.WriteValueBitPacked(val4, __instance.currentLevelID);
					BytePacker.WriteValueBitPacked(val4, __instance.currentLevel.moldSpreadIterations);
					BytePacker.WriteValueBitPacked(val4, __instance.currentLevel.moldStartPosition);
					Debug.Log((object)$"Sending Level Info to client: Seed : {__instance.randomMapSeed} Level ID: {__instance.currentLevelID} Mold Spread Iterations: {__instance.currentLevel.moldSpreadIterations} Mold Start Position: {__instance.currentLevel.moldStartPosition}");
					MoldSpreadManager val5 = Object.FindObjectOfType<MoldSpreadManager>();
					bool flag = (Object)(object)val5 != (Object)null;
					((FastBufferWriter)(ref val4)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
					if (flag)
					{
						((FastBufferWriter)(ref val4)).WriteValueSafe<int>(val5.planetMoldStates[StartOfRound.Instance.currentLevelID].destroyedMold.ToArray(), default(ForPrimitives));
					}
					BytePacker.WriteValueBitPacked(val4, instance.currentLevel.currentWeather + 255);
					endSendClientRpcMethod.Invoke(instance, new object[4] { val4, num, val3, 0 });
					uint num2 = 2729232387u;
					FastBufferWriter val6 = (FastBufferWriter)beginSendClientRpcMethod.Invoke(instance, new object[3] { num2, val3, 0 });
					Debug.Log((object)("Sending weather to client: " + (instance.currentLevel.currentWeather + 255)));
					endSendClientRpcMethod.Invoke(instance, new object[4] { val6, num2, val3, 0 });
				}
				if (NetworkManager.Singleton.LocalClientId != clientId && !__instance.inShipPhase)
				{
					__instance.livingPlayers++;
					StartOfRound playersManager = __instance.allPlayerScripts[0].playersManager;
					playersManager.livingPlayers++;
				}
				if (((NetworkBehaviour)__instance).IsClient && NetworkManager.Singleton.LocalClientId == clientId)
				{
					RoundManager_Patch.isMidSessionJoiningRound = !StartOfRoundInstance.inShipPhase;
				}
			}
			catch (Exception e)
			{
				Plugin.LogException(e);
			}
		}

		[IteratorStateMachine(typeof(<KillPlayer>d__17))]
		internal static IEnumerator KillPlayer(PlayerControllerB playerControllerB)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <KillPlayer>d__17(0)
			{
				playerControllerB = playerControllerB
			};
		}

		[IteratorStateMachine(typeof(<TeleportToPreviousLocation>d__18))]
		internal static IEnumerator TeleportToPreviousLocation(PlayerControllerB playerControllerB)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TeleportToPreviousLocation>d__18(0)
			{
				playerControllerB = playerControllerB
			};
		}

		[HarmonyPatch("OnClientConnect")]
		[HarmonyPostfix]
		private static void OnClientConnectPatch(ulong clientId)
		{
			Debug.Log((object)$"Client {clientId} has connected");
			isPlayerDead = playerControllerB?.isPlayerDead ?? false;
		}

		[HarmonyPatch(typeof(RoundManager))]
		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPostfix]
		private static void GenerateNewFloorPostfix(RoundManager __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			wasPresentAtGameStart = Object.FindObjectOfType<StartMatchLever>().leverHasBeenPulled;
			if (!wasPresentAtGameStart && PreviousLocation != Vector3.zero)
			{
				Debug.Log((object)$"Previous location: {PreviousLocation}");
				IEnumerator enumerator = TeleportToPreviousLocation(startOfRound.allPlayerScripts[playerObjectID]);
				if (!isPlayerDead)
				{
					((MonoBehaviour)startOfRound).StartCoroutine(enumerator);
					return;
				}
				StartOfRound obj = startOfRound;
				obj.livingPlayers++;
				enumerator = KillPlayer(startOfRound.allPlayerScripts[playerObjectID]);
				((MonoBehaviour)startOfRound).StartCoroutine(enumerator);
				startOfRound.allPlayerScripts[playerObjectID].DisablePlayerModel(playerObject, false, false);
			}
		}
	}
	[HarmonyDebug]
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
	internal class OnPlayerDC_patch
	{
		[HarmonyPrefix]
		private static bool Prefix(StartOfRound __instance, int playerObjectNumber, ulong clientId)
		{
			if (clientId == OnPlayerConnectedClientRpc_patch.currentClientId && !NetworkManager.Singleton.IsServer)
			{
				Debug.Log((object)$"OnPlayerDC: Local client is disconnecting currentClientId: {OnPlayerConnectedClientRpc_patch.currentClientId} and clientId: {clientId}");
				OnPlayerConnectedClientRpc_patch.isClient = false;
				RoundManager_Patch.isMidSessionJoiningRound = false;
			}
			Debug.Log((object)"Calling OnPlayerDC!");
			if (!__instance.ClientPlayerList.ContainsKey(clientId))
			{
				Debug.Log((object)"disconnect: clientId key already removed!");
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && clientId == GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				Debug.Log((object)"OnPlayerDC: Local client is disconnecting so return.");
				return false;
			}
			if (((NetworkBehaviour)__instance).NetworkManager.ShutdownInProgress || (Object)(object)NetworkManager.Singleton == (Object)null)
			{
				Debug.Log((object)"Shutdown is in progress, returning");
				return false;
			}
			Debug.Log((object)"Player DC'ing 2");
			if (((NetworkBehaviour)__instance).IsServer && __instance.ClientPlayerList.TryGetValue(clientId, out var value))
			{
				HUDManager.Instance.AddTextToChatOnServer($"[playerNum{__instance.allPlayerScripts[value].playerClientId}] disconnected.", -1);
			}
			if (!__instance.allPlayerScripts[playerObjectNumber].isPlayerDead)
			{
				__instance.livingPlayers--;
			}
			__instance.ClientPlayerList.Remove(clientId);
			__instance.connectedPlayersAmount--;
			Debug.Log((object)"Player DC'ing 3");
			PlayerControllerB component = __instance.allPlayerObjects[playerObjectNumber].GetComponent<PlayerControllerB>();
			component.sentPlayerValues = false;
			component.isPlayerControlled = false;
			if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
			{
				HUDManager.Instance.UpdateBoxesSpectateUI();
			}
			if (!NetworkManager.Singleton.ShutdownInProgress && ((NetworkBehaviour)__instance).IsServer)
			{
				((Component)component).gameObject.GetComponent<NetworkObject>().RemoveOwnership();
			}
			QuickMenuManager obj = Object.FindObjectOfType<QuickMenuManager>();
			if (obj != null)
			{
				obj.RemoveUserFromPlayerList(playerObjectNumber);
			}
			component.DropAllHeldItems(true, true);
			Plugin.SetLobbyJoinable(joinable: true);
			component.DisablePlayerModel(OnPlayerConnectedClientRpc_patch.StartOfRoundInstance.allPlayerObjects[playerObjectNumber], false, false);
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}