Skip to content

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

fix(gameengine): keep our interface over a merged mod's

Olcay Seygan8b22dacbc422
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab0f48f7e..6c70a9e80 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ found and fixed — EA's own, not port damage.**
- A mod is a folder now. Start the game with `-mod` and the folder, and the archives in it replace Zero Hour's files, as before, and so do the plain files under its `Data` and `Art` folders, which the game used to ignore. A modder can drop in one changed file without packing an archive first.
- Several mods run at once. Give `-mod` once for each, and where two of them change the same file, the one named later wins.
- Reforged stays on top of every mod. This build's balance, its fixes to EA's data, its AI and its menus load after the mod and win where they touch the same unit, weapon or button, so a mod plays with Reforged's rules. A change that names something the mod renamed or removed is passed over instead of stopping the game, which is how ShockWave starts and plays. A mod's own copy of a file Reforged ships, 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 no longer repaints the game around it. Shockwave Chaos set the whole skirmish lobby in Comic Sans, with its own yellow-edged boxes, loading bars, main menu backdrop and score screens, because its archives replaced the font list, the shell's image sheets and the pictures they are cut from. Every menu and lobby layout, the fonts, the shell's colours and frames and the in-match screens are ours now under any mod. The mod's units, their build pictures and its generals with their portraits still come from the mod, and its new generals still appear in the lobby's faction list.
- The maps stay Zero Hour's under every mod. A mod that carries its own maps, Contra among them, used to fill the skirmish and LAN map lists with them, and its edited copies of the stock maps replaced ours under the same names: picking Twilight Flame started Contra's Twilight Flame. The map list and every map you start are Zero Hour's and Reforged's now, whatever mods are loaded, so everyone in a lobby plays the same map.
- A `mod.json` in the folder names the mod and its version. The names stand beside the version number in the options menu, in the order the mods were given, and go into every replay you record, so a replay made with mods says which ones, and the replay list marks it as another version when the game is running without them.
- Joining a LAN game that runs different mods used to end in a box about a mismatch and nothing else. It names the host's mods now, or tells you the host plays without any.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h
index e06477175..d894d8612 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h
@@ -145,6 +145,10 @@ public:
};
+/// openFile reads a merged mod's own copy of one of our interface image sheets by this name in front of
+/// its path (getModUICopies)
+#define MOD_UI_COPY "ModUI~"
+
class ArchiveFileSystem : public SubsystemInterface
{
public:
@@ -186,11 +190,19 @@ class ArchiveFileSystem : public SubsystemInterface
Bool doesModFileExist( Int mod, const AsciiString& filename ) const;
Bool getModFileInfo( Int mod, const AsciiString& filename, FileInfo *fileInfo ) const;
+ /// a texture one of our interface image sheets names (FileSystem::isForkUIPath); a mod's copy never wins
+ Bool isOurUITexture( const AsciiString& filename ) const;
+ /// "ModUI~<path>" for each interface image sheet in directory that a merged mod brought its own copy
+ /// of: openFile reads the mod's copy by that name, so ImageCollection::load gets the images only the
+ /// mod has before ours take every name both define
+ void getModUICopies( const AsciiString& directory, std::vector<AsciiString> &names ) const;
+
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 collectUITextures( void ); ///< fills m_uiTextures before loadMods merges a mod in
void keepModsApart( size_t modCount ); ///< one tree per -mod, and the merged one left as retail's
void addModArchive( Int mod, ArchiveFile *archiveFile, const AsciiString& archiveFilename ); ///< over the merged tree, or into the mod's own when kept apart
const ArchivedDirectoryInfo & focusedRoot( void ) const;
@@ -202,6 +214,8 @@ protected:
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
std::map<AsciiString, AsciiString> m_archiveLayer; ///< archive -> the -mod or -modpatch path that loaded it (modLayerOf)
+ std::map<AsciiString, AsciiString> m_modUICopies; ///< lower-case interface image sheet -> the last mod archive with its own copy
+ std::set<AsciiString> m_uiTextures; ///< lower-case "art\textures\..." our interface image sheets name
Int m_focus;
};
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
index 8103dabde..4963899e1 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/FileSystem.h
@@ -150,6 +150,10 @@ public:
/// .wnd layouts ...); see the definition for how the set is decided.
static Bool isForkOwnedPath(const AsciiString& filename);
+ /// TRUE for a game path that draws the game's interface (a .wnd, Language.ini's fonts, the shell's
+ /// image sheets): a merged mod never replaces it, the copy retail or the fork has wins
+ static Bool isForkUIPath(const AsciiString& filename);
+
/// TRUE for a game path under "Maps\": the maps are always ours, a mod's own maps are never listed or
/// loaded, so every machine in a match reads the same map whatever mods it runs
static Bool isMapPath(const AsciiString& filename);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
index 0660464f7..ebd4b8449 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp
@@ -50,6 +50,7 @@
#include "Common/ArchiveFile.h"
#include "Common/ArchiveFileSystem.h"
#include "Common/AsciiString.h"
+#include "Common/file.h"
#include "Common/GlobalData.h"
#include "Common/LocalFileSystem.h"
#include "Common/PerfTimer.h"
@@ -143,6 +144,7 @@ void ArchiveFileSystem::addToTree(ArchivedDirectoryInfo &root, const ArchiveFile
// a mod's maps never go in, merged or kept apart: the maps are ours (FileSystem::isMapPath)
const Bool modArchive = modLayerOf(archiveFilename).isNotEmpty();
Int mapsIgnored = 0;
+ Int uiKept = 0;
FilenameListIter it = filenameList.begin();
@@ -178,10 +180,24 @@ void ArchiveFileSystem::addToTree(ArchivedDirectoryInfo &root, const ArchiveFile
}
// token is the filename, and dirInfo is the directory that this file is in.
- if (dirInfo->m_files.find(token) == dirInfo->m_files.end() || overwrite) {
- AsciiString path2;
- path2 = debugpath;
- path2.concat(token);
+ AsciiString path2;
+ path2 = debugpath;
+ path2.concat(token);
+ // a merged mod's interface file stays out where retail or the fork has one (FileSystem::isForkUIPath);
+ // an image sheet of it is still read first, under its "ModUI~" name, for the images only the mod
+ // has. A texture our sheets name stays out even where only its other extension is ours, because
+ // the loader takes a .dds before the .tga it was asked for.
+ ArchivedFileLocationMap::const_iterator held = dirInfo->m_files.find(token);
+ const Bool oursHeld = held != dirInfo->m_files.end() && modLayerOf(held->second).isEmpty();
+ if (modArchive && &root == &m_rootDirectory && (isOurUITexture(path2) || (oursHeld && FileSystem::isForkUIPath(path2))))
+ {
+ if (path2.startsWith("data\\ini\\mappedimages\\"))
+ m_modUICopies[path2] = archiveFilename;
+ ++uiKept;
+ it++;
+ continue;
+ }
+ if (held == dirInfo->m_files.end() || overwrite) {
// DEBUG_LOG(("ArchiveFileSystem::loadIntoDirectoryTree - adding file %s, archived in %s\n", path2.str(), archiveFilename.str()));
dirInfo->m_files[token] = archiveFilename;
}
@@ -190,6 +206,78 @@ void ArchiveFileSystem::addToTree(ArchivedDirectoryInfo &root, const ArchiveFile
}
if (mapsIgnored > 0)
DEBUG_LOG(("ArchiveFileSystem - %d map files in %s are ignored, the maps are ours\n", mapsIgnored, archiveFilename.str()));
+ if (uiKept > 0)
+ DEBUG_LOG(("ArchiveFileSystem - %d interface files in %s are ignored, the interface is ours\n", uiKept, archiveFilename.str()));
+}
+
+Bool ArchiveFileSystem::isOurUITexture(const AsciiString& filename) const
+{
+ AsciiString path = filename;
+ path.toLower();
+ return m_uiTextures.find(path) != m_uiTextures.end();
+}
+
+void ArchiveFileSystem::getModUICopies(const AsciiString& directory, std::vector<AsciiString> &names) const
+{
+ AsciiString prefix = directory;
+ prefix.toLower();
+ prefix.concat('\\');
+ for (std::map<AsciiString, AsciiString>::const_iterator it = m_modUICopies.begin(); it != m_modUICopies.end(); ++it)
+ {
+ if (it->first.startsWith(prefix.str()))
+ {
+ AsciiString name;
+ name.format("%s%s", MOD_UI_COPY, it->first.str());
+ names.push_back(name);
+ }
+ }
+}
+
+/// every texture our interface image sheets name, read from the sheets retail and the fork hold before
+/// any mod is in the tree; the loader may ask for either the .tga or the .dds of one
+void ArchiveFileSystem::collectUITextures()
+{
+ FilenameList sheets;
+ getFileListInDirectory(AsciiString(""), AsciiString("Data\\INI\\MappedImages\\"), AsciiString("*.ini"), sheets, TRUE);
+ for (FilenameListIter sheet = sheets.begin(); sheet != sheets.end(); ++sheet)
+ {
+ if (!FileSystem::isForkUIPath(*sheet))
+ continue;
+ File *file = openFile(sheet->str());
+ std::string text(file->size(), '\0');
+ file->read(&text[0], (Int)text.size());
+ file->close();
+ size_t at = 0;
+ while (at < text.size())
+ {
+ size_t end = text.find('\n', at);
+ if (end == std::string::npos)
+ end = text.size();
+ std::string line = text.substr(at, end - at);
+ at = end + 1;
+ line = line.substr(0, line.find(';'));
+ const size_t equals = line.find('=');
+ if (equals == std::string::npos)
+ continue;
+ AsciiString key = line.substr(0, equals).c_str();
+ AsciiString value = line.substr(equals + 1).c_str();
+ key.trim();
+ value.trim();
+ if (key.compareNoCase("Texture") != 0 || value.isEmpty())
+ continue;
+ value.toLower();
+ AsciiString path;
+ path.format("art\\textures\\%s", value.str());
+ m_uiTextures.insert(path);
+ if (path.endsWith(".tga"))
+ {
+ AsciiString dds = std::string(path.str(), path.getLength() - 4).c_str();
+ dds.concat(".dds");
+ m_uiTextures.insert(dds);
+ }
+ }
+ }
+ DEBUG_LOG(("ArchiveFileSystem::loadMods - %d interface textures stay ours\n", (Int)m_uiTextures.size()));
}
/// the fork's upscaled art goes by its file name, ReforgedTextures.big and the like
@@ -217,6 +305,8 @@ void ArchiveFileSystem::loadMods() {
forkArt.push_back(it->first);
}
+ collectUITextures();
+
// -modfactions loads retail's factions and each mod's from their own files (FileSystem::setFocus)
if (TheGlobalData->m_modFactions)
keepModsApart(TheGlobalData->m_mods.size());
@@ -341,8 +431,14 @@ Bool ArchiveFileSystem::doesFileExist(const Char *filename) const
return TRUE;
}
-File * ArchiveFileSystem::openFile(const Char *filename, Int access /* = 0 */)
+File * ArchiveFileSystem::openFile(const Char *filename, Int access /* = 0 */)
{
+ if (strncmp(filename, MOD_UI_COPY, strlen(MOD_UI_COPY)) == 0)
+ {
+ const Char *path = filename + strlen(MOD_UI_COPY);
+ return m_archiveFileMap[m_modUICopies[AsciiString(path)]]->openFile(path, access);
+ }
+
AsciiString archiveFilename;
archiveFilename = getArchiveFilenameForFile(AsciiString(filename));
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
index 44d9248ea..fdfcd8550 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
@@ -493,12 +493,15 @@ AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArc
// ...except over a file the fork ships: retail < mods < the fork. That copy is the one the install
// folder holds loose, and the plain lookup after this finds it.
- if ((loose.isNotEmpty() || archived) && isForkOwnedPath(filename) && TheLocalFileSystem->doesFileExist(filename.str()))
+ // The interface is ours whoever has it: a mod's loose .wnd, Language.ini or shell image is never
+ // read; its archived copies were kept out of the tree in ArchiveFileSystem::addToTree.
+ const Bool oursAlways = isForkUIPath(filename) || TheArchiveFileSystem->isOurUITexture(filename);
+ if ((loose.isNotEmpty() || archived) && (oursAlways || (isForkOwnedPath(filename) && TheLocalFileSystem->doesFileExist(filename.str()))))
{
static std::set<std::string> reported;
if (reported.insert(std::string(filename.str())).second)
{
- DEBUG_LOG(("FileSystem - the mod's %s is ignored, the fork's own copy wins (%s)\n",
+ DEBUG_LOG(("FileSystem - the mod's %s is ignored, our own copy wins (%s)\n",
filename.str(), loose.isNotEmpty() ? loose.str() : archive.str()));
}
return AsciiString();
@@ -555,6 +558,50 @@ Bool FileSystem::isForkOwnedPath(const AsciiString& filename)
|| p == "install_final.bmp";
}
+//============================================================================
+// FileSystem::isForkUIPath
+//============================================================================
+Bool FileSystem::isForkUIPath(const AsciiString& filename)
+{
+ // A mod integrates into our game and never brings its own interface: every window layout, the
+ // fonts (Language.ini, HeaderTemplate.ini), the shell's colours and transitions and the image sheets
+ // the shell and the HUD frames are cut from. The image sheets a mod's cameos live in
+ // (SAUserInterface512 and the like) and the Generals Challenge portraits stay the mod's: those are
+ // its units and its generals. The textures our sheets name are added in ArchiveFileSystem::loadMods.
+ AsciiString path = filename;
+ path.toLower();
+ std::string p(path.str());
+ for (size_t i = 0; i < p.size(); ++i)
+ {
+ if (p[i] == '/')
+ p[i] = '\\';
+ }
+ if (p.compare(0, strlen("window\\"), "window\\") == 0)
+ return TRUE;
+ const size_t slash = p.find_last_of('\\');
+ const std::string dir = slash == std::string::npos ? std::string() : p.substr(0, slash + 1);
+ const std::string name = slash == std::string::npos ? p : p.substr(slash + 1);
+ // Data\<language>\Language.ini and HeaderTemplate.ini
+ if (dir.compare(0, strlen("data\\"), "data\\") == 0 && dir.find('\\', strlen("data\\")) == dir.size() - 1
+ && (name == "language.ini" || name == "headertemplate.ini"))
+ return TRUE;
+ if ((dir == "data\\ini\\" || dir == "data\\ini\\default\\")
+ && (name == "shellmenuscheme.ini" || name == "windowtransitions.ini" || name == "ingameui.ini" || name == "controlbarresizer.ini"))
+ return TRUE;
+ static const char *const sheets[] = { "handcreatedmappedimages.ini", "scshelluserinterface512.ini",
+ "scsmshelluserinterface512.ini", "scgameuserinterface512.ini", "sclogosuserinterface512.ini",
+ "scpurchasepowers512.ini", "sacontrolbar512.ini", "sncontrolbar512.ini", "sucontrolbar512.ini" };
+ if (dir.compare(0, strlen("data\\ini\\mappedimages\\"), "data\\ini\\mappedimages\\") == 0)
+ {
+ for (size_t i = 0; i < sizeof(sheets) / sizeof(sheets[0]); ++i)
+ {
+ if (name == sheets[i])
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
//============================================================================
// FileSystem::getFileInfo
//============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp
index 11f4abf94..2a7fda188 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/Image.cpp
@@ -37,6 +37,7 @@
#define DEFINE_IMAGE_STATUS_NAMES
#include "Lib/BaseType.h"
+#include "Common/ArchiveFileSystem.h"
#include "Common/LocalFileSystem.h"
#include "Common/Debug.h"
#include "Common/INI.h"
@@ -257,6 +258,14 @@ void ImageCollection::load( Int textureSize )
// construct path to the mapped images folder of the correct texture size
sprintf( buffer, "Data\\INI\\MappedImages\\TextureSize_%d", textureSize );
+ // a merged mod's own copies of our interface sheets first: the images only it has (its cameos) are
+ // read from them, and ours, loaded after, take back every name both define (FileSystem::isForkUIPath)
+ std::vector<AsciiString> modCopies;
+ TheArchiveFileSystem->getModUICopies( AsciiString( buffer ), modCopies );
+ TheArchiveFileSystem->getModUICopies( AsciiString( "Data\\INI\\MappedImages\\HandCreated" ), modCopies );
+ for (size_t i = 0; i < modCopies.size(); ++i)
+ ini.load( modCopies[ i ], INI_LOAD_OVERWRITE, NULL );
+
// load all the ine files in that directory
ini.loadDirectory( AsciiString( buffer ), TRUE, INI_LOAD_OVERWRITE, NULL );