diff --git a/src/game/game.cpp b/src/game/game.cpp index a3537fc..c505a81 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -9,8 +9,6 @@ namespace game Com_Error_t Com_Error; - Conbuf_AppendText_t Conbuf_AppendText; - DB_LoadXAssets_t DB_LoadXAssets; Dvar_SetFromStringByName_t Dvar_SetFromStringByName; @@ -73,6 +71,30 @@ namespace game } } + __declspec(naked) unsigned int conbuf_append_text_dedicated(const char* message) + { + static DWORD func = 0x53C790; + + __asm + { + mov ecx, message + call func + retn + } + } + + void Conbuf_AppendText(const char* message) + { + if(is_dedi()) + { + conbuf_append_text_dedicated(message); + } + else + { + reinterpret_cast(SELECT_VALUE(0x4C84E0, 0x5CF610, 0))(message); + } + } + __declspec(naked) unsigned int find_variable_dedicated(unsigned int parentId, unsigned int name) { static DWORD func = 0x4E7ED0; @@ -273,19 +295,29 @@ namespace game launcher::mode mode = launcher::mode::none; + launcher::mode get_mode() + { + if(mode == launcher::mode::none) + { + throw std::runtime_error("Launcher mode not valid. Something must be wrong."); + } + + return mode; + } + bool is_mp() { - return mode == launcher::mode::multiplayer; + return get_mode() == launcher::mode::multiplayer; } bool is_sp() { - return mode == launcher::mode::singleplayer; + return get_mode() == launcher::mode::singleplayer; } bool is_dedi() { - return mode == launcher::mode::server; + return get_mode() == launcher::mode::server; } void initialize(const launcher::mode _mode) @@ -296,8 +328,6 @@ namespace game native::Com_Error = native::Com_Error_t(SELECT_VALUE(0x425540, 0x555450, 0x4D93F0)); - native::Conbuf_AppendText = native::Conbuf_AppendText_t(SELECT_VALUE(0x4C84E0, 0x5CF610, 0x53C790)); - native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770)); native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0)); diff --git a/src/game/game.hpp b/src/game/game.hpp index 96af738..1b02182 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -17,9 +17,6 @@ namespace game typedef void (*Com_Error_t)(int code, const char* fmt, ...); extern Com_Error_t Com_Error; - typedef void (*Conbuf_AppendText_t)(const char* message); - extern Conbuf_AppendText_t Conbuf_AppendText; - typedef void (*DB_LoadXAssets_t)(XZoneInfo* zoneInfo, unsigned int zoneCount, int sync); extern DB_LoadXAssets_t DB_LoadXAssets; @@ -71,6 +68,8 @@ namespace game void AddRefToValue(VariableValue* value); + void Conbuf_AppendText(const char* message); + unsigned int FindVariable(unsigned int parentId, unsigned int name); VariableValue GetEntityFieldValue(unsigned int classnum, int entnum, int offset); diff --git a/src/module/console.cpp b/src/module/console.cpp index 7bcb9e1..be56bfd 100644 --- a/src/module/console.cpp +++ b/src/module/console.cpp @@ -42,9 +42,10 @@ public: void post_load() override { - if (game::is_dedi()) return; - - game::native::Sys_ShowConsole(); + if (!game::is_dedi()) + { + game::native::Sys_ShowConsole(); + } std::lock_guard _(this->mutex_); this->console_initialized_ = true; diff --git a/src/module/scheduler.cpp b/src/module/scheduler.cpp index e512cfa..9a47c52 100644 --- a/src/module/scheduler.cpp +++ b/src/module/scheduler.cpp @@ -3,6 +3,7 @@ #include "utils/string.hpp" #include "game/structs.hpp" #include "game/game.hpp" +#include "utils/hook.hpp" std::mutex scheduler::mutex_; std::queue> scheduler::errors_; @@ -27,6 +28,12 @@ void scheduler::error(const std::string& message, int level) errors_.emplace(message, level); } +void scheduler::frame_stub() +{ + execute(); + reinterpret_cast(SELECT_VALUE(0x458600, 0x556470, 0x4DB070))(); +} + __declspec(naked) void scheduler::execute() { __asm @@ -80,6 +87,11 @@ bool scheduler::get_next_error(const char** error_message, int* error_level) return true; } +void scheduler::post_load() +{ + utils::hook(SELECT_VALUE(0x44C7DB, 0x55688E, 0x4DB324), frame_stub, HOOK_CALL).install()->quick(); +} + void scheduler::pre_destroy() { std::lock_guard _(mutex_); diff --git a/src/module/scheduler.hpp b/src/module/scheduler.hpp index 001c6ac..6de4541 100644 --- a/src/module/scheduler.hpp +++ b/src/module/scheduler.hpp @@ -7,10 +7,10 @@ class scheduler final : public module public: static void on_frame(const std::function& callback); static void once(const std::function& callback); - static void execute(); static void error(const std::string& message, int level); + void post_load() override; void pre_destroy() override; private: @@ -19,6 +19,9 @@ private: static utils::concurrent_list> callbacks_; static utils::concurrent_list> single_callbacks_; + static void frame_stub(); + + static void execute(); static void execute_safe(); static void execute_error(); static bool get_next_error(const char** error_message, int* error_level); diff --git a/src/steam/steam.cpp b/src/steam/steam.cpp index 694326e..558ffb6 100644 --- a/src/steam/steam.cpp +++ b/src/steam/steam.cpp @@ -136,7 +136,6 @@ namespace steam void SteamAPI_RunCallbacks() { callbacks::run_callbacks(); - scheduler::execute(); } void SteamAPI_Shutdown()