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(gameengine): pass AsciiString to log calls as c strings
Olcay Seyganb5aa811b3be5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bd38fffb1..4aed74fd8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -273,7 +273,7 @@ found and fixed, EA's own, not port damage.**- A German, French or other non-English Zero Hour on a Mac or Linux speaks its own language. Windows' installer writes the language into the registry, and nothing does that on a Mac or Linux, so the game took English and found it in the original Generals' files beside Zero Hour: the menus came up in Generals' English with Zero Hour's own lines missing, so it looked like plain Generals. With no language set it now takes the one your Zero Hour's own files are in. A language you set yourself still wins.- Text on the Linux menus is as wide as on Windows. Linux has no Arial, and the font standing in for it reports a wider average letter, so every menu font the game sets to a fixed width came out a quarter narrower than it should, the "Generals" lettering and the menu buttons among them. Each is measured against Arial's own figure now, and lands within one percent of Windows.- The game no longer crashes on some Linux PCs as its window opens. The game hands out memory its own way, and on Linux the graphics driver gets its memory from the game too. Some drivers, AMD's on Debian 12 among them, need every piece lined up on a 16-byte boundary, and the game's lined up on 4, so the start died or went through depending on where the pieces happened to fall. On Linux everything outside the game's own pools now comes from the system, which lines it up as the driver expects.-- `./build-linux.sh` stopped on Linux Mint and Arch after the centred Classic interface went in: the new code compared layout names with a Windows-only spelling that GCC on Linux has never heard of. It uses the name every platform knows now, and so do the two debug-build spots with the same habit. From 3.0.0 on, `./build-macos.sh` and `./build-linux.sh` stopped again, on another Windows-only spelling in the mod code and, on Linux, a file name written in the wrong case, which Windows does not mind. The log blamed the audio library because it was the last file the build had started; the real error sat higher up. Both are fixed, after Andreas Berger found them. On 3.2.0 `./build-macos.sh` got nearly to the end and stopped on four of the build's own tests of how the game reads its files, which were missing two pieces the game's job scheduler picked up in that version. They have them now, after Martin K. reported it.+- `./build-linux.sh` stopped on Linux Mint and Arch after the centred Classic interface went in: the new code compared layout names with a Windows-only spelling that GCC on Linux has never heard of. It uses the name every platform knows now, and so do the two debug-build spots with the same habit. From 3.0.0 on, `./build-macos.sh` and `./build-linux.sh` stopped again, on another Windows-only spelling in the mod code and, on Linux, a file name written in the wrong case, which Windows does not mind. The log blamed the audio library because it was the last file the build had started; the real error sat higher up. Both are fixed, after Andreas Berger found them. On 3.2.0 `./build-macos.sh` got nearly to the end and stopped on four of the build's own tests of how the game reads its files, which were missing two pieces the game's job scheduler picked up in that version. They have them now, after Martin K. reported it. Since 3.4.0 `./build-macos.sh` stopped once more, this time on the save and load code: it handed the save file's name to a log line as a whole text object where the line wanted plain characters, which the Mac's compiler refuses and Windows lets through, so on Windows that line printed garbage in place of the file name. It hands over the name itself now, and the Windows build warns about the same mistake anywhere else. Martin K. reported this one too.- Windows on Arm laptops, the Snapdragon ones, get a build made for them. Microsoft never shipped those machines the library the game loads its textures and shaders through, so the game brings its own, the texture code the Mac and Linux versions already run. Switched on in place of Microsoft's library on an ordinary Windows PC, it draws the same battlefields, with no tree, house or patch of ground going missing. Nobody has played it on a Snapdragon laptop yet.- The Linux game has Generals' icon. The window carries it in the taskbar and in the window switcher, and `add-to-menu.sh` in the folder `./build-linux.sh` makes puts the game in the desktop's app menu with it, which is where GNOME takes a running game's icon from. It had none.- Thanks to ilyasakin, whose port this is.diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex ae4247f77..eea88b8c8 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -201,7 +201,9 @@ if(MSVC)# translator only runs in code compiled with asynchronous EH, so under /EHsc the hook# is dead (MSVC says so: "warning C4535: _set_se_translator() requires /EHa") and a# faulting frame just kills the process with 0xC0000005 and no log at all.- add_compile_options(/W3 /permissive /EHa)+ # /w34840 raises C4840, a class object passed to printf-style varargs, to /W3: clang on+ # macOS refuses it outright (-Wnon-pod-varargs) and MSVC used to pass it in silence.+ add_compile_options(/W3 /w34840 /permissive /EHa)# There is no debugger on the porting machine, so ReleaseCrashInfo.txt's stack# dump is the only stack we get. StackDump.cpp walks the EBP chain by hand and# /O2 implies /Oy (no frame pointer), which leaves that dump empty; /Zi + /DEBUGdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cppindex 31eb3106a..b96993fb1 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp@@ -287,7 +287,16 @@ void AsciiString::format(AsciiString format, ...){validate();va_list args;+ // C4840 here is va_start naming a class-typed last parameter, which both compilers handle;+ // it is kept on everywhere else to catch a string object passed through the "...".+#ifdef _MSC_VER+#pragma warning(push)+#pragma warning(disable: 4840)+#endifva_start(args, format);+#ifdef _MSC_VER+#pragma warning(pop)+#endifformat_va(format, args);va_end(args);validate();diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cppindex 4051a59b8..335eb7245 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp@@ -1551,9 +1551,9 @@ void GameState::xferSaveData( Xfer *xfer, SnapshotType which )// the DEBUG_CRASH is compiled out of a release build; the module that threw logged itselfDEBUG_LOG(( "GameState::xferSaveData - error saving block '%s' in file '%s'\n",- blockName.str(), xfer->getIdentifier() ));+ blockName.str(), xfer->getIdentifier().str() ));DEBUG_CRASH(( "Error saving block '%s' in file '%s'\n",- blockName.str(), xfer->getIdentifier() ));+ blockName.str(), xfer->getIdentifier().str() ));throw;} // end catch@@ -1634,9 +1634,9 @@ void GameState::xferSaveData( Xfer *xfer, SnapshotType which )// the DEBUG_CRASH is compiled out of a release build; the module that threw logged itselfDEBUG_LOG(( "GameState::xferSaveData - error loading block '%s' in file '%s'\n",- blockInfo->blockName.str(), xfer->getIdentifier() ));+ blockInfo->blockName.str(), xfer->getIdentifier().str() ));DEBUG_CRASH(( "Error loading block '%s' in file '%s'\n",- blockInfo->blockName.str(), xfer->getIdentifier() ));+ blockInfo->blockName.str(), xfer->getIdentifier().str() ));throw;} // end catchdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cppindex 76aae9598..7a1a82f6a 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp@@ -298,7 +298,16 @@ void UnicodeString::format(UnicodeString format, ...){validate();va_list args;+ // C4840 here is va_start naming a class-typed last parameter, which both compilers handle;+ // it is kept on everywhere else to catch a string object passed through the "...".+#ifdef _MSC_VER+#pragma warning(push)+#pragma warning(disable: 4840)+#endifva_start(args, format);+#ifdef _MSC_VER+#pragma warning(pop)+#endifformat_va(format, args);va_end(args);validate();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 911a80cc6..d24bfddde 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -3075,7 +3075,16 @@ void InGameUI::message( AsciiString stringManagerLabel, ... )// construct the final text after formattingva_list args;+ // C4840 here is va_start naming a class-typed last parameter, which both compilers handle;+ // it is kept on everywhere else to catch a string object passed through the "...".+#ifdef _MSC_VER+#pragma warning(push)+#pragma warning(disable: 4840)+#endifva_start( args, stringManagerLabel );+#ifdef _MSC_VER+#pragma warning(pop)+#endifWideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];// truncate rather than throw: an uncaught engine exception aborts with 0xC0000409 and no log// at all, so an over-long chat or script message used to be a silent hard crash.@@ -3102,7 +3111,14 @@ void InGameUI::message( UnicodeString format, ... )// construct the final text after formattingva_list args;+#ifdef _MSC_VER+#pragma warning(push)+#pragma warning(disable: 4840)+#endifva_start( args, format );+#ifdef _MSC_VER+#pragma warning(pop)+#endifWideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];// truncate rather than throw: an uncaught engine exception aborts with 0xC0000409 and no log// at all, so an over-long chat or script message used to be a silent hard crash.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Create/GrantUpgradeCreate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Create/GrantUpgradeCreate.cppindex 27798a62a..559ea2ceb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Create/GrantUpgradeCreate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Create/GrantUpgradeCreate.cpp@@ -92,7 +92,7 @@ void GrantUpgradeCreate::onCreate( void )const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( getGrantUpgradeCreateModuleData()->m_upgradeName );if( !upgradeTemplate ){- DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName(), getGrantUpgradeCreateModuleData()->m_upgradeName ) );+ DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName().str(), getGrantUpgradeCreateModuleData()->m_upgradeName.str() ) );return;}@@ -125,7 +125,7 @@ void GrantUpgradeCreate::onBuildComplete( void )const UpgradeTemplate *upgradeTemplate = TheUpgradeCenter->findUpgrade( getGrantUpgradeCreateModuleData()->m_upgradeName );if( !upgradeTemplate ){- DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName(), getGrantUpgradeCreateModuleData()->m_upgradeName ) );+ DEBUG_ASSERTCRASH( 0, ("GrantUpdateCreate for %s can't find upgrade template %s.", getObject()->getName().str(), getGrantUpgradeCreateModuleData()->m_upgradeName.str() ) );return;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cppindex ec38fdbf9..5b0313f7a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp@@ -713,7 +713,7 @@ void Add_Files( const char * dir, MixFileCreator & mix )StringClass name;name.Format( "%s%s", dir, find_info.cFileName );StringClass source;- source.Format( "makemix\\%s", name );+ source.Format( "makemix\\%s", name.Peek_Buffer() );mix.Add_File( source, name );// WWDEBUG_SAY(( "Adding file from %s %s\n", source, name ));}