fix campaign reset wiping player stats#7430
Draft
Goober5000 wants to merge 1 commit intoscp-fs2open:masterfrom
Draft
fix campaign reset wiping player stats#7430Goober5000 wants to merge 1 commit intoscp-fs2open:masterfrom
Goober5000 wants to merge 1 commit intoscp-fs2open:masterfrom
Conversation
campaign_reset() deletes the CSG file before reloading, so mission_campaign_load() finds no savefile and calls csg_reset_data(), which unconditionally zeros p->stats. Save and restore Player->stats around the reset so accumulated score, rank, kills, and medals are preserved regardless of whether the reload succeeds. Also re-save the CSG file after restoring stats: mission_campaign_load() already wrote a fresh CSG with zeros when it found no existing savefile, so without re-saving the next game load would read zeros from disk. Also now protects against resetting a campaign that is not the active one. Follow-up to scp-fs2open#1450, scp-fs2open#1451, scp-fs2open#6238, and scp-fs2open#6419. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
campaign_reset() deletes the CSG file before reloading, so mission_campaign_load() finds no savefile and calls csg_reset_data(), which unconditionally zeros p->stats. Save and restore Player->stats around the reset so accumulated score, rank, kills, and medals are preserved regardless of whether the reload succeeds.
Also re-save the CSG file after restoring stats: mission_campaign_load() already wrote a fresh CSG with zeros when it found no existing savefile, so without re-saving the next game load would read zeros from disk.
Also now protects against resetting a campaign that is not the active one.
Follow-up to #1450, #1451, #6238, and #6419.