Merge pull request #44 from diamante0018/master

Player collision/ejection
This commit is contained in:
Maurice Heumann 2022-03-15 12:03:04 +01:00 committed by GitHub
commit aaebbd89f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 0 deletions

View File

@ -63,6 +63,8 @@ namespace game
PM_WeaponUseAmmo_t PM_WeaponUseAmmo; PM_WeaponUseAmmo_t PM_WeaponUseAmmo;
CM_TransformedCapsuleTrace_t CM_TransformedCapsuleTrace;
Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand; Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand;
decltype(longjmp)* _longjmp; decltype(longjmp)* _longjmp;
@ -664,6 +666,9 @@ namespace game
native::PM_WeaponUseAmmo = native::PM_WeaponUseAmmo_t(SELECT_VALUE(0x463F80, 0x42E930, 0x0)); native::PM_WeaponUseAmmo = native::PM_WeaponUseAmmo_t(SELECT_VALUE(0x463F80, 0x42E930, 0x0));
native::CM_TransformedCapsuleTrace = native::CM_TransformedCapsuleTrace_t(
SELECT_VALUE(0x4F9B80, 0x541340, 0x0));
native::Cmd_ExecuteSingleCommand = native::Cmd_ExecuteSingleCommand_t( native::Cmd_ExecuteSingleCommand = native::Cmd_ExecuteSingleCommand_t(
SELECT_VALUE(0x4D6960, 0x5462B0, 0x4CC360)); SELECT_VALUE(0x4D6960, 0x5462B0, 0x4CC360));

View File

@ -100,6 +100,11 @@ namespace game
typedef void (*PM_WeaponUseAmmo_t)(playerState_s* ps, const Weapon weapon, bool isAlternate, int amount, PlayerHandIndex hand); typedef void (*PM_WeaponUseAmmo_t)(playerState_s* ps, const Weapon weapon, bool isAlternate, int amount, PlayerHandIndex hand);
extern PM_WeaponUseAmmo_t PM_WeaponUseAmmo; extern PM_WeaponUseAmmo_t PM_WeaponUseAmmo;
typedef void (*CM_TransformedCapsuleTrace_t)(game::native::trace_t* results, const float* start, const float* end,
const game::native::Bounds* bounds, const game::native::Bounds* capsule, int contents,
const float* origin, const float* angles);
extern CM_TransformedCapsuleTrace_t CM_TransformedCapsuleTrace;
typedef void (*Cmd_ExecuteSingleCommand_t)(LocalClientNum_t localClientNum, int controllerIndex, const char* text); typedef void (*Cmd_ExecuteSingleCommand_t)(LocalClientNum_t localClientNum, int controllerIndex, const char* text);
extern Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand; extern Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand;

View File

@ -5,6 +5,8 @@
const game::native::dvar_t* player_movement::player_sustainAmmo; const game::native::dvar_t* player_movement::player_sustainAmmo;
const game::native::dvar_t* player_movement::pm_bounces; 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;
void player_movement::pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon, 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) bool is_alternate, int amount, game::native::PlayerHandIndex hand)
@ -69,6 +71,27 @@ __declspec(naked) void player_movement::pm_step_slide_move_stub_sp()
} }
} }
int player_movement::stuck_in_client_stub(game::native::gentity_s* self)
{
if (player_movement::pm_playerEjection->current.enabled)
{
return reinterpret_cast<int(*)(game::native::gentity_s*)>(0x4F8930)(self);
}
return 0;
}
void player_movement::cm_transformed_capsule_trace_stub(game::native::trace_t* results, const float* start,
const float* end, const game::native::Bounds* bounds, const game::native::Bounds* capsule, int contents,
const float* origin, const float* angles)
{
if (player_movement::pm_playerCollision->current.enabled)
{
game::native::CM_TransformedCapsuleTrace(results, start, end,
bounds, capsule, contents, origin, angles);
}
}
const game::native::dvar_t* player_movement::dvar_register_player_sustain_ammo(const char* dvar_name, const game::native::dvar_t* player_movement::dvar_register_player_sustain_ammo(const char* dvar_name,
bool value, unsigned __int16 /*flags*/, const char* description) bool value, unsigned __int16 /*flags*/, const char* description)
{ {
@ -80,6 +103,9 @@ const game::native::dvar_t* player_movement::dvar_register_player_sustain_ammo(c
void player_movement::patch_mp() void player_movement::patch_mp()
{ {
player_movement::pm_playerEjection = game::native::Dvar_RegisterBool("pm_playerEjection",
true, game::native::DVAR_CODINFO, "Push intersecting players away from each other");
utils::hook(0x418D9C, &player_movement::dvar_register_player_sustain_ammo, HOOK_CALL).install()->quick(); utils::hook(0x418D9C, &player_movement::dvar_register_player_sustain_ammo, HOOK_CALL).install()->quick();
utils::hook(0x42B5DA, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); utils::hook(0x42B5DA, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick();
@ -87,6 +113,10 @@ void player_movement::patch_mp()
utils::hook(0x42AE95, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); utils::hook(0x42AE95, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick();
utils::hook(0x424D51, &player_movement::pm_step_slide_move_stub_mp, HOOK_JUMP).install()->quick(); utils::hook(0x424D51, &player_movement::pm_step_slide_move_stub_mp, HOOK_JUMP).install()->quick();
utils::hook(0x4F9EFB, &player_movement::stuck_in_client_stub, HOOK_CALL).install()->quick(); // ClientEndFrame
utils::hook(0x57CF45, &player_movement::cm_transformed_capsule_trace_stub, HOOK_CALL).install()->quick(); // SV_ClipMoveToEntity
utils::hook(0x482C1B, &player_movement::cm_transformed_capsule_trace_stub, HOOK_CALL).install()->quick(); // CG_ClipMoveToEntity
} }
void player_movement::patch_sp() void player_movement::patch_sp()
@ -99,6 +129,9 @@ void player_movement::patch_sp()
utils::hook(0x6484E2, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick(); utils::hook(0x6484E2, &player_movement::pm_weapon_use_ammo, HOOK_CALL).install()->quick();
utils::hook(0x43D918, &player_movement::pm_step_slide_move_stub_sp, HOOK_JUMP).install()->quick(); utils::hook(0x43D918, &player_movement::pm_step_slide_move_stub_sp, HOOK_JUMP).install()->quick();
utils::hook(0x41F9A6, &player_movement::cm_transformed_capsule_trace_stub, HOOK_CALL).install()->quick(); // SV_ClipMoveToEntity
utils::hook(0x57B14F, &player_movement::cm_transformed_capsule_trace_stub, HOOK_CALL).install()->quick(); // CG_ClipMoveToEntity
} }
void player_movement::post_load() void player_movement::post_load()
@ -110,6 +143,8 @@ void player_movement::post_load()
player_movement::pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false, player_movement::pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false,
game::native::dvar_flags::DVAR_CODINFO, "CoD4 Bounces"); game::native::dvar_flags::DVAR_CODINFO, "CoD4 Bounces");
player_movement::pm_playerCollision = game::native::Dvar_RegisterBool("pm_playerCollision",
true, game::native::DVAR_CODINFO, "Push intersecting players away from each other");
if (game::is_mp()) this->patch_mp(); if (game::is_mp()) this->patch_mp();
else if (game::is_sp()) this->patch_sp(); else if (game::is_sp()) this->patch_sp();

View File

@ -10,6 +10,8 @@ public:
private: private:
static const game::native::dvar_t* player_sustainAmmo; static const game::native::dvar_t* player_sustainAmmo;
static const game::native::dvar_t* pm_bounces; static const game::native::dvar_t* pm_bounces;
static const game::native::dvar_t* pm_playerEjection;
static const game::native::dvar_t* pm_playerCollision;
static void pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon, static void pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon,
bool isAlternate, int amount, game::native::PlayerHandIndex hand); bool isAlternate, int amount, game::native::PlayerHandIndex hand);
@ -20,6 +22,11 @@ private:
static void pm_step_slide_move_stub_mp(); static void pm_step_slide_move_stub_mp();
static void pm_step_slide_move_stub_sp(); static void pm_step_slide_move_stub_sp();
static int stuck_in_client_stub(game::native::gentity_s* self);
static void cm_transformed_capsule_trace_stub(game::native::trace_t* results, const float* start,
const float* end, const game::native::Bounds* bounds, const game::native::Bounds* capsule,
int contents, const float* origin, const float* angles);
static void patch_mp(); static void patch_mp();
static void patch_sp(); static void patch_sp();
}; };