From aaba9cbcc5686ae015b2787a5fd7cec3adc929cd Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Sat, 8 Oct 2022 00:19:02 +0300 Subject: [PATCH 1/3] add bounces & gravity dvars --- src/client/component/gameplay.cpp | 77 +++++++++++++++++++++++++++++++ src/client/game/dvars.cpp | 3 ++ src/client/game/dvars.hpp | 3 ++ 3 files changed, 83 insertions(+) create mode 100644 src/client/component/gameplay.cpp diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp new file mode 100644 index 00000000..382a42f8 --- /dev/null +++ b/src/client/component/gameplay.cpp @@ -0,0 +1,77 @@ +#include +#include "loader/component_loader.hpp" + +#include "dvars.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + +#include +#include +#include + +namespace gameplay +{ + namespace + { + void* bg_bounces_stub() + { + return utils::hook::assemble([](utils::hook::assembler& a) + { + const auto no_bounce = a.newLabel(); + const auto loc_70FB6F = a.newLabel(); + + a.push(rax); + + a.mov(rax, qword_ptr(reinterpret_cast(&dvars::bg_bounces))); + a.mov(al, byte_ptr(rax, 0x10)); + a.cmp(ptr(rbp, -0x66), al); + + a.pop(rax); + a.jz(no_bounce); + a.jmp(0x70FBF0_b); + + a.bind(no_bounce); + a.cmp(ptr(rsp, 0x44), r14d); + a.jnz(loc_70FB6F); + a.jmp(0x70FBE1_b); + + a.bind(loc_70FB6F); + a.jmp(0x70FB6F_b); + }); + } + + void* bg_gravity_stub() + { + return utils::hook::assemble([](utils::hook::assembler& a) + { + a.mov(rax, qword_ptr(reinterpret_cast(&dvars::bg_gravity))); + a.mov(eax, dword_ptr(rax, 0x10)); + a.mov(dword_ptr(rdi, 0x78), eax); + + a.call(0xBB3030_b); + a.mov(ptr(rdi, 0x32C), eax); + + a.jmp(0xAFA342_b); + }); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + // Implement bounces + dvars::bg_bounces = game::Dvar_RegisterBool("bg_bounces", false, game::DVAR_FLAG_REPLICATED, "Enables bouncing"); + utils::hook::jump(0x70FBB7_b, bg_bounces_stub(), true); + + // Implement gravity dvar + dvars::bg_gravity = game::Dvar_RegisterInt("bg_gravity", 800, 0, 1000, game::DVAR_FLAG_REPLICATED, "Game gravity in inches per second squared"); + utils::hook::nop(0xAFA330_b, 13); + utils::hook::jump(0xAFA330_b, bg_gravity_stub(), true); + } + }; +} + +REGISTER_COMPONENT(gameplay::component) \ No newline at end of file diff --git a/src/client/game/dvars.cpp b/src/client/game/dvars.cpp index 1b74ecf1..63f32ba1 100644 --- a/src/client/game/dvars.cpp +++ b/src/client/game/dvars.cpp @@ -25,6 +25,9 @@ namespace dvars game::dvar_t* r_fullbright = nullptr; + game::dvar_t* bg_bounces = nullptr; + game::dvar_t* bg_gravity = nullptr; + std::string dvar_get_vector_domain(const int components, const game::DvarLimits& domain) { if (domain.vector.min == -FLT_MAX) diff --git a/src/client/game/dvars.hpp b/src/client/game/dvars.hpp index b7dfd342..8534c176 100644 --- a/src/client/game/dvars.hpp +++ b/src/client/game/dvars.hpp @@ -21,6 +21,9 @@ namespace dvars extern game::dvar_t* r_fullbright; + extern game::dvar_t* bg_bounces; + extern game::dvar_t* bg_gravity; + std::string dvar_get_vector_domain(const int components, const game::DvarLimits& domain); std::string dvar_get_domain(const game::DvarType type, const game::DvarLimits& domain); std::string dvar_get_name(const game::dvar_t* dvar); From 5acd8073562f63e7c540d225f54811d2725b5fc3 Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 11 Oct 2022 22:22:48 +0300 Subject: [PATCH 2/3] playerejection --- src/client/component/gameplay.cpp | 15 ++++++++++++++- src/client/game/dvars.cpp | 2 ++ src/client/game/dvars.hpp | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp index 382a42f8..22f22f30 100644 --- a/src/client/component/gameplay.cpp +++ b/src/client/component/gameplay.cpp @@ -14,6 +14,16 @@ namespace gameplay { namespace { + utils::hook::detour stuck_in_client_hook; + + void stuck_in_client_stub(void* entity) + { + if (dvars::g_playerEjection->current.enabled) + { + stuck_in_client_hook.invoke(entity); + } + } + void* bg_bounces_stub() { return utils::hook::assemble([](utils::hook::assembler& a) @@ -63,13 +73,16 @@ namespace gameplay void post_unpack() override { // Implement bounces - dvars::bg_bounces = game::Dvar_RegisterBool("bg_bounces", false, game::DVAR_FLAG_REPLICATED, "Enables bouncing"); + dvars::bg_bounces = game::Dvar_RegisterBool("bg_bounces", false, game::DVAR_FLAG_REPLICATED, "Enables bounces"); utils::hook::jump(0x70FBB7_b, bg_bounces_stub(), true); // Implement gravity dvar dvars::bg_gravity = game::Dvar_RegisterInt("bg_gravity", 800, 0, 1000, game::DVAR_FLAG_REPLICATED, "Game gravity in inches per second squared"); utils::hook::nop(0xAFA330_b, 13); utils::hook::jump(0xAFA330_b, bg_gravity_stub(), true); + + dvars::g_playerEjection = game::Dvar_RegisterBool("g_playerEjection", true, game::DVAR_FLAG_REPLICATED, "Flag whether player ejection is on or off"); + stuck_in_client_hook.create(0xAFD9B0_b, stuck_in_client_stub); } }; } diff --git a/src/client/game/dvars.cpp b/src/client/game/dvars.cpp index 63f32ba1..d4ba436a 100644 --- a/src/client/game/dvars.cpp +++ b/src/client/game/dvars.cpp @@ -28,6 +28,8 @@ namespace dvars game::dvar_t* bg_bounces = nullptr; game::dvar_t* bg_gravity = nullptr; + game::dvar_t* g_playerEjection = nullptr; + std::string dvar_get_vector_domain(const int components, const game::DvarLimits& domain) { if (domain.vector.min == -FLT_MAX) diff --git a/src/client/game/dvars.hpp b/src/client/game/dvars.hpp index 8534c176..dfce1b8f 100644 --- a/src/client/game/dvars.hpp +++ b/src/client/game/dvars.hpp @@ -24,6 +24,8 @@ namespace dvars extern game::dvar_t* bg_bounces; extern game::dvar_t* bg_gravity; + extern game::dvar_t* g_playerEjection; + std::string dvar_get_vector_domain(const int components, const game::DvarLimits& domain); std::string dvar_get_domain(const game::DvarType type, const game::DvarLimits& domain); std::string dvar_get_name(const game::dvar_t* dvar); From a6920d08a0fac9ffef9845a6dfba63dc9cb0bd3e Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Wed, 12 Oct 2022 17:11:45 +0300 Subject: [PATCH 3/3] rename --- src/client/component/gameplay.cpp | 8 ++++---- src/client/game/dvars.cpp | 2 +- src/client/game/dvars.hpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp index 22f22f30..ffcf30f4 100644 --- a/src/client/component/gameplay.cpp +++ b/src/client/component/gameplay.cpp @@ -51,11 +51,11 @@ namespace gameplay }); } - void* bg_gravity_stub() + void* g_gravity_stub() { return utils::hook::assemble([](utils::hook::assembler& a) { - a.mov(rax, qword_ptr(reinterpret_cast(&dvars::bg_gravity))); + a.mov(rax, qword_ptr(reinterpret_cast(&dvars::g_gravity))); a.mov(eax, dword_ptr(rax, 0x10)); a.mov(dword_ptr(rdi, 0x78), eax); @@ -77,9 +77,9 @@ namespace gameplay utils::hook::jump(0x70FBB7_b, bg_bounces_stub(), true); // Implement gravity dvar - dvars::bg_gravity = game::Dvar_RegisterInt("bg_gravity", 800, 0, 1000, game::DVAR_FLAG_REPLICATED, "Game gravity in inches per second squared"); + dvars::g_gravity = game::Dvar_RegisterInt("g_gravity", 800, 0, 1000, game::DVAR_FLAG_REPLICATED, "Game gravity in inches per second squared"); utils::hook::nop(0xAFA330_b, 13); - utils::hook::jump(0xAFA330_b, bg_gravity_stub(), true); + utils::hook::jump(0xAFA330_b, g_gravity_stub(), true); dvars::g_playerEjection = game::Dvar_RegisterBool("g_playerEjection", true, game::DVAR_FLAG_REPLICATED, "Flag whether player ejection is on or off"); stuck_in_client_hook.create(0xAFD9B0_b, stuck_in_client_stub); diff --git a/src/client/game/dvars.cpp b/src/client/game/dvars.cpp index d4ba436a..b4f69635 100644 --- a/src/client/game/dvars.cpp +++ b/src/client/game/dvars.cpp @@ -26,7 +26,7 @@ namespace dvars game::dvar_t* r_fullbright = nullptr; game::dvar_t* bg_bounces = nullptr; - game::dvar_t* bg_gravity = nullptr; + game::dvar_t* g_gravity = nullptr; game::dvar_t* g_playerEjection = nullptr; diff --git a/src/client/game/dvars.hpp b/src/client/game/dvars.hpp index dfce1b8f..adb4344b 100644 --- a/src/client/game/dvars.hpp +++ b/src/client/game/dvars.hpp @@ -22,7 +22,7 @@ namespace dvars extern game::dvar_t* r_fullbright; extern game::dvar_t* bg_bounces; - extern game::dvar_t* bg_gravity; + extern game::dvar_t* g_gravity; extern game::dvar_t* g_playerEjection;