Decompiled source of ServerQuickConnect v1.0.1

plugins/ServerQuickConnect.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: AssemblyFileVersion("1.0.1")]
[assembly: Guid("C2C7B9C4-6E5A-4A3D-9F57-5E2B4E8D91A1")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyProduct("Server Quick Connect")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Server Quick Connect")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Radamanto")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServerQuickConnect
{
	internal static class MenuQuickConnect
	{
		[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
		private static class Patch_FejdStartup_SetupGui
		{
			private static void Postfix(FejdStartup __instance)
			{
				if (IsEnabled())
				{
					TryApplyButton(__instance);
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnQuickConnectClicked;
		}

		private static readonly FieldRef<FejdStartup, ServerJoinData> FR_m_queuedJoinServer = AccessTools.FieldRefAccess<FejdStartup, ServerJoinData>("m_queuedJoinServer");

		private static readonly MethodInfo? MI_HideAll = AccessTools.Method(typeof(FejdStartup), "HideAll", (Type[])null, (Type[])null);

		private static readonly MethodInfo? MI_ShowCharacterSelection = AccessTools.Method(typeof(FejdStartup), "ShowCharacterSelection", (Type[])null, (Type[])null);

		private static GameObject? _quickConnectButton;

		private static bool IsEnabled()
		{
			return ServerQuickConnectPlugin.CE_QuickConnect_Enabled.Value;
		}

		private static void TryApplyButton(FejdStartup fs)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			if ((Object)(object)fs?.m_menuList == (Object)null)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)_quickConnectButton))
			{
				if (!((Object)(object)_quickConnectButton.transform.parent == (Object)null))
				{
					SetButtonText(_quickConnectButton, ServerQuickConnectPlugin.CE_QuickConnect_ButtonText.Value);
					Button val = _quickConnectButton.GetComponent<Button>() ?? _quickConnectButton.GetComponentInChildren<Button>(true);
					if (Object.op_Implicit((Object)(object)val))
					{
						((UnityEventBase)val.onClick).RemoveAllListeners();
						ButtonClickedEvent onClick = val.onClick;
						object obj = <>O.<0>__OnQuickConnectClicked;
						if (obj == null)
						{
							UnityAction val2 = OnQuickConnectClicked;
							<>O.<0>__OnQuickConnectClicked = val2;
							obj = (object)val2;
						}
						((UnityEvent)onClick).AddListener((UnityAction)obj);
						((Selectable)val).interactable = true;
					}
					_quickConnectButton.transform.SetSiblingIndex(0);
					return;
				}
				_quickConnectButton = null;
			}
			Transform val3 = fs.m_menuList.transform.Find("MenuEntries/Start game");
			if (!Object.op_Implicit((Object)(object)val3))
			{
				return;
			}
			Button component = ((Component)val3).GetComponent<Button>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)((Component)component).transform.parent))
			{
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)component).gameObject, ((Component)component).transform.parent, false);
			((Object)val4).name = "RD_QuickConnectButton";
			val4.SetActive(true);
			Button val5 = val4.GetComponent<Button>() ?? val4.GetComponentInChildren<Button>(true);
			if (!Object.op_Implicit((Object)(object)val5))
			{
				Object.Destroy((Object)(object)val4);
				return;
			}
			((UnityEventBase)val5.onClick).RemoveAllListeners();
			((Selectable)val5).navigation = ((Selectable)component).navigation;
			((Selectable)val5).transition = ((Selectable)component).transition;
			((Selectable)val5).interactable = true;
			ButtonClickedEvent onClick2 = val5.onClick;
			object obj2 = <>O.<0>__OnQuickConnectClicked;
			if (obj2 == null)
			{
				UnityAction val6 = OnQuickConnectClicked;
				<>O.<0>__OnQuickConnectClicked = val6;
				obj2 = (object)val6;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj2);
			SetButtonText(val4, ServerQuickConnectPlugin.CE_QuickConnect_ButtonText.Value);
			val4.transform.SetSiblingIndex(0);
			_quickConnectButton = val4;
		}

		private static void OnQuickConnectClicked()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (!IsEnabled())
			{
				return;
			}
			FejdStartup instance = FejdStartup.m_instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				string text = ServerQuickConnectPlugin.CE_QuickConnect_IP.Value?.Trim() ?? "";
				int value = ServerQuickConnectPlugin.CE_QuickConnect_Port.Value;
				string serverPassword = ServerQuickConnectPlugin.CE_QuickConnect_Password.Value ?? "";
				if (!string.IsNullOrEmpty(text) && value >= 1 && value <= 65535)
				{
					FejdStartup.ServerPassword = serverPassword;
					ServerJoinData val = default(ServerJoinData);
					((ServerJoinData)(ref val))..ctor(new ServerJoinDataDedicated(text, (ushort)value));
					FR_m_queuedJoinServer.Invoke(instance) = val;
					MI_HideAll?.Invoke(instance, Array.Empty<object>());
					MI_ShowCharacterSelection?.Invoke(instance, Array.Empty<object>());
				}
			}
		}

		private static void SetButtonText(GameObject go, string text)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = go.transform.Find("Text");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			Color color;
			bool flag = TryGetButtonColor(out color);
			Text component = ((Component)val).GetComponent<Text>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.text = text;
				if (flag)
				{
					((Graphic)component).color = color;
				}
			}
			TMP_Text component2 = ((Component)val).GetComponent<TMP_Text>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.text = text;
				if (flag)
				{
					((Graphic)component2).color = color;
					component2.faceColor = Color32.op_Implicit(color);
					component2.enableVertexGradient = false;
				}
				component2.ForceMeshUpdate(true, true);
			}
		}

		private static bool TryGetButtonColor(out Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			color = default(Color);
			string text = ServerQuickConnectPlugin.CE_QuickConnect_ButtonColor.Value?.Trim() ?? "";
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			return ColorUtility.TryParseHtmlString(text, ref color);
		}
	}
	[BepInPlugin("radamanto.ServerQuickConnect", "Server Quick Connect", "1.0.1")]
	public class ServerQuickConnectPlugin : BaseUnityPlugin
	{
		public const string ModGUID = "radamanto.ServerQuickConnect";

		public const string ModName = "Server Quick Connect";

		public const string ModVersion = "1.0.1";

		private readonly Harmony _harmony = new Harmony("radamanto.ServerQuickConnect");

		private static bool _bootstrapped;

		internal static ConfigEntry<bool> CE_QuickConnect_Enabled;

		internal static ConfigEntry<string> CE_QuickConnect_ButtonText;

		internal static ConfigEntry<string> CE_QuickConnect_IP;

		internal static ConfigEntry<int> CE_QuickConnect_Port;

		internal static ConfigEntry<string> CE_QuickConnect_Password;

		internal static ConfigEntry<string> CE_QuickConnect_ButtonColor;

		private void Awake()
		{
			if (!_bootstrapped)
			{
				_bootstrapped = true;
				CE_QuickConnect_Enabled = Cfg("02 - Quick Connect", "02.01 - Enabled", defaultValue: true, "Adds a main menu button that connects directly to the server.");
				CE_QuickConnect_ButtonText = Cfg("02 - Quick Connect", "02.02 - ButtonText", "Connect Vikings Server", "Text displayed on the main menu button.");
				CE_QuickConnect_ButtonColor = Cfg("02 - Quick Connect", "02.03 - ButtonColor", "#8CFF8CFF", "Button text color in HEX. Example: #8CFF8CFF. If invalid, the default template color is kept.");
				CE_QuickConnect_IP = Cfg("02 - Quick Connect", "02.04 - IP", "127.0.0.1", "Server IP address.");
				CE_QuickConnect_Port = Cfg("02 - Quick Connect", "02.05 - Port", 2456, "Server game port.");
				CE_QuickConnect_Password = Cfg("02 - Quick Connect", "02.06 - Password", "", "Server password.");
				_harmony.PatchAll();
			}
		}

		protected ConfigEntry<T> Cfg<T>(string section, string key, T defaultValue, string description)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
}