Decompiled source of Sort by Player Count v1.0.1

BepInEx/plugins/SortByPlayersButton.dll

Decompiled 7 months ago
using System;
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 TMPro;
using UnityEngine;
using UnityEngine.Events;
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: AssemblyTitle("SortByPlayersButton")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SortByPlayersButton")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("63810973-dffb-4a49-bd2e-b339991e9181")]
[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 SortByPlayersButton
{
	[BepInPlugin("loadingsomething.SortByPlayersButton", "SortByPlayersButton", "1.0.1")]
	public class SortByPlayersButtonPlugin : BaseUnityPlugin
	{
		private const string modGUID = "loadingsomething.SortByPlayersButton";

		private const string modName = "SortByPlayersButton";

		private const string modVer = "1.0.1";

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("loadingsomething.SortByPlayersButton");
			val.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
}
namespace SortByPlayersButton.Patches
{
	[HarmonyPatch]
	internal class MenuManagerPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<LobbySlot, int> <>9__0_1;

			public static UnityAction <>9__0_0;

			internal void <AddSortButton>b__0_0()
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				LobbySlot[] source = Object.FindObjectsOfType<LobbySlot>();
				source = source.OrderByDescending((LobbySlot lobby) => int.Parse(((TMP_Text)lobby.playerCount).text.Split(new char[1] { ' ' })[0])).ToArray();
				float num = 0f;
				for (int i = 0; i < source.Length; i++)
				{
					((Component)source[i]).gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, num);
					num -= 42f;
				}
			}

			internal int <AddSortButton>b__0_1(LobbySlot lobby)
			{
				return int.Parse(((TMP_Text)lobby.playerCount).text.Split(new char[1] { ' ' })[0]);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "Start")]
		private static void AddSortButton()
		{
			//IL_0039: 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_004d: 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_007b: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			GameObject val = GameObject.Find("/Canvas/MenuContainer/LobbyList/ListPanel/RefreshButton");
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent);
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchoredPosition += new Vector2(0f, 18f);
			((TMP_Text)val2.GetComponentInChildren<TextMeshProUGUI>()).text = "[ Sort ]";
			Button component2 = val2.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component2.onClick;
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				UnityAction val3 = delegate
				{
					//IL_0050: Unknown result type (might be due to invalid IL or missing references)
					LobbySlot[] source = Object.FindObjectsOfType<LobbySlot>();
					source = source.OrderByDescending((LobbySlot lobby) => int.Parse(((TMP_Text)lobby.playerCount).text.Split(new char[1] { ' ' })[0])).ToArray();
					float num = 0f;
					for (int i = 0; i < source.Length; i++)
					{
						((Component)source[i]).gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, num);
						num -= 42f;
					}
				};
				<>c.<>9__0_0 = val3;
				obj = (object)val3;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
		}
	}
}