From 4f75e2a562c4d805207653faf5020fb0f2a688e1 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 22 Mar 2022 20:52:31 +0000 Subject: [PATCH] Implement jump spread dvar --- src/module/player_movement.cpp | 41 ++++++++++++++++++++++++++++++++-- src/module/player_movement.hpp | 8 ++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/module/player_movement.cpp b/src/module/player_movement.cpp index 5ddf1d1..525f481 100644 --- a/src/module/player_movement.cpp +++ b/src/module/player_movement.cpp @@ -11,6 +11,7 @@ const game::native::dvar_t* player_movement::jump_ladderPushVel; const game::native::dvar_t* player_movement::jump_enableFallDamage; const game::native::dvar_t* player_movement::jump_height; const game::native::dvar_t* player_movement::jump_stepSize; +const game::native::dvar_t* player_movement::jump_spreadAdd; const game::native::dvar_t* player_movement::pm_bounces; const game::native::dvar_t* player_movement::pm_playerEjection; const game::native::dvar_t* player_movement::pm_playerCollision; @@ -20,6 +21,7 @@ const game::native::dvar_t* player_movement::pm_elevators; DWORD player_movement::bounce_addr; DWORD player_movement::dont_bounce_addr; DWORD player_movement::push_off_ladder_addr; +DWORD player_movement::jump_start_addr; void player_movement::pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon, bool is_alternate, int amount, game::native::PlayerHandIndex hand) @@ -127,7 +129,7 @@ __declspec(naked) void player_movement::jump_push_off_ladder_stub() } } -__declspec(naked) void player_movement::jump_start_stub() +__declspec(naked) void player_movement::jump_check_stub() { __asm { @@ -294,6 +296,19 @@ __declspec(naked) void player_movement::jump_get_step_height_stub_sp() } } +__declspec(naked) void player_movement::jump_start_stub() +{ + __asm + { + push eax + mov eax, player_movement::jump_spreadAdd + fadd dword ptr [eax + 0xC] + pop eax + + jmp player_movement::jump_start_addr + } +} + const game::native::dvar_t* player_movement::dvar_register_player_sustain_ammo(const char* dvar_name, bool value, unsigned __int16 /*flags*/, const char* description) { @@ -321,6 +336,15 @@ const game::native::dvar_t* player_movement::dvar_register_jump_step_size(const return player_movement::jump_stepSize; } +const game::native::dvar_t* player_movement::dvar_register_jump_spread_add(const char* dvar_name, + float value, float min, float max, unsigned __int16 /*flags*/, const char* description) +{ + player_movement::jump_spreadAdd = game::native::Dvar_RegisterFloat(dvar_name, + value, min, max, game::native::DVAR_CODINFO, description); + + return player_movement::jump_spreadAdd; +} + const game::native::dvar_t* player_movement::dvar_register_jump_slowdown_enable(const char* dvar_name, bool value, unsigned __int16 /*flags*/, const char* description) { @@ -352,6 +376,7 @@ void player_movement::patch_mp() utils::hook(0x41602B, &player_movement::dvar_register_jump_height, HOOK_CALL).install()->quick(); utils::hook(0x416074, &player_movement::dvar_register_jump_slowdown_enable, HOOK_CALL).install()->quick(); utils::hook(0x41605E, &player_movement::dvar_register_jump_step_size, HOOK_CALL).install()->quick(); + utils::hook(0x4160DA, &player_movement::dvar_register_jump_spread_add, HOOK_CALL).install()->quick(); utils::hook(0x42B5DA, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); utils::hook(0x42B2BD, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); @@ -375,7 +400,8 @@ void player_movement::patch_mp() utils::hook(0x416866, &player_movement::jump_push_off_ladder_stub, HOOK_JUMP).install()->quick(); // Jump_Check utils::hook::nop(0x41686B, 1); // Nop skipped opcode - utils::hook(0x416969, &player_movement::jump_start_stub, HOOK_JUMP).install()->quick(); // Jump_Check + // Modify third argument of Jump_Start with the value of jump_height dvar + utils::hook(0x416969, &player_movement::jump_check_stub, HOOK_JUMP).install()->quick(); // Jump_Check utils::hook::nop(0x41696E, 1); // Nop skipped opcode utils::hook(0x4225CA, &player_movement::jump_apply_slowdown_stub, HOOK_CALL).install()->quick(); // PM_WalkMove @@ -384,6 +410,10 @@ void player_movement::patch_mp() utils::hook(0x422BE0, &player_movement::pm_crash_land_stub_mp, HOOK_CALL).install()->quick(); // PM_GroundTrace utils::hook(0x424B2B, &player_movement::jump_get_step_height_stub_mp, HOOK_CALL).install()->quick(); // PM_StepSlideMove + + // Modify the hardcoded value of the spread with the value of jump_spreadAdd + utils::hook(0x4166F0, &player_movement::jump_start_stub, HOOK_JUMP).install()->quick(); + utils::hook::nop(0x4166F5, 1); // Nop skipped opcode } void player_movement::patch_sp() @@ -394,6 +424,8 @@ void player_movement::patch_sp() 128.0f, 0.0f, 1024.0f, game::native::DVAR_CODINFO, "The velocity of a jump off of a ladder"); player_movement::jump_stepSize = game::native::Dvar_RegisterFloat("jump_stepSize", 18.0f, 0.0f, 64.0f, game::native::DVAR_CODINFO, "The maximum step up to the top of a jump arc"); + player_movement::jump_spreadAdd = game::native::Dvar_RegisterFloat("jump_spreadAdd", + 64.0f, 0.0f, 512.0f, game::native::DVAR_CODINFO, "The amount of spread scale to add as a side effect of jumping"); utils::hook(0x648C3A, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); utils::hook(0x64891D, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); @@ -418,6 +450,10 @@ void player_movement::patch_sp() utils::hook(0x48C1F5, &player_movement::jump_get_step_height_stub_sp, HOOK_JUMP).install()->quick(); // PM_StepSlideMove utils::hook::nop(0x48C1FA, 1); // Nop skipped opcode + + // Modify the hardcoded value of the spread with the value of jump_spreadAdd + utils::hook(0x63E90A, &player_movement::jump_start_stub, HOOK_JUMP).install()->quick(); + utils::hook::nop(0x63E90F, 1); // Nop skipped opcode } void player_movement::post_load() @@ -433,6 +469,7 @@ void player_movement::post_load() player_movement::bounce_addr = SELECT_VALUE(0x43D91F, 0x424D58, 0x0); player_movement::dont_bounce_addr = SELECT_VALUE(0x43D933, 0x424D6C, 0x0); player_movement::push_off_ladder_addr = SELECT_VALUE(0x63EA4C, 0x41686C, 0x0); + player_movement::jump_start_addr = SELECT_VALUE(0x63E910, 0x4166F6, 0x0); player_movement::pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false, game::native::dvar_flags::DVAR_CODINFO, "CoD4 Bounces"); diff --git a/src/module/player_movement.hpp b/src/module/player_movement.hpp index e132879..b3f2cd5 100644 --- a/src/module/player_movement.hpp +++ b/src/module/player_movement.hpp @@ -13,6 +13,7 @@ private: static const game::native::dvar_t* jump_enableFallDamage; static const game::native::dvar_t* jump_height; static const game::native::dvar_t* jump_stepSize; + static const game::native::dvar_t* jump_spreadAdd; static const game::native::dvar_t* pm_bounces; static const game::native::dvar_t* pm_playerEjection; static const game::native::dvar_t* pm_playerCollision; @@ -22,6 +23,7 @@ private: static DWORD bounce_addr; static DWORD dont_bounce_addr; static DWORD push_off_ladder_addr; + static DWORD jump_start_addr; static void pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon, bool is_alternate, int amount, game::native::PlayerHandIndex hand); @@ -32,6 +34,8 @@ private: float value, float min, float max, unsigned __int16 flags, const char* description); static const game::native::dvar_t* dvar_register_jump_step_size(const char* dvar_name, float value, float min, float max, unsigned __int16 flags, const char* description); + static const game::native::dvar_t* dvar_register_jump_spread_add(const char* dvar_name, + float value, float min, float max, unsigned __int16 flags, const char* description); static const game::native::dvar_t* dvar_register_jump_slowdown_enable(const char* dvar_name, bool value, unsigned __int16 flags, const char* description); static const game::native::dvar_t* dvar_register_player_sustain_ammo(const char* dvar_name, @@ -57,7 +61,7 @@ private: static void jump_push_off_ladder_stub(); // On SP this is already unlocked - static void jump_start_stub(); + static void jump_check_stub(); static void jump_apply_slowdown_stub(game::native::playerState_s* ps); static float jump_get_land_factor(game::native::playerState_s* ps); @@ -69,6 +73,8 @@ private: static bool jump_get_step_height_stub_mp(game::native::playerState_s* ps, const float* origin, float* stepSize); static void jump_get_step_height_stub_sp(); + static void jump_start_stub(); + static void patch_mp(); static void patch_sp(); };