Skip to content

Commit

Permalink
Delay skipping Launch Options until after settings are loaded. (#4)
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
flerouwu committed Feb 1, 2024
1 parent fa474b9 commit 75c144b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
18 changes: 18 additions & 0 deletions FastStartup/Patches/PreInitSceneScriptPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FastStartup.TimeSavers;
using HarmonyLib;

namespace FastStartup.Patches;

// ReSharper disable InconsistentNaming
[HarmonyPatch(typeof(PreInitSceneScript))]
public static class PreInitSceneScriptPatch {
[HarmonyPrefix]
[HarmonyPatch("SkipToFinalSetting")]
public static bool SkipToFinalSetting(PreInitSceneScript __instance) {
if (!Plugin.Config.SkipLaunchMode.Value) return true;

__instance.launchSettingsPanelsContainer.SetActive(false);
LaunchOptionsSaver.Start();
return false;
}
}
11 changes: 6 additions & 5 deletions FastStartup/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using BepInEx;
using FastStartup.Patches;
using FastStartup.TimeSavers;
using HarmonyLib;
using UnityEngine.SceneManagement;

namespace FastStartup;
Expand All @@ -15,11 +17,6 @@ public class Plugin : BaseUnityPlugin {

private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
switch (scene.name) {
// Launch Mode scene
case "InitSceneLaunchOptions":
new LaunchOptionsSaver().Start();
break;

// Boot Animation scene
case "InitScene":
case "InitSceneLANMode":
Expand All @@ -43,6 +40,10 @@ public class Plugin : BaseUnityPlugin {

SceneManager.sceneLoaded += OnSceneLoaded;
Logger.LogInfo($"Plugin {ModId} is loaded!");

Logger.LogInfo("Loading patches...");
var harmony = new Harmony(ModId);
harmony.PatchAll(typeof(PreInitSceneScriptPatch));
}


Expand Down
4 changes: 1 addition & 3 deletions FastStartup/TimeSavers/LaunchOptionsSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace FastStartup.TimeSavers;
/// </summary>
internal static class LaunchOptionsSaver {
private static readonly ManualLogSource LogSource = new($"{Plugin.ModName}.Savers.LaunchOptions");
private static bool HasRan;
public static bool HasRan;

static LaunchOptionsSaver() {
Logger.Sources.Add(LogSource);
Expand All @@ -23,8 +23,6 @@ internal static class LaunchOptionsSaver {
if (HasRan) return;
HasRan = true;

Plugin.Initialize();

var mode = Plugin.Config.AutoLaunchMode.Value;
LogSource.LogInfo($"Skipping launch options, defaulting to {Plugin.Config.AutoLaunchMode.Value}.");
switch (mode) {
Expand Down
2 changes: 1 addition & 1 deletion FastStartup/TimeSavers/SplashSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static class SplashSaver {
// or if I could just do this once when the mod was loaded, but I
// found no luck.
// - flerouwu
while (!Plugin.Initialized) {
while (!LaunchOptionsSaver.HasRan) {
SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
if (Time.realtimeSinceStartup < duration) continue;
Expand Down

0 comments on commit 75c144b

Please sign in to comment.