diff --git a/plugin_template/swinfo.json b/plugin_template/swinfo.json index 35fbf0c..8b294aa 100644 --- a/plugin_template/swinfo.json +++ b/plugin_template/swinfo.json @@ -5,10 +5,10 @@ "name": "Skip Splash Screen", "description": "Skips the splash screen and health warning. To be used only for developing mods (faster iteration).", "source": "https://github.com/Falki-git/SkipSplashScreen", - "version": "1.2.0", + "version": "1.3.0", "version_check": "https://raw.githubusercontent.com/Falki-git/SkipSplashScreen/master/plugin_template/swinfo.json", "ksp2_version": { - "min": "0.1.5", + "min": "0.2.1", "max": "*" }, "dependencies": [ diff --git a/src/SkipSplashScreen/SkipSplashScreenPlugin.cs b/src/SkipSplashScreen/SkipSplashScreenPlugin.cs index 0229fdf..e0236a8 100644 --- a/src/SkipSplashScreen/SkipSplashScreenPlugin.cs +++ b/src/SkipSplashScreen/SkipSplashScreenPlugin.cs @@ -1,5 +1,4 @@ -using System.Collections; -using BepInEx; +using BepInEx; using BepInEx.Configuration; using HarmonyLib; using JetBrains.Annotations; @@ -22,22 +21,31 @@ public class SkipSplashScreenPlugin : BaseSpaceWarpPlugin private new static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("SkipSplashScreen"); + private GameObject _mainMenu; private CampaignMenu _campaignMenuScript; private bool _singlePlayerMenuTriggered; private bool _loadInitiated; private bool _hasFinished; private ConfigEntry _loadLastSavedCampaign; + private ConfigEntry _loadIgnoreAutoSaves; public void Start() { Harmony.CreateAndPatchAll(typeof(SkipSplashScreenPlugin)); - + _loadLastSavedCampaign = Config.Bind( MyPluginInfo.PLUGIN_NAME, "Auto load last played campaign", false, "Automatically loads the last save game file after main menu is finished loading."); + + _loadIgnoreAutoSaves = Config.Bind( + MyPluginInfo.PLUGIN_NAME, + "Ignore auto-saves when loading last save game", + false, + "If enabled, auto-saves are ignored when automatically loading last save game."); + } public void Update() @@ -87,9 +95,9 @@ private void TriggerSinglePlayerMenu() { Logger.LogInfo("'Auto load last played campaign' is enabled. To turn it off go into Settings -> Mods -> Skip Splash Screen"); - var mainMenu = GameObject.Find( + _mainMenu = GameObject.Find( "GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/MainMenu(Clone)/"); - var campaignMenu = mainMenu.GetChild("CampaignMenu"); + var campaignMenu = _mainMenu.GetChild("CampaignMenu"); _campaignMenuScript = campaignMenu.GetComponent(); var campaignSavesList = _campaignMenuScript.Game.SaveLoadManager.GetCampaignSaveFiles(CampaignType.SinglePlayer); @@ -100,43 +108,39 @@ private void TriggerSinglePlayerMenu() private void LoadLastSinglePlayerGame() { - // Wait for the CampaignEntryTiles to get created - if (_campaignMenuScript._campaignEntryTiles.Count == 0) + // Wait for all the saves to load and get displayed + // In 0.2.1 the first save of the first campaign is auto-selected when opening the menu + if (_campaignMenuScript._campaignLoadMenu.CurrentSelectedFilePath is null) return; - - CampaignTileEntry latestCampaign = null; - DateTime latestPlayed = DateTime.MinValue; - // Determine what campaign was played last. - foreach (var campaign in _campaignMenuScript._campaignEntryTiles) - { - var lastPlayed = DateTime.Parse(campaign.CampaignLastPlayedTime); + var save_components = _mainMenu.GetComponentsInChildren(); + Logger.LogDebug($"save_components.Length: {save_components.Length}"); - if (latestCampaign == null || lastPlayed > latestPlayed) - { - latestCampaign = campaign; - latestPlayed = lastPlayed; - } + var saveGamesList = _mainMenu.GetChild("SaveGamesList"); + if (saveGamesList.transform.childCount != save_components.Length) + { + // Haven't seen this happen, but just in case + Logger.LogError($"Visual ({saveGamesList.transform.childCount}) and logical {save_components.Length} save counts don't match"); + return; } - if (latestCampaign != null) + for (var i = 0; i