Decompiled source of Holdens Lobby Viewer Plus v2.0.2

HoldensLobbyViewer.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Realtime;
using Steamworks;
using TMPro;
using ThirdPersonMod;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HoldensLobbyViewer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Holden")]
[assembly: AssemblyProduct("HoldensLobbyViewer")]
[assembly: AssemblyCopyright("Copyright © Holden 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("12aa83f7-baa2-4332-be61-e878ccf60e56")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ThirdPersonMod
{
	public class ReflectionUtil<R>
	{
		private const BindingFlags privateInst = BindingFlags.Instance | BindingFlags.NonPublic;

		private const BindingFlags privateStatic = BindingFlags.Static | BindingFlags.NonPublic;

		private const BindingFlags privateField = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField;

		private const BindingFlags privateProp = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty;

		private const BindingFlags privateMethod = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

		private const BindingFlags staticField = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField;

		private const BindingFlags staticProp = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty;

		private const BindingFlags staticMethod = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

		private R @object { get; }

		private Type type { get; }

		internal ReflectionUtil(R obj)
		{
			@object = obj;
			type = typeof(R);
		}

		private object GetValue(string variableName, BindingFlags flags)
		{
			FieldInfo field = type.GetField(variableName, flags);
			if (!(field != null))
			{
				return null;
			}
			return field.GetValue(@object);
		}

		private object GetProperty(string propertyName, BindingFlags flags)
		{
			PropertyInfo property = type.GetProperty(propertyName, flags);
			if (!(property != null))
			{
				return null;
			}
			return property.GetValue(@object);
		}

		private void SetValue(string variableName, object value, BindingFlags flags)
		{
			FieldInfo field = type.GetField(variableName, flags);
			if (field != null)
			{
				field.SetValue(@object, value);
			}
		}

		private void SetProperty(string propertyName, object value, BindingFlags flags)
		{
			PropertyInfo property = type.GetProperty(propertyName, flags);
			if (property != null)
			{
				property.SetValue(@object, value);
			}
		}

		private object InvokeMethod(string methodName, BindingFlags flags, params object[] args)
		{
			MethodInfo[] methods = type.GetMethods(flags);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name == methodName && MatchMethodParameters(methodInfo, args))
				{
					return methodInfo.Invoke(@object, args);
				}
			}
			return null;
		}

		private bool MatchMethodParameters(MethodInfo method, object[] args)
		{
			ParameterInfo[] parameters = method.GetParameters();
			if (parameters.Length != args.Length)
			{
				return false;
			}
			for (int i = 0; i < parameters.Length; i++)
			{
				if (!parameters[i].ParameterType.IsInstanceOfType(args[i]) && args[i] != null)
				{
					return false;
				}
			}
			return true;
		}

		public object GetValue(string fieldName, bool isStatic = false, bool isProperty = false)
		{
			BindingFlags flags = ((!isProperty) ? (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField)) : (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty)));
			if (!isProperty)
			{
				return GetValue(fieldName, flags);
			}
			return GetProperty(fieldName, flags);
		}

		public void SetValue(string fieldName, object value, bool isStatic = false, bool isProperty = false)
		{
			BindingFlags flags = ((!isProperty) ? (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField)) : (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty)));
			if (isProperty)
			{
				SetProperty(fieldName, value, flags);
			}
			else
			{
				SetValue(fieldName, value, flags);
			}
		}

		public object Invoke(string methodName, bool isStatic = false, params object[] args)
		{
			return InvokeMethod(methodName, isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod), args);
		}
	}
	public static class ReflectorExtensions
	{
		public static ReflectionUtil<R> Reflect<R>(this R obj)
		{
			return new ReflectionUtil<R>(obj);
		}
	}
}
namespace HoldensLobbyViewer
{
	public class LobbyManager : MonoBehaviour
	{
		private Callback<LobbyMatchList_t> lobbyMatchListCallback;

		public List<CSteamID> lobbyList = new List<CSteamID>();

		public List<CSteamID> usLobbies = new List<CSteamID>();

		public List<CSteamID> uswLobbies = new List<CSteamID>();

		public List<CSteamID> asiaLobbies = new List<CSteamID>();

		public List<CSteamID> saLobbies = new List<CSteamID>();

		public List<CSteamID> euLobbies = new List<CSteamID>();

		public void Start()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			SteamAPI.Init();
			lobbyMatchListCallback = Callback<LobbyMatchList_t>.Create((DispatchDelegate<LobbyMatchList_t>)OnLobbyMatchList);
			BuildVersion val = new BuildVersion(Application.version);
			SteamMatchmaking.AddRequestLobbyListStringFilter("ContentWarningVersion", ((BuildVersion)(ref val)).ToMatchmaking(), (ELobbyComparison)0);
			SteamMatchmaking.AddRequestLobbyListFilterSlotsAvailable(1);
			SteamMatchmaking.AddRequestLobbyListDistanceFilter((ELobbyDistanceFilter)3);
			SteamMatchmaking.RequestLobbyList();
		}

		private void OnLobbyMatchList(LobbyMatchList_t callback)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			lobbyList.Clear();
			usLobbies.Clear();
			uswLobbies.Clear();
			asiaLobbies.Clear();
			saLobbies.Clear();
			euLobbies.Clear();
			for (int i = 0; i < callback.m_nLobbiesMatching; i++)
			{
				CSteamID lobbyByIndex = SteamMatchmaking.GetLobbyByIndex(i);
				lobbyList.Add(lobbyByIndex);
				addRoomToRegionList(lobbyByIndex);
			}
		}

		private void addRoomToRegionList(CSteamID room)
		{
			//IL_0000: 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_0037: 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_0069: 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)
			string lobbyData = SteamMatchmaking.GetLobbyData(room, "PhotonRegion");
			if (lobbyData == "us")
			{
				usLobbies.Add(room);
			}
			if (lobbyData == "usw")
			{
				uswLobbies.Add(room);
			}
			if (lobbyData == "asia")
			{
				asiaLobbies.Add(room);
			}
			if (lobbyData == "sa")
			{
				saLobbies.Add(room);
			}
			if (lobbyData == "eu")
			{
				euLobbies.Add(room);
			}
		}

		private void OnDestroy()
		{
			SteamAPI.Shutdown();
		}
	}
	public enum LobbyCategory
	{
		us,
		usw,
		asia,
		sa,
		eu,
		all
	}
	internal class LobbyMenu : Singleton<LobbyMenu>
	{
		public CW_TAB firstTab;

		public CW_TABS categoryTabs;

		public Transform m_lobbiesContainer;

		private GameObject layoutGroupGO;

		private GameObject svGO;

		public static LobbyCategory currentCategory = LobbyCategory.all;

		public static Button usBtn;

		public static Button uswBtn;

		public static Button asiaBtn;

		public static Button euBtn;

		public static Button saBtn;

		public static Button allBtn;

		private ScrollRect scrollRect;

		public static CSteamID lastJoinedRoom;

		public static LoadBalancingClient NetworkingClient;

		private Dictionary<string, Button> m_buttons = new Dictionary<string, Button>();

		private Dictionary<string, string> m_hosts = new Dictionary<string, string>();

		public static List<string> m_brokenList = new List<string>();

		private float timer;

		private float interval = 0.5f;

		private void Start()
		{
			svGO = CreateScrollableVerticalLayoutGroup();
		}

		private void OnEnable()
		{
			Show(currentCategory);
		}

		private void Show(LobbyCategory category)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			if (LobbyMain.lobbyManager.lobbyList.Count > 0)
			{
				SetupBtnNames();
				foreach (CSteamID lobby in LobbyMain.lobbyManager.lobbyList)
				{
					CSteamID room = lobby;
					if (!((CSteamID)(ref room)).IsValid())
					{
						continue;
					}
					string lobbyData = SteamMatchmaking.GetLobbyData(room, "PhotonRegion");
					if (currentCategory.ToString() != "all" && lobbyData != currentCategory.ToString())
					{
						continue;
					}
					hashSet.Add(((object)(CSteamID)(ref room)).ToString());
					if (!m_brokenList.Contains(((object)(CSteamID)(ref room)).ToString()) & !m_buttons.ContainsKey(((object)(CSteamID)(ref room)).ToString()))
					{
						SteamMatchmaking.JoinLobby(room);
						if ((bool)new ReflectionUtil<SteamLobbyHandler>(MainMenuHandler.SteamLobbyHandler).GetValue("m_isJoining"))
						{
							continue;
						}
						int lobbyMemberLimit = SteamMatchmaking.GetLobbyMemberLimit(room);
						int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(room);
						string friendPersonaName = SteamFriends.GetFriendPersonaName(SteamMatchmaking.GetLobbyOwner(room));
						friendPersonaName = friendPersonaName.Substring(0, Math.Min(8, friendPersonaName.Length));
						if (friendPersonaName == "")
						{
							continue;
						}
						string btnText = $"Host: {friendPersonaName} | {lobbyData.ToUpper()} | Players: {numLobbyMembers}/{lobbyMemberLimit}";
						Button component = MainMenu.CreateBtnCopy(((object)(CSteamID)(ref room)).ToString() ?? "", btnText, 100f, layoutGroupGO.transform).GetComponent<Button>();
						((UnityEvent)component.onClick).AddListener((UnityAction)delegate
						{
							//IL_0007: Unknown result type (might be due to invalid IL or missing references)
							OnServerButtonClicked(room);
						});
						m_buttons.Add(((object)(CSteamID)(ref room)).ToString(), component);
						m_hosts.Add(((object)(CSteamID)(ref room)).ToString(), friendPersonaName);
						SteamMatchmaking.LeaveLobby(room);
					}
					if (m_buttons.ContainsKey(((object)(CSteamID)(ref room)).ToString()))
					{
						int lobbyMemberLimit2 = SteamMatchmaking.GetLobbyMemberLimit(room);
						int numLobbyMembers2 = SteamMatchmaking.GetNumLobbyMembers(room);
						string text = m_hosts[((object)(CSteamID)(ref room)).ToString()];
						string text2 = $"Host: {text} | {lobbyData.ToUpper()} | Players: {numLobbyMembers2}/{lobbyMemberLimit2}";
						((TMP_Text)((Component)m_buttons[((object)(CSteamID)(ref room)).ToString()]).GetComponentInChildren<TextMeshProUGUI>()).text = text2;
					}
				}
			}
			List<string> list = new List<string>();
			foreach (string key in m_buttons.Keys)
			{
				if (m_brokenList.Contains(key.ToString()) || !hashSet.Contains(key))
				{
					Object.Destroy((Object)(object)((Component)m_buttons[key]).gameObject);
					list.Add(key);
				}
			}
			foreach (string item in list)
			{
				m_buttons.Remove(item);
				m_hosts.Remove(item);
			}
		}

		private void OnServerButtonClicked(CSteamID room)
		{
			//IL_002e: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			MethodInfo method = typeof(SteamLobbyHandler).GetMethod("JoinLobby", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				method.Invoke(MainMenuHandler.SteamLobbyHandler, new object[1] { room });
				lastJoinedRoom = room;
			}
		}

		public void SelectCategory(LobbyCategory lobbyCategory)
		{
			currentCategory = lobbyCategory;
		}

		private void Update()
		{
			timer += Time.deltaTime;
			if (timer >= interval)
			{
				Show(currentCategory);
				timer = 0f;
			}
		}

		private void SetupBtnNames()
		{
			((TMP_Text)((Component)usBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "US  (" + LobbyMain.lobbyManager.usLobbies.Count + ")";
			((TMP_Text)((Component)uswBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "USW  (" + LobbyMain.lobbyManager.uswLobbies.Count + ")";
			((TMP_Text)((Component)euBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "EU  (" + LobbyMain.lobbyManager.euLobbies.Count + ")";
			((TMP_Text)((Component)saBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "SA  (" + LobbyMain.lobbyManager.saLobbies.Count + ")";
			((TMP_Text)((Component)asiaBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "ASIA (" + LobbyMain.lobbyManager.asiaLobbies.Count + ")";
			((TMP_Text)((Component)allBtn).GetComponentInChildren<TextMeshProUGUI>()).text = "ALL (" + LobbyMain.lobbyManager.lobbyList.Count + ")";
		}

		public void OnScroll(PointerEventData data)
		{
			if ((Object)(object)scrollRect != (Object)null)
			{
				scrollRect.OnScroll(data);
			}
		}

		private GameObject CreateScrollableVerticalLayoutGroup()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002e: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ScrollView");
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = new Vector2(800f, 600f);
			obj.anchorMin = new Vector2(0.5f, 0.5f);
			obj.anchorMax = new Vector2(0.5f, 0.5f);
			obj.pivot = new Vector2(0.5f, 0.5f);
			obj.anchoredPosition = Vector2.zero;
			Image obj2 = val.AddComponent<Image>();
			((Graphic)obj2).color = Color.clear;
			((Graphic)obj2).raycastTarget = true;
			val.AddComponent<GraphicRaycaster>();
			scrollRect = val.AddComponent<ScrollRect>();
			scrollRect.horizontal = false;
			scrollRect.scrollSensitivity = 45f;
			layoutGroupGO = new GameObject("ContentPanel");
			layoutGroupGO.transform.SetParent(val.transform, false);
			RectTransform val2 = layoutGroupGO.AddComponent<RectTransform>();
			val2.sizeDelta = new Vector2(0f, 0f);
			val2.anchorMin = new Vector2(0f, 1f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.pivot = new Vector2(0.5f, 1f);
			VerticalLayoutGroup obj3 = layoutGroupGO.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj3).spacing = 70f;
			ContentSizeFitter obj4 = layoutGroupGO.AddComponent<ContentSizeFitter>();
			obj4.verticalFit = (FitMode)2;
			obj4.horizontalFit = (FitMode)2;
			scrollRect.content = val2;
			val.transform.localPosition = new Vector3(val.transform.localPosition.x, val.transform.localPosition.y + 100f, val.transform.localPosition.z);
			return val;
		}
	}
	[ContentWarningPlugin("12aa83f7-baa2-6332-be41-e636ccf60e56", "1.0", true)]
	[BepInPlugin("holden.plugin.main.lobbyviewermod", "Holden's Lobby Viewer Mod!", "1.0")]
	public class LobbyMain : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(MainMenuHandler), "Start")]
		public static class StartPatch
		{
			[HarmonyPostfix]
			public static void Postfix()
			{
				lobbyManager.Start();
			}
		}

		[HarmonyPatch(typeof(Modal), "ShowError", new Type[]
		{
			typeof(string),
			typeof(string)
		})]
		public static class PatchModalShowError
		{
			[HarmonyPostfix]
			public static void Postfix(string title, string body)
			{
				//IL_0000: 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)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				_ = LobbyMenu.lastJoinedRoom;
				if (true & ((body == "Game closed") | (body == "Game does not exist")))
				{
					SteamFriends.GetFriendPersonaName(SteamMatchmaking.GetLobbyOwner(LobbyMenu.lastJoinedRoom));
					LobbyMenu.m_brokenList.Add(((object)(CSteamID)(ref LobbyMenu.lastJoinedRoom)).ToString());
				}
			}
		}

		[HarmonyPatch(typeof(UIPageHandler), "TransistionToPage", new Type[]
		{
			typeof(UIPage),
			typeof(PageTransistion)
		})]
		public static class PatchTransition
		{
			[HarmonyPrefix]
			public static void TransistionToPage(UIPage page, PageTransistion pageTransistion)
			{
				MyPageUI.TryAttachToPageHandler();
			}
		}

		public static LobbyManager lobbyManager = new LobbyManager();

		public static GameObject LobbiesPage;

		private static LobbyMain instance;

		private float interval = 1f;

		private float timer;

		public static LobbyMain Instance
		{
			get
			{
				if ((Object)(object)instance == (Object)null)
				{
					instance = new LobbyMain();
				}
				return instance;
			}
		}

		public static void ApplyPatches()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.holden.codewarning").PatchAll(Assembly.GetExecutingAssembly());
		}

		private void Start()
		{
			instance = this;
			ApplyPatches();
			MyPageUI.TryAttachToPageHandler();
		}

		private void Update()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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)
			timer += Time.deltaTime;
			if ((Object)(object)LobbiesPage != (Object)null && LobbiesPage.activeInHierarchy && timer >= interval)
			{
				BuildVersion val = new BuildVersion(Application.version);
				SteamMatchmaking.AddRequestLobbyListStringFilter("ContentWarningVersion", ((BuildVersion)(ref val)).ToMatchmaking(), (ELobbyComparison)0);
				SteamMatchmaking.AddRequestLobbyListFilterSlotsAvailable(1);
				SteamMatchmaking.AddRequestLobbyListDistanceFilter((ELobbyDistanceFilter)3);
				SteamMatchmaking.RequestLobbyList();
				timer = 0f;
			}
		}
	}
	internal class MainMenu : MonoBehaviour
	{
		public Button joinFriendBtn;

		public Button viewLobbiesBtn;

		public Button hostGameBtn;

		private Transform page;

		private Canvas canvas;

		private MainMenuMainPage main;

		public static GameObject btnToCopy;

		private void Awake()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			canvas = Object.FindObjectOfType<Canvas>();
			page = GameObject.Find("MainPage").transform;
			main = Object.FindObjectOfType<MainMenuMainPage>();
			btnToCopy = ((Component)main.quitButton).gameObject;
			CreateButtons();
			((UnityEvent)joinFriendBtn.onClick).AddListener(new UnityAction(OnJoinFriendButtonClicked));
			((UnityEvent)viewLobbiesBtn.onClick).AddListener(new UnityAction(OnViewLobbiesButtonClicked));
			((UnityEvent)hostGameBtn.onClick).AddListener(new UnityAction(OnHostPublicGameButtonClicked));
		}

		private void Start()
		{
			((TMP_Text)((Component)joinFriendBtn).gameObject.GetComponentInChildren<TextMeshProUGUI>()).text = "Join Friend";
		}

		private void CreateButtons()
		{
			hostGameBtn = CreateBtnCopy("hostGameBtn", "Host Public Game", 450f, page).GetComponent<Button>();
			viewLobbiesBtn = CreateBtnCopy("viewLobbiesBtn", "View Lobbies", 375f, page).GetComponent<Button>();
			joinFriendBtn = CreateBtnCopy("JoinFriendBtn", "Join Friend", 300f, page).GetComponent<Button>();
		}

		public static GameObject CreateBtnCopy(string name, string btnText, float y, Transform parent)
		{
			//IL_002a: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(btnToCopy, parent);
			Object.Destroy((Object)(object)obj.GetComponentInChildren<GameObjectLocalizer>());
			((Object)obj).name = name;
			RectTransform component = obj.GetComponent<RectTransform>();
			component.anchoredPosition = new Vector2(-325f, y);
			component.anchorMax = new Vector2(1f, 0f);
			component.anchorMin = new Vector2(1f, 0f);
			component.sizeDelta = new Vector2(500f, 50f);
			((Transform)component).localScale = new Vector3(1f, 1f, 1f);
			((Transform)component).rotation = Quaternion.identity;
			((TMP_Text)obj.GetComponentInChildren<TextMeshProUGUI>()).text = btnText;
			return obj;
		}

		private void OnJoinFriendButtonClicked()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			List<CSteamID> list = new List<CSteamID>();
			FriendGameInfo_t val = default(FriendGameInfo_t);
			for (int i = 0; i < SteamFriends.GetFriendCount((EFriendFlags)4); i++)
			{
				SteamFriends.GetFriendByIndex(i, (EFriendFlags)4);
				SteamFriends.GetFriendGamePlayed(SteamFriends.GetFriendByIndex(i, (EFriendFlags)65535), ref val);
				if (val.m_gameID.m_GameID == 2881650 && ((CSteamID)(ref val.m_steamIDLobby)).IsValid())
				{
					list.Add(val.m_steamIDLobby);
				}
			}
			if (list.Count == 0)
			{
				Modal.ShowError("No Friend Lobbies Found!", "Failed to find any valid joinable friend lobbies. Please try again.");
				return;
			}
			MainMenuHandler.SteamLobbyHandler.Reflect<SteamLobbyHandler>().Invoke("JoinLobby", true, list[Random.Range(0, list.Count)]);
		}

		private void OnHostPublicGameButtonClicked()
		{
			MainMenuHandler.Instance.SilentHost();
		}

		private void OnViewLobbiesButtonClicked()
		{
			MyPageUI.TransitionToPage<MainMenuViewLobbiesPage>();
		}
	}
	internal class MainMenuViewLobbiesPage : MainMenuPage
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__6_0;

			public static UnityAction <>9__6_1;

			public static UnityAction <>9__6_2;

			public static UnityAction <>9__6_3;

			public static UnityAction <>9__6_4;

			public static UnityAction <>9__6_5;

			public static UnityAction <>9__6_6;

			internal void <Awake>b__6_0()
			{
				MyPageUI.TransitionToPage<MainMenuMainPage>();
			}

			internal void <Awake>b__6_1()
			{
				LobbyMenu.currentCategory = LobbyCategory.all;
			}

			internal void <Awake>b__6_2()
			{
				LobbyMenu.currentCategory = LobbyCategory.eu;
			}

			internal void <Awake>b__6_3()
			{
				LobbyMenu.currentCategory = LobbyCategory.us;
			}

			internal void <Awake>b__6_4()
			{
				LobbyMenu.currentCategory = LobbyCategory.usw;
			}

			internal void <Awake>b__6_5()
			{
				LobbyMenu.currentCategory = LobbyCategory.sa;
			}

			internal void <Awake>b__6_6()
			{
				LobbyMenu.currentCategory = LobbyCategory.asia;
			}
		}

		private GameObject canvasGo;

		private Canvas canvas;

		private float screenWidth;

		private float screenHeight;

		private GameObject layoutGroupGO;

		private Button backBtn;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0040: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_0176: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Expected O, but got Unknown
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Expected O, but got Unknown
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Expected O, but got Unknown
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Expected O, but got Unknown
			canvasGo = ((Component)Object.FindAnyObjectByType<MainMenuHandler>()).gameObject;
			canvas = Object.FindObjectOfType<Canvas>();
			Rect pixelRect = canvas.pixelRect;
			screenHeight = ((Rect)(ref pixelRect)).height;
			pixelRect = canvas.pixelRect;
			screenWidth = ((Rect)(ref pixelRect)).width;
			((Component)this).GetComponent<RectTransform>().anchoredPosition = new Vector2(0.5f, 0f);
			GameObject val = new GameObject("BackgroundImage");
			val.transform.SetParent(((Component)this).transform, false);
			((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.9412f);
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).localScale = Vector2.op_Implicit(new Vector2(screenWidth, screenHeight));
			component.anchoredPosition = Vector2.zero;
			SetLayoutGroup();
			((Component)this).gameObject.AddComponent<LobbyMenu>();
			backBtn = MainMenu.CreateBtnCopy("backBtn", "Back", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)backBtn).gameObject.transform.position = new Vector3(314.6961f, 80f, 0f);
			ButtonClickedEvent onClick = backBtn.onClick;
			object obj = <>c.<>9__6_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					MyPageUI.TransitionToPage<MainMenuMainPage>();
				};
				<>c.<>9__6_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			((Component)backBtn).GetComponent<RectTransform>().anchoredPosition = new Vector2(-700f, -400f);
			LobbyMenu.allBtn = MainMenu.CreateBtnCopy("allBtn", "ALL", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.allBtn).gameObject.transform.position = new Vector3(314.6961f, 900f, 0f);
			ButtonClickedEvent onClick2 = LobbyMenu.allBtn.onClick;
			object obj2 = <>c.<>9__6_1;
			if (obj2 == null)
			{
				UnityAction val3 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.all;
				};
				<>c.<>9__6_1 = val3;
				obj2 = (object)val3;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj2);
			((Component)LobbyMenu.allBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMenu.euBtn = MainMenu.CreateBtnCopy("euBtn", "EU", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.euBtn).gameObject.transform.position = new Vector3(314.6961f, 750f, 0f);
			ButtonClickedEvent onClick3 = LobbyMenu.euBtn.onClick;
			object obj3 = <>c.<>9__6_2;
			if (obj3 == null)
			{
				UnityAction val4 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.eu;
				};
				<>c.<>9__6_2 = val4;
				obj3 = (object)val4;
			}
			((UnityEvent)onClick3).AddListener((UnityAction)obj3);
			((Component)LobbyMenu.euBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMenu.usBtn = MainMenu.CreateBtnCopy("usBtn", "US", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.usBtn).gameObject.transform.position = new Vector3(314.6961f, 700f, 0f);
			ButtonClickedEvent onClick4 = LobbyMenu.usBtn.onClick;
			object obj4 = <>c.<>9__6_3;
			if (obj4 == null)
			{
				UnityAction val5 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.us;
				};
				<>c.<>9__6_3 = val5;
				obj4 = (object)val5;
			}
			((UnityEvent)onClick4).AddListener((UnityAction)obj4);
			((Component)LobbyMenu.usBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMenu.uswBtn = MainMenu.CreateBtnCopy("uswBtn", "USW", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.uswBtn).gameObject.transform.position = new Vector3(314.6961f, 650f, 0f);
			ButtonClickedEvent onClick5 = LobbyMenu.uswBtn.onClick;
			object obj5 = <>c.<>9__6_4;
			if (obj5 == null)
			{
				UnityAction val6 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.usw;
				};
				<>c.<>9__6_4 = val6;
				obj5 = (object)val6;
			}
			((UnityEvent)onClick5).AddListener((UnityAction)obj5);
			((Component)LobbyMenu.uswBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMenu.saBtn = MainMenu.CreateBtnCopy("saBtn", "SA", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.saBtn).gameObject.transform.position = new Vector3(314.6961f, 600f, 0f);
			ButtonClickedEvent onClick6 = LobbyMenu.saBtn.onClick;
			object obj6 = <>c.<>9__6_5;
			if (obj6 == null)
			{
				UnityAction val7 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.sa;
				};
				<>c.<>9__6_5 = val7;
				obj6 = (object)val7;
			}
			((UnityEvent)onClick6).AddListener((UnityAction)obj6);
			((Component)LobbyMenu.saBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMenu.asiaBtn = MainMenu.CreateBtnCopy("asiaBtn", "ASIA", 100f, ((Component)this).transform).GetComponent<Button>();
			((Component)LobbyMenu.asiaBtn).gameObject.transform.position = new Vector3(314.6961f, 550f, 0f);
			ButtonClickedEvent onClick7 = LobbyMenu.asiaBtn.onClick;
			object obj7 = <>c.<>9__6_6;
			if (obj7 == null)
			{
				UnityAction val8 = delegate
				{
					LobbyMenu.currentCategory = LobbyCategory.asia;
				};
				<>c.<>9__6_6 = val8;
				obj7 = (object)val8;
			}
			((UnityEvent)onClick7).AddListener((UnityAction)obj7);
			((Component)LobbyMenu.asiaBtn).gameObject.transform.SetParent(layoutGroupGO.transform);
			LobbyMain.LobbiesPage = ((Component)this).gameObject;
			((Component)this).gameObject.SetActive(false);
		}

		private void SetLayoutGroup()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			layoutGroupGO = new GameObject("LayoutGroup");
			layoutGroupGO.transform.SetParent(((Component)this).transform, false);
			VerticalLayoutGroup obj = layoutGroupGO.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 50f;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
			RectTransform component = layoutGroupGO.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = new Vector2(-850f, 300f);
			component.sizeDelta = new Vector2(200f, 0f);
		}
	}
	public class MyPageUI : MonoBehaviour
	{
		private UIPageHandler pageHandler;

		private bool hasAddedPages;

		private void Awake()
		{
			pageHandler = Object.FindObjectOfType<UIPageHandler>();
		}

		private void Update()
		{
			UIPage currentPage = pageHandler.currentPage;
			MainMenuMainPage val = (MainMenuMainPage)(object)((currentPage is MainMenuMainPage) ? currentPage : null);
			if (val != null)
			{
				if ((Object)(object)((Component)val).GetComponent<MainMenu>() == (Object)null)
				{
					((Component)val).gameObject.AddComponent<MainMenu>();
				}
				AddPages();
			}
		}

		private void AddPages()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!hasAddedPages)
			{
				GameObject val = new GameObject("MainMenuViewLobbiesPage", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(((Component)Object.FindObjectOfType<UIPageHandler>()).transform, false);
				TryRegisterPage((UIPage)(object)val.AddComponent<MainMenuViewLobbiesPage>());
				hasAddedPages = true;
			}
		}

		public static void TryAttachToPageHandler()
		{
			UIPageHandler val = Object.FindObjectOfType<UIPageHandler>();
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject.GetComponent<MyPageUI>() != (Object)null))
			{
				((Component)val).gameObject.AddComponent<MyPageUI>();
			}
		}

		public static void TryRegisterPage(UIPage page)
		{
			UIPageHandler val = Object.FindObjectOfType<UIPageHandler>();
			if (!((Object)(object)val == (Object)null) && val.Reflect<UIPageHandler>().GetValue("_pages") is Dictionary<Type, UIPage> dictionary)
			{
				dictionary.Add(((object)page).GetType(), page);
			}
		}

		public static void TransitionToPage<T>() where T : UIPage
		{
			Object.FindObjectOfType<UIPageHandler>().TransistionToPage<T>();
		}
	}
}