Decompiled source of LobbyBrowser v1.0.2

BoplLobbyBrowser.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("BoplLobbyBrowser")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoplLobbyBrowser")]
[assembly: AssemblyTitle("BoplLobbyBrowser")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
[BepInPlugin("com.creed.bopl.lobbybrowser", "Bopl Lobby Browser", "1.4.0")]
public sealed class BoplLobbyBrowserPlugin : BaseUnityPlugin
{
	private sealed class LobbyEntry
	{
		public Lobby Lobby { get; }

		public string IdText { get; }

		public int MemberCount { get; }

		public int MaxMembers { get; }

		public bool Compatible { get; }

		public bool Expanded { get; set; }

		public LobbyEntry(Lobby lobby, string idText, int memberCount, int maxMembers, bool compatible)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Lobby = lobby;
			IdText = idText;
			MemberCount = memberCount;
			MaxMembers = maxMembers;
			Compatible = compatible;
			Expanded = false;
		}

		public bool Matches(string query)
		{
			if (string.IsNullOrWhiteSpace(query))
			{
				return true;
			}
			return IdText.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0;
		}
	}

	private const int MaxLobbyResults = 20;

	private const float JoinConfirmationTimeout = 20f;

	private const float LobbyCheckInterval = 0.25f;

	private const float WindowWidth = 620f;

	private const float WindowHeight = 460f;

	private readonly List<LobbyEntry> _regionalLobbies = new List<LobbyEntry>();

	private readonly List<LobbyEntry> _globalLobbies = new List<LobbyEntry>();

	private ConfigEntry<KeyboardShortcut> _toggleKey;

	private Vector2 _scrollPosition;

	private Rect _windowRect;

	private string _searchText = string.Empty;

	private string _status = "Press P to search regional and global public lobbies.";

	private string _regionalStatus = "Not searched.";

	private string _globalStatus = "Not searched.";

	private string[] _currentLobbyRoster = Array.Empty<string>();

	private string _currentLobbyIdText = string.Empty;

	private bool _isOpen;

	private bool _isRefreshing;

	private bool _isJoining;

	private bool _regionalExpanded = true;

	private bool _globalExpanded = true;

	private float _nextLobbyCheck;

	private float _nextRosterRefresh;

	private float _joinStartedAt;

	private ulong _currentLobbyId;

	private ulong _pendingJoinLobbyId;

	private bool _clientSideAllowanceRegistered;

	private GUIStyle _creditStyle;

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "ToggleKey", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Open or close the lobby browser.");
		UpdateWindowBounds();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[LobbyBrowser] loaded. Press P to list compatible public lobbies; no lobby is joined automatically.");
	}

	private void Start()
	{
		if (_clientSideAllowanceRegistered)
		{
			return;
		}
		try
		{
			CharacterSelectHandler_online.clientSideMods_you_can_increment_this_to_enable_matchmaking_for_your_mods__please_dont_use_it_to_cheat_thats_really_cringe_especially_if_its_desyncing_others___you_didnt_even_win_on_your_opponents_screen___I_cannot_imagine_a_sadder_existence++;
			_clientSideAllowanceRegistered = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[LobbyBrowser] registered one client-side mod allowance in Start.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[LobbyBrowser] failed to register client-side mod allowance: " + ex));
		}
	}

	private void Update()
	{
		//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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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)
		float unscaledTime = Time.unscaledTime;
		if ((_isOpen || _pendingJoinLobbyId != 0L) && unscaledTime >= _nextLobbyCheck)
		{
			ObserveCurrentLobby();
			_nextLobbyCheck = unscaledTime + ((_pendingJoinLobbyId == 0L) ? 1f : 0.25f);
		}
		if (_isOpen && unscaledTime >= _nextRosterRefresh)
		{
			RefreshCurrentLobbyRoster();
			_nextRosterRefresh = unscaledTime + 1f;
		}
		if (Keyboard.current == null)
		{
			return;
		}
		try
		{
			KeyboardShortcut value = _toggleKey.Value;
			Key val = ConvertKey(((KeyboardShortcut)(ref value)).MainKey);
			if ((int)val != 0 && ((ButtonControl)Keyboard.current[val]).wasPressedThisFrame && (!_isOpen || string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())))
			{
				_isOpen = !_isOpen;
				if (_isOpen)
				{
					ObserveCurrentLobby();
					_nextLobbyCheck = Time.unscaledTime + 1f;
				}
				if (_isOpen && _regionalLobbies.Count == 0 && _globalLobbies.Count == 0)
				{
					RefreshLobbies();
				}
			}
			if (_isOpen && ((ButtonControl)Keyboard.current.escapeKey).wasPressedThisFrame)
			{
				_isOpen = false;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[LobbyBrowser] input handling failed: " + ex));
		}
	}

	private static Key ConvertKey(KeyCode keyCode)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Invalid comparison between Unknown and I4
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected I4, but got Unknown
		if ((int)keyCode >= 97 && (int)keyCode <= 122)
		{
			return (Key)(15 + (keyCode - 97));
		}
		if ((int)keyCode != 27)
		{
			if ((int)keyCode != 112)
			{
				return (Key)((keyCode - 282) switch
				{
					0 => 94, 
					1 => 95, 
					2 => 96, 
					3 => 97, 
					4 => 98, 
					5 => 99, 
					6 => 100, 
					7 => 101, 
					8 => 102, 
					9 => 103, 
					10 => 104, 
					11 => 105, 
					_ => 0, 
				});
			}
			return (Key)30;
		}
		return (Key)60;
	}

	private async void RefreshLobbies()
	{
		if (_isRefreshing)
		{
			return;
		}
		_isRefreshing = true;
		_status = "Searching regionally, then across all regions for version " + Constants.version + "...";
		try
		{
			if (!SteamClient.IsValid || !SteamClient.IsLoggedOn)
			{
				_status = "Steam is not initialized or not logged in.";
				_regionalLobbies.Clear();
				_globalLobbies.Clear();
				return;
			}
			_regionalStatus = "Searching...";
			_globalStatus = "Waiting for regional search...";
			_regionalLobbies.Clear();
			_globalLobbies.Clear();
			Lobby[] results = await RequestLobbies(regional: true);
			AddResults(_regionalLobbies, results);
			_regionalStatus = _regionalLobbies.Count + " compatible open lobby/lobbies.";
			_globalStatus = "Searching worldwide...";
			AddGlobalResults(await RequestLobbies(regional: false));
			_globalStatus = _globalLobbies.Count + " additional worldwide lobby/lobbies.";
			_status = "Search complete. Regional results are listed separately from additional worldwide results.";
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[LobbyBrowser] search completed; regional=" + _regionalLobbies.Count + ", additional worldwide=" + _globalLobbies.Count + "."));
		}
		catch (Exception ex)
		{
			_status = "Lobby search failed: " + ex.GetType().Name + " (see BepInEx log).";
			((BaseUnityPlugin)this).Logger.LogError((object)("[LobbyBrowser] lobby search failed: " + ex));
		}
		finally
		{
			_isRefreshing = false;
		}
	}

	private static async Task<Lobby[]> RequestLobbies(bool regional)
	{
		LobbyQuery val = SteamMatchmaking.LobbyList;
		val = ((LobbyQuery)(ref val)).WithMaxResults(20);
		val = ((LobbyQuery)(ref val)).WithKeyValue("version", Constants.version);
		LobbyQuery val2 = ((LobbyQuery)(ref val)).WithSlotsAvailable(1);
		val2 = (regional ? ((LobbyQuery)(ref val2)).FilterDistanceClose() : ((LobbyQuery)(ref val2)).FilterDistanceWorldwide());
		return await ((LobbyQuery)(ref val2)).RequestAsync();
	}

	private void AddResults(List<LobbyEntry> destination, Lobby[] results)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		if (results == null)
		{
			return;
		}
		for (int i = 0; i < results.Length; i++)
		{
			if (SteamId.op_Implicit(((Lobby)(ref results[i])).Id) != _currentLobbyId)
			{
				destination.Add(CreateLobbyEntry(results[i]));
			}
		}
	}

	private void AddGlobalResults(Lobby[] results)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		if (results == null)
		{
			return;
		}
		HashSet<ulong> hashSet = new HashSet<ulong>();
		for (int i = 0; i < _regionalLobbies.Count; i++)
		{
			Lobby lobby = _regionalLobbies[i].Lobby;
			hashSet.Add(SteamId.op_Implicit(((Lobby)(ref lobby)).Id));
		}
		for (int j = 0; j < results.Length; j++)
		{
			ulong num = SteamId.op_Implicit(((Lobby)(ref results[j])).Id);
			if (!hashSet.Contains(num) && num != _currentLobbyId)
			{
				_globalLobbies.Add(CreateLobbyEntry(results[j]));
			}
		}
	}

	private void ObserveCurrentLobby()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			SteamManager instance = SteamManager.instance;
			ulong currentLobbyId = _currentLobbyId;
			_currentLobbyId = (((Object)(object)instance == (Object)null) ? 0 : SteamId.op_Implicit(((Lobby)(ref instance.currentLobby)).Id));
			if (_currentLobbyId != 0L && _currentLobbyId != currentLobbyId)
			{
				RemoveLobbyFromSearchResults(_currentLobbyId);
			}
			if (_pendingJoinLobbyId != 0L && _currentLobbyId == _pendingJoinLobbyId)
			{
				_pendingJoinLobbyId = 0uL;
				_isJoining = false;
				_status = "Joined lobby " + _currentLobbyId + ".";
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[LobbyBrowser] confirmed lobby join by current lobby ID " + _currentLobbyId + "."));
			}
			else if (_pendingJoinLobbyId != 0L && Time.realtimeSinceStartup - _joinStartedAt >= 20f)
			{
				ulong pendingJoinLobbyId = _pendingJoinLobbyId;
				_pendingJoinLobbyId = 0uL;
				_isJoining = false;
				_status = "Join was not confirmed: current lobby ID did not match lobby " + pendingJoinLobbyId + ".";
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[LobbyBrowser] join timed out without current lobby ID matching " + pendingJoinLobbyId + "."));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[LobbyBrowser] could not check current lobby ID: " + ex.Message));
		}
	}

	private void RemoveLobbyFromSearchResults(ulong lobbyId)
	{
		_regionalLobbies.RemoveAll(delegate(LobbyEntry entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			Lobby lobby = entry.Lobby;
			return SteamId.op_Implicit(((Lobby)(ref lobby)).Id) == lobbyId;
		});
		_globalLobbies.RemoveAll(delegate(LobbyEntry entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			Lobby lobby = entry.Lobby;
			return SteamId.op_Implicit(((Lobby)(ref lobby)).Id) == lobbyId;
		});
	}

	private unsafe void RefreshCurrentLobbyRoster()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			SteamManager instance = SteamManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				_currentLobbyRoster = Array.Empty<string>();
				_currentLobbyIdText = string.Empty;
				return;
			}
			Lobby currentLobby = instance.currentLobby;
			if (SteamId.op_Implicit(((Lobby)(ref currentLobby)).Id) == 0L)
			{
				_currentLobbyRoster = Array.Empty<string>();
				_currentLobbyIdText = string.Empty;
				return;
			}
			_currentLobbyIdText = ((object)((Lobby)(ref currentLobby)).Id/*cast due to .constrained prefix*/).ToString();
			Dictionary<ulong, string> dictionary = new Dictionary<ulong, string>();
			if (instance.connectedPlayers != null)
			{
				for (int i = 0; i < instance.connectedPlayers.Count; i++)
				{
					SteamConnection val = instance.connectedPlayers[i];
					if (val != null)
					{
						dictionary[SteamId.op_Implicit(val.id)] = Mathf.RoundToInt(val.Ping * 1000f) + " ms";
					}
				}
			}
			List<string> list = new List<string>();
			foreach (Friend member in ((Lobby)(ref currentLobby)).Members)
			{
				Friend current = member;
				string? text;
				if (!string.IsNullOrEmpty(((Friend)(ref current)).Name))
				{
					text = ((Friend)(ref current)).Name;
				}
				else
				{
					SteamId id = current.Id;
					text = ((object)(*(SteamId*)(&id))/*cast due to .constrained prefix*/).ToString();
				}
				string text2 = text;
				bool flag = SteamId.op_Implicit(current.Id) == SteamId.op_Implicit(((Lobby)(ref currentLobby)).Owner.Id);
				if (!dictionary.TryGetValue(SteamId.op_Implicit(current.Id), out var value))
				{
					value = "Ping unavailable";
				}
				list.Add((flag ? "HOST  " : string.Empty) + text2 + "  |  " + value);
			}
			_currentLobbyRoster = list.ToArray();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[LobbyBrowser] could not refresh current lobby roster: " + ex.Message));
		}
	}

	private static LobbyEntry CreateLobbyEntry(Lobby lobby)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return new LobbyEntry(lobby, ((object)((Lobby)(ref lobby)).Id/*cast due to .constrained prefix*/).ToString(), ((Lobby)(ref lobby)).MemberCount, ((Lobby)(ref lobby)).MaxMembers, string.Equals(((Lobby)(ref lobby)).GetData("version"), Constants.version, StringComparison.Ordinal));
	}

	private void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (_isOpen)
		{
			UpdateWindowBounds();
			_windowRect = GUI.Window(((Object)this).GetInstanceID(), _windowRect, new WindowFunction(DrawWindow), "Bopl Lobby Browser");
		}
	}

	private void UpdateWindowBounds()
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Min(620f, Mathf.Max(320f, (float)Screen.width - 16f));
		float num2 = Mathf.Min(460f, Mathf.Max(240f, (float)Screen.height - 16f));
		if (((Rect)(ref _windowRect)).width <= 0f || ((Rect)(ref _windowRect)).height <= 0f)
		{
			_windowRect = new Rect(Mathf.Max(0f, ((float)Screen.width - num) * 0.5f), Mathf.Max(0f, ((float)Screen.height - num2) * 0.5f), num, num2);
			return;
		}
		((Rect)(ref _windowRect)).width = num;
		((Rect)(ref _windowRect)).height = num2;
		((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - num));
		((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - num2));
	}

	private void DrawWindow(int windowId)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("P: toggle | Esc: close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		if (_creditStyle == null)
		{
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = 9
			};
			val.normal.textColor = new Color(1f, 1f, 1f, 0.55f);
			_creditStyle = val;
		}
		GUILayout.Label("Made by UxCreed", _creditStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(84f) });
		GUILayout.FlexibleSpace();
		if (GUILayout.Button(_isRefreshing ? "Searching..." : "Refresh", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(84f) }) && !_isRefreshing)
		{
			RefreshLobbies();
		}
		if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
		{
			_isOpen = false;
		}
		GUILayout.EndHorizontal();
		_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
		GUILayout.Label("Compatible version: " + Constants.version + " | Open public lobbies with a free slot.", Array.Empty<GUILayoutOption>());
		GUILayout.Label(_status, Array.Empty<GUILayoutOption>());
		DrawCurrentLobby();
		GUI.SetNextControlName("LobbyBrowserSearch");
		_searchText = GUILayout.TextField(_searchText ?? string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(22f) });
		_regionalExpanded = DrawLobbySection("Regional", _regionalStatus, _regionalLobbies, _regionalExpanded);
		_globalExpanded = DrawLobbySection("Global (outside regional results)", _globalStatus, _globalLobbies, _globalExpanded);
		GUILayout.EndScrollView();
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width, 24f));
	}

	private void DrawCurrentLobby()
	{
		GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
		if (_currentLobbyRoster.Length == 0)
		{
			GUILayout.Label("Not currently in a lobby.", Array.Empty<GUILayoutOption>());
		}
		else
		{
			GUILayout.Label("Currently in lobby " + _currentLobbyIdText + "  |  " + _currentLobbyRoster.Length + " player(s)", Array.Empty<GUILayoutOption>());
			for (int i = 0; i < _currentLobbyRoster.Length; i++)
			{
				GUILayout.Label("  " + _currentLobbyRoster[i], Array.Empty<GUILayoutOption>());
			}
		}
		GUILayout.EndVertical();
	}

	private bool DrawLobbySection(string title, string status, List<LobbyEntry> entries, bool expanded)
	{
		expanded = GUILayout.Toggle(expanded, title + "  (" + entries.Count + ")  |  " + status, GUI.skin.button, Array.Empty<GUILayoutOption>());
		if (!expanded)
		{
			return false;
		}
		bool flag = false;
		for (int i = 0; i < entries.Count; i++)
		{
			LobbyEntry lobbyEntry = entries[i];
			if (lobbyEntry.Matches(_searchText))
			{
				flag = true;
				DrawLobbyEntry(lobbyEntry);
			}
		}
		if (!flag)
		{
			GUILayout.Label((entries.Count == 0) ? "  No results yet." : "  No lobbies match that search.", Array.Empty<GUILayoutOption>());
		}
		return expanded;
	}

	private void DrawLobbyEntry(LobbyEntry entry)
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		entry.Expanded = GUILayout.Toggle(entry.Expanded, entry.Expanded ? "Collapse" : "Expand", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
		GUILayout.Label(entry.MemberCount + "/" + entry.MaxMembers + " players  |  Lobby " + entry.IdText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		GUI.enabled = entry.Compatible && !_isJoining;
		if (GUILayout.Button(_isJoining ? "Joining..." : "Join", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }))
		{
			JoinLobby(entry.Lobby, entry);
		}
		GUI.enabled = true;
		GUILayout.EndHorizontal();
		if (entry.Expanded)
		{
			GUILayout.Label("Player names and ping are shown only after you join this lobby.", Array.Empty<GUILayoutOption>());
		}
		GUILayout.EndVertical();
	}

	private void JoinLobby(Lobby lobby, LobbyEntry entry)
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if (_isJoining || !SteamClient.IsValid || !SteamClient.IsLoggedOn)
		{
			return;
		}
		string data = ((Lobby)(ref lobby)).GetData("version");
		if (!entry.Compatible || !string.Equals(data, Constants.version, StringComparison.Ordinal))
		{
			_status = "This lobby is running a different game version and cannot be joined.";
			return;
		}
		try
		{
			SteamManager instance = SteamManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				_status = "The game's SteamManager is not ready.";
				return;
			}
			MethodInfo method = typeof(SteamManager).GetMethod("JoinLobby", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(Lobby) }, null);
			if (method == null)
			{
				_status = "The game's lobby-join method was not found.";
				((BaseUnityPlugin)this).Logger.LogError((object)"[LobbyBrowser] SteamManager.JoinLobby(Lobby) not found; refusing to join through a fallback path.");
				return;
			}
			_isJoining = true;
			_joinStartedAt = Time.realtimeSinceStartup;
			_pendingJoinLobbyId = SteamId.op_Implicit(((Lobby)(ref lobby)).Id);
			_status = "Asking the game's normal lobby flow to join lobby " + entry.IdText + "...";
			method.Invoke(instance, new object[1] { lobby });
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[LobbyBrowser] requested join via SteamManager.JoinLobby for lobby " + ((object)((Lobby)(ref lobby)).Id/*cast due to .constrained prefix*/).ToString() + "."));
		}
		catch (Exception ex)
		{
			_isJoining = false;
			_pendingJoinLobbyId = 0uL;
			_status = "Could not request lobby join; see BepInEx log.";
			((BaseUnityPlugin)this).Logger.LogError((object)("[LobbyBrowser] failed to invoke game's lobby join flow: " + ex));
		}
	}
}