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.

feat(gameengine): a mod's skirmish scripts replace ours whole

Olcay Seygan853d215340d1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ae15bf1d..ab343c8e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,7 +24,7 @@ found and fixed — EA's own, not port damage.**
- A mod is a folder now. Start the game with `-mod` and the folder, and the archives in it replace Zero Hour's files, as before, and so do the plain files under its `Data` and `Art` folders, which the game used to ignore. A modder can drop in one changed file without packing an archive first.
- Several mods run at once. Give `-mod` once for each, and where two of them change the same file, the one named later wins.
-- Reforged stays on top of every mod. This build's balance, its fixes to EA's data, its AI and its menus load after the mod and win where they touch the same unit, weapon or button, so a mod plays with Reforged's rules. A change that names something the mod renamed or removed is passed over instead of stopping the game, which is how ShockWave starts and plays. A mod's own copy of a file Reforged ships, its skirmish AI scripts or the skirmish setup screen among them, is ignored, and so are any upscaled art archives it carries.
+- Reforged stays on top of every mod. This build's balance, its fixes to EA's data, its AI and its menus load after the mod and win where they touch the same unit, weapon or button, so a mod plays with Reforged's rules. A change that names something the mod renamed or removed is passed over instead of stopping the game, which is how ShockWave starts and plays. A mod's own copy of a file Reforged ships, the skirmish setup screen among them, is ignored, and so are any upscaled art archives it carries. The one exception is the skirmish AI's scripts: a mod's are written for its own generals, so they replace Reforged's, and Reforged's smarter AI plays them.
- A `mod.json` in the folder names the mod and its version. The names stand beside the version number in the options menu, in the order the mods were given, and go into every replay you record, so a replay made with mods says which ones, and the replay list marks it as another version when the game is running without them.
- Joining a LAN game that runs different mods used to end in a box about a mismatch and nothing else. It names the host's mods now, or tells you the host plays without any.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
index 536902fba..07cd73b87 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
@@ -144,8 +144,8 @@ public:
/// which no mod replaces.
AsciiString modLooseFile(const AsciiString& filename, Bool *inModArchive = NULL) const;
- /// TRUE for a game path the fork ships loose (BalanceReforged.ini, Patch.str, SkirmishScripts.scb,
- /// its .wnd layouts ...); see the definition for how the set is decided.
+ /// TRUE for a game path the fork ships loose and no mod replaces (BalanceReforged.ini, Patch.str, its
+ /// .wnd layouts ...); see the definition for how the set is decided.
static Bool isForkOwnedPath(const AsciiString& filename);
Bool createDirectory(AsciiString directory); ///< create a directory of the given name.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 87aeccde2..38de0823d 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -559,6 +559,8 @@ public:
UnsignedInt m_iniCRC; ///< CRC of important INI files
UnsignedInt m_exeCRC; ///< CRC of the executable
+ void computeExeCRC( void ); ///< m_exeCRC from the build fingerprint, the version and the two scb as they resolve now
+ UnsignedInt m_baseExeCRC; ///< m_exeCRC before any -mod mounted: the build without its mods, for the LAN mod check
BodyDamageType m_movementPenaltyDamageState; ///< at this body damage state, we have movement penalties
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
index 868011e0f..c2ee670b5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h
@@ -396,7 +396,8 @@ struct LANMessage
UnsignedInt iniCRC;
char serial[g_maxSerialLength];
char modNamePad; ///< puts modName on an even offset, 70
- WideChar modName[g_lanModNameLength+1]; ///< the joiner's -mod name, empty for none; older builds leave junk here, but their exe CRC differs first
+ WideChar modName[g_lanModNameLength+1]; ///< the joiner's -mod list, empty for none
+ UnsignedInt baseExeCRC; ///< the joiner's exe CRC before its mods mounted; older builds leave junk in both
} GameToJoin;
// GameJoined is sent with JOIN_ACCEPT
@@ -473,6 +474,7 @@ static_assert(offsetof(LANMessage, GameToJoin.exeCRC) == 38, "LANMessage::GameTo
static_assert(offsetof(LANMessage, GameToJoin.iniCRC) == 42, "LANMessage::GameToJoin.iniCRC");
static_assert(offsetof(LANMessage, GameToJoin.serial) == 46, "LANMessage::GameToJoin.serial");
static_assert(offsetof(LANMessage, GameToJoin.modName) == 70, "LANMessage::GameToJoin.modName");
+static_assert(offsetof(LANMessage, GameToJoin.baseExeCRC) == 372, "LANMessage::GameToJoin.baseExeCRC");
static_assert(offsetof(LANMessage, GameNotJoined.modName) == 80, "LANMessage::GameNotJoined.modName");
static_assert(offsetof(LANMessage, GameJoined.slotPosition) == 76, "LANMessage::GameJoined.slotPosition");
static_assert(offsetof(LANMessage, GameNotJoined.reason) == 76, "LANMessage::GameNotJoined.reason");
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index af79fe6d9..c5a47bea0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -2898,6 +2898,8 @@ void parseCommandLine(int argc, char *argv[])
{
DEBUG_LOG(("MODS %d loaded, last wins: %s\n", (Int)TheGlobalData->m_mods.size(), TheGlobalData->m_modName.str()));
TheFileSystem->reset();
+ // the mod's skirmish and multiplayer scripts are the ones the match runs, so they are the ones the join compares
+ TheWritableGlobalData->computeExeCRC();
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 6d4fbbe74..1e02dbfc9 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1229,43 +1229,9 @@ GlobalData::GlobalData()
a binary modified after the build. Its four bytes go in as the platform stores them, which is the
same on every platform the game builds for (little-endian). The version and the two multiplayer
scripts follow, as before. */
- const Int blockSize = 65536;
- CRC exeCRC;
- const UnsignedInt buildFingerprint = ZH_BUILD_FINGERPRINT;
- exeCRC.computeCRC( &buildFingerprint, sizeof( buildFingerprint ) );
- File *fp = NULL;
- if (TheVersion)
- {
- UnsignedInt version = TheVersion->getVersionNumber();
- exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
- }
- // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
- fp = TheFileSystem->openFile("Data\\Scripts\\SkirmishScripts.scb", File::READ | File::BINARY);
- if (fp != NULL) {
- unsigned char crcBlock[blockSize];
- Int amtRead = 0;
- while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
- {
- exeCRC.computeCRC(crcBlock, amtRead);
- }
- fp->close();
- fp = NULL;
- }
- fp = TheFileSystem->openFile("Data\\Scripts\\MultiplayerScripts.scb", File::READ | File::BINARY);
- if (fp != NULL) {
- unsigned char crcBlock[blockSize];
- Int amtRead = 0;
- while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
- {
- exeCRC.computeCRC(crcBlock, amtRead);
- }
- fp->close();
- fp = NULL;
- }
+ computeExeCRC();
+ m_baseExeCRC = m_exeCRC;
- m_exeCRC = exeCRC.get();
- DEBUG_LOG(("EXE CRC: 0x%8.8X\n", m_exeCRC));
-
m_movementPenaltyDamageState = BODY_REALLYDAMAGED;
m_shouldUpdateTGAToDDS = FALSE;
@@ -1375,6 +1341,43 @@ GlobalData *GlobalData::newOverride( void )
} // end newOveride
+//-------------------------------------------------------------------------------------------------
+/** The build fingerprint, the version and the two multiplayer scripts as they resolve now: once at
+ * construction, and again after -mod mounts its archives (parseCommandLine), since a mod's
+ * SkirmishScripts.scb or MultiplayerScripts.scb is the one the match runs. Without -mod it runs once
+ * and the value is what it always was. */
+//-------------------------------------------------------------------------------------------------
+void GlobalData::computeExeCRC( void )
+{
+ const Int blockSize = 65536;
+ CRC exeCRC;
+ const UnsignedInt buildFingerprint = ZH_BUILD_FINGERPRINT;
+ exeCRC.computeCRC( &buildFingerprint, sizeof( buildFingerprint ) );
+ if (TheVersion)
+ {
+ UnsignedInt version = TheVersion->getVersionNumber();
+ exeCRC.computeCRC( &version, sizeof(UnsignedInt) );
+ }
+ // Add in MP scripts to the EXE CRC, since the game will go out of sync if they change
+ const char *scripts[] = { "Data\\Scripts\\SkirmishScripts.scb", "Data\\Scripts\\MultiplayerScripts.scb" };
+ for (Int s = 0; s < 2; ++s)
+ {
+ File *fp = TheFileSystem->openFile(scripts[s], File::READ | File::BINARY);
+ if (fp == NULL)
+ continue;
+ unsigned char crcBlock[blockSize];
+ Int amtRead = 0;
+ while ( (amtRead=fp->read(crcBlock, blockSize)) > 0 )
+ {
+ exeCRC.computeCRC(crcBlock, amtRead);
+ }
+ fp->close();
+ }
+
+ m_exeCRC = exeCRC.get();
+ DEBUG_LOG(("EXE CRC: 0x%8.8X\n", m_exeCRC));
+}
+
//-------------------------------------------------------------------------------------------------
void GlobalData::init( void )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 4ad2e5b05..c37b64fc4 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -856,11 +856,22 @@ void Player::setDefaultTeam(void) {
tname.set("team");
tname.concat(m_playerName);
Team *dt = TheTeamFactory->findTeam(tname);
- DEBUG_ASSERTCRASH(dt, ("no team"));
- if (dt) {
- m_defaultTeam = dt;
- dt->setActive();
- }
+ if (dt == NULL) {
+ /* A skirmish slot takes the name of the skirmish side its general's scripts are written for
+ (initFromDict), drops its own teamplayer<n>, and gets its teams from those scripts instead. A
+ general the skirmish scripts have no player for - a mod's, under the fork's SkirmishScripts.scb -
+ is left with no team at all, and the AI read the NULL on its first pass. Every player is given
+ its default team here, so the singleton validateSides would have added is made now. */
+ DEBUG_LOG(("Player::setDefaultTeam - %s had no %s, making it\n", m_playerName.str(), tname.str()));
+ Dict d;
+ d.setAsciiString(TheKey_teamName, tname);
+ d.setAsciiString(TheKey_teamOwner, m_playerName);
+ d.setBool(TheKey_teamIsSingleton, true);
+ TheTeamFactory->initTeam(tname, m_playerName, TRUE, &d);
+ dt = TheTeamFactory->findTeam(tname);
+ }
+ m_defaultTeam = dt;
+ dt->setActive();
}
//=============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
index 07cff673d..80cd29ef5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
@@ -390,7 +390,9 @@ Bool FileSystem::isForkOwnedPath(const AsciiString& filename)
// of Code/Data (less Scenarios, Cinema and the shader cache) plus the classic bar textures.
// Tests/test_gameengine.cpp walks Code/Data and fails when a master falls outside this. Retail's own
// loose files (Data\Scripts\MultiplayerScripts.scb, the movies, the cursors) are not in it, so a mod
- // still replaces those. The fork's Reforged*.big are kept on top in ArchiveFileSystem::loadMods.
+ // still replaces those. Nor is the fork's SkirmishScripts.scb, by the owner's call: a mod's skirmish
+ // AI is written for its own generals, which the fork's has no players for, so a mod's scb wins whole
+ // and the fork's C++ AI runs it. The fork's Reforged*.big are kept on top in ArchiveFileSystem::loadMods.
AsciiString path = filename;
path.toLower();
std::string p(path.str());
@@ -407,7 +409,6 @@ Bool FileSystem::isForkOwnedPath(const AsciiString& filename)
if (starts("data\\ini\\mappedimages\\handcreated\\reforged") && ends(".ini"))
return TRUE;
return p == "data\\patch.str"
- || p == "data\\scripts\\skirmishscripts.scb"
|| starts("data\\turkish\\") || starts("data\\german\\")
|| starts("art\\textures\\reforged") || starts("art\\textures\\classicwidebar")
|| starts("window\\")
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp
index d374d7d93..f32a5e030 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp
@@ -673,6 +673,7 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ )
msg.GameToJoin.serial[g_maxSerialLength-1] = '\0';
// so a host whose INI set differs can tell the player it is the mod and which one (handleRequestJoin)
WideCharFromUtf8(TheGlobalData->m_modName.str(), msg.GameToJoin.modName, ARRAY_SIZE(msg.GameToJoin.modName));
+ msg.GameToJoin.baseExeCRC = TheGlobalData->m_baseExeCRC;
sendMessage(&msg, ip);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
index 4de2e3b32..25b7d8612 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp
@@ -259,13 +259,16 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
gameDataMatchName(dataMatch),
msg->GameToJoin.iniCRC, TheGlobalData->m_iniCRC,
msg->GameToJoin.exeCRC, TheGlobalData->m_exeCRC));
- // Same exe and a different INI set is what two different -mod folders look like; then the
- // player is told the host's mod rather than the bare mismatch.
+ // The same build under different -mod lists: a mod changes the INI set and, with its own
+ // skirmish or multiplayer scripts, the exe CRC too (GlobalData::computeExeCRC), so the build is
+ // compared as it was before the mods mounted. Then the player is told the host's mods rather
+ // than the bare mismatch.
WideChar joinerMod[g_lanModNameLength+1];
WideCharNCpy(joinerMod, msg->GameToJoin.modName, g_lanModNameLength);
joinerMod[g_lanModNameLength] = 0;
WideCharFromUtf8(TheGlobalData->m_modName.str(), reply.GameNotJoined.modName, ARRAY_SIZE(reply.GameNotJoined.modName));
- const Bool modsDiffer = dataMatch == GAMEDATA_INI_DIFFERS && WideCharCmp(joinerMod, reply.GameNotJoined.modName) != 0;
+ const Bool modsDiffer = msg->GameToJoin.baseExeCRC == TheGlobalData->m_baseExeCRC &&
+ WideCharCmp(joinerMod, reply.GameNotJoined.modName) != 0;
DEBUG_LOG(("LANAPI::handleRequestJoin - mods them/us '%s'/'%s'\n",
WideCharAsUtf8(joinerMod).str(), TheGlobalData->m_modName.str()));
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 1abeb3ba8..a937344e3 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -17148,6 +17148,9 @@ TEST(every_shipped_master_is_fork_owned_and_retail_files_are_not)
std::string relative = std::filesystem::relative(it->path(), data).generic_string();
if (relative.rfind("Scenarios/", 0) == 0 || relative.rfind("Cinema/", 0) == 0 || relative == "dx11shaders.shipped")
continue;
+ // shipped, but the one master a mod may replace: its skirmish AI is written for its own generals
+ if (relative == "Scripts/SkirmishScripts.scb")
+ continue;
// the post-build copy keeps Data\ in front of these and puts the rest at the top of Run
const char *underData[] = { "INI/", "Scripts/", "Turkish/", "German/" };
Bool keepsData = relative == "Patch.str";
@@ -17163,6 +17166,7 @@ TEST(every_shipped_master_is_fork_owned_and_retail_files_are_not)
CHECK(FileSystem::isForkOwnedPath(AsciiString("Art\\Textures\\ClassicWideBarGLA.tga")));
CHECK(!FileSystem::isForkOwnedPath(AsciiString("Data\\Scripts\\MultiplayerScripts.scb")));
+ CHECK(!FileSystem::isForkOwnedPath(AsciiString("Data\\Scripts\\SkirmishScripts.scb")));
CHECK(!FileSystem::isForkOwnedPath(AsciiString("Data\\Scripts\\Scripts.ini")));
CHECK(!FileSystem::isForkOwnedPath(AsciiString("Data\\INI\\GameData.ini")));
CHECK(!FileSystem::isForkOwnedPath(AsciiString("Data\\INI\\Object\\AmericaTankReforged.ini")));