Skip to content

Commit 318e754

Browse files
authored
Merge pull request #6 from Falki-git/dev
v1.3.0 Adds a config to ignore autosaves when auto loading a save - by @SunSerega
2 parents 68510f2 + 0d6e658 commit 318e754

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

plugin_template/swinfo.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"name": "Skip Splash Screen",
66
"description": "Skips the splash screen and health warning. To be used only for developing mods (faster iteration).",
77
"source": "https://github.com/Falki-git/SkipSplashScreen",
8-
"version": "1.2.0",
8+
"version": "1.3.0",
99
"version_check": "https://raw.githubusercontent.com/Falki-git/SkipSplashScreen/master/plugin_template/swinfo.json",
1010
"ksp2_version": {
11-
"min": "0.1.5",
11+
"min": "0.2.1",
1212
"max": "*"
1313
},
1414
"dependencies": [

src/SkipSplashScreen/SkipSplashScreenPlugin.cs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections;
2-
using BepInEx;
1+
using BepInEx;
32
using BepInEx.Configuration;
43
using HarmonyLib;
54
using JetBrains.Annotations;
@@ -22,22 +21,31 @@ public class SkipSplashScreenPlugin : BaseSpaceWarpPlugin
2221

2322
private new static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("SkipSplashScreen");
2423

24+
private GameObject _mainMenu;
2525
private CampaignMenu _campaignMenuScript;
2626
private bool _singlePlayerMenuTriggered;
2727
private bool _loadInitiated;
2828
private bool _hasFinished;
2929

3030
private ConfigEntry<bool> _loadLastSavedCampaign;
31+
private ConfigEntry<bool> _loadIgnoreAutoSaves;
3132

3233
public void Start()
3334
{
3435
Harmony.CreateAndPatchAll(typeof(SkipSplashScreenPlugin));
35-
36+
3637
_loadLastSavedCampaign = Config.Bind(
3738
MyPluginInfo.PLUGIN_NAME,
3839
"Auto load last played campaign",
3940
false,
4041
"Automatically loads the last save game file after main menu is finished loading.");
42+
43+
_loadIgnoreAutoSaves = Config.Bind(
44+
MyPluginInfo.PLUGIN_NAME,
45+
"Ignore auto-saves when loading last save game",
46+
false,
47+
"If enabled, auto-saves are ignored when automatically loading last save game.");
48+
4149
}
4250

4351
public void Update()
@@ -87,9 +95,9 @@ private void TriggerSinglePlayerMenu()
8795
{
8896
Logger.LogInfo("'Auto load last played campaign' is enabled. To turn it off go into Settings -> Mods -> Skip Splash Screen");
8997

90-
var mainMenu = GameObject.Find(
98+
_mainMenu = GameObject.Find(
9199
"GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/MainMenu(Clone)/");
92-
var campaignMenu = mainMenu.GetChild("CampaignMenu");
100+
var campaignMenu = _mainMenu.GetChild("CampaignMenu");
93101
_campaignMenuScript = campaignMenu.GetComponent<CampaignMenu>();
94102

95103
var campaignSavesList = _campaignMenuScript.Game.SaveLoadManager.GetCampaignSaveFiles(CampaignType.SinglePlayer);
@@ -100,43 +108,39 @@ private void TriggerSinglePlayerMenu()
100108

101109
private void LoadLastSinglePlayerGame()
102110
{
103-
// Wait for the CampaignEntryTiles to get created
104-
if (_campaignMenuScript._campaignEntryTiles.Count == 0)
111+
// Wait for all the saves to load and get displayed
112+
// In 0.2.1 the first save of the first campaign is auto-selected when opening the menu
113+
if (_campaignMenuScript._campaignLoadMenu.CurrentSelectedFilePath is null)
105114
return;
106-
107-
CampaignTileEntry latestCampaign = null;
108-
DateTime latestPlayed = DateTime.MinValue;
109115

110-
// Determine what campaign was played last.
111-
foreach (var campaign in _campaignMenuScript._campaignEntryTiles)
112-
{
113-
var lastPlayed = DateTime.Parse(campaign.CampaignLastPlayedTime);
116+
var save_components = _mainMenu.GetComponentsInChildren<SaveLoadDialogFileEntry>();
117+
Logger.LogDebug($"save_components.Length: {save_components.Length}");
114118

115-
if (latestCampaign == null || lastPlayed > latestPlayed)
116-
{
117-
latestCampaign = campaign;
118-
latestPlayed = lastPlayed;
119-
}
119+
var saveGamesList = _mainMenu.GetChild("SaveGamesList");
120+
if (saveGamesList.transform.childCount != save_components.Length)
121+
{
122+
// Haven't seen this happen, but just in case
123+
Logger.LogError($"Visual ({saveGamesList.transform.childCount}) and logical {save_components.Length} save counts don't match");
124+
return;
120125
}
121126

122-
if (latestCampaign != null)
127+
for (var i = 0; i<saveGamesList.transform.childCount; ++i)
123128
{
124-
// What campaign tile entry is clicked, last saved game is automatically selected
125-
latestCampaign.OnCampaignClick();
126-
Logger.LogInfo($"Auto loading campaign '{latestCampaign.CampaignName}'.");
129+
string curr_save_name = save_components[i]._labelSaveName.text;
130+
if (_loadIgnoreAutoSaves.Value && curr_save_name.StartsWith("autosave")) continue;
131+
Logger.LogInfo($"Auto loading save '{curr_save_name}'.");
132+
133+
// It's called "lastPlayed" but it's actually just "lastSelected"
134+
// (this is remembered after closing the menu, but not after restarting the game)
135+
save_components[i].SetCurrentToggleState(lastPlayed: true);
127136

128-
StartCoroutine(Load());
129-
_loadInitiated = true;
137+
break;
130138
}
131-
}
132139

133-
private IEnumerator Load()
134-
{
135-
// Wait for the next frame cause save file won't be still selected here
136-
yield return null;
137140
_campaignMenuScript._campaignLoadMenu.LoadSelectedFile();
138-
139141
DestroyPlugin();
142+
143+
_loadInitiated = true;
140144
}
141145

142146
private void DestroyPlugin()

0 commit comments

Comments
 (0)