Decompiled source of Flees ServerPrioritizer v0.0.1

ServerPrioritizer.dll

Decompiled a day 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 Steamworks;
using UnityEngine;

[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("ServerPrioritizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cc5bc2a73b2e3ea71c8a5284d59ec56dfecfaeab")]
[assembly: AssemblyProduct("Server prioritizer for ATLYSS")]
[assembly: AssemblyTitle("ServerPrioritizer")]
[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 ServerPrioritizer
{
	[BepInPlugin("com.fleetime.serverprioritizer", "ServerPrioritizer", "0.0.1")]
	[BepInProcess("ATLYSS.exe")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(LobbyListManager))]
		[HarmonyPatch("Iterate_SteamLobbies")]
		public class IterateSteamLobbiesPatch
		{
			public static void Postfix(LobbyListManager __instance)
			{
				if (string.IsNullOrWhiteSpace(_cachedDesiredLobbyName) || __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))]
		[HarmonyPatch("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;
			}
		}

		internal static ManualLogSource Logger;

		private static ConfigEntry<string> _desiredLobbyNameConfig;

		private static string _cachedDesiredLobbyName;

		private void Awake()
		{
			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.");
			_cachedDesiredLobbyName = _desiredLobbyNameConfig.Value;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Logger.LogInfo((object)("Desired server name set to '" + _cachedDesiredLobbyName + "'"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.fleetime.serverprioritizer";

		public const string PLUGIN_NAME = "ServerPrioritizer";

		public const string PLUGIN_VERSION = "0.0.1";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ServerPrioritizer";

		public const string PLUGIN_NAME = "Server prioritizer for ATLYSS";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}