Decompiled source of AutoConnect v0.1.2

AutoConnect.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutoConnect.UIComponents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.UI;
using Stunlock.Core;
using Stunlock.Localization;
using Stunlock.Network;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutoConnect")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A V Rising mod to customize your crosshairs")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+1.Branch.master.Sha.17fa4a5be14753c477cf9bad0a40fb73056811f1.17fa4a5be14753c477cf9bad0a40fb73056811f1")]
[assembly: AssemblyProduct("AutoConnect")]
[assembly: AssemblyTitle("AutoConnect")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.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 AutoConnect
{
	public class Configuration
	{
		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<float> WaitSeconds;

		internal static void Initialize(ConfigFile config)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			config.SaveOnConfigSet = true;
			ModEnabled = config.Bind<bool>("Options", "ModEnabled", false, "Enables or disables the mod.");
			WaitSeconds = config.Bind<float>("Options", "WaitSeconds", 30f, new ConfigDescription("The amount of seconds to wait before reconnecting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 120f), Array.Empty<object>()));
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(30, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Initialized configuration file");
			}
			log.LogInfo(val);
		}
	}
	[BepInPlugin("AutoConnect", "AutoConnect", "0.1.2")]
	public class Plugin : BasePlugin
	{
		private static Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		public override void Load()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			Configuration.Initialize(((BasePlugin)this).Config);
			_harmony = new Harmony("AutoConnect");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("AutoConnect");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.2");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "AutoConnect";

		public const string PLUGIN_NAME = "AutoConnect";

		public const string PLUGIN_VERSION = "0.1.2";
	}
}
namespace AutoConnect.UIComponents
{
	internal class CustomHeader
	{
		private OptionsPanel_Interface _panel;

		private string _label;

		public CustomHeader Panel(OptionsPanel_Interface panel)
		{
			_panel = panel;
			return this;
		}

		public CustomHeader Label(string label)
		{
			_label = label;
			return this;
		}

		public SettingsEntry_Label Build()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			AssetGuid val = AssetGuid.NewGuid();
			LocalizationKey val2 = default(LocalizationKey);
			((LocalizationKey)(ref val2))..ctor(val);
			Localization.LocalizedStrings.Add(val, _label);
			SettingsEntry_Label obj = OptionsHelper.AddHeader(_panel.ContentNode, _panel.HeaderPrefab, val2);
			((TMP_Text)((SettingsEntryBase)obj).HeaderText.Text).text = _label;
			return obj;
		}
	}
	internal class CustomSlider
	{
		private OptionsPanel_Interface _panel;

		private string _label;

		private float _minvalue;

		private float _maxvalue;

		private float _defaultvalue;

		private float _initialvalue;

		private Action<float> _onValueChanged;

		public CustomSlider Panel(OptionsPanel_Interface panel)
		{
			_panel = panel;
			return this;
		}

		public CustomSlider Label(string label)
		{
			_label = label;
			return this;
		}

		public CustomSlider MinValue(float defaultValue)
		{
			_minvalue = defaultValue;
			return this;
		}

		public CustomSlider MaxValue(float initialValue)
		{
			_maxvalue = initialValue;
			return this;
		}

		public CustomSlider DefaultValue(float defaultValue)
		{
			_defaultvalue = defaultValue;
			return this;
		}

		public CustomSlider InitialValue(float initialValue)
		{
			_initialvalue = initialValue;
			return this;
		}

		public CustomSlider OnValueChanged(Action<float> callback)
		{
			_onValueChanged = callback;
			return this;
		}

		public SettingsEntry_Slider Build()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			AssetGuid val = AssetGuid.NewGuid();
			LocalizationKey val2 = default(LocalizationKey);
			((LocalizationKey)(ref val2))..ctor(val);
			if (_label != null)
			{
				Localization.LocalizedStrings.Add(val, _label);
			}
			return OptionsHelper.AddSlider(_panel.ContentNode, _panel.SliderPrefab, false, val2, default(Nullable_Unboxed<LocalizationKey>), _minvalue, _maxvalue, _defaultvalue, _initialvalue, 1, true, Action<float>.op_Implicit(_onValueChanged));
		}
	}
	internal class CustomToggle
	{
		private OptionsPanel_Interface _panel;

		private string _label;

		private string _tooltip;

		private bool _defaultValue;

		private bool _initialValue;

		private Action<bool> _onValueChanged;

		public CustomToggle Panel(OptionsPanel_Interface panel)
		{
			_panel = panel;
			return this;
		}

		public CustomToggle Label(string label)
		{
			_label = label;
			return this;
		}

		public CustomToggle Tooltip(string tooltip)
		{
			_tooltip = tooltip;
			return this;
		}

		public CustomToggle DefaultValue(bool defaultValue)
		{
			_defaultValue = defaultValue;
			return this;
		}

		public CustomToggle InitialValue(bool initialValue)
		{
			_initialValue = initialValue;
			return this;
		}

		public CustomToggle OnValueChanged(Action<bool> callback)
		{
			_onValueChanged = callback;
			return this;
		}

		public SettingsEntry_Checkbox Build()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			AssetGuid val = AssetGuid.NewGuid();
			LocalizationKey val2 = default(LocalizationKey);
			((LocalizationKey)(ref val2))..ctor(val);
			AssetGuid val3 = AssetGuid.NewGuid();
			LocalizationKey val4 = default(LocalizationKey);
			((LocalizationKey)(ref val4))..ctor(val3);
			if (_label != null)
			{
				Localization.LocalizedStrings.Add(val, _label);
			}
			if (_tooltip != null)
			{
				Localization.LocalizedStrings.Add(val3, _tooltip);
			}
			SettingsEntry_Checkbox val5 = OptionsHelper.AddCheckbox(_panel.ContentNode, _panel.CheckboxPrefab, false, val2, val4, _defaultValue, _initialValue, Action<bool>.op_Implicit(_onValueChanged), (Func<bool>)null);
			if (_tooltip != null)
			{
				((DatalessSelectionGroupBase<SettingsEntryBase>)(object)_panel.EntriesSelectionGroup).Entries.Add((SettingsEntryBase)(object)val5);
			}
			return val5;
		}
	}
}
namespace AutoConnect.Patches
{
	[HarmonyPatch(typeof(ClientBootstrapSystem))]
	internal static class ClientBootstrapSystemPatches
	{
		private static bool _retryPending;

		private static double _retryTime;

		private static float _nextUpdateTime;

		private static TextMeshProUGUI _cachedText;

		private static ClientConnectData _last;

		[HarmonyPatch("OnStatusChangedEvent")]
		[HarmonyPostfix]
		public static void OnStatusChanged(StatusChangedEvent statusChangedEvent, ClientBootstrapSystem __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			if ((int)statusChangedEvent.Status != 5 || !Configuration.ModEnabled.Value)
			{
				UpdateCountdownText("Connecting");
				_retryPending = false;
			}
			else if ((int)__instance.DisconnectChangeReason == 11)
			{
				_last = __instance._LastConnectData;
				_retryTime = Time.unscaledTime + Configuration.WaitSeconds.Value;
				_retryPending = true;
			}
		}

		[HarmonyPatch("OnUpdate")]
		[HarmonyPostfix]
		public static void OnUpdate(ClientBootstrapSystem __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (_retryPending && Configuration.ModEnabled.Value)
			{
				UpdateCountdownText();
				if ((double)Time.unscaledTime >= _retryTime)
				{
					_retryPending = false;
					__instance.Connect(_last.ConnectAddress, _last.FallbackConnectAddress.value, _last.PlatformIds, _last.SessionTicket, _last.Password);
				}
			}
		}

		private static void UpdateCountdownText(string text = null)
		{
			if (!_retryPending || Time.unscaledTime < _nextUpdateTime)
			{
				return;
			}
			_nextUpdateTime = Mathf.Floor(Time.unscaledTime) + 1f;
			int num = Mathf.CeilToInt((float)(_retryTime - (double)Time.unscaledTime));
			if (num < 0)
			{
				num = 0;
			}
			if ((Object)(object)_cachedText == (Object)null || !Object.op_Implicit((Object)(object)_cachedText))
			{
				GameObject val = GameObject.Find("MainMenuCanvas(Clone)");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Transform val2 = val.transform.Find("Canvas/MenuParent/ConnectionView(Clone)/LoadingContent/LoadingTextContainer");
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				_cachedText = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>();
			}
			if ((Object)(object)_cachedText != (Object)null && text == null)
			{
				((TMP_Text)_cachedText).text = $"[<color=#ecdd1f>AutoConnect</color>] Server is full! Reconnecting in {num} second{((num == 1) ? "" : "s")}...\n";
			}
			else
			{
				((TMP_Text)_cachedText).text = text;
			}
		}
	}
	[HarmonyPatch(typeof(OptionsPanel_Interface), "Start")]
	internal static class Patch_OptionsPanel_Interface
	{
		[HarmonyPostfix]
		private static void Postfix(OptionsPanel_Interface __instance)
		{
			new CustomHeader().Panel(__instance).Label("AutoConnect 0.1.2").Build();
			new CustomToggle().Panel(__instance).Label("Enable Mod").Tooltip("<align=\"center\">Enable or disable the mod.</align>")
				.DefaultValue(defaultValue: false)
				.InitialValue(Configuration.ModEnabled.Value)
				.OnValueChanged(OnModEnabledToggle)
				.Build();
			new CustomSlider().Panel(__instance).Label("Seconds Before Reconnect").MinValue(5f)
				.MaxValue(120f)
				.InitialValue(Configuration.WaitSeconds.Value)
				.DefaultValue(30f)
				.OnValueChanged(OnWaitSecondsChanged)
				.Build();
		}

		private static void OnModEnabledToggle(bool value)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Configuration.ModEnabled.Value = value;
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[UI] Mod enabled changed to: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(value);
			}
			log.LogInfo(val);
		}

		private static void OnWaitSecondsChanged(float value)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Configuration.WaitSeconds.Value = value;
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(30, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[UI] Wait seconds changed to: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(value);
			}
			log.LogInfo(val);
		}
	}
}