From fa9020c08425047e30a2e5aa02871c47d30794d4 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Thu, 3 Mar 2022 12:37:46 +0100 Subject: [PATCH 1/5] Fix in-game UI --- src/client/component/auth.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index 5ea40d9c..f0950e96 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -227,8 +227,8 @@ namespace auth utils::hook::jump(0x140488BC1, get_direct_connect_stub(), true); // H1(1.4) utils::hook::call(0x140250ED2, send_connect_data_stub); // H1(1.4) - // Check for sending connect packet - utils::hook::set(0x14059A6E0, 0xC301B0); + // Skip checks for sending connect packet + utils::hook::jump(0x1402508FC, 0x140250946); // Don't instantly timeout the connecting client ? not sure about this utils::hook::set(0x14025136B, 0xC3); } From 91c0856f867c251ccd67583b4f6e29a80b274b9d Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Thu, 3 Mar 2022 12:51:02 +0100 Subject: [PATCH 2/5] Game console fixes --- src/client/component/game_console.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index 289a07a8..cf7c3056 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -59,7 +59,7 @@ namespace game_console std::vector matches{}; float color_white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - float color_title[4] = {0.9f, 0.9f, 0.5f, 1.0f}; + float color_title[4] = {0.25f, 0.62f, 0.3f, 1.0f}; void clear() { @@ -453,11 +453,19 @@ namespace game_console bool console_char_event(const int local_client_num, const int key) { - if (key == game::keyNum_t::K_GRAVE || key == game::keyNum_t::K_TILDE) + if (key == game::keyNum_t::K_GRAVE || + key == game::keyNum_t::K_TILDE || + key == '|' || + key == '\\') { return false; } + if (key > 127) + { + return true; + } + if (*game::keyCatchers & 1) { if (key == game::keyNum_t::K_TAB) // tab (auto complete) From 41172e10e65f234bc3c59275d2f9bb6855ae136b Mon Sep 17 00:00:00 2001 From: m Date: Thu, 3 Mar 2022 06:56:46 -0600 Subject: [PATCH 3/5] add filesystem + executing custom cfg files --- src/client/component/filesystem.cpp | 94 +++++++++++++++++++++++++++++ src/client/component/filesystem.hpp | 19 ++++++ src/client/component/patches.cpp | 29 ++++++--- 3 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 src/client/component/filesystem.cpp create mode 100644 src/client/component/filesystem.hpp diff --git a/src/client/component/filesystem.cpp b/src/client/component/filesystem.cpp new file mode 100644 index 00000000..da11d2e4 --- /dev/null +++ b/src/client/component/filesystem.cpp @@ -0,0 +1,94 @@ +#include +#include "loader/component_loader.hpp" +#include "filesystem.hpp" +#include "game_module.hpp" + +#include "game/game.hpp" +#include "dvars.hpp" + +#include +#include + +namespace filesystem +{ + namespace + { + bool custom_path_registered = false; + + std::string get_binary_directory() + { + const auto dir = game_module::get_host_module().get_folder(); + return utils::string::replace(dir, "/", "\\"); + } + + void register_custom_path_stub(const char* path, const char* dir) + { + if (!custom_path_registered) + { + custom_path_registered = true; + + const auto launcher_dir = get_binary_directory(); + game::FS_AddLocalizedGameDirectory(launcher_dir.data(), "data"); + } + + game::FS_AddLocalizedGameDirectory(path, dir); + } + + void fs_startup_stub(const char* gamename) + { + custom_path_registered = false; + game::FS_Startup(gamename); + } + } + + file::file(std::string name) + : name_(std::move(name)) + { + char* buffer{}; + const auto size = game::FS_ReadFile(this->name_.data(), &buffer); + + if (size >= 0 && buffer) + { + this->valid_ = true; + this->buffer_.append(buffer, size); + game::FS_FreeFile(buffer); + } + } + + bool file::exists() const + { + return this->valid_; + } + + const std::string& file::get_buffer() const + { + return this->buffer_; + } + + const std::string& file::get_name() const + { + return this->name_; + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + // Set fs_basegame + dvars::override::register_string("fs_basegame", "h1-mod", game::DVAR_FLAG_WRITE); + + utils::hook::call(SELECT_VALUE(0x1403B76E2, 0x1404ED3E2), fs_startup_stub); + if (game::environment::is_mp()) + { + utils::hook::call(0x1404ED823, fs_startup_stub); + } + + utils::hook::call(SELECT_VALUE(0x1403B8D31, 0x1404EE3D0), register_custom_path_stub); + utils::hook::call(SELECT_VALUE(0x1403B8D51, 0x1404EE3F0), register_custom_path_stub); + utils::hook::call(SELECT_VALUE(0x1403B8D90, 0x1404EE42F), register_custom_path_stub); + } + }; +} + +REGISTER_COMPONENT(filesystem::component) \ No newline at end of file diff --git a/src/client/component/filesystem.hpp b/src/client/component/filesystem.hpp new file mode 100644 index 00000000..6cec8c87 --- /dev/null +++ b/src/client/component/filesystem.hpp @@ -0,0 +1,19 @@ +#pragma once + +namespace filesystem +{ + class file + { + public: + file(std::string name); + + bool exists() const; + const std::string& get_buffer() const; + const std::string& get_name() const; + + private: + bool valid_ = false; + std::string name_; + std::string buffer_; + }; +} \ No newline at end of file diff --git a/src/client/component/patches.cpp b/src/client/component/patches.cpp index a8ee11fc..e9aaf21a 100644 --- a/src/client/component/patches.cpp +++ b/src/client/component/patches.cpp @@ -7,6 +7,7 @@ #include "console.hpp" #include "network.hpp" #include "scheduler.hpp" +#include "filesystem.hpp" #include "game/game.hpp" #include "game/dvars.hpp" @@ -77,16 +78,27 @@ namespace patches } // CG_SetClientDvarFromServer - reinterpret_cast(0x140236120)(a1, a2, dvar, value); + utils::hook::invoke(0x140236120, a1, a2, dvar, value); } - /*void aim_assist_add_to_target_list(void* a1, void* a2) + const char* db_read_raw_file_stub(const char* filename, char* buf, const int size) { - if (!dvars::aimassist_enabled->current.enabled) - return; + std::string file_name = filename; + if (file_name.find(".cfg") == std::string::npos) + { + file_name.append(".cfg"); + } - game::AimAssist_AddToTargetList(a1, a2); - }*/ + const auto file = filesystem::file(file_name); + if (file.exists()) + { + snprintf(buf, size, "%s\n", file.get_buffer().data()); + return buf; + } + + // DB_ReadRawFile + return utils::hook::invoke(SELECT_VALUE(0x1401CD4F0, 0x1402BEF10), filename, buf, size); + } void bsp_sys_error_stub(const char* error, const char* arg1) { @@ -131,7 +143,7 @@ namespace patches return; } - reinterpret_cast(0x140481A00)(client, msg); + utils::hook::invoke(0x140481A00, client, msg); } void aim_assist_add_to_target_list(void* a1, void* a2) @@ -172,6 +184,9 @@ namespace patches utils::hook::nop(SELECT_VALUE(0x14018797E, 0x14024EF60), 2); utils::hook::nop(SELECT_VALUE(0x1401856DC, 0x14024C6B0), 6); + // Allow executing custom cfg files with the "exec" command + utils::hook::call(SELECT_VALUE(0x140343855, 0x140403E28), db_read_raw_file_stub); + if (!game::environment::is_sp()) { patch_mp(); From 8bf28416e720991c9adffbe69244742bc9df9316 Mon Sep 17 00:00:00 2001 From: m Date: Thu, 3 Mar 2022 07:07:37 -0600 Subject: [PATCH 4/5] use hooking utils invoke --- src/client/component/colors.cpp | 3 +-- src/client/component/command.cpp | 2 +- src/client/component/dedicated.cpp | 2 +- src/client/component/party.cpp | 11 ++++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/client/component/colors.cpp b/src/client/component/colors.cpp index 66abb6b1..75eff23a 100644 --- a/src/client/component/colors.cpp +++ b/src/client/component/colors.cpp @@ -96,8 +96,7 @@ namespace colors const size_t unk, const size_t unk2) { // CL_GetClientName (CL_GetClientNameAndClantag?) - const auto result = reinterpret_cast(0x14025BAA0)( // H1 (1.4) - local_client_num, index, buf, size, unk, unk2); + const auto result = utils::hook::invoke(0x14025BAA0, local_client_num, index, buf, size, unk, unk2); utils::string::strip(buf, buf, size); diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 01f7b241..b5c1ad40 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -91,7 +91,7 @@ namespace command void parse_commandline_stub() { parse_command_line(); - reinterpret_cast(0x1400D8210)(); // mwr: test + utils::hook::invoke(0x1400D8210); } game::dvar_t* dvar_command_stub() diff --git a/src/client/component/dedicated.cpp b/src/client/component/dedicated.cpp index dd9f920f..8de5e9ac 100644 --- a/src/client/component/dedicated.cpp +++ b/src/client/component/dedicated.cpp @@ -26,7 +26,7 @@ namespace dedicated initialized = true; // R_LoadGraphicsAssets - reinterpret_cast(0x1405DF4B0)(); + utils::hook::invoke(0x1405DF4B0); } void send_heartbeat() diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 81159b58..0605afad 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -119,7 +119,7 @@ namespace party } // This function either does Dvar_SetString or Dvar_RegisterString for the given dvar - reinterpret_cast(0x1404FB210)(dvar_name, string); + utils::hook::invoke(0x1404FB210, dvar_name, string); } void disconnect_stub() @@ -129,12 +129,12 @@ namespace party if (game::CL_IsCgameInitialized()) { // CL_ForwardCommandToServer - reinterpret_cast(0x140253480)(0, "disconnect"); + utils::hook::invoke(0x140253480, 0, "disconnect"); // CL_WritePacket - reinterpret_cast(0x14024DB10)(0); + utils::hook::invoke(0x14024DB10, 0); } // CL_Disconnect - reinterpret_cast(0x140252060)(0); + utils::hook::invoke(0x140252060, 0); } } @@ -337,7 +337,8 @@ namespace party *reinterpret_cast(0x14A3A91D0) = 1; // sv_map_restart *reinterpret_cast(0x14A3A91D4) = 1; // sv_loadScripts *reinterpret_cast(0x14A3A91D8) = 0; // sv_migrate - reinterpret_cast(0x14047E7F0)(); // SV_CheckLoadGame + + utils::hook::invoke(0x14047E7F0); // SV_CheckLoadGame }); command::add("fast_restart", []() From 836bbf89a33bb8d3f52dab51f0469d26efda9166 Mon Sep 17 00:00:00 2001 From: Skull Merlin <86374920+skkuull@users.noreply.github.com> Date: Thu, 3 Mar 2022 16:49:58 +0200 Subject: [PATCH 5/5] missing address for sp --- src/client/game/symbols.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index ff0b8b64..6e9bd9e8 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -145,7 +145,7 @@ namespace game * Variables **************************************************************/ - WEAK symbol sv_cmd_args{0, 0x14946BA20}; + WEAK symbol sv_cmd_args{0x14AD99A10, 0x14946BA20}; WEAK symbol command_whitelist{0x141079A60, 0x14120C360}; WEAK symbol cmd_functions{0x14AD99AB8, 0x14946BAC8};