Add g_gravity dvar

This commit is contained in:
FutureRave 2022-04-27 00:02:11 +01:00
parent 6d18534a6d
commit 0f22c5b77d
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
3 changed files with 31 additions and 7 deletions

View File

@ -11,12 +11,14 @@ namespace gameplay
{
utils::hook::detour pm_weapon_use_ammo_hook;
void stuck_in_client_stub(void* entity)
int stuck_in_client_stub(void* entity)
{
if (dvars::g_playerEjection->current.enabled)
{
reinterpret_cast<void(*)(void*)>(0x1402DA310)(entity); // StuckInClient
return utils::hook::invoke<int>(0x1402DA310, entity); // StuckInClient
}
return 0;
}
void cm_transformed_capsule_trace_stub(game::trace_t* results, const float* start, const float* end,
@ -24,11 +26,8 @@ namespace gameplay
{
if (dvars::g_playerCollision->current.enabled)
{
reinterpret_cast<void(*)
(game::trace_t*, const float*, const float*, game::Bounds*, game::Bounds*, unsigned int,
const float*, const float*)>
(0x1403AB1C0)
(results, start, end, bounds, capsule, contents, origin, angles); // CM_TransformedCapsuleTrace
utils::hook::invoke<void>(0x1403AB1C0,
results, start, end, bounds, capsule, contents, origin, angles); // CM_TransformedCapsuleTrace
}
}
@ -64,6 +63,23 @@ namespace gameplay
pm_weapon_use_ammo_hook.invoke<void>(ps, weapon, is_alternate, amount, hand);
}
}
const auto client_end_frame_stub = utils::hook::assemble([](utils::hook::assembler& a)
{
a.push(rax);
a.mov(rax, qword_ptr(reinterpret_cast<int64_t>(&dvars::g_gravity)));
a.mov(eax, dword_ptr(rax, 0x10));
a.mov(word_ptr(rbx, 0x36), ax);
a.pop(rax);
// Game code hook skipped
a.mov(eax, dword_ptr(rbx, 0x5084));
a.mov(rdi, rcx);
a.jmp(0x1402D5A6A);
});
}
class component final : public component_interface
@ -95,6 +111,12 @@ namespace gameplay
// Change jump_slowdownEnable dvar flags to just "replicated"
utils::hook::set<uint8_t>(0x140135992, game::DVAR_FLAG_REPLICATED);
// Choosing the following min/max because the game would truncate larger values
dvars::g_gravity = game::Dvar_RegisterInt("g_gravity", 800, std::numeric_limits<short>::min(),
std::numeric_limits<short>::max(), game::DVAR_FLAG_REPLICATED, "Gravity in inches per second per second");
utils::hook::jump(0x1402D5A5D, client_end_frame_stub, true);
utils::hook::nop(0x1402D5A69, 1); // Nop skipped opcode
}
};
}

View File

@ -21,6 +21,7 @@ namespace dvars
game::dvar_t* g_playerCollision = nullptr;
game::dvar_t* pm_bouncing = nullptr;
game::dvar_t* g_gravity = nullptr;
game::dvar_t* player_sustainAmmo = nullptr;

View File

@ -20,6 +20,7 @@ namespace dvars
extern game::dvar_t* g_playerEjection;
extern game::dvar_t* pm_bouncing;
extern game::dvar_t* g_gravity;
extern game::dvar_t* player_sustainAmmo;