Skip to content

Commit

Permalink
Merge pull request #12 from dystopm/mp-dying-time-cvar
Browse files Browse the repository at this point in the history
Fix death animation when mp_dying_time < 3.0 depending on animation
  • Loading branch information
wopox1337 authored Jul 12, 2023
2 parents 68d29bf + 449a9c5 commit 9dc7879
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions regamedll/common/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
// Starting from BIT(16) to reserve space for more flags for Engine
#define FTRACE_BULLET BIT(16)
#define FTRACE_FLASH BIT(17)
#define FTRACE_KNIFE BIT(18)

// walkmove modes
#define WALKMOVE_NORMAL 0 // normal walkmove
Expand Down
3 changes: 1 addition & 2 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ extern cvar_t sv_enablebunnyhopping;
extern cvar_t plant_c4_anywhere;
extern cvar_t give_c4_frags;
extern cvar_t hostages_rescued_ratio;

extern cvar_t legacy_vehicle_block;
extern cvar_t dying_time;

extern cvar_t legacy_vehicle_block;
#endif

extern cvar_t scoreboard_showmoney;
Expand Down
44 changes: 40 additions & 4 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8818,9 +8818,7 @@ void CBasePlayer::SpawnClientSideCorpse()
if (pev->effects & EF_NODRAW)
return;

// do not make a corpse if the player goes to respawn.
if (pev->deadflag == DEAD_RESPAWNABLE)
return;
// deadflag == DEAD_RESPAWNABLE already checked before
#endif

#ifdef REGAMEDLL_ADD
Expand All @@ -8830,6 +8828,41 @@ void CBasePlayer::SpawnClientSideCorpse()

char *infobuffer = GET_INFO_BUFFER(edict());
char *pModel = GET_KEY_VALUE(infobuffer, "model");
float timeDiff = pev->animtime - gpGlobals->time;

#ifdef REGAMEDLL_ADD
if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float animDuration = -1.0;

studiohdr_t *pstudiohdr = (studiohdr_t *)GET_MODEL_PTR(ENT(pev));
if (pstudiohdr && pev->sequence < pstudiohdr->numseq) // model ptr and sequence validation
{
// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);
animDuration = pseqdesc->numframes / pseqdesc->fps;
}

if (animDuration <= 0.0)
{
// in case of failure
animDuration = DEATH_ANIMATION_TIME;
}

// client receives a negative value
animDuration *= -1.0;

if (animDuration < timeDiff) // reasonable way to fix client side unfinished sequence bug
{
// by some reason, if client receives a value less
// than "(negative current sequence time) * 100"
// animation will play visually awkward
// at this function call time, player death animation
// has already finished so we can safely fake it
timeDiff = animDuration;
}
}
#endif

MESSAGE_BEGIN(MSG_ALL, gmsgSendCorpse);
WRITE_STRING(pModel);
Expand All @@ -8839,14 +8872,17 @@ void CBasePlayer::SpawnClientSideCorpse()
WRITE_COORD(pev->angles.x);
WRITE_COORD(pev->angles.y);
WRITE_COORD(pev->angles.z);
WRITE_LONG((pev->animtime - gpGlobals->time) * 100);
WRITE_LONG(timeDiff * 100);
WRITE_BYTE(pev->sequence);
WRITE_BYTE(pev->body);
WRITE_BYTE(m_iTeam);
WRITE_BYTE(entindex());
MESSAGE_END();

#ifndef REGAMEDLL_FIXES
// already defined in StartDeathCam
m_canSwitchObserverModes = true;
#endif

if (TheTutor)
{
Expand Down
26 changes: 26 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_knife.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ void FindHullIntersection(const Vector &vecSrc, TraceResult &tr, float *mins, fl
distance = 1e6f;

vecHullEnd = vecSrc + ((vecHullEnd - vecSrc) * 2);
#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceLine(vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &tmpTrace);

if (tmpTrace.flFraction < 1.0f)
Expand All @@ -147,6 +150,9 @@ void FindHullIntersection(const Vector &vecSrc, TraceResult &tr, float *mins, fl
vecEnd.y = vecHullEnd.y + minmaxs[j][1];
vecEnd.z = vecHullEnd.z + minmaxs[k][2];

#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, pEntity, &tmpTrace);

if (tmpTrace.flFraction < 1.0f)
Expand Down Expand Up @@ -274,11 +280,21 @@ BOOL CKnife::Swing(BOOL fFirst)
vecSrc = m_pPlayer->GetGunPosition();
vecEnd = vecSrc + gpGlobals->v_forward * KnifeSwingDistance();

#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr);

if (tr.flFraction >= 1.0f)
{
#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceHull(vecSrc, vecEnd, dont_ignore_monsters, head_hull, m_pPlayer->edict(), &tr);
#ifdef REGAMEDLL_ADD
// We manually reset it because Engine doesn't unlike TraceLine
gpGlobals->trace_flags = 0;
#endif

if (tr.flFraction < 1.0f)
{
Expand Down Expand Up @@ -457,11 +473,21 @@ BOOL CKnife::Stab(BOOL fFirst)
vecSrc = m_pPlayer->GetGunPosition();
vecEnd = vecSrc + gpGlobals->v_forward * KnifeStabDistance();

#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr);

if (tr.flFraction >= 1.0f)
{
#ifdef REGAMEDLL_ADD
gpGlobals->trace_flags = FTRACE_KNIFE;
#endif
UTIL_TraceHull(vecSrc, vecEnd, dont_ignore_monsters, head_hull, m_pPlayer->edict(), &tr);
#ifdef REGAMEDLL_ADD
// We manually reset it because Engine doesn't unlike TraceLine
gpGlobals->trace_flags = 0;
#endif

if (tr.flFraction < 1.0f)
{
Expand Down

0 comments on commit 9dc7879

Please sign in to comment.