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
build(cmake): port phase 2 support libs (debug, wwdownload, gamespy)
Olcay Seygan6966e32f401d
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 9c024fa24..36881cd84 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -190,3 +190,79 @@ add_executable(dx8_smoke ${WW}/WW3D2/test_dx8_smoke.cpp)target_include_directories(dx8_smoke PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)target_link_directories(dx8_smoke PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Lib)target_link_libraries(dx8_smoke PRIVATE d3d8 user32)++# ===========================================================================+# Phase 2 - remaining support libs. None of these touch DX8.+# ===========================================================================+set(LIBSRC ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source)++# ---- debug ----------------------------------------------------------------+# EA's in-repo debug/logging lib (RTS.dsp links it as debug.lib). Self-contained+# apart from the Win32 SDK. The test1-6/, netserv/ and debug_dlg/ subdirs are+# separate .dsp projects, not part of the lib.+add_library(debug STATIC+ ${LIBSRC}/debug/debug.cpp ${LIBSRC}/debug/debug_cmd.cpp+ ${LIBSRC}/debug/debug_debug.cpp ${LIBSRC}/debug/debug_except.cpp+ ${LIBSRC}/debug/debug_getdefaultcommands.cpp+ ${LIBSRC}/debug/debug_internal.cpp+ ${LIBSRC}/debug/debug_io_con.cpp ${LIBSRC}/debug/debug_io_flat.cpp+ ${LIBSRC}/debug/debug_io_net.cpp ${LIBSRC}/debug/debug_io_ods.cpp+ ${LIBSRC}/debug/debug_purecall.cpp+ ${LIBSRC}/debug/debug_stack.cpp)+target_include_directories(debug PUBLIC ${LIBSRC}/debug)+target_link_libraries(debug PUBLIC dbghelp comctl32 ws2_32)++# ---- wwdownload -----------------------------------------------------------+# FTP patch downloader. Its wlib/resource.h includes are all commented out in+# the shipped source, so it needs nothing but winsock.+add_library(wwdownload STATIC+ ${WW}/WWDownload/Download.cpp ${WW}/WWDownload/FTP.CPP+ ${WW}/WWDownload/registry.cpp ${WW}/WWDownload/urlBuilder.cpp)+target_include_directories(wwdownload PUBLIC ${WW}/WWDownload ${WW})+target_link_libraries(wwdownload PUBLIC wsock32 winmm)++# ---- benchmark ------------------------------------------------------------+# BYTEmark sources are missing; benchmark_stub.c stands in for them. See the+# file header for why a constant is enough and when to revisit.+add_library(benchmark STATIC ${LIBSRC}/Benchmark/benchmark_stub.c)+target_include_directories(benchmark PUBLIC ${LIBSRC}/Benchmark)++# ---- eabrowserdispatch ----------------------------------------------------+# Only BrowserDispatch.idl shipped; the .h/_i.c that GameEngine's WebBrowser.h+# expects are MIDL output. Generate them at build time (MSBuild puts cl.exe,+# MIDL's preprocessor, on PATH) into a dir laid out so the shipped+# #include "EABrowserDispatch/BrowserDispatch.h" resolves unchanged.+set(EABD_GEN ${CMAKE_CURRENT_BINARY_DIR}/generated/EABrowserDispatch)+file(MAKE_DIRECTORY ${EABD_GEN})+# midl.exe ships with the Windows SDK, not on PATH at configure time.+file(GLOB MIDL_HINTS "$ENV{ProgramFiles\(x86\)}/Windows Kits/10/bin/*/x86")+find_program(MIDL_EXECUTABLE midl HINTS ${MIDL_HINTS} REQUIRED)+add_custom_command(+ OUTPUT ${EABD_GEN}/BrowserDispatch.h ${EABD_GEN}/BrowserDispatch_i.c+ COMMAND ${MIDL_EXECUTABLE} /nologo /env win32 /win32+ /h ${EABD_GEN}/BrowserDispatch.h+ /iid ${EABD_GEN}/BrowserDispatch_i.c+ /proxy ${EABD_GEN}/BrowserDispatch_p.c+ /dlldata ${EABD_GEN}/dlldata.c+ /tlb ${EABD_GEN}/BrowserDispatch.tlb+ ${LIBSRC}/EABrowserDispatch/BrowserDispatch.idl+ DEPENDS ${LIBSRC}/EABrowserDispatch/BrowserDispatch.idl+ COMMENT "MIDL BrowserDispatch.idl")+add_library(eabrowserdispatch STATIC+ ${EABD_GEN}/BrowserDispatch_i.c ${EABD_GEN}/BrowserDispatch.h)+target_include_directories(eabrowserdispatch+ PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/generated)++# ---- gamespy --------------------------------------------------------------+# PLAN.md called for hand-written stubs behind the five GameSpy* libs, but the+# real SDK is open source (TheSuperHackers/GamespySDK, itself CMake-based), so+# vendor and build it instead: correct signatures, structs and enum values+# rather than 73 guessed prototypes. Multiplayer stays out of scope - this only+# has to compile and link; nothing needs to reach a live GameSpy server.+# OpenSSL/HTTPS off so the SDK does not FetchContent OpenSSL for services that+# have been dead since 2014; voice and tests off for the same reason.+set(GS_OPENSSL OFF CACHE BOOL "" FORCE)+set(GS_SECURESECONNECT OFF CACHE BOOL "" FORCE)+set(GS_BUILD_TESTS OFF CACHE BOOL "" FORCE)+set(GS_INCLUDE_VOICE OFF CACHE BOOL "" FORCE)+add_subdirectory(${LIBSRC}/GameSpy ${CMAKE_CURRENT_BINARY_DIR}/gamespy)diff --git a/GeneralsMD/Code/Libraries/Source/Benchmark/benchmark_stub.c b/GeneralsMD/Code/Libraries/Source/Benchmark/benchmark_stub.cnew file mode 100644index 000000000..86bbd5eca--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/Benchmark/benchmark_stub.c@@ -0,0 +1,43 @@+/*+ * Stub for the BYTEmark/nbench benchmark library.+ *+ * The real sources (nbench0/nbench1/emfloat/misc/sysspec, per Benchmark.dsp) were+ * stripped from the repo along with the other third-party code. Exactly one call+ * site exists in the whole game:+ *+ * GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp+ * -> testMinimumRequirements() -> RunBenchmark(0, NULL, &f, &i, &m)+ *+ * and its results only feed GameLODManager, which compares them against the+ * BenchProfile presets in the game's INI to pick a static detail level on first+ * launch (GameLOD.cpp:299-320). Nothing else in the engine reads them, so a+ * constant is enough to boot; running BYTEmark on a 2020s CPU would in any case+ * report "far faster than every 2003 preset", which is what the constants say.+ *+ * ponytail: fixed indices, not a measurement. These are the calibration knob for+ * detail-level selection -- if Phase 5 shows the game picking a silly LOD, tune+ * them against the shipped BenchProfile entries (or vendor real nbench) rather+ * than patching GameLOD. Higher = machine rated faster.+ */++#include "benchmark.h"++/* Roughly "top of the 2003 preset table, with headroom". Same units the shipped+ * BenchProfile INI entries use; ratios are all GameLOD ever takes of them. */+#define BENCH_FLOAT_INDEX 100.0f+#define BENCH_INT_INDEX 100.0f+#define BENCH_MEM_INDEX 100.0f++int RunBenchmark(int argc, char *argv[], float *floatResult, float *intResult, float *memResult)+{+ (void)argc;+ (void)argv;++ /* The one caller always passes all three, but the real nbench tolerated NULLs+ * and this is an external-facing C entry point, so keep the checks. */+ if (floatResult != 0) *floatResult = BENCH_FLOAT_INDEX;+ if (intResult != 0) *intResult = BENCH_INT_INDEX;+ if (memResult != 0) *memResult = BENCH_MEM_INDEX;++ return 0;+}diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cpp b/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cppindex 09f18aeff..25e465489 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cpp+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.cpp@@ -227,7 +227,8 @@ bool DebugCmdInterfaceDebug::Execute(class Debug& dbg, const char *cmd,// regular I/O command// find I/O class- for (Debug::IOFactoryListEntry *cur=dbg.firstIOFactory;cur;cur=cur->next)+ Debug::IOFactoryListEntry *cur;+ for (cur=dbg.firstIOFactory;cur;cur=cur->next)if (!strcmp(argv[0],cur->ioID))break;if (!cur)@@ -357,7 +358,8 @@ bool DebugCmdInterfaceDebug::Execute(class Debug& dbg, const char *cmd,// must fixup lastPatternEntry nowif (dbg.firstPatternEntry){- for (Debug::PatternListEntry *cur=dbg.firstPatternEntry;cur->next;cur=cur->next);+ Debug::PatternListEntry *cur;+ for (cur=dbg.firstPatternEntry;cur->next;cur=cur->next);dbg.lastPatternEntry=cur;}elsediff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.h b/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.hindex f4f523923..6f9d11398 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.h+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_cmd.h@@ -51,7 +51,7 @@class DebugCmdInterface{// no copy/assign op- DebugCmdInterface(const &DebugCmdInterface);+ DebugCmdInterface(const DebugCmdInterface&);DebugCmdInterface& operator=(const DebugCmdInterface&);protected:diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp b/GeneralsMD/Code/Libraries/Source/debug/debug_debug.cppindex 1949e8cbf..58b1aa99c 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp@@ -878,7 +878,8 @@ Debug& Debug::operator<<(const MemDump &dump)// itemsconst unsigned char *curByte=cur;- for (unsigned k=0;k<itemPerLine;k++,curByte+=dump.m_bytePerItem)+ unsigned k;+ for (k=0;k<itemPerLine;k++,curByte+=dump.m_bytePerItem){operator<<(" ");@@ -971,7 +972,8 @@ void Debug::AddHResultTranslator(unsigned prio, HResultTranslator func, void *us// now find the right place to insert the translator// (slow but this function is not time critical)- for (unsigned k=0;k<Instance.numHrTranslators;++k)+ unsigned k;+ for (k=0;k<Instance.numHrTranslators;++k)if (Instance.hrTranslators[k].prio<prio)break;@@ -1220,7 +1222,8 @@ const char *Debug::AddLogGroup(const char *fileOrGroup, const char *descr)}// is that log group known?- for (KnownLogGroupList *cur=firstLogGroup;cur;cur=cur->next)+ KnownLogGroupList *cur;+ for (cur=firstLogGroup;cur;cur=cur->next){if (!strcmp(cur->nameGroup,fileOrGroup)){diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp b/GeneralsMD/Code/Libraries/Source/debug/debug_except.cppindex 4872bf994..dac78b4fa 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp@@ -158,7 +158,9 @@ void DebugExceptionhandler::LogFPURegisters(Debug &dbg, struct _EXCEPTION_POINTE<< " ErrSel: " << Debug::Width(8) << flt.ErrorSelector << "\n"<< "DataOfs: " << Debug::Width(8) << flt.DataOffset<< " DataSel: " << Debug::Width(8) << flt.DataSelector << "\n"- << "Cr0NpxState: " << Debug::Width(8) << flt.Cr0NpxState << "\n";+ // Cr0NpxState was renamed to Spare0 in the modern Windows SDK's+ // _FLOATING_SAVE_AREA; same offset, same contents.+ << "Cr0NpxState: " << Debug::Width(8) << flt.Spare0 << "\n";for (unsigned k=0;k<SIZE_OF_80387_REGISTERS/10;++k){diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io.h b/GeneralsMD/Code/Libraries/Source/debug/debug_io.hindex 4ff5f2e16..7f77f69e4 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_io.h+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_io.h@@ -46,7 +46,7 @@class DebugIOInterface{// no copy/assign op- DebugIOInterface(const &DebugIOInterface);+ DebugIOInterface(const DebugIOInterface&);DebugIOInterface& operator=(const DebugIOInterface&);protected:diff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cpp b/GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cppindex 729f5089a..2980c1518 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cpp+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_io_flat.cpp@@ -306,7 +306,8 @@ DebugIOFlat::~DebugIOFlat()void DebugIOFlat::Write(StringType type, const char *src, const char *str){- for (SplitListEntry *cur=m_firstSplit;cur;cur=cur->next)+ SplitListEntry *cur;+ for (cur=m_firstSplit;cur;cur=cur->next){if (!(cur->stringTypes&(1<<type)))continue;@@ -468,7 +469,8 @@ void DebugIOFlat::Execute(class Debug& dbg, const char *cmd, bool structuredCmd,// create our filename, search for stream with same filenamechar fn[256];ExpandMagic(m_baseFilename,cur->name,fn);- for (StreamListEntry *stream=m_firstStream;stream;stream=stream->next)+ StreamListEntry *stream;+ for (stream=m_firstStream;stream;stream=stream->next)if (!strcmp(stream->stream->GetFilename(),fn))break;if (!stream)@@ -526,7 +528,8 @@ void DebugIOFlat::Execute(class Debug& dbg, const char *cmd, bool structuredCmd,// must fixup m_lastSplitPtr nowif (m_firstSplit){- for (SplitListEntry *cur=m_firstSplit;cur->next;cur=cur->next);+ SplitListEntry *cur;+ for (cur=m_firstSplit;cur->next;cur=cur->next);m_firstSplit=cur;}elsediff --git a/GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp b/GeneralsMD/Code/Libraries/Source/debug/debug_stack.cppindex cf357918d..eaa36a4e8 100644--- a/GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp+++ b/GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp@@ -86,7 +86,8 @@ static void InitDbghelp(void)// Get function addressesunsigned *funcptr=gDbg.funcPtr;- for (unsigned k=0;DebughelpFunctionNames[k];++k,++funcptr)+ unsigned k;+ for (k=0;DebughelpFunctionNames[k];++k,++funcptr){*funcptr=(unsigned)GetProcAddress(g_dbghelp,DebughelpFunctionNames[k]);if (!*funcptr)