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
fix(gameenginedevice): find the base game in Steam's own layout
Olcay Seyganfaa8e2b15912
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c0d766282..015c4607d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -876,7 +876,8 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A long chat message or an unusual map name could kill the process.- A map name the game cannot make sense of is refused as you start, instead of taking the game down later. A path with a space in it and no quotes around it left the loader walking the same step of that path forever, growing a string until it ran out of room, and the game then went on starting with half of itself missing. What you saw was a crash a second later, in the part of the game that runs a match, naming nothing that had anything to do with it. Any failure during start-up now stops the game there and says which one it was.- Starting the game from the folder the zip was unpacked to says what is wrong. None of Zero Hour's own files are in that folder, so the first one the game asked for was missing, and the box that came up blamed viruses and overheated hardware. It now names the folder it looked in and tells you to run install.bat.-- A machine that once had Generals installed from a disc or The First Decade, and later removed it, no longer loses the original game's files. The old install leaves its address behind in Windows, the game trusted it over the copy Steam keeps beside Zero Hour, and the main menu came up over magenta water and black hills. A folder that turns out to be empty is passed over now, and when the original game's files are nowhere at all, a box says so and points you at Steam's file check instead of starting.+- A machine that once had Generals installed from a disc or The First Decade, and later removed it, no longer loses the original game's files. The old install leaves its address behind in Windows, the game trusted it over the copy Steam keeps beside Zero Hour, and the main menu came up over magenta water and black hills. A folder that turns out to be empty is passed over now.+- Buying both games on Steam is enough. Steam writes nothing to Windows saying where it put them and installs the two side by side in their own folders, so the game had no way of finding the original one unless you had copied its files across by hand: a fresh install of both came up on a magenta main menu with most of the sound effects missing. The folder next to Zero Hour's is searched now. When the original game's files really are nowhere, a box names the folder to put them in, rather than leaving you to read a pink menu.- Nor can a map handed to you over the network, however long a name the other machine gives it.- An order too big for one packet arrives in pieces, and a piece that claims to belong outside the order is dropped instead of landing there.- A chat line too long for a packet is dropped rather than arriving as a different, shorter line.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cppindex baf180578..87ec145f2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp@@ -27,6 +27,7 @@/////////////////////////////////////////////////////////////#include <winsock2.h>+#include <windows.h> // MessageBox, for the one thing a player has to be told before the menu#include "Common/AudioAffect.h"#include "Common/ArchiveFile.h"#include "Common/ArchiveFileSystem.h"@@ -46,6 +47,40 @@static const char *BIGFileIdentifier = "BIGF";+// What makes a folder the base game's. Textures.big is where the shell map's ground comes from,+// and an uninstalled copy takes it away while leaving its registry key behind.+static const char *const BASE_GAME_ARCHIVE = "Textures.big";++// Where to look when the registry does not say. Steam writes no key and installs the two games as+// sibling folders under steamapps\common (apps 2229870 and 2732960), so the base game is one folder+// over; a copied-over install puts the same bigs in ZH_Generals next to the exe.+static const char *const BASE_GAME_DIRECTORIES[] = {+ "ZH_Generals\\",+ "..\\Command & Conquer Generals\\",+};++static Bool holdsBaseGameArchives(const char *directory)+{+ AsciiString archive = directory;+ archive.concat(BASE_GAME_ARCHIVE);+ return TheLocalFileSystem->doesFileExist(archive.str());+}++// The game starts without the base archives and then looks and sounds broken: magenta ground and+// water, "Missing Audio File" for half the sound effects, no music and no tree models. None of+// that names its own cause, and a player staring at a pink main menu has nothing to go on, so it is+// said here - before the menu, in the one place that knows.+static void reportMissingBaseGame(void)+{+ DEBUG_LOG(("Win32BIGFileSystem::init - no base game archives anywhere; most of the art and audio will be missing.\n"));+ ::MessageBox(NULL,+ "Zero Hour shares most of its artwork, sound effects and music with Command & Conquer Generals, "+ "and none of the base game's .big files could be found.\n\n"+ "Install Generals, or copy its .big files into a folder named ZH_Generals next to generals.exe.",+ "Zero Hour Reforged",+ MB_OK | MB_ICONWARNING | MB_TASKMODAL);+}+Win32BIGFileSystem::Win32BIGFileSystem() : ArchiveFileSystem() {}@@ -74,35 +109,45 @@ void Win32BIGFileSystem::init() {// unreachable. Re-load the patch archives with overwrite so they win, like retail.loadBigFilesFromDirectory("", "Patch*.big", TRUE, FALSE);- // load original Generals assets- AsciiString installPath;- GetStringFromGeneralsRegistry("", "InstallPath", installPath );- //@todo this will need to be ramped up to a crash for release-#ifndef _INTERNAL- // had to make this non-internal only, otherwise we can't autobuild- // GeneralsZH...- DEBUG_ASSERTCRASH(installPath != "", ("Be 1337! Go install Generals!"));-#endif- // Zero Hour is not standalone: the base game's bigs carry most of the art,- // audio and the music tracks, and the CD check in AudioManager::init spins- // on a "Missing CD" prompt without them. A retail install registers the- // key above; the Steam build does not, it ships the base game's bigs in a- // ZH_Generals subdirectory next to the exe instead. Fall back to that- // layout so a copied-over Steam install works with no registry writes.- //- // A registered folder that holds no Textures.big gets the same fallback. An uninstalled- // retail or First Decade copy leaves its key behind, and trusting it loaded no base archive- // at all: the water and the ground came up magenta and black on the shell map.- AsciiString baseTextures = installPath;- baseTextures.concat("Textures.big");- if (installPath=="" || !TheLocalFileSystem->doesFileExist(baseTextures.str()))+ // Zero Hour is not standalone: the base game's bigs carry most of the art, the sound effects+ // and the music. A retail install registers the key below and Steam registers nothing, so a+ // folder that holds Textures.big is what this looks for rather than a key that exists. The+ // pass above already loaded whatever sits next to the exe, so there is only something to fetch+ // when the base archives are not already there.+ if (!holdsBaseGameArchives("")){- DEBUG_LOG(("Win32BIGFileSystem::init - no base game archives in the registered folder '%s', trying ZH_Generals\\\n", installPath.str()));- installPath = "ZH_Generals\\";+ AsciiString installPath;+ GetStringFromGeneralsRegistry("", "InstallPath", installPath );+ if (!installPath.isEmpty() && !installPath.endsWith("\\"))+ {+ installPath.concat("\\");+ }+ // An uninstalled retail or First Decade copy leaves its key behind, and trusting it loaded+ // no base archive at all: the water and the ground came up magenta and black on the shell map.+ if (installPath.isEmpty() || !holdsBaseGameArchives(installPath.str()))+ {+ DEBUG_LOG(("Win32BIGFileSystem::init - no base game archives in the registered folder '%s'\n", installPath.str()));+ installPath.clear();+ for (Int i = 0; i < (Int)ARRAY_SIZE(BASE_GAME_DIRECTORIES) && installPath.isEmpty(); i++)+ {+ if (holdsBaseGameArchives(BASE_GAME_DIRECTORIES[i]))+ {+ installPath = BASE_GAME_DIRECTORIES[i];+ }+ }+ }+ if (installPath.isEmpty())+ {+ reportMissingBaseGame();+ }+ else+ {+ // Loaded second on purpose: loadIntoDirectoryTree does not overwrite, so the+ // Zero Hour bigs already in the tree win over the base game's copies.+ DEBUG_LOG(("Win32BIGFileSystem::init - loading the base game's archives from '%s'\n", installPath.str()));+ loadBigFilesFromDirectory(installPath, "*.big");+ }}- // Loaded second on purpose: loadIntoDirectoryTree does not overwrite, so the- // Zero Hour bigs already in the tree win over the base game's copies.- loadBigFilesFromDirectory(installPath, "*.big");// ... except where that costs resolution: a number of the base game's textures were shipped// downscaled in TexturesZH.big, and load order alone made those the ones the game uses.