@@ -22,22 +22,31 @@ public class SkipSplashScreenPlugin : BaseSpaceWarpPlugin
2222
2323 private new static readonly ManualLogSource Logger = BepInEx . Logging . Logger . CreateLogSource ( "SkipSplashScreen" ) ;
2424
25+ private GameObject _mainMenu ;
2526 private CampaignMenu _campaignMenuScript ;
2627 private bool _singlePlayerMenuTriggered ;
2728 private bool _loadInitiated ;
2829 private bool _hasFinished ;
2930
3031 private ConfigEntry < bool > _loadLastSavedCampaign ;
32+ private ConfigEntry < bool > _loadIgnoreAutoSaves ;
3133
3234 public void Start ( )
3335 {
3436 Harmony . CreateAndPatchAll ( typeof ( SkipSplashScreenPlugin ) ) ;
35-
37+
3638 _loadLastSavedCampaign = Config . Bind (
3739 MyPluginInfo . PLUGIN_NAME ,
3840 "Auto load last played campaign" ,
3941 false ,
4042 "Automatically loads the last save game file after main menu is finished loading." ) ;
43+
44+ _loadIgnoreAutoSaves = Config . Bind (
45+ MyPluginInfo . PLUGIN_NAME ,
46+ "Ignore auto-saves when loading last save game" ,
47+ false ,
48+ "If enabled, auto-saves are ignored when automatically loading last save game" ) ;
49+
4150 }
4251
4352 public void Update ( )
@@ -87,9 +96,9 @@ private void TriggerSinglePlayerMenu()
8796 {
8897 Logger . LogInfo ( "'Auto load last played campaign' is enabled. To turn it off go into Settings -> Mods -> Skip Splash Screen" ) ;
8998
90- var mainMenu = GameObject . Find (
99+ _mainMenu = GameObject . Find (
91100 "GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/MainMenu(Clone)/" ) ;
92- var campaignMenu = mainMenu . GetChild ( "CampaignMenu" ) ;
101+ var campaignMenu = _mainMenu . GetChild ( "CampaignMenu" ) ;
93102 _campaignMenuScript = campaignMenu . GetComponent < CampaignMenu > ( ) ;
94103
95104 var campaignSavesList = _campaignMenuScript . Game . SaveLoadManager . GetCampaignSaveFiles ( CampaignType . SinglePlayer ) ;
@@ -100,43 +109,39 @@ private void TriggerSinglePlayerMenu()
100109
101110 private void LoadLastSinglePlayerGame ( )
102111 {
103- // Wait for the CampaignEntryTiles to get created
104- if ( _campaignMenuScript . _campaignEntryTiles . Count == 0 )
112+ // Wait for all the saves to load and get displayed
113+ // In 0.2.1 the first save of the first campaign is auto-selected when opening the menu
114+ if ( _campaignMenuScript . _campaignLoadMenu . CurrentSelectedFilePath is null )
105115 return ;
106-
107- CampaignTileEntry latestCampaign = null ;
108- DateTime latestPlayed = DateTime . MinValue ;
109116
110- // Determine what campaign was played last.
111- foreach ( var campaign in _campaignMenuScript . _campaignEntryTiles )
112- {
113- var lastPlayed = DateTime . Parse ( campaign . CampaignLastPlayedTime ) ;
117+ var save_components = _mainMenu . GetComponentsInChildren < SaveLoadDialogFileEntry > ( ) ;
118+ Logger . LogDebug ( $ "save_components.Length: { save_components . Length } ") ;
114119
115- if ( latestCampaign == null || lastPlayed > latestPlayed )
116- {
117- latestCampaign = campaign ;
118- latestPlayed = lastPlayed ;
119- }
120+ var sgl = _mainMenu . GetChild ( "SaveGamesList" ) ;
121+ if ( sgl . transform . childCount != save_components . Length )
122+ {
123+ // Haven't seen this happen, but just in case
124+ Logger . LogError ( $ "Visual ({ sgl . transform . childCount } ) and logical { save_components . Length } save counts don't match") ;
125+ return ;
120126 }
121127
122- if ( latestCampaign != null )
128+ for ( var i = 0 ; i < sgl . transform . childCount ; ++ i )
123129 {
124- // What campaign tile entry is clicked, last saved game is automatically selected
125- latestCampaign . OnCampaignClick ( ) ;
126- Logger . LogInfo ( $ "Auto loading campaign '{ latestCampaign . CampaignName } '.") ;
130+ string curr_save_name = save_components [ i ] . _labelSaveName . text ;
131+ if ( _loadIgnoreAutoSaves . Value && curr_save_name . StartsWith ( "autosave" ) ) continue ;
132+ Logger . LogInfo ( $ "Auto loading save '{ curr_save_name } '.") ;
133+
134+ // It's called "lastPlayed" but it's actually just "lastSelected"
135+ // (this is remembered after closing the menu, but not after restarting the game)
136+ save_components [ i ] . SetCurrentToggleState ( lastPlayed : true ) ;
127137
128- StartCoroutine ( Load ( ) ) ;
129- _loadInitiated = true ;
138+ break ;
130139 }
131- }
132140
133- private IEnumerator Load ( )
134- {
135- // Wait for the next frame cause save file won't be still selected here
136- yield return null ;
137141 _campaignMenuScript . _campaignLoadMenu . LoadSelectedFile ( ) ;
138-
139142 DestroyPlugin ( ) ;
143+
144+ _loadInitiated = true ;
140145 }
141146
142147 private void DestroyPlugin ( )
0 commit comments