diff --git a/src/client/component/game_log.cpp b/src/client/component/game_log.cpp index d36d39c7..405fbd2f 100644 --- a/src/client/component/game_log.cpp +++ b/src/client/component/game_log.cpp @@ -2,6 +2,7 @@ #include "loader/component_loader.hpp" #include "game/game.hpp" +#include "game/utils.hpp" #include #include @@ -11,6 +12,8 @@ namespace game_log { namespace { + const game::dvar_t* g_log; + void g_scr_log_print() { char string[1024]{}; @@ -41,10 +44,10 @@ namespace game_log va_list ap; va_start(ap, fmt); - vsprintf_s(va_buffer, fmt, ap); + vsnprintf_s(va_buffer, _TRUNCATE, fmt, ap); va_end(ap); - const auto* file = "games_mp.log"; + const auto* file = g_log ? g_log->current.value.string : "games_mp.log"; const auto time = *game::level_time / 1000; utils::io::write_file(file, utils::string::va("%3i:%i%i %s", @@ -54,6 +57,12 @@ namespace game_log va_buffer ), true); } + + const game::dvar_t* register_g_log_stub() + { + g_log = game::register_dvar_string("g_log", "games_mp.log", game::DVAR_NONE, "Log file path"); + return g_log; + } } class component final : public server_component @@ -64,6 +73,11 @@ namespace game_log // Fix format string vulnerability & make it work utils::hook::jump(0x1402D9300_g, g_scr_log_print); utils::hook::jump(0x1402A7BB0_g, g_log_printf_stub); + + utils::hook::call(0x1402A82D6_g, register_g_log_stub); + + // G_InitGame: because we changed the dvar g_log from a bool dvar to a string dvar we need to skip a bunch of related code to force it + utils::hook::jump(0x1402AC00E_g, 0x1402AC061_g, true); } }; } diff --git a/src/client/component/loot.cpp b/src/client/component/loot.cpp index b0f6c519..291bcdd6 100644 --- a/src/client/component/loot.cpp +++ b/src/client/component/loot.cpp @@ -11,12 +11,12 @@ namespace loot { namespace { - game::dvar_t* dvar_cg_unlockall_loot; - game::dvar_t* dvar_cg_unlockall_purchases; - game::dvar_t* dvar_cg_unlockall_attachments; - game::dvar_t* dvar_cg_unlockall_camos_and_reticles; - game::dvar_t* dvar_cg_unlockall_calling_cards; - game::dvar_t* dvar_cg_unlockall_specialists_outfits; + const game::dvar_t* dvar_cg_unlockall_loot; + const game::dvar_t* dvar_cg_unlockall_purchases; + const game::dvar_t* dvar_cg_unlockall_attachments; + const game::dvar_t* dvar_cg_unlockall_camos_and_reticles; + const game::dvar_t* dvar_cg_unlockall_calling_cards; + const game::dvar_t* dvar_cg_unlockall_specialists_outfits; utils::hook::detour loot_getitemquantity_hook; utils::hook::detour liveinventory_getitemquantity_hook; diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index f594a8dc..2c8c64c9 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -104,18 +104,18 @@ namespace game WEAK symbol Dvar_GetString{0x1422BF590, 0x140575E30}; WEAK symbol Dvar_DisplayableValue{0x1422BC080}; WEAK symbol Dvar_GetBool{0x1422BCED0}; - WEAK symbol Dvar_RegisterBool{ 0x1422D0900, 0x14057B500 }; - WEAK symbol Dvar_SessionModeRegisterBool{ 0x1422D0D40, 0x14057BAA0 }; WEAK symbol Dvar_SessionModeSetDefaultBool{ 0x1422D0E90, 0x14057BCE0 }; - WEAK symbol Dvar_RegisterString{ 0x1422D0B70 }; diff --git a/src/client/game/utils.cpp b/src/client/game/utils.cpp index ed5642f2..72225213 100644 --- a/src/client/game/utils.cpp +++ b/src/client/game/utils.cpp @@ -38,7 +38,7 @@ namespace game return dvar->current.value.enabled; } - dvar_t* register_sessionmode_dvar_bool(const char* dvar_name, const bool value, const dvarFlags_e flags, const char* description, const eModes mode) + const dvar_t* register_sessionmode_dvar_bool(const char* dvar_name, const bool value, const int flags, const char* description, const eModes mode) { const auto hash = Dvar_GenerateHash(dvar_name); auto registered_dvar = Dvar_SessionModeRegisterBool(hash, dvar_name, value, flags, description); @@ -63,7 +63,7 @@ namespace game return registered_dvar; } - dvar_t* register_dvar_bool(const char* dvar_name, const bool value, const dvarFlags_e flags, const char* description) + const dvar_t* register_dvar_bool(const char* dvar_name, const bool value, const int flags, const char* description) { const auto hash = Dvar_GenerateHash(dvar_name); auto registered_dvar = Dvar_RegisterBool(hash, dvar_name, value, flags, description); @@ -76,6 +76,19 @@ namespace game return registered_dvar; } + const dvar_t* register_dvar_string(const char* dvar_name, const char* value, const int flags, const char* description) + { + const auto hash = Dvar_GenerateHash(dvar_name); + auto registered_dvar = Dvar_RegisterString(hash, dvar_name, value, flags, description); + + if (registered_dvar) + { + registered_dvar->debugName = dvar_name; + } + + return registered_dvar; + } + void dvar_add_flags(const char* dvar_name, const dvarFlags_e flags) { auto dvar = Dvar_FindVar(dvar_name); diff --git a/src/client/game/utils.hpp b/src/client/game/utils.hpp index 07ffc164..c59bbfc7 100644 --- a/src/client/game/utils.hpp +++ b/src/client/game/utils.hpp @@ -8,8 +8,9 @@ namespace game int get_dvar_int(const char* dvar_name); bool get_dvar_bool(const char* dvar_name); - dvar_t* register_dvar_bool(const char* dvar_name, bool value, dvarFlags_e flags, const char* description); - dvar_t* register_sessionmode_dvar_bool(const char* dvar_name, const bool value, const dvarFlags_e flags, const char* description, const eModes mode = MODE_COUNT); + const dvar_t* register_dvar_bool(const char* dvar_name, bool value, int flags, const char* description); + const dvar_t* register_sessionmode_dvar_bool(const char* dvar_name, bool value, int flags, const char* description, eModes mode = MODE_COUNT); + const dvar_t* register_dvar_string(const char* dvar_name, const char* value, int flags, const char* description); void dvar_add_flags(const char* dvar, dvarFlags_e flags); void dvar_set_flags(const char* dvar_name, dvarFlags_e flags); }