Decompiled source of QuickLaunch v1.0.0

QuickLaunch.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Reptile;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("QuickLaunch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QuickLaunch")]
[assembly: AssemblyTitle("QuickLaunch")]
[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 QuickLaunch
{
	internal class QuickLaunchConfig
	{
		private ConfigEntry<QuickLaunchMode> _mode;

		public QuickLaunchMode Mode => _mode.Value;

		public QuickLaunchConfig(ConfigFile configFile)
		{
			_mode = configFile.Bind<QuickLaunchMode>("General", "Mode", QuickLaunchMode.LoadLastSave, "What to do when starting up the game. If loading or creating a save fails, you will simply be sent to the main menu.");
		}
	}
	internal enum QuickLaunchMode
	{
		LoadLastSave,
		SkipIntro,
		CreateNewSaveInFreeSlot,
		CreateNewSaveInSlot1,
		CreateNewSaveInSlot2,
		CreateNewSaveInSlot3,
		LoadSaveInSlot1,
		LoadSaveInSlot2,
		LoadSaveInSlot3
	}
	[BepInPlugin("QuickLaunch", "QuickLaunch", "1.0.0")]
	internal class QuickLaunchPlugin : BaseUnityPlugin
	{
		public static QuickLaunchPlugin Instance { get; private set; }

		public QuickLaunchConfig LaunchConfig { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			try
			{
				new Harmony("QuickLaunch").PatchAll();
				LaunchConfig = new QuickLaunchConfig(((BaseUnityPlugin)this).Config);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"QuickLaunch 1.0.0 loaded!");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("Failed to load {0} {1}!{2}{3}", "QuickLaunch", "1.0.0", Environment.NewLine, ex));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "QuickLaunch";

		public const string PLUGIN_NAME = "QuickLaunch";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace QuickLaunch.Patches
{
	[HarmonyPatch(typeof(Bootstrap))]
	internal class BootstrapPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("LaunchGame")]
		private static bool LaunchGame_Prefix(Bootstrap __instance)
		{
			((MonoBehaviour)__instance).StartCoroutine(SetupGameQuickLaunch(__instance));
			return false;
		}

		private static IEnumerator SetupGameQuickLaunch(Bootstrap bootstrap)
		{
			string coreSceneName = Path.GetFileNameWithoutExtension(bootstrap.sceneLibrary.coreScenePath);
			yield return bootstrap.LoadSceneAssets(coreSceneName);
			SceneManager.SetActiveScene(SceneManager.GetSceneByName(coreSceneName));
			Core.Instance.StartCore(bootstrap.assets, bootstrap.gameVersion);
			((MonoBehaviour)Core.Instance.BaseModule).StartCoroutine(StartGameQuickLaunch(Core.Instance.BaseModule));
		}

		private static IEnumerator StartGameQuickLaunch(BaseModule baseModule)
		{
			QuickLaunchMode mode = QuickLaunchPlugin.Instance.LaunchConfig.Mode;
			baseModule.ShowLoadingScreen();
			yield return baseModule.user.LoginASync();
			if (baseModule.user.IsLoggedIn)
			{
				yield return baseModule.user.LoadUserSaveData();
				SaveManager saveManager = baseModule.saveManager;
				baseModule.TriggerPostLoginAttemptEvents(baseModule.user.IsLoggedIn);
				baseModule.uiManager.InstantiateMainMenuSceneUI();
				bool flag = false;
				int num = saveManager.UsedSaveSlotCount;
				if (num >= 3)
				{
					num = -1;
				}
				switch (mode)
				{
				case QuickLaunchMode.LoadSaveInSlot1:
					mode = QuickLaunchMode.LoadLastSave;
					saveManager.SetCurrentSaveSlot(0);
					break;
				case QuickLaunchMode.LoadSaveInSlot2:
					mode = QuickLaunchMode.LoadLastSave;
					saveManager.SetCurrentSaveSlot(1);
					break;
				case QuickLaunchMode.LoadSaveInSlot3:
					mode = QuickLaunchMode.LoadLastSave;
					saveManager.SetCurrentSaveSlot(2);
					break;
				}
				switch (mode)
				{
				case QuickLaunchMode.LoadLastSave:
				{
					if (saveManager.HasCurrentSaveSlot)
					{
						baseModule.StartGameFromCurrentSaveSlotToStage(saveManager.CurrentSaveSlot.CurrentStage);
						break;
					}
					baseModule.uiManager.InstantiateMainMenuSceneUI();
					ASceneSetupInstruction val2 = baseModule.PrepareLoadMainMenuSceneInstruction();
					baseModule.StartSceneSetup(val2);
					while (baseModule.IsLoading)
					{
						yield return null;
					}
					yield break;
				}
				case QuickLaunchMode.SkipIntro:
				{
					baseModule.uiManager.InstantiateMainMenuSceneUI();
					ASceneSetupInstruction val = baseModule.PrepareLoadMainMenuSceneInstruction();
					baseModule.StartSceneSetup(val);
					while (baseModule.IsLoading)
					{
						yield return null;
					}
					yield break;
				}
				case QuickLaunchMode.CreateNewSaveInSlot1:
					flag = true;
					num = 0;
					break;
				case QuickLaunchMode.CreateNewSaveInSlot2:
					flag = true;
					num = 1;
					break;
				case QuickLaunchMode.CreateNewSaveInSlot3:
					flag = true;
					num = 2;
					break;
				case QuickLaunchMode.CreateNewSaveInFreeSlot:
					flag = true;
					break;
				}
				if (!flag)
				{
					yield break;
				}
				if (num < 0 || num >= 3)
				{
					baseModule.uiManager.InstantiateMainMenuSceneUI();
					ASceneSetupInstruction val3 = baseModule.PrepareLoadMainMenuSceneInstruction();
					baseModule.StartSceneSetup(val3);
					while (baseModule.IsLoading)
					{
						yield return null;
					}
				}
				else
				{
					baseModule.StartNewGameForSaveSlot(num);
				}
			}
			else
			{
				baseModule.GoBackToIntro();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}