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.

build(cmake): add VS2022 CMake port of leaf libraries

Olcay Seyganb7f89198f6f4
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txt
new file mode 100644
index 000000000..de776d187
--- /dev/null
+++ b/GeneralsMD/Code/CMakeLists.txt
@@ -0,0 +1,131 @@
+cmake_minimum_required(VERSION 3.20)
+project(GeneralsMD CXX C)
+
+# Win32 only: the code is full of 32-bit inline __asm, which MSVC x64 rejects outright.
+if(MSVC AND NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
+ message(FATAL_ERROR "Configure for Win32: cmake -A Win32")
+endif()
+
+set(WW ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/WWVegas)
+set(COMP ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/Compression)
+
+add_compile_definitions(WIN32 _WINDOWS _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)
+if(MSVC)
+ # /permissive- is off on purpose: this is 2003-era code and templates here rely on
+ # pre-two-phase-lookup name binding (simplevec.h et al).
+ add_compile_options(/W3 /permissive /EHsc)
+endif()
+
+# ---- wwdebug --------------------------------------------------------------
+add_library(wwdebug STATIC
+ ${WW}/WWDebug/wwdebug.cpp
+ ${WW}/WWDebug/wwmemlog.cpp
+ ${WW}/WWDebug/wwprofile.cpp)
+target_include_directories(wwdebug PUBLIC ${WW}/WWDebug PRIVATE ${WW}/WWLib ${WW}/Wwutil)
+
+# ---- wwutil ---------------------------------------------------------------
+add_library(wwutil STATIC
+ ${WW}/Wwutil/mathutil.cpp
+ ${WW}/Wwutil/miscutil.cpp)
+target_include_directories(wwutil PUBLIC ${WW}/Wwutil PRIVATE ${WW}/WWLib ${WW}/WWMath)
+target_link_libraries(wwutil PRIVATE wwdebug)
+
+# ---- wwmath ---------------------------------------------------------------
+add_library(wwmath STATIC
+ ${WW}/WWMath/aabox.cpp ${WW}/WWMath/aabtreecull.cpp
+ ${WW}/WWMath/cardinalspline.cpp ${WW}/WWMath/catmullromspline.cpp
+ ${WW}/WWMath/colmath.cpp ${WW}/WWMath/colmathaabox.cpp
+ ${WW}/WWMath/colmathaabtri.cpp ${WW}/WWMath/colmathfrustum.cpp
+ ${WW}/WWMath/colmathline.cpp ${WW}/WWMath/colmathobbobb.cpp
+ ${WW}/WWMath/colmathobbox.cpp ${WW}/WWMath/colmathobbtri.cpp
+ ${WW}/WWMath/colmathplane.cpp ${WW}/WWMath/colmathsphere.cpp
+ ${WW}/WWMath/cullsys.cpp ${WW}/WWMath/curve.cpp
+ ${WW}/WWMath/euler.cpp ${WW}/WWMath/frustum.cpp
+ ${WW}/WWMath/gridcull.cpp ${WW}/WWMath/hermitespline.cpp
+ ${WW}/WWMath/lineseg.cpp ${WW}/WWMath/lookuptable.cpp
+ ${WW}/WWMath/matrix3.cpp ${WW}/WWMath/matrix3d.cpp
+ ${WW}/WWMath/matrix4.cpp ${WW}/WWMath/obbox.cpp
+ ${WW}/WWMath/ode.cpp ${WW}/WWMath/pot.cpp
+ ${WW}/WWMath/quat.cpp ${WW}/WWMath/tcbspline.cpp
+ ${WW}/WWMath/tri.cpp ${WW}/WWMath/v3_rnd.cpp
+ ${WW}/WWMath/vehiclecurve.cpp ${WW}/WWMath/vp.cpp
+ ${WW}/WWMath/wwmath.cpp)
+target_include_directories(wwmath PUBLIC ${WW}/WWMath PRIVATE ${WW}/WWLib ${WW}/WWSaveLoad ${WW}/Wwutil)
+target_link_libraries(wwmath PRIVATE wwdebug)
+
+# ---- compression ----------------------------------------------------------
+# zlib 1.1.4 (vendored, per README) minus maketree.c - that one is a table
+# generator with its own main(). Lzhl_tcp.cpp is also skipped (socket layer,
+# nothing in the game calls it).
+add_library(compression STATIC
+ ${COMP}/CompressionManager.cpp
+ ${COMP}/EAC/btreeabout.cpp ${COMP}/EAC/btreedecode.cpp ${COMP}/EAC/btreeencode.cpp
+ ${COMP}/EAC/huffabout.cpp ${COMP}/EAC/huffdecode.cpp ${COMP}/EAC/huffencode.cpp
+ ${COMP}/EAC/refabout.cpp ${COMP}/EAC/refdecode.cpp ${COMP}/EAC/refencode.cpp
+ ${COMP}/LZHCompress/NoxCompress.cpp
+ ${COMP}/LZHCompress/CompLibSource/Huff.cpp
+ ${COMP}/LZHCompress/CompLibSource/Lz.cpp
+ ${COMP}/LZHCompress/CompLibSource/Lzhl.cpp
+ ${COMP}/ZLib/adler32.c ${COMP}/ZLib/compress.c ${COMP}/ZLib/crc32.c
+ ${COMP}/ZLib/deflate.c ${COMP}/ZLib/gzio.c ${COMP}/ZLib/infblock.c
+ ${COMP}/ZLib/infcodes.c ${COMP}/ZLib/inffast.c ${COMP}/ZLib/inflate.c
+ ${COMP}/ZLib/inftrees.c ${COMP}/ZLib/infutil.c ${COMP}/ZLib/trees.c
+ ${COMP}/ZLib/uncompr.c ${COMP}/ZLib/zutil.c)
+target_include_directories(compression
+ PUBLIC ${COMP} ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Include
+ PRIVATE ${COMP}/LZHCompress/CompLibHeader)
+# CompressionManager calls z_compress2/z_uncompress and BaseType.h owns 'Byte',
+# so zlib must be built with its Z_PREFIX renames on.
+target_compile_definitions(compression PRIVATE Z_PREFIX)
+
+# Round-trip check over every codec CompressionManager exposes.
+add_executable(compression_selfcheck ${COMP}/test_compression.cpp)
+target_link_libraries(compression_selfcheck PRIVATE compression)
+
+# Guards the hand-rolled Matrix3D::Get_Inverse that replaced D3DXMatrixInverse.
+add_executable(wwmath_selfcheck ${WW}/WWMath/test_inverse.cpp)
+target_include_directories(wwmath_selfcheck PRIVATE ${WW}/WWLib ${WW}/WWSaveLoad ${WW}/Wwutil)
+target_link_libraries(wwmath_selfcheck PRIVATE wwmath wwsaveload wwlib wwdebug)
+
+# ---- wwlib ----------------------------------------------------------------
+add_library(wwlib STATIC
+ ${WW}/WWLib/_convert.cpp ${WW}/WWLib/_mono.cpp ${WW}/WWLib/argv.cpp
+ ${WW}/WWLib/b64pipe.cpp ${WW}/WWLib/b64straw.cpp ${WW}/WWLib/base64.cpp
+ ${WW}/WWLib/blit.cpp ${WW}/WWLib/blowfish.cpp ${WW}/WWLib/buff.cpp
+ ${WW}/WWLib/bufffile.cpp ${WW}/WWLib/chunkio.cpp ${WW}/WWLib/convert.cpp
+ ${WW}/WWLib/cpudetect.cpp ${WW}/WWLib/crc.cpp ${WW}/WWLib/cstraw.cpp
+ ${WW}/WWLib/data.cpp ${WW}/WWLib/ddraw.cpp ${WW}/WWLib/dsurface.cpp
+ ${WW}/WWLib/Except.cpp ${WW}/WWLib/FastAllocator.cpp
+ ${WW}/WWLib/ffactory.cpp ${WW}/WWLib/gcd_lcm.cpp ${WW}/WWLib/hash.cpp
+ ${WW}/WWLib/hsv.cpp ${WW}/WWLib/ini.cpp ${WW}/WWLib/int.cpp
+ ${WW}/WWLib/jshell.cpp ${WW}/WWLib/keyboard.cpp ${WW}/WWLib/LaunchWeb.cpp
+ ${WW}/WWLib/lcw.cpp ${WW}/WWLib/load.cpp ${WW}/WWLib/mixfile.cpp
+ ${WW}/WWLib/mono.cpp ${WW}/WWLib/mpmath.cpp ${WW}/WWLib/mpu.cpp
+ ${WW}/WWLib/msgloop.cpp ${WW}/WWLib/multilist.cpp ${WW}/WWLib/mutex.cpp
+ ${WW}/WWLib/nstrdup.cpp ${WW}/WWLib/palette.cpp ${WW}/WWLib/pcx.cpp
+ ${WW}/WWLib/pipe.cpp ${WW}/WWLib/pk.cpp ${WW}/WWLib/ramfile.cpp
+ ${WW}/WWLib/random.cpp ${WW}/WWLib/rawfile.cpp ${WW}/WWLib/rc4.cpp
+ ${WW}/WWLib/rcfile.cpp ${WW}/WWLib/readline.cpp ${WW}/WWLib/realcrc.cpp
+ ${WW}/WWLib/refcount.cpp ${WW}/WWLib/registry.cpp ${WW}/WWLib/rgb.cpp
+ ${WW}/WWLib/rle.cpp ${WW}/WWLib/rndstrng.cpp ${WW}/WWLib/sampler.cpp
+ ${WW}/WWLib/sha.cpp ${WW}/WWLib/slnode.cpp ${WW}/WWLib/srandom.cpp
+ ${WW}/WWLib/stimer.cpp ${WW}/WWLib/straw.cpp ${WW}/WWLib/strtok_r.cpp
+ ${WW}/WWLib/systimer.cpp ${WW}/WWLib/tagblock.cpp ${WW}/WWLib/TARGA.CPP
+ ${WW}/WWLib/textfile.cpp ${WW}/WWLib/tgatodxt.cpp ${WW}/WWLib/thread.cpp
+ ${WW}/WWLib/trim.cpp ${WW}/WWLib/vector.cpp ${WW}/WWLib/verchk.cpp
+ ${WW}/WWLib/widestring.cpp ${WW}/WWLib/win.cpp ${WW}/WWLib/WWCOMUtil.cpp
+ ${WW}/WWLib/wwfile.cpp ${WW}/WWLib/wwfont.cpp ${WW}/WWLib/wwstring.cpp
+ ${WW}/WWLib/xpipe.cpp ${WW}/WWLib/xstraw.cpp ${WW}/WWLib/xsurface.cpp)
+target_include_directories(wwlib PUBLIC ${WW}/WWLib PRIVATE ${WW}/WWMath ${WW}/Wwutil)
+target_link_libraries(wwlib PRIVATE wwdebug PUBLIC winmm) # timeGetTime/timeBeginPeriod
+
+# ---- wwsaveload -----------------------------------------------------------
+add_library(wwsaveload STATIC
+ ${WW}/WWSaveLoad/definition.cpp ${WW}/WWSaveLoad/definitionfactory.cpp
+ ${WW}/WWSaveLoad/definitionfactorymgr.cpp ${WW}/WWSaveLoad/definitionmgr.cpp
+ ${WW}/WWSaveLoad/parameter.cpp ${WW}/WWSaveLoad/persistfactory.cpp
+ ${WW}/WWSaveLoad/pointerremap.cpp ${WW}/WWSaveLoad/saveload.cpp
+ ${WW}/WWSaveLoad/saveloadstatus.cpp ${WW}/WWSaveLoad/saveloadsubsystem.cpp
+ ${WW}/WWSaveLoad/twiddler.cpp ${WW}/WWSaveLoad/wwsaveload.cpp)
+target_include_directories(wwsaveload PUBLIC ${WW}/WWSaveLoad PRIVATE ${WW}/WWLib ${WW}/WWMath ${WW}/Wwutil)
+target_link_libraries(wwsaveload PRIVATE wwdebug wwlib wwmath)
diff --git a/GeneralsMD/Code/Libraries/Source/Compression/test_compression.cpp b/GeneralsMD/Code/Libraries/Source/Compression/test_compression.cpp
new file mode 100644
index 000000000..a1ecc53c9
--- /dev/null
+++ b/GeneralsMD/Code/Libraries/Source/Compression/test_compression.cpp
@@ -0,0 +1,55 @@
+// Round-trip self-check for CompressionManager over every codec it exposes.
+// Run the 'compression_selfcheck' target; "OK" per codec means pass.
+
+#include "Compression.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void)
+{
+ // Compressible-but-not-trivial payload: repeated text with a counter mixed in.
+ enum { SRC_LEN = 64 * 1024 };
+ static char src[SRC_LEN];
+ for (int i = 0; i < SRC_LEN; i++) {
+ src[i] = (char)("Command & Conquer Generals Zero Hour "[i % 37] + (i / 1024) % 7);
+ }
+
+ // Explicit list: COMPRESSION_MAX==COMPRESSION_REFPACK in the enum, so a
+ // MIN..MAX sweep would only cover NONE+REFPACK. Names are local because
+ // getCompressionNameByType's table also stops at COMPRESSION_MAX.
+ static const struct { CompressionType type; const char * name; } codecs[] = {
+ { COMPRESSION_REFPACK, "RefPack" }, { COMPRESSION_NOXLZH, "NoxLZH" },
+ { COMPRESSION_ZLIB1, "ZLib1" }, { COMPRESSION_ZLIB9, "ZLib9" },
+ { COMPRESSION_BTREE, "BTree" }, { COMPRESSION_HUFF, "Huff" },
+ };
+
+ int failures = 0;
+ for (int t = 0; t < (int)(sizeof(codecs) / sizeof(codecs[0])); t++) {
+ CompressionType type = codecs[t].type;
+ const char * name = codecs[t].name;
+
+ int max_out = CompressionManager::getMaxCompressedSize(SRC_LEN, type);
+ char * packed = (char *)malloc(max_out);
+ int packed_len = CompressionManager::compressData(type, src, SRC_LEN, packed, max_out);
+ if (packed_len <= 0) {
+ printf("FAIL %-12s compressData returned %d\n", name, packed_len);
+ failures++; free(packed); continue;
+ }
+
+ static char unpacked[SRC_LEN];
+ memset(unpacked, 0, SRC_LEN);
+ int unpacked_len = CompressionManager::decompressData(packed, packed_len, unpacked, SRC_LEN);
+ if (unpacked_len != SRC_LEN || memcmp(src, unpacked, SRC_LEN) != 0) {
+ printf("FAIL %-12s roundtrip: %d bytes back, expected %d\n", name, unpacked_len, SRC_LEN);
+ failures++; free(packed); continue;
+ }
+
+ printf("OK %-12s %d -> %d bytes\n", name, SRC_LEN, packed_len);
+ free(packed);
+ }
+
+ if (failures) { printf("%d codec(s) FAILED\n", failures); return 1; }
+ printf("all codecs OK\n");
+ return 0;
+}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp
index defb02601..88e542f16 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp
@@ -95,7 +95,7 @@ static unsigned FreeCount;
** Name for each memory category. I'm padding the array with some "undefined" strings in case
** someone forgets to set the name when adding a new category.
*/
-static char * _MemoryCategoryNames[] =
+static const char * _MemoryCategoryNames[] =
{
"UNKNOWN",
"Geometry",
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp
index 37f3fd64c..18a1f7a3f 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp
@@ -434,7 +434,8 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
/*
** Match the exception type with the error string and print it out
*/
- for (int i=0 ; _codes[i] != 0xffffffff ; i++) {
+ int i; // used after the loop to index _code_txt, so it can't be loop-scoped
+ for (i=0 ; _codes[i] != 0xffffffff ; i++) {
if (_codes[i] == e_info->ExceptionRecord->ExceptionCode) {
DebugString("Exception Handler: Found exception description\n");
break;
@@ -611,7 +612,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
Add_Txt(scrap);
sprintf(scrap, " Data Selector: %08x\r\n", context->FloatSave.DataSelector);
Add_Txt(scrap);
- sprintf(scrap, " Cr0NpxState: %08x\r\n", context->FloatSave.Cr0NpxState);
+ sprintf(scrap, " Cr0NpxState: %08x\r\n", context->FloatSave.Spare0); // SDK renamed Cr0NpxState -> Spare0
Add_Txt(scrap);
for (int fp=0 ; fp<SIZE_OF_80387_REGISTERS / 10 ; fp++) {
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/INDEX.H b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/INDEX.H
index d9b908cef..0fa548e23 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/INDEX.H
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/INDEX.H
@@ -695,7 +695,7 @@ template<class INDEX, class T>
#ifdef __BORLANDC__
NodeElement const * IndexClass<INDEX, T>::Search_For_Node(INDEX const & id) const
#else
-IndexClass<INDEX, T>::NodeElement const * IndexClass<INDEX, T>::Search_For_Node(INDEX const & id) const
+typename IndexClass<INDEX, T>::NodeElement const * IndexClass<INDEX, T>::Search_For_Node(INDEX const & id) const
#endif
{
/*
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h
index 6a60faa6d..8648231f7 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/always.h
@@ -93,8 +93,10 @@
// additional overloads for 'placement new'
//inline void* __cdecl operator new (size_t s, void *p) { return p; }
//inline void __cdecl operator delete (void *, void *p) { }
+#if !defined(_MSC_VER) || _MSC_VER < 1300 // VC7+ <new> already defines array placement new/delete
inline void* __cdecl operator new[] (size_t s, void *p) { return p; }
inline void __cdecl operator delete[] (void *, void *p) { }
+#endif
#endif
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp
index 071830b05..6cbfd1da1 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/mixfile.cpp
@@ -361,7 +361,7 @@ MixFileFactoryClass::Flush_Changes (void)
//
// Add the new files that are pending
//
- for (index = 0; index < PendingAddFileList.Count (); index ++) {
+ for (int index = 0; index < PendingAddFileList.Count (); index ++) {
new_mix_file.Add_File (PendingAddFileList[index].FullPath, PendingAddFileList[index].Filename);
}
}
@@ -454,7 +454,7 @@ bool MixFileFactoryClass::Build_Ordered_Filename_List (DynamicVectorClass<String
// add names to output parameter
list.Clear();
list.Resize( name_list.Count());
- for (i = 0; i < local_file_info.Count(); ++i) {
+ for (int i = 0; i < local_file_info.Count(); ++i) {
list.Add(local_file_info[i].Filename);
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp
index b6c10ed60..c6010e6fc 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp
@@ -39,7 +39,6 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "sha.h"
-#include <iostream.h>
#include <stdlib.h>
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp
index c61c7d4e4..8d12e013b 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/wwmath.cpp
@@ -58,7 +58,7 @@ void WWMath::Init(void)
_FastAsinTable[a]=asin(cv);
}
- for (a=0;a<SIN_TABLE_SIZE;++a) {
+ for (int a=0;a<SIN_TABLE_SIZE;++a) {
float cv= (float)a * 2.0f * WWMATH_PI / SIN_TABLE_SIZE; //float(a-SIN_TABLE_SIZE/2)*(1.0f/(SIN_TABLE_SIZE/2));
_FastSinTable[a]=sin(cv);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp
index 17445fc77..2fe4a0306 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Wwutil/miscutil.cpp
@@ -47,7 +47,7 @@ LPCSTR cMiscUtil::Get_Text_Time(void)
// Note: BoundsChecker reports 2 memory leaks in ctime here.
//
- long time_now = ::time(NULL);
+ time_t time_now = ::time(NULL); // time_t is 64-bit now, no longer a long
char * time_str = ::ctime(&time_now);
time_str[::strlen(time_str) - 1] = 0; // remove \n
return time_str;