From 84d8d80d30687d7c8635f4c902c0d3881a028ed2 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 16 Jan 2026 09:25:49 +0800 Subject: [PATCH] Code edits to SingleCore to make it run safer Changed SingleCore to be disabled by default. (its usage is questionable on newer systems.) --- artifacts/ddraw.ini | 2 +- sfall/Modules/MiscPatches.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index ddac6516..03bce110 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -406,7 +406,7 @@ ViewXPos=-1 ViewYPos=-1 ;Set to 1 to force Fallout not to use multiple processor cores even if they are available -SingleCore=1 +SingleCore=0 ;Set to 1 to override the art_cache_size setting in fallout2.cfg OverrideArtCacheSize=0 diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index 5af374a4..b52ecbd7 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -928,13 +928,21 @@ void MiscPatches::init() { SafeWrite32(0x444323, (DWORD)&patchName); } - if (IniReader::GetConfigInt("Misc", "SingleCore", 1)) { + if (IniReader::GetConfigInt("Misc", "SingleCore", 0)) { SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); if (sysInfo.dwNumberOfProcessors > 1) { - dlogr("Applying single core patch.", DL_INIT); HANDLE process = GetCurrentProcess(); - SetProcessAffinityMask(process, 2); // use only CPU 1 + DWORD_PTR procAffinity, sysAffinity; + if (GetProcessAffinityMask(process, &procAffinity, &sysAffinity)) { + DWORD_PTR newMask = procAffinity & ~static_cast(1); // exclude CPU 0 + if (newMask == 0) newMask = procAffinity; // fall back if no other cores + newMask &= -static_cast(newMask); // pick the first available core + if (newMask != 0 && newMask != procAffinity) { + dlogr("Applying single core patch.", DL_INIT); + SetProcessAffinityMask(process, newMask); + } + } } }