From cf8deb9cacea9aad868183ef90206135825e8e2e Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Tue, 6 Dec 2022 22:11:25 +0300 Subject: [PATCH] Update func_vehicle for multiplayer (#792) * Update func_vehicle for multiplayer. Added mp_legacy_vehicle_block cvar. * Update dist/game.cfg Co-authored-by: Sergey Shorokhov * Update regamedll/dlls/game.cpp Co-authored-by: Sergey Shorokhov * Fix default behavior * Optimization Thanks to https://github.com/s1lentq/ReGameDLL_CS/pull/737#issuecomment-1068038171 help! * Update README.md Co-authored-by: Sergey Shorokhov --- README.md | 1 + dist/game.cfg | 9 ++++++ regamedll/dlls/game.cpp | 4 +++ regamedll/dlls/game.h | 1 + regamedll/dlls/multiplay_gamerules.cpp | 4 +++ regamedll/dlls/player.cpp | 15 +++++++++ regamedll/dlls/vehicle.cpp | 43 +++++++++++++++++++++----- 7 files changed, 70 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index db1305b01..bf7408dac 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab | mp_plant_c4_anywhere | 0 | 0 | 1 | When set, players can plant anywhere, not only in bombsites.
`0` disabled
`1` enabled | | mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. | | mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. | +| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.
`0` New behavior
`1` Legacy behavior | ## How to install zBot for CS 1.6? diff --git a/dist/game.cfg b/dist/game.cfg index 6bb2b7b03..efebcba89 100644 --- a/dist/game.cfg +++ b/dist/game.cfg @@ -494,3 +494,12 @@ mp_give_c4_frags "3" // // Default value: "1.0" mp_hostages_rescued_ratio "1.0" + +// Legacy func_vehicle behavior when blocked by another entity. +// New one is more useful for playing multiplayer. +// +// 0 - New behavior +// 1 - Legacy behavior +// +// Default value: "1" +mp_legacy_vehicle_block "1" diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp index 672c6a62f..11e35513b 100644 --- a/regamedll/dlls/game.cpp +++ b/regamedll/dlls/game.cpp @@ -166,6 +166,8 @@ cvar_t give_c4_frags = { "mp_give_c4_frags", "3", 0, 3.0f, n cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, nullptr }; +cvar_t legacy_vehicle_block = { "mp_legacy_vehicle_block", "1", 0, 0.0f, nullptr }; + void GameDLL_Version_f() { if (Q_stricmp(CMD_ARGV(1), "version") != 0) @@ -410,6 +412,8 @@ void EXT_FUNC GameDLLInit() CVAR_REGISTER(&hostages_rescued_ratio); + CVAR_REGISTER(&legacy_vehicle_block); + // print version CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n"); diff --git a/regamedll/dlls/game.h b/regamedll/dlls/game.h index bcdfd0196..a9b9158b0 100644 --- a/regamedll/dlls/game.h +++ b/regamedll/dlls/game.h @@ -191,6 +191,7 @@ extern cvar_t plant_c4_anywhere; extern cvar_t give_c4_frags; extern cvar_t hostages_rescued_ratio; +extern cvar_t legacy_vehicle_block; #endif extern cvar_t scoreboard_showmoney; diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index ab0aa0fb6..2a8821d9f 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -3926,7 +3926,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerKilled)(CBasePlayer *pVictim, else if (ktmp && ktmp->Classify() == CLASS_VEHICLE) { CBasePlayer *pDriver = static_cast(((CFuncVehicle *)ktmp)->m_pDriver); +#ifdef REGAMEDLL_FIXES + if (pDriver && !pDriver->has_disconnected) +#else if (pDriver) +#endif { pKiller = pDriver->pev; peKiller = static_cast(pDriver); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 6202012eb..7c0b62e19 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -4030,7 +4030,12 @@ void CBasePlayer::PlayerUse() CBaseEntity *pTrain = Instance(pev->groundentity); if (pTrain && pTrain->Classify() == CLASS_VEHICLE) { +#ifdef REGAMEDLL_ADD + if (legacy_vehicle_block.value) + ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#else ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#endif } return; } @@ -4572,7 +4577,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() { m_afPhysicsFlags &= ~PFLAG_ONTRAIN; m_iTrain = (TRAIN_NEW | TRAIN_OFF); +#ifdef REGAMEDLL_ADD + if (legacy_vehicle_block.value) + ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#else ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#endif return; } } @@ -4581,7 +4591,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() // Turn off the train if you jump, strafe, or the train controls go dead m_afPhysicsFlags &= ~PFLAG_ONTRAIN; m_iTrain = (TRAIN_NEW | TRAIN_OFF); +#ifdef REGAMEDLL_ADD + if (legacy_vehicle_block.value) + ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#else ((CFuncVehicle *)pTrain)->m_pDriver = nullptr; +#endif return; } diff --git a/regamedll/dlls/vehicle.cpp b/regamedll/dlls/vehicle.cpp index 55b453ed7..ffd0bc550 100644 --- a/regamedll/dlls/vehicle.cpp +++ b/regamedll/dlls/vehicle.cpp @@ -109,7 +109,7 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther) pevOther->velocity.z += 300; pev->velocity = pev->velocity * 0.85; - ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pOther->pev->classname), pev->dmg); + ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pevOther->classname), pev->dmg); UTIL_MakeVectors(pev->angles); Vector forward, right, vOrigin; @@ -131,13 +131,42 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther) float maxz = pev->origin.z + (2 * Q_abs(int(pev->mins.z - pev->maxs.z))); #endif - if (pOther->pev->origin.x < minx - || pOther->pev->origin.x > maxx - || pOther->pev->origin.y < miny - || pOther->pev->origin.y > maxy - || pOther->pev->origin.z < minz - || pOther->pev->origin.z > maxz) + if (pevOther->origin.x < minx + || pevOther->origin.x > maxx + || pevOther->origin.y < miny + || pevOther->origin.y > maxy + || pevOther->origin.z < minz + || pevOther->origin.z > maxz) { +#ifdef REGAMEDLL_ADD + if (legacy_vehicle_block.value) + { + pOther->TakeDamage(pev, pev, 150, DMG_CRUSH); + return; + } + + CBasePlayer* playerDriver = static_cast(m_pDriver); + + if (pOther->Classify() == CLASS_PLAYER) + { + CBasePlayer* playerOther = static_cast(pOther); + if (!playerDriver || (!friendlyfire.value && playerDriver->m_iTeam == playerOther->m_iTeam)) + { + // Just kick player + return; + } + else + { + playerOther->TakeDamage(pev, playerDriver->pev, 150, DMG_CRUSH); + return; + } + } + else if (FClassnameIs(pevOther, "hostage_entity") && playerDriver) + { + pOther->TakeDamage(playerDriver->pev, playerDriver->pev, 150, DMG_CRUSH); + return; + } +#endif pOther->TakeDamage(pev, pev, 150, DMG_CRUSH); } }