Decompiled source of ServerListTweaks v1.0.0

ServerListTweaks.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MenuLib;
using Photon.Pun;
using Photon.Realtime;
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("ServerListTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ServerListTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b614d822-f94f-4297-9508-8bc122e1194e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ServerListTweaks;

[BepInPlugin("Bratwurst.ServerListTweaks", "Server List Tweaks Mod", "1.0.0")]
public class Loader : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Action <>9__13_1;

		public static BuilderDelegate <>9__13_0;

		internal void <Awake>b__13_0(Transform parent)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			<>c__DisplayClass13_0 CS$<>8__locals0 = new <>c__DisplayClass13_0
			{
				forceRefresh = delegate
				{
					MenuPageServerList val = Object.FindObjectOfType<MenuPageServerList>();
					if ((Object)(object)val != (Object)null && !((MonoBehaviour)val).IsInvoking("StartRefresh"))
					{
						((MonoBehaviour)val).StopAllCoroutines();
						((MonoBehaviour)val).StartCoroutine(ForceServerRefresh(val));
						mls.LogInfo((object)"Server list refresh triggered via button.");
					}
				}
			};
			MenuAPI.CreateREPOButton("Refresh Servers", CS$<>8__locals0.forceRefresh, parent, Vector2.zero);
			MenuAPI.CreateREPOToggle("ASCII servers only", (Action<bool>)delegate(bool b)
			{
				filterascii.Value = b;
				CS$<>8__locals0.forceRefresh();
			}, parent, new Vector2(160f, 10f), "ON", "OFF", filterascii.Value);
			MenuAPI.CreateREPOInputField("Filter by Regex", (Action<string>)delegate(string s)
			{
				filterby.Value = s.Trim();
				CS$<>8__locals0.forceRefresh();
			}, parent, new Vector2(450f, 10f), false, "", filterby.Value);
		}

		internal void <Awake>b__13_1()
		{
			MenuPageServerList val = Object.FindObjectOfType<MenuPageServerList>();
			if ((Object)(object)val != (Object)null && !((MonoBehaviour)val).IsInvoking("StartRefresh"))
			{
				((MonoBehaviour)val).StopAllCoroutines();
				((MonoBehaviour)val).StartCoroutine(ForceServerRefresh(val));
				mls.LogInfo((object)"Server list refresh triggered via button.");
			}
		}
	}

	[CompilerGenerated]
	private sealed class <>c__DisplayClass13_0
	{
		public Action forceRefresh;

		internal void <Awake>b__2(bool b)
		{
			filterascii.Value = b;
			forceRefresh();
		}

		internal void <Awake>b__3(string s)
		{
			filterby.Value = s.Trim();
			forceRefresh();
		}
	}

	private const string modGUID = "Bratwurst.ServerListTweaks";

	private const string modName = "Server List Tweaks Mod";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("Bratwurst.ServerListTweaks");

	internal static ManualLogSource mls;

	public static ConfigEntry<bool> filterascii { get; private set; }

	public static ConfigEntry<string> filterby { get; private set; }

	private void Awake()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		mls = Logger.CreateLogSource("Bratwurst.ServerListTweaks");
		mls.LogInfo((object)"Server List Tweaks Mod - Loaded");
		harmony.PatchAll();
		filterascii = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "filterascii", true, new ConfigDescription("Whether or not to filter out non-ascii servers.", (AcceptableValueBase)null, Array.Empty<object>()));
		filterby = ((BaseUnityPlugin)this).Config.Bind<string>("General", "filterby", "", new ConfigDescription("Regex by which to filter server names.", (AcceptableValueBase)null, Array.Empty<object>()));
		object obj = <>c.<>9__13_0;
		if (obj == null)
		{
			BuilderDelegate val = delegate(Transform parent)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				Action forceRefresh = delegate
				{
					MenuPageServerList val2 = Object.FindObjectOfType<MenuPageServerList>();
					if ((Object)(object)val2 != (Object)null && !((MonoBehaviour)val2).IsInvoking("StartRefresh"))
					{
						((MonoBehaviour)val2).StopAllCoroutines();
						((MonoBehaviour)val2).StartCoroutine(ForceServerRefresh(val2));
						mls.LogInfo((object)"Server list refresh triggered via button.");
					}
				};
				MenuAPI.CreateREPOButton("Refresh Servers", forceRefresh, parent, Vector2.zero);
				MenuAPI.CreateREPOToggle("ASCII servers only", (Action<bool>)delegate(bool b)
				{
					filterascii.Value = b;
					forceRefresh();
				}, parent, new Vector2(160f, 10f), "ON", "OFF", filterascii.Value);
				MenuAPI.CreateREPOInputField("Filter by Regex", (Action<string>)delegate(string s)
				{
					filterby.Value = s.Trim();
					forceRefresh();
				}, parent, new Vector2(450f, 10f), false, "", filterby.Value);
			};
			<>c.<>9__13_0 = val;
			obj = (object)val;
		}
		MenuAPI.AddElementToServerListMenu((BuilderDelegate)obj);
	}

	private static IEnumerator ForceServerRefresh(MenuPageServerList serverList)
	{
		Traverse roomListField = Traverse.Create((object)serverList).Field("roomList");
		object roomListObj = roomListField.GetValue();
		if (roomListObj is IList roomList)
		{
			roomList.Clear();
		}
		Traverse.Create((object)serverList).Field("receivedList").SetValue((object)false);
		PhotonNetwork.Disconnect();
		while ((int)PhotonNetwork.NetworkingClient.State != 14 && (int)PhotonNetwork.NetworkingClient.State > 0)
		{
			yield return null;
		}
		SteamManager.instance.SendSteamAuthTicket();
		DataDirector.instance.PhotonSetRegion();
		DataDirector.instance.PhotonSetVersion();
		DataDirector.instance.PhotonSetAppId();
		PhotonNetwork.ConnectUsingSettings();
		while (!Traverse.Create((object)serverList).Field("receivedList").GetValue<bool>())
		{
			yield return null;
		}
		foreach (Transform item in serverList.serverElementParent)
		{
			Transform child = item;
			Object.Destroy((Object)(object)((Component)child).gameObject);
		}
		((MonoBehaviour)serverList).StartCoroutine("UpdatePage");
	}
}
[HarmonyPatch]
internal class RoomListPatch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method("MenuPageServerList:OnRoomListUpdate", (Type[])null, (Type[])null);
	}

	private static void Prefix(List<RoomInfo> _roomList)
	{
		Debug.Log((object)"[Patch] Filtering non-ASCII room names...");
		_roomList.RemoveAll(delegate(RoomInfo room)
		{
			if (!Loader.filterascii.Value)
			{
				return false;
			}
			if (((Dictionary<object, object>)(object)room.CustomProperties).TryGetValue("server_name", out var value) && value is string text)
			{
				string text2 = text;
				foreach (char c in text2)
				{
					if (c > '\u007f')
					{
						return true;
					}
				}
				if (Loader.filterby.Value.Length > 0)
				{
					if (new Regex(Loader.filterby.Value).IsMatch(text))
					{
						return false;
					}
					return true;
				}
				return false;
			}
			return true;
		});
	}
}