diff --git a/cyberpunk_amd_patch/src/Options.cpp b/cyberpunk_amd_patch/src/Options.cpp index 4a87286a..c300dbcb 100644 --- a/cyberpunk_amd_patch/src/Options.cpp +++ b/cyberpunk_amd_patch/src/Options.cpp @@ -31,6 +31,7 @@ Options::Options(HMODULE aModule) this->PatchSMT = config.value("smt", this->PatchSMT); this->PatchSpectre = config.value("spectre", this->PatchSpectre); this->PatchMemoryPool = config.value("memory_pool", this->PatchMemoryPool); + this->PatchVirtualInput = config.value("virtual_input", this->PatchVirtualInput); } nlohmann::json config; @@ -38,6 +39,7 @@ Options::Options(HMODULE aModule) config["smt"] = this->PatchSMT; config["spectre"] = this->PatchSpectre; config["memory_pool"] = this->PatchMemoryPool; + config["virtual_input"] = this->PatchVirtualInput; std::ofstream o(configPath); o << config.dump(4) << std::endl; diff --git a/cyberpunk_amd_patch/src/Options.h b/cyberpunk_amd_patch/src/Options.h index 4ccc2d4a..2e395b0a 100644 --- a/cyberpunk_amd_patch/src/Options.h +++ b/cyberpunk_amd_patch/src/Options.h @@ -11,6 +11,7 @@ struct Options bool PatchSpectre { true }; bool PatchSMT{ true }; bool PatchAVX{ false }; + bool PatchVirtualInput{ true }; bool PatchMemoryPool{ true }; std::filesystem::path Path; }; \ No newline at end of file diff --git a/cyberpunk_amd_patch/src/dllmain.cpp b/cyberpunk_amd_patch/src/dllmain.cpp index 85f60924..2368ef90 100644 --- a/cyberpunk_amd_patch/src/dllmain.cpp +++ b/cyberpunk_amd_patch/src/dllmain.cpp @@ -14,6 +14,7 @@ #pragma comment(linker, "/DLL") void PoolPatch(Image* apImage); +void VirtualInputFix(Image* apImage); void PatchAmd(Image* apImage); void PatchAvx(Image* apImage); void HotPatchFix(Image* apImage); @@ -38,6 +39,9 @@ void Initialize(HMODULE mod) if(options.PatchMemoryPool) PoolPatch(&image); + if (options.PatchVirtualInput) + VirtualInputFix(&image); + spdlog::default_logger()->flush(); } diff --git a/cyberpunk_amd_patch/src/virtual_input_fix.cpp b/cyberpunk_amd_patch/src/virtual_input_fix.cpp new file mode 100644 index 00000000..2cb2976f --- /dev/null +++ b/cyberpunk_amd_patch/src/virtual_input_fix.cpp @@ -0,0 +1,35 @@ +#include "Image.h" +#include + +void VirtualInputFix(Image* apImage) +{ + const uint8_t payload[] = { + 0x8B, 0x44, 0x24, 0x54, 0x85, 0xC0, 0x75, 0x26 + }; + + auto* pMemoryItor = apImage->pTextStart; + auto* pEnd = apImage->pTextEnd; + + while (pMemoryItor + std::size(payload) < pEnd) + { + if (memcmp(pMemoryItor, payload, std::size(payload)) == 0) + { + DWORD oldProtect = 0; + VirtualProtect(pMemoryItor, 8, PAGE_EXECUTE_WRITECOPY, &oldProtect); + pMemoryItor[0] = 0x36; + pMemoryItor[1] = 0x8B; + pMemoryItor[2] = 0x07; + pMemoryItor[3] = 0x90; + VirtualProtect(pMemoryItor, 8, oldProtect, nullptr); + + spdlog::info("\tVirtual Input Patch: success"); + + return; + } + + pMemoryItor++; + } + + spdlog::warn("\tVirtual Input Patch: failed"); + +}