From a6b17cf64d335016684b3a50713150879122c67f Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 18 Jul 2021 17:36:01 +0200 Subject: [PATCH 1/3] Better quit_hard --- src/Components/Modules/Command.cpp | 2 +- src/Components/Modules/QuickPatch.cpp | 34 +++------------------- src/Steam/Proxy.cpp | 10 +++---- src/Utils/Library.cpp | 6 ++-- src/Utils/Library.hpp | 41 ++++++++++++++++++++++----- 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 1037144e..5f23f9a2 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -252,7 +252,7 @@ namespace Components Game::TeleportPlayer(&Game::g_entities[clientNum], pos, orientation); - // Logging that will spam the console and screen if people use cinematics + //Logging that will spam the console and screen if people use cinematics //Logger::Print("Successfully teleported player!\n"); //Toast::Show("cardicon_abduction", "Success", "You have been teleported!", toastDurationShort); }); diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 4cdee9f5..d0c8a103 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -399,36 +399,10 @@ namespace Components // quit_hard Command::Add("quit_hard", [](Command::Params*) { - typedef enum _HARDERROR_RESPONSE_OPTION { - OptionAbortRetryIgnore, - OptionOk, - OptionOkCancel, - OptionRetryCancel, - OptionYesNo, - OptionYesNoCancel, - OptionShutdownSystem - } HARDERROR_RESPONSE_OPTION, *PHARDERROR_RESPONSE_OPTION; - - typedef enum _HARDERROR_RESPONSE { - ResponseReturnToCaller, - ResponseNotHandled, - ResponseAbort, - ResponseCancel, - ResponseIgnore, - ResponseNo, - ResponseOk, - ResponseRetry, - ResponseYes - } HARDERROR_RESPONSE, *PHARDERROR_RESPONSE; - - BOOLEAN hasPerms; - HARDERROR_RESPONSE response; - - auto result = ImportFunction("ntdll.dll", "RtlAdjustPrivilege") - (19, true, false, &hasPerms); - - result = ImportFunction("ntdll.dll", "NtRaiseHardError") - (0xC000007B /*0x0000000A*/, 0, nullptr, nullptr, OptionShutdownSystem, &response); + int data = false; + const Utils::Library ntdll("ntdll.dll"); + ntdll.invoke_pascal("RtlAdjustPrivilege", 19, true, false, &data); + ntdll.invoke_pascal("NtRaiseHardError", 0xC000007B, 0, nullptr, nullptr, 6, &data); }); // bounce dvar diff --git a/src/Steam/Proxy.cpp b/src/Steam/Proxy.cpp index 1458972f..07bd2abc 100644 --- a/src/Steam/Proxy.cpp +++ b/src/Steam/Proxy.cpp @@ -384,11 +384,11 @@ namespace Steam Proxy::LaunchWatchGuard(); Proxy::Overlay = ::Utils::Library(GAMEOVERLAY_LIB, false); - if (!Proxy::Overlay.valid()) return false; + if (!Proxy::Overlay.is_valid()) return false; } Proxy::Client = ::Utils::Library(STEAMCLIENT_LIB, false); - if (!Proxy::Client.valid()) return false; + if (!Proxy::Client.is_valid()) return false; Proxy::SteamClient = Proxy::Client.get("CreateInterface")("SteamClient008", nullptr); if(!Proxy::SteamClient) return false; @@ -526,7 +526,7 @@ namespace Steam void Proxy::SetOverlayNotificationPosition(uint32_t eNotificationPosition) { - if (Proxy::Overlay.valid()) + if (Proxy::Overlay.is_valid()) { Proxy::Overlay.get("SetNotificationPosition")(eNotificationPosition); } @@ -534,7 +534,7 @@ namespace Steam bool Proxy::IsOverlayEnabled() { - if (Proxy::Overlay.valid()) + if (Proxy::Overlay.is_valid()) { return Proxy::Overlay.get("IsOverlayEnabled")(); } @@ -544,7 +544,7 @@ namespace Steam bool Proxy::BOverlayNeedsPresent() { - if (Proxy::Overlay.valid()) + if (Proxy::Overlay.is_valid()) { return Proxy::Overlay.get("BOverlayNeedsPresent")(); } diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index 7c12fe71..a8773cb8 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -15,9 +15,9 @@ namespace Utils } } - bool Library::valid() + bool Library::is_valid() const { - return (this->getModule() != nullptr); + return this->_module != nullptr; } HMODULE Library::getModule() @@ -27,7 +27,7 @@ namespace Utils void Library::free() { - if (this->valid()) + if (this->is_valid()) { FreeLibrary(this->getModule()); } diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index c5b3815b..92674eaf 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -9,18 +9,45 @@ namespace Utils Library(const std::string& buffer, bool freeOnDestroy = true); ~Library(); - bool valid(); + bool is_valid() const; HMODULE getModule(); template - std::function get(const std::string& process) + T get_proc(const std::string& process) const { - if (!this->valid()) - { - throw std::runtime_error("Library not loaded!"); - } + if (!this->is_valid()) T{}; + return reinterpret_cast(GetProcAddress(this->_module, process.data())); + } - return reinterpret_cast(GetProcAddress(this->getModule(), process.data())); + template + std::function get(const std::string& process) const + { + if (!this->is_valid()) return std::function(); + return static_cast(this->get_proc(process)); + } + + template + T invoke(const std::string& process, Args ... args) const + { + auto method = this->get(process); + if (method) return method(args...); + return T(); + } + + template + T invoke_pascal(const std::string& process, Args ... args) const + { + auto method = this->get(process); + if (method) return method(args...); + return T(); + } + + template + T invoke_this(const std::string& process, void* this_ptr, Args ... args) const + { + auto method = this->get(this_ptr, process); + if (method) return method(args...); + return T(); } void free(); From fcb0d220f9bf6f9b31b2bcd751f49e92e9f657b7 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 18 Jul 2021 18:11:20 +0200 Subject: [PATCH 2/3] Fix Quit Hard --- src/STDInclude.hpp | 1 + src/Utils/Library.cpp | 29 +++++++++++++++++++++++++++++ src/Utils/Library.hpp | 8 +++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index e06ba418..3a7fc61a 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -149,6 +149,7 @@ template class Sizer { }; #pragma comment(lib, "Advapi32.lib") #pragma comment(lib, "rpcrt4.lib") #pragma comment(lib, "dbghelp.lib") +#pragma comment(lib, "ntdll.lib") // Enable additional literals using namespace std::literals; diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index a8773cb8..4b6fc0e8 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -2,11 +2,40 @@ namespace Utils { + Library Library::load(const std::string& name) + { + return Library(LoadLibraryA(name.data())); + } + + Library Library::load(const std::filesystem::path& path) + { + return Library::load(path.generic_string()); + } + + Library Library::get_by_address(void* address) + { + HMODULE handle = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast(address), &handle); + return Library(handle); + } + Library::Library(const std::string& buffer, bool _freeOnDestroy) : _module(nullptr), freeOnDestroy(_freeOnDestroy) { this->_module = LoadLibraryExA(buffer.data(), nullptr, 0); } + Library::Library(const std::string& buffer) + { + this->_module = GetModuleHandleA(buffer.data()); + this->freeOnDestroy = true; + } + + Library::Library(const HMODULE handle) + { + this->_module = handle; + this->freeOnDestroy = true; + } + Library::~Library() { if (this->freeOnDestroy) diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index 92674eaf..b479a6cf 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -5,8 +5,14 @@ namespace Utils class Library { public: + static Library load(const std::string& name); + static Library load(const std::filesystem::path& path); + static Library get_by_address(void* address); + Library() : _module(nullptr), freeOnDestroy(false) {}; - Library(const std::string& buffer, bool freeOnDestroy = true); + Library(const std::string& buffer, bool freeOnDestroy); + explicit Library(const std::string& name); + explicit Library(HMODULE handle); ~Library(); bool is_valid() const; From 5f7cefa5c95685af445f71de7b60f80285e729f8 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 18 Jul 2021 18:11:20 +0200 Subject: [PATCH 3/3] Fix Quit Hard --- src/STDInclude.hpp | 1 + src/Utils/Library.cpp | 29 +++++++++++++++++++++++++++++ src/Utils/Library.hpp | 8 +++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index e06ba418..3a7fc61a 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -149,6 +149,7 @@ template class Sizer { }; #pragma comment(lib, "Advapi32.lib") #pragma comment(lib, "rpcrt4.lib") #pragma comment(lib, "dbghelp.lib") +#pragma comment(lib, "ntdll.lib") // Enable additional literals using namespace std::literals; diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index a8773cb8..4b6fc0e8 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -2,11 +2,40 @@ namespace Utils { + Library Library::load(const std::string& name) + { + return Library(LoadLibraryA(name.data())); + } + + Library Library::load(const std::filesystem::path& path) + { + return Library::load(path.generic_string()); + } + + Library Library::get_by_address(void* address) + { + HMODULE handle = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast(address), &handle); + return Library(handle); + } + Library::Library(const std::string& buffer, bool _freeOnDestroy) : _module(nullptr), freeOnDestroy(_freeOnDestroy) { this->_module = LoadLibraryExA(buffer.data(), nullptr, 0); } + Library::Library(const std::string& buffer) + { + this->_module = GetModuleHandleA(buffer.data()); + this->freeOnDestroy = true; + } + + Library::Library(const HMODULE handle) + { + this->_module = handle; + this->freeOnDestroy = true; + } + Library::~Library() { if (this->freeOnDestroy) diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index 92674eaf..b479a6cf 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -5,8 +5,14 @@ namespace Utils class Library { public: + static Library load(const std::string& name); + static Library load(const std::filesystem::path& path); + static Library get_by_address(void* address); + Library() : _module(nullptr), freeOnDestroy(false) {}; - Library(const std::string& buffer, bool freeOnDestroy = true); + Library(const std::string& buffer, bool freeOnDestroy); + explicit Library(const std::string& name); + explicit Library(HMODULE handle); ~Library(); bool is_valid() const;