From eec738e1292a47c8e368c621c19da5891d8edc72 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sat, 21 May 2022 16:59:28 +0200 Subject: [PATCH] Minor refactor --- src/client/component/chat.cpp | 2 +- src/client/component/gameplay.cpp | 8 ++++---- src/client/component/gsc_patches.cpp | 21 +++++++++++++++++++++ src/client/game/game.cpp | 4 ++-- src/client/game/game.hpp | 10 +++++----- src/client/game/symbols.hpp | 2 ++ src/client/std_include.hpp | 3 --- 7 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 src/client/component/gsc_patches.cpp diff --git a/src/client/component/chat.cpp b/src/client/component/chat.cpp index 0e66a72..19911a2 100644 --- a/src/client/component/chat.cpp +++ b/src/client/component/chat.cpp @@ -60,7 +60,7 @@ void client_command(int client_number) { class component final : public component_interface { public: void post_unpack() override { - utils::hook::call(SELECT(0x58DA1C, 0x4FB3BD), client_command); + utils::hook::call(SELECT_VALUE(0x58DA1C, 0x4FB3BD), client_command); add_chat_commands(); } diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp index 16d4f73..a89025d 100644 --- a/src/client/component/gameplay.cpp +++ b/src/client/component/gameplay.cpp @@ -69,12 +69,12 @@ void __declspec(naked) jump_start_sp_stub() { class component final : public component_interface { public: void post_unpack() override { - if (game::environment::t5mp()) { + if (game::environment::is_mp()) { jump_height = reinterpret_cast(0xC4F7D8); utils::hook::jump(0x5CE92F, jump_start_mp_stub); } - if (game::environment::t5zm()) { + if (game::environment::is_sp()) { player_sustainAmmo = reinterpret_cast(0xBCD250); pm_weapon_use_ammo_hook.create(0x6979B0, &pm_weapon_use_ammo_stub); @@ -83,8 +83,8 @@ public: } player_sprintStrafeSpeedScale = - reinterpret_cast(SELECT(0xC51AE8, 0xBCD18C)); - utils::hook::jump(SELECT(0x6344B0, 0x611BC0), + reinterpret_cast(SELECT_VALUE(0xC51AE8, 0xBCD18C)); + utils::hook::jump(SELECT_VALUE(0x6344B0, 0x611BC0), bg_get_sprint_strafe_speed_scale_stub); } }; diff --git a/src/client/component/gsc_patches.cpp b/src/client/component/gsc_patches.cpp new file mode 100644 index 0000000..ae275a1 --- /dev/null +++ b/src/client/component/gsc_patches.cpp @@ -0,0 +1,21 @@ +#include + +#include "../loader/component_loader.hpp" +#include + +namespace gsc_patches { +namespace { +void g_log_printf(const char* fmt) { game::G_LogPrintf("%s", fmt); } +} // namespace + +class component final : public component_interface { +public: + void post_unpack() override { + if (game::environment::is_mp()) { + utils::hook::call(0x8426D3, g_log_printf); + } + } +}; +} // namespace gsc_patches + +REGISTER_COMPONENT(gsc_patches::component) diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index 3b9f6d4..39a7bfc 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -6,8 +6,8 @@ gamemode current = reinterpret_cast(0xA6840C) == "multiplayer"s : gamemode::zombies; namespace environment { -bool t5mp() { return current == gamemode::multiplayer; } +bool is_mp() { return current == gamemode::multiplayer; } -bool t5zm() { return current == gamemode::zombies; } +bool is_sp() { return current == gamemode::zombies; } } // namespace environment } // namespace game diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index d690d06..04c3ead 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -1,6 +1,6 @@ #pragma once -#define SELECT(mp, zm) (game::environment::t5mp() ? mp : zm) +#define SELECT_VALUE(mp, zm) (game::environment::is_mp() ? (mp) : (zm)) namespace game { enum gamemode { none, multiplayer, zombies }; @@ -8,8 +8,8 @@ enum gamemode { none, multiplayer, zombies }; extern gamemode current; namespace environment { -bool t5mp(); -bool t5zm(); +bool is_mp(); +bool is_sp(); } // namespace environment template class symbol { @@ -17,8 +17,8 @@ public: symbol(const size_t t5mp, const size_t t5zm) : t5mp_(reinterpret_cast(t5mp)), t5zm_(reinterpret_cast(t5zm)) {} - T* get() const { - if (environment::t5mp()) { + [[nodiscard]] T* get() const { + if (environment::is_mp()) { return t5mp_; } diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index ab35520..c43ba0b 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -58,8 +58,10 @@ WEAK symbol I_CleanStr{0x4B0700, 0x0}; WEAK symbol ConcatArgs{0x5D5F10, 0x4FB210}; WEAK symbol ClientCommand{0x63DB70, 0x4AF770}; + WEAK symbol G_Say{0x51BBD0, 0x49A790}; +WEAK symbol G_LogPrintf{0x5CD250, 0x69EA30}; WEAK symbol Scr_Notify{ 0x458D30, 0x0}; diff --git a/src/client/std_include.hpp b/src/client/std_include.hpp index 5dff469..ab36796 100644 --- a/src/client/std_include.hpp +++ b/src/client/std_include.hpp @@ -1,8 +1,5 @@ #pragma once -#define BINARY_PAYLOAD_SIZE 0x0A000000 -#define TLS_PAYLOAD_SIZE 0x2000 - #define DLL_EXPORT extern "C" __declspec(dllexport) #define WIN32_LEAN_AND_MEAN