diff --git a/src/client/component/cheats.cpp b/src/client/component/cheats.cpp index 84d402e..1c8bb8a 100644 --- a/src/client/component/cheats.cpp +++ b/src/client/component/cheats.cpp @@ -15,7 +15,7 @@ void __declspec(naked) draw_red_box_stub() { __asm { push eax mov eax, cl_EnableCheats - cmp byte ptr [eax + 12], 1 + cmp byte ptr [eax + 0xC], 1 pop eax je draw @@ -35,7 +35,7 @@ void __declspec(naked) blind_eye_check_stub() { __asm { push eax mov eax, cl_EnableCheats - cmp byte ptr [eax + 12], 1 + cmp byte ptr [eax + 0xC], 1 pop eax je draw diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index eca09f7..f90e958 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -100,9 +100,9 @@ private: console::info("{} doesn't exist", dvar_name); return; } - if (dvar->type != game::dvar_type::DVAR_TYPE_STRING && - dvar->type != game::dvar_type::DVAR_TYPE_ENUM) { - console::info("{} is not a string-based dvar\n", dvar->name); + if (dvar->type != game::DVAR_TYPE_STRING && + dvar->type != game::DVAR_TYPE_ENUM) { + console::info("{} is not a string-based dvar", dvar->name); return; } diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 522659d..f5e67f2 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -75,7 +75,7 @@ private: void initialize() { this->console_thread_ = - utils::thread::create_named_thread("Console", [this]() { + utils::thread::create_named_thread("Console", [this] { if (!utils::flags::has_flag("noconsole")) { game::Sys_ShowConsole(); } @@ -92,7 +92,7 @@ private: } TranslateMessage(&msg); - DispatchMessage(&msg); + DispatchMessageA(&msg); } else { this->log_messages(); std::this_thread::sleep_for(1ms); @@ -145,17 +145,12 @@ private: HWND get_window() { return *reinterpret_cast(0x5A86330); } -#ifdef _DEBUG -void print(const std::source_location& location, std::string_view fmt, - std::format_args&& args) { -#else -void print(std::string_view fmt, std::format_args&& args) { -#endif +void print(std::string_view fmt, std::format_args&& args, + const std::source_location& loc) { #ifdef _DEBUG const auto msg = std::vformat(fmt, args); - const auto line = - std::format("Debug:\n {}\nFile: {}\nFunction: {}\n\n", msg, - location.file_name(), location.function_name()); + const auto line = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", + msg, loc.file_name(), loc.line()); #else const auto line = std::vformat(fmt, args) + "\n"; #endif diff --git a/src/client/component/console.hpp b/src/client/component/console.hpp index 50c21ce..c104ec0 100644 --- a/src/client/component/console.hpp +++ b/src/client/component/console.hpp @@ -3,28 +3,17 @@ namespace console { HWND get_window(); -#ifdef _DEBUG -void print(const std::source_location& location, +void print(std::string_view fmt, std::format_args&& args, + const std::source_location& loc); - std::string_view fmt, std::format_args&& args); -#else -void print(std::string_view fmt, std::format_args&& args); -#endif - -static inline void console_log(std::string_view fmt, std::format_args&& args) { -#ifdef _DEBUG - print(std::source_location::current(), fmt, std::move(args)); -#else - print(fmt, std::move(args)); -#endif -} +template class info { +public: + info(std::string_view fmt, const Args&... args, + const std::source_location& loc = std::source_location::current()) { + print(fmt, std::make_format_args(args...), loc); + } +}; template -static inline void info(std::string_view fmt, Args&&... args) { - console_log(fmt, std::make_format_args(args...)); -} - -static inline void info(std::string_view fmt) { - console_log(fmt, std::make_format_args(0)); -} +info(std::string_view fmt, const Args&... args) -> info; } // namespace console diff --git a/src/client/component/dvar_patches.cpp b/src/client/component/dvar_patches.cpp index 48bbdad..96abbf8 100644 --- a/src/client/component/dvar_patches.cpp +++ b/src/client/component/dvar_patches.cpp @@ -9,10 +9,10 @@ namespace dvar_patches { namespace { void dvar_set_from_string_by_name_stub(const char* dvar_name, const char* string) { - console::info("Server tried setting {} with value {}", dvar_name, string); + console::info("Server tried setting '{}' with value '{}'", dvar_name, string); } -void dvar_override_cheat_protection_stub(bool /*a1*/) { +void dvar_override_cheat_protection_stub(bool /*cheat_override*/) { *game::isCheatOverride = true; } } // namespace diff --git a/src/client/component/exploit.cpp b/src/client/component/exploit.cpp index 07e202f..ed84360 100644 --- a/src/client/component/exploit.cpp +++ b/src/client/component/exploit.cpp @@ -70,7 +70,7 @@ private: key_catcher::on_key_press( "L", []([[maybe_unused]] const game::LocalClientNum_t& local_client) { - command::execute("undo_exploit"); + command::execute("undoExploit"); }); key_catcher::on_key_press( diff --git a/src/client/component/patches.cpp b/src/client/component/patches.cpp index d70856d..72d77c9 100644 --- a/src/client/component/patches.cpp +++ b/src/client/component/patches.cpp @@ -3,6 +3,8 @@ #include +#include "console.hpp" + namespace patches { namespace { constexpr auto max_fps = 125; // Meme @@ -15,12 +17,36 @@ void __declspec(naked) get_com_max_fps() { retn } } + +void bd_log_message_stub(const game::bdLogMessageType /*type*/, + const char* const /*base_channel*/, + const char* const /*channel*/, + const char* const /*file*/, + const char* const /*function*/, + const unsigned int /*line*/, const char* format, ...) { + char buf[4096] = {0}; + va_list ap; + va_start(ap, format); + vsnprintf_s(buf, _TRUNCATE, format, ap); + va_end(ap); + + console::info("{}", buf); +} } // namespace class component final : public component_interface { void post_unpack() override { utils::hook(0x4E470D, get_com_max_fps, HOOK_JUMP).install()->quick(); utils::hook::nop(0x4E4712, 4); + + utils::hook(0x6EA960, bd_log_message_stub, HOOK_JUMP).install()->quick(); + + // Another meme + static const auto* my_cg_fov = game::Dvar_RegisterFloat( + "my_cg_fov", 100.0f, 65.0f, 160.0f, game::DVAR_INIT, ""); + utils::hook::set(0x54BAF8, &my_cg_fov); + utils::hook::set(0x54BC35, &my_cg_fov); + utils::hook::set(0x5711C4, &my_cg_fov); } }; } // namespace patches diff --git a/src/client/component/scheduler.cpp b/src/client/component/scheduler.cpp index d364b02..8197aa0 100644 --- a/src/client/component/scheduler.cpp +++ b/src/client/component/scheduler.cpp @@ -64,9 +64,8 @@ private: void merge_callbacks() { callbacks_.access([&](task_list& tasks) { new_callbacks_.access([&](task_list& new_tasks) { - tasks.insert(tasks.end(), - std::move_iterator(new_tasks.begin()), - std::move_iterator(new_tasks.end())); + tasks.insert(tasks.end(), std::move_iterator(new_tasks.begin()), + std::move_iterator(new_tasks.end())); new_tasks = {}; }); }); @@ -137,7 +136,7 @@ unsigned int thread_id; class component final : public component_interface { public: void post_unpack() override { - thread = utils::thread::create_named_thread("Async Scheduler", []() { + thread = utils::thread::create_named_thread("Async Scheduler", [] { while (!kill) { execute(pipeline::async); std::this_thread::sleep_for(10ms); diff --git a/src/client/component/scheduler.hpp b/src/client/component/scheduler.hpp index 0fbaf1d..929ef9b 100644 --- a/src/client/component/scheduler.hpp +++ b/src/client/component/scheduler.hpp @@ -12,7 +12,7 @@ enum pipeline { static const bool cond_continue = false; static const bool cond_end = true; -void clear_tasks(const pipeline type); +void clear_tasks(pipeline type); void schedule(const std::function& callback, pipeline type = pipeline::client, diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index ac940b6..dc29ad1 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -9,6 +9,12 @@ typedef vec_t vec2_t[2]; typedef vec_t vec3_t[3]; typedef vec_t vec4_t[4]; +enum bdLogMessageType { + BD_LOG_INFO, + BD_LOG_WARNING, + BD_LOG_ERROR, +}; + struct cmd_function_t { cmd_function_t* next; const char* name; @@ -166,8 +172,8 @@ enum dvar_flags : std::uint16_t { DVAR_CODINFO = 1 << 3, DVAR_SCRIPTINFO = 1 << 4, DVAR_SERVERINFO = 1 << 10, - DVAR_WRITEPROTECTED = 1 << 11, - DVAR_READONLY = 1 << 13, + DVAR_INIT = 1 << 11, + DVAR_ROM = 1 << 13, DVAR_AUTOEXEC = 1 << 15, };