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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): -modpatch stacks a patch on the mod before it
Olcay Seygan436f80a9ead1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4d6ca9b97..40d881355 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,7 @@ found and fixed — EA's own, not port damage.**- 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.- Two total conversions in one match. Add `-modfactions` to the mods you give, and each mod's armies join Zero Hour's own instead of replacing them: the faction list reads "ShockWave - USA" and "The End of Days - USA" under plain "USA", and a ShockWave army can fight an End of Days one. Each side builds from its own mod's units, weapons, upgrades and generals' powers, and each looks and sounds like its own mod: a ShockWave tank wears ShockWave's model and textures even where The End of Days replaces the same file, and speaks with ShockWave's voice. Playing a mod's faction, your command bar, build pictures, unit names and tooltips are that mod's; on one of Zero Hour's own you keep our bar. The End of Days' Russia is in the list under its own name. Menus, lobby and colours stay ours whatever mods you load. The skirmish AI lays out a mod's base from the mod's own buildings, but it still trains the army it knows from Zero Hour.+- A patch for a mod stays with that mod. Give it with `-modpatch` right after the mod it changes, and its files replace that mod's one for one, even beside a second total conversion: a ShockWave balance patch reaches ShockWave's armies and leaves The End of Days alone. Given first, a patch changes Zero Hour's own files. The launcher's MODS page marks each mod a patch or a full mod, and a `mod.json` can say `"patch": true`. With two full mods switched on the launcher now plays them side by side; before, ShockWave and The End of Days together stopped the game at startup.## One interfacediff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 4be4c9ae4..0f4b14e12 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -706,6 +706,9 @@ public:std::vector<AsciiString> m_mods; ///< every -mod in command-line order, later wins: a folder ends in '\', anything else is a .bigAsciiString m_modName; ///< UTF-8, each mod's "<name> <version>" from its mod.json (else the folder or archive name), joined by ", " in m_mods order; empty without -modstd::vector<AsciiString> m_modNames; ///< UTF-8, each mod's mod.json "name" (else the folder or archive name), in m_mods order+ std::vector<Bool> m_modIsPatch; ///< -modpatch: TRUE for each m_mods entry given as a patch; without -modfactions a patch is a plain -mod+ std::vector< std::vector<AsciiString> > m_modPatches; ///< -modfactions: the -modpatch folders over each m_mods[n], later wins+ std::vector<AsciiString> m_retailPatches; ///< -modfactions: the -modpatch folders given before any -mod, over retail's filesBool m_modFactions; ///< -modfactions: every mod's factions load beside retail's under "M<n>~" names (ModNamespace)//-allAdvice featurediff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 55cbfeb82..30ce8e077 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -28,6 +28,7 @@#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine#include "zhio.h"+#include <algorithm>#include <string>#include "Common/ArchiveFileSystem.h"@@ -2605,7 +2606,7 @@ static AsciiString modIdentity( const AsciiString &modPath, Bool isDir, AsciiStrreturn name;}-Int parseMod(char *args[], Int num)+static Int addMod(char *args[], Int num, Bool isPatch){if (TheWritableGlobalData && num > 1){@@ -2646,20 +2647,60 @@ Int parseMod(char *args[], Int num)}// repeatable: each -mod goes after the ones before it and wins over them (loadMods, FileSystem::modLooseFile)TheWritableGlobalData->m_mods.push_back( modPath );+ TheWritableGlobalData->m_modIsPatch.push_back( isPatch );AsciiString bareName;AsciiString name = modIdentity( modPath, (statBuf.st_mode & S_IFDIR) != 0, &bareName );TheWritableGlobalData->m_modNames.push_back( bareName );+ // a patch reads "ShockWave 1.201 + Tweak 1.0" in the version line, a replay and a refused joinif (TheGlobalData->m_modName.isNotEmpty())- TheWritableGlobalData->m_modName.concat( ", " );+ TheWritableGlobalData->m_modName.concat( isPatch ? " + " : ", " );TheWritableGlobalData->m_modName.concat( name );- DEBUG_LOG(("MOD %d name='%s' path='%s'\n", (Int)TheGlobalData->m_mods.size(), name.str(), modPath.str()));+ DEBUG_LOG(("MOD %d name='%s' path='%s'%s\n", (Int)TheGlobalData->m_mods.size(), name.str(), modPath.str(), isPatch ? " patch" : ""));return 2;}return 1;}+Int parseMod(char *args[], Int num)+{+ return addMod( args, num, FALSE );+}++/** -modpatch <folder>: a mod that changes the one given before it file by file rather than bringing+ * armies of its own, or retail's files when it comes first. Without -modfactions it is a plain -mod. */+Int parseModPatch(char *args[], Int num)+{+ return addMod( args, num, TRUE );+}++/** -modfactions keeps each full mod's files apart, so a patch joins the full mod before it (retail's+ * files when none is) and the full mods alone are the faction sets, M1, M2 and so on. */+static void foldModPatches()+{+ GlobalData *data = TheWritableGlobalData;+ std::vector<AsciiString> mods;+ std::vector<AsciiString> names;+ for (size_t i = 0; i < data->m_mods.size(); ++i)+ {+ if (!data->m_modIsPatch[i])+ {+ mods.push_back( data->m_mods[i] );+ names.push_back( data->m_modNames[i] );+ data->m_modPatches.push_back( std::vector<AsciiString>() );+ continue;+ }+ if (mods.empty())+ data->m_retailPatches.push_back( data->m_mods[i] );+ else+ data->m_modPatches.back().push_back( data->m_mods[i] );+ DEBUG_LOG(("MODPATCH '%s' over %s\n", data->m_modNames[i].str(), mods.empty() ? "retail" : names.back().str()));+ }+ data->m_mods = mods;+ data->m_modNames = names;+}+Int parseModFactions(char *args[], Int){if (TheWritableGlobalData)@@ -2683,6 +2724,7 @@ static CommandLineParam params[] ={ "-playStats", parsePlayStats },{ "-mod", parseMod },{ "-modfactions", parseModFactions },+ { "-modpatch", parseModPatch },{ "-noshaders", parseNoShaders },{ "-particlebounce", parseParticleBounce },{ "-smoke", parseSmoke },@@ -2906,9 +2948,13 @@ void parseCommandLine(int argc, char *argv[])}}- // with no -mod there is nothing to keep apart, and the retail focus would have no tree to read- if (TheGlobalData->m_mods.empty())+ // with no full -mod there is nothing to keep apart, and the retail focus would have no tree to read;+ // patches alone then stack as plain mods+ const std::vector<Bool> &isPatch = TheGlobalData->m_modIsPatch;+ if (std::find( isPatch.begin(), isPatch.end(), FALSE ) == isPatch.end())TheWritableGlobalData->m_modFactions = FALSE;+ if (TheGlobalData->m_modFactions)+ foldModPatches();TheArchiveFileSystem->loadMods();// GameData.ini and the language check have already asked about files the mod may now supplydiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cppindex 2f9d329ef..f460a2553 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp@@ -211,10 +211,21 @@ void ArchiveFileSystem::loadMods() {keepModsApart(TheGlobalData->m_mods.size());// In command-line order, each with overwrite: a later -mod wins over an earlier one, and all of them- // over the retail archives. A folder's archives go in the order Win32BIGFileSystem's own pass uses.+ // over the retail archives. Under -modfactions a -modpatch goes over the full mod it was given+ // after, in that mod's own tree, or over retail's when it came first (-1). A folder's archives go+ // in the order Win32BIGFileSystem's own pass uses.+ std::vector< std::pair<Int, AsciiString> > layers;+ for (size_t i = 0; i < TheGlobalData->m_retailPatches.size(); ++i)+ layers.push_back(std::make_pair(-1, TheGlobalData->m_retailPatches[i]));for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i){- const AsciiString &mod = TheGlobalData->m_mods[i];+ layers.push_back(std::make_pair((Int)i, TheGlobalData->m_mods[i]));+ for (size_t p = 0; i < TheGlobalData->m_modPatches.size() && p < TheGlobalData->m_modPatches[i].size(); ++p)+ layers.push_back(std::make_pair((Int)i, TheGlobalData->m_modPatches[i][p]));+ }+ for (size_t layer = 0; layer < layers.size(); ++layer)+ {+ const AsciiString &mod = layers[layer].second;FilenameList archives;if (mod.endsWith("\\") || mod.endsWith("/"))TheLocalFileSystem->getFileListInDirectory(mod, AsciiString(""), AsciiString("*.big"), archives, TRUE);@@ -235,7 +246,7 @@ void ArchiveFileSystem::loadMods() {continue;}DEBUG_LOG(("ArchiveFileSystem::loadMods - loading %s into the directory tree.\n", it->str()));- addModArchive((Int)i, archiveFile, *it);+ addModArchive(layers[layer].first, archiveFile, *it);}}@@ -256,7 +267,7 @@ void ArchiveFileSystem::addModArchive(Int mod, ArchiveFile *archiveFile, const Am_archiveFileMap[archiveFilename] = archiveFile;// kept apart, a mod's files are reached only through its own focus or an "M<n>~" name: the merged// view stays retail's, so the menus, the lobby and every file a faction does not name are ours- if (!m_modRoots.empty())+ if (!m_modRoots.empty() && mod >= 0){addToTree(m_modRoots[mod], archiveFile, archiveFilename, TRUE);m_archiveMod[archiveFilename] = mod;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cppindex 53d4cfe67..0420e584b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp@@ -158,21 +158,45 @@ void FileSystem::setFocus( Int focus )AsciiString FileSystem::focusedLooseFile( const AsciiString& filename ) const{- // retail is Run's own loose files; a mod is its folder's, and a mod that is one .big has none+ // retail is Run's own loose files under the patches given before any -mod (modLooseFile); a mod is+ // its folder's and its patches', and a mod that is one .big has noneif (s_focus == FILE_FOCUS_RETAIL)+ {+ Bool inPatchArchive = FALSE;+ AsciiString patched = modLooseFile( filename, &inPatchArchive );+ if (patched.isNotEmpty() || inPatchArchive)+ return patched;return TheLocalFileSystem->doesFileExist( filename.str() ) ? filename : AsciiString();+ }return modFolderFile( s_focus, filename );}+/** -modfactions: the folders a faction set's loose files come from, its -modpatch ones after the+ * mod's own so they win. FILE_FOCUS_RETAIL is the patches given before any -mod. */+static std::vector<AsciiString> modLayers( Int mod )+{+ if (mod < 0)+ return TheGlobalData->m_retailPatches;+ std::vector<AsciiString> layers( 1, TheGlobalData->m_mods[ mod ] );+ if (mod < (Int)TheGlobalData->m_modPatches.size())+ layers.insert( layers.end(), TheGlobalData->m_modPatches[ mod ].begin(), TheGlobalData->m_modPatches[ mod ].end() );+ return layers;+}+AsciiString FileSystem::modFolderFile( Int mod, const AsciiString& filename ) const{- const AsciiString &modPath = TheGlobalData->m_mods[ mod ];- if (!modPath.endsWith( "\\" ) && !modPath.endsWith( "/" ))- return AsciiString();- AsciiString path = modPath;- path.concat( filename );- return TheLocalFileSystem->doesFileExist( path.str() ) ? path : AsciiString();+ const std::vector<AsciiString> layers = modLayers( mod );+ for (size_t i = layers.size(); i-- > 0; )+ {+ if (!layers[i].endsWith( "\\" ) && !layers[i].endsWith( "/" ))+ continue;+ AsciiString path = layers[i];+ path.concat( filename );+ if (TheLocalFileSystem->doesFileExist( path.str() ))+ return path;+ }+ return AsciiString();}//============================================================================@@ -393,19 +417,16 @@ void FileSystem::getFileListInDirectory(const AsciiString& directory, const Asci// a mod's loose files listed under their game path, so a file it replaces is loaded once, from the mod (openFile)// TheGlobalData is not there yet while GameData.ini itself loads, and there is no -mod before it is- // -modfactions' merged view is retail's- if (TheGlobalData == NULL || isAbsolutePath(directory) || s_focus == FILE_FOCUS_RETAIL ||- (s_focus == FILE_FOCUS_ALL && TheGlobalData->m_modFactions))+ // -modfactions' merged view is retail's with the patches given before any -mod, and a focus sees+ // its own mod and that mod's patches+ if (TheGlobalData == NULL || isAbsolutePath(directory)){return;}- for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i)+ const std::vector<AsciiString> folders = TheGlobalData->m_modFactions ? modLayers(s_focus) : TheGlobalData->m_mods;+ for (size_t i = 0; i < folders.size(); ++i){- const AsciiString &modDir = TheGlobalData->m_mods[i];- if (s_focus >= 0 && (Int)i != s_focus)- {- continue;- }+ const AsciiString &modDir = folders[i];if (!modDir.endsWith("\\") && !modDir.endsWith("/")){continue; // a .big, already in the archive tree@@ -431,9 +452,14 @@ AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArc*inModArchive = FALSE;}// a folder is not a file: "" or "Maps\" would otherwise find the mod folder itself, which exists- // -modfactions reaches a mod's files only by its focus or its "M<n>~" names- if (TheGlobalData == NULL || TheGlobalData->m_mods.empty() || TheGlobalData->m_modFactions || isAbsolutePath(filename) ||- filename.isEmpty() || filename.endsWith("\\") || filename.endsWith("/"))+ // -modfactions reaches a mod's files only by its focus or its "M<n>~" names, so here only the+ // patches given before any -mod go over retail's+ if (TheGlobalData == NULL || isAbsolutePath(filename) || filename.isEmpty() || filename.endsWith("\\") || filename.endsWith("/"))+ {+ return AsciiString();+ }+ const std::vector<AsciiString> &mods = TheGlobalData->m_modFactions ? TheGlobalData->m_retailPatches : TheGlobalData->m_mods;+ if (mods.empty()){return AsciiString();}@@ -444,9 +470,9 @@ AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArcconst AsciiString archive = TheArchiveFileSystem->getArchiveFilenameForFile(filename);AsciiString loose;Bool archived = FALSE;- for (size_t i = TheGlobalData->m_mods.size(); i-- > 0 && loose.isEmpty() && !archived; )+ for (size_t i = mods.size(); i-- > 0 && loose.isEmpty() && !archived; ){- const AsciiString &mod = TheGlobalData->m_mods[i];+ const AsciiString &mod = mods[i];const Bool isFolder = mod.endsWith("\\") || mod.endsWith("/");if (isFolder){