diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 327b43bf..50944cb1 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -1,31 +1,20 @@ #include #include "loader/component_loader.hpp" +#include "command.hpp" #include "game_console.hpp" #include "game/game.hpp" #include "game/dvars.hpp" +#include #include namespace console { namespace { - DWORD WINAPI console(LPVOID) - { - ShowWindow(GetConsoleWindow(), SW_SHOW); - - std::string cmd; - - while (true) - { - std::getline(std::cin, cmd); - game_console::execute(cmd.data()); - } - - return 0; - } + std::thread console_thread; } class component final : public component_interface @@ -33,7 +22,18 @@ namespace console public: void post_unpack() override { - CreateThread(0, 0, console, 0, 0, 0); + ShowWindow(GetConsoleWindow(), SW_SHOW); + SetConsoleTitle("H2-Mod"); + + console_thread = utils::thread::create_named_thread("Console", []() + { + std::string cmd; + while (true) + { + std::getline(std::cin, cmd); + command::execute(cmd.data(), false); + } + }); } }; } diff --git a/src/client/component/exception.cpp b/src/client/component/exception.cpp index 45cd29ab..ee6839b4 100644 --- a/src/client/component/exception.cpp +++ b/src/client/component/exception.cpp @@ -85,7 +85,7 @@ namespace exception { std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n" "A minidump has been written.\n\n", - exception_data.code, (uint64_t)exception_data.address - game::base_address); + exception_data.code, exception_data.address); error_str += "Make sure to update your graphics card drivers and install operating system updates!"; @@ -157,7 +157,7 @@ namespace exception line("Environment: "s + game::environment::get_string()); line("Timestamp: "s + get_timestamp()); line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode)); - line(utils::string::va("Address: 0x%llX", (uint64_t)exceptioninfo->ExceptionRecord->ExceptionAddress - game::base_address)); + line(utils::string::va("Address: 0x%llX", exceptioninfo->ExceptionRecord->ExceptionAddress)); line(utils::string::va("Base: 0x%llX", game::base_address)); #pragma warning(push) diff --git a/src/client/component/scheduler.cpp b/src/client/component/scheduler.cpp index 8077ab8e..653818ff 100644 --- a/src/client/component/scheduler.cpp +++ b/src/client/component/scheduler.cpp @@ -4,6 +4,7 @@ #include "scheduler.hpp" #include "game/game.hpp" +#include #include #include @@ -163,9 +164,9 @@ namespace scheduler class component final : public component_interface { public: - void post_unpack() override + void post_start() override { - thread = std::thread([]() + thread = utils::thread::create_named_thread("Async Scheduler", []() { while (!kill) { @@ -173,11 +174,23 @@ namespace scheduler std::this_thread::sleep_for(10ms); } }); + } + void post_unpack() override + { r_end_frame_hook.create(game::base_address + 0x76D7B0, scheduler::r_end_frame_stub); g_run_frame_hook.create(game::base_address + 0x4CB030, scheduler::server_frame_stub); main_frame_hook.create(game::base_address + 0x417FA0, scheduler::main_frame_stub); } + + void pre_destroy() override + { + kill = true; + if (thread.joinable()) + { + thread.join(); + } + } }; }