Skip to content

Commit

Permalink
Merge pull request #5517 from Goober5000/fix_fred_bugs
Browse files Browse the repository at this point in the history
fix mission corruption in FRED
  • Loading branch information
Goober5000 authored Jul 29, 2023
2 parents 1252d79 + 689ac56 commit d82b02a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
13 changes: 11 additions & 2 deletions fred2/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,9 @@ int CFred_mission_save::save_campaign_file(const char *pathname)

Campaign_tree_formp->save_tree(); // flush all changes so they get saved.
Campaign_tree_viewp->sort_elements();

reset_parse();
raw_ptr = Parse_text_raw;
fred_parse_flag = 0;

pathname = cf_add_ext(pathname, FS_CAMPAIGN_FILE_EXT);
Expand Down Expand Up @@ -2599,8 +2601,13 @@ int CFred_mission_save::save_mission_info()

required_string_fred("$Version:");
parse_comments(2);
// Since previous versions of FreeSpace interpret this as a float, this can only have one decimal point
fout(" %d.%d", The_mission.required_fso_version.major, The_mission.required_fso_version.minor);
if (Mission_save_format == FSO_FORMAT_RETAIL) {
// All retail missions, both FS1 and FS2, have the same version
fout(" %d.%d", LEGACY_MISSION_VERSION.major, LEGACY_MISSION_VERSION.minor);
} else {
// Since previous versions of FreeSpace interpret this as a float, this can only have one decimal point
fout(" %d.%d", The_mission.required_fso_version.major, The_mission.required_fso_version.minor);
}

// XSTR
required_string_fred("$Name:");
Expand Down Expand Up @@ -3083,7 +3090,9 @@ void CFred_mission_save::save_mission_internal(const char *pathname)
The_mission.required_fso_version = MISSION_VERSION;

reset_parse();
raw_ptr = Parse_text_raw;
fred_parse_flag = 0;

fp = cfopen(pathname, "wt", CFILE_NORMAL, CF_TYPE_MISSIONS);
if (!fp) {
nprintf(("Error", "Can't open mission file to save.\n"));
Expand Down
2 changes: 1 addition & 1 deletion fred2/missionsave.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CFred_mission_save
/**
* @brief Default constructor
*/
CFred_mission_save() : err(0), raw_ptr(Parse_text_raw) {}
CFred_mission_save() : err(0), raw_ptr(nullptr), fp(nullptr) {}

/**
* @brief Move past the comment without copying it to the output file. Used for special FSO comment tags
Expand Down
12 changes: 10 additions & 2 deletions qtfred/src/mission/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,7 @@ int CFred_mission_save::save_messages()
int CFred_mission_save::save_campaign_file(const char *pathname)
{
reset_parse();
raw_ptr = Parse_text_raw;
fred_parse_flag = 0;

pathname = cf_add_ext(pathname, FS_CAMPAIGN_FILE_EXT);
Expand Down Expand Up @@ -2494,8 +2495,13 @@ int CFred_mission_save::save_mission_info()

required_string_fred("$Version:");
parse_comments(2);
// Since previous versions of FreeSpace interpret this as a float, this can only have one decimal point
fout(" %d.%d", The_mission.required_fso_version.major, The_mission.required_fso_version.minor);
if (save_format == MissionFormat::RETAIL) {
// All retail missions, both FS1 and FS2, have the same version
fout(" %d.%d", LEGACY_MISSION_VERSION.major, LEGACY_MISSION_VERSION.minor);
} else {
// Since previous versions of FreeSpace interpret this as a float, this can only have one decimal point
fout(" %d.%d", The_mission.required_fso_version.major, The_mission.required_fso_version.minor);
}

// XSTR
required_string_fred("$Name:");
Expand Down Expand Up @@ -2993,7 +2999,9 @@ void CFred_mission_save::save_mission_internal(const char* pathname)
The_mission.required_fso_version = MISSION_VERSION;

reset_parse();
raw_ptr = Parse_text_raw;
fred_parse_flag = 0;

fp = cfopen(pathname, "wt", CFILE_NORMAL, CF_TYPE_MISSIONS);
if (!fp) {
nprintf(("Error", "Can't open mission file to save.\n"));
Expand Down
2 changes: 1 addition & 1 deletion qtfred/src/mission/missionsave.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CFred_mission_save {
* @brief Default constructor
*/
explicit CFred_mission_save(EditorViewport* viewport = nullptr, MissionFormat format = MissionFormat::STANDARD) :
raw_ptr(Parse_text_raw), save_format(format), _editor(viewport ? viewport->editor : nullptr), _viewport(viewport) {
save_format(format), _editor(viewport ? viewport->editor : nullptr), _viewport(viewport) {
}

/**
Expand Down

0 comments on commit d82b02a

Please sign in to comment.