View Issue Details

IDProjectCategoryView StatusLast Update
0002809FSSCPPilot datapublic2013-03-24 09:32
ReporterFUBAR-BDHR Assigned Toniffiwan  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.6.19 
Summary0002809: Quick start debug key G broken in new pilot code
DescriptionPrior to the new pilot code in debug you could press G at the main menu and it would launch the last mission played.

Now with a converted pilot it launches the currently selected campaign mission. With a new pilot I received the following whether or not any missions have been played:

Assert: si_index >= 0
File: missionshipchoice.cpp
Line: 2483

ntdll.dll! ZwWaitForSingleObject + 21 bytes
kernel32.dll! WaitForSingleObjectEx + 67 bytes
kernel32.dll! WaitForSingleObject + 18 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! SCP_DumpStack + 354 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! WinAssert + 194 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! update_player_ship + 60 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! create_default_player_ship + 183 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! mission_load + 243 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! game_start_mission + 184 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! game_enter_state + 1019 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! gameseq_set_state + 310 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! game_process_event + 459 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! gameseq_process_events + 152 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! game_main + 782 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! WinMain + 330 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! __tmainCRTStartup + 322 bytes
fs2_open_3_6_19_SSE2-DEBUG.exe! WinMainCRTStartup + 15 bytes
kernel32.dll! BaseThreadInitThunk + 18 bytes
ntdll.dll! RtlInitializeExceptionChain + 99 bytes
ntdll.dll! RtlInitializeExceptionChain + 54 bytes
Steps To ReproduceRun debug. Play a mission from the tech room. Exit the mission and press G. It should reload the same mission and bypass the loadout screen. Depending on if it is a converted pilot or new pilot you should get the problem or the error.
TagsNo tags attached.

Activities

niffiwan

2013-03-16 03:46

developer   ~0014768

FYI - the code that lets the "quick start" work was removed in the initial pilot code commit. It used to store a list of "Recent_missions" in the .pl2 file. It would be fairly easy to add back in, the only issue is that I think it'll break pilot file compatibility. I'll investigate further...

niffiwan

2013-03-16 23:34

developer   ~0014770

Last edited: 2013-03-16 23:34

So - two issues...
1) Recent_missions aren't being stored (solution = just re-add the relevant code)
2) Last ship flown by the player is getting wiped

I've got an ugly hack that gets around the 2nd issue, but I need to figure out if there's another way to save that info after a mission is ...ended? Or completed?

MjnMixael

2013-03-17 01:51

manager   ~0014771

Last edited: 2013-03-17 01:51

2) is related to 2753.

niffiwan

2013-03-17 03:23

developer   ~0014773

Please try the attached patch. It's a little hacky in places, but the whole quick-start mission code is a little hacky :|

There are some issues with the patch:
1) it'll popup-error & assert if you 'quick start' without having played any missions in the currently active mod/campaign
2) it'll error (& exit) if you switch mods, then 'quick start' and the last run mission isn't available in the new mod

Both errors are easy to workaround - start new mission normally.

To be honest, given that this is a modder's tool (i.e. only available in debug) then I think these two issues are acceptable.

niffiwan

2013-03-17 21:08

developer   ~0014775

Last edited: 2013-03-17 21:10

as mentioned by FUBAR on IRC, there's a cmdline flag which does something similar. Check that this still works as well

-start_mission <.fs2 file>

FUBAR-BDHR

2013-03-21 03:19

developer   ~0014790

Looks like this one is good too. Non campaign missions even work after switching campaigns.

Also it appears -start_mission was not affected by this issue as it does bring up the loadout screen where G in debug does not.

niffiwan

2013-03-21 10:25

developer  

mantis2809-2-svn.patch (5,251 bytes)   
Index: code/pilotfile/csg.cpp
===================================================================
--- code/pilotfile/csg.cpp	(revision 9592)
+++ code/pilotfile/csg.cpp	(working copy)
@@ -11,6 +11,7 @@
 #include "missionui/missionscreencommon.h"
 #include "mission/missioncampaign.h"
 #include "missionui/missionshipchoice.h"
+#include "mission/missionload.h"
 #include "sound/audiostr.h"
 #include "io/joy.h"
 #include "io/mouse.h"
@@ -31,7 +32,8 @@
 //       that sort!
 //
 //   0 - initial version
-static const ubyte CSG_VERSION = 0;
+//   1 - re-add recent missions
+static const ubyte CSG_VERSION = 1;
 
 
 void pilotfile::csg_read_flags()
@@ -1173,6 +1175,46 @@
 	endSection();
 }
 
+/*
+ * Only used for quick start missions
+ */
+void pilotfile::csg_read_lastmissions()
+{
+	int i;
+
+	// restore list of most recently played missions
+	Num_recent_missions = cfread_int( cfp );
+	Assert(Num_recent_missions <= MAX_RECENT_MISSIONS);
+	for ( i = 0; i < Num_recent_missions; i++ ) {
+		char *cp;
+
+		cfread_string_len( Recent_missions[i], MAX_FILENAME_LEN, cfp);
+		// Remove the extension (safety check: shouldn't exist anyway)
+		cp = strchr(Recent_missions[i], '.');
+			if (cp)
+				*cp = 0;
+	}
+}
+
+/*
+ * Only used for quick start missions
+ */
+
+void pilotfile::csg_write_lastmissions()
+{
+	int i;
+
+	startSection(Section::LastMissions);
+
+	// store list of most recently played missions
+	cfwrite_int(Num_recent_missions, cfp);
+	for (i=0; i<Num_recent_missions; i++) {
+		cfwrite_string_len(Recent_missions[i], cfp);
+	}
+
+	endSection();
+}
+
 void pilotfile::csg_reset_data()
 {
 	int idx;
@@ -1376,6 +1418,11 @@
 					csg_read_cutscenes();
 					break;
 
+				case Section::LastMissions:
+					mprintf(("CSG => Parsing:  Last Missions...\n"));
+					csg_read_lastmissions();
+					break;
+
 				default:
 					mprintf(("CSG => Skipping unknown section 0x%04x!\n", section_id));
 					break;
@@ -1487,6 +1534,8 @@
 	csg_write_controls();
 	mprintf(("CSG => Saving:  Cutscenes...\n"));
 	csg_write_cutscenes();
+	mprintf(("CSG => Saving:  Last Missions...\n"));
+	csg_write_lastmissions();
 
 	// Done!
 	mprintf(("CSG => Saving complete!\n"));
Index: code/pilotfile/pilotfile.h
===================================================================
--- code/pilotfile/pilotfile.h	(revision 9592)
+++ code/pilotfile/pilotfile.h	(working copy)
@@ -120,7 +120,8 @@
 				RedAlert		= 0x0011,
 				Variables		= 0x0012,
 				Missions		= 0x0013,
-				Cutscenes		= 0x0014
+				Cutscenes		= 0x0014,
+				LastMissions	= 0x0015
 			};
 		};
 
@@ -175,6 +176,7 @@
 		void csg_read_settings();
 		void csg_read_controls();
 		void csg_read_cutscenes();
+		void csg_read_lastmissions();
 
 		void csg_write_flags();
 		void csg_write_info();
@@ -188,6 +190,7 @@
 		void csg_write_settings();
 		void csg_write_controls();
 		void csg_write_cutscenes();
+		void csg_write_lastmissions();
 };
 
 extern pilotfile Pilot;
Index: code/missionui/missionshipchoice.cpp
===================================================================
--- code/missionui/missionshipchoice.cpp	(revision 9592)
+++ code/missionui/missionshipchoice.cpp	(working copy)
@@ -23,6 +23,7 @@
 #include "globalincs/linklist.h"
 #include "io/mouse.h"
 #include "playerman/player.h"
+#include "pilotfile/pilotfile.h"
 #include "menuui/snazzyui.h"
 #include "anim/animplay.h"
 #include "anim/packunpack.h"
@@ -2492,17 +2493,18 @@
 		change_ship_type(Player_obj->instance, si_index);
 
 	Player->last_ship_flown_si_index = si_index;
+	Pilot.save_savefile();  // saves both Recent_mission & last_ship_flown_si_index (for quick-start-missions)
 }
 
-// ----------------------------------------------------------------------------
-// create a default player ship
-//
-//	parameters:		use_last_flown	=> select ship that was last flown on a mission
-//						(this is a default parameter which is set to 1)
-//
-// returns:			0 => success
-//               !0 => failure
-//
+/*
+ * create a default player ship
+ *
+ * @note: only used for quick start missions
+ *
+ * @param	use_last_flown	select ship that was last flown on a mission (default parameter set to 1)
+ *
+ * @return	0 => success, !0 => failure
+ */
 int create_default_player_ship(int use_last_flown)
 {
 	int	player_ship_class=-1, i;
@@ -2525,7 +2527,14 @@
 			return 1;
 	}
 
-	update_player_ship(player_ship_class);
+	// if we still haven't found the last flown ship, handle the error semi-gracefully
+	if (player_ship_class == -1) {
+		popup(PF_TITLE_BIG | PF_TITLE_RED | PF_USE_AFFIRMATIVE_ICON | PF_NO_NETWORKING, 1, POPUP_OK, XSTR("Error!\n\nCannot find "
+			"a valid last flown ship\n\nHave you played any missions since activating this mod/campaign?", -1));
+		return 1;
+	} else {
+		update_player_ship(player_ship_class);
+	}
 
 	// debug code to keep using descent style physics if the player starts a new game
 #ifndef NDEBUG
Index: code/mission/missionload.cpp
===================================================================
--- code/mission/missionload.cpp	(revision 9592)
+++ code/mission/missionload.cpp	(working copy)
@@ -113,6 +113,8 @@
 		Assert(!ret);
 	}
 
+	ml_update_recent_missions(filename_ext);  // update recently played missions list (save the csg later)
+
 	init_hud();
 	return 0;
 }
mantis2809-2-svn.patch (5,251 bytes)   

niffiwan

2013-03-21 10:28

developer   ~0014793

Thanks for testing the patch... however I wasn't 100% happy with it so I changed it slightly. Instead of saving/restoring the value of the last ship, I moved the save of the campaign file so that it includes the last ship as well as the recent missions. Nothing much else is different. So, would you mind giving it another quick test? (sorry, I should have removed the previous patch when I decided that I wasn't happy with it...)

FUBAR-BDHR

2013-03-22 02:04

developer   ~0014797

Looks like it still works.

MjnMixael

2013-03-23 00:08

manager   ~0014808

Works for me as well.

niffiwan

2013-03-24 09:32

developer   ~0014827

Fix committed to trunk@9597.

Related Changesets

fs2open: trunk r9597

2013-03-24 06:18

niffiwan


Ported: N/A

Details Diff
Fix for mantis 2809: re-enable quick-start-missions (g key in debug)
Save Recent_missions & last_flown_ship_si_index to CSG
Affected Issues
0002809
mod - /trunk/fs2_open/code/mission/missionload.cpp Diff File
mod - /trunk/fs2_open/code/missionui/missionshipchoice.cpp Diff File
mod - /trunk/fs2_open/code/pilotfile/csg.cpp Diff File
mod - /trunk/fs2_open/code/pilotfile/pilotfile.h Diff File

Issue History

Date Modified Username Field Change
2013-03-15 03:54 FUBAR-BDHR New Issue
2013-03-15 21:56 niffiwan Assigned To => niffiwan
2013-03-15 21:56 niffiwan Status new => assigned
2013-03-16 03:46 niffiwan Note Added: 0014768
2013-03-16 23:34 niffiwan Note Added: 0014770
2013-03-16 23:34 niffiwan Note Edited: 0014770
2013-03-17 01:51 MjnMixael Note Added: 0014771
2013-03-17 01:51 MjnMixael Note Edited: 0014771
2013-03-17 03:16 niffiwan File Added: mantis2809-svn.patch
2013-03-17 03:23 niffiwan Note Added: 0014773
2013-03-17 03:23 niffiwan Status assigned => feedback
2013-03-17 21:08 niffiwan Note Added: 0014775
2013-03-17 21:10 niffiwan Note Edited: 0014775
2013-03-21 03:19 FUBAR-BDHR Note Added: 0014790
2013-03-21 03:19 FUBAR-BDHR Status feedback => assigned
2013-03-21 10:25 niffiwan File Added: mantis2809-2-svn.patch
2013-03-21 10:28 niffiwan Note Added: 0014793
2013-03-21 10:28 niffiwan Status assigned => feedback
2013-03-22 02:04 FUBAR-BDHR Note Added: 0014797
2013-03-22 02:04 FUBAR-BDHR Status feedback => assigned
2013-03-22 02:12 niffiwan File Deleted: mantis2809-svn.patch
2013-03-22 02:12 niffiwan Status assigned => code review
2013-03-23 00:08 MjnMixael Note Added: 0014808
2013-03-24 09:32 niffiwan Changeset attached => fs2open trunk r9597
2013-03-24 09:32 niffiwan Note Added: 0014827
2013-03-24 09:32 niffiwan Status code review => resolved
2013-03-24 09:32 niffiwan Resolution open => fixed