Decompiled source of BiggerLobby v2.7.0

BepInEx/plugins/BiggerLobby.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BiggerLobby.Models;
using BiggerLobby.Patches;
using BiggerLobby.UI;
using Dissonance.Audio.Playback;
using GameNetcodeStuff;
using HarmonyLib;
using LC_API.ServerAPI;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
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("BiggerLobby")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Increase the max players to 50 in Lethal Company")]
[assembly: AssemblyFileVersion("2.7.0.0")]
[assembly: AssemblyInformationalVersion("2.7.0")]
[assembly: AssemblyProduct("BiggerLobby")]
[assembly: AssemblyTitle("BiggerLobby")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.7.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;
		}
	}
}
namespace BiggerLobby
{
	public static class Helper
	{
		public static T[] ResizeArray<T>(T[] oldArray, int newSize)
		{
			if (oldArray.Length >= newSize)
			{
				return oldArray;
			}
			T[] array = new T[newSize];
			oldArray.CopyTo(array, 0);
			return array;
		}

		public static void ResizeList<T>(this List<T> list, int size, T element = default(T))
		{
			int count = list.Count;
			if (size < count)
			{
				list.RemoveRange(size, count - size);
			}
			else if (size > count)
			{
				if (size > list.Capacity)
				{
					list.Capacity = size;
				}
				list.AddRange(Enumerable.Repeat(element, size - count));
			}
		}
	}
	[BepInPlugin("BiggerLobby", "BiggerLobby", "2.7.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		public static bool oldhastime;

		public static int MaxPlayers = 16;

		public static bool instantiating;

		public static NetworkObject[] PlayerObjects = (NetworkObject[])(object)new NetworkObject[0];

		public static Harmony _harmony;

		public static Harmony _harmony2;

		public static ConfigEntry<int>? _LoudnessMultiplier;

		public static bool Initialized = false;

		public static IDictionary<uint, NetworkObject> CustomNetObjects = new Dictionary<uint, NetworkObject>();

		internal static ManualLogSource? Logger { get; set; }

		private void Awake()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			Instance = this;
			_LoudnessMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Player loudness", 1, "Default player loudness");
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("BiggerLobby");
			_harmony2 = new Harmony("BiggerLobbyA");
			_harmony.PatchAll(typeof(NonGamePatches));
			_harmony.PatchAll(typeof(NonGamePatches.InternalPatches));
			_harmony.PatchAll(typeof(NonGamePatches.InternalPatches2));
			CustomNetObjects.Clear();
			_harmony2.PatchAll(typeof(ChatPatches));
			_harmony2.PatchAll(typeof(ListSizeTranspilers));
			_harmony2.PatchAll(typeof(PlayerObjects));
			Logger.LogInfo((object)"BiggerLobby loaded");
		}

		private void Start()
		{
			Initialize();
		}

		private void OnDestroy()
		{
			Initialize();
		}

		private void Initialize()
		{
			if (!Initialized)
			{
				Initialized = true;
				ModdedServer.SetServerModdedOnly();
			}
		}

		public static int GetPlayerCount()
		{
			return MaxPlayers;
		}

		public static int GetPlayerCountMinusOne()
		{
			return MaxPlayers - 1;
		}

		public static PlayerControllerB[] GetRealPlayerScripts(StartOfRound startOfRound)
		{
			if ((Object)(object)startOfRound == (Object)null || startOfRound.allPlayerScripts == null)
			{
				return (PlayerControllerB[])(object)new PlayerControllerB[0];
			}
			return startOfRound.allPlayerScripts.Where((PlayerControllerB x) => x.isPlayerDead || x.isPlayerControlled).ToArray();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BiggerLobby";

		public const string PLUGIN_NAME = "BiggerLobby";

		public const string PLUGIN_VERSION = "2.7.0";
	}
}
namespace BiggerLobby.UI
{
	public class ExpandedStatsUI : MonoBehaviour
	{
		private bool _initialized;

		private bool _debugStatsUI;

		private static StatsUIReferences? _statsUIReferences;

		private PlayerStatsList _fourPlayersList;

		private PlayerStatsList _eightPlayersList;

		private PlayerStatsList _moreThanEightPlayersList;

		private List<GameObject> _moreThanEightPlayersPages = new List<GameObject>();

		public int UpperPlayerLimit = 40;

		public float SecondsPanelVisible = 8.5f;

		private Sprite FourPlayerStatBoxes;

		private Sprite EightPlayerStatBoxes;

		private void Start()
		{
			if (!_initialized)
			{
				if (_debugStatsUI)
				{
					DebugStats();
				}
				SetupFourPlayerSlots();
				SetupEightPlayerSlots();
				SetupMoreThanEightPlayersSlots();
				EightPlayerStatBoxes = _statsUIReferences.StatsBoxesThin;
				FourPlayerStatBoxes = ((Component)((Component)this).transform.GetChild(1)).GetComponent<Image>().sprite;
				((Component)this).transform.GetChild(2).Find("AllDead").SetAsLastSibling();
				_initialized = true;
			}
		}

		private void DebugStats()
		{
			((Behaviour)((Component)this).gameObject.GetComponent<Animator>()).enabled = false;
			((Component)((Component)this).transform.GetChild(0)).GetComponent<CanvasGroup>().alpha = 1f;
			((Component)((Component)this).transform.GetChild(1)).GetComponent<CanvasGroup>().alpha = 1f;
			((Component)((Component)this).transform.GetChild(2)).GetComponent<CanvasGroup>().alpha = 1f;
			((Component)((Component)this).transform.GetChild(2).Find("AllDead")).gameObject.SetActive(false);
		}

		private void SetupFourPlayerSlots()
		{
			_fourPlayersList = new PlayerStatsList(CreateTransformAtParentOrigin("FourPlayersList", ((Component)this).transform.GetChild(2)));
			for (int i = 0; i < 4; i++)
			{
				Transform val = ((Component)this).transform.GetChild(2).Find($"PlayerSlot{i + 1}");
				val.SetParent(_fourPlayersList.transform);
				_fourPlayersList.AddPlayerSlotTransform(val);
			}
		}

		private void SetupEightPlayerSlots()
		{
			_eightPlayersList = new PlayerStatsList(CreateTransformAtParentOrigin("EightPlayersList", ((Component)this).transform.GetChild(2)));
			List<Transform> playerSlots = SetupEightPlayerPage(_eightPlayersList.transform);
			_eightPlayersList.AddPlayerSlotTransforms(playerSlots);
		}

		private void SetupMoreThanEightPlayersSlots()
		{
			_moreThanEightPlayersList = new PlayerStatsList(CreateTransformAtParentOrigin("MoreThanEightPlayersList", ((Component)this).transform.GetChild(2)));
			int num = (int)Math.Ceiling((float)UpperPlayerLimit / 8f);
			for (int i = 0; i < num; i++)
			{
				Transform val = CreateTransformAtParentOrigin($"Page{i}", _moreThanEightPlayersList.transform);
				_moreThanEightPlayersPages.Add(((Component)val).gameObject);
				List<Transform> playerSlots = SetupEightPlayerPage(val);
				_moreThanEightPlayersList.AddPlayerSlotTransforms(playerSlots);
				if (i != 0)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		private List<Transform> SetupEightPlayerPage(Transform parent)
		{
			//IL_002c: 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)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> list = new List<Transform>();
			for (int i = 0; i < 8; i++)
			{
				Transform val = Object.Instantiate<Transform>(_fourPlayersList.transform.GetChild(0), parent, true);
				SetupPlayerSlot(val);
				val.localPosition = new Vector3(val.localPosition.x, -26.1f * (float)i, val.localPosition.z);
				list.Add(val);
			}
			return list;
		}

		private void SetupPlayerSlot(Transform playerSlot)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI component = ((Component)playerSlot.Find("Notes")).GetComponent<TextMeshProUGUI>();
			TextMeshProUGUI component2 = ((Component)playerSlot.GetChild(0)).GetComponent<TextMeshProUGUI>();
			RectTransform component3 = ((Component)component2).GetComponent<RectTransform>();
			Image component4 = ((Component)playerSlot.GetChild(1)).GetComponent<Image>();
			RectTransform component5 = ((Component)component4).GetComponent<RectTransform>();
			((TMP_Text)component).text = "* Most lazy employee\n* Most paranoid employee\n* Sustained the most injuries";
			((TMP_Text)component).fontSize = 9f;
			((TMP_Text)component2).text = "CrazyDude12WW";
			((Transform)component3).localPosition = new Vector3(((Transform)component3).localPosition.x, 101.5f, ((Transform)component3).localPosition.z);
			component4.sprite = _statsUIReferences.CheckmarkThin;
			component5.sizeDelta = new Vector2(component5.sizeDelta.x, 31.235f);
			((Transform)component5).localPosition = new Vector3(((Transform)component5).localPosition.x, 101.5f, ((Transform)component5).localPosition.z);
		}

		private Transform CreateTransformAtParentOrigin(string name, Transform parent)
		{
			//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = new GameObject(name).transform;
			transform.SetParent(parent);
			transform.localPosition = Vector3.zero;
			transform.localRotation = Quaternion.identity;
			transform.localScale = Vector3.one;
			return transform;
		}

		public void LoadStatsUIBundle()
		{
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Join((ReadOnlySpan<char>)Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location), (ReadOnlySpan<char>)"statsuireferences"));
			_statsUIReferences = obj.LoadAsset<GameObject>("assets/prefabs/statsuireferences.prefab").GetComponent<StatsUIReferences>();
			obj.Unload(false);
		}

		public PlayerStatsList GetStatsListFromPlayerCount(int playerCount)
		{
			_fourPlayersList.gameObject.SetActive(false);
			_eightPlayersList.gameObject.SetActive(false);
			_moreThanEightPlayersList.gameObject.SetActive(false);
			PlayerStatsList playerStatsList = _fourPlayersList;
			if (playerCount > 8)
			{
				playerStatsList = _moreThanEightPlayersList;
			}
			else if (playerCount > 4)
			{
				playerStatsList = _eightPlayersList;
			}
			SetupStatsList(playerStatsList, playerCount);
			return playerStatsList;
		}

		private void SetupStatsList(PlayerStatsList playerStatsList, int playerCount)
		{
			playerStatsList.gameObject.SetActive(true);
			((Component)((Component)this).transform.GetChild(1)).GetComponent<Image>().sprite = ((playerCount <= 4) ? FourPlayerStatBoxes : EightPlayerStatBoxes);
			if (playerCount > 8)
			{
				((MonoBehaviour)this).StartCoroutine(PaginatePlayers(playerCount));
			}
			for (int i = 0; i < playerStatsList.Names.Count; i++)
			{
				((TMP_Text)playerStatsList.Names[i]).text = "";
				((TMP_Text)playerStatsList.Notes[i]).text = "";
				((Behaviour)playerStatsList.States[i]).enabled = false;
			}
		}

		private IEnumerator PaginatePlayers(int playerCount)
		{
			int maxPageCount = (int)Math.Ceiling((float)playerCount / 8f);
			float pageDuration = SecondsPanelVisible / (float)maxPageCount;
			foreach (GameObject moreThanEightPlayersPage in _moreThanEightPlayersPages)
			{
				moreThanEightPlayersPage.SetActive(false);
			}
			for (int i = 0; i < maxPageCount; i++)
			{
				_moreThanEightPlayersPages[i].SetActive(true);
				if (i > 0)
				{
					_moreThanEightPlayersPages[i - 1].SetActive(false);
				}
				yield return (object)new WaitForSeconds(pageDuration);
			}
		}

		public static ExpandedStatsUI GetFromAnimator(Animator endgameStatsAnimator)
		{
			ExpandedStatsUI result = default(ExpandedStatsUI);
			if (((Component)endgameStatsAnimator).TryGetComponent<ExpandedStatsUI>(ref result))
			{
				return result;
			}
			ExpandedStatsUI expandedStatsUI = ((Component)endgameStatsAnimator).gameObject.AddComponent<ExpandedStatsUI>();
			if ((Object)(object)_statsUIReferences == (Object)null)
			{
				expandedStatsUI.LoadStatsUIBundle();
			}
			return expandedStatsUI;
		}

		public static Sprite? GetReplacementCheckmark()
		{
			return _statsUIReferences?.CheckmarkThin;
		}
	}
}
namespace BiggerLobby.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class ChatPatches
	{
		private static MethodInfo TargetMethod()
		{
			return typeof(HUDManager).GetMethod("AddChatMessage", BindingFlags.Instance | BindingFlags.NonPublic);
		}

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_003d: 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_005d: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			ConstructorInfo constructorInfo = AccessTools.Constructor(typeof(StringBuilder), new Type[1] { typeof(string) }, false);
			MethodInfo methodInfo = AccessTools.Method(typeof(ChatPatches), "ApplyCustomPlayerNumber", (Type[])null, (Type[])null);
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Newobj, (object)constructorInfo, (string)null)
			}).ThrowIfInvalid("Unable to find StringBuilder constructor.").Advance(1)
				.Insert((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Callvirt, (object)methodInfo)
				})
				.InstructionEnumeration();
		}

		public static StringBuilder ApplyCustomPlayerNumber(StringBuilder stringBuilder)
		{
			PlayerControllerB[] realPlayerScripts = Plugin.GetRealPlayerScripts(StartOfRound.Instance);
			if (realPlayerScripts == null)
			{
				return stringBuilder;
			}
			for (int i = 4; i < realPlayerScripts.Length; i++)
			{
				if (realPlayerScripts[i]?.playerUsername != null)
				{
					stringBuilder.Replace($"[playerNum{i}]", realPlayerScripts[i].playerUsername);
				}
			}
			return stringBuilder;
		}
	}
	[HarmonyPatch]
	public class ListSizeTranspilers
	{
		private static MethodInfo _playerCountMethod = AccessTools.Method(typeof(Plugin), "GetPlayerCount", (Type[])null, (Type[])null);

		private static MethodInfo _playerCountMinusOneMethod = AccessTools.Method(typeof(Plugin), "GetPlayerCountMinusOne", (Type[])null, (Type[])null);

		private static MethodInfo _realPlayerScriptsMethod = AccessTools.Method(typeof(Plugin), "GetRealPlayerScripts", (Type[])null, (Type[])null);

		private static void CheckAndReplace(List<CodeInstruction> codes, int index)
		{
			if (codes[index].opcode == OpCodes.Ldc_I4_4)
			{
				codes[index].opcode = OpCodes.Call;
				codes[index].operand = _playerCountMethod;
			}
		}

		[HarmonyPatch(typeof(HUDManager), "SyncAllPlayerLevelsServerRpc", new Type[] { })]
		[HarmonyPatch(typeof(DressGirlAI), "ChoosePlayerToHaunt")]
		[HarmonyPatch(typeof(CrawlerAI), "Start")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> SyncLevelsRpc(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Newarr)
				{
					CheckAndReplace(list, i - 1);
				}
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SendNewPlayerValuesServerRpc")]
		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
		[HarmonyPatch(typeof(DressGirlAI), "ChoosePlayerToHaunt")]
		[HarmonyPatch(typeof(EnemyAI), "GetClosestPlayer")]
		[HarmonyPatch(typeof(SpringManAI), "DoAIInterval")]
		[HarmonyPatch(typeof(SpringManAI), "Update")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> SendNewPlayerValuesServerRpc(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Blt)
				{
					CheckAndReplace(list, i - 1);
				}
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch(typeof(QuickMenuManager), "ConfirmKickUserFromServer")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> ConfirmKickUserFromServer(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_3)
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = _playerCountMinusOneMethod;
					break;
				}
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> FillEndGameStatsPatch(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "allPlayerScripts")
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = _realPlayerScriptsMethod;
				}
			}
			return list.Where((CodeInstruction x) => x.opcode != OpCodes.Nop).AsEnumerable();
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesServerRpc")]
		[HarmonyPatch(typeof(StartOfRound), "OnClientConnect")]
		[HarmonyPatch(typeof(PlayerControllerB), "SpectateNextPlayer")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> SyncShipUnlockablesServerRpc(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_4)
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = _playerCountMethod;
				}
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch]
	public class NonGamePatches
	{
		[HarmonyPatch(typeof(GameNetworkManager))]
		internal class InternalPatches
		{
			private static MethodInfo TargetMethod()
			{
				return typeof(GameNetworkManager).GetMethod("ConnectionApproval", BindingFlags.Instance | BindingFlags.NonPublic);
			}

			[HarmonyPrefix]
			private static bool PostFix(GameNetworkManager __instance, ConnectionApprovalRequest request, ConnectionApprovalResponse response)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: 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)
				Debug.Log((object)("Connection approval callback! Game version of client request: " + Encoding.ASCII.GetString(request.Payload).ToString()));
				Debug.Log((object)$"Joining client id: {request.ClientNetworkId}; Local/host client id: {NetworkManager.Singleton.LocalClientId}");
				if (request.ClientNetworkId == NetworkManager.Singleton.LocalClientId)
				{
					Debug.Log((object)"Stopped connection approval callback, as the client in question was the host!");
					return false;
				}
				bool flag = !__instance.disallowConnection;
				if (flag)
				{
					string @string = Encoding.ASCII.GetString(request.Payload);
					string[] array = @string.Split(",");
					if (string.IsNullOrEmpty(@string))
					{
						response.Reason = "Unknown; please verify your game files.";
						flag = false;
					}
					else if (__instance.gameHasStarted)
					{
						response.Reason = "Game has already started!";
						flag = false;
					}
					else if (__instance.gameVersionNum.ToString() != array[0])
					{
						response.Reason = $"Game version mismatch! Their version: {__instance.gameVersionNum}. Your version: {array[0]}";
						flag = false;
					}
					else if (!__instance.disableSteam && ((Object)(object)StartOfRound.Instance == (Object)null || array.Length < 2 || StartOfRound.Instance.KickedClientIds.Contains((ulong)Convert.ToInt64(array[1]))))
					{
						response.Reason = "You cannot rejoin after being kicked.";
						flag = false;
					}
					else if (!@string.Contains("BiggerLobbyVersion2.5.0"))
					{
						response.Reason = "You need to have <color=#008282>BiggerLobby V2.5.0</color> to join this server!";
						flag = false;
					}
				}
				else
				{
					response.Reason = "The host was not accepting connections.";
				}
				Debug.Log((object)$"Approved connection?: {flag}. Connected players #: {__instance.connectedPlayers}");
				Debug.Log((object)("Disapproval reason: " + response.Reason));
				response.CreatePlayerObject = false;
				response.Approved = flag;
				response.Pending = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager))]
		internal class InternalPatches2
		{
			private static MethodInfo TargetMethod()
			{
				return typeof(GameNetworkManager).GetMethod("SteamMatchmaking_OnLobbyCreated", BindingFlags.Instance | BindingFlags.NonPublic);
			}

			[HarmonyPostfix]
			private static void PostFix(GameNetworkManager __instance, Result result, Lobby lobby)
			{
				((Lobby)(ref lobby)).SetData("name", "[BiggerLobby]" + ((Lobby)(ref lobby)).GetData("name"));
			}
		}

		private static PropertyInfo _playbackVolumeProperty = typeof(VoicePlayback).GetInterface("IVoicePlaybackInternal").GetProperty("PlaybackVolume");

		private static FieldInfo _lobbyListField = AccessTools.Field(typeof(SteamLobbyManager), "currentLobbyList");

		[HarmonyPatch(typeof(StartOfRound), "UpdatePlayerVoiceEffects")]
		[HarmonyPrefix]
		public static void UpdatePlayerVoiceEffects(StartOfRound __instance)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			typeof(StartOfRound).GetField("updatePlayerVoiceInterval", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, 2f);
			PlayerControllerB val = ((!GameNetworkManager.Instance.localPlayerController.isPlayerDead || !((Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null)) ? GameNetworkManager.Instance.localPlayerController : GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript);
			for (int i = 0; i < __instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val2 = __instance.allPlayerScripts[i];
				if ((!val2.isPlayerControlled && !val2.isPlayerDead) || (Object)(object)val2 == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					continue;
				}
				if (val2.voicePlayerState == null || val2.currentVoiceChatIngameSettings._playerState == null || (Object)(object)val2.currentVoiceChatAudioSource == (Object)null)
				{
					__instance.RefreshPlayerVoicePlaybackObjects();
					if (val2.voicePlayerState == null || (Object)(object)val2.currentVoiceChatAudioSource == (Object)null)
					{
						Debug.Log((object)$"Was not able to access voice chat object for player #{i}; {val2.voicePlayerState == null}; {(Object)(object)val2.currentVoiceChatAudioSource == (Object)null}");
						continue;
					}
				}
				AudioSource currentVoiceChatAudioSource = __instance.allPlayerScripts[i].currentVoiceChatAudioSource;
				bool flag = val2.speakingToWalkieTalkie && val.holdingWalkieTalkie && (Object)(object)val2 != (Object)(object)val;
				if (val2.isPlayerDead)
				{
					((Behaviour)((Component)currentVoiceChatAudioSource).GetComponent<AudioLowPassFilter>()).enabled = false;
					((Behaviour)((Component)currentVoiceChatAudioSource).GetComponent<AudioHighPassFilter>()).enabled = false;
					currentVoiceChatAudioSource.panStereo = 0f;
					SoundManager.Instance.playerVoicePitchTargets[val2.playerClientId] = 1f;
					SoundManager.Instance.SetPlayerPitch(1f, (int)val2.playerClientId);
					if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
					{
						currentVoiceChatAudioSource.spatialBlend = 0f;
						val2.currentVoiceChatIngameSettings.set2D = true;
						if ((Object)(object)val2.currentVoiceChatIngameSettings != (Object)null && (Object)(object)val2.currentVoiceChatIngameSettings._playbackComponent != (Object)null)
						{
							_playbackVolumeProperty.SetValue(val2.currentVoiceChatIngameSettings._playbackComponent, Mathf.Clamp((SoundManager.Instance.playerVoiceVolumes[i] + 1f) * (float)(2 * Plugin._LoudnessMultiplier.Value), 0f, 1f));
						}
					}
					else
					{
						currentVoiceChatAudioSource.spatialBlend = 1f;
						val2.currentVoiceChatIngameSettings.set2D = false;
						if ((Object)(object)val2.currentVoiceChatIngameSettings != (Object)null && (Object)(object)val2.currentVoiceChatIngameSettings._playbackComponent != (Object)null)
						{
							_playbackVolumeProperty.SetValue(val2.currentVoiceChatIngameSettings._playbackComponent, 0);
						}
					}
					continue;
				}
				AudioLowPassFilter component = ((Component)currentVoiceChatAudioSource).GetComponent<AudioLowPassFilter>();
				OccludeAudio component2 = ((Component)currentVoiceChatAudioSource).GetComponent<OccludeAudio>();
				((Behaviour)component).enabled = true;
				component2.overridingLowPass = flag || __instance.allPlayerScripts[i].voiceMuffledByEnemy;
				((Behaviour)((Component)currentVoiceChatAudioSource).GetComponent<AudioHighPassFilter>()).enabled = flag;
				if (!flag)
				{
					currentVoiceChatAudioSource.spatialBlend = 1f;
					val2.currentVoiceChatIngameSettings.set2D = false;
					currentVoiceChatAudioSource.bypassListenerEffects = false;
					currentVoiceChatAudioSource.bypassEffects = false;
					currentVoiceChatAudioSource.outputAudioMixerGroup = SoundManager.Instance.playerVoiceMixers[val2.playerClientId];
					component.lowpassResonanceQ = 1f;
				}
				else
				{
					currentVoiceChatAudioSource.spatialBlend = 0f;
					val2.currentVoiceChatIngameSettings.set2D = true;
					if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
					{
						currentVoiceChatAudioSource.panStereo = 0f;
						currentVoiceChatAudioSource.outputAudioMixerGroup = SoundManager.Instance.playerVoiceMixers[val2.playerClientId];
						currentVoiceChatAudioSource.bypassListenerEffects = false;
						currentVoiceChatAudioSource.bypassEffects = false;
					}
					else
					{
						currentVoiceChatAudioSource.panStereo = 0.4f;
						currentVoiceChatAudioSource.bypassListenerEffects = false;
						currentVoiceChatAudioSource.bypassEffects = false;
						currentVoiceChatAudioSource.outputAudioMixerGroup = SoundManager.Instance.playerVoiceMixers[val2.playerClientId];
					}
					component2.lowPassOverride = 4000f;
					component.lowpassResonanceQ = 3f;
				}
				if ((Object)(object)val2.currentVoiceChatIngameSettings != (Object)null && (Object)(object)val2.currentVoiceChatIngameSettings._playbackComponent != (Object)null)
				{
					_playbackVolumeProperty.SetValue(val2.currentVoiceChatIngameSettings._playbackComponent, Mathf.Clamp((SoundManager.Instance.playerVoiceVolumes[i] + 1f) * (float)(2 * Plugin._LoudnessMultiplier.Value), 0f, 1f));
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPrefix]
		public static void ResizeLists(ref StartOfRound __instance)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			__instance.allPlayerObjects = Helper.ResizeArray(__instance.allPlayerObjects, Plugin.MaxPlayers);
			__instance.allPlayerScripts = Helper.ResizeArray(__instance.allPlayerScripts, Plugin.MaxPlayers);
			__instance.gameStats.allPlayerStats = Helper.ResizeArray(__instance.gameStats.allPlayerStats, Plugin.MaxPlayers);
			__instance.playerSpawnPositions = Helper.ResizeArray(__instance.playerSpawnPositions, Plugin.MaxPlayers);
			for (int i = 4; i < Plugin.MaxPlayers; i++)
			{
				__instance.gameStats.allPlayerStats[i] = new PlayerStats();
				__instance.playerSpawnPositions[i] = __instance.playerSpawnPositions[0];
			}
		}

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPrefix]
		public static void ResizeHUD(ref HUDManager __instance)
		{
			ExpandedStatsUI.GetFromAnimator(__instance.endgameStatsAnimator);
		}

		[HarmonyPatch(typeof(SoundManager), "SetPlayerVoiceFilters")]
		[HarmonyPrefix]
		public static bool SetPlayerVoiceFilters(ref SoundManager __instance)
		{
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				if (!StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && !StartOfRound.Instance.allPlayerScripts[i].isPlayerDead)
				{
					__instance.playerVoicePitches[i] = 1f;
					__instance.playerVoiceVolumes[i] = 1f;
					continue;
				}
				if (StartOfRound.Instance.allPlayerScripts[i].voicePlayerState != null)
				{
					typeof(VoicePlayback).GetProperty("Dissonance.Audio.Playback.IVoicePlaybackInternal.PlaybackVolume", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(StartOfRound.Instance.allPlayerScripts[i].currentVoiceChatIngameSettings._playbackComponent, Mathf.Clamp((SoundManager.Instance.playerVoiceVolumes[i] + 1f) * (float)(2 * Plugin._LoudnessMultiplier.Value), 0f, 1f));
				}
				if (Mathf.Abs(__instance.playerVoicePitches[i] - __instance.playerVoicePitchTargets[i]) > 0.025f)
				{
					__instance.playerVoicePitches[i] = Mathf.Lerp(__instance.playerVoicePitches[i], __instance.playerVoicePitchTargets[i], 3f * Time.deltaTime);
				}
				else if (__instance.playerVoicePitches[i] != __instance.playerVoicePitchTargets[i])
				{
					__instance.playerVoicePitches[i] = __instance.playerVoicePitchTargets[i];
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(MenuManager), "OnEnable")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void CustomMenu(ref MenuManager __instance)
		{
			//IL_0196: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: 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_0260: Expected O, but got Unknown
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.isInitScene)
			{
				return;
			}
			float num = 30f;
			GameObject gameObject = ((Component)__instance.HostSettingsOptionsNormal.transform.parent.parent).gameObject;
			RectTransform val = ((gameObject != null) ? gameObject.GetComponent<RectTransform>() : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = ((Transform)val).Find("LobbyHostOptions");
				obj = ((obj2 != null) ? ((Component)obj2).GetComponent<RectTransform>() : null);
			}
			RectTransform val2 = (RectTransform)obj;
			object obj3;
			if (val2 == null)
			{
				obj3 = null;
			}
			else
			{
				Transform obj4 = ((Transform)val2).Find("OptionsNormal");
				obj3 = ((obj4 != null) ? ((Component)obj4).GetComponent<RectTransform>() : null);
			}
			RectTransform val3 = (RectTransform)obj3;
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				return;
			}
			object obj5;
			if (val3 == null)
			{
				obj5 = null;
			}
			else
			{
				Transform obj6 = ((Transform)val3).Find("ServerNameField");
				obj5 = ((obj6 != null) ? ((Component)obj6).GetComponent<RectTransform>() : null);
			}
			RectTransform val4 = (RectTransform)obj5;
			object obj7;
			if (val3 == null)
			{
				obj7 = null;
			}
			else
			{
				Transform obj8 = ((Transform)val3).Find("ServerTagInputField");
				obj7 = ((obj8 != null) ? ((Component)obj8).GetComponent<RectTransform>() : null);
			}
			RectTransform val5 = (RectTransform)obj7;
			object obj9;
			if (val == null)
			{
				obj9 = null;
			}
			else
			{
				Transform obj10 = ((Transform)val).Find("Confirm");
				obj9 = ((obj10 != null) ? ((Component)obj10).GetComponent<RectTransform>() : null);
			}
			RectTransform val6 = (RectTransform)obj9;
			object obj11;
			if (val == null)
			{
				obj11 = null;
			}
			else
			{
				Transform obj12 = ((Transform)val).Find("Back");
				obj11 = ((obj12 != null) ? ((Component)obj12).GetComponent<RectTransform>() : null);
			}
			RectTransform val7 = (RectTransform)obj11;
			object obj13;
			if (val == null)
			{
				obj13 = null;
			}
			else
			{
				Transform obj14 = ((Transform)val).Find("PrivatePublicDescription");
				obj13 = ((obj14 != null) ? ((Component)obj14).GetComponent<TextMeshProUGUI>() : null);
			}
			TextMeshProUGUI privatePublicDescription = (TextMeshProUGUI)obj13;
			if ((Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null || (Object)(object)privatePublicDescription == (Object)null)
			{
				return;
			}
			RectTransform val8 = Object.Instantiate<RectTransform>(val4, ((Component)val4).transform.parent);
			TMP_InputField playerNumberInputField = ((Component)val8).GetComponent<TMP_InputField>();
			val.sizeDelta += new Vector2(0f, num / 2f);
			val2.anchoredPosition += new Vector2(0f, num / 4f);
			val5.anchoredPosition += new Vector2(0f, (0f - num) / 2f);
			val6.anchoredPosition += new Vector2(0f, (0f - num) / 2f);
			val7.anchoredPosition += new Vector2(0f, (0f - num) / 2f);
			foreach (RectTransform item in (Transform)val3)
			{
				RectTransform val9 = item;
				if (!((Object)(object)val9 == (Object)null) && !(((Object)val9).name == "EnterAName") && !((Object)(object)val9 == (Object)(object)val4) && !((Object)(object)val9 == (Object)(object)val5))
				{
					val9.anchoredPosition += new Vector2(0f, 0f - num);
				}
			}
			((Object)val8).name = "ServerPlayersField";
			playerNumberInputField.contentType = (ContentType)2;
			((TMP_Text)((Component)((Component)val8).transform.Find("Text Area").Find("Placeholder")).gameObject.GetComponent<TextMeshProUGUI>()).text = "Max players (16)...";
			((UnityEvent<string>)(object)playerNumberInputField.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				OnChange();
			});
			void OnChange()
			{
				if (!int.TryParse(Regex.Replace(playerNumberInputField.text, "[^0-9]", ""), out var result))
				{
					result = 16;
				}
				result = Math.Min(Math.Max(result, 4), 40);
				ManualLogSource? logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)$"Setting max player count to: {result}");
				}
				if (result > 16)
				{
					((TMP_Text)privatePublicDescription).text = "Notice: High max player counts\nmay cause lag.";
				}
				else if (((TMP_Text)privatePublicDescription).text == "Notice: High max player counts\nmay cause lag.")
				{
					((TMP_Text)privatePublicDescription).text = "yeah you should be good now lol";
				}
			}
		}

		[HarmonyPatch(typeof(MenuManager), "StartHosting")]
		[HarmonyPrefix]
		public static bool StartHost(MenuManager __instance)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (!GameNetworkManager.Instance.currentLobby.HasValue)
			{
				return true;
			}
			if (!int.TryParse(Regex.Replace(((TMP_Text)((Component)((Component)__instance.HostSettingsOptionsNormal.transform.Find("ServerPlayersField")).gameObject.transform.Find("Text Area").Find("Text")).gameObject.GetComponent<TextMeshProUGUI>()).text, "[^0-9]", ""), out var result))
			{
				result = 16;
			}
			result = Math.Min(Math.Max(result, 4), 40);
			Lobby valueOrDefault = GameNetworkManager.Instance.currentLobby.GetValueOrDefault();
			((Lobby)(ref valueOrDefault)).SetData("MaxPlayers", result.ToString());
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)$"Setting max players to {result}!");
			}
			Plugin.MaxPlayers = result;
			if ((Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				GameNetworkManager.Instance.maxAllowedPlayers = Plugin.MaxPlayers;
			}
			return true;
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPrefix]
		public static void FillEndGameStats(HUDManager __instance)
		{
			ExpandedStatsUI fromAnimator = ExpandedStatsUI.GetFromAnimator(__instance.endgameStatsAnimator);
			if (!((Object)(object)fromAnimator == (Object)null) && !((Object)(object)StartOfRound.Instance == (Object)null))
			{
				PlayerStatsList statsListFromPlayerCount = fromAnimator.GetStatsListFromPlayerCount(Plugin.GetRealPlayerScripts(StartOfRound.Instance).Length);
				__instance.statsUIElements.playerNamesText = statsListFromPlayerCount.Names.ToArray();
				__instance.statsUIElements.playerStates = statsListFromPlayerCount.States.ToArray();
				__instance.statsUIElements.playerNotesText = statsListFromPlayerCount.Notes.ToArray();
				ManualLogSource? logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)"Adding EXPANDED stats!");
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		[HarmonyPostfix]
		public static void FillEndGameStatsPostfix(HUDManager __instance)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null || Plugin.GetRealPlayerScripts(StartOfRound.Instance).Length <= 4)
			{
				return;
			}
			TextMeshProUGUI[] playerNotesText = __instance.statsUIElements.playerNotesText;
			foreach (TextMeshProUGUI val in playerNotesText)
			{
				if (!(((TMP_Text)val).text == ""))
				{
					((TMP_Text)val).text = ((TMP_Text)val).text.Replace("Notes:", "").Trim();
				}
			}
			Sprite replacementCheckmark = ExpandedStatsUI.GetReplacementCheckmark();
			if ((Object)(object)replacementCheckmark == (Object)null)
			{
				return;
			}
			Image[] playerStates = __instance.statsUIElements.playerStates;
			foreach (Image val2 in playerStates)
			{
				if (!((Object)(object)val2.sprite != (Object)(object)__instance.statsUIElements.aliveIcon))
				{
					val2.sprite = replacementCheckmark;
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "StartHost")]
		[HarmonyPrefix]
		public static bool DoTheThe()
		{
			Plugin.CustomNetObjects.Clear();
			return true;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "StartClient")]
		[HarmonyPrefix]
		public static bool StartClient(GameNetworkManager __instance)
		{
			Plugin.CustomNetObjects.Clear();
			return true;
		}

		[HarmonyPatch(typeof(MenuManager), "StartAClient")]
		[HarmonyPrefix]
		public static bool StartAClient()
		{
			Plugin.CustomNetObjects.Clear();
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"LAN Running.");
			}
			return true;
		}

		[HarmonyPatch(typeof(SteamLobbyManager), "loadLobbyListAndFilter")]
		[HarmonyPostfix]
		public static IEnumerator LoadLobbyListAndFilter(IEnumerator result, SteamLobbyManager __instance)
		{
			while (result.MoveNext())
			{
				yield return result.Current;
			}
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"Injecting BL playercounts into lobby list.");
			}
			LobbySlot[] componentsInChildren = ((Component)__instance.levelListContainer).GetComponentsInChildren<LobbySlot>(true);
			foreach (LobbySlot val in componentsInChildren)
			{
				try
				{
					((TMP_Text)val.LobbyName).text = ((TMP_Text)val.LobbyName).text.Replace("[BiggerLobby]", "[BL]");
					if (!int.TryParse(((Lobby)(ref val.thisLobby)).GetData("MaxPlayers"), out var result2))
					{
						result2 = 4;
					}
					((TMP_Text)val.playerCount).text = ((TMP_Text)val.playerCount).text.Replace("/ 4", $"/ {result2}");
				}
				catch (Exception ex)
				{
					ManualLogSource? logger2 = Plugin.Logger;
					if (logger2 != null)
					{
						logger2.LogWarning((object)"Exception while injecting BL lobby metadata:");
					}
					ManualLogSource? logger3 = Plugin.Logger;
					if (logger3 != null)
					{
						logger3.LogWarning((object)ex);
					}
				}
			}
		}

		[HarmonyPatch(typeof(SteamMatchmaking), "CreateLobbyAsync")]
		[HarmonyPrefix]
		public static void SetMaxMembers(ref int maxMembers)
		{
			maxMembers = Plugin.MaxPlayers;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SetConnectionDataBeforeConnecting")]
		[HarmonyPrefix]
		public static bool SetConnectionDataBeforeConnecting(GameNetworkManager __instance)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			__instance.localClientWaitingForApproval = true;
			Debug.Log((object)("Game version: " + __instance.gameVersionNum));
			if (__instance.disableSteam)
			{
				NetworkManager.Singleton.NetworkConfig.ConnectionData = Encoding.ASCII.GetBytes(__instance.gameVersionNum + ",BiggerLobbyVersion2.5.0");
			}
			else
			{
				NetworkManager.Singleton.NetworkConfig.ConnectionData = Encoding.ASCII.GetBytes(__instance.gameVersionNum + "," + SteamId.op_Implicit(SteamClient.SteamId) + ",BiggerLobbyVersion2.5.0");
			}
			return false;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "LobbyDataIsJoinable")]
		[HarmonyPrefix]
		public static bool SkipLobbySizeCheck(ref GameNetworkManager __instance, ref bool __result, Lobby lobby)
		{
			//IL_004f: 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)
			string data = ((Lobby)(ref lobby)).GetData("vers");
			if (!int.TryParse(((Lobby)(ref lobby)).GetData("MaxPlayers"), out var result))
			{
				result = 16;
			}
			result = Math.Min(Math.Max(result, 4), 40);
			if (((Lobby)(ref lobby)).MemberCount >= result || ((Lobby)(ref lobby)).MemberCount < 1)
			{
				Debug.Log((object)$"Lobby join denied! Too many members in lobby! {((Lobby)(ref lobby)).Id}");
				Object.FindObjectOfType<MenuManager>().SetLoadingScreen(false, (RoomEnter)4, "The server is full!");
				__result = false;
				return false;
			}
			if (data != __instance.gameVersionNum.ToString())
			{
				Debug.Log((object)$"Lobby join denied! Attempted to join vers.{data} lobby id: {((Lobby)(ref lobby)).Id}");
				Object.FindObjectOfType<MenuManager>().SetLoadingScreen(false, (RoomEnter)2, $"The server host is playing on version {data} while you are on version {__instance.gameVersionNum}.");
				__result = false;
				return false;
			}
			if (((Lobby)(ref lobby)).GetData("joinable") == "false")
			{
				Debug.Log((object)"Lobby join denied! Host lobby is not joinable");
				Object.FindObjectOfType<MenuManager>().SetLoadingScreen(false, (RoomEnter)2, "The server host has already landed their ship, or they are still loading in.");
				__result = false;
				return false;
			}
			Plugin.MaxPlayers = result;
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)$"Setting max players to {result}!");
			}
			if ((Object)(object)__instance != (Object)null)
			{
				__instance.maxAllowedPlayers = Plugin.MaxPlayers;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch]
	internal class PlayerObjects
	{
		private static StartOfRound startOfRound;

		private static bool instantiating;

		private static int nextClientId;

		private static PlayerControllerB referencePlayer;

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPrefix]
		public static void ResizeLists(ref StartOfRound __instance)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			__instance.allPlayerObjects = Helper.ResizeArray(__instance.allPlayerObjects, Plugin.MaxPlayers);
			__instance.allPlayerScripts = Helper.ResizeArray(__instance.allPlayerScripts, Plugin.MaxPlayers);
			__instance.gameStats.allPlayerStats = Helper.ResizeArray(__instance.gameStats.allPlayerStats, Plugin.MaxPlayers);
			__instance.playerSpawnPositions = Helper.ResizeArray(__instance.playerSpawnPositions, Plugin.MaxPlayers);
			for (int i = 4; i < Plugin.MaxPlayers; i++)
			{
				__instance.gameStats.allPlayerStats[i] = new PlayerStats();
				__instance.playerSpawnPositions[i] = __instance.playerSpawnPositions[0];
			}
		}

		[HarmonyPatch(typeof(ForestGiantAI), "Start")]
		[HarmonyPrefix]
		public static bool ResizeLists2(ref ForestGiantAI __instance)
		{
			__instance.playerStealthMeters = Helper.ResizeArray(__instance.playerStealthMeters, Plugin.MaxPlayers);
			return true;
		}

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPostfix]
		public static void ResizeLists2(ref HUDManager __instance)
		{
		}

		[HarmonyPatch(typeof(SoundManager), "Awake")]
		[HarmonyPostfix]
		public static void SoundWake(ref SoundManager __instance)
		{
			__instance.playerVoiceMixers = Helper.ResizeArray(__instance.playerVoiceMixers, Plugin.MaxPlayers);
			for (int i = 0; i < Plugin.MaxPlayers; i++)
			{
				__instance.playerVoiceMixers[i] = __instance.diageticMixer.outputAudioMixerGroup;
			}
		}

		[HarmonyPatch(typeof(SoundManager), "Start")]
		[HarmonyPostfix]
		public static void ResizeSoundManagerLists(ref SoundManager __instance)
		{
			__instance.playerVoicePitchLerpSpeed = new float[Plugin.MaxPlayers + 1];
			__instance.playerVoicePitchTargets = new float[Plugin.MaxPlayers + 1];
			__instance.playerVoiceVolumes = new float[Plugin.MaxPlayers + 1];
			__instance.playerVoicePitches = new float[Plugin.MaxPlayers + 1];
			for (int i = 1; i < Plugin.MaxPlayers + 1; i++)
			{
				__instance.playerVoicePitchLerpSpeed[i] = 3f;
				__instance.playerVoicePitchTargets[i] = 1f;
				__instance.playerVoicePitches[i] = 1f;
				__instance.playerVoiceVolumes[i] = 1f;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")]
		[HarmonyPrefix]
		public static bool EnableEnemyMesh(EnemyAI __instance, bool enable, bool overrideDoNotSet = false)
		{
			int layer = ((!enable) ? 23 : 19);
			for (int i = 0; i < __instance.skinnedMeshRenderers.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)__instance.skinnedMeshRenderers[i]) && (!((Component)__instance.skinnedMeshRenderers[i]).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)__instance.skinnedMeshRenderers[i]).gameObject.layer = layer;
				}
			}
			for (int j = 0; j < __instance.meshRenderers.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)__instance.meshRenderers[j]) && (!((Component)__instance.meshRenderers[j]).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)__instance.meshRenderers[j]).gameObject.layer = layer;
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(ShipTeleporter), "Awake")]
		[HarmonyPrefix]
		public static bool Awake2(ShipTeleporter __instance)
		{
			int[] array = new int[Plugin.MaxPlayers];
			for (int i = 0; i < Plugin.MaxPlayers; i++)
			{
				array[i] = -1;
			}
			typeof(ShipTeleporter).GetField("playersBeingTeleported", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, array);
			__instance.buttonTrigger.interactable = false;
			typeof(ShipTeleporter).GetField("cooldownTime", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, __instance.cooldownAmount);
			return false;
		}

		[HarmonyPatch(typeof(NetworkSceneManager), "PopulateScenePlacedObjects")]
		[HarmonyPrefix]
		public static bool AddPlayers(NetworkSceneManager __instance)
		{
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			startOfRound = StartOfRound.Instance;
			if ((Object)(object)startOfRound.allPlayerObjects[Plugin.MaxPlayers - 1] != (Object)null)
			{
				return true;
			}
			referencePlayer = startOfRound.allPlayerObjects[0].GetComponent<PlayerControllerB>();
			GameObject playerPrefab = startOfRound.playerPrefab;
			Transform transform = ((Component)startOfRound.playersContainer).transform;
			FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
			PropertyInfo property = typeof(NetworkObject).GetProperty("NetworkObjectId", BindingFlags.Instance | BindingFlags.Public);
			typeof(NetworkSceneManager).GetField("ScenePlacedObjects", BindingFlags.Instance | BindingFlags.NonPublic);
			instantiating = true;
			typeof(NetworkSpawnManager).GetMethod("SpawnNetworkObjectLocally", BindingFlags.Instance | BindingFlags.NonPublic, null, CallingConventions.Any, new Type[6]
			{
				typeof(NetworkObject),
				typeof(ulong),
				typeof(bool),
				typeof(bool),
				typeof(ulong),
				typeof(bool)
			}, null);
			for (int i = 4; i < Plugin.MaxPlayers; i++)
			{
				nextClientId = i;
				GameObject val = Object.Instantiate<GameObject>(playerPrefab, transform);
				PlayerControllerB component = val.GetComponent<PlayerControllerB>();
				NetworkObject component2 = val.GetComponent<NetworkObject>();
				NetworkObject component3 = ((Component)val.transform.Find("PlayerPhysicsBox")).gameObject.GetComponent<NetworkObject>();
				NetworkObject component4 = ((Component)val.transform.Find("ScavengerModel/metarig/ScavengerModelArmsOnly/metarig/spine.003/shoulder.R/arm.R_upper/arm.R_lower/hand.R/LocalItemHolder")).gameObject.GetComponent<NetworkObject>();
				NetworkObject component5 = ((Component)val.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/shoulder.R/arm.R_upper/arm.R_lower/hand.R/ServerItemHolder")).gameObject.GetComponent<NetworkObject>();
				component.TeleportPlayer(StartOfRound.Instance.notSpawnedPosition.position, false, 0f, false, true);
				startOfRound.allPlayerObjects[i] = val;
				startOfRound.allPlayerScripts[i] = component;
				uint num = (uint)(6942069 + i);
				ulong num2 = 6942069uL + (ulong)i;
				uint num3 = (uint)(123456789 + i);
				uint num4 = (uint)(987654321 + i);
				uint num5 = (uint)(124585949 + i);
				ulong num6 = 123456789uL + (ulong)i;
				ulong num7 = 987654321uL + (ulong)i;
				ulong num8 = 124585949uL + (ulong)i;
				Scene scene = ((Component)component2).gameObject.scene;
				_ = ((Scene)(ref scene)).handle;
				field.SetValue(component2, num);
				property.SetValue(component2, num2);
				field.SetValue(component3, num3);
				property.SetValue(component3, num6);
				field.SetValue(component4, num4);
				property.SetValue(component4, num7);
				field.SetValue(component5, num5);
				property.SetValue(component5, num8);
				ManualCameraRenderer[] array = Object.FindObjectsByType<ManualCameraRenderer>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				for (int j = 0; j < array.Length; j++)
				{
					array[j].AddTransformAsTargetToRadar(((Component)component).transform, "Player #" + j, false);
				}
			}
			instantiating = false;
			return true;
		}

		[HarmonyPatch(typeof(QuickMenuManager), "AddUserToPlayerList")]
		[HarmonyPrefix]
		public static bool AddUserToPlayerList(QuickMenuManager __instance, ulong steamId, string playerName, int playerObjectId)
		{
			if (playerObjectId >= 0 && playerObjectId <= Plugin.MaxPlayers)
			{
				__instance.playerListSlots[playerObjectId].KickUserButton.SetActive(((NetworkBehaviour)StartOfRound.Instance).IsServer);
				__instance.playerListSlots[playerObjectId].slotContainer.SetActive(true);
				__instance.playerListSlots[playerObjectId].isConnected = true;
				__instance.playerListSlots[playerObjectId].playerSteamId = steamId;
				((TMP_Text)__instance.playerListSlots[playerObjectId].usernameHeader).text = playerName.Replace("bizzlemip", "<color=#008282>bizzlemip</color>");
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					__instance.playerListSlots[playerObjectId].volumeSliderContainer.SetActive(playerObjectId != (int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(QuickMenuManager), "Update")]
		[HarmonyPrefix]
		private static bool Update(QuickMenuManager __instance)
		{
			for (int i = 0; i < __instance.playerListSlots.Length; i++)
			{
				if (__instance.playerListSlots[i].isConnected)
				{
					float num = __instance.playerListSlots[i].volumeSlider.value / __instance.playerListSlots[i].volumeSlider.maxValue;
					if (num == -1f)
					{
						SoundManager.Instance.playerVoiceVolumes[i] = -1f;
					}
					else
					{
						SoundManager.Instance.playerVoiceVolumes[i] = num;
					}
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(QuickMenuManager), "Start")]
		[HarmonyPrefix]
		public static bool FixPlayerList(ref QuickMenuManager __instance)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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)
			//IL_013e: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Expected O, but got Unknown
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Expected O, but got Unknown
			GameObject val = null;
			GameObject gameObject = ((Component)__instance.playerListPanel.transform.Find("Image")).gameObject;
			if (Object.op_Implicit((Object)(object)gameObject.transform.Find("Mask")))
			{
				val = ((Component)gameObject.transform.Find("Mask")).gameObject;
			}
			GameObject val2 = new GameObject("Mask");
			GameObject val3 = new GameObject("ScrollViewport");
			GameObject val4 = new GameObject("BGCollision");
			GameObject val5 = new GameObject("ScrollContent");
			val2.transform.SetParent(gameObject.transform);
			val3.transform.SetParent(val2.transform);
			val4.transform.SetParent(val3.transform);
			val5.transform.SetParent(val3.transform);
			val2.transform.localScale = Vector3.one;
			val3.transform.localScale = Vector3.one;
			val5.transform.localScale = Vector3.one;
			val2.AddComponent<RectTransform>().sizeDelta = new Vector2(300f, 280f);
			val2.transform.localPosition = new Vector3(-10f, 110f, 0f);
			val3.transform.localPosition = new Vector3(0f, -10f, 0f);
			val5.AddComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
			val2.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
			val2.transform.localPosition = new Vector3(-10f, 110f, 0f);
			val2.AddComponent<RectMask2D>();
			VerticalLayoutGroup val6 = val5.AddComponent<VerticalLayoutGroup>();
			ContentSizeFitter obj = val5.AddComponent<ContentSizeFitter>();
			ScrollRect obj2 = val3.AddComponent<ScrollRect>();
			obj2.viewport = val3.AddComponent<RectTransform>();
			obj2.content = val5.GetComponent<RectTransform>();
			obj2.horizontal = false;
			Image val7 = val4.AddComponent<Image>();
			val4.GetComponent<RectTransform>().anchorMin = new Vector2(0f, 0f);
			val4.GetComponent<RectTransform>().anchorMax = new Vector2(1f, 1f);
			((Graphic)val7).color = new Color(255f, 255f, 255f, 0f);
			((HorizontalOrVerticalLayoutGroup)val6).spacing = 50f;
			obj.horizontalFit = (FitMode)0;
			obj.verticalFit = (FitMode)2;
			__instance.playerListSlots = Helper.ResizeArray(__instance.playerListSlots, Plugin.MaxPlayers);
			for (int i = 0; i < Plugin.MaxPlayers; i++)
			{
				if (i < 4)
				{
					__instance.playerListSlots[i].slotContainer.transform.SetParent(val5.transform);
					continue;
				}
				PlayerListSlot val8 = new PlayerListSlot();
				GameObject val9 = (val8.slotContainer = Object.Instantiate<GameObject>(__instance.playerListSlots[0].slotContainer));
				val8.volumeSliderContainer = ((Component)val9.transform.Find("VoiceVolumeSlider")).gameObject;
				val8.KickUserButton = ((Component)val9.transform.Find("KickButton")).gameObject;
				QuickMenuManager yeahoriginal = __instance;
				int localI = i;
				((UnityEvent)val8.KickUserButton.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					yeahoriginal.KickUserFromServer(localI);
				});
				val8.isConnected = false;
				val8.usernameHeader = ((Component)val9.transform.Find("PlayerNameButton").Find("PName")).gameObject.GetComponent<TextMeshProUGUI>();
				val8.volumeSlider = ((Component)val9.transform.Find("VoiceVolumeSlider").Find("Slider")).gameObject.GetComponent<Slider>();
				val8.playerSteamId = __instance.playerListSlots[0].playerSteamId;
				val9.transform.SetParent(val5.transform, false);
				__instance.playerListSlots[i] = val8;
			}
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
			return true;
		}

		[HarmonyPatch(typeof(ManualCameraRenderer), "Awake")]
		[HarmonyPrefix]
		public static bool Mawake(ref ManualCameraRenderer __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			for (int i = 0; i < 4; i++)
			{
				__instance.radarTargets.Add(new TransformAndName(((Component)StartOfRound.Instance.allPlayerScripts[i]).transform, StartOfRound.Instance.allPlayerScripts[i].playerUsername, false));
			}
			__instance.targetTransformIndex = 0;
			__instance.targetedPlayer = StartOfRound.Instance.allPlayerScripts[0];
			return false;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
		[HarmonyPrefix]
		public static bool FixPlayerObject(ref PlayerControllerB __instance)
		{
			if (!instantiating)
			{
				return true;
			}
			((Object)((Component)__instance).gameObject).name = $"ExtraPlayer{nextClientId}";
			__instance.playerClientId = (ulong)nextClientId;
			__instance.actualClientId = (ulong)nextClientId;
			StartOfRound.Instance.allPlayerObjects[nextClientId] = ((Component)((Component)__instance).transform.parent).gameObject;
			StartOfRound.Instance.allPlayerScripts[nextClientId] = __instance;
			FieldInfo[] fields = typeof(PlayerControllerB).GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				object value = fieldInfo.GetValue(__instance);
				object value2 = fieldInfo.GetValue(referencePlayer);
				if (value == null && value2 != null)
				{
					fieldInfo.SetValue(__instance, value2);
				}
			}
			((Behaviour)__instance).enabled = true;
			return true;
		}

		[HarmonyPatch(typeof(StartOfRound), "GetPlayerSpawnPosition")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> GetPlayerSpawnPosition(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			list[0].opcode = OpCodes.Ldc_I4_1;
			return list.AsEnumerable();
		}
	}
}
namespace BiggerLobby.Models
{
	public class PlayerStatsList
	{
		public Transform transform;

		public List<TextMeshProUGUI> Names = new List<TextMeshProUGUI>();

		public List<Image> States = new List<Image>();

		public List<TextMeshProUGUI> Notes = new List<TextMeshProUGUI>();

		public GameObject gameObject => ((Component)transform).gameObject;

		public PlayerStatsList(Transform transform)
		{
			this.transform = transform;
		}

		public void AddPlayerSlotTransform(Transform playerSlot)
		{
			TextMeshProUGUI component = ((Component)playerSlot.GetChild(0)).GetComponent<TextMeshProUGUI>();
			Image component2 = ((Component)playerSlot.GetChild(1)).GetComponent<Image>();
			TextMeshProUGUI component3 = ((Component)playerSlot.Find("Notes")).GetComponent<TextMeshProUGUI>();
			Names.Add(component);
			States.Add(component2);
			Notes.Add(component3);
		}

		public void AddPlayerSlotTransforms(List<Transform> playerSlots)
		{
			foreach (Transform playerSlot in playerSlots)
			{
				AddPlayerSlotTransform(playerSlot);
			}
		}
	}
	public enum StatsScreenType
	{
		FourPlayers,
		EightPlayers,
		MoreThanEightPlayers
	}
	public class StatsUIReferences : MonoBehaviour
	{
		public Sprite StatsBoxesThin;

		public Sprite StatsBoxesGradeOnly;

		public Sprite CheckmarkThin;

		public ScrollRect ThinScrollRect;
	}
}