Decompiled source of QuickLaunch v1.0.11

Landoria.QuickLaunch.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using GUIFramework;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Landoria.QuickLaunch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Landoria.QuickLaunch")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("046ED613-45E5-48D3-9B7B-72703870DA05")]
[assembly: AssemblyFileVersion("1.0.11")]
[assembly: AssemblyInformationalVersion("1.0.11")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.11.33673")]
namespace Landoria.QuickLaunch;

[BepInPlugin("Landoria.QuickLaunch", "Landoria.QuickLaunch", "1.0.11")]
public sealed class QuickLaunchPlugin : BaseUnityPlugin
{
	private const string PluginGuid = "Landoria.QuickLaunch";

	private const string PluginName = "Landoria.QuickLaunch";

	private const string PluginVersion = "1.0.11";

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		QuickLaunchSession.Log = ((BaseUnityPlugin)this).Logger;
		RememberedPassword.Log = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"AssemblyVersion: {((object)this).GetType().Assembly.GetName().Version}.");
		_harmony = new Harmony("Landoria.QuickLaunch");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Landoria.QuickLaunch 1.0.11 is loaded.");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		_harmony = null;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Landoria.QuickLaunch 1.0.11 is unloaded.");
		QuickLaunchSession.Log = null;
		RememberedPassword.Log = null;
	}
}
internal static class QuickLaunchSession
{
	private const string LastSessionPreference = "Landoria.QuickLaunch.LastSession";

	private const string LastServerPreference = "Landoria.QuickLaunch.LastServer";

	private const string LastServerNamePreference = "Landoria.QuickLaunch.LastServerName";

	private const string LastBackendPreference = "Landoria.QuickLaunch.LastBackend";

	private const string LastPlayFabHostPreference = "Landoria.QuickLaunch.LastPlayFabHost";

	private const string LocalSession = "local";

	private const string MultiplayerSession = "multiplayer";

	private static bool _attemptedAutoStart;

	private static bool _launchingAutomatically;

	private static ServerJoinData _joiningServer = ServerJoinData.None;

	internal static ManualLogSource Log { get; set; }

	internal static bool IsAutomaticLoading { get; private set; }

	internal static string ConnectingServerName { get; private set; }

	internal static void StartLastSession(FejdStartup startup)
	{
		IsAutomaticLoading = false;
		RememberedPassword.Reset();
		if (_attemptedAutoStart)
		{
			return;
		}
		_attemptedAutoStart = true;
		if (!CancelAutomaticStart())
		{
			string profileFilename = PlatformPrefs.GetString("profile", "");
			if (RememberedProfileExists(profileFilename))
			{
				StartRememberedSession(startup, profileFilename);
			}
		}
	}

	internal static void RecordLocalSession()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Log.LogDebug((object)"QuickLaunch FejdStartup.OnWorldStart prefix invoked.");
		IsAutomaticLoading = _launchingAutomatically;
		_joiningServer = ServerJoinData.None;
		ConnectingServerName = null;
		RememberedPassword.Reset();
		ClearSessionPreferences();
		PlatformPrefs.SetString("Landoria.QuickLaunch.LastSession", "local");
		PlatformPrefs.Save();
	}

	internal static void RecordMultiplayerSession(FejdStartup startup)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		Log.LogDebug((object)"QuickLaunch FejdStartup.JoinServer prefix invoked.");
		IsAutomaticLoading = _launchingAutomatically || (IsAutomaticLoading && ((ServerJoinData)(ref _joiningServer)).IsValid && _joiningServer == startup.GetServerToJoin());
		if (startup.HasServerToJoin())
		{
			_joiningServer = startup.GetServerToJoin();
			RememberedPassword.BeginAttempt(IsAutomaticLoading && IsRememberedServer(_joiningServer));
			ConnectingServerName = GetConnectingServerName(_joiningServer);
		}
	}

	internal unsafe static void RememberConnectedServer(ZNet network)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if (!network.IsServer() && ((ServerJoinData)(ref _joiningServer)).IsValid && (int)ZNet.GetConnectionStatus() == 2)
		{
			OnlineBackendType onlineBackend = ZNet.m_onlineBackend;
			ClearSessionPreferences();
			PlatformPrefs.SetString("Landoria.QuickLaunch.LastServer", $"{_joiningServer.m_type}:{_joiningServer}");
			PlatformPrefs.SetString("Landoria.QuickLaunch.LastBackend", ((object)(*(OnlineBackendType*)(&onlineBackend))/*cast due to .constrained prefix*/).ToString());
			string connectingServerName = default(string);
			if (MultiBackendMatchmaking.TryGetServerName(_joiningServer, ref connectingServerName))
			{
				ConnectingServerName = connectingServerName;
			}
			SaveConnectedServer(onlineBackend, network.GetWorldName());
		}
	}

	private static void StartRememberedSession(FejdStartup startup, string profileFilename)
	{
		if (PlatformPrefs.GetString("Landoria.QuickLaunch.LastSession", "") == "multiplayer")
		{
			JoinLastMultiplayerSession(startup, profileFilename);
			return;
		}
		string worldName = PlatformPrefs.GetString("world", "");
		if (RememberedWorldExists(worldName))
		{
			startup.OnCharacterStart();
			if (IsRememberedWorldSelected(startup, worldName))
			{
				StartWorld(startup, profileFilename, worldName);
			}
		}
	}

	private static bool CancelAutomaticStart()
	{
		if (!ZInput.GetKey((KeyCode)27, true))
		{
			return false;
		}
		Log.LogDebug((object)"QuickLaunch cancelled with Escape; saved session unchanged.");
		return true;
	}

	private static bool RememberedProfileExists(string profileFilename)
	{
		if (string.IsNullOrEmpty(profileFilename))
		{
			return false;
		}
		return SaveSystem.GetAllPlayerProfiles().Exists((PlayerProfile profile) => profile.GetFilename() == profileFilename);
	}

	private static bool RememberedWorldExists(string worldName)
	{
		if (string.IsNullOrEmpty(worldName))
		{
			return false;
		}
		return SaveSystem.GetWorldList().Exists((World world) => world.m_name == worldName);
	}

	private static void JoinLastMultiplayerSession(FejdStartup startup, string profileFilename)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		LocalServerList val = new LocalServerList((string)null, ServerListGui.GetServerListLocations("recent"));
		ServerJoinData val3;
		try
		{
			if (val.Count == 0)
			{
				goto IL_002a;
			}
			ServerJoinData val2 = val[0];
			if (!((ServerJoinData)(ref val2)).IsValid)
			{
				goto IL_002a;
			}
			val3 = val[0];
			startup.SetServerToJoin(val3);
			goto end_IL_0011;
			IL_002a:
			Log.LogError((object)"QuickLaunch could not find a valid recent multiplayer server.");
			return;
			end_IL_0011:;
		}
		finally
		{
			((IDisposable)val)?.Dispose();
		}
		((MonoBehaviour)startup).StartCoroutine(JoinWhenReady(startup, val3, profileFilename));
	}

	private static IEnumerator JoinWhenReady(FejdStartup startup, ServerJoinData server, string profileFilename)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		if (NeedsPlayFabLogin(server))
		{
			yield return WaitForPlayFab(startup, server);
		}
		if (!((Object)(object)startup == (Object)null) && !(startup.GetServerToJoin() != server) && !CancelAutomaticStart() && (!NeedsPlayFabLogin(server) || PlayFabManager.IsLoggedIn))
		{
			Log.LogDebug((object)$"QuickLaunch is joining multiplayer server '{server}' with character '{profileFilename}'.");
			startup.OnCharacterStart();
			RunAutomaticStart((Action)startup.OnJoinStart);
		}
	}

	private unsafe static bool NeedsPlayFabLogin(ServerJoinData server)
	{
		//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_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		ServerJoinDataType type = server.m_type;
		if (!(((object)(*(ServerJoinDataType*)(&type))/*cast due to .constrained prefix*/).ToString() == "PlayFabUser"))
		{
			type = server.m_type;
			return ((object)(*(ServerJoinDataType*)(&type))/*cast due to .constrained prefix*/).ToString() == "Dedicated";
		}
		return true;
	}

	private static IEnumerator WaitForPlayFab(FejdStartup startup, ServerJoinData server)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		Log.LogDebug((object)"QuickLaunch is waiting for PlayFab login in the background.");
		DateTime deadline = DateTime.UtcNow.AddSeconds(60.0);
		while (!PlayFabManager.IsLoggedIn && !CancelAutomaticStart() && !((Object)(object)startup == (Object)null) && !(startup.GetServerToJoin() != server))
		{
			if (DateTime.UtcNow >= deadline)
			{
				Log.LogWarning((object)"QuickLaunch stopped waiting for PlayFab login; staying in the menu.");
				break;
			}
			yield return null;
		}
	}

	private static void RunAutomaticStart(Action start)
	{
		_launchingAutomatically = true;
		try
		{
			start();
		}
		finally
		{
			_launchingAutomatically = false;
		}
	}

	private static void SaveConnectedServer(OnlineBackendType backend, string worldName)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Invalid comparison between Unknown and I4
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		PlatformPrefs.SetString("Landoria.QuickLaunch.LastServerName", ConnectingServerName ?? string.Empty);
		PlatformPrefs.SetString("Landoria.QuickLaunch.LastPlayFabHost", ((int)backend == 1) ? ZNet.GetServerString(false) : string.Empty);
		PlatformPrefs.SetString("Landoria.QuickLaunch.LastSession", "multiplayer");
		RememberedPassword.SaveSuccessfulAttempt();
		PlatformPrefs.Save();
		Log.LogDebug((object)($"QuickLaunch remembered connected server '{_joiningServer}' with backend '{backend}' " + "and world '" + worldName + "'."));
		_joiningServer = ServerJoinData.None;
	}

	private static void ClearSessionPreferences()
	{
		string[] array = new string[7] { "Landoria.QuickLaunch.LastSession", "Landoria.QuickLaunch.LastServer", "Landoria.QuickLaunch.LastServerName", "Landoria.QuickLaunch.LastBackend", "Landoria.QuickLaunch.LastPlayFabHost", "Landoria.QuickLaunch.LastWorld", "Landoria.QuickLaunch.LastPassword" };
		for (int i = 0; i < array.Length; i++)
		{
			PlatformPrefs.DeleteKey(array[i]);
		}
	}

	private static bool IsRememberedWorldSelected(FejdStartup startup, string worldName)
	{
		World value = Traverse.Create((object)startup).Field("m_world").GetValue<World>();
		if (value != null)
		{
			return value.m_name == worldName;
		}
		return false;
	}

	private static string GetConnectingServerName(ServerJoinData server)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		string text = default(string);
		if (MultiBackendMatchmaking.TryGetServerName(server, ref text) && !string.IsNullOrWhiteSpace(text))
		{
			return text;
		}
		if (!IsRememberedServer(server))
		{
			return null;
		}
		return PlatformPrefs.GetString("Landoria.QuickLaunch.LastServerName", "");
	}

	private unsafe static bool IsRememberedServer(ServerJoinData server)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		bool num = PlatformPrefs.GetString("Landoria.QuickLaunch.LastServer", "") == $"{server.m_type}:{server}";
		ServerJoinDataType type = server.m_type;
		bool flag = ((object)(*(ServerJoinDataType*)(&type))/*cast due to .constrained prefix*/).ToString() == "PlayFabUser" && PlatformPrefs.GetString("Landoria.QuickLaunch.LastBackend", "") == ((object)(OnlineBackendType)1/*cast due to .constrained prefix*/).ToString() && PlatformPrefs.GetString("Landoria.QuickLaunch.LastPlayFabHost", "") == ((ServerJoinData)(ref server)).PlayFabUser.m_remotePlayerId;
		return num || flag;
	}

	private static void StartWorld(FejdStartup startup, string profileFilename, string worldName)
	{
		Log.LogDebug((object)("QuickLaunch is joining local world '" + worldName + "' with character '" + profileFilename + "'."));
		RunAutomaticStart((Action)startup.OnWorldStart);
	}
}
[HarmonyPatch(typeof(FejdStartup), "Start")]
internal static class StartPatch
{
	private static void Prefix()
	{
		if ((Object)(object)CinematicsManager.s_instance != (Object)null)
		{
			CinematicsManager.s_instance.m_introOnStartup = false;
		}
	}

	private static void Postfix(FejdStartup __instance)
	{
		QuickLaunchSession.Log.LogDebug((object)"QuickLaunch FejdStartup.Start postfix invoked.");
		QuickLaunchSession.StartLastSession(__instance);
	}
}
[HarmonyPatch(typeof(FejdStartup), "OnWorldStart")]
internal static class LocalSessionPatch
{
	private static void Prefix()
	{
		QuickLaunchSession.RecordLocalSession();
	}
}
[HarmonyPatch(typeof(FejdStartup), "JoinServer")]
internal static class MultiplayerSessionPatch
{
	private static void Prefix(FejdStartup __instance)
	{
		QuickLaunchSession.RecordMultiplayerSession(__instance);
	}
}
[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
internal static class ConnectedServerPatch
{
	private static void Postfix(ZNet __instance)
	{
		QuickLaunchSession.RememberConnectedServer(__instance);
	}
}
[HarmonyPatch(typeof(Hud), "UpdateBlackScreen")]
internal static class LoadingWorldLabel
{
	private const string LabelName = "QuickLaunchWorldName";

	private const float DisplaySeconds = 6f;

	private static TMP_Text _label;

	private static Hud _hud;

	private static bool _initialLoadingFinished;

	private static float? _firstShownAt;

	private static void Postfix(Hud __instance, Player player)
	{
		ZNet instance = ZNet.instance;
		if ((Object)(object)_hud != (Object)(object)__instance)
		{
			_hud = __instance;
			_initialLoadingFinished = false;
			_firstShownAt = null;
			_label = null;
		}
		bool activeInHierarchy = ((Component)__instance.m_loadingScreen).gameObject.activeInHierarchy;
		if ((Object)(object)player != (Object)null && !activeInHierarchy)
		{
			_initialLoadingFinished = true;
		}
		bool num = QuickLaunchSession.IsAutomaticLoading && !_initialLoadingFinished && (!_firstShownAt.HasValue || Time.realtimeSinceStartup - _firstShownAt.Value < 6f) && (Object)(object)instance != (Object)null && (Object)(object)Game.instance != (Object)null && !Game.instance.IsShuttingDown() && activeInHierarchy;
		string text = null;
		if (num)
		{
			text = (instance.IsServer() ? instance.GetWorldName() : QuickLaunchSession.ConnectingServerName);
		}
		if (string.IsNullOrWhiteSpace(text))
		{
			if ((Object)(object)_label != (Object)null)
			{
				((Component)_label).gameObject.SetActive(false);
			}
			return;
		}
		if ((Object)(object)_label == (Object)null)
		{
			_label = CreateLabel(__instance);
		}
		if (!((Object)(object)_label == (Object)null))
		{
			if (!_firstShownAt.HasValue)
			{
				_firstShownAt = Time.realtimeSinceStartup;
			}
			string connectionText = GetConnectionText(text);
			if (_label.text != connectionText)
			{
				_label.text = connectionText;
			}
			((Component)_label).gameObject.SetActive(true);
		}
	}

	private static string GetConnectionText(string destination)
	{
		PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
		string text = ((playerProfile != null) ? playerProfile.GetName() : null);
		if (!string.IsNullOrWhiteSpace(text))
		{
			return "Connecting to " + destination + " with " + text;
		}
		return "Connecting to " + destination;
	}

	private static TMP_Text CreateLabel(Hud hud)
	{
		//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)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		TMP_Text componentInChildren = hud.m_loadingProgress.GetComponentInChildren<TMP_Text>(true);
		if ((Object)(object)componentInChildren == (Object)null)
		{
			return null;
		}
		GameObject val = new GameObject("QuickLaunchWorldName", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		val.transform.SetParent(((Component)hud.m_loadingScreen).transform, false);
		TMP_Text component = val.GetComponent<TMP_Text>();
		component.font = componentInChildren.font;
		component.fontSharedMaterial = componentInChildren.fontSharedMaterial;
		component.fontSize = 18f;
		component.fontStyle = (FontStyles)0;
		((Graphic)component).color = new Color(1f, 1f, 1f, 0.4f);
		component.alignment = (TextAlignmentOptions)1025;
		component.richText = false;
		((Graphic)component).raycastTarget = false;
		component.textWrappingMode = (TextWrappingModes)1;
		component.overflowMode = (TextOverflowModes)1;
		RectTransform rectTransform = component.rectTransform;
		Vector2 anchorMin = (rectTransform.anchorMax = Vector2.zero);
		rectTransform.anchorMin = anchorMin;
		rectTransform.pivot = Vector2.zero;
		rectTransform.anchoredPosition = new Vector2(24f, 24f);
		rectTransform.sizeDelta = new Vector2(500f, 48f);
		return component;
	}
}
internal static class RememberedPassword
{
	internal const string Preference = "Landoria.QuickLaunch.LastPassword";

	private static readonly byte[] Entropy = Encoding.UTF8.GetBytes("Landoria.QuickLaunch.Password.v1");

	private static string _savedCipher;

	private static string _candidateCipher;

	private static bool _activeAttempt;

	internal static ManualLogSource Log { private get; set; }

	internal static bool HasSavedPassword => !string.IsNullOrEmpty(_savedCipher);

	internal static void Reset()
	{
		_savedCipher = null;
		_candidateCipher = null;
		_activeAttempt = false;
	}

	internal static void BeginAttempt(bool restore)
	{
		Reset();
		_activeAttempt = true;
		if (restore && Environment.OSVersion.Platform == PlatformID.Win32NT)
		{
			_savedCipher = PlatformPrefs.GetString("Landoria.QuickLaunch.LastPassword", "");
		}
	}

	internal static void SaveSuccessfulAttempt()
	{
		if (!string.IsNullOrEmpty(_candidateCipher))
		{
			PlatformPrefs.SetString("Landoria.QuickLaunch.LastPassword", _candidateCipher);
		}
		Reset();
	}

	internal static void Capture(ZNet network, string password)
	{
		if (!_activeAttempt || network.IsServer() || string.IsNullOrEmpty(password) || Environment.OSVersion.Platform != PlatformID.Win32NT)
		{
			return;
		}
		byte[] bytes = Encoding.UTF8.GetBytes(password);
		try
		{
			_candidateCipher = Convert.ToBase64String(ProtectedData.Protect(bytes, Entropy, (DataProtectionScope)0));
		}
		catch (Exception arg)
		{
			Log.LogWarning((object)$"QuickLaunch could not protect the server password: {arg}");
			_candidateCipher = null;
		}
		finally
		{
			Array.Clear(bytes, 0, bytes.Length);
		}
	}

	internal static string Restore()
	{
		byte[] array = null;
		try
		{
			array = ProtectedData.Unprotect(Convert.FromBase64String(_savedCipher), Entropy, (DataProtectionScope)0);
			return Encoding.UTF8.GetString(array);
		}
		catch (Exception arg)
		{
			Log.LogWarning((object)$"QuickLaunch could not restore the server password: {arg}");
			PlatformPrefs.DeleteKey("Landoria.QuickLaunch.LastPassword");
			PlatformPrefs.Save();
			return null;
		}
		finally
		{
			if (array != null)
			{
				Array.Clear(array, 0, array.Length);
			}
			_savedCipher = null;
		}
	}

	internal static void HandleConnectionError(ConnectionStatus status)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Invalid comparison between Unknown and I4
		if (_activeAttempt && (int)status == 6)
		{
			PlatformPrefs.DeleteKey("Landoria.QuickLaunch.LastPassword");
			PlatformPrefs.Save();
		}
		Reset();
	}
}
[HarmonyPatch(typeof(ZNet), "SendPeerInfo")]
internal static class CapturePasswordPatch
{
	private static void Prefix(ZNet __instance, string password)
	{
		RememberedPassword.Capture(__instance, password);
	}
}
[HarmonyPatch(typeof(ZNet), "RPC_ClientHandshake")]
internal static class SubmitPasswordPatch
{
	private static void Postfix(ZNet __instance, bool needPassword)
	{
		if (needPassword && QuickLaunchSession.IsAutomaticLoading && RememberedPassword.HasSavedPassword && __instance.InPasswordDialog())
		{
			string text = RememberedPassword.Restore();
			if (!string.IsNullOrEmpty(text))
			{
				((UnityEvent<string>)(object)((Component)__instance.m_passwordDialog).GetComponentInChildren<GuiInputField>().OnInputSubmit).Invoke(text);
			}
		}
	}
}
[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
internal static class InvalidPasswordPatch
{
	private static void Prefix(ConnectionStatus statusOverride)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		RememberedPassword.HandleConnectionError(((int)statusOverride == 0) ? ZNet.GetConnectionStatus() : statusOverride);
	}
}