Decompiled source of Joive PlayerList v1.0.0

BG-PlayerList-Joive.dll

Decompiled a week 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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Joive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Scrollable player list and kick menu for Burglin Gnomes.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BG Player List")]
[assembly: AssemblyTitle("BG-PlayerList-Joive")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 Joive.BGPlayerList
{
	[BepInPlugin("joive.bg.playerlist", "BG Player List", "1.0.0")]
	public sealed class PlayerListPlugin : BaseUnityPlugin
	{
		private sealed class PlayerRow
		{
			public ulong ClientId;

			public ulong KickId;

			public string KickIdText;

			public string DisplayName;

			public bool IsLocal;

			public bool IsHost;

			public bool IsConnected;
		}

		private const float DefaultWindowWidth = 760f;

		private const float DefaultWindowHeight = 520f;

		private static ManualLogSource Log;

		private ConfigEntry<string> menuKey;

		private ConfigEntry<bool> openOnStart;

		private ConfigEntry<bool> pauseGameWhileOpen;

		private ConfigEntry<float> autoRefreshSeconds;

		private ConfigEntry<bool> showSteamIds;

		private ConfigEntry<bool> confirmKick;

		private KeyCode cachedMenuKey = (KeyCode)289;

		private bool visible;

		private bool centered;

		private Rect windowRect;

		private Vector2 scroll;

		private string searchText = "";

		private float nextRefreshTime;

		private string status = "Not refreshed yet.";

		private readonly List<PlayerRow> players = new List<PlayerRow>();

		private ulong? pendingKickClientId;

		private bool modalActive;

		private bool oldCursorVisible;

		private CursorLockMode oldCursorLock;

		private float oldTimeScale = 1f;

		private PlayerController modalController;

		private bool hadControllerUiOpen;

		private bool oldControllerUiOpen;

		private Texture2D dimTexture;

		private GUIStyle windowStyle;

		private Texture2D windowTexture;

		private Texture2D headerTexture;

		private GUIStyle titleStyle;

		private GUIStyle tabStyle;

		private GUIStyle activeButtonStyle;

		private GUIStyle buttonStyle;

		private GUIStyle dangerButtonStyle;

		private GUIStyle labelStyle;

		private GUIStyle smallLabelStyle;

		private GUIStyle boxStyle;

		private GUIStyle textFieldStyle;

		private void Awake()
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			menuKey = ((BaseUnityPlugin)this).Config.Bind<string>("General", "MenuKey", "F8", "Key used to open the fixed player list menu.");
			openOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OpenOnStart", false, "Open the menu once after the mod loads.");
			pauseGameWhileOpen = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PauseGameWhileOpen", true, "Pause Time.timeScale while the menu is open.");
			autoRefreshSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AutoRefreshSeconds", 0f, "How often to refresh the player list while the menu is open. 0 disables auto-refresh. Default is 0 for FPS-friendly manual refresh.");
			showSteamIds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowSteamIds", true, "Show Steam IDs / kick IDs when available.");
			confirmKick = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ConfirmKick", true, "Require a second click before kicking a player.");
			cachedMenuKey = ParseKey(menuKey.Value, (KeyCode)289);
			windowRect = new Rect(120f, 90f, 760f, 520f);
			Log.LogInfo((object)"BG Player List loaded by Joive.");
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(cachedMenuKey))
			{
				SetVisible(!visible);
			}
			if (Input.GetKeyDown((KeyCode)27) && visible)
			{
				SetVisible(value: false);
			}
			if (openOnStart.Value)
			{
				openOnStart.Value = false;
				SetVisible(value: true);
			}
			if (visible && autoRefreshSeconds.Value > 0.05f && Time.unscaledTime >= nextRefreshTime)
			{
				RefreshPlayers();
				nextRefreshTime = Time.unscaledTime + Mathf.Max(0.25f, autoRefreshSeconds.Value);
			}
			UpdateModalState();
		}

		private void OnGUI()
		{
			//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_0029: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (visible)
			{
				EnsureStyles();
				if (!centered)
				{
					CenterWindow();
				}
				int depth = GUI.depth;
				Color color = GUI.color;
				Matrix4x4 matrix = GUI.matrix;
				GUI.depth = -10000;
				GUI.color = Color.white;
				GUI.matrix = Matrix4x4.identity;
				GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)dimTexture, (ScaleMode)0);
				Rect val = ClampRect(windowRect);
				GUI.DrawTexture(val, (Texture)(object)windowTexture, (ScaleMode)0);
				GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 34f), (Texture)(object)headerTexture, (ScaleMode)0);
				windowRect = ClampRect(GUI.Window(405180, val, new WindowFunction(DrawWindow), GUIContent.none, windowStyle));
				GUI.depth = depth;
				GUI.color = color;
				GUI.matrix = matrix;
			}
		}

		private void DrawWindow(int id)
		{
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0317: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Fixed Player List", titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Refresh", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(100f),
				GUILayout.Height(30f)
			}))
			{
				RefreshPlayers();
			}
			if (GUILayout.Button("Close", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(80f),
				GUILayout.Height(30f)
			}))
			{
				SetVisible(value: false);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			GUILayout.BeginVertical(boxStyle, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			searchText = GUILayout.TextField(searchText ?? "", textFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinWidth(180f),
				GUILayout.Height(28f)
			});
			GUILayout.Space(8f);
			bool flag = GUILayout.Toggle(pauseGameWhileOpen.Value, "Pause game", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(115f) });
			if (flag != pauseGameWhileOpen.Value)
			{
				pauseGameWhileOpen.Value = flag;
				if (visible)
				{
					DeactivateModal();
					ActivateModal();
				}
			}
			bool flag2 = GUILayout.Toggle(showSteamIds.Value, "Show IDs", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			if (flag2 != showSteamIds.Value)
			{
				showSteamIds.Value = flag2;
			}
			GUILayout.EndHorizontal();
			GUILayout.Label(status, smallLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.Space(8f);
			DrawHeader();
			scroll = GUILayout.BeginScrollView(scroll, boxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			List<PlayerRow> list = FilteredPlayers();
			if (list.Count == 0)
			{
				GUILayout.Label("No players found. Join/host a session, then press Refresh.", labelStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				foreach (PlayerRow item in list)
				{
					DrawPlayerRow(item);
				}
			}
			GUILayout.EndScrollView();
			GUILayout.Space(6f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("F8 opens this menu. Host/server only can kick. BG Player List by Joive", smallLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label("Players: " + players.Count, smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 28f));
		}

		private void DrawHeader()
		{
			GUILayout.BeginHorizontal(boxStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Name", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(260f) });
			GUILayout.Label("Client", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) });
			if (showSteamIds.Value)
			{
				GUILayout.Label("Kick/Steam ID", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) });
			}
			GUILayout.FlexibleSpace();
			GUILayout.Label(((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsServer) ? "Action" : "Host only", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
			GUILayout.EndHorizontal();
		}

		private void DrawPlayerRow(PlayerRow player)
		{
			GUILayout.BeginHorizontal(boxStyle, Array.Empty<GUILayoutOption>());
			string text = player.DisplayName;
			if (player.IsLocal)
			{
				text += "  (you)";
			}
			if (player.IsHost)
			{
				text += "  [host]";
			}
			GUILayout.Label(text, labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(260f) });
			GUILayout.Label(player.ClientId.ToString(), labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) });
			if (showSteamIds.Value)
			{
				GUILayout.Label(player.KickIdText, smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) });
			}
			GUILayout.FlexibleSpace();
			GUI.enabled = (Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsServer && !player.IsLocal && player.IsConnected;
			bool flag = pendingKickClientId.HasValue && pendingKickClientId.Value == player.ClientId;
			string obj = ((confirmKick.Value && flag) ? "Confirm kick" : "Kick");
			GUIStyle val = ((confirmKick.Value && flag) ? dangerButtonStyle : buttonStyle);
			if (GUILayout.Button(obj, val, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(120f),
				GUILayout.Height(28f)
			}))
			{
				if (confirmKick.Value && !flag)
				{
					pendingKickClientId = player.ClientId;
					status = "Click Confirm kick for " + player.DisplayName + ".";
				}
				else
				{
					KickPlayer(player);
					pendingKickClientId = null;
				}
			}
			GUI.enabled = true;
			GUILayout.EndHorizontal();
		}

		private void RefreshPlayers()
		{
			players.Clear();
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				status = "NetworkManager.Singleton is null. Start or join a session first.";
				return;
			}
			Bootstrap component = ((Component)singleton).GetComponent<Bootstrap>();
			bool flag = (Object)(object)component != (Object)null && component.isOnlineMode;
			Dictionary<ulong, PlayerNetworking> dictionary = new Dictionary<ulong, PlayerNetworking>();
			try
			{
				PlayerNetworking[] array = Object.FindObjectsOfType<PlayerNetworking>();
				foreach (PlayerNetworking val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						ulong ownerClientId = ((NetworkBehaviour)val).OwnerClientId;
						dictionary[ownerClientId] = val;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("PlayerNetworking scan failed: " + ex.Message));
			}
			HashSet<ulong> hashSet = new HashSet<ulong>();
			try
			{
				foreach (NetworkClient connectedClients in singleton.ConnectedClientsList)
				{
					AddClientRow(singleton, component, flag, connectedClients.ClientId, dictionary, hashSet);
				}
			}
			catch (Exception ex2)
			{
				Log.LogWarning((object)("ConnectedClientsList scan failed: " + ex2.Message));
			}
			foreach (KeyValuePair<ulong, PlayerNetworking> item in dictionary)
			{
				if (!hashSet.Contains(item.Key))
				{
					AddPlayerRowFromPlayer(singleton, component, flag, item.Key, item.Value, hashSet);
				}
			}
			players.Sort(delegate(PlayerRow a, PlayerRow b)
			{
				int num = b.IsHost.CompareTo(a.IsHost);
				if (num != 0)
				{
					return num;
				}
				int num2 = b.IsLocal.CompareTo(a.IsLocal);
				return (num2 != 0) ? num2 : string.Compare(a.DisplayName, b.DisplayName, StringComparison.OrdinalIgnoreCase);
			});
			status = $"Refreshed {players.Count} player(s). Server: {singleton.IsServer}. Online: {flag}.";
		}

		private void AddClientRow(NetworkManager nm, Bootstrap bootstrap, bool online, ulong clientId, Dictionary<ulong, PlayerNetworking> byClientId, HashSet<ulong> added)
		{
			byClientId.TryGetValue(clientId, out var value);
			AddPlayerRowFromPlayer(nm, bootstrap, online, clientId, value, added);
		}

		private void AddPlayerRowFromPlayer(NetworkManager nm, Bootstrap bootstrap, bool online, ulong clientId, PlayerNetworking player, HashSet<ulong> added)
		{
			if (!added.Add(clientId))
			{
				return;
			}
			string playerName = GetPlayerName(player, clientId, nm);
			ulong kickId = clientId;
			string kickIdText = clientId.ToString();
			if (online)
			{
				if (TryGetSteamIdForClient(clientId, out var steamId))
				{
					kickId = steamId;
					kickIdText = steamId.ToString();
				}
				else
				{
					kickIdText = "steam id unavailable";
				}
			}
			players.Add(new PlayerRow
			{
				ClientId = clientId,
				KickId = kickId,
				KickIdText = kickIdText,
				DisplayName = playerName,
				IsLocal = (clientId == nm.LocalClientId),
				IsHost = (clientId == 0),
				IsConnected = true
			});
		}

		private string GetPlayerName(PlayerNetworking player, ulong clientId, NetworkManager nm)
		{
			if ((Object)(object)player != (Object)null)
			{
				try
				{
					SteamPlayer steamPlayer = player.SteamPlayer;
					string text = default(string);
					if ((Object)(object)steamPlayer != (Object)null && steamPlayer.TryGetName(ref text) && !string.IsNullOrWhiteSpace(text))
					{
						return text;
					}
				}
				catch
				{
				}
			}
			if (clientId == nm.LocalClientId)
			{
				return "Local Player";
			}
			if (clientId == 0L)
			{
				return "Host";
			}
			return "Client " + clientId;
		}

		private bool TryGetSteamIdForClient(ulong clientId, out ulong steamId)
		{
			steamId = 0uL;
			try
			{
				MethodInfo method = typeof(SteamPlayer).GetMethod("GetSteamId", BindingFlags.Static | BindingFlags.Public);
				if (method == null)
				{
					return false;
				}
				object obj = method.Invoke(null, new object[1] { clientId });
				if (obj == null)
				{
					return false;
				}
				return TryConvertSteamIdObject(obj, out steamId);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)$"Steam ID lookup failed for client {clientId}: {ex.Message}");
				return false;
			}
		}

		private bool TryConvertSteamIdObject(object value, out ulong steamId)
		{
			steamId = 0uL;
			if (value is ulong num)
			{
				steamId = num;
				return true;
			}
			Type type = value.GetType();
			string[] array = new string[5] { "Value", "value", "m_SteamID", "steamid", "SteamId" };
			foreach (string name in array)
			{
				FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && TryConvertToUInt64(field.GetValue(value), out steamId))
				{
					return true;
				}
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && TryConvertToUInt64(property.GetValue(value, null), out steamId))
				{
					return true;
				}
			}
			return ulong.TryParse(value.ToString(), out steamId);
		}

		private bool TryConvertToUInt64(object value, out ulong result)
		{
			result = 0uL;
			if (value == null)
			{
				return false;
			}
			if (value is ulong num)
			{
				result = num;
				return true;
			}
			if (value is long num2 && num2 >= 0)
			{
				result = (ulong)num2;
				return true;
			}
			return ulong.TryParse(value.ToString(), out result);
		}

		private void KickPlayer(PlayerRow player)
		{
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
				{
					status = "Only the host/server can kick players.";
					return;
				}
				Bootstrap component = ((Component)singleton).GetComponent<Bootstrap>();
				if ((Object)(object)component != (Object)null)
				{
					component.KickPlayer(player.KickId);
					status = "Kick requested for " + player.DisplayName + ".";
					Log.LogInfo((object)$"Kick requested: name={player.DisplayName}, client={player.ClientId}, kickId={player.KickId}");
				}
				else
				{
					singleton.DisconnectClient(player.ClientId);
					status = "Disconnected client " + player.ClientId + ".";
					Log.LogInfo((object)$"Disconnected client without Bootstrap: client={player.ClientId}");
				}
				RefreshPlayers();
			}
			catch (Exception ex)
			{
				status = "Kick failed: " + ex.Message;
				Log.LogError((object)$"Kick failed for {player.DisplayName} client={player.ClientId} kickId={player.KickId}: {ex}");
			}
		}

		private List<PlayerRow> FilteredPlayers()
		{
			string query = (searchText ?? "").Trim();
			if (query.Length == 0)
			{
				return players.ToList();
			}
			return players.Where((PlayerRow p) => Contains(p.DisplayName, query) || Contains(p.ClientId.ToString(), query) || Contains(p.KickIdText, query)).ToList();
		}

		private bool Contains(string value, string query)
		{
			if (value != null)
			{
				return value.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private void SetVisible(bool value)
		{
			if (visible != value)
			{
				visible = value;
				pendingKickClientId = null;
				if (visible)
				{
					centered = false;
					nextRefreshTime = 0f;
					RefreshPlayers();
					ActivateModal();
				}
				else
				{
					DeactivateModal();
				}
			}
		}

		private void UpdateModalState()
		{
			if (visible && !modalActive)
			{
				ActivateModal();
			}
			else if (!visible && modalActive)
			{
				DeactivateModal();
			}
			if (visible && (Object)(object)modalController != (Object)null)
			{
				SetControllerUiOpen(modalController, value: true);
			}
			if (visible && pauseGameWhileOpen.Value && Time.timeScale != 0f)
			{
				Time.timeScale = 0f;
			}
		}

		private void ActivateModal()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!modalActive)
			{
				modalActive = true;
				oldCursorVisible = Cursor.visible;
				oldCursorLock = Cursor.lockState;
				oldTimeScale = Time.timeScale;
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				modalController = FindLocalController();
				if ((Object)(object)modalController != (Object)null)
				{
					hadControllerUiOpen = TryGetControllerUiOpen(modalController, out oldControllerUiOpen);
					SetControllerUiOpen(modalController, value: true);
					CallRefreshMouseState(modalController);
				}
				if (pauseGameWhileOpen.Value)
				{
					Time.timeScale = 0f;
				}
			}
		}

		private void DeactivateModal()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!modalActive)
			{
				return;
			}
			if (pauseGameWhileOpen.Value)
			{
				Time.timeScale = ((oldTimeScale <= 0f) ? 1f : oldTimeScale);
			}
			if ((Object)(object)modalController != (Object)null)
			{
				if (hadControllerUiOpen)
				{
					SetControllerUiOpen(modalController, oldControllerUiOpen);
				}
				else
				{
					SetControllerUiOpen(modalController, value: false);
				}
				CallRefreshMouseState(modalController);
			}
			Cursor.visible = oldCursorVisible;
			Cursor.lockState = oldCursorLock;
			modalController = null;
			hadControllerUiOpen = false;
			oldControllerUiOpen = false;
			modalActive = false;
		}

		private PlayerController FindLocalController()
		{
			try
			{
				PlayerNetworking val = ((IEnumerable<PlayerNetworking>)Object.FindObjectsOfType<PlayerNetworking>()).FirstOrDefault((Func<PlayerNetworking, bool>)((PlayerNetworking p) => (Object)(object)p != (Object)null && ((NetworkBehaviour)p).IsLocalPlayer));
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				FieldInfo field = typeof(PlayerNetworking).GetField("controller", BindingFlags.Instance | BindingFlags.NonPublic);
				return (PlayerController)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
			}
			catch
			{
				return null;
			}
		}

		private bool TryGetControllerUiOpen(PlayerController controller, out bool value)
		{
			value = false;
			try
			{
				FieldInfo field = typeof(PlayerController).GetField("isUiOpen", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field == null)
				{
					return false;
				}
				value = (bool)field.GetValue(controller);
				return true;
			}
			catch
			{
				return false;
			}
		}

		private void SetControllerUiOpen(PlayerController controller, bool value)
		{
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			try
			{
				FieldInfo field = typeof(PlayerController).GetField("isUiOpen", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(controller, value);
				}
			}
			catch
			{
			}
		}

		private void CallRefreshMouseState(PlayerController controller)
		{
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			try
			{
				typeof(PlayerController).GetMethod("RefreshMouseState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(controller, null);
			}
			catch
			{
			}
		}

		private KeyCode ParseKey(string text, KeyCode fallback)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Enum.TryParse<KeyCode>(text, ignoreCase: true, out KeyCode result))
				{
					return result;
				}
			}
			catch
			{
			}
			return fallback;
		}

		private void CenterWindow()
		{
			float num = Mathf.Min(760f, (float)Screen.width - 30f);
			float num2 = Mathf.Min(520f, (float)Screen.height - 30f);
			((Rect)(ref windowRect)).width = Mathf.Max(520f, num);
			((Rect)(ref windowRect)).height = Mathf.Max(380f, num2);
			((Rect)(ref windowRect)).x = Mathf.Max(10f, ((float)Screen.width - ((Rect)(ref windowRect)).width) * 0.5f);
			((Rect)(ref windowRect)).y = Mathf.Max(10f, ((float)Screen.height - ((Rect)(ref windowRect)).height) * 0.5f);
			centered = true;
		}

		private Rect ClampRect(Rect rect)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			((Rect)(ref rect)).width = Mathf.Min(((Rect)(ref rect)).width, (float)Screen.width - 20f);
			((Rect)(ref rect)).height = Mathf.Min(((Rect)(ref rect)).height, (float)Screen.height - 20f);
			((Rect)(ref rect)).x = Mathf.Clamp(((Rect)(ref rect)).x, 10f, Mathf.Max(10f, (float)Screen.width - ((Rect)(ref rect)).width - 10f));
			((Rect)(ref rect)).y = Mathf.Clamp(((Rect)(ref rect)).y, 10f, Mathf.Max(10f, (float)Screen.height - ((Rect)(ref rect)).height - 10f));
			return rect;
		}

		private void EnsureStyles()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00af: 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_00ed: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_018b: Expected O, but got Unknown
			//IL_0192: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01d7: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: 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_01f6: 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_021f: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: 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_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Expected O, but got Unknown
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Expected O, but got Unknown
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Expected O, but got Unknown
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Expected O, but got Unknown
			//IL_036e: Expected O, but got Unknown
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Expected O, but got Unknown
			//IL_03ac: Expected O, but got Unknown
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			if (windowStyle == null)
			{
				dimTexture = MakeTexture(new Color(0f, 0f, 0f, 0.72f));
				windowTexture = MakeTexture(new Color(0.01f, 0.015f, 0.023f, 1f));
				headerTexture = MakeTexture(new Color(0.02f, 0.033f, 0.048f, 1f));
				Texture2D texture = windowTexture;
				Texture2D val = MakeTexture(new Color(0.045f, 0.07f, 0.1f, 1f));
				Texture2D background = MakeTexture(new Color(0.07f, 0.12f, 0.17f, 1f));
				Texture2D val2 = MakeTexture(new Color(0.06f, 0.32f, 0.46f, 1f));
				Texture2D texture2 = MakeTexture(new Color(0.42f, 0.07f, 0.06f, 1f));
				Texture2D background2 = MakeTexture(new Color(0.62f, 0.12f, 0.1f, 1f));
				Texture2D texture3 = MakeTexture(new Color(0.012f, 0.018f, 0.027f, 1f));
				Texture2D texture4 = MakeTexture(new Color(0.035f, 0.05f, 0.07f, 1f));
				windowStyle = new GUIStyle(GUIStyle.none)
				{
					padding = new RectOffset(16, 16, 14, 14),
					border = new RectOffset(0, 0, 0, 0)
				};
				SetAllStates(windowStyle, texture, Color.white);
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					fontSize = 18,
					fontStyle = (FontStyle)1
				};
				val3.normal.textColor = Color.white;
				titleStyle = val3;
				GUIStyle val4 = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					fontSize = 13
				};
				val4.normal.textColor = new Color(0.88f, 0.93f, 0.96f, 1f);
				labelStyle = val4;
				GUIStyle val5 = new GUIStyle(labelStyle)
				{
					fontSize = 11
				};
				val5.normal.textColor = new Color(0.62f, 0.7f, 0.76f, 1f);
				val5.wordWrap = true;
				smallLabelStyle = val5;
				buttonStyle = new GUIStyle(GUI.skin.button)
				{
					alignment = (TextAnchor)4,
					fontSize = 12,
					fontStyle = (FontStyle)1
				};
				SetAllStates(buttonStyle, val, Color.white);
				buttonStyle.hover.background = background;
				buttonStyle.active.background = val2;
				buttonStyle.focused.background = val;
				activeButtonStyle = new GUIStyle(buttonStyle);
				SetAllStates(activeButtonStyle, val2, Color.white);
				dangerButtonStyle = new GUIStyle(buttonStyle);
				SetAllStates(dangerButtonStyle, texture2, Color.white);
				dangerButtonStyle.hover.background = background2;
				dangerButtonStyle.active.background = background2;
				boxStyle = new GUIStyle(GUI.skin.box)
				{
					padding = new RectOffset(8, 8, 6, 6),
					margin = new RectOffset(2, 2, 2, 4)
				};
				SetAllStates(boxStyle, texture3, Color.white);
				textFieldStyle = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 13,
					padding = new RectOffset(8, 8, 5, 5)
				};
				SetAllStates(textFieldStyle, texture4, Color.white);
				textFieldStyle.normal.textColor = Color.white;
				textFieldStyle.focused.textColor = Color.white;
			}
		}

		private static Texture2D MakeTexture(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}

		private static void SetAllStates(GUIStyle style, Texture2D texture, Color textColor)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			style.normal.background = texture;
			style.hover.background = texture;
			style.active.background = texture;
			style.focused.background = texture;
			style.onNormal.background = texture;
			style.onHover.background = texture;
			style.onActive.background = texture;
			style.onFocused.background = texture;
			style.normal.textColor = textColor;
			style.hover.textColor = textColor;
			style.active.textColor = textColor;
			style.focused.textColor = textColor;
			style.onNormal.textColor = textColor;
			style.onHover.textColor = textColor;
			style.onActive.textColor = textColor;
			style.onFocused.textColor = textColor;
		}
	}
}