From d9b834bedec40a828da8317d1e7727791cbc7822 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 30 May 2022 20:37:58 +0200 Subject: [PATCH] Better unpack hook --- src/client/component/console.cpp | 27 +++++++++++++++++++++++++-- src/client/component/console.hpp | 6 ------ src/client/main.cpp | 2 +- src/client/steam/steam.cpp | 3 +++ src/common/utils/string.hpp | 10 ++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) delete mode 100644 src/client/component/console.hpp diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 1847465d..fbecf976 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -1,5 +1,4 @@ #include -#include "console.hpp" #include "loader/component_loader.hpp" #include @@ -9,10 +8,32 @@ namespace console { namespace { + volatile bool g_started = false; + void create_game_console() { reinterpret_cast(0x142333F80_g)(); } + + void print_message(const char* message) + { + if (g_started) + { + reinterpret_cast(0x1421499C0_g)(0, 0, "%s", message); + } + } + + void print_stub(const char* fmt, ...) + { + va_list ap; + va_start(ap, fmt); + + char buffer[1024]{0}; + const int res = vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap); + print_message(buffer); + + va_end(ap); + } } class component final : public component_interface @@ -20,6 +41,8 @@ namespace console public: void post_unpack() override { + utils::hook::jump(printf, print_stub); + this->terminate_runner_ = false; this->console_runner_ = utils::thread::create_named_thread("Console IO", [this] @@ -33,8 +56,8 @@ namespace console a.sub(eax, edx); a.jmp(0x142333B4F_g); })); - create_game_console(); + g_started = true; } MSG msg{}; diff --git a/src/client/component/console.hpp b/src/client/component/console.hpp deleted file mode 100644 index 28a19e30..00000000 --- a/src/client/component/console.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace console -{ - void print(int type, const char* fmt, ...); -} diff --git a/src/client/main.cpp b/src/client/main.cpp index 07bae723..4c2dc5f0 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -58,7 +58,7 @@ namespace patch_steam_import("SteamAPI_Init"); patch_steam_import("SteamAPI_RestartAppIfNecessary"); - utils::hook::set(game.get_iat_entry("kernel32.dll", "InitializeCriticalSection"), initialize_critical_section); + //utils::hook::set(game.get_iat_entry("kernel32.dll", "InitializeCriticalSection"), initialize_critical_section); utils::hook::set(game.get_iat_entry("kernel32.dll", "ExitProcess"), exit_hook); } diff --git a/src/client/steam/steam.cpp b/src/client/steam/steam.cpp index 6c933c1f..54c3cf01 100644 --- a/src/client/steam/steam.cpp +++ b/src/client/steam/steam.cpp @@ -4,6 +4,8 @@ #include #include +#include "loader/component_loader.hpp" + namespace steam { uint64_t callbacks::call_id_ = 0; @@ -109,6 +111,7 @@ namespace steam const std::string steam_path = SteamAPI_GetSteamInstallPath(); if (!steam_path.empty() && ::utils::io::file_exists(steam_path + "/steam.exe")) { + component_loader::post_unpack(); return false; } diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index 20fa4827..d634ffe8 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -45,6 +45,8 @@ namespace utils::string class entry final { public: + entry() = default; + explicit entry(const size_t _size = MinBufferSize) : size(_size), buffer(nullptr) { if (this->size < MinBufferSize) this->size = MinBufferSize; @@ -70,12 +72,12 @@ namespace utils::string this->allocate(); } - size_t size; - char* buffer; + size_t size{}; + char* buffer{nullptr}; }; - size_t current_buffer_; - entry string_pool_[Buffers]; + size_t current_buffer_{}; + entry string_pool_[Buffers]{}; }; const char* va(const char* fmt, ...);