Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(savegame): load mission saves from older builds and retail

Olcay Seygan07b9c783a7eb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af1dfa1e7..8610000f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ found and fixed — EA's own, not port damage.**
## Every campaign mission is open
- Picking USA, GLA or China now opens a list of that campaign's missions, every one of them open. Pick a mission, then the difficulty, and it starts with its briefing and movie as it always did; win it and the campaign carries on to the next one. Every campaign mission starts at the same rank however you reach it, so starting at the fourth is the same game as playing through to it.
+- The "Mission Start" saves the campaign makes after each victory load again, from the original game and from every earlier version of Reforged. They hold only the campaign, the mission and the difficulty, none of which the 60-step battle changed. A game saved in the middle of a mission on an earlier version still does not load.
## Health bars you can read at a glance
@@ -47,7 +48,7 @@ found and fixed — EA's own, not port damage.**
- The match plays at the speed it always did. Every speed, delay, reload and build time in the game's data was converted to the shorter step, so a Crusader still fires every two seconds. The balance is the one you know.
- Mission timers keep EA's clock. A map's countdown still ticks 30 times a second, because the missions read a running timer's number and act on it: the second American mission declares victory when its "Win" timer drops below 1700, and on the first 60-step builds that came after 38 seconds instead of 10. The cutscene cues, the random music pick in the campaigns and the generals' challenges, the shell map's camera loop and the lightning on Eastern Everglades and Rocky Rampage were off the same way, 30 maps in all, and run on their original timing again. Custom maps get the same.
- Normal speed is now the fastest a skirmish or a mission runs. The game speed choice in the skirmish lobby offers x0.5, x0.75 and x1, and x1 is 60 steps a second; the x1.5 and x2 it used to have are gone. A lobby left on one of them, or a saved game made at one, comes back at x1, and the speed console command and a mission's own script stay between half speed and normal as well. Replays still play as fast as you ask, and network games are untouched.
-- Replays and saved games from earlier versions will not load in this one. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.
+- Replays and games saved in the middle of a match from earlier versions will not load in this one. The "Mission Start" saves a campaign makes between missions do, and every campaign mission can be picked from the campaign menu. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.
- Guns fire at their 2003 rate again. After a shot the game goes back to aiming for a step before it can fire again, which at 30 steps put a 100 millisecond Quad Cannon on a shot every 0.133 seconds; at 60 the same loop fired it every 0.100, a third faster. Shot delays and reloads are rounded to the old step and a gun's next shot is held to the old rhythm, so every weapon fires on the frames it did in 2003. A turret with no turning speed in its data rose twice as fast as it should, aircraft weighed their thrust against gravity at half strength, and a unit hit on the step before still counted as untouched for stealth. All three keep EA's timing now.
- Mod guns shoot straight again. Shockwave Chaos and other mods give their machine guns and autocannons a shell that arcs 300 high but flies so fast that the 30-step game only ever put it at the muzzle and on the target. At 60 steps the shell stopped partway up that arc, so in Chaos a Humvee's autocannon round went 200 into the air before coming down on a tank 100 away. A shell now passes through the points it passed through in 2003 and flies straight between them, so mod rounds hit straight and the original game's shells fly the same arcs. A shell fired point blank, close enough to arrive in one step, used to fly to the corner of the map and explode there, a bug since 2003; it hits its target now.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameState.h b/GeneralsMD/Code/GameEngine/Include/Common/GameState.h
index 9b7bf11c7..83a81321e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GameState.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GameState.h
@@ -118,7 +118,7 @@ public:
Int version; // GameState block version the file was written with, read with the header
/// FALSE for a save written by the original game or by a build from before logic ran at 60
- /// ticks a second: none of them loads in this one.
+ /// ticks a second, unless it is a mission save: that one holds no frame counts and loads.
Bool isLoadable( void ) const;
};
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index ab9332187..2ee7d7aa5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -616,7 +616,11 @@ static void startPendingSaveGame( void )
return;
}
- TheGameLogic->prepareNewGame( GAME_SINGLE_PLAYER, DIFFICULTY_NORMAL, 0 );
+ // A mission save starts its map afresh with a new game message of its own. Prepared here as
+ // well, loadGame clears that prepared game first, and clearing a game in a run started from the
+ // command line quits it.
+ if (gameInfo.saveGameInfo.saveFileType != SAVE_FILE_TYPE_MISSION)
+ TheGameLogic->prepareNewGame( GAME_SINGLE_PLAYER, DIFFICULTY_NORMAL, 0 );
if (TheGameState->loadGame( gameInfo ) != SC_OK)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp
index dafd5a834..104d81d29 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp
@@ -81,7 +81,8 @@ static const Char *ZERO_NAME_ONLY = "00000000";
static const Int MAX_SAVE_FILE_NUMBER = 99999999;
// The GameState block's version. 4 adds nothing to the block: it marks the build where logic went
-// to 60 ticks a second, and a file written before that cannot load in this one. The original
+// to 60 ticks a second, and a file written before that cannot load in this one (a mission save
+// aside: SaveGameInfo::isLoadable). The original
// game's files are 2, as were this fork's until 3 added the game speed.
static const XferVersion GAME_STATE_VERSION = 4;
@@ -122,7 +123,13 @@ Bool SaveGameInfo::isLoadable( void ) const
{
// a newer one never gets this far: xferVersion refuses it while the header is read
- return version >= GAME_STATE_VERSION;
+ if( version >= GAME_STATE_VERSION )
+ return TRUE;
+
+ // A mission save holds only this block and the campaign's, neither of which counts frames, so
+ // the one an older build or the original game wrote at a mission's start still loads. Version
+ // 2 is the first that records the file type.
+ return version >= 2 && saveFileType == SAVE_FILE_TYPE_MISSION;
} // end isLoadable
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index bed6f5c99..d838e3632 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -17805,6 +17805,25 @@ TEST(modfactions_prefix_the_last_part_of_a_file_path)
TheWritableGlobalData = saved;
}
+#include "Common/GameState.h"
+
+// A save from before 60 Hz logic is refused, except a mission save (the GameState and campaign
+// blocks only, no frame counts), which carries a campaign over from any earlier build or retail.
+TEST(save_older_than_60hz_loads_only_as_mission_save)
+{
+ SaveGameInfo info;
+ info.version = 4;
+ CHECK( info.isLoadable() );
+ info.version = 3;
+ CHECK( !info.isLoadable() );
+ info.saveFileType = SAVE_FILE_TYPE_MISSION;
+ CHECK( info.isLoadable() );
+ info.version = 2;
+ CHECK( info.isLoadable() );
+ info.version = 1; // no file type recorded, so no way to tell it is a mission save
+ CHECK( !info.isLoadable() );
+}
+
#include "test_minimap_input.inc"
#include "test_selection_priority.inc"
#include "test_widechar_width.inc"