Decompiled source of VeryLateCompany v0.3.0

McBowie.VeryLateCompany.dll

Decompiled 2 months 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 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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("McBowie.VeryLateCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("VeryLateCompany")]
[assembly: AssemblyTitle("McBowie.VeryLateCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[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;
}
[HarmonyPatch(typeof(RoundManager), "SetToCurrentLevelWeather")]
internal static class SetToCurrentLevelWeather_patch
{
	[HarmonyPrefix]
	private static void Prefix()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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);
}
[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);

	[HarmonyPrefix]
	private static bool Prefix(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if ((Object)(object)networkManager != (Object)null && networkManager.IsListening && !networkManager.IsHost)
		{
			try
			{
				int num = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref num);
				int num2 = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref num2);
				int num3 = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref num3);
				int num4 = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref num4);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				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 = default(int);
					ByteUnpacker.ReadValueBitPacked(reader, ref num5);
					num5 -= 255;
					if (num5 < 0)
					{
						num5 = -1;
					}
					WeatherSync.CurrentWeather = (LevelWeatherType)num5;
					WeatherSync.DoOverride = true;
				}
				RPCExecStage.SetValue(target, RpcEnum.Client);
				((RoundManager)((target is RoundManager) ? target : null)).GenerateNewLevelClientRpc(num, num2, num3, num4, array);
				RPCExecStage.SetValue(target, RpcEnum.None);
				return false;
			}
			catch
			{
				WeatherSync.DoOverride = false;
				((FastBufferReader)(ref reader)).Seek(0);
				return true;
			}
		}
		return true;
	}
}
namespace VeryLateCompany
{
	[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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Harmony val = new Harmony("McBowie.VeryLateCompany");
			val.PatchAll(typeof(Plugin).Assembly);
			Logger.LogInfo((object)" VeryLateCompany v0.1.0 has loaded!");
		}

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

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "McBowie.VeryLateCompany";

		public const string PLUGIN_NAME = "VeryLateCompany";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
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_029e: Unknown result type (might be due to invalid IL or missing references)
			string text = HUDManager.Instance.chatTextField.text.Split(' ')[0];
			if ((!HUDManager.Instance.localPlayer.isHostPlayerObject && text != "!help") || !text.StartsWith("!"))
			{
				return;
			}
			text = text.Trim('!');
			if (!commands.Contains(text))
			{
				return;
			}
			switch (text)
			{
			case "allowJoin":
			case "openLobby":
				msg = "Opening the lobby for joining";
				Plugin.SetLobbyJoinable(joinable: true);
				break;
			case "return":
			case "leave":
				msg = "Sending the ship out into orbit";
				StartOfRound.Instance.ShipLeaveAutomatically(false);
				break;
			case "entrance":
			{
				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);
				EntranceTeleport[] array3 = array2;
				foreach (EntranceTeleport val2 in array3)
				{
					if (val2.entranceId == 0 && val2.isEntranceToBuilding)
					{
						val.TeleportPlayer(val2.entrancePoint.position, false, 0f, false, true);
						break;
					}
				}
				break;
			}
			case "noclip":
				msg = (noClipState ? "Disabling" : "Enabling") + " noclip for " + StartOfRound.Instance.localPlayerController.playerUsername;
				noClipState = !noClipState;
				StartOfRound.Instance.localPlayerController.playerCollider.enabled = !noClipState;
				break;
			case "help":
				msg = StartOfRound.Instance.localPlayerController.playerUsername + " needs a teleport";
				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 && ((NetworkBehaviour)__instance).IsHost)
			{
				NoClipMovement();
			}
		}

		private static void NoClipMovement()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0151: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: 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_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			try
			{
				if (((ButtonControl)Keyboard.current.wKey).isPressed)
				{
					Quaternion rotation = ((Component)localPlayerController).transform.rotation;
					Vector3 val = rotation * Vector3.forward;
					((Vector3)(ref val)).Normalize();
					Transform transform = ((Component)localPlayerController).transform;
					transform.position += val * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.aKey).isPressed)
				{
					Quaternion rotation2 = ((Component)localPlayerController).transform.rotation;
					Quaternion val2 = Quaternion.AngleAxis(-90f, Vector3.up);
					Vector3 val3 = val2 * rotation2 * Vector3.forward;
					((Vector3)(ref val3)).Normalize();
					Transform transform2 = ((Component)localPlayerController).transform;
					transform2.position += val3 * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.dKey).isPressed)
				{
					Quaternion rotation3 = ((Component)localPlayerController).transform.rotation;
					Quaternion val4 = Quaternion.AngleAxis(90f, Vector3.up);
					Vector3 val5 = val4 * rotation3 * Vector3.forward;
					((Vector3)(ref val5)).Normalize();
					Transform transform3 = ((Component)localPlayerController).transform;
					transform3.position += val5 * noClipSpeed;
				}
			}
			catch
			{
			}
			try
			{
				if (((ButtonControl)Keyboard.current.sKey).isPressed)
				{
					Quaternion rotation4 = ((Component)localPlayerController).transform.rotation;
					Vector3 val6 = rotation4 * Vector3.back;
					((Vector3)(ref val6)).Normalize();
					Transform transform4 = ((Component)localPlayerController).transform;
					transform4.position += val6 * 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 val7 = -Vector3.up;
					Transform transform6 = ((Component)localPlayerController).transform;
					transform6.position += val7 * noClipSpeed;
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerConnectedClientRpc")]
	[HarmonyWrapSafe]
	internal class OnPlayerConnectedClientRpc_patch
	{
		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;

		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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			PreviousLocation = __instance.allPlayerObjects[assignedPlayerObjectId].transform.position;
		}

		[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_00e0: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected I4, but got Unknown
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			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--;
				}
			}
			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);
				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 });
				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++;
			}
		}

		internal static IEnumerator KillPlayer(PlayerControllerB playerControllerB)
		{
			HUDManager.Instance.DisplayTip("Mid-game join", "You were not alive before reconnecting and will be killed in 5 seconds", true, false, "LC_Tip1");
			yield return (object)new WaitForSeconds(5f);
			playerControllerB.KillPlayer(Vector3.zero, false, (CauseOfDeath)0, 0, default(Vector3));
		}

		internal static IEnumerator TeleportToPreviousLocation(PlayerControllerB playerControllerB)
		{
			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");
			yield return (object)new WaitForSeconds(5f);
			playerControllerB.TeleportPlayer(PreviousLocation, false, 0f, false, true);
			Debug.Log((object)("Teleporting player [" + playerControllerB.playerUsername + "]"));
		}

		[HarmonyPatch("OnClientConnect")]
		[HarmonyPostfix]
		private static void OnClientConnectPatch(ulong clientId)
		{
			isPlayerDead = playerControllerB?.isPlayerDead ?? false;
		}

		[HarmonyPatch(typeof(RoundManager))]
		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPostfix]
		private static void GenerateNewFloorPostfix()
		{
			wasPresentAtGameStart = Object.FindObjectOfType<StartMatchLever>().leverHasBeenPulled;
			if (!wasPresentAtGameStart)
			{
				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);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
	internal class OnPlayerDC_patch
	{
		[HarmonyPrefix]
		private static bool Prefix(StartOfRound __instance, int playerObjectNumber, ulong clientId)
		{
			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 val = Object.FindObjectOfType<QuickMenuManager>();
			if (val != null)
			{
				val.RemoveUserFromPlayerList(playerObjectNumber);
			}
			component.DropAllHeldItems(true, true);
			Plugin.SetLobbyJoinable(joinable: true);
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}