From 65248326c1bf093b4af8c05939aaa4d0985154af Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Mon, 13 Feb 2023 18:47:22 +0100 Subject: [PATCH] Fix stuttering on AMD Fix for #147 --- src/client/component/arxan.cpp | 11 ------- src/client/component/client_patches.cpp | 43 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/client/component/client_patches.cpp diff --git a/src/client/component/arxan.cpp b/src/client/component/arxan.cpp index 8bb06232..dc43c6e3 100644 --- a/src/client/component/arxan.cpp +++ b/src/client/component/arxan.cpp @@ -755,17 +755,6 @@ namespace arxan { search_and_patch_integrity_checks(); //restore_debug_functions(); - - scheduler::once([] - { - SetProcessAffinityMask(GetCurrentProcess(), 2 << (std::min(std::thread::hardware_concurrency(), 4U))); - - scheduler::once([] { - DWORD_PTR affinity_proc, affinity_sys; - GetProcessAffinityMask(GetCurrentProcess(), &affinity_proc, &affinity_sys); - SetProcessAffinityMask(GetCurrentProcess(), affinity_sys); - }, scheduler::pipeline::main, 1s); - }, scheduler::pipeline::main); } component_priority priority() const override diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp new file mode 100644 index 00000000..0d218137 --- /dev/null +++ b/src/client/component/client_patches.cpp @@ -0,0 +1,43 @@ +#include +#include "loader/component_loader.hpp" + +#include "scheduler.hpp" + +namespace client_patches +{ + namespace + { + void reduce_process_affinity() + { + const DWORD_PTR affinity = (2ULL << (std::min(std::thread::hardware_concurrency(), 4U))) - 1; + SetProcessAffinityMask(GetCurrentProcess(), affinity); + } + + void reset_process_affinity() + { + DWORD_PTR affinity_proc, affinity_sys; + GetProcessAffinityMask(GetCurrentProcess(), &affinity_proc, &affinity_sys); + SetProcessAffinityMask(GetCurrentProcess(), affinity_sys); + } + + void fix_amd_cpu_stuttering() + { + scheduler::once([] + { + reduce_process_affinity(); + scheduler::once(reset_process_affinity, scheduler::pipeline::main, 1s); + }, scheduler::pipeline::main); + } + } + + class component final : public client_component + { + public: + void post_unpack() override + { + fix_amd_cpu_stuttering(); + } + }; +} + +REGISTER_COMPONENT(client_patches::component)