Skip to content

Commit 9c27651

Browse files
authored
bugfix(cpudetect): Fix issues caused by broken memory benchmark value (#1409)
1 parent 3a58ec4 commit 9c27651

File tree

14 files changed

+60
-49
lines changed

14 files changed

+60
-49
lines changed

Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ set(WWLIB_SRC
131131
widestring.cpp
132132
widestring.h
133133
win.h
134+
WWCommon.h
134135
wwfile.cpp
135136
WWFILE.H
136137
wwstring.cpp
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#if defined(_MSC_VER) && _MSC_VER < 1300
22+
typedef unsigned MemValueType;
23+
#else
24+
typedef unsigned long long MemValueType;
25+
#endif

Core/Libraries/Source/WWVegas/WWLib/always.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#ifndef ALWAYS_H
4141
#define ALWAYS_H
4242

43+
#include "WWCommon.h"
44+
4345
#include <assert.h>
4446
#include <new>
4547

Core/Libraries/Source/WWVegas/WWLib/cpudetect.h

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,12 @@ class CPUDetectClass
194194
static unsigned Get_L1_Instruction_Trace_Cache_Set_Associative() { return L1InstructionTraceCacheSetAssociative; }
195195

196196
// System memory
197-
198-
#if defined(_MSC_VER) && _MSC_VER < 1300
199-
static unsigned Get_Total_Physical_Memory() { return TotalPhysicalMemory; }
200-
static unsigned Get_Available_Physical_Memory() { return AvailablePhysicalMemory; }
201-
static unsigned Get_Total_Page_File_Size() { return TotalPageMemory; }
202-
static unsigned Get_Available_Page_File_Size() { return AvailablePageMemory; }
203-
static unsigned Get_Total_Virtual_Memory() { return TotalVirtualMemory; }
204-
static unsigned Get_Available_Virtual_Memory() { return AvailableVirtualMemory; }
205-
#else
206-
static unsigned long long Get_Total_Physical_Memory() { return TotalPhysicalMemory; }
207-
static unsigned long long Get_Available_Physical_Memory() { return AvailablePhysicalMemory; }
208-
static unsigned long long Get_Total_Page_File_Size() { return TotalPageMemory; }
209-
static unsigned long long Get_Available_Page_File_Size() { return AvailablePageMemory; }
210-
static unsigned long long Get_Total_Virtual_Memory() { return TotalVirtualMemory; }
211-
static unsigned long long Get_Available_Virtual_Memory() { return AvailableVirtualMemory; }
212-
#endif
197+
static MemValueType Get_Total_Physical_Memory() { return TotalPhysicalMemory; }
198+
static MemValueType Get_Available_Physical_Memory() { return AvailablePhysicalMemory; }
199+
static MemValueType Get_Total_Page_File_Size() { return TotalPageMemory; }
200+
static MemValueType Get_Available_Page_File_Size() { return AvailablePageMemory; }
201+
static MemValueType Get_Total_Virtual_Memory() { return TotalVirtualMemory; }
202+
static MemValueType Get_Available_Virtual_Memory() { return AvailableVirtualMemory; }
213203

214204
static unsigned Get_Processor_Type() { return ProcessorType; }
215205

@@ -288,21 +278,14 @@ class CPUDetectClass
288278
// L1 instruction trace cache information
289279
static unsigned L1InstructionTraceCacheSize;
290280
static unsigned L1InstructionTraceCacheSetAssociative;
291-
#if defined(_MSC_VER) && _MSC_VER < 1300
292-
static unsigned TotalPhysicalMemory;
293-
static unsigned AvailablePhysicalMemory;
294-
static unsigned TotalPageMemory;
295-
static unsigned AvailablePageMemory;
296-
static unsigned TotalVirtualMemory;
297-
static unsigned AvailableVirtualMemory;
298-
#else
299-
static unsigned long long TotalPhysicalMemory;
300-
static unsigned long long AvailablePhysicalMemory;
301-
static unsigned long long TotalPageMemory;
302-
static unsigned long long AvailablePageMemory;
303-
static unsigned long long TotalVirtualMemory;
304-
static unsigned long long AvailableVirtualMemory;
305-
#endif
281+
282+
static MemValueType TotalPhysicalMemory;
283+
static MemValueType AvailablePhysicalMemory;
284+
static MemValueType TotalPageMemory;
285+
static MemValueType AvailablePageMemory;
286+
static MemValueType TotalVirtualMemory;
287+
static MemValueType AvailableVirtualMemory;
288+
306289
static unsigned OSVersionNumberMajor;
307290
static unsigned OSVersionNumberMinor;
308291
static unsigned OSVersionBuildNumber;

Generals/Code/GameEngine/Include/Common/GameCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
// ----------------------------------------------------------------------------------------------
5454
#include "Lib/BaseType.h"
55+
#include "WWCommon.h"
5556
#include "Common/GameDefines.h"
5657

5758
// ----------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Include/Common/GameLOD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class GameLODManager
213213
StaticGameLODLevel m_idealDetailLevel;
214214
ChipsetType m_videoChipType;
215215
CpuType m_cpuType;
216-
Int m_numRAM;
216+
MemValueType m_numRAM;
217217
Int m_cpuFreq;
218218
Real m_intBenchIndex;
219219
Real m_floatBenchIndex;

Generals/Code/GameEngine/Source/Common/GameLOD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define PROFILE_ERROR_LIMIT 0.94f //fraction of profiled result needed to get a match. Allows some room for error/fluctuation.
4646

4747
//Hack to get access to a static method on the W3DDevice side. -MW
48-
extern Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);
48+
extern Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, MemValueType *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);
4949

5050
GameLODManager *TheGameLODManager=NULL;
5151

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class W3DShaderManager
8888
/// Loads a .vso file and creates a vertex shader for it
8989
static HRESULT LoadAndCreateD3DShader(const char* strFilePath, const DWORD* pDeclaration, DWORD Usage, Bool ShaderType, DWORD* pHandle);
9090

91-
static Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);
91+
static Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, MemValueType *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);
9292
static StaticGameLODLevel getGPUPerformanceIndex(void);
9393
static Real GetCPUBenchTime(void);
9494

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
#include "Common/GameLOD.h"
7272
#include "d3dx8tex.h"
7373
#include "dx8caps.h"
74-
#include "Common/GameLOD.h"
7574

7675

7776
/** Interface definition for custom shaders we define in our app. These shaders can perform more complex
@@ -2801,12 +2800,12 @@ HRESULT W3DShaderManager::LoadAndCreateD3DShader(const char* strFilePath, const
28012800
#define MIN_ACCEPTED_TEXTURE_MEMORY (1024*1024*30) //30 MB
28022801

28032802
/**Hack to give gameengine access to this function*/
2804-
Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex)
2803+
Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, MemValueType *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex)
28052804
{
28062805
return W3DShaderManager::testMinimumRequirements(videoChipType,cpuType,cpuFreq,numRAM,intBenchIndex,floatBenchIndex,memBenchIndex);
28072806
}
28082807

2809-
Bool W3DShaderManager::testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex)
2808+
Bool W3DShaderManager::testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, MemValueType *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex)
28102809
{
28112810
if (videoChipType)
28122811
*videoChipType = getChipset();
@@ -2838,11 +2837,11 @@ Bool W3DShaderManager::testMinimumRequirements(ChipsetType *videoChipType, CpuTy
28382837

28392838
if (intBenchIndex && floatBenchIndex && memBenchIndex)
28402839
{
2841-
// TheSuperHackers @tweak Aliendroid1 19/06/2025 Legacy benchmarking code was removed.
2842-
// Since modern hardware always meets the minimum requirements, we preset the benchmark "results" to a high value.
2843-
*intBenchIndex = 10.0f;
2840+
// TheSuperHackers @tweak Aliendroid1 19/06/2025 Legacy benchmarking code was removed.
2841+
// Since modern hardware always meets the minimum requirements, we preset the benchmark "results" to a high value.
2842+
*intBenchIndex = 10.0f;
28442843
*floatBenchIndex = 10.0f;
2845-
*memBenchIndex = 10.0f;
2844+
*memBenchIndex = 10.0f;
28462845
}
28472846

28482847
return TRUE;

GeneralsMD/Code/GameEngine/Include/Common/GameCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
// ----------------------------------------------------------------------------------------------
6060
#include "Lib/BaseType.h"
61+
#include "WWCommon.h"
6162
#include "Common/GameDefines.h"
6263

6364
// ----------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)