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): mod folders, repeatable -mod and named mod mismatch
Olcay Seygandcd0a0eeabdd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d1f666b60..d5e37b7c4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,13 @@ found and fixed — EA's own, not port damage.**- Windows on Arm laptops, the Snapdragon ones, get a build made for them. Microsoft never shipped those machines the library the game loads its textures and shaders through, so the game brings its own, the texture code the Mac and Linux versions already run. Switched on in place of Microsoft's library on an ordinary Windows PC, it draws the same battlefields, with no tree, house or patch of ground going missing. Nobody has played it on a Snapdragon laptop yet.- Thanks to ilyasakin, whose port this is.+## Mods++- A mod is a folder now. Start the game with `-mod` and the folder, and the archives in it win over the game's own, 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.+- 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.+## The command bar moves to the middle- The command bar is one console standing in the middle of the bottom edge: a taller radar, your selection and the build grid side by side, with the power bar over the grid. The idle worker and rank keys sit in a row over your selection, and in multiplayer the smoke signals join them. The red under-attack lamp is gone: the ping on the radar, the voice and the line in the event feed already tell you where you are hit, and the lamp only blinked about it a second time.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 7f24144a9..3a144e993 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1738,3 +1738,11 @@ ENDCONTROLBAR:Demo_ToolTipGLAScienceRebelAmbush"Allows you to create a surprise ambush of Rebels anywhere \n \n Rank 1: 4 Rebels \n Rank 2: 6 Rebels \n Rank 3: 10 Rebels \n \n Deploy from: Command Center"END++LAN:ErrorModMismatch+"This game runs different mods. The host's mods: %s. Start the game with the same mods, in the same order, to join."+END++LAN:NoMod+"none"+ENDdiff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 9de8c0263..e987601d0 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -2589,6 +2589,14 @@ LAN:ErrorCRCMismatch"Oyun bir uyumsuzluk tespit etti. Çok oyunculu oyun, oyuncular arasındaki senkronizasyon verisini kaybetti. Rakibiniz sürümünü değiştirmiş olabilir; onu Yok Sayma Listenize eklemek isteyebilirsiniz"END+LAN:ErrorModMismatch+"Bu oyun başka modlarla oynanıyor. Kurucunun modları: %s. Katılmak için oyunu aynı modlarla, aynı sırayla başlatın."+END++LAN:NoMod+"yok"+END+LAN:ErrorGameStarted"Üzgünüz, bu oyun zaten başladı"ENDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.hindex 07b5a76bb..f48654f0c 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h@@ -138,6 +138,11 @@ public:void getFileListInDirectory(const AsciiString& directory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories.Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const; ///< fills in the FileInfo struct for the file given. returns TRUE if successful.+ /// "<mod dir><filename>" when the last -mod that has this game path has it loose, else empty. When+ /// that mod has it in an archive instead, *inModArchive says so. Either copy beats Run's loose files+ /// and every archive that is not a mod's.+ AsciiString modLooseFile(const AsciiString& filename, Bool *inModArchive = NULL) const;+Bool createDirectory(AsciiString directory); ///< create a directory of the given name./// language when Data\<language>\Language.ini is loose or in an archive, otherwise the firstdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 84e1b5eb3..87aeccde2 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -725,8 +725,8 @@ public:Bool m_isBreakableMovie; ///< if we enter a breakable movie, set this flagBool m_breakTheMovie; ///< The user has hit escape!- AsciiString m_modDir;- AsciiString m_modBIG;+ std::vector<AsciiString> m_mods; ///< every -mod in command-line order, later wins: a folder ends in '\', anything else is a .big+ AsciiString 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 -mod//-allAdvice feature//Bool m_allAdvice;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/version.h b/GeneralsMD/Code/GameEngine/Include/Common/version.hindex a66de2342..ff007581e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/version.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/version.h@@ -43,7 +43,8 @@ public:UnsignedInt getVersionNumber( void ); ///< Return a 4-byte integer suitable for WOLAPIAsciiString getAsciiVersion( void ); ///< Return a human-readable version numberAsciiString getReleaseVersion( void ); ///< The fork's release number as the tags write it, "v2.6.0"- UnicodeString getUnicodeVersion( void ); ///< Return a human-readable version number+ UnicodeString getUnicodeVersion( void ); ///< Return a human-readable version number, with " [<mod>]" under -mod+ UnicodeString getUnicodeModName( void ); ///< TheGlobalData->m_modName as text, empty without -modUnicodeString getFullUnicodeVersion( void ); ///< Return a human-readable version numberAsciiString getAsciiBuildTime( void ); ///< Return a formated date/time string for build timeUnicodeString getUnicodeBuildTime( void ); ///< Return a formated date/time string for build timediff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.hindex 0b4ba00fd..868011e0f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h@@ -54,6 +54,7 @@ static const Int g_lanMaxChatLength = 100;static const Int m_lanMaxOptionsLength = MAX_LANAPI_PACKET_SIZE - ( 8 + (g_lanGameNameLength+1)*2 + 4 + (g_lanPlayerNameLength+1)*2+ (g_lanLoginNameLength+1) + (g_lanHostNameLength+1) );static const Int g_maxSerialLength = 23; // including the trailing '\0'+static const Int g_lanModNameLength = 150; // the -mod list in a join request and its refusal; longer lists are cut//// Whether to put this machine's Windows login and computer name on the wire. EA cut the@@ -123,6 +124,7 @@ public:RET_GAME_GONE, // OnGameJoinRET_BUSY, // OnGameCreate/Join/etc if another action is in progressRET_UNKNOWN, // Default message for oddity+ RET_MOD_MISMATCH, // OnGameJoin: the INI CRCs differ and so do the two -mod namesRET_MAX};UnicodeString getErrorStringFromReturnType( ReturnType ret );@@ -254,6 +256,7 @@ protected:PendingActionType m_pendingAction; ///< What action are we performing?UnsignedInt m_expiration; ///< When should we give up on our action?UnsignedInt m_actionTimeout;+ UnicodeString m_joinDeniedHostMod; ///< The host's mod from the last RET_MOD_MISMATCH, empty for noneUnsignedInt m_directConnectRemoteIP;///< The IP address of the game we are direct connecting to.// Resend timer ---------------------------------------------------------------------------@@ -392,6 +395,8 @@ struct LANMessageUnsignedInt exeCRC;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} GameToJoin;// GameJoined is sent with JOIN_ACCEPT@@ -410,6 +415,7 @@ struct LANMessageUnsignedInt gameIP;UnsignedInt playerIP;LANAPIInterface::ReturnType reason;+ WideChar modName[g_lanModNameLength+1]; ///< the host's -mod name with RET_MOD_MISMATCH, empty for none} GameNotJoined;// Accept is sent with SET_ACCEPT@@ -466,6 +472,8 @@ static_assert(offsetof(LANMessage, PlayerInfo.playerName) == 38, "LANMessage::Plstatic_assert(offsetof(LANMessage, GameToJoin.exeCRC) == 38, "LANMessage::GameToJoin.exeCRC");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, 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");static_assert(offsetof(LANMessage, Accept.isAccepted) == 68, "LANMessage::Accept.isAccepted");diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 854dff85a..af79fe6d9 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -28,9 +28,12 @@#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine#include "zhio.h"+#include <string>+#include "Common/ArchiveFileSystem.h"#include "Common/CommandLine.h"#include "Common/CRCDebug.h"+#include "Common/file.h"#include "Common/LocalFileSystem.h"#include "Common/OptionsCatalog.h"#include "Common/version.h"@@ -2525,6 +2528,80 @@ Int parseUpdateImages(char *args[], int num)return 1;}+/** The string value of "key" in mod.json, or empty. ponytail: a flat object of string values is+ * all the launcher writes, so this finds the key and reads to the closing quote, honouring only a+ * backslash escape; a real parser is for the day mod.json grows nesting. */+static AsciiString modJsonString( const std::string &json, const char *key )+{+ const char *space = " \t\r\n";+ std::string quoted = std::string( "\"" ) + key + "\"";+ size_t at = std::string::npos;+ // the key is the quoted name followed by a colon; the same text as somebody's value is not+ for (size_t found = json.find( quoted ); found != std::string::npos; found = json.find( quoted, found + 1 ))+ {+ size_t colon = json.find_first_not_of( space, found + quoted.size() );+ if (colon != std::string::npos && json[colon] == ':')+ {+ at = json.find_first_not_of( space, colon + 1 );+ break;+ }+ }+ // a number or anything else that is not a string is no name+ if (at == std::string::npos || json[at] != '"')+ return AsciiString();++ AsciiString value;+ for (++at; at < json.size() && json[at] != '"'; ++at)+ {+ if (json[at] == '\\' && at + 1 < json.size())+ ++at;+ value.concat( json[at] );+ }+ return value;+}++/** What the mod is called on the version line, in the replay and in a refused join: "<name> <version>"+ * from the folder's mod.json, else the folder's or the archive's own name. */+static AsciiString modIdentity( const AsciiString &modPath, Bool isDir )+{+ AsciiString name;+ if (isDir)+ {+ AsciiString jsonPath = modPath;+ jsonPath.concat( "mod.json" );+ File *file = TheLocalFileSystem->openFile( jsonPath.str(), File::READ | File::BINARY );+ if (file != NULL)+ {+ Int size = file->size();+ char *contents = file->readEntireAndClose();+ std::string json( contents, size );+ delete [] contents;++ name = modJsonString( json, "name" );+ AsciiString version = modJsonString( json, "version" );+ if (name.isNotEmpty() && version.isNotEmpty())+ {+ name.concat( ' ' );+ name.concat( version );+ }+ }+ }+ if (name.isEmpty())+ {+ // the last path component, without the trailing separator a folder was given and without ".big"+ std::string path( modPath.str() );+ while (!path.empty() && (path.back() == '\\' || path.back() == '/'))+ path.pop_back();+ size_t slash = path.find_last_of( "\\/" );+ if (slash != std::string::npos)+ path.erase( 0, slash + 1 );+ if (!isDir && path.size() > 4 && strcasecmp( path.c_str() + path.size() - 4, ".big" ) == 0)+ path.erase( path.size() - 4 );+ name = path.c_str();+ }+ return name;+}+Int parseMod(char *args[], Int num){if (TheWritableGlobalData && num > 1)@@ -2559,13 +2636,19 @@ Int parseMod(char *args[], Int num)if (!modPath.endsWith("\\") && !modPath.endsWith("/"))modPath.concat('\\');DEBUG_LOG(("Mod dir is '%s'.\n", modPath.str()));- TheWritableGlobalData->m_modDir = modPath;}else{DEBUG_LOG(("Mod file is '%s'.\n", modPath.str()));- TheWritableGlobalData->m_modBIG = modPath;}+ // repeatable: each -mod goes after the ones before it and wins over them (loadMods, FileSystem::modLooseFile)+ TheWritableGlobalData->m_mods.push_back( modPath );++ AsciiString name = modIdentity( modPath, (statBuf.st_mode & S_IFDIR) != 0 );+ if (TheGlobalData->m_modName.isNotEmpty())+ TheWritableGlobalData->m_modName.concat( ", " );+ TheWritableGlobalData->m_modName.concat( name );+ DEBUG_LOG(("MOD %d name='%s' path='%s'\n", (Int)TheGlobalData->m_mods.size(), name.str(), modPath.str()));return 2;}@@ -2809,6 +2892,13 @@ void parseCommandLine(int argc, char *argv[])}TheArchiveFileSystem->loadMods();++ // GameData.ini and the language check have already asked about files the mod may now supply+ if (TheGlobalData->m_modName.isNotEmpty())+ {+ DEBUG_LOG(("MODS %d loaded, last wins: %s\n", (Int)TheGlobalData->m_mods.size(), TheGlobalData->m_modName.str()));+ TheFileSystem->reset();+ }}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex e3540218d..081610640 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -319,8 +319,12 @@ static void checksumModels( XferCRC &xferCRC )AsciiString model = *it;model.toLower();- AsciiString source = TheLocalFileSystem->doesFileExist( model.str() )- ? model : TheArchiveFileSystem->getArchiveFilenameForFile( model );+ // the file openFile will read: a mod's loose or archived copy first (FileSystem::modLooseFile)+ Bool inModArchive = FALSE;+ AsciiString source = TheFileSystem->modLooseFile( model, &inModArchive );+ if (source.isEmpty())+ source = TheLocalFileSystem->doesFileExist( model.str() ) && !inModArchive+ ? model : TheArchiveFileSystem->getArchiveFilenameForFile( model );ModelChecksum entry;const Bool sourceKnown = TheLocalFileSystem->getFileInfo( source, &entry.source );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cppindex 6aa4d88d6..ea33718de 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp@@ -173,30 +173,34 @@ void ArchiveFileSystem::loadIntoDirectoryTree(const ArchiveFile *archiveFile, co}void ArchiveFileSystem::loadMods() {- if (TheGlobalData->m_modBIG.isNotEmpty())+ // In command-line order, each with overwrite: a later -mod wins over an earlier one, and all of them+ // over the retail and Reforged archives already in the tree.+ for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i){- ArchiveFile *archiveFile = openArchiveFile(TheGlobalData->m_modBIG.str());+ const AsciiString &mod = TheGlobalData->m_mods[i];+ if (mod.endsWith("\\") || mod.endsWith("/"))+ {+#ifdef DEBUG_LOGGING+ Bool ret =+#endif+ loadBigFilesFromDirectory(mod, "*.big", TRUE);+ DEBUG_ASSERTLOG(ret, ("loadBigFilesFromDirectory(%s) returned FALSE!\n", mod.str()));+ continue;+ }++ ArchiveFile *archiveFile = openArchiveFile(mod.str());if (archiveFile != NULL) {- DEBUG_LOG(("ArchiveFileSystem::loadMods - loading %s into the directory tree.\n", TheGlobalData->m_modBIG.str()));- loadIntoDirectoryTree(archiveFile, TheGlobalData->m_modBIG, TRUE);- m_archiveFileMap[TheGlobalData->m_modBIG] = archiveFile;- DEBUG_LOG(("ArchiveFileSystem::loadMods - %s inserted into the archive file map.\n", TheGlobalData->m_modBIG.str()));+ DEBUG_LOG(("ArchiveFileSystem::loadMods - loading %s into the directory tree.\n", mod.str()));+ loadIntoDirectoryTree(archiveFile, mod, TRUE);+ m_archiveFileMap[mod] = archiveFile;+ DEBUG_LOG(("ArchiveFileSystem::loadMods - %s inserted into the archive file map.\n", mod.str()));}else{- DEBUG_LOG(("ArchiveFileSystem::loadMods - could not openArchiveFile(%s)\n", TheGlobalData->m_modBIG.str()));+ DEBUG_LOG(("ArchiveFileSystem::loadMods - could not openArchiveFile(%s)\n", mod.str()));}}-- if (TheGlobalData->m_modDir.isNotEmpty())- {-#ifdef DEBUG_LOGGING- Bool ret =-#endif- loadBigFilesFromDirectory(TheGlobalData->m_modDir, "*.big", TRUE);- DEBUG_ASSERTLOG(ret, ("loadBigFilesFromDirectory(%s) returned FALSE!\n", TheGlobalData->m_modDir.str()));- }}Bool ArchiveFileSystem::doesFileExist(const Char *filename) constdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cppindex c5f6af32b..3b393b2a5 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp@@ -54,6 +54,7 @@#include "Common/ArchiveFileSystem.h"#include "Common/CDManager.h"#include "Common/GameAudio.h"+#include "Common/GlobalData.h"#include "Common/LocalFileSystem.h"#include "Common/PerfTimer.h"#include "Common/RAMFile.h"@@ -62,6 +63,12 @@DECLARE_PERF_TIMER(FileSystem)+/// a drive or a root: the user data folder and the like, which a mod folder never stands in for+static Bool isAbsolutePath( const AsciiString &path )+{+ return strchr( path.str(), ':' ) != NULL || path.startsWith( "\\" ) || path.startsWith( "/" );+}+//----------------------------------------------------------------------------// Externals//----------------------------------------------------------------------------@@ -208,6 +215,23 @@ File* FileSystem::openFile( const Char *filename, Int access )return NULL;}+ // a mod's copy, loose or archived, goes in front of Run's own loose files and every other archive;+ // writes stay where they were+ if ( (access & (File::WRITE | File::CREATE | File::APPEND | File::TRUNCATE)) == 0 )+ {+ Bool inModArchive = FALSE;+ AsciiString modded = modLooseFile( AsciiString( filename ), &inModArchive );+ if ( modded.isNotEmpty() )+ {+ DEBUG_LOG(( "FileSystem::openFile - mod file %s\n", modded.str() ));+ return TheLocalFileSystem->openFile( modded.str(), access );+ }+ if ( inModArchive )+ {+ return TheArchiveFileSystem->openFile( filename, access );+ }+ }+if ( TheLocalFileSystem != NULL ){file = TheLocalFileSystem->openFile( filename, access );@@ -247,7 +271,7 @@ Bool FileSystem::doesFileExist(const Char *filename) constif (i!=m_fileExist.end())return i->second;- if (TheLocalFileSystem->doesFileExist(filename))+ if (TheLocalFileSystem->doesFileExist(filename) || modLooseFile(AsciiString(filename)).isNotEmpty()){m_fileExist[key]=true;return TRUE;@@ -270,6 +294,74 @@ void FileSystem::getFileListInDirectory(const AsciiString& directory, const AsciUSE_PERF_TIMER(FileSystem)TheLocalFileSystem->getFileListInDirectory(AsciiString(""), directory, searchName, filenameList, searchSubdirectories);TheArchiveFileSystem->getFileListInDirectory(AsciiString(""), directory, searchName, filenameList, searchSubdirectories);++ // 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+ if (TheGlobalData == NULL || isAbsolutePath(directory))+ {+ return;+ }+ for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i)+ {+ const AsciiString &modDir = TheGlobalData->m_mods[i];+ if (!modDir.endsWith("\\") && !modDir.endsWith("/"))+ {+ continue; // a .big, already in the archive tree+ }+ AsciiString modDirectory = modDir;+ modDirectory.concat(directory);+ FilenameList modded;+ TheLocalFileSystem->getFileListInDirectory(AsciiString(""), modDirectory, searchName, modded, searchSubdirectories);+ for (FilenameListIter it = modded.begin(); it != modded.end(); ++it)+ {+ filenameList.insert(AsciiString(it->str() + modDir.getLength()));+ }+ }+}++//============================================================================+// FileSystem::modLooseFile+//============================================================================+AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArchive) const+{+ if (inModArchive != NULL)+ {+ *inModArchive = FALSE;+ }+ // a folder is not a file: "" or "Maps\" would otherwise find the mod folder itself, which exists+ if (TheGlobalData == NULL || TheGlobalData->m_mods.empty() || isAbsolutePath(filename) ||+ filename.isEmpty() || filename.endsWith("\\") || filename.endsWith("/"))+ {+ return AsciiString();+ }++ // The last -mod that has the file wins, whether it has it loose or in an archive: a later mod's+ // .big beats an earlier mod's loose copy. An archive key is the -mod path itself, or that folder+ // followed by the archive's name (loadMods).+ const AsciiString archive = TheArchiveFileSystem->getArchiveFilenameForFile(filename);+ for (size_t i = TheGlobalData->m_mods.size(); i-- > 0; )+ {+ const AsciiString &mod = TheGlobalData->m_mods[i];+ const Bool isFolder = mod.endsWith("\\") || mod.endsWith("/");+ if (isFolder)+ {+ AsciiString path = mod;+ path.concat(filename);+ if (TheLocalFileSystem->doesFileExist(path.str()))+ {+ return path;+ }+ }+ if (archive.isNotEmpty() && (isFolder ? archive.startsWithNoCase(mod.str()) : archive.compareNoCase(mod) == 0))+ {+ if (inModArchive != NULL)+ {+ *inModArchive = TRUE;+ }+ return AsciiString();+ }+ }+ return AsciiString();}//============================================================================@@ -292,6 +384,15 @@ Bool FileSystem::getFileInfo(const AsciiString& filename, FileInfo *fileInfo) coreturn TRUE;}+ Bool inModArchive = FALSE;+ AsciiString modded = modLooseFile(filename, &inModArchive);+ if (modded.isNotEmpty()) {+ return TheLocalFileSystem->getFileInfo(modded, fileInfo);+ }+ if (inModArchive) {+ return TheArchiveFileSystem->getFileInfo(filename, fileInfo);+ }+if (TheLocalFileSystem->getFileInfo(filename, fileInfo)) {return TRUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/version.cpp b/GeneralsMD/Code/GameEngine/Source/Common/version.cppindex 3356d6847..8744cce74 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/version.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/version.cpp@@ -29,7 +29,9 @@#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Lib/WideCharFns.h"#include "GameClient/GameText.h"+#include "Common/GlobalData.h"#include "Common/version.h"Version *TheVersion = NULL; ///< The Version singleton@@ -114,9 +116,25 @@ UnicodeString Version::getUnicodeVersion( void )version.concat(UnicodeString(u" Internal"));#endif+ // The replay header carries this string and playback compares it, so a modded replay names its mod+ // and is flagged as another version when it is opened without that mod.+ if (TheGlobalData->m_modName.isNotEmpty())+ {+ version.concat(UnicodeString(u" ["));+ version.concat(getUnicodeModName());+ version.concat(UnicodeString(u"]"));+ }+return version;}+UnicodeString Version::getUnicodeModName( void )+{+ WideChar name[512]; // the whole -mod list; the replay header reads up to 1024 units back+ WideCharFromUtf8( TheGlobalData->m_modName.str(), name, ARRAY_SIZE(name) );+ return UnicodeString( name );+}+UnicodeString Version::getFullUnicodeVersion( void ){UnicodeString version;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cppindex bf71a9967..49e58d4bb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp@@ -2341,6 +2341,23 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )UnicodeString releaseVersion;releaseVersion.translate( TheVersion->getReleaseVersion() );versionString.concat( releaseVersion );+ if (TheGlobalData->m_modName.isNotEmpty())+ {+ // the label is one line under the menu; a long -mod list keeps its start, the replay keeps all of it+ const Int MAX_MOD_CHARS = 48;+ UnicodeString mods = TheVersion->getUnicodeModName();+ if (mods.getLength() > MAX_MOD_CHARS)+ {+ UnicodeString cut;+ for (Int i = 0; i < MAX_MOD_CHARS - 3; ++i)+ cut.concat( mods.getCharAt( i ) );+ cut.concat( u"..." );+ mods = cut;+ }+ versionString.concat( u" [" );+ versionString.concat( mods );+ versionString.concat( u"]" );+ }if (TheVersion->showFullVersion()){diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cppindex bd656e01a..d374d7d93 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp@@ -671,6 +671,8 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ )// and the far end reads these as C strings out of the packet.strlcpy(msg.GameToJoin.serial, s.str(), ARRAY_SIZE(msg.GameToJoin.serial));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));sendMessage(&msg, ip);diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cppindex 91a864242..2571bb1ad 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp@@ -85,6 +85,7 @@ UnicodeString LANAPIInterface::getErrorStringFromReturnType( ReturnType ret )case RET_DUPLICATE_NAME:return TheGameText->fetch("LAN:ErrorDuplicateName");case RET_CRC_MISMATCH:+ case RET_MOD_MISMATCH:return TheGameText->fetch("LAN:ErrorCRCMismatch");case RET_GAME_STARTED:return TheGameText->fetch("LAN:ErrorGameStarted");@@ -693,6 +694,11 @@ void LANAPI::OnGameJoin( ReturnType ret, LANGameInfo *theGame )UnicodeString title, body;title = TheGameText->fetch("LAN:JoinFailed");body = getErrorStringFromReturnType(ret);+ if (ret == RET_MOD_MISMATCH)+ {+ body.format(TheGameText->fetch("LAN:ErrorModMismatch").str(),+ m_joinDeniedHostMod.isEmpty() ? TheGameText->fetch("LAN:NoMod").str() : m_joinDeniedHostMod.str());+ }MessageBoxOk(title, body, NULL);}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cppindex f11ff95ae..4de2e3b32 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp@@ -259,8 +259,18 @@ 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.+ 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;+ DEBUG_LOG(("LANAPI::handleRequestJoin - mods them/us '%s'/'%s'\n",+ WideCharAsUtf8(joinerMod).str(), TheGlobalData->m_modName.str()));+reply.LANMessageType = LANMessage::MSG_JOIN_DENY;- reply.GameNotJoined.reason = LANAPIInterface::RET_CRC_MISMATCH;+ reply.GameNotJoined.reason = modsDiffer ? LANAPIInterface::RET_MOD_MISMATCH : LANAPIInterface::RET_CRC_MISMATCH;reply.GameNotJoined.gameIP = m_localIP;reply.GameNotJoined.playerIP = senderIP;canJoin = false;@@ -455,6 +465,11 @@ void LANAPI::handleJoinDeny( LANMessage *msg, UnsignedInt senderIP ){if (m_pendingAction == ACT_JOIN) // Are we trying to join?{+ if (msg->GameNotJoined.reason == RET_MOD_MISMATCH)+ {+ msg->GameNotJoined.modName[g_lanModNameLength] = 0;+ m_joinDeniedHostMod = UnicodeString(msg->GameNotJoined.modName);+ }OnGameJoin(msg->GameNotJoined.reason, LookupGame(UnicodeString(msg->GameNotJoined.gameName)));m_pendingAction = ACT_NONE;m_expiration = 0;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cppindex 725e18cc2..58f7fc0ed 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp@@ -259,10 +259,14 @@ VideoStreamInterface* BinkVideoPlayer::open( AsciiString movieTitle )if (pVideo) {DEBUG_LOG(("BinkVideoPlayer::createStream() - About to open bink file\n"));- if (TheGlobalData->m_modDir.isNotEmpty())+ // the last -mod folder with the movie wins, like every other file (FileSystem::modLooseFile)+ for (size_t i = TheGlobalData->m_mods.size(); i-- > 0; ){+ const AsciiString &modDir = TheGlobalData->m_mods[i];+ if (!modDir.endsWith("\\") && !modDir.endsWith("/"))+ continue;char filePath[ _MAX_PATH ];- snprintf( filePath, ARRAY_SIZE(filePath), "%s%s\\%s.%s", TheGlobalData->m_modDir.str(), VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );+ snprintf( filePath, ARRAY_SIZE(filePath), "%s%s\\%s.%s", modDir.str(), VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );HBINK handle = BinkOpen(filePath , BINKPRELOADALL );DEBUG_ASSERTLOG(!handle, ("opened bink file %s\n", filePath));if (handle)