Decompiled source of Flees ServerPrioritizer v0.0.4

ServerPrioritizer.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using Steamworks;
using UnityEngine;
using UnityEngine.Events;

[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("com.fleetime.serverprioritizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.4.0")]
[assembly: AssemblyInformationalVersion("0.0.4+c6182950f7655e942e1aeaee0d33c9b0dad3137d")]
[assembly: AssemblyProduct("ServerPrioritizer")]
[assembly: AssemblyTitle("com.fleetime.serverprioritizer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.4.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 ServerPrioritizer
{
	[BepInPlugin("com.fleetime.serverprioritizer", "ServerPrioritizer", "0.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("ATLYSS.exe")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(LobbyListManager), "Iterate_SteamLobbies")]
		public class IterateSteamLobbiesPatch
		{
			public static void Postfix(LobbyListManager __instance)
			{
				if (string.IsNullOrWhiteSpace(_desiredLobbyNameConfig.Value) && _cachedDesiredLobbyName != _lastJoinedLobbyNameConfig.Value)
				{
					Logger.LogInfo((object)("Using '" + _lastJoinedLobbyNameConfig.Value + "' as the desired server name since its empty."));
					_cachedDesiredLobbyName = _lastJoinedLobbyNameConfig.Value;
				}
				if (__instance._lobbyListEntries == null || __instance._lobbyListEntries.Count == 0)
				{
					Logger.LogInfo((object)"_lobbyListEntries is empty");
					return;
				}
				GameObject val = null;
				int num = -1;
				for (int i = 0; i < __instance._lobbyListEntries.Count; i++)
				{
					GameObject val2 = __instance._lobbyListEntries[i];
					LobbyDataEntry component = val2.GetComponent<LobbyDataEntry>();
					if ((Object)(object)component != (Object)null && component._lobbyName == _cachedDesiredLobbyName)
					{
						val = val2;
						num = i;
						break;
					}
				}
				if ((Object)(object)val != (Object)null && num != 0)
				{
					__instance._lobbyListEntries.RemoveAt(num);
					__instance._lobbyListEntries.Insert(0, val);
					val.transform.SetSiblingIndex(0);
					Logger.LogInfo((object)("Moved '" + _cachedDesiredLobbyName + "' to the top of the server list."));
				}
			}
		}

		[HarmonyPatch(typeof(SteamLobby), "GetLobbiesList")]
		public static class GetLobbiesListPatch
		{
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				MethodInfo methodInfo = AccessTools.Method(typeof(SteamMatchmaking), "AddRequestLobbyListResultCountFilter", (Type[])null, (Type[])null);
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].opcode == OpCodes.Call && list[i].operand is MethodInfo methodInfo2 && methodInfo2 == methodInfo && i > 0 && list[i - 1].opcode == OpCodes.Ldc_I4_S && (sbyte)list[i - 1].operand == 60)
					{
						list.RemoveAt(i - 1);
						list.RemoveAt(i - 1);
						Logger.LogInfo((object)"Successfully patched out SteamMatchmaking.AddRequestLobbyListResultCountFilter(60).");
						i -= 2;
					}
				}
				return list;
			}
		}

		[HarmonyPatch(typeof(ServerInfoObject), "Update")]
		public static class OnServerInfoObjectUpdatePatch
		{
			private static void Postfix(ServerInfoObject __instance)
			{
				if (!(_lastJoinedLobbyNameConfig.Value == __instance._serverName))
				{
					Logger.LogInfo((object)("Storing '" + __instance._serverName + "' as the last entered server."));
					_lastJoinedLobbyNameConfig.Value = __instance._serverName;
				}
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__4_0;

			internal void <Awake>b__4_0()
			{
				SettingsTab modTab = Settings.ModTab;
				modTab.AddHeader("Server Prioritizer");
				modTab.AddTextField("Server Name", _desiredLobbyNameConfig, "Server Name");
			}
		}

		internal static ManualLogSource Logger;

		private static ConfigEntry<string> _desiredLobbyNameConfig;

		private static ConfigEntry<string> _lastJoinedLobbyNameConfig;

		private static string _cachedDesiredLobbyName;

		private void Awake()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin com.fleetime.serverprioritizer is loaded!");
			_desiredLobbyNameConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ServerName", "Eu 24/7 SFW", "Enter the name of the ATLYSS server you want to see at the top of the list here. If left empty, the last joined server will appear on top.");
			_lastJoinedLobbyNameConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "LastJoinedServer", "", "No need to make any changes here, this field is only used for persistence.");
			_cachedDesiredLobbyName = _desiredLobbyNameConfig.Value;
			Logger.LogInfo((object)"EasySettings found – config UI enabled.");
			UnityEvent onInitialized = Settings.OnInitialized;
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					SettingsTab modTab = Settings.ModTab;
					modTab.AddHeader("Server Prioritizer");
					modTab.AddTextField("Server Name", _desiredLobbyNameConfig, "Server Name");
				};
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			onInitialized.AddListener((UnityAction)obj);
			Settings.OnApplySettings.AddListener((UnityAction)delegate
			{
				((BaseUnityPlugin)this).Config.Save();
				_cachedDesiredLobbyName = _desiredLobbyNameConfig.Value;
				Logger.LogInfo((object)("Desired server name set to '" + _cachedDesiredLobbyName + "'"));
			});
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Logger.LogInfo((object)("Desired server name set to '" + _cachedDesiredLobbyName + "'"));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.fleetime.serverprioritizer";

		public const string PLUGIN_NAME = "ServerPrioritizer";

		public const string PLUGIN_VERSION = "0.0.4";
	}
}