From 2c3f445f8f219d485822e473cf407324a5a604c7 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 10 May 2018 17:24:03 +0200 Subject: [PATCH] [AntiCheat] Introduce LibUnlocker --- src/Components/Modules/AntiCheat.cpp | 18 ++++-------------- src/Components/Modules/AntiCheat.hpp | 13 +++++++++++++ src/Utils/Utils.cpp | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Components/Modules/AntiCheat.cpp b/src/Components/Modules/AntiCheat.cpp index c987574d..7223896d 100644 --- a/src/Components/Modules/AntiCheat.cpp +++ b/src/Components/Modules/AntiCheat.cpp @@ -329,40 +329,30 @@ namespace Components void AntiCheat::PatchWinAPI() { - AntiCheat::UninstallLibHook(); + LibUnlocker _; // Initialize directx Utils::Hook::Call(0x5078C0)(); - - AntiCheat::InstallLibHook(); } void AntiCheat::SoundInitStub(int a1, int a2, int a3) { - AntiCheat::UninstallLibHook(); - + LibUnlocker _; Game::SND_Init(a1, a2, a3); - - AntiCheat::InstallLibHook(); } void AntiCheat::SoundInitDriverStub() { - AntiCheat::UninstallLibHook(); - + LibUnlocker _; Game::SND_InitDriver(); - - AntiCheat::InstallLibHook(); } void AntiCheat::LostD3DStub() { - AntiCheat::UninstallLibHook(); + LibUnlocker _; // Reset directx Utils::Hook::Call(0x508070)(); - - AntiCheat::InstallLibHook(); } __declspec(naked) void AntiCheat::CinematicStub() diff --git a/src/Components/Modules/AntiCheat.hpp b/src/Components/Modules/AntiCheat.hpp index f3cdfb6a..d2af2551 100644 --- a/src/Components/Modules/AntiCheat.hpp +++ b/src/Components/Modules/AntiCheat.hpp @@ -20,6 +20,19 @@ namespace Components AntiCheat(); ~AntiCheat(); + class LibUnlocker + { + public: + LibUnlocker() + { + UninstallLibHook(); + } + ~LibUnlocker() + { + InstallLibHook(); + } + }; + static void CrashClient(); static void InitLoadLibHook(); diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index b2e9e35e..4adb4b9d 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -123,11 +123,21 @@ namespace Utils void SafeShellExecute(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd) { - __try +#ifndef DISABLE_ANTICHEAT + Components::AntiCheat::LibUnlocker _; +#endif + + [=]() { - ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd); - } - __finally {} + __try + { + ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd); + } + __finally + {} + }(); + + std::this_thread::yield(); } void OpenUrl(std::string url)