Decompiled source of SearchServersByName v1.0.0

BepInEx/plugins/asm.SearchServersByName/SearchServersByName.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("SearchServersByName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SearchServersByName")]
[assembly: AssemblyTitle("SearchServersByName")]
[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 SearchServersByName
{
	[BepInPlugin("SearchServersByName", "SearchServersByName", "1.0.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass6_0
		{
			public Task queryTask;

			internal bool <RunQueryCoroutine>b__0()
			{
				return queryTask.IsCompleted;
			}
		}

		[CompilerGenerated]
		private sealed class <RunQueryCoroutine>d__6 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public SteamLobbyManager __instance;

			public LobbyQuery lobbyQuery;

			private <>c__DisplayClass6_0 <>8__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <RunQueryCoroutine>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>8__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002f: 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_005a: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass6_0();
					<>8__1.queryTask = RunQuery(__instance, lobbyQuery);
					<>2__current = (object)new WaitUntil((Func<bool>)(() => <>8__1.queryTask.IsCompleted));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (<>8__1.queryTask.IsFaulted)
					{
						Logger.LogError((object)("The async lobby query failed with an exception: " + <>8__1.queryTask.Exception));
						GameNetworkManager.Instance.waitingForLobbyDataRefresh = false;
						((TMP_Text)__instance.serverListBlankText).text = "Error: Failed to get servers.";
					}
					Logger.LogInfo((object)"RunQueryCoroutine has completed.");
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal static ManualLogSource Logger;

		internal static Harmony Harmony = new Harmony("SearchServersByName");

		private const string TagsPlaceholderPath = "Canvas/MenuContainer/LobbyList/ListPanel/ServerTagInputField/Text Area/Placeholder";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin SearchServersByName is loaded!");
			Harmony.PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode lsm)
		{
			if (!(((Scene)(ref scene)).name == "MainMenu"))
			{
				return;
			}
			GameObject val = GameObject.Find("Canvas/MenuContainer/LobbyList/ListPanel/ServerTagInputField/Text Area/Placeholder");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Can't find the 'Placeholder' GameObject using path: Canvas/MenuContainer/LobbyList/ListPanel/ServerTagInputField/Text Area/Placeholder");
				return;
			}
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogError((object)"Can't find TextMeshProUGUI component on the 'Placeholder' GameObject.");
			}
			else
			{
				((TMP_Text)component).text = "Enter server name...";
			}
		}

		[HarmonyPatch(typeof(SteamLobbyManager), "LoadServerList")]
		[HarmonyPrefix]
		private static bool LoadServerList(SteamLobbyManager __instance)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00c3: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (GameNetworkManager.Instance.waitingForLobbyDataRefresh)
			{
				return false;
			}
			if (__instance.loadLobbyListCoroutine != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(__instance.loadLobbyListCoroutine);
			}
			__instance.refreshServerListTimer = 0f;
			((TMP_Text)__instance.serverListBlankText).text = "Loading server list...";
			__instance.currentLobbyList = null;
			LobbySlot[] array = Object.FindObjectsOfType<LobbySlot>();
			for (int i = 0; i < array.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array[i]).gameObject);
			}
			Logger.LogInfo((object)"Requested server list");
			GameNetworkManager.Instance.waitingForLobbyDataRefresh = true;
			LobbyQuery val;
			LobbyQuery lobbyQuery;
			switch (__instance.sortByDistanceSetting)
			{
			case 0:
				val = SteamMatchmaking.LobbyList;
				lobbyQuery = ((LobbyQuery)(ref val)).FilterDistanceClose();
				break;
			case 1:
				val = SteamMatchmaking.LobbyList;
				lobbyQuery = ((LobbyQuery)(ref val)).FilterDistanceFar();
				break;
			default:
				val = SteamMatchmaking.LobbyList;
				lobbyQuery = ((LobbyQuery)(ref val)).FilterDistanceWorldwide();
				break;
			}
			val = ((LobbyQuery)(ref lobbyQuery)).WithSlotsAvailable(1);
			lobbyQuery = ((LobbyQuery)(ref val)).WithKeyValue("vers", GameNetworkManager.Instance.gameVersionNum.ToString());
			((MonoBehaviour)__instance).StartCoroutine(RunQueryCoroutine(__instance, lobbyQuery));
			return false;
		}

		[IteratorStateMachine(typeof(<RunQueryCoroutine>d__6))]
		private static IEnumerator RunQueryCoroutine(SteamLobbyManager __instance, LobbyQuery lobbyQuery)
		{
			//IL_000e: 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)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RunQueryCoroutine>d__6(0)
			{
				__instance = __instance,
				lobbyQuery = lobbyQuery
			};
		}

		private static async Task RunQuery(SteamLobbyManager __instance, LobbyQuery lobbyQuery)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.sortWithChallengeMoons)
			{
				lobbyQuery = ((LobbyQuery)(ref lobbyQuery)).WithKeyValue("chal", "f");
			}
			lobbyQuery = ((LobbyQuery)(ref lobbyQuery)).WithKeyValue("tag", "none");
			Lobby[] array = await ((LobbyQuery)(ref lobbyQuery)).RequestAsync();
			if (__instance.serverTagInputField.text != string.Empty)
			{
				List<Lobby> list = array.ToList();
				string searchLower = __instance.serverTagInputField.text.ToLower();
				list.RemoveAll((Lobby lobby) => !((Lobby)(ref lobby)).GetData("name").ToLower().Contains(searchLower));
				array = list.ToArray();
			}
			__instance.currentLobbyList = array;
			GameNetworkManager.Instance.waitingForLobbyDataRefresh = false;
			if (__instance.currentLobbyList != null)
			{
				if (__instance.currentLobbyList.Length == 0)
				{
					((TMP_Text)__instance.serverListBlankText).text = "No available servers to join.";
				}
				else
				{
					((TMP_Text)__instance.serverListBlankText).text = "";
				}
				__instance.lobbySlotPositionOffset = 0f;
				__instance.loadLobbyListCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.loadLobbyListAndFilter(__instance.currentLobbyList));
			}
			else
			{
				Logger.LogInfo((object)"Lobby list is null after request.");
				((TMP_Text)__instance.serverListBlankText).text = "No available servers to join.";
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SearchServersByName";

		public const string PLUGIN_NAME = "SearchServersByName";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}