From 3836a55efb99002a7ebeb50b1e344eeb03c78ea2 Mon Sep 17 00:00:00 2001
From: stm <14291421+stephanmeesters@users.noreply.github.com>
Date: Tue, 13 Jan 2026 17:20:50 +0100
Subject: [PATCH 1/5] feat: Add simulation math CRC utility
---
Core/GameEngine/CMakeLists.txt | 2 +
.../Include/Common/SimulationMathCrc.h | 28 +++++++
.../Source/Common/SimulationMathCrc.cpp | 79 +++++++++++++++++++
.../GameEngine/Source/Common/CommandLine.cpp | 10 +++
4 files changed, 119 insertions(+)
create mode 100644 Core/GameEngine/Include/Common/SimulationMathCrc.h
create mode 100644 Core/GameEngine/Source/Common/SimulationMathCrc.cpp
diff --git a/Core/GameEngine/CMakeLists.txt b/Core/GameEngine/CMakeLists.txt
index eb7b7541e14..533dfa487ee 100644
--- a/Core/GameEngine/CMakeLists.txt
+++ b/Core/GameEngine/CMakeLists.txt
@@ -118,6 +118,7 @@ set(GAMEENGINE_SRC
# Include/Common/StatsCollector.h
# Include/Common/STLTypedefs.h
Include/Common/StreamingArchiveFile.h
+ Include/Common/SimulationMathCrc.h
# Include/Common/SubsystemInterface.h
# Include/Common/SystemInfo.h
# Include/Common/Team.h
@@ -582,6 +583,7 @@ set(GAMEENGINE_SRC
# Source/Common/GameMain.cpp
Source/Common/GameUtility.cpp
# Source/Common/GlobalData.cpp
+ Source/Common/SimulationMathCrc.cpp
# Source/Common/INI/INI.cpp
# Source/Common/INI/INIAiData.cpp
# Source/Common/INI/INIAnimation.cpp
diff --git a/Core/GameEngine/Include/Common/SimulationMathCrc.h b/Core/GameEngine/Include/Common/SimulationMathCrc.h
new file mode 100644
index 00000000000..c813556085f
--- /dev/null
+++ b/Core/GameEngine/Include/Common/SimulationMathCrc.h
@@ -0,0 +1,28 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2026 TheSuperHackers
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see .
+*/
+
+#pragma once
+
+#include "Lib/BaseType.h"
+
+class SimulationMathCrc
+{
+public:
+ static UnsignedInt calculate();
+ static void print();
+};
diff --git a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
new file mode 100644
index 00000000000..80bcfa400e8
--- /dev/null
+++ b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
@@ -0,0 +1,79 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2026 TheSuperHackers
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see .
+*/
+
+#include "PreRTS.h"
+
+#include "Common/SimulationMathCrc.h"
+#include "Common/XferCRC.h"
+#include "WWMath/matrix3d.h"
+#include "WWMath/wwmath.h"
+
+#include
+#include
+
+static void append_matrix_crc(XferCRC &xfer)
+{
+ Matrix3D matrix;
+ Matrix3D factors_matrix;
+
+ matrix.Set(
+ 4.1f, 1.2f, 0.3f, 0.4f,
+ 0.5f, 3.6f, 0.7f, 0.8f,
+ 0.9f, 1.0f, 2.1f, 1.2f);
+
+ factors_matrix.Set(
+ WWMath::Sin(0.7f) * log10f(2.3f),
+ WWMath::Cos(1.1f) * powf(1.1f, 2.0f),
+ tanf(0.3f),
+ asinf(0.9673022627830505),
+ acosf(0.9673022627830505),
+ atanf(0.9673022627830505) * powf(1.1f, 2.0f),
+ atan2f(0.4f, 1.3f),
+ sinhf(0.2f),
+ coshf(0.4f) * tanhf(0.5f),
+ sqrtf(55788.84375),
+ expf(0.1f) * log10f(2.3f),
+ logf(1.4f));
+
+ Matrix3D::Multiply(matrix, factors_matrix, &matrix);
+ matrix.Get_Inverse(matrix);
+
+ xfer.xferMatrix3D(&matrix);
+}
+
+UnsignedInt SimulationMathCrc::calculate()
+{
+ XferCRC xfer;
+ xfer.open("SimulationMathCrc");
+
+ _fpreset();
+ // TheSuperHackers @info stm Use the same rounding mode as used in the game, this affects vc6 only.
+ _controlfp(0x000A001F, _MCW_RC | _MCW_PC | _MCW_EM);
+
+ append_matrix_crc(xfer);
+
+ _fpreset();
+
+ xfer.close();
+
+ return xfer.getCRC();
+}
+
+void SimulationMathCrc::print() {
+ printf("Simulation CRC: %08X\n", calculate());
+}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 0ec260b3861..71e7b5720d4 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -30,6 +30,7 @@
#include "Common/CRCDebug.h"
#include "Common/LocalFileSystem.h"
#include "Common/Recorder.h"
+#include "Common/SimulationMathCrc.h"
#include "Common/version.h"
#include "GameClient/ClientInstance.h"
#include "GameClient/TerrainVisual.h" // for TERRAIN_LOD_MIN definition
@@ -458,6 +459,13 @@ Int parseJobs(char *args[], int num)
return 1;
}
+Int parsePrintSimMathCrc(char *args[], int num)
+{
+ SimulationMathCrc::print();
+ exit(0);
+ return 1;
+}
+
Int parseXRes(char *args[], int num)
{
if (num > 1)
@@ -1163,6 +1171,8 @@ static CommandLineParam paramsForStartup[] =
// (If you have 4 cores, call it with -jobs 4)
// If you do not call this, all replays will be simulated in sequence in the same process.
{ "-jobs", parseJobs },
+
+ { "-printSimMathCrc", parsePrintSimMathCrc },
};
// These Params are parsed during Engine Init before INI data is loaded
From 60fe1d62b047db02b6ff62a746c1788eaa93a078 Mon Sep 17 00:00:00 2001
From: stm <14291421+stephanmeesters@users.noreply.github.com>
Date: Wed, 14 Jan 2026 00:51:18 +0100
Subject: [PATCH 2/5] Style touchup
---
Core/GameEngine/Source/Common/SimulationMathCrc.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
index 80bcfa400e8..398e78e51bb 100644
--- a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
+++ b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
@@ -26,7 +26,7 @@
#include
#include
-static void append_matrix_crc(XferCRC &xfer)
+static void appendMatrixCrc(XferCRC &xfer)
{
Matrix3D matrix;
Matrix3D factors_matrix;
@@ -62,10 +62,10 @@ UnsignedInt SimulationMathCrc::calculate()
xfer.open("SimulationMathCrc");
_fpreset();
- // TheSuperHackers @info stm Use the same rounding mode as used in the game, this affects vc6 only.
+ // TheSuperHackers @info stm Use the same rounding mode as used in the game. This affects vc6 only.
_controlfp(0x000A001F, _MCW_RC | _MCW_PC | _MCW_EM);
- append_matrix_crc(xfer);
+ appendMatrixCrc(xfer);
_fpreset();
@@ -75,5 +75,5 @@ UnsignedInt SimulationMathCrc::calculate()
}
void SimulationMathCrc::print() {
- printf("Simulation CRC: %08X\n", calculate());
+ printf("Simulation Math CRC: %08X\n", calculate());
}
From dc7d4e1eac651e2fd9c88df11f3b689c54331525 Mon Sep 17 00:00:00 2001
From: stm <14291421+stephanmeesters@users.noreply.github.com>
Date: Mon, 19 Jan 2026 13:11:41 +0100
Subject: [PATCH 3/5] Remove command line option. Minor style touchup
---
Core/GameEngine/CMakeLists.txt | 4 ++--
Core/GameEngine/Source/Common/SimulationMathCrc.cpp | 5 -----
.../Code/GameEngine/Source/Common/CommandLine.cpp | 10 ----------
3 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/Core/GameEngine/CMakeLists.txt b/Core/GameEngine/CMakeLists.txt
index 533dfa487ee..fd155b1ab32 100644
--- a/Core/GameEngine/CMakeLists.txt
+++ b/Core/GameEngine/CMakeLists.txt
@@ -118,7 +118,7 @@ set(GAMEENGINE_SRC
# Include/Common/StatsCollector.h
# Include/Common/STLTypedefs.h
Include/Common/StreamingArchiveFile.h
- Include/Common/SimulationMathCrc.h
+ Include/Common/SimulationMathCrc.h
# Include/Common/SubsystemInterface.h
# Include/Common/SystemInfo.h
# Include/Common/Team.h
@@ -583,7 +583,7 @@ set(GAMEENGINE_SRC
# Source/Common/GameMain.cpp
Source/Common/GameUtility.cpp
# Source/Common/GlobalData.cpp
- Source/Common/SimulationMathCrc.cpp
+ Source/Common/SimulationMathCrc.cpp
# Source/Common/INI/INI.cpp
# Source/Common/INI/INIAiData.cpp
# Source/Common/INI/INIAnimation.cpp
diff --git a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
index 398e78e51bb..fc219ca3714 100644
--- a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
+++ b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
@@ -24,7 +24,6 @@
#include "WWMath/wwmath.h"
#include
-#include
static void appendMatrixCrc(XferCRC &xfer)
{
@@ -73,7 +72,3 @@ UnsignedInt SimulationMathCrc::calculate()
return xfer.getCRC();
}
-
-void SimulationMathCrc::print() {
- printf("Simulation Math CRC: %08X\n", calculate());
-}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 71e7b5720d4..0ec260b3861 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -30,7 +30,6 @@
#include "Common/CRCDebug.h"
#include "Common/LocalFileSystem.h"
#include "Common/Recorder.h"
-#include "Common/SimulationMathCrc.h"
#include "Common/version.h"
#include "GameClient/ClientInstance.h"
#include "GameClient/TerrainVisual.h" // for TERRAIN_LOD_MIN definition
@@ -459,13 +458,6 @@ Int parseJobs(char *args[], int num)
return 1;
}
-Int parsePrintSimMathCrc(char *args[], int num)
-{
- SimulationMathCrc::print();
- exit(0);
- return 1;
-}
-
Int parseXRes(char *args[], int num)
{
if (num > 1)
@@ -1171,8 +1163,6 @@ static CommandLineParam paramsForStartup[] =
// (If you have 4 cores, call it with -jobs 4)
// If you do not call this, all replays will be simulated in sequence in the same process.
{ "-jobs", parseJobs },
-
- { "-printSimMathCrc", parsePrintSimMathCrc },
};
// These Params are parsed during Engine Init before INI data is loaded
From e6b2bd5dcd3c01f2601b27f725fe1578d15f1909 Mon Sep 17 00:00:00 2001
From: stm <14291421+stephanmeesters@users.noreply.github.com>
Date: Mon, 19 Jan 2026 13:21:00 +0100
Subject: [PATCH 4/5] Fix header file
---
Core/GameEngine/Include/Common/SimulationMathCrc.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/Core/GameEngine/Include/Common/SimulationMathCrc.h b/Core/GameEngine/Include/Common/SimulationMathCrc.h
index c813556085f..0a3a0255e5f 100644
--- a/Core/GameEngine/Include/Common/SimulationMathCrc.h
+++ b/Core/GameEngine/Include/Common/SimulationMathCrc.h
@@ -24,5 +24,4 @@ class SimulationMathCrc
{
public:
static UnsignedInt calculate();
- static void print();
};
From 97dc9b74f30cd81fae8a637cad14e6917ff867ea Mon Sep 17 00:00:00 2001
From: stm <14291421+stephanmeesters@users.noreply.github.com>
Date: Thu, 29 Jan 2026 10:17:15 +0100
Subject: [PATCH 5/5] Update info comment
---
Core/GameEngine/Source/Common/SimulationMathCrc.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
index fc219ca3714..fbc2d89c839 100644
--- a/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
+++ b/Core/GameEngine/Source/Common/SimulationMathCrc.cpp
@@ -61,7 +61,7 @@ UnsignedInt SimulationMathCrc::calculate()
xfer.open("SimulationMathCrc");
_fpreset();
- // TheSuperHackers @info stm Use the same rounding mode as used in the game. This affects vc6 only.
+ // TheSuperHackers @info stephanmeesters 29/01/2026 Use the same rounding mode as used in the game. This affects vc6 only.
_controlfp(0x000A001F, _MCW_RC | _MCW_PC | _MCW_EM);
appendMatrixCrc(xfer);