Skip to content

Commit

Permalink
engine: always use original player hulls for pmove trace, because mod…
Browse files Browse the repository at this point in the history
…s can write invalid data in pmove->player_{mins,maxs}
  • Loading branch information
a1batross committed Jul 21, 2024
1 parent d4a2011 commit 7a469fb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
27 changes: 21 additions & 6 deletions engine/client/cl_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2435,8 +2435,8 @@ static void GAME_EXPORT pfnLocalPlayerBounds( int hull, float *mins, float *maxs
{
if( hull >= 0 && hull < 4 )
{
if( mins ) VectorCopy( clgame.pmove->player_mins[hull], mins );
if( maxs ) VectorCopy( clgame.pmove->player_maxs[hull], maxs );
if( mins ) VectorCopy( host.player_mins[hull], mins );
if( maxs ) VectorCopy( host.player_maxs[hull], maxs );
}
}

Expand Down Expand Up @@ -2504,9 +2504,17 @@ CL_PushTraceBounds
*/
static void GAME_EXPORT CL_PushTraceBounds( int hullnum, const float *mins, const float *maxs )
{
if( !host.trace_bounds_pushed )
{
memcpy( host.player_mins_backup, host.player_mins, sizeof( host.player_mins_backup ));
memcpy( host.player_maxs_backup, host.player_maxs, sizeof( host.player_maxs_backup ));

host.trace_bounds_pushed = true;
}

hullnum = bound( 0, hullnum, 3 );
VectorCopy( mins, clgame.pmove->player_mins[hullnum] );
VectorCopy( maxs, clgame.pmove->player_maxs[hullnum] );
VectorCopy( mins, host.player_mins[hullnum] );
VectorCopy( maxs, host.player_maxs[hullnum] );
}

/*
Expand All @@ -2517,8 +2525,15 @@ CL_PopTraceBounds
*/
static void GAME_EXPORT CL_PopTraceBounds( void )
{
memcpy( clgame.pmove->player_mins, host.player_mins, sizeof( host.player_mins ));
memcpy( clgame.pmove->player_maxs, host.player_maxs, sizeof( host.player_maxs ));
if( !host.trace_bounds_pushed )
{
Con_Reportf( S_ERROR "%s called without push!\n", __func__ );
return;
}

host.trace_bounds_pushed = false;
memcpy( host.player_mins, host.player_mins_backup, sizeof( host.player_mins ));
memcpy( host.player_maxs, host.player_maxs_backup, sizeof( host.player_maxs ));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions engine/client/cl_pmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ void GAME_EXPORT CL_SetSolidPlayers( int playernum )
// some fields needs to be override from cls.predicted_players
VectorCopy( player->origin, pe->origin );
VectorCopy( player->angles, pe->angles );
VectorCopy( clgame.pmove->player_mins[player->usehull], pe->mins );
VectorCopy( clgame.pmove->player_maxs[player->usehull], pe->maxs );
VectorCopy( host.player_mins[player->usehull], pe->mins );
VectorCopy( host.player_maxs[player->usehull], pe->maxs );
pe->movetype = player->movetype;
pe->solid = player->solid;
}
Expand Down
5 changes: 5 additions & 0 deletions engine/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ typedef struct host_parm_s
vec3_t player_mins[MAX_MAP_HULLS]; // 4 hulls allowed
vec3_t player_maxs[MAX_MAP_HULLS]; // 4 hulls allowed

// for CL_{Push,Pop}TraceBounds
vec3_t player_mins_backup[MAX_MAP_HULLS];
vec3_t player_maxs_backup[MAX_MAP_HULLS];
qboolean trace_bounds_pushed;

qboolean allow_console; // allow console in dev-mode or multiplayer game
qboolean allow_console_init; // initial value to allow the console
qboolean key_overstrike; // key overstrike mode
Expand Down
28 changes: 14 additions & 14 deletions engine/common/pm_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ hull_t *PM_HullForBsp( physent_t *pe, playermove_t *pmove, float *offset )
Assert( hull != NULL );

// calculate an offset value to center the origin
VectorSubtract( hull->clip_mins, pmove->player_mins[pmove->usehull], offset );
VectorSubtract( hull->clip_mins, host.player_mins[pmove->usehull], offset );
VectorAdd( offset, pe->origin, offset );

return hull;
Expand All @@ -203,7 +203,7 @@ static hull_t *PM_HullForStudio( physent_t *pe, playermove_t *pmove, int *numhit
{
vec3_t size;

VectorSubtract( pmove->player_maxs[pmove->usehull], pmove->player_mins[pmove->usehull], size );
VectorSubtract( host.player_maxs[pmove->usehull], host.player_mins[pmove->usehull], size );
VectorScale( size, 0.5f, size );

return Mod_HullForStudio( pe->studiomodel, pe->frame, pe->sequence, pe->angles, pe->origin, size, pe->controller, pe->blending, numhitboxes, NULL );
Expand Down Expand Up @@ -379,8 +379,8 @@ pmtrace_t PM_PlayerTraceExt( playermove_t *pmove, vec3_t start, vec3_t end, int

if( pe->solid == SOLID_CUSTOM )
{
VectorCopy( pmove->player_mins[pmove->usehull], mins );
VectorCopy( pmove->player_maxs[pmove->usehull], maxs );
VectorCopy( host.player_mins[pmove->usehull], mins );
VectorCopy( host.player_maxs[pmove->usehull], maxs );
VectorClear( offset );
}
else if( pe->model )
Expand All @@ -401,17 +401,17 @@ pmtrace_t PM_PlayerTraceExt( playermove_t *pmove, vec3_t start, vec3_t end, int
}
else
{
VectorSubtract( pe->mins, pmove->player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, pmove->player_mins[pmove->usehull], maxs );
VectorSubtract( pe->mins, host.player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, host.player_mins[pmove->usehull], maxs );

hull = PM_HullForBox( mins, maxs );
VectorCopy( pe->origin, offset );
}
}
else
{
VectorSubtract( pe->mins, pmove->player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, pmove->player_mins[pmove->usehull], maxs );
VectorSubtract( pe->mins, host.player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, host.player_mins[pmove->usehull], maxs );

hull = PM_HullForBox( mins, maxs );
VectorCopy( pe->origin, offset );
Expand Down Expand Up @@ -442,7 +442,7 @@ pmtrace_t PM_PlayerTraceExt( playermove_t *pmove, vec3_t start, vec3_t end, int

if( transform_bbox )
{
World_TransformAABB( matrix, pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], mins, maxs );
World_TransformAABB( matrix, host.player_mins[pmove->usehull], host.player_maxs[pmove->usehull], mins, maxs );
VectorSubtract( hull->clip_mins, mins, offset ); // calc new local offset

for( j = 0; j < 3; j++ )
Expand Down Expand Up @@ -569,8 +569,8 @@ int PM_TestPlayerPosition( playermove_t *pmove, vec3_t pos, pmtrace_t *ptrace, p

if( pe->solid == SOLID_CUSTOM )
{
VectorCopy( pmove->player_mins[pmove->usehull], mins );
VectorCopy( pmove->player_maxs[pmove->usehull], maxs );
VectorCopy( host.player_mins[pmove->usehull], mins );
VectorCopy( host.player_maxs[pmove->usehull], maxs );
VectorClear( offset );
}
else if( pe->model )
Expand All @@ -584,8 +584,8 @@ int PM_TestPlayerPosition( playermove_t *pmove, vec3_t pos, pmtrace_t *ptrace, p
}
else
{
VectorSubtract( pe->mins, pmove->player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, pmove->player_mins[pmove->usehull], maxs );
VectorSubtract( pe->mins, host.player_maxs[pmove->usehull], mins );
VectorSubtract( pe->maxs, host.player_mins[pmove->usehull], maxs );

hull = PM_HullForBox( mins, maxs );
VectorCopy( pe->origin, offset );
Expand All @@ -611,7 +611,7 @@ int PM_TestPlayerPosition( playermove_t *pmove, vec3_t pos, pmtrace_t *ptrace, p

if( transform_bbox )
{
World_TransformAABB( matrix, pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], mins, maxs );
World_TransformAABB( matrix, host.player_mins[pmove->usehull], host.player_maxs[pmove->usehull], mins, maxs );
VectorSubtract( hull->clip_mins, mins, offset ); // calc new local offset

for( j = 0; j < 3; j++ )
Expand Down
4 changes: 2 additions & 2 deletions engine/server/sv_phys.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ static qboolean SV_TestEntityPosition( edict_t *ent, edict_t *blocker )
{
// to avoid falling through tracktrain update client mins\maxs here
if( FBitSet( ent->v.flags, FL_DUCKING ))
SV_SetMinMaxSize( ent, svgame.pmove->player_mins[1], svgame.pmove->player_maxs[1], true );
else SV_SetMinMaxSize( ent, svgame.pmove->player_mins[0], svgame.pmove->player_maxs[0], true );
SV_SetMinMaxSize( ent, host.player_mins[1], host.player_maxs[1], true );
else SV_SetMinMaxSize( ent, host.player_mins[0], host.player_maxs[0], true );
}

trace = SV_Move( ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, MOVE_NORMAL, ent, monsterClip );
Expand Down
2 changes: 1 addition & 1 deletion engine/server/sv_pmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ static void SV_FinishPMove( playermove_t *pmove, sv_client_t *cl )
clent->v.angles[YAW] = clent->v.v_angle[YAW];
}

SV_SetMinMaxSize( clent, pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], false );
SV_SetMinMaxSize( clent, host.player_mins[pmove->usehull], host.player_maxs[pmove->usehull], false );

// all next calls ignore footstep sounds
pmove->runfuncs = false;
Expand Down

0 comments on commit 7a469fb

Please sign in to comment.