Decompiled source of ServerListViewer v1.0.0

ServerListViewer.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Globalization;
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.Core.Logging.Interpolation;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SteamworksNative;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ServerListViewer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ServerListViewer")]
[assembly: AssemblyTitle("ServerListViewer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServerListViewer
{
	internal static class Patches
	{
		public static KeyCode ToggleKey = (KeyCode)283;

		private static GameObject serverListObj;

		private static bool initialized = false;

		private static ManualLogSource logger = Logger.CreateLogSource("ServerListViewer");

		[HarmonyPatch(typeof(MonoBehaviourPublicGataInefObInUnique), "Method_Private_Void_GameObject_Boolean_Vector3_Quaternion_0")]
		[HarmonyPatch(typeof(MonoBehaviourPublicCSDi2UIInstObUIloDiUnique), "Method_Private_Void_0")]
		[HarmonyPrefix]
		internal static bool PreBepinexDetection()
		{
			return false;
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicGalomeGacrsemiGaupObUnique), "Start")]
		[HarmonyPostfix]
		internal static void MenuStart()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			try
			{
				if (!initialized)
				{
					ManualLogSource obj = logger;
					if (obj != null)
					{
						obj.LogInfo((object)"Menu scene loaded, initializing server list");
					}
					InitializeServerList();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource val = logger;
				if (val != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error in scene loaded handler: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					val.LogError(val2);
				}
			}
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicObRaovInObSiSiUnique), "StartTransition")]
		[HarmonyPostfix]
		internal static void OnStartTransition()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			try
			{
				if (initialized && (Object)(object)serverListObj != (Object)null && serverListObj.activeSelf)
				{
					serverListObj.SetActive(false);
					Cursor.lockState = (CursorLockMode)1;
					Cursor.visible = false;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource val = logger;
				if (val != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error in scene change handler: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					val.LogError(val2);
				}
			}
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicRaovTMinTemeColoonCoUnique), "Update")]
		[HarmonyPostfix]
		internal static void PostGameManagerUpdate()
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			if (!initialized || (Object)(object)serverListObj == (Object)null)
			{
				return;
			}
			bool flag2 = default(bool);
			try
			{
				if (Input.GetKeyDown(ToggleKey))
				{
					bool flag = !serverListObj.activeSelf;
					serverListObj.SetActive(flag);
					ManualLogSource val = logger;
					if (val != null)
					{
						BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(35, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Server list visibility toggled to: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(flag);
						}
						val.LogInfo(val2);
					}
					if (flag)
					{
						Cursor.lockState = (CursorLockMode)0;
						Cursor.visible = true;
						ManualLogSource obj = logger;
						if (obj != null)
						{
							obj.LogInfo((object)"Cursor unlocked and made visible");
						}
						serverListObj.SetActive(true);
						Transform child = serverListObj.transform.GetChild(0);
						((Component)child).gameObject.SetActive(true);
						Transform child2 = serverListObj.transform.GetChild(0);
						for (int i = 0; i < child2.childCount; i++)
						{
							Transform child3 = ((Component)child2).transform.GetChild(i);
							((Component)child3).gameObject.SetActive(true);
							ManualLogSource val3 = logger;
							if (val3 != null)
							{
								BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(17, 1, ref flag2);
								if (flag2)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Activated child: ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)((Component)child3).gameObject).name);
								}
								val3.LogInfo(val2);
							}
						}
					}
					else
					{
						Cursor.lockState = (CursorLockMode)1;
						Cursor.visible = false;
						ManualLogSource obj2 = logger;
						if (obj2 != null)
						{
							obj2.LogInfo((object)"Cursor locked and made invisible");
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource val4 = logger;
				if (val4 != null)
				{
					BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Error toggling server list: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
					}
					val4.LogError(val5);
				}
			}
			if (!((Object)(object)serverListObj != (Object)null) || !serverListObj.activeSelf)
			{
				return;
			}
			Transform child4 = serverListObj.transform.GetChild(0);
			if (!((Component)child4).gameObject.activeSelf)
			{
				serverListObj.SetActive(false);
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
				ManualLogSource obj3 = logger;
				if (obj3 != null)
				{
					obj3.LogInfo((object)"Cursor locked and made invisible due to child being inactive");
				}
			}
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "LeaveLobby")]
		[HarmonyPostfix]
		internal static void PostLeaveLobby()
		{
			if ((Object)(object)serverListObj != (Object)null)
			{
				serverListObj.SetActive(false);
				ManualLogSource obj = logger;
				if (obj != null)
				{
					obj.LogInfo((object)"Server list UI deactivated after leaving lobby");
				}
			}
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicRaprTetiplTelovemiTeUnique), "JoinLobby")]
		[HarmonyPrefix]
		internal static void PreJoinLobby()
		{
			//IL_002c: 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)
			MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique instance = MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				ManualLogSource obj = logger;
				if (obj != null)
				{
					obj.LogWarning((object)"SteamManager not initialized, cannot join lobby");
				}
			}
			else
			{
				if (!(instance.currentLobby != (CSteamID)0uL))
				{
					return;
				}
				instance.LeaveLobby();
				if ((Object)(object)serverListObj != (Object)null)
				{
					serverListObj.SetActive(false);
					ManualLogSource obj2 = logger;
					if (obj2 != null)
					{
						obj2.LogInfo((object)"Server list UI deactivated after leaving lobby");
					}
				}
			}
		}

		private static void InitializeServerList()
		{
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Expected O, but got Unknown
			if (initialized)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				ManualLogSource obj = logger;
				if (obj != null)
				{
					obj.LogInfo((object)"Starting server list initialization");
				}
				GameObject val = GameObject.Find("UI");
				if ((Object)(object)val != (Object)null)
				{
					ManualLogSource obj2 = logger;
					if (obj2 != null)
					{
						obj2.LogInfo((object)"Found UI object, Spawning dupe");
					}
					MonoBehaviourPublicGaseliGaVibuToclmiToUnique componentInChildren = val.GetComponentInChildren<MonoBehaviourPublicGaseliGaVibuToclmiToUnique>(true);
					if ((Object)(object)componentInChildren != (Object)null)
					{
						GameObject val2 = new GameObject("ServerListViewer_Standalone");
						Canvas val3 = val2.AddComponent<Canvas>();
						val3.renderMode = (RenderMode)0;
						val3.sortingOrder = 1000;
						CanvasScaler val4 = val2.AddComponent<CanvasScaler>();
						val4.uiScaleMode = (ScaleMode)1;
						val4.referenceResolution = new Vector2(1920f, 1080f);
						val2.AddComponent<GraphicRaycaster>();
						Transform val5 = ((Component)componentInChildren).transform;
						while ((Object)(object)val5.parent != (Object)(object)val.transform && (Object)(object)val5.parent != (Object)null)
						{
							val5 = val5.parent;
						}
						GameObject val6 = Object.Instantiate<GameObject>(((Component)val5).gameObject, val2.transform);
						val6.transform.localPosition = Vector3.zero;
						RectTransform component = val6.GetComponent<RectTransform>();
						if ((Object)(object)component != (Object)null)
						{
							component.anchorMin = new Vector2(0f, 0f);
							component.anchorMax = new Vector2(1f, 1f);
							component.pivot = new Vector2(0.5f, 0.5f);
							component.sizeDelta = Vector2.zero;
							((Transform)component).localPosition = Vector3.zero;
						}
						Object.DontDestroyOnLoad((Object)(object)val2);
						serverListObj = val2;
						for (int i = 0; i < val6.transform.childCount; i++)
						{
							Transform child = val6.transform.GetChild(i);
							((Component)child).gameObject.SetActive(true);
							ManualLogSource val7 = logger;
							if (val7 != null)
							{
								BepInExInfoLogInterpolatedStringHandler val8 = new BepInExInfoLogInterpolatedStringHandler(17, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val8).AppendLiteral("Activated child: ");
									((BepInExLogInterpolatedStringHandler)val8).AppendFormatted<string>(((Object)((Component)child).gameObject).name);
								}
								val7.LogInfo(val8);
							}
						}
						serverListObj.SetActive(false);
						ManualLogSource obj3 = logger;
						if (obj3 != null)
						{
							obj3.LogInfo((object)"Server list initialized (parent inactive, children active)");
						}
					}
					else
					{
						ManualLogSource obj4 = logger;
						if (obj4 != null)
						{
							obj4.LogWarning((object)"Server list component not found in UI hierarchy");
						}
					}
				}
				else
				{
					ManualLogSource obj5 = logger;
					if (obj5 != null)
					{
						obj5.LogWarning((object)"UI object not found in scene");
					}
				}
				initialized = true;
			}
			catch (Exception ex)
			{
				ManualLogSource val9 = logger;
				if (val9 != null)
				{
					BepInExErrorLogInterpolatedStringHandler val10 = new BepInExErrorLogInterpolatedStringHandler(35, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("Failed to initialize server list: ");
						((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(ex.Message);
						((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("\n");
						((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(ex.StackTrace);
					}
					val9.LogError(val10);
				}
				serverListObj = null;
				initialized = true;
			}
		}
	}
	[BepInPlugin("Albion.ServerListViewer", "ServerListViewer", "1.0.0")]
	public class ServerListViewer : BasePlugin
	{
		internal static ServerListViewer Instance;

		public override void Load()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
			CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
			CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
			CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
			Instance = this;
			BindConfigValues(ref Patches.ToggleKey, "ToggleKey", "Key to toggle the menu on.");
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
			((BasePlugin)Instance).Config.Reload();
			GetConfigEntry(ref Patches.ToggleKey, "ToggleKey");
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded [");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ServerListViewer");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("]");
			}
			log.LogInfo(val);
		}

		internal void BindConfigValues<T>(ref T value, string name, string description)
		{
			value = ((BasePlugin)this).Config.Bind<T>("ServerListViewer", name, value, description).Value;
		}

		internal static void GetConfigEntry<T>(ref T value, string name)
		{
			ConfigEntry<T> val = default(ConfigEntry<T>);
			if (((BasePlugin)Instance).Config.TryGetEntry<T>("ServerListViewer", name, ref val))
			{
				value = val.Value;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ServerListViewer";

		public const string PLUGIN_NAME = "ServerListViewer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}