Repository navigation
remove the MAX_CAMPAIGN_MISSIONS limit - #7823
Goober5000 wants to merge 2 commits into
Conversation
06261ac to
13263ed
Compare
1faae27 to
af0db17
Compare
Campaigns were limited to 100 missions by a fixed-size array in the campaign struct, and the campaign parser did not check that limit, so a campaign file with more missions overflowed the array into the vectors that follow it. Campaign.missions is now an SCP_vector sized by the parser, and the separate num_missions count is replaced by the vector's size. cmission members now have default initializers so that resized entries start out valid. The other arrays sized by MAX_CAMPAIGN_MISSIONS are vectors as well: the mission name lists in the mission load menu and the ready room. In FRED2, the campaign tree's Sorted, Elements, Level_counts, and Links arrays are vectors too, which removes the MAX_LEVELS and MAX_CAMPAIGN_TREE_LINKS limits and the separate Total_links count. Removing a mission from the tree now pops the vacated last slot. The multiplayer client sizes its mission list from the count the server sends. Multiplayer campaigns are still limited to 255 missions, since the protocol sends the count as a ubyte. When reading a campaign save file, data for a stored mission index that is out of range is now discarded, where it was previously written into the array without a check. The Lua campaign mission accessors, the loop brief stage handle, the debriefing persona lookup, and the main hall lookups also check the index against the mission list, and the main hall falls back to its defaults when the campaign has no missions. Since a save file's mission data is stored by index, it only applies to the campaign it was saved from. The barracks and pilot selection screens can load a pilot's save file while a different campaign is loaded, so mission data from a save file for another campaign is now discarded, and saving is skipped until a matching save file is loaded or the save data is cleared, so that the mixed data is not written to the campaign's save file. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
af0db17 to
1cf909f
Compare
dustinspace217
left a comment
There was a problem hiding this comment.
Read through this one; the conversion looks complete and I didn't find any cmission pointer that a resize could invalidate. A few spots where the old 100 spare slots used to hide an out-of-range index:
csg_read_infodoesn't range-checkprev_missionorloop_reentry, so a mod update that shortens a campaign under an existing save makes Continue read past the end at readyroom.cpp:841. The new!Csg_campaign_mismatchat csg.cpp:151 also lets another campaign'snext_missionthrough, which a script callingloadCampaignSavefilemid-mission can reach via exit-loop or jump-to-mission. Clamping all three always, and only skippingm_data_invalidon a mismatch, would cover both. (Our #7906 adds the prev/loop clamps against the old array; I'll rebase it onto this.)- FRED2
remove_mission: if the last mission is selected and an earlier one is removed,Cur_campaign_missionstill points at the popped slot (campaigntreeview.cpp:1292), and the main hall and persona edits write there. Remapping it from the last slot tomshould fix it. I couldn't run FRED2 here, so this is from reading. Campaign_mission_flags[MAX_MISSIONS](readyroom.cpp:206) overflows above 1024 missions and nothing reads it, so it could just go.- Discarded records still count in
num_missions_completed, so the next save declares more records than it writes. The section read cap catches it, so it's only a warning on each load, but subtracting the discards would keep the count right. - When saving is skipped for a mismatch (csg.cpp:1904), release builds show nothing, and settings and control changes are dropped too. Would a
ReleaseWarningand a note in theloadCampaignSavefiledoc make sense?
Smaller: getMainHallIndex returns -1 with no missions where the engine uses hall 0; sort_links and correct_position index missions[-1] for end-of-campaign links (older, but now outside the vector); the sim room list stops at 200 lines; the promotion voice table is still a fixed [35]; and a few whitespace-only edits on untouched lines.
I haven't playtested this yet; this is from reading and a clean Debug build.
|
@dustinspace217 can you review this while keeping #7824 in mind? Some of them may be addressed there |
|
Went through each point again with #7824 (4281b92) open next to it. Its first commit is the same patch as this PR, and its other two commits only touch readyroom.cpp, missioncampaign.cpp/.h, missionload.cpp, multiui.cpp, managepilot.cpp and the scripting ui.cpp. So:
This is still from reading, not a playtest. |
| static int Standalone_mission_flags[MAX_MISSIONS]; | ||
| static char *Campaign_missions[MAX_MISSIONS] = { NULL }; | ||
| static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS] = { NULL }; | ||
| static SCP_vector<char*> Campaign_mission_names; |
There was a problem hiding this comment.
Decidedly not a fan of SCP_vector<char*> over SCP_vector<SCP_string>, especially since quite some code is destroying the allocated strings which degrades to an automatic destruction with a real string
| char * recent_missions[MAX_RECENT_MISSIONS]; | ||
| char * campaign_names[MAX_CAMPAIGNS+2]; | ||
| char * campaign_missions[MAX_CAMPAIGN_MISSIONS]; | ||
| SCP_vector<char*> campaign_missions; |
There was a problem hiding this comment.
Also #7825 Actually not #7825, but I can do it when that PR comes out of draft
EDIT: actually no:
missionload.cpp:163(campaign_missions): this one can't beSCP_string. The listbox'sset_new_list(int, char**)needs an array ofchar*. The names themselves are already stored inSCP_vector<SCP_string> Campaign_missions;campaign_missionsis only thechar*view of them that the listbox takes.
When reading a campaign save file, prev_mission and loop_reentry are now checked against the mission list as well as next_mission. An out-of-range prev_mission is reset to -1, and an out-of-range next_mission or loop_reentry is reset to 0, since for those -1 means the campaign ends there. The invalid-data warning is shown only when the save file is for the loaded campaign. Mission records discarded for an out-of-range index no longer count toward num_missions_completed, so the next save declares as many records as it writes. In FRED2, removing a mission now keeps the selection on the mission that is moved into the vacated slot, and deleting a link clears or shifts the selected link index so that it doesn't run past the end of the link list. End-of-campaign links, whose target is -1, are skipped when correcting mission levels and are sorted after the other links, instead of indexing the mission list with -1. The Lua documentation for getMainHallIndex now says that it returns a 0-based index, and loadCampaignSavefile documents that loading a save file for another campaign blocks saving. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@dustinspace217 addressed |
dustinspace217
left a comment
There was a problem hiding this comment.
Re-checked at bf530ad. All three save indexes are now clamped whatever the campaign, the warning only shows for the loaded campaign, and discarded records no longer count toward num_missions_completed. In FRED2 the selection follows the mission moved into the removed slot, the link selection is kept in range after a delete, and end-of-campaign links are skipped in sort_links and correct_position. Fine by me to leave Campaign_mission_flags to #7825.
From reading only; FRED2 doesn't build here, so the MSVC jobs are the compile check for that part.
Campaigns were limited to 100 missions by a fixed-size array in the campaign struct, and the campaign parser did not check that limit, so a campaign file with more missions overflowed the array into the vectors that follow it. Campaign.missions is now an SCP_vector sized by the parser, and the separate num_missions count is replaced by the vector's size. cmission members now have default initializers so that resized entries start out valid.
The other arrays sized by MAX_CAMPAIGN_MISSIONS are vectors as well: the mission name lists in the mission load menu and the ready room, and the retail promotion voice table. In FRED2, the campaign tree's Sorted, Elements, Level_counts, and Links arrays are vectors too, which removes the MAX_LEVELS and MAX_CAMPAIGN_TREE_LINKS limits and the separate Total_links count. Removing a mission from the tree now pops the vacated last slot.
The multiplayer client sizes its mission list from the count the server sends. Multiplayer campaigns are still limited to 255 missions, since the protocol sends the count as a ubyte.
When reading a campaign save file, data for a stored mission index that is out of range is now discarded, where it was previously written into the array without a check. The Lua campaign mission accessors, the loop brief stage handle, the debriefing persona lookup, and the main hall lookups also check the index against the mission list, and the main hall falls back to its defaults when the campaign has no missions.
Since a save file's mission data is stored by index, it only applies to the campaign it was saved from. The barracks and pilot selection screens can load a pilot's save file while a different campaign is loaded, so mission data from a save file for another campaign is now discarded, and saving is skipped until a matching save file is loaded or the save data is cleared, so that the mixed data is not written to the campaign's save file.