Decompiled source of LoadAllLobby v1.0.0

BepInEx/plugins/LoadAllLobby.dll

Decompiled a month ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LoadAllLobby")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoadAllLobby")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a7c74411-41ca-42e6-a8ec-96aaaecf50f4")]
[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 LoadAllLobby;

[BepInPlugin("LoadAllLobby", "LoadAllLobby", "1.0.0")]
public class LoadAllLobbyPlugin : BaseUnityPlugin
{
	public const string Version = "1.0.0";

	private void Awake()
	{
		Harmony.CreateAndPatchAll(typeof(SteamLobbyPatch), (string)null);
	}
}
public static class SteamLobbyPatch
{
	private static readonly Dictionary<int, string> vers = new Dictionary<int, string>
	{
		{ 45, "[v45] " },
		{ 47, "[v47] " },
		{ 49, "[v49] " },
		{ 50, "[v50] " },
		{ 9999, "[v49|MoreCompany1.8] " },
		{ 10000, "[v50|MoreCompany1.9] " }
	};

	private static bool doLoad = false;

	[HarmonyPatch(typeof(SteamLobbyManager), "LoadServerList")]
	[HarmonyPrefix]
	[HarmonyWrapSafe]
	public static bool LoadServerList(SteamLobbyManager __instance)
	{
		if (doLoad)
		{
			return false;
		}
		doLoad = true;
		LoadAllLobby(__instance);
		return false;
	}

	public static async void LoadAllLobby(SteamLobbyManager __instance)
	{
		__instance.SetField<SteamLobbyManager>("refreshServerListTimer", 0f);
		((TMP_Text)__instance.serverListBlankText).text = "Loading server list...";
		__instance.SetField<SteamLobbyManager>("currentLobbyList", null);
		LobbySlot[] array = Object.FindObjectsOfType<LobbySlot>();
		for (int i = 0; i < array.Length; i++)
		{
			Object.Destroy((Object)(object)((Component)array[i]).gameObject);
		}
		List<Lobby> lobbies = new List<Lobby>();
		foreach (KeyValuePair<int, string> item in vers.OrderBy((KeyValuePair<int, string> x) => (GameNetworkManager.Instance.gameVersionNum != x.Key) ? x.Key : 0))
		{
			int sortByDistanceSetting = __instance.sortByDistanceSetting;
			LobbyQuery lobbyQuery = default(LobbyQuery);
			LobbyQuery val;
			switch (sortByDistanceSetting)
			{
			case 0:
				val = SteamMatchmaking.LobbyList;
				((LobbyQuery)(ref val)).FilterDistanceClose();
				val = SteamMatchmaking.LobbyList;
				val = ((LobbyQuery)(ref val)).FilterDistanceClose();
				val = ((LobbyQuery)(ref val)).WithSlotsAvailable(1);
				lobbyQuery = ((LobbyQuery)(ref val)).WithKeyValue("vers", item.Key.ToString());
				break;
			case 1:
				val = SteamMatchmaking.LobbyList;
				((LobbyQuery)(ref val)).FilterDistanceFar();
				val = SteamMatchmaking.LobbyList;
				val = ((LobbyQuery)(ref val)).FilterDistanceFar();
				val = ((LobbyQuery)(ref val)).WithSlotsAvailable(1);
				lobbyQuery = ((LobbyQuery)(ref val)).WithKeyValue("vers", item.Key.ToString());
				break;
			default:
				val = SteamMatchmaking.LobbyList;
				((LobbyQuery)(ref val)).FilterDistanceWorldwide();
				val = SteamMatchmaking.LobbyList;
				val = ((LobbyQuery)(ref val)).FilterDistanceWorldwide();
				val = ((LobbyQuery)(ref val)).WithSlotsAvailable(1);
				lobbyQuery = ((LobbyQuery)(ref val)).WithKeyValue("vers", item.Key.ToString());
				break;
			}
			if (!((Behaviour)__instance.sortWithChallengeMoonsCheckbox).enabled)
			{
				lobbyQuery = ((LobbyQuery)(ref lobbyQuery)).WithKeyValue("chal", "f");
			}
			if (__instance.serverTagInputField.text != string.Empty)
			{
				lobbyQuery = ((LobbyQuery)(ref lobbyQuery)).WithKeyValue("tag", __instance.serverTagInputField.text.Substring(0, Mathf.Min(19, __instance.serverTagInputField.text.Length)).ToLower());
			}
			Lobby[] lobby = await ((LobbyQuery)(ref lobbyQuery)).RequestAsync();
			if (lobby != null)
			{
				Lobby[] array2 = lobby;
				for (int j = 0; j < array2.Length; j++)
				{
					Lobby item2 = array2[j];
					((Lobby)(ref item2)).SetData("name", item.Value + ((Lobby)(ref item2)).GetData("name"));
					item2 = default(Lobby);
				}
				lobbies.AddRange(lobby);
			}
			lobbyQuery = default(LobbyQuery);
		}
		__instance.SetField<SteamLobbyManager>("currentLobbyList", lobbies.ToArray());
		if (lobbies.Count == 0)
		{
			((TMP_Text)__instance.serverListBlankText).text = "No available servers to join.";
		}
		else
		{
			((TMP_Text)__instance.serverListBlankText).text = "";
		}
		__instance.SetField<SteamLobbyManager>("lobbySlotPositionOffset", 0f);
		__instance.SetField<SteamLobbyManager>("loadLobbyListCoroutine", ((MonoBehaviour)__instance).StartCoroutine((IEnumerator)typeof(SteamLobbyManager).GetMethod("loadLobbyListAndFilter", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { lobbies.ToArray() })));
		doLoad = false;
	}

	public static T2 GetField<T, T2>(this T obj, string name)
	{
		return (T2)obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).GetValue(obj);
	}

	public static void SetField<T>(this T obj, string name, object value)
	{
		obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).SetValue(obj, value);
	}
}