diff --git a/Core/GameEngine/CMakeLists.txt b/Core/GameEngine/CMakeLists.txt index 8a7110946d6..51d40af1d4f 100644 --- a/Core/GameEngine/CMakeLists.txt +++ b/Core/GameEngine/CMakeLists.txt @@ -21,8 +21,8 @@ set(GAMEENGINE_SRC # Include/Common/CDManager.h # Include/Common/ClientUpdateModule.h # Include/Common/CommandLine.h -# Include/Common/crc.h -# Include/Common/CRCDebug.h + Include/Common/crc.h + Include/Common/CRCDebug.h # Include/Common/CriticalSection.h # Include/Common/CustomMatchPreferences.h # Include/Common/DamageFX.h @@ -564,8 +564,8 @@ set(GAMEENGINE_SRC # Source/Common/Bezier/BezierSegment.cpp # Source/Common/BitFlags.cpp # Source/Common/CommandLine.cpp -# Source/Common/crc.cpp -# Source/Common/CRCDebug.cpp + Source/Common/crc.cpp + Source/Common/CRCDebug.cpp # Source/Common/DamageFX.cpp # Source/Common/Dict.cpp # Source/Common/DiscreteCircle.cpp diff --git a/GeneralsMD/Code/GameEngine/Include/Common/CRCDebug.h b/Core/GameEngine/Include/Common/CRCDebug.h similarity index 100% rename from GeneralsMD/Code/GameEngine/Include/Common/CRCDebug.h rename to Core/GameEngine/Include/Common/CRCDebug.h diff --git a/GeneralsMD/Code/GameEngine/Include/Common/crc.h b/Core/GameEngine/Include/Common/crc.h similarity index 100% rename from GeneralsMD/Code/GameEngine/Include/Common/crc.h rename to Core/GameEngine/Include/Common/crc.h diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CRCDebug.cpp b/Core/GameEngine/Source/Common/CRCDebug.cpp similarity index 100% rename from GeneralsMD/Code/GameEngine/Source/Common/CRCDebug.cpp rename to Core/GameEngine/Source/Common/CRCDebug.cpp diff --git a/GeneralsMD/Code/GameEngine/Source/Common/crc.cpp b/Core/GameEngine/Source/Common/crc.cpp similarity index 100% rename from GeneralsMD/Code/GameEngine/Source/Common/crc.cpp rename to Core/GameEngine/Source/Common/crc.cpp diff --git a/Generals/Code/GameEngine/CMakeLists.txt b/Generals/Code/GameEngine/CMakeLists.txt index c0d605965bd..d3f4e7379be 100644 --- a/Generals/Code/GameEngine/CMakeLists.txt +++ b/Generals/Code/GameEngine/CMakeLists.txt @@ -19,8 +19,8 @@ set(GAMEENGINE_SRC Include/Common/CDManager.h Include/Common/ClientUpdateModule.h Include/Common/CommandLine.h - Include/Common/crc.h - Include/Common/CRCDebug.h +# Include/Common/crc.h +# Include/Common/CRCDebug.h Include/Common/CriticalSection.h Include/Common/CustomMatchPreferences.h Include/Common/DamageFX.h @@ -523,8 +523,8 @@ set(GAMEENGINE_SRC Source/Common/Bezier/BezierSegment.cpp Source/Common/BitFlags.cpp Source/Common/CommandLine.cpp - Source/Common/crc.cpp - Source/Common/CRCDebug.cpp +# Source/Common/crc.cpp +# Source/Common/CRCDebug.cpp Source/Common/DamageFX.cpp Source/Common/Dict.cpp Source/Common/DiscreteCircle.cpp diff --git a/Generals/Code/GameEngine/Include/Common/CRCDebug.h b/Generals/Code/GameEngine/Include/Common/CRCDebug.h deleted file mode 100644 index 6a0d7e2f267..00000000000 --- a/Generals/Code/GameEngine/Include/Common/CRCDebug.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// CRCDebug.h /////////////////////////////////////////////////////////////// -// Macros/functions/etc to help logging values for tracking down sync errors -// Author: Matthew D. Campbell, June 2002 - -// no #pragma once - we want to be able to conditionally define NO_DEBUG_CRC in indiv .cpp files - -#ifndef __CRCDEBUG_H__ -#define __CRCDEBUG_H__ - -#include "Common/Debug.h" - -#ifndef NO_DEBUG_CRC - #ifdef DEBUG_LOGGING - #define DEBUG_CRC - #endif -#endif - -#ifdef DEBUG_CRC - -#include "Common/AsciiString.h" -#include "GameLogic/GameLogic.h" -#include "Lib/BaseType.h" -#include "WWMath/vector3.h" -#include "WWMath/matrix3d.h" - - #define AS_INT(x) (*(Int *)(&x)) - #define DUMPVEL DUMPCOORD3DNAMED(&m_vel, "m_vel") - #define DUMPACCEL DUMPCOORD3DNAMED(&m_accel, "m_accel") - #define DUMPVECTOR3(x) DUMPVECTOR3NAMED(x, #x) - #define DUMPVECTOR3NAMED(x, y) dumpVector3(x, y, __FILE__, __LINE__) - #define DUMPCOORD3D(x) DUMPCOORD3DNAMED(x, #x) - #define DUMPCOORD3DNAMED(x, y) dumpCoord3D(x, y, __FILE__, __LINE__) - #define DUMPMATRIX3D(x) DUMPMATRIX3DNAMED(x, #x) - #define DUMPMATRIX3DNAMED(x, y) dumpMatrix3D(x, y, __FILE__, __LINE__) - #define DUMPREAL(x) DUMPREALNAMED(x, #x) - #define DUMPREALNAMED(x, y) dumpReal(x, y, __FILE__, __LINE__) - - extern Int TheCRCFirstFrameToLog; - extern UnsignedInt TheCRCLastFrameToLog; - - void dumpVector3(const Vector3 *v, AsciiString name, AsciiString fname, Int line); - void dumpCoord3D(const Coord3D *c, AsciiString name, AsciiString fname, Int line); - void dumpMatrix3D(const Matrix3D *m, AsciiString name, AsciiString fname, Int line); - void dumpReal(Real r, AsciiString name, AsciiString fname, Int line); - - void outputCRCDebugLines( void ); - void CRCDebugStartNewGame( void ); - void outputCRCDumpLines( void ); - - void addCRCDebugLine(const char *fmt, ...); - void addCRCDebugLineNoCounter(const char *fmt, ...); - void addCRCDumpLine(const char *fmt, ...); - void addCRCGenLine(const char *fmt, ...); - #define CRCDEBUG_LOG(x) addCRCDebugLine x - #define CRCDUMP_LOG(x) addCRCDumpLine x - #define CRCGEN_LOG(x) addCRCGenLine x - - class CRCVerification - { - public: - CRCVerification(); - ~CRCVerification(); - protected: - UnsignedInt m_startCRC; - }; - #define VERIFY_CRC CRCVerification crcVerification; - - extern Int lastCRCDebugFrame; - extern Int lastCRCDebugIndex; - - extern Bool g_verifyClientCRC; - extern Bool g_clientDeepCRC; - - extern Bool g_crcModuleDataFromClient; - extern Bool g_crcModuleDataFromLogic; - - extern Bool g_keepCRCSaves; - extern Bool g_saveDebugCRCPerFrame; - extern AsciiString g_saveDebugCRCPerFrameDir; - - extern Bool g_logObjectCRCs; - -#else // DEBUG_CRC - - #define DUMPVEL {} - #define DUMPACCEL {} - #define DUMPVECTOR3(x) {} - #define DUMPVECTOR3NAMED(x, y) {} - #define DUMPCOORD3D(x) {} - #define DUMPCOORD3DNAMED(x, y) {} - #define DUMPMATRIX3D(x) {} - #define DUMPMATRIX3DNAMED(x, y) {} - - #define DUMPREAL(x) {} - #define DUMPREALNAMED(x, y) {} - - #define CRCDEBUG_LOG(x) {} - #define CRCDUMP_LOG(x) {} - #define CRCGEN_LOG(x) {} - - #define VERIFY_CRC {} - -#endif - -extern Int NET_CRC_INTERVAL; -extern Int REPLAY_CRC_INTERVAL; -extern Bool TheDebugIgnoreSyncErrors; - -#endif // __CRCDEBUG_H__ \ No newline at end of file diff --git a/Generals/Code/GameEngine/Include/Common/crc.h b/Generals/Code/GameEngine/Include/Common/crc.h deleted file mode 100644 index 5b05c92f2ad..00000000000 --- a/Generals/Code/GameEngine/Include/Common/crc.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// CRC.h /////////////////////////////////////////////////////////////// -// A class encapsulating CRC calculation -// Author: Matthew D. Campbell, October 2001 - -#pragma once - -#ifndef _CRC_H_ -#define _CRC_H_ - -#include "Lib/BaseType.h" - -#ifdef RTS_DEBUG - -//#include "winsock2.h" // for htonl - -class CRC -{ -public: - CRC() { crc = 0; } - - void computeCRC( const void *buf, Int len ); ///< Compute the CRC for a buffer, added into current CRC - void clear( void ) { crc = 0; } ///< Clears the CRC to 0 -// UnsignedInt get( void ) { return htonl(crc); } ///< Get the combined CRC - UnsignedInt get( void ); - -#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC - void set( UnsignedInt v ) - { - crc = v; - } -#endif - -private: - void addCRC( UnsignedByte val ); ///< CRC a 4-byte block - - UnsignedInt crc; -}; - -#else - -// optimized inline only version -class CRC -{ -public: - CRC(void) { crc=0; } - - /// Compute the CRC for a buffer, added into current CRC - __forceinline void computeCRC( const void *buf, Int len ) - { - if (!buf||len<1) - return; - -#if !(defined(_MSC_VER) && _MSC_VER < 1300) - // C++ version left in for reference purposes - for (UnsignedByte *uintPtr=(UnsignedByte *)buf;len>0;len--,uintPtr++) - { - int hibit; - if (crc & 0x80000000) - { - hibit = 1; - } - else - { - hibit = 0; - } - - crc <<= 1; - crc += *uintPtr; - crc += hibit; - } -#else - // ASM version, verified by comparing resulting data with C++ version data - unsigned *crcPtr=&crc; - _asm - { - mov esi,[buf] - mov ecx,[len] - dec ecx - mov edi,[crcPtr] - mov ebx,dword ptr [edi] - xor eax,eax - lp: - mov al,byte ptr [esi] - shl ebx,1 - inc esi - adc ebx,eax - dec ecx - jns lp - mov dword ptr [edi],ebx - }; -#endif - } - - /// Clears the CRC to 0 - void clear( void ) - { - crc = 0; - } - - ///< Get the combined CRC - UnsignedInt get( void ) const - { - return crc; - } - -#if (defined(_MSC_VER) && _MSC_VER < 1300) && RETAIL_COMPATIBLE_CRC - void set( UnsignedInt v ) - { - crc = v; - } -#endif - -private: - UnsignedInt crc; -}; - -#endif - -#endif // _CRC_H_ diff --git a/Generals/Code/GameEngine/Source/Common/CRCDebug.cpp b/Generals/Code/GameEngine/Source/Common/CRCDebug.cpp deleted file mode 100644 index e1401c394ce..00000000000 --- a/Generals/Code/GameEngine/Source/Common/CRCDebug.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - - -#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine - -#include "Common/CRCDebug.h" -#include "Common/Debug.h" -#include "Common/PerfTimer.h" -#include "Common/LocalFileSystem.h" -#include "GameClient/InGameUI.h" -#include "GameNetwork/IPEnumeration.h" -#include - - -#ifdef DEBUG_CRC - -static const Int MaxStrings = 64000; -static const Int MaxStringLen = 1024; - -static char DebugStrings[MaxStrings][MaxStringLen]; -static Int nextDebugString = 0; -static Int numDebugStrings = 0; -//static char DumpStrings[MaxStrings][MaxStringLen]; -//static Int nextDumpString = 0; -//static Int numDumpStrings = 0; - -#define IS_FRAME_OK_TO_LOG TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() && !TheDebugIgnoreSyncErrors && \ - TheCRCFirstFrameToLog >= 0 && TheCRCFirstFrameToLog <= TheGameLogic->getFrame() \ - && TheGameLogic->getFrame() <= TheCRCLastFrameToLog - -CRCVerification::CRCVerification() -{ -#ifdef DEBUG_LOGGING -/**/ - if (g_verifyClientCRC && (IS_FRAME_OK_TO_LOG)) - { - m_startCRC = TheGameLogic->getCRC(CRC_RECALC, (g_clientDeepCRC)?"clientPre.crc":""); - } - else - { - m_startCRC = 0; - } -/**/ -#endif -} - -CRCVerification::~CRCVerification() -{ -#ifdef DEBUG_LOGGING -/**/ - UnsignedInt endCRC = 0; - if (g_verifyClientCRC && (IS_FRAME_OK_TO_LOG)) - { - endCRC = TheGameLogic->getCRC(CRC_RECALC, (g_clientDeepCRC)?"clientPost.crc":""); - } - DEBUG_ASSERTCRASH(!TheGameLogic->isInGame() || m_startCRC == endCRC, ("GameLogic changed outside of GameLogic::update() on frame %d!", TheGameLogic->getFrame())); - if (TheGameLogic->isInMultiplayerGame() && m_startCRC != endCRC) - { - if (TheInGameUI) - { - TheInGameUI->message(UnicodeString(L"GameLogic changed outside of GameLogic::update() - call Matt (x36804)!")); - } - CRCDEBUG_LOG(("GameLogic changed outside of GameLogic::update()!!!")); - } -/**/ -#endif -} - -void outputCRCDebugLines( void ) -{ - IPEnumeration ips; - AsciiString fname; - fname.format("crcDebug%s.txt", ips.getMachineName().str()); - FILE *fp = fopen(fname.str(), "wt"); - int start = 0; - int end = nextDebugString; - if (numDebugStrings >= MaxStrings) - start = nextDebugString - MaxStrings; - - for (Int i=start; iisInShellGame()) - return; - if (g_saveDebugCRCPerFrame) - { - // Create folder for frame data, if it doesn't exist yet. - CreateDirectory(g_saveDebugCRCPerFrameDir.str(), NULL); - - // Delete existing files - FilenameList files; - AsciiString dir = g_saveDebugCRCPerFrameDir; - dir.concat("/"); - TheLocalFileSystem->getFileListInDirectory(dir.str(), "", "DebugFrame_*.txt", files, FALSE); - FilenameList::iterator it; - for (it = files.begin(); it != files.end(); ++it) - { - DeleteFile(it->str()); - } - } - nextDebugString = 0; - numDebugStrings = 0; - lastCRCDebugFrame = 0; - lastCRCDebugIndex = 0; -} - -static void outputCRCDebugLinesPerFrame() -{ - if (!g_saveDebugCRCPerFrame || numDebugStrings == 0) - return; - AsciiString fname; - fname.format("%s/DebugFrame_%06d.txt", g_saveDebugCRCPerFrameDir.str(), lastCRCDebugFrame); - FILE *fp = fopen(fname.str(), "wt"); - int start = 0; - int end = nextDebugString; - if (numDebugStrings >= MaxStrings) - start = nextDebugString - MaxStrings; - nextDebugString = 0; - numDebugStrings = 0; - if (!fp) - return; - - for (Int i=start; i= MaxStrings) - start = nextDumpString - MaxStrings; - - for (Int i=start; igetFrame()) - { - outputCRCDebugLinesPerFrame(); - lastCRCDebugFrame = TheGameLogic->getFrame(); - lastCRCDebugIndex = 0; - } - - if (count) - sprintf(DebugStrings[nextDebugString], "%d:%05d ", TheGameLogic->getFrame(), lastCRCDebugIndex++); - else - DebugStrings[nextDebugString][0] = 0; - Int len = strlen(DebugStrings[nextDebugString]); - - vsnprintf(DebugStrings[nextDebugString]+len, MaxStringLen-len, fmt, args); - - char *tmp = DebugStrings[nextDebugString]; - while (tmp && *tmp) - { - if (*tmp == '\r' || *tmp == '\n') - { - *tmp = ' '; - } - ++tmp; - } - - //DEBUG_LOG(("%s", DebugStrings[nextDebugString])); - - ++nextDebugString; - ++numDebugStrings; - if (nextDebugString == MaxStrings) - nextDebugString = 0; -} - -void addCRCDebugLine(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - addCRCDebugLineInternal(true, fmt, args); - va_end(args); -} - -void addCRCDebugLineNoCounter(const char *fmt, ...) -{ - // TheSuperHackers @feature helmutbuhler 04/09/2025 - // This version doesn't increase the lastCRCDebugIndex counter - // and can be used for logging lines that don't necessarily match up on all peers. - // (Otherwise the numbers would no longer match up and the diff would be very difficult to read) - va_list args; - va_start(args, fmt); - addCRCDebugLineInternal(false, fmt, args); - va_end(args); -} - -void addCRCGenLine(const char *fmt, ...) -{ - if (!(IS_FRAME_OK_TO_LOG)) - return; - - static char buf[MaxStringLen]; - va_list va; - va_start( va, fmt ); - vsnprintf(buf, MaxStringLen, fmt, va ); - va_end( va ); - addCRCDebugLine("%s", buf); - - //DEBUG_LOG(("%s", buf)); -} - -void addCRCDumpLine(const char *fmt, ...) -{ - /* - va_list va; - va_start( va, fmt ); - vsnprintf(DumpStrings[nextDumpString], MaxStringLen, fmt, va ); - va_end( va ); - - ++nextDumpString; - ++numDumpStrings; - if (nextDumpString == MaxStrings) - nextDumpString = 0; - */ -} - -void dumpVector3(const Vector3 *v, AsciiString name, AsciiString fname, Int line) -{ - if (!(IS_FRAME_OK_TO_LOG)) return; - fname.toLower(); - fname = getFname(fname); - addCRCDebugLine("dumpVector3() %s:%d %s %8.8X %8.8X %8.8X", - fname.str(), line, name.str(), - AS_INT(v->X), AS_INT(v->Y), AS_INT(v->Z)); -} - -void dumpCoord3D(const Coord3D *c, AsciiString name, AsciiString fname, Int line) -{ - if (!(IS_FRAME_OK_TO_LOG)) return; - fname.toLower(); - fname = getFname(fname); - addCRCDebugLine("dumpCoord3D() %s:%d %s %8.8X %8.8X %8.8X", - fname.str(), line, name.str(), - AS_INT(c->x), AS_INT(c->y), AS_INT(c->z)); -} - -void dumpMatrix3D(const Matrix3D *m, AsciiString name, AsciiString fname, Int line) -{ - if (!(IS_FRAME_OK_TO_LOG)) return; - fname.toLower(); - fname = getFname(fname); - const Real *matrix = (const Real *)m; - addCRCDebugLine("dumpMatrix3D() %s:%d %s", - fname.str(), line, name.str()); - for (Int i=0; i<3; ++i) - addCRCDebugLine(" 0x%08X 0x%08X 0x%08X 0x%08X", - AS_INT(matrix[(i<<2)+0]), AS_INT(matrix[(i<<2)+1]), AS_INT(matrix[(i<<2)+2]), AS_INT(matrix[(i<<2)+3])); -} - -void dumpReal(Real r, AsciiString name, AsciiString fname, Int line) -{ - if (!(IS_FRAME_OK_TO_LOG)) return; - fname.toLower(); - fname = getFname(fname); - addCRCDebugLine("dumpReal() %s:%d %s %8.8X (%f)", - fname.str(), line, name.str(), AS_INT(r), r); -} - -#endif // DEBUG_CRC diff --git a/Generals/Code/GameEngine/Source/Common/crc.cpp b/Generals/Code/GameEngine/Source/Common/crc.cpp deleted file mode 100644 index f3cbc369e2a..00000000000 --- a/Generals/Code/GameEngine/Source/Common/crc.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** 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 . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - - -#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine - -#include "Common/crc.h" -#include "Common/Debug.h" - -#ifdef RTS_DEBUG - -void CRC::addCRC( UnsignedByte val ) -{ - int hibit; - - //cout << "\t\t" << hex << val; -// val = htonl(val); - //cout << " / " << hex << val <