Decompiled source of MorePlayers v2.2.1

GladioMorePlayers.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using Steamworks;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("GladioMorePlayers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("More players for the game Gladio Mori by Plebeian Studio.")]
[assembly: AssemblyFileVersion("2.2.1.0")]
[assembly: AssemblyInformationalVersion("2.2.1+e4a1e169d59fc93956732a8657fb63908027c5dd")]
[assembly: AssemblyProduct("GladioMorePlayers")]
[assembly: AssemblyTitle("GladioMorePlayers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.1.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace GladioMorePlayers
{
	[BepInPlugin("gay.crf.gladiomoreplayers", "Gladio More Players", "2.2.1")]
	public class MorePlayersMod : BaseUnityPlugin
	{
		public static MorePlayersMod? instance;

		public static ManualLogSource? log;

		public ConfigEntry<int>? maxPlayers;

		private ConfigEntry<string>? openMenuBind;

		public ConfigEntry<bool>? randomizeSpawns;

		internal List<MultiplayerRoomPlayer>? currentPlayers;

		public Dictionary<string, bool> bannedPlayers = new Dictionary<string, bool>();

		internal bool uiOpen;

		private void Awake()
		{
			instance = this;
			log = ((BaseUnityPlugin)this).Logger;
			((Object)Chainloader.ManagerObject).hideFlags = (HideFlags)61;
			Harmony.CreateAndPatchAll(typeof(HarmonyPatches), (string)null);
			maxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "maxPlayers", 16, "Maximum amount of players that can join your server.");
			openMenuBind = ((BaseUnityPlugin)this).Config.Bind<string>("General", "openMenuBind", "f6", "Keybind to open the manager UI. See 'Mapping virtual axes to controls' on https://docs.unity3d.com/Manual/class-InputManager.html for key names.");
			randomizeSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "randomizeSpawns", false, "Whether player's spawns should be randomized every round. true or false.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"More Players has initialized!");
		}

		private void OnGUI()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (!uiOpen || maxPlayers == null || randomizeSpawns == null)
			{
				return;
			}
			GUILayout.BeginArea(new Rect((float)(Screen.width / 2 - Screen.width / 8), 0f, (float)(Screen.width / 4), (float)(Screen.height / 2)));
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Box("More Players Manager", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Box($"Maximum Players: {maxPlayers.Value}\n(restart lobby after change)", Array.Empty<GUILayoutOption>());
			maxPlayers.Value = (int)GUILayout.HorizontalSlider((float)maxPlayers.Value, 1f, 16f, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			randomizeSpawns.Value = GUILayout.Toggle(randomizeSpawns.Value, "Randomize Spawns", Array.Empty<GUILayoutOption>());
			if (currentPlayers == null || currentPlayers.Count == 0)
			{
				GUILayout.EndVertical();
				GUILayout.EndArea();
				return;
			}
			if (GUILayout.Button("Ready All", Array.Empty<GUILayoutOption>()))
			{
				currentPlayers.ForEach(delegate(MultiplayerRoomPlayer player)
				{
					SetReadyState(player, readyState: true);
				});
			}
			if (GUILayout.Button("Un-Ready All", Array.Empty<GUILayoutOption>()))
			{
				currentPlayers.ForEach(delegate(MultiplayerRoomPlayer player)
				{
					SetReadyState(player, readyState: false);
				});
			}
			bool flag = (Object)(object)MultiplayerLobbyStatusManager.singleton != (Object)null;
			foreach (MultiplayerRoomPlayer currentPlayer in currentPlayers)
			{
				if ((Object)(object)currentPlayer == (Object)null || currentPlayer.disconnecting)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (flag)
				{
					GUILayout.Box("Player: " + currentPlayer.playerName + " is " + (currentPlayer.playerReadyState ? "Ready" : "Not Ready"), Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Box("Player: " + currentPlayer.playerName, Array.Empty<GUILayoutOption>());
				}
				if (((NetworkBehaviour)currentPlayer).connectionToServer == null)
				{
					if (GUILayout.Button("Kick", Array.Empty<GUILayoutOption>()))
					{
						KickPlayer(currentPlayer);
					}
					if (GUILayout.Button("Ban", Array.Empty<GUILayoutOption>()))
					{
						BanPlayer(currentPlayer);
					}
				}
				if (flag && GUILayout.Button("Toggle Ready", Array.Empty<GUILayoutOption>()))
				{
					SetReadyState(currentPlayer, !currentPlayer.playerReadyState);
				}
				bool flag2 = GUILayout.Toggle(currentPlayer.Networkspectator, "Spectator", Array.Empty<GUILayoutOption>());
				if (currentPlayer.Networkspectator != flag2)
				{
					currentPlayer.Networkspectator = flag2;
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
			GUILayout.EndArea();
		}

		private void Update()
		{
			if (openMenuBind != null && Input.GetKeyDown(openMenuBind.Value))
			{
				uiOpen = !uiOpen;
			}
		}

		internal void UpdateStoredPlayerList()
		{
			currentPlayers = Object.FindObjectsOfType<MultiplayerRoomPlayer>().ToList();
		}

		private void SetReadyState(MultiplayerRoomPlayer player, bool readyState)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			((NetworkRoomPlayer)player).SetReadyToBegin(readyState);
			((MultiplayerRoomManager)NetworkManager.singleton).ReadyStatusChanged();
		}

		private void BanPlayer(MultiplayerRoomPlayer player)
		{
			string steamId = GetSteamId(((NetworkConnection)((NetworkBehaviour)player).connectionToClient).connectionId);
			bannedPlayers[steamId] = true;
			KickPlayer(player);
		}

		internal static void KickPlayer(MultiplayerRoomPlayer player)
		{
			((NetworkConnection)((Component)player).GetComponent<NetworkIdentity>().connectionToClient).Disconnect();
		}

		internal bool IsPlayerBanned(string steamId)
		{
			bool value;
			return bannedPlayers.TryGetValue(steamId, out value) && value;
		}

		internal bool IsPlayerBanned(MultiplayerRoomPlayer player)
		{
			return IsPlayerBanned(GetSteamId(((NetworkConnection)((NetworkBehaviour)player).connectionToClient).connectionId));
		}

		internal bool IsPlayerBanned(int connectionId)
		{
			return IsPlayerBanned(GetSteamId(connectionId));
		}

		internal static string GetSteamId(int connectionId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return ((MultiplayerRoomManager)NetworkManager.singleton).GetTransport().ServerGetClientAddress(connectionId);
		}

		internal static string GetSteamId(MultiplayerRoomPlayer player)
		{
			return GetSteamId(((NetworkConnection)((NetworkBehaviour)player).connectionToClient).connectionId);
		}
	}
	[HarmonyPatch]
	public static class HarmonyPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerMultiplayerInputManager), "Awake")]
		private static void AddNewSpawns()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("SpawnPoints");
			Vector3[] array = (Vector3[])(object)new Vector3[12]
			{
				new Vector3(-8f, 1.45f, 9f),
				new Vector3(8f, 1.45f, 9f),
				new Vector3(8f, 1.45f, -9f),
				new Vector3(-8f, 1.45f, -9f),
				new Vector3(0f, 1.45f, -12f),
				new Vector3(0f, 1.45f, 12f),
				new Vector3(-12f, 1.45f, 0f),
				new Vector3(12f, 1.45f, 0f),
				new Vector3(-7f, 6f, 7f),
				new Vector3(7f, 6f, 7f),
				new Vector3(7f, 6f, -7f),
				new Vector3(-7f, 6f, -7f)
			};
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "map_ArenaOfBlades" && val.transform.childCount < array.Length + 4)
			{
				for (int i = 0; i < array.Length; i++)
				{
					GameObject val2 = new GameObject();
					val2.transform.position = array[i];
					val2.transform.SetParent(val.transform);
					((Object)val2).name = $"Spawnpoint ({4 + i})";
				}
			}
			MorePlayersMod instance = MorePlayersMod.instance;
			if (instance.randomizeSpawns == null)
			{
				MorePlayersMod.log.LogError((object)"Could not get random spawns pref! Defaulting to false.");
			}
			else
			{
				if (!instance.randomizeSpawns.Value)
				{
					return;
				}
				List<int> list = new List<int>();
				List<Transform> list2 = new List<Transform>();
				for (int j = 0; j < val.transform.childCount; j++)
				{
					list.Add(j);
					list2.Add(val.transform.GetChild(j));
				}
				foreach (Transform item in list2)
				{
					item.SetSiblingIndex(list[Random.Range(0, list.Count)]);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "HostLobby")]
		private static bool ChangeLobbyMaxConnections()
		{
			MorePlayersMod instance = MorePlayersMod.instance;
			if (instance.maxPlayers == null)
			{
				MorePlayersMod.log.LogError((object)"Could not get max players pref! Defaulting to 4 players.");
				return true;
			}
			NetworkManager.singleton.maxConnections = instance.maxPlayers.Value;
			if (SteamClient.IsValid)
			{
				SteamMatchmaking.CreateLobbyAsync(instance.maxPlayers.Value);
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MultiplayerRoomPlayer), "OnStartClient")]
		private static void UpdatePlayersOnPlayerStart()
		{
			MorePlayersMod.instance.UpdateStoredPlayerList();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MultiplayerRoomPlayer), "OnStopClient")]
		private static void UpdatePlayersOnPlayerStop()
		{
			MorePlayersMod.instance.UpdateStoredPlayerList();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MultiplayerRoomManager), "OnServerConnect")]
		private static void KickBannedPlayers(NetworkConnectionToClient conn)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			MorePlayersMod? instance = MorePlayersMod.instance;
			MultiplayerRoomManager val = (MultiplayerRoomManager)NetworkManager.singleton;
			if (instance.IsPlayerBanned(((NetworkConnection)conn).connectionId))
			{
				val.GetTransport().ServerDisconnect(((NetworkConnection)conn).connectionId);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "GladioMorePlayers";

		public const string PLUGIN_NAME = "GladioMorePlayers";

		public const string PLUGIN_VERSION = "2.2.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}