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): every mod's factions load beside retail's, by switch
Olcay Seyganbcccb2428a3a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ab343c8e8..629f18fa7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,6 +27,7 @@ found and fixed — EA's own, not port damage.**- 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.+- 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. What every side shares still comes from the mod named last: the models and textures two mods both replace, the unit names and voices, the menus and the skirmish AI, which does not know how to play a mod's faction yet.## The command bar moves to the middlediff --git a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.hindex fa92689b2..09c77336b 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h@@ -175,12 +175,26 @@ class ArchiveFileSystem : public SubsystemInterfaceAsciiString getArchiveFilenameForFile(const AsciiString& filename) const;void loadMods( void );+ /// FileSystem::setFocus: FILE_FOCUS_ALL is the merged tree, FILE_FOCUS_RETAIL the tree as it was+ /// before any -mod, a -mod index that mod's archives alone. Only -modfactions keeps the apart trees.+ void setFocus( Int focus ) { m_focus = focus; }+protected:virtual void loadIntoDirectoryTree(const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite = FALSE ); ///< load the archive file's header information and apply it to the global archive directory tree.+ void addToTree(ArchivedDirectoryInfo &root, const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite);void prioritizeLargerFiles(const AsciiString& directory, const char *inferiorArchive, const char *superiorArchive); ///< where two archives claim the same file in this directory, keep the bigger copy.+ void keepModsApart( size_t modCount ); ///< snapshot the retail tree and start one empty tree per -mod+ void addModArchive( Int mod, ArchiveFile *archiveFile, const AsciiString& archiveFilename ); ///< over the merged tree, and into the mod's own when kept apart+ const ArchivedDirectoryInfo & focusedRoot( void ) const;+ Bool inFocus( const AsciiString& archiveFilename ) const;+ArchiveFileMap m_archiveFileMap;ArchivedDirectoryInfo m_rootDirectory;+ ArchivedDirectoryInfo m_retailRoot; ///< -modfactions: the tree before any -mod+ std::vector<ArchivedDirectoryInfo> m_modRoots; ///< -modfactions: each -mod's archives alone, in its own order+ std::map<AsciiString, Int> m_archiveMod; ///< -modfactions: archive -> -mod index; retail's are not in it+ Int m_focus;};diff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.hindex 07cd73b87..5966a74a6 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h@@ -101,6 +101,8 @@ typedef FilenameList::iterator FilenameListIter;#define TEST_TGA_DIR_PATH "../TestArt/" ///< .tga texture files live here#endif+enum { FILE_FOCUS_ALL = -2, FILE_FOCUS_RETAIL = -1 }; ///< FileSystem::setFocus; 0 and up is a -mod index+struct FileInfo {Int sizeHigh;Int sizeLow;@@ -148,6 +150,11 @@ public:/// .wnd layouts ...); see the definition for how the set is decided.static Bool isForkOwnedPath(const AsciiString& filename);+ /// -modfactions: FILE_FOCUS_RETAIL or a -mod index makes every read see that set of files alone,+ /// so retail and each mod load their factions one after another; FILE_FOCUS_ALL is the merged view.+ void setFocus(Int focus);+ Int getFocus() const { return s_focus; }+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 first@@ -159,7 +166,11 @@ public:void loadMusicFilesFromCD();void unloadMusicFilesFromCD();protected:+ AsciiString focusedLooseFile(const AsciiString& filename) const; ///< the loose copy the focus sees, else emptymutable std::map<unsigned,bool> m_fileExist;+ // static: GlobalData's constructor reads files through a TheFileSystem that a few engine tests leave+ // NULL, and openFile has always answered NULL there without touching the object+ static Int s_focus;};extern FileSystem* TheFileSystem;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 38de0823d..add69aff2 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -729,6 +729,8 @@ public:Bool m_breakTheMovie; ///< The user has hit escape!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 -mod+ std::vector<AsciiString> m_modNames; ///< UTF-8, each mod's mod.json "name" (else the folder or archive name), in m_mods order+ Bool m_modFactions; ///< -modfactions: every mod's factions load beside retail's under "M<n>~" names (ModNamespace)//-allAdvice feature//Bool m_allAdvice;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.hindex 5ec448ef3..81de1847f 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h@@ -36,6 +36,9 @@// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////#include <stddef.h> // for offsetof, which we don't use but everyone who includes us does+#include <set>+#include <string>+#include <vector>#include "Common/STLTypedefs.h"#include "Common/AsciiString.h"#include "Common/GameCommon.h"@@ -164,6 +167,54 @@ public:typedef void (*INIBlockParse)( INI *ini );typedef void (*BuildMultiIniFieldProc)(MultiIniFieldParse& p);+//-------------------------------------------------------------------------------------------------+/** -modfactions: every name a mod defines is read as "M<n>~name" while that mod's files load, so two+ * mods and retail can each have their own FactionAmerica, Ranger and Command_ConstructBarracks side+ * by side. A name the mod does not define stays retail's. The rewrite is of the text, before the+ * INI checksum sees it, so it is the same on every machine that has the same mods in the same order. */+//-------------------------------------------------------------------------------------------------+enum ModNameType+{+ MODNAME_OBJECT, MODNAME_WEAPON, MODNAME_ARMOR, MODNAME_DAMAGEFX, MODNAME_UPGRADE, MODNAME_SCIENCE,+ MODNAME_SPECIALPOWER, MODNAME_COMMANDSET, MODNAME_COMMANDBUTTON, MODNAME_FXLIST, MODNAME_OCL,+ MODNAME_PARTICLESYSTEM, MODNAME_LOCOMOTOR, MODNAME_PLAYERTEMPLATE,+ MODNAME_COUNT+};++class ModNamespace+{+public:+ ModNamespace() : m_active( -1 ) {}++ void scanMods( void ); ///< every -mod's faction files, each under its own FileSystem focus+ void scanLine( Int mod, const char *line ); ///< a block header names one of the mod's own; "Side = X" keeps X out+ void finishScan( Int mod ); ///< drop the side names, which the engine compares as text+ void setActive( Int mod ) { m_active = mod; } ///< -1: nothing is rewritten+ Int getActive( void ) const { return m_active; }+ Int getNameCount( Int mod ) const { return (Int)m_mods[ mod ].all.size(); }++ /// rewrite the active mod's names in a comment-free line in place, every word but the first;+ /// FALSE when the result would not fit capacity bytes+ Bool rewriteLine( char *line, size_t capacity ) const;+ /// "M<n>~X" where mod n has no `type` called X is a reference to retail's X: TRUE and *retailName+ /// set. Finders ask this on a miss, so a definition of the mod's own X never falls through to retail's.+ Bool findRetailName( const AsciiString &name, ModNameType type, AsciiString *retailName ) const;+ Bool findRetailKey( NameKeyType key, ModNameType type, NameKeyType *retailKey ) const;++ static const char *const FactionFiles[]; ///< what scanMods reads and the mod passes load, NULL-ended; no ".ini" is a directory++private:+ struct Names+ {+ std::set<std::string> all;+ std::set<std::string> byType[ MODNAME_COUNT ];+ std::set<std::string> sides;+ };+ std::vector<Names> m_mods;+ Int m_active;+};+extern ModNamespace TheModNamespace;+//-------------------------------------------------------------------------------------------------/** INI Reader interface *///-------------------------------------------------------------------------------------------------@@ -179,6 +230,8 @@ public:void loadDirectory( AsciiString dirName, Bool subdirs, INILoadType loadType, Xfer *pXfer ); ///< load directory of INI filesvoid load( AsciiString filename, INILoadType loadType, Xfer *pXfer ); ///< load INI file+ /// -modfactions: load path (a directory when directory) from each -mod in turn, under its focus and its names+ static void loadModPasses( const char *path, Xfer *pXfer, Bool directory = FALSE );static Bool isDeclarationOfType( AsciiString blockType, AsciiString blockName, char *bufferToCheck );static Bool isEndOfBlock( char *bufferToCheck );diff --git a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.hindex 68361715b..32d49a922 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h@@ -79,6 +79,9 @@ public:PlayerTemplate();inline void setNameKey(NameKeyType namekey) { m_nameKey = namekey; }+ /// -modfactions: the -mod this template came from, -1 for retail's own+ inline void setModIndex(Int mod) { m_modIndex = mod; }+ inline Int getModIndex() const { return m_modIndex; }inline NameKeyType getNameKey() const { DEBUG_ASSERTCRASH(m_nameKey != NAMEKEY_INVALID, ("bad namekey")); return m_nameKey; }inline AsciiString getName() const { return KEYNAME(m_nameKey); }@@ -153,6 +156,7 @@ protected:private:NameKeyType m_nameKey;+ Int m_modIndex;UnicodeString m_displayName;AsciiString m_side, m_baseSide;Handicap m_handicap; ///< initial baseline for Player capabilitiesdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex c5a47bea0..c82ac2288 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -2561,8 +2561,9 @@ static AsciiString modJsonString( const std::string &json, const char *key )}/** 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 )+ * from the folder's mod.json, else the folder's or the archive's own name. *bareName is the same+ * without the version, which is what -modfactions puts in front of a faction. */+static AsciiString modIdentity( const AsciiString &modPath, Bool isDir, AsciiString *bareName ){AsciiString name;if (isDir)@@ -2578,6 +2579,7 @@ static AsciiString modIdentity( const AsciiString &modPath, Bool isDir )delete [] contents;name = modJsonString( json, "name" );+ *bareName = name;AsciiString version = modJsonString( json, "version" );if (name.isNotEmpty() && version.isNotEmpty()){@@ -2598,6 +2600,7 @@ static AsciiString modIdentity( const AsciiString &modPath, Bool isDir )if (!isDir && path.size() > 4 && strcasecmp( path.c_str() + path.size() - 4, ".big" ) == 0)path.erase( path.size() - 4 );name = path.c_str();+ *bareName = name;}return name;}@@ -2644,7 +2647,9 @@ 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 );- AsciiString name = modIdentity( modPath, (statBuf.st_mode & S_IFDIR) != 0 );+ AsciiString bareName;+ AsciiString name = modIdentity( modPath, (statBuf.st_mode & S_IFDIR) != 0, &bareName );+ TheWritableGlobalData->m_modNames.push_back( bareName );if (TheGlobalData->m_modName.isNotEmpty())TheWritableGlobalData->m_modName.concat( ", " );TheWritableGlobalData->m_modName.concat( name );@@ -2655,6 +2660,15 @@ Int parseMod(char *args[], Int num)return 1;}+Int parseModFactions(char *args[], Int)+{+ if (TheWritableGlobalData)+ {+ TheWritableGlobalData->m_modFactions = TRUE;+ }+ return 1;+}+static CommandLineParam params[] ={{ "-noshellmap", parseNoShellMap },@@ -2668,6 +2682,7 @@ static CommandLineParam params[] ={ "-scriptDebug", parseScriptDebug },{ "-playStats", parsePlayStats },{ "-mod", parseMod },+ { "-modfactions", parseModFactions },{ "-noshaders", parseNoShaders },{ "-particlebounce", parseParticleBounce },{ "-smoke", parseSmoke },@@ -2891,6 +2906,9 @@ 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())+ TheWritableGlobalData->m_modFactions = FALSE;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/DamageFX.cpp b/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cppindex a09169f5d..1f869505e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/DamageFX.cpp@@ -278,9 +278,10 @@ const DamageFX *DamageFXStore::findDamageFX(AsciiString name) const{NameKeyType namekey = TheNameKeyGenerator->nameToKey(name);DamageFXMap::const_iterator it = m_dfxmap.find(namekey);- if (it == m_dfxmap.end())+ if (it == m_dfxmap.end()){- return NULL;+ AsciiString retailName;+ return TheModNamespace.findRetailName(name, MODNAME_DAMAGEFX, &retailName) ? findDamageFX(retailName) : NULL;}else{diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 081610640..e1ef27466 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -55,6 +55,7 @@#include "Common/INIException.h"#include "Common/MessageStream.h"#include "Common/ThingFactory.h"+#include "Common/ThingTemplate.h"#include "Common/file.h"#include "Common/FileSystem.h"#include "Common/ArchiveFileSystem.h"@@ -197,6 +198,37 @@ void initSubsystem(SUBSYSTEM*& sysref, AsciiString name, SUBSYSTEM* sys, Xfer *pTheSubsystemList->initSubsystem(sys, path1, path2, dirpath, pXfer, name);}+//-------------------------------------------------------------------------------------------------+/** A store a faction is made of. With -modfactions retail's own files load alone, and then each+ * mod's under that mod's names (INI::loadModPasses); a mod's Default\ file never loads. Without it+ * this is initSubsystem. */+//-------------------------------------------------------------------------------------------------+template<class SUBSYSTEM>+void initFactionSubsystem(SUBSYSTEM*& sysref, AsciiString name, SUBSYSTEM* sys, Xfer *pXfer, const char* path1,+ const char* path2, const char* dirpath = NULL)+{+ const Bool apart = TheGlobalData->m_modFactions;+ if (apart)+ TheFileSystem->setFocus(FILE_FOCUS_RETAIL);+ initSubsystem(sysref, name, sys, pXfer, path1, path2, dirpath);+ if (apart)+ TheFileSystem->setFocus(FILE_FOCUS_ALL);+ INI::loadModPasses(dirpath != NULL ? dirpath : path2, pXfer, dirpath != NULL);+}++/** A store that names faction parts without being one (crates, the AI's build lists, the ranks):+ * with -modfactions retail's copy, since a mod's names its own parts as they are only under its prefix. */+template<class SUBSYSTEM>+void initRetailSubsystem(SUBSYSTEM*& sysref, AsciiString name, SUBSYSTEM* sys, Xfer *pXfer, const char* path1, const char* path2)+{+ const Bool apart = TheGlobalData->m_modFactions;+ if (apart)+ TheFileSystem->setFocus(FILE_FOCUS_RETAIL);+ initSubsystem(sysref, name, sys, pXfer, path1, path2);+ if (apart)+ TheFileSystem->setFocus(FILE_FOCUS_ALL);+}+//-------------------------------------------------------------------------------------------------#if defined(_WIN32)extern HINSTANCE ApplicationHInstance; ///< our application instance@@ -219,6 +251,26 @@ static void checksumFileContents( XferCRC &xferCRC, const char *path )delete [] contents;}+/** The same for a file a faction is made of: with -modfactions retail's copy, then each mod's that+ * has one (modsToo), as ControlBar::init loads them. */+static void checksumFactionFile( XferCRC &xferCRC, const char *path, Bool modsToo )+{+ if (!TheGlobalData->m_modFactions)+ {+ checksumFileContents( xferCRC, path );+ return;+ }+ TheFileSystem->setFocus( FILE_FOCUS_RETAIL );+ checksumFileContents( xferCRC, path );+ for (Int mod = 0; modsToo && mod < (Int)TheGlobalData->m_mods.size(); ++mod)+ {+ TheFileSystem->setFocus( mod );+ if (TheFileSystem->doesFileExist( path ))+ checksumFileContents( xferCRC, path );+ }+ TheFileSystem->setFocus( FILE_FOCUS_ALL );+}+//-------------------------------------------------------------------------------------------------/** What a model's bytes hashed to, and the size and write time of the file they were read out of:* the archive the model resolved to, or the loose model itself. */@@ -1072,7 +1124,10 @@ void GameEngine::init( int argc, char *argv[] )#endif/////////////////////////////////////////////////////////////////////////////////////////////- initSubsystem(TheScienceStore,"TheScienceStore", MSGNEW("GameEngineSubsystem") ScienceStore(), &xferCRC, "Data\\INI\\Default\\Science.ini", "Data\\INI\\Science.ini");+ // -modfactions: which names each mod defines, read before any of its files load+ if (TheGlobalData->m_modFactions)+ TheModNamespace.scanMods();+ initFactionSubsystem(TheScienceStore,"TheScienceStore", MSGNEW("GameEngineSubsystem") ScienceStore(), &xferCRC, "Data\\INI\\Default\\Science.ini", "Data\\INI\\Science.ini");// New sciences only: a name EA already defined stops the loadini.load( AsciiString( "Data\\INI\\ScienceReforged.ini" ), INI_LOAD_MULTIFILE, &xferCRC );initSubsystem(TheMultiplayerSettings,"TheMultiplayerSettings", MSGNEW("GameEngineSubsystem") MultiplayerSettings(), &xferCRC, "Data\\INI\\Default\\Multiplayer.ini", "Data\\INI\\Multiplayer.ini");@@ -1117,8 +1172,8 @@ void GameEngine::init( int argc, char *argv[] )initSubsystem(TheMessageStream,"TheMessageStream", createMessageStream(), NULL);initSubsystem(TheSidesList,"TheSidesList", MSGNEW("GameEngineSubsystem") SidesList(), NULL);initSubsystem(TheCaveSystem,"TheCaveSystem", MSGNEW("GameEngineSubsystem") CaveSystem(), NULL);- initSubsystem(TheRankInfoStore,"TheRankInfoStore", MSGNEW("GameEngineSubsystem") RankInfoStore(), &xferCRC, NULL, "Data\\INI\\Rank.ini");- initSubsystem(ThePlayerTemplateStore,"ThePlayerTemplateStore", MSGNEW("GameEngineSubsystem") PlayerTemplateStore(), &xferCRC, "Data\\INI\\Default\\PlayerTemplate.ini", "Data\\INI\\PlayerTemplate.ini");+ initRetailSubsystem(TheRankInfoStore,"TheRankInfoStore", MSGNEW("GameEngineSubsystem") RankInfoStore(), &xferCRC, NULL, "Data\\INI\\Rank.ini");+ initFactionSubsystem(ThePlayerTemplateStore,"ThePlayerTemplateStore", MSGNEW("GameEngineSubsystem") PlayerTemplateStore(), &xferCRC, "Data\\INI\\Default\\PlayerTemplate.ini", "Data\\INI\\PlayerTemplate.ini");initSubsystem(TheParticleSystemManager,"TheParticleSystemManager", createParticleSystemManager(), NULL);#ifdef DUMP_PERF_STATS///////////////////////////////////////////////////////////////////////////@@ -1129,24 +1184,24 @@ void GameEngine::init( int argc, char *argv[] )#endif/////////////////////////////////////////////////////////////////////////////////////////////- initSubsystem(TheFXListStore,"TheFXListStore", MSGNEW("GameEngineSubsystem") FXListStore(), &xferCRC, "Data\\INI\\Default\\FXList.ini", "Data\\INI\\FXList.ini");+ initFactionSubsystem(TheFXListStore,"TheFXListStore", MSGNEW("GameEngineSubsystem") FXListStore(), &xferCRC, "Data\\INI\\Default\\FXList.ini", "Data\\INI\\FXList.ini");/* The fork's own detonation light, on top of EA's list. It is a separate file rather than aloose copy of FXList.ini because a loose copy shadows the whole 190K shipped file: it goesstale against every patch, it cannot be reviewed, and - since it lands in the INI CRC below -it silently refuses every multiplayer join from a machine that does not have the same one. */ini.load( AsciiString( "Data\\INI\\FXListReforged.ini" ), INI_LOAD_OVERWRITE, &xferCRC );- initSubsystem(TheWeaponStore,"TheWeaponStore", MSGNEW("GameEngineSubsystem") WeaponStore(), &xferCRC, NULL, "Data\\INI\\Weapon.ini");- initSubsystem(TheObjectCreationListStore,"TheObjectCreationListStore", MSGNEW("GameEngineSubsystem") ObjectCreationListStore(), &xferCRC, "Data\\INI\\Default\\ObjectCreationList.ini", "Data\\INI\\ObjectCreationList.ini");+ initFactionSubsystem(TheWeaponStore,"TheWeaponStore", MSGNEW("GameEngineSubsystem") WeaponStore(), &xferCRC, NULL, "Data\\INI\\Weapon.ini");+ initFactionSubsystem(TheObjectCreationListStore,"TheObjectCreationListStore", MSGNEW("GameEngineSubsystem") ObjectCreationListStore(), &xferCRC, "Data\\INI\\Default\\ObjectCreationList.ini", "Data\\INI\\ObjectCreationList.ini");/* Lists EA left out or got wrong, before any object names one: a list parsed again is clearedand replaced whole, and a new name is simply added. */ini.load( AsciiString( "Data\\INI\\ObjectCreationListReforged.ini" ), INI_LOAD_OVERWRITE, &xferCRC );- initSubsystem(TheLocomotorStore,"TheLocomotorStore", MSGNEW("GameEngineSubsystem") LocomotorStore(), &xferCRC, NULL, "Data\\INI\\Locomotor.ini");- initSubsystem(TheSpecialPowerStore,"TheSpecialPowerStore", MSGNEW("GameEngineSubsystem") SpecialPowerStore(), &xferCRC, "Data\\INI\\Default\\SpecialPower.ini", "Data\\INI\\SpecialPower.ini");+ initFactionSubsystem(TheLocomotorStore,"TheLocomotorStore", MSGNEW("GameEngineSubsystem") LocomotorStore(), &xferCRC, NULL, "Data\\INI\\Locomotor.ini");+ initFactionSubsystem(TheSpecialPowerStore,"TheSpecialPowerStore", MSGNEW("GameEngineSubsystem") SpecialPowerStore(), &xferCRC, "Data\\INI\\Default\\SpecialPower.ini", "Data\\INI\\SpecialPower.ini");/* Powers edited in place (a scan Frenzy should not give) and the Demolitions General's ownRebel Ambush, before any object names one. */ini.load( AsciiString( "Data\\INI\\SpecialPowerReforged.ini" ), INI_LOAD_MULTIFILE, &xferCRC );- initSubsystem(TheDamageFXStore,"TheDamageFXStore", MSGNEW("GameEngineSubsystem") DamageFXStore(), &xferCRC, NULL, "Data\\INI\\DamageFX.ini");- initSubsystem(TheArmorStore,"TheArmorStore", MSGNEW("GameEngineSubsystem") ArmorStore(), &xferCRC, NULL, "Data\\INI\\Armor.ini");+ initFactionSubsystem(TheDamageFXStore,"TheDamageFXStore", MSGNEW("GameEngineSubsystem") DamageFXStore(), &xferCRC, NULL, "Data\\INI\\DamageFX.ini");+ initFactionSubsystem(TheArmorStore,"TheArmorStore", MSGNEW("GameEngineSubsystem") ArmorStore(), &xferCRC, NULL, "Data\\INI\\Armor.ini");initSubsystem(TheBuildAssistant,"TheBuildAssistant", MSGNEW("GameEngineSubsystem") BuildAssistant, NULL);@@ -1159,7 +1214,7 @@ void GameEngine::init( int argc, char *argv[] )- initSubsystem(TheThingFactory,"TheThingFactory", createThingFactory(), &xferCRC, "Data\\INI\\Default\\Object.ini", NULL, "Data\\INI\\Object");+ initFactionSubsystem(TheThingFactory,"TheThingFactory", createThingFactory(), &xferCRC, "Data\\INI\\Default\\Object.ini", NULL, "Data\\INI\\Object");/* The fork's balance, written over EA's numbers after every object, weapon and armor exists.MULTIFILE edits a template in place and leaves every field the file does not name as EAwrote it, so the file holds the changes and nothing else; an Armor block still replaces@@ -1177,7 +1232,7 @@ void GameEngine::init( int argc, char *argv[] )#endif/////////////////////////////////////////////////////////////////////////////////////////////- initSubsystem(TheUpgradeCenter,"TheUpgradeCenter", MSGNEW("GameEngineSubsystem") UpgradeCenter, &xferCRC, "Data\\INI\\Default\\Upgrade.ini", "Data\\INI\\Upgrade.ini");+ initFactionSubsystem(TheUpgradeCenter,"TheUpgradeCenter", MSGNEW("GameEngineSubsystem") UpgradeCenter, &xferCRC, "Data\\INI\\Default\\Upgrade.ini", "Data\\INI\\Upgrade.ini");// An upgrade parsed again is edited in place, so this file names only what changesini.load( AsciiString( "Data\\INI\\UpgradeReforged.ini" ), INI_LOAD_MULTIFILE, &xferCRC );initSubsystem(TheGameClient,"TheGameClient", createGameClient(), NULL);@@ -1191,10 +1246,10 @@ void GameEngine::init( int argc, char *argv[] )#endif/////////////////////////////////////////////////////////////////////////////////////////////- initSubsystem(TheAI,"TheAI", MSGNEW("GameEngineSubsystem") AI(), &xferCRC, "Data\\INI\\Default\\AIData.ini", "Data\\INI\\AIData.ini");+ initRetailSubsystem(TheAI,"TheAI", MSGNEW("GameEngineSubsystem") AI(), &xferCRC, "Data\\INI\\Default\\AIData.ini", "Data\\INI\\AIData.ini");initSubsystem(TheGameLogic,"TheGameLogic", createGameLogic(), NULL);initSubsystem(TheTeamFactory,"TheTeamFactory", MSGNEW("GameEngineSubsystem") TeamFactory(), NULL);- initSubsystem(TheCrateSystem,"TheCrateSystem", MSGNEW("GameEngineSubsystem") CrateSystem(), &xferCRC, "Data\\INI\\Default\\Crate.ini", "Data\\INI\\Crate.ini");+ initRetailSubsystem(TheCrateSystem,"TheCrateSystem", MSGNEW("GameEngineSubsystem") CrateSystem(), &xferCRC, "Data\\INI\\Default\\Crate.ini", "Data\\INI\\Crate.ini");initSubsystem(ThePlayerList,"ThePlayerList", MSGNEW("GameEngineSubsystem") PlayerList(), NULL);initSubsystem(TheRecorder,"TheRecorder", createRecorder(), NULL);initSubsystem(TheRadar,"TheRadar", createRadar(), NULL);@@ -1242,9 +1297,9 @@ void GameEngine::init( int argc, char *argv[] )// the control bar parses these without the checksum, and the AI builds and hunts from them- checksumFileContents( xferCRC, "Data\\INI\\Default\\CommandButton.ini" );- checksumFileContents( xferCRC, "Data\\INI\\CommandButton.ini" );- checksumFileContents( xferCRC, "Data\\INI\\CommandSet.ini" );+ checksumFactionFile( xferCRC, "Data\\INI\\Default\\CommandButton.ini", FALSE );+ checksumFactionFile( xferCRC, "Data\\INI\\CommandButton.ini", TRUE );+ checksumFactionFile( xferCRC, "Data\\INI\\CommandSet.ini", TRUE );checksumFileContents( xferCRC, "Data\\INI\\CommandSetReforged.ini" );checksumModels( xferCRC );@@ -2495,6 +2550,32 @@ static void updateHeadlessRun( void )}}+ // -modfactions: whose objects each side is made of, ten seconds in+ if (TheGlobalData->m_modFactions && frame == 300)+ {+ Int total[ MAX_PLAYER_COUNT ] = { 0 }, namespaced[ MAX_PLAYER_COUNT ] = { 0 };+ AsciiString example[ MAX_PLAYER_COUNT ];+ for (Object *obj = TheGameLogic->getFirstObject(); obj != NULL; obj = obj->getNextObject())+ {+ const Int index = obj->getControllingPlayer()->getPlayerIndex();+ ++total[ index ];+ if (strchr( obj->getTemplate()->getName().str(), '~' ) != NULL)+ {+ ++namespaced[ index ];+ if (example[ index ].isEmpty())+ example[ index ] = obj->getTemplate()->getName();+ }+ }+ for (Int i = 0; i < ThePlayerList->getPlayerCount() && i < MAX_PLAYER_COUNT; ++i)+ {+ Player *p = ThePlayerList->getNthPlayer( i );+ if (!p->isPlayableSide() || p->isPlayerObserver())+ continue;+ DEBUG_LOG(("MODNS frame %d player %d plays %s: %d objects, %d of them a mod's, e.g. %s\n", frame, i,+ p->getPlayerTemplate()->getName().str(), total[ i ], namespaced[ i ], example[ i ].str()));+ }+ }+/* A -video range that runs up to or past -maxframes keeps the run alive until its last picture isdrawn, which happens on the pass after the logic reaches that frame. */Int maxGameFrames = TheGlobalData->m_maxGameFrames;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 1e02dbfc9..9a3f8164b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -1105,6 +1105,7 @@ GlobalData::GlobalData()m_isBreakableMovie = FALSE;m_breakTheMovie = FALSE;+ m_modFactions = FALSE;setTimeOfDay( m_timeOfDay );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cppindex de2e8374e..471ccf1d4 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp@@ -41,6 +41,8 @@#include "Common/file.h"#include "Common/FileSystem.h"#include "Common/GameAudio.h"+#include "Common/GlobalData.h"+#include "Common/NameKeyGenerator.h"#include "Common/Science.h"#include "Common/StackDump.h" // g_LastErrorDump, see prepFile#include "Common/SpecialPower.h"@@ -433,6 +435,213 @@ void INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer )} // end load+//-------------------------------------------------------------------------------------------------+/** -modfactions: one pass of path per -mod, each seeing only its own files and reading its own names+ * with the mod's prefix. Without the switch this does nothing. */+//-------------------------------------------------------------------------------------------------+void INI::loadModPasses( const char *path, Xfer *pXfer, Bool directory )+{+ // the engine tests bring the control bar and the particle systems up without any GlobalData+ if (TheGlobalData == NULL || !TheGlobalData->m_modFactions)+ return;++ for (Int mod = 0; mod < (Int)TheGlobalData->m_mods.size(); ++mod)+ {+ TheFileSystem->setFocus( mod );+ TheModNamespace.setActive( mod );+ INI ini;+ if (directory)+ ini.loadDirectory( AsciiString( path ), TRUE, INI_LOAD_OVERWRITE, pXfer );+ else if (TheFileSystem->doesFileExist( path ))+ ini.load( AsciiString( path ), INI_LOAD_OVERWRITE, pXfer );+ TheModNamespace.setActive( -1 );+ TheFileSystem->setFocus( FILE_FOCUS_ALL );+ }+}++//-------------------------------------------------------------------------------------------------+// ModNamespace+//-------------------------------------------------------------------------------------------------+ModNamespace TheModNamespace;++const char *const ModNamespace::FactionFiles[] =+{+ "Data\\INI\\Science.ini", "Data\\INI\\PlayerTemplate.ini", "Data\\INI\\FXList.ini", "Data\\INI\\Weapon.ini",+ "Data\\INI\\ObjectCreationList.ini", "Data\\INI\\Locomotor.ini", "Data\\INI\\SpecialPower.ini",+ "Data\\INI\\DamageFX.ini", "Data\\INI\\Armor.ini", "Data\\INI\\Object", "Data\\INI\\Upgrade.ini",+ "Data\\INI\\CommandButton.ini", "Data\\INI\\CommandSet.ini", "Data\\INI\\ParticleSystem.ini",+ NULL+};++/// the block keywords whose second word is a name the mod defines+static const struct { const char *keyword; ModNameType type; } ModBlockTypes[] =+{+ { "Object", MODNAME_OBJECT }, { "ObjectReskin", MODNAME_OBJECT }, { "ChildObject", MODNAME_OBJECT },+ { "Weapon", MODNAME_WEAPON }, { "Armor", MODNAME_ARMOR }, { "DamageFX", MODNAME_DAMAGEFX },+ { "Upgrade", MODNAME_UPGRADE }, { "Science", MODNAME_SCIENCE }, { "SpecialPower", MODNAME_SPECIALPOWER },+ { "CommandSet", MODNAME_COMMANDSET }, { "CommandButton", MODNAME_COMMANDBUTTON }, { "FXList", MODNAME_FXLIST },+ { "ObjectCreationList", MODNAME_OCL }, { "ParticleSystem", MODNAME_PARTICLESYSTEM },+ { "Locomotor", MODNAME_LOCOMOTOR }, { "PlayerTemplate", MODNAME_PLAYERTEMPLATE },+};++void ModNamespace::scanMods( void )+{+ m_mods.assign( TheGlobalData->m_mods.size(), Names() );+ for (Int mod = 0; mod < (Int)m_mods.size(); ++mod)+ {+ TheFileSystem->setFocus( mod );+ FilenameList files;+ for (const char *const *path = FactionFiles; *path != NULL; ++path)+ {+ if (strstr( *path, ".ini" ) == NULL)+ {+ AsciiString dir( *path );+ dir.concat( '\\' );+ TheFileSystem->getFileListInDirectory( dir, "*.ini", files, TRUE );+ }+ else if (TheFileSystem->doesFileExist( *path ))+ {+ files.insert( AsciiString( *path ) );+ }+ }+ for (FilenameListIter it = files.begin(); it != files.end(); ++it)+ {+ File *file = TheFileSystem->openFile( it->str(), File::READ );+ const Int size = file->size();+ char *contents = file->readEntireAndClose();+ std::string text( contents, size );+ delete [] contents;+ for (size_t start = 0; start < text.size(); )+ {+ size_t end = text.find( '\n', start );+ if (end == std::string::npos)+ end = text.size();+ scanLine( mod, text.substr( start, end - start ).c_str() );+ start = end + 1;+ }+ }+ finishScan( mod );+ TheFileSystem->setFocus( FILE_FOCUS_ALL );++ const Names &names = m_mods[ mod ];+ DEBUG_LOG(( "MODNS M%d~ is '%s': %d names from %d files, %d objects, %d weapons, %d upgrades, %d sciences, %d player templates\n",+ mod + 1, TheGlobalData->m_modNames[ mod ].str(), (Int)names.all.size(), (Int)files.size(),+ (Int)names.byType[ MODNAME_OBJECT ].size(), (Int)names.byType[ MODNAME_WEAPON ].size(),+ (Int)names.byType[ MODNAME_UPGRADE ].size(), (Int)names.byType[ MODNAME_SCIENCE ].size(),+ (Int)names.byType[ MODNAME_PLAYERTEMPLATE ].size() ));+ }+}++void ModNamespace::scanLine( Int mod, const char *line )+{+ static const char *SPACE = " \t\r\n";+ static const char *WORD_END = " \t\r\n=";+ std::string text( line );+ const size_t comment = text.find( ';' );+ if (comment != std::string::npos)+ text.erase( comment );++ const size_t keywordAt = text.find_first_not_of( SPACE );+ if (keywordAt == std::string::npos)+ return;+ const size_t keywordEnd = text.find_first_of( WORD_END, keywordAt );+ if (keywordEnd == std::string::npos)+ return;+ const std::string keyword = text.substr( keywordAt, keywordEnd - keywordAt );+ size_t nameAt = text.find_first_not_of( SPACE, keywordEnd );+ if (nameAt == std::string::npos)+ return;++ if ((Int)m_mods.size() <= mod)+ m_mods.resize( mod + 1 );+ Names &names = m_mods[ mod ];+ if (keyword == "Side" || keyword == "BaseSide")+ {+ if (text[ nameAt ] == '=')+ nameAt = text.find_first_not_of( SPACE, nameAt + 1 );+ if (nameAt != std::string::npos)+ names.sides.insert( text.substr( nameAt, text.find_first_of( WORD_END, nameAt ) - nameAt ) );+ return;+ }+ // "Weapon = PRIMARY X" is a field, "Weapon X" a definition+ if (text[ nameAt ] == '=')+ return;++ for (size_t i = 0; i < ARRAY_SIZE( ModBlockTypes ); ++i)+ {+ if (keyword == ModBlockTypes[ i ].keyword)+ {+ const std::string name = text.substr( nameAt, text.find_first_of( WORD_END, nameAt ) - nameAt );+ names.all.insert( name );+ names.byType[ ModBlockTypes[ i ].type ].insert( name );+ return;+ }+ }+}++void ModNamespace::finishScan( Int mod )+{+ // a side is compared as text everywhere (Side = GLA), and The End of Days names a CommandSet "GLA"+ Names &names = m_mods[ mod ];+ for (std::set<std::string>::const_iterator it = names.sides.begin(); it != names.sides.end(); ++it)+ names.all.erase( *it );+}++Bool ModNamespace::rewriteLine( char *line, size_t capacity ) const+{+ const Names &names = m_mods[ m_active ];+ char prefix[ 16 ];+ snprintf( prefix, sizeof( prefix ), "M%d~", m_active + 1 );++ // INI's own separators; readLine has already turned every other control character into a space+ std::string out;+ Bool first = TRUE;+ for (const char *p = line; *p != 0; )+ {+ if (*p == ' ' || *p == '=')+ {+ out += *p++;+ continue;+ }+ const char *start = p;+ while (*p != 0 && *p != ' ' && *p != '=')+ ++p;+ const std::string word( start, p - start );+ if (!first && names.all.count( word ) != 0)+ out += prefix;+ out += word;+ first = FALSE;+ }+ if (out.size() >= capacity)+ return FALSE;+ memcpy( line, out.c_str(), out.size() + 1 );+ return TRUE;+}++Bool ModNamespace::findRetailName( const AsciiString &name, ModNameType type, AsciiString *retailName ) const+{+ const char *text = name.str();+ if (m_mods.empty() || text[ 0 ] != 'M')+ return FALSE;+ char *tilde = NULL;+ const long mod = strtol( text + 1, &tilde, 10 );+ if (tilde == text + 1 || *tilde != '~' || mod < 1 || mod > (long)m_mods.size())+ return FALSE;+ if (m_mods[ mod - 1 ].byType[ type ].count( tilde + 1 ) != 0)+ return FALSE;+ *retailName = tilde + 1;+ return TRUE;+}++Bool ModNamespace::findRetailKey( NameKeyType key, ModNameType type, NameKeyType *retailKey ) const+{+ AsciiString retailName;+ if (m_mods.empty() || !findRetailName( TheNameKeyGenerator->keyToName( key ), type, &retailName ))+ return FALSE;+ *retailKey = TheNameKeyGenerator->nameToKey( retailName );+ return TRUE;+}+//-------------------------------------------------------------------------------------------------/** Read a line from the already open file. Any comments will be remved and* therefore ignored from any given line */@@ -498,6 +707,14 @@ void INI::readLine( void )} // end if}+ // -modfactions: the mod's own names, before the checksum below reads the line+ if (TheModNamespace.getActive() >= 0 && !TheModNamespace.rewriteLine(m_buffer, sizeof(m_buffer)))+ {+ g_LastErrorDump.format("INI::readLine: line %d of '%s' is too long once its mod names are prefixed\n", m_lineNum, m_filename.str());+ DEBUG_LOG(("%s", g_LastErrorDump.str()));+ throw INI_BUFFER_TOO_SMALL;+ }+if (s_xfer){s_xfer->xferUser( m_buffer, sizeof( char ) * strlen( m_buffer ) );diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cppindex b3d42752b..4fd8fc38b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp@@ -197,6 +197,7 @@ AsciiString PlayerTemplate::getStartingUnit( Int i ) const//-----------------------------------------------------------------------------PlayerTemplate::PlayerTemplate() :m_nameKey(NAMEKEY_INVALID),+ m_modIndex(-1),m_observer(false),m_playableSide(false),m_oldFaction(false),@@ -355,7 +356,8 @@ const PlayerTemplate* PlayerTemplateStore::findPlayerTemplate(NameKeyType namekeif ((*it).getNameKey() == namekey)return &(*it);}- return NULL;+ NameKeyType retailKey;+ return TheModNamespace.findRetailKey(namekey, MODNAME_PLAYERTEMPLATE, &retailKey) ? findPlayerTemplate(retailKey) : NULL;}//-----------------------------------------------------------------------------@@ -423,6 +425,7 @@ void PlayerTemplateStore::getAllSideStrings(AsciiStringList *outStringList)PlayerTemplate npt;ini->initFromINI( &npt, npt.getFieldParse() );npt.setNameKey(namekey);+ npt.setModIndex(TheModNamespace.getActive());ThePlayerTemplateStore->m_playerTemplates.push_back(npt);}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Science.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Science.cppindex 927168e12..e76a4aab3 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Science.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Science.cpp@@ -95,6 +95,10 @@ ScienceType ScienceStore::getScienceFromInternalName(const AsciiString& name) co{if (name.isEmpty())return SCIENCE_INVALID;+ // a science is its name's key, found or not, so the -modfactions retail fallback is asked every time+ AsciiString retailName;+ if (TheModNamespace.findRetailName(name, MODNAME_SCIENCE, &retailName))+ return getScienceFromInternalName(retailName);NameKeyType nkt = TheNameKeyGenerator->nameToKey(name);ScienceType st = (ScienceType)nkt;return st;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/SpecialPower.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/SpecialPower.cppindex 902256e65..2e4553b8c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/SpecialPower.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/SpecialPower.cpp@@ -280,6 +280,9 @@ SpecialPowerTemplate* SpecialPowerStore::findSpecialPowerTemplatePrivate( AsciiSif( m_specialPowerTemplates[ i ]->getName() == name )return m_specialPowerTemplates[ i ];+ AsciiString retailName;+ if( TheModNamespace.findRetailName( name, MODNAME_SPECIALPOWER, &retailName ) )+ return findSpecialPowerTemplatePrivate( retailName );return NULL; // not found}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cppindex ecc2101b5..6ace26dd2 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp@@ -111,7 +111,7 @@ ArchiveFileSystem *TheArchiveFileSystem = NULL;//------------------------------------------------------// ArchivedFileInfo//-------------------------------------------------------ArchiveFileSystem::ArchiveFileSystem()+ArchiveFileSystem::ArchiveFileSystem() : m_focus( FILE_FOCUS_ALL ){}@@ -129,6 +129,11 @@ ArchiveFileSystem::~ArchiveFileSystem()}void ArchiveFileSystem::loadIntoDirectoryTree(const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite)+{+ addToTree(m_rootDirectory, archiveFile, archiveFilename, overwrite);+}++void ArchiveFileSystem::addToTree(ArchivedDirectoryInfo &root, const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite){FilenameList filenameList;@@ -144,7 +149,7 @@ void ArchiveFileSystem::loadIntoDirectoryTree(const ArchiveFile *archiveFile, coAsciiString token;AsciiString debugpath;- ArchivedDirectoryInfo *dirInfo = &m_rootDirectory;+ ArchivedDirectoryInfo *dirInfo = &root;Bool infoInPath;infoInPath = path.nextToken(&token, "\\/");@@ -201,6 +206,10 @@ void ArchiveFileSystem::loadMods() {forkArt.push_back(it->first);}+ // -modfactions loads retail's factions and each mod's from their own files (FileSystem::setFocus)+ if (TheGlobalData->m_modFactions)+ 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.for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i)@@ -226,8 +235,7 @@ void ArchiveFileSystem::loadMods() {continue;}DEBUG_LOG(("ArchiveFileSystem::loadMods - loading %s into the directory tree.\n", it->str()));- loadIntoDirectoryTree(archiveFile, *it, TRUE);- m_archiveFileMap[*it] = archiveFile;+ addModArchive((Int)i, archiveFile, *it);}}@@ -238,17 +246,50 @@ void ArchiveFileSystem::loadMods() {}}+void ArchiveFileSystem::keepModsApart(size_t modCount)+{+ m_retailRoot = m_rootDirectory;+ m_modRoots.assign(modCount, ArchivedDirectoryInfo());+}++void ArchiveFileSystem::addModArchive(Int mod, ArchiveFile *archiveFile, const AsciiString& archiveFilename)+{+ loadIntoDirectoryTree(archiveFile, archiveFilename, TRUE);+ m_archiveFileMap[archiveFilename] = archiveFile;+ if (m_modRoots.empty())+ return;+ addToTree(m_modRoots[mod], archiveFile, archiveFilename, TRUE);+ m_archiveMod[archiveFilename] = mod;+}++const ArchivedDirectoryInfo &ArchiveFileSystem::focusedRoot() const+{+ if (m_focus == FILE_FOCUS_ALL)+ return m_rootDirectory;+ if (m_focus == FILE_FOCUS_RETAIL)+ return m_retailRoot;+ return m_modRoots[m_focus];+}++Bool ArchiveFileSystem::inFocus(const AsciiString& archiveFilename) const+{+ if (m_focus == FILE_FOCUS_ALL)+ return TRUE;+ std::map<AsciiString, Int>::const_iterator it = m_archiveMod.find(archiveFilename);+ return (it == m_archiveMod.end() ? FILE_FOCUS_RETAIL : it->second) == m_focus;+}+Bool ArchiveFileSystem::doesFileExist(const Char *filename) const{AsciiString path = filename;path.toLower();AsciiString token;- const ArchivedDirectoryInfo *dirInfo = &m_rootDirectory;+ const ArchivedDirectoryInfo *dirInfo = &focusedRoot();path.nextToken(&token, "\\/");- while (!token.find('.') || path.find('.'))+ while (!token.find('.') || path.find('.')){ArchivedDirectoryInfoMap::const_iterator tempiter = dirInfo->m_directories.find(token);if (tempiter != dirInfo->m_directories.end())@@ -377,7 +418,7 @@ AsciiString ArchiveFileSystem::getArchiveFilenameForFile(const AsciiString& fileAsciiString token;AsciiString debugpath;- const ArchivedDirectoryInfo *dirInfo = &m_rootDirectory;+ const ArchivedDirectoryInfo *dirInfo = &focusedRoot();path.nextToken(&token, "\\/");@@ -426,7 +467,8 @@ void ArchiveFileSystem::getFileListInDirectory(const AsciiString& currentDirecto{ArchiveFileMap::const_iterator it = m_archiveFileMap.begin();while (it != m_archiveFileMap.end()) {- it->second->getFileListInDirectory(currentDirectory, originalDirectory, searchName, filenameList, searchSubdirectories);+ if (inFocus(it->first))+ it->second->getFileListInDirectory(currentDirectory, originalDirectory, searchName, filenameList, searchSubdirectories);it++;}}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cppindex 80cd29ef5..1f9e23298 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp@@ -135,11 +135,41 @@ FileSystem *TheFileSystem = NULL;// FileSystem::FileSystem//============================================================================+Int FileSystem::s_focus = FILE_FOCUS_ALL;+FileSystem::FileSystem(){}+//============================================================================+// FileSystem::setFocus+//============================================================================++void FileSystem::setFocus( Int focus )+{+ s_focus = focus;+ TheArchiveFileSystem->setFocus( focus );+}++//============================================================================+// FileSystem::focusedLooseFile+//============================================================================++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+ if (s_focus == FILE_FOCUS_RETAIL)+ return TheLocalFileSystem->doesFileExist( filename.str() ) ? filename : AsciiString();++ const AsciiString &mod = TheGlobalData->m_mods[ s_focus ];+ if (!mod.endsWith( "\\" ) && !mod.endsWith( "/" ))+ return AsciiString();+ AsciiString path = mod;+ path.concat( filename );+ return TheLocalFileSystem->doesFileExist( path.str() ) ? path : AsciiString();+}+//============================================================================// FileSystem::~FileSystem//============================================================================@@ -218,9 +248,18 @@ File* FileSystem::openFile( const Char *filename, Int access )return NULL;}+ const Bool readOnly = (access & (File::WRITE | File::CREATE | File::APPEND | File::TRUNCATE)) == 0;+ if ( readOnly && s_focus != FILE_FOCUS_ALL )+ {+ AsciiString loose = focusedLooseFile( AsciiString( filename ) );+ if ( loose.isNotEmpty() )+ return TheLocalFileSystem->openFile( loose.str(), access );+ return TheArchiveFileSystem->openFile( filename, access );+ }+// 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 )+ if ( readOnly ){Bool inModArchive = FALSE;AsciiString modded = modLooseFile( AsciiString( filename ), &inModArchive );@@ -269,6 +308,10 @@ Bool FileSystem::doesFileExist(const Char *filename) constif (isGeneratedMapPath( AsciiString( filename ) ))return TRUE;+ // the cache is the merged view's; a focus asks its own files every time (setFocus)+ if (s_focus != FILE_FOCUS_ALL)+ return focusedLooseFile( AsciiString( filename ) ).isNotEmpty() || TheArchiveFileSystem->doesFileExist( filename );+unsigned key=TheNameKeyGenerator->nameToLowercaseKey(filename);std::map<unsigned,bool>::iterator i=m_fileExist.find(key);if (i!=m_fileExist.end())@@ -295,18 +338,26 @@ Bool FileSystem::doesFileExist(const Char *filename) constvoid FileSystem::getFileListInDirectory(const AsciiString& directory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const{USE_PERF_TIMER(FileSystem)- TheLocalFileSystem->getFileListInDirectory(AsciiString(""), directory, searchName, filenameList, searchSubdirectories);+ // a mod's focus does not see Run's own loose files, retail's sees no mod's (setFocus)+ if (s_focus < 0)+ {+ 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))+ if (TheGlobalData == NULL || isAbsolutePath(directory) || s_focus == FILE_FOCUS_RETAIL){return;}for (size_t i = 0; i < TheGlobalData->m_mods.size(); ++i){const AsciiString &modDir = TheGlobalData->m_mods[i];+ if (s_focus >= 0 && (Int)i != s_focus)+ {+ continue;+ }if (!modDir.endsWith("\\") && !modDir.endsWith("/")){continue; // a .big, already in the archive tree@@ -435,6 +486,14 @@ Bool FileSystem::getFileInfo(const AsciiString& filename, FileInfo *fileInfo) coreturn TRUE;}+ if (s_focus != FILE_FOCUS_ALL) {+ AsciiString loose = focusedLooseFile(filename);+ if (loose.isNotEmpty()) {+ return TheLocalFileSystem->getFileInfo(loose, fileInfo);+ }+ return TheArchiveFileSystem->getFileInfo(filename, fileInfo);+ }+Bool inModArchive = FALSE;AsciiString modded = modLooseFile(filename, &inModArchive);if (modded.isNotEmpty()) {diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cppindex ecc31731d..fefc09e47 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp@@ -374,6 +374,9 @@ const UpgradeTemplate *UpgradeCenter::findUpgradeByKey( NameKeyType key ) constif( upgrade->getUpgradeNameKey() == key )return upgrade;+ NameKeyType retailKey;+ if( TheModNamespace.findRetailKey( key, MODNAME_UPGRADE, &retailKey ) )+ return findUpgradeByKey( retailKey );// item not foundreturn NULL;}@@ -393,6 +396,12 @@ const UpgradeTemplate *UpgradeCenter::findUpgrade( const AsciiString& name ) con//-------------------------------------------------------------------------------------------------UpgradeTemplate *UpgradeCenter::newUpgrade( const AsciiString& name ){+ // every upgrade is one bit of UpgradeMaskType; -modfactions puts every mod's beside retail's+ if( m_nextTemplateMaskBit >= UPGRADE_MAX_COUNT )+ {+ DEBUG_LOG(( "Upgrade %s would be upgrade number %d, and UPGRADE_MAX_COUNT is %d\n", name.str(), m_nextTemplateMaskBit + 1, UPGRADE_MAX_COUNT ));+ throw INI_INVALID_DATA;+ }UpgradeTemplate *newUpgrade = newInstance(UpgradeTemplate);// copy data from the default upgrade@@ -410,7 +419,6 @@ UpgradeTemplate *UpgradeCenter::newUpgrade( const AsciiString& name )newMask.set( m_nextTemplateMaskBit );//Int64 newMask = 1i64 << m_nextTemplateMaskBit;m_nextTemplateMaskBit++;- DEBUG_ASSERTCRASH( m_nextTemplateMaskBit < UPGRADE_MAX_COUNT, ("Can't have over %d types of Upgrades and have a Bitfield function.", UPGRADE_MAX_COUNT) );newUpgrade->friend_setUpgradeMask( newMask );// link upgradediff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cppindex d826238e1..759dea87f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp@@ -289,6 +289,10 @@ ThingTemplate *ThingFactory::findTemplateInternal( const AsciiString& name, Boolreturn tIt->second;}+ AsciiString retailName;+ if (TheModNamespace.findRetailName(name, MODNAME_OBJECT, &retailName))+ return findTemplateInternal(retailName, check);+#ifdef LOAD_TEST_ASSETSif (!strncmp(name.str(), TEST_STRING, strlen(TEST_STRING))){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cppindex ab9d38181..079353465 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp@@ -910,7 +910,8 @@ const FXList *FXListStore::findFXList(const char* name) const{return &(*it).second;}- return NULL;+ AsciiString retailName;+ return TheModNamespace.findRetailName(AsciiString(name), MODNAME_FXLIST, &retailName) ? findFXList(retailName.str()) : NULL;}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex bf36e9217..20c60458a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -2836,12 +2836,20 @@ void ControlBar::init( void ){INI ini;m_sideSelectAnimateDown = FALSE;+ // -modfactions: retail's own buttons and sets first, then each mod's under its names+ const Bool apart = TheGlobalData != NULL && TheGlobalData->m_modFactions;+ if (apart)+ TheFileSystem->setFocus( FILE_FOCUS_RETAIL );// load the command buttonsini.load( AsciiString( "Data\\INI\\Default\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );ini.load( AsciiString( "Data\\INI\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );// load the command setsini.load( AsciiString( "Data\\INI\\CommandSet.ini" ), INI_LOAD_OVERWRITE, NULL );+ if (apart)+ TheFileSystem->setFocus( FILE_FOCUS_ALL );+ INI::loadModPasses( "Data\\INI\\CommandButton.ini", NULL );+ INI::loadModPasses( "Data\\INI\\CommandSet.ini", NULL );// the fork's corrections to EA's buttons and sets, edited in place; GameEngine::init checksums itini.load( AsciiString( "Data\\INI\\CommandSetReforged.ini" ), INI_LOAD_MULTIFILE, NULL );@@ -4031,6 +4039,9 @@ CommandButton *ControlBar::findNonConstCommandButton( const AsciiString& name )if( command->getName() == name )return const_cast<CommandButton*>((const CommandButton*)command->getFinalOverride());+ AsciiString retailName;+ if( TheModNamespace.findRetailName( name, MODNAME_COMMANDBUTTON, &retailName ) )+ return findNonConstCommandButton( retailName );return NULL; // not found} // end findCommandButton@@ -4140,6 +4151,9 @@ CommandSet* ControlBar::findNonConstCommandSet( const AsciiString& name )if( set->getName() == name )return const_cast<CommandSet*>((const CommandSet *) set);+ AsciiString retailName;+ if( TheModNamespace.findRetailName( name, MODNAME_COMMANDSET, &retailName ) )+ return findNonConstCommandSet( retailName );return NULL; // set not found}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cppindex 4eebedcc0..19d6b46d1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp@@ -33,6 +33,7 @@#define DEFINE_PARTICLE_SYSTEM_NAMES+#include "Common/FileSystem.h"#include "Common/GameState.h"#include "Common/INI.h"#include "Common/PerfTimer.h"@@ -3506,7 +3507,14 @@ void ParticleSystemManager::init( void ){/// Read INI data and build templatesINI ini;+ // -modfactions: retail's own systems first, then each mod's under its names+ const Bool apart = TheGlobalData != NULL && TheGlobalData->m_modFactions;+ if (apart)+ TheFileSystem->setFocus( FILE_FOCUS_RETAIL );ini.load( AsciiString( "Data\\INI\\ParticleSystem.ini" ), INI_LOAD_OVERWRITE, NULL );+ if (apart)+ TheFileSystem->setFocus( FILE_FOCUS_ALL );+ INI::loadModPasses( "Data\\INI\\ParticleSystem.ini", NULL );// The fork's own systems, beside EA's 1088 rather than in a loose copy of all of themini.load( AsciiString( "Data\\INI\\ParticleSystemReforged.ini" ), INI_LOAD_OVERWRITE, NULL );@@ -3761,6 +3769,11 @@ ParticleSystemTemplate *ParticleSystemManager::findTemplate( const AsciiString &if (find != m_templateMap.end()) {sysTemplate = (*find).second;}+ else {+ AsciiString retailName;+ if (TheModNamespace.findRetailName(name, MODNAME_PARTICLESYSTEM, &retailName))+ sysTemplate = findTemplate(retailName);+ }return sysTemplate;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cppindex 682fb1d35..8fee73c76 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp@@ -122,9 +122,10 @@ const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const{NameKeyType namekey = TheNameKeyGenerator->nameToKey(name);ArmorTemplateMap::const_iterator it = m_armorTemplates.find(namekey);- if (it == m_armorTemplates.end())+ if (it == m_armorTemplates.end()){- return NULL;+ AsciiString retailName;+ return TheModNamespace.findRetailName(name, MODNAME_ARMOR, &retailName) ? findArmorTemplate(retailName) : NULL;}else{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cppindex 50338e5d4..dd53dd940 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp@@ -655,8 +655,11 @@ LocomotorTemplate* LocomotorStore::findLocomotorTemplate(NameKeyType namekey)return NULL;LocomotorTemplateMap::iterator it = m_locomotorTemplates.find(namekey);- if (it == m_locomotorTemplates.end())- return NULL;+ if (it == m_locomotorTemplates.end())+ {+ NameKeyType retailKey;+ return TheModNamespace.findRetailKey(namekey, MODNAME_LOCOMOTOR, &retailKey) ? findLocomotorTemplate(retailKey) : NULL;+ }elsereturn (*it).second;}@@ -668,9 +671,10 @@ const LocomotorTemplate* LocomotorStore::findLocomotorTemplate(NameKeyType namekreturn NULL;LocomotorTemplateMap::const_iterator it = m_locomotorTemplates.find(namekey);- if (it == m_locomotorTemplates.end())+ if (it == m_locomotorTemplates.end()){- return NULL;+ NameKeyType retailKey;+ return TheModNamespace.findRetailKey(namekey, MODNAME_LOCOMOTOR, &retailKey) ? findLocomotorTemplate(retailKey) : NULL;}else{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cppindex 25f58e9d6..1d0f95ddb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp@@ -1615,9 +1615,10 @@ const ObjectCreationList *ObjectCreationListStore::findObjectCreationList(constreturn NULL;ObjectCreationListMap::const_iterator it = m_ocls.find(NAMEKEY(name));- if (it == m_ocls.end())+ if (it == m_ocls.end()){- return NULL;+ AsciiString retailName;+ return TheModNamespace.findRetailName(AsciiString(name), MODNAME_OCL, &retailName) ? findObjectCreationList(retailName.str()) : NULL;}else{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex 514a249f3..cae880898 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -1648,6 +1648,9 @@ WeaponTemplate *WeaponStore::findWeaponTemplatePrivate( NameKeyType key ) constif( it != m_weaponTemplateHashMap.end() )return it->second;+ NameKeyType retailKey;+ if( TheModNamespace.findRetailKey( key, MODNAME_WEAPON, &retailKey ) )+ return findWeaponTemplatePrivate( retailKey );return NULL;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cppindex dda75ec50..bfffa10a6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp@@ -48,6 +48,8 @@#include "Common/PlayerTemplate.h"#include "GameNetwork/LANAPICallbacks.h" // for acceptTrueColor, etc#include "GameClient/ChallengeGenerals.h"+#include "Common/GlobalData.h"+#include "Lib/WideCharFns.h"#ifdef _INTERNAL// for occasional debugging...@@ -326,12 +328,25 @@ void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameAsciiString side;side.format("SIDE:%s", fac->getSide().str());- if (seenSides.find(side) != seenSides.end())+ // -modfactions: each mod's America is a side of its own, "<mod name> - USA"+ AsciiString seenKey;+ seenKey.format("%d:%s", fac->getModIndex(), side.str());+ if (seenSides.find(seenKey) != seenSides.end())continue;- seenSides.insert(side);+ seenSides.insert(seenKey);- newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], TheGameText->fetch(side), def->getColor());+ UnicodeString label = TheGameText->fetch(side);+ if (fac->getModIndex() >= 0)+ {+ WideChar modName[128];+ WideCharFromUtf8(TheGlobalData->m_modNames[fac->getModIndex()].str(), modName, ARRAY_SIZE(modName));+ UnicodeString sideLabel = label;+ label = UnicodeString(modName);+ label.concat(UnicodeString(u" - "));+ label.concat(sideLabel);+ }+ newIndex = GadgetComboBoxAddEntry(comboArray[comboBox], label, def->getColor());GadgetComboBoxSetItemData(comboArray[comboBox], newIndex, (void *)(intptr_t)c);}seenSides.clear();diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex a937344e3..5c92c3c59 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -29,6 +29,8 @@#include "Common/LocalFileSystem.h"#include "Common/LocalFile.h"#include "Common/INI.h"+#include "Common/ArchiveFile.h"+#include "Common/ArchiveFileSystem.h"#include "Common/INIException.h"#include "Common/STLTypedefs.h"#include "Common/DataChunk.h"@@ -17174,6 +17176,134 @@ TEST(every_shipped_master_is_fork_owned_and_retail_files_are_not)CHECK(!FileSystem::isForkOwnedPath(AsciiString("Art\\Textures\\AVPaladin.tga")));}+// -modfactions: a mod's own names get its prefix everywhere but the line's first word, a name it does+// not define stays retail's, and a side name stays text even when the mod also calls a block that.+TEST(modfactions_prefix_only_the_mods_own_names)+{+ bootOnce();+ ModNamespace names;+ names.scanLine( 0, "Object AmericaRanger ; the mod's own" );+ names.scanLine( 0, "Weapon RangerGun" );+ names.scanLine( 0, " Weapon = PRIMARY RetailGun" ); // a field, not a definition+ names.scanLine( 0, "CommandSet GLA CommandSet" ); // The End of Days really has this line+ names.scanLine( 0, " Side = GLA" );+ names.finishScan( 0 );+ names.setActive( 0 );++ char line[ 64 ];+ strcpy( line, "Object AmericaRanger" );+ CHECK( names.rewriteLine( line, sizeof( line ) ) );+ CHECK_STR( line, "Object M1~AmericaRanger" );+ strcpy( line, " Weapon = PRIMARY RangerGun" );+ CHECK( names.rewriteLine( line, sizeof( line ) ) );+ CHECK_STR( line, " Weapon = PRIMARY M1~RangerGun" );+ strcpy( line, " Weapon = SECONDARY RetailGun" );+ CHECK( names.rewriteLine( line, sizeof( line ) ) );+ CHECK_STR( line, " Weapon = SECONDARY RetailGun" );+ strcpy( line, " Side = GLA" );+ CHECK( names.rewriteLine( line, sizeof( line ) ) );+ CHECK_STR( line, " Side = GLA" );+ strcpy( line, "RangerGun = RangerGun" ); // the first word is the field+ CHECK( names.rewriteLine( line, sizeof( line ) ) );+ CHECK_STR( line, "RangerGun = M1~RangerGun" );+ strcpy( line, "Object AmericaRanger" );+ CHECK( !names.rewriteLine( line, 23 ) ); // "Object M1~AmericaRanger" needs 24+ CHECK_STR( line, "Object AmericaRanger" );++ // a finder's miss: the mod's own name stays a miss, anything else is retail's+ AsciiString retail;+ CHECK( !names.findRetailName( AsciiString( "M1~AmericaRanger" ), MODNAME_OBJECT, &retail ) );+ CHECK( names.findRetailName( AsciiString( "M1~RangerGun" ), MODNAME_OBJECT, &retail ) );+ CHECK_STR( retail.str(), "RangerGun" );+ CHECK( !names.findRetailName( AsciiString( "M1~RangerGun" ), MODNAME_WEAPON, &retail ) );+ CHECK( !names.findRetailName( AsciiString( "M2~AmericaRanger" ), MODNAME_OBJECT, &retail ) ); // no second mod+ CHECK( !names.findRetailName( AsciiString( "AmericaRanger" ), MODNAME_OBJECT, &retail ) );+ NameKeyType key;+ CHECK( names.findRetailKey( NAMEKEY( "M1~Upgrade_Retail" ), MODNAME_UPGRADE, &key ) );+ CHECK_EQ( key, NAMEKEY( "Upgrade_Retail" ) );+}++class ModTestArchiveFile : public ArchiveFile+{+public:+ ModTestArchiveFile() { m_file = NULL; } // the base leaves it to the device's archive to set+ void add( const char *directory, const char *file )+ {+ ArchivedFileInfo info;+ info.m_filename = file;+ addFile( AsciiString( directory ), &info );+ }+ virtual Bool getFileInfo( const AsciiString&, FileInfo* ) const { return FALSE; }+ virtual File* openFile( const Char*, Int ) { return NULL; }+ virtual void closeAllFiles( void ) {}+ virtual AsciiString getName( void ) { return AsciiString::TheEmptyString; }+ virtual AsciiString getPath( void ) { return AsciiString::TheEmptyString; }+ virtual void setSearchPriority( Int ) {}+ virtual void close( void ) {}+};++class ModTestArchiveFileSystem : public ArchiveFileSystem+{+public:+ virtual void init( void ) {}+ virtual void update( void ) {}+ virtual void reset( void ) {}+ virtual void postProcessLoad( void ) {}+ virtual ArchiveFile* openArchiveFile( const Char* ) { return NULL; }+ virtual void closeArchiveFile( const Char* ) {}+ virtual void closeAllArchiveFiles( void ) {}+ virtual void closeAllFiles( void ) {}+ virtual Bool loadBigFilesFromDirectory( AsciiString, AsciiString, Bool, Bool ) { return FALSE; }++ void addRetail( ArchiveFile *archive, const char *name )+ {+ loadIntoDirectoryTree( archive, AsciiString( name ) );+ m_archiveFileMap[ AsciiString( name ) ] = archive;+ }+ using ArchiveFileSystem::keepModsApart;+ using ArchiveFileSystem::addModArchive;+};++// -modfactions' focus: retail sees the tree from before any -mod, a mod its own archives, nothing else+TEST(modfactions_focus_sees_one_set_of_archives)+{+ bootOnce();+ ModTestArchiveFileSystem archives;+ ModTestArchiveFile *retail = new ModTestArchiveFile, *one = new ModTestArchiveFile, *two = new ModTestArchiveFile;+ retail->add( "data\\ini\\", "weapon.ini" );+ retail->add( "data\\ini\\object\\", "a.ini" );+ one->add( "data\\ini\\", "weapon.ini" );+ one->add( "data\\ini\\object\\", "b.ini" );+ two->add( "data\\ini\\object\\", "c.ini" );+ archives.addRetail( retail, "INIZH.big" );+ archives.keepModsApart( 2 );+ archives.addModArchive( 0, one, AsciiString( "Mods\\One\\!one.big" ) );+ archives.addModArchive( 1, two, AsciiString( "Mods\\Two\\!two.big" ) );++ const AsciiString weapon( "Data\\INI\\Weapon.ini" );+ CHECK_STR( archives.getArchiveFilenameForFile( weapon ).str(), "Mods\\One\\!one.big" ); // merged: the mod wins+ archives.setFocus( FILE_FOCUS_RETAIL );+ CHECK_STR( archives.getArchiveFilenameForFile( weapon ).str(), "INIZH.big" );+ archives.setFocus( 0 );+ CHECK_STR( archives.getArchiveFilenameForFile( weapon ).str(), "Mods\\One\\!one.big" );+ archives.setFocus( 1 );+ CHECK( !archives.doesFileExist( weapon.str() ) );++ FilenameList listed;+ archives.getFileListInDirectory( AsciiString( "" ), AsciiString( "Data\\INI\\Object\\" ), AsciiString( "*.ini" ), listed, TRUE );+ CHECK_EQ( (Int)listed.size(), 1 );+ CHECK( listed.begin()->endsWithNoCase( "c.ini" ) );+ listed.clear();+ archives.setFocus( FILE_FOCUS_RETAIL );+ archives.getFileListInDirectory( AsciiString( "" ), AsciiString( "Data\\INI\\Object\\" ), AsciiString( "*.ini" ), listed, TRUE );+ CHECK_EQ( (Int)listed.size(), 1 );+ CHECK( listed.begin()->endsWithNoCase( "a.ini" ) );+ listed.clear();+ archives.setFocus( FILE_FOCUS_ALL );+ archives.getFileListInDirectory( AsciiString( "" ), AsciiString( "Data\\INI\\Object\\" ), AsciiString( "*.ini" ), listed, TRUE );+ CHECK_EQ( (Int)listed.size(), 3 );+}+#include "test_minimap_input.inc"#include "test_selection_priority.inc"#include "test_widechar_width.inc"