Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateBaseline handles vector inputs incorrectly #3078

Open
SamVanheer opened this issue Mar 16, 2021 · 0 comments
Open

CreateBaseline handles vector inputs incorrectly #3078

SamVanheer opened this issue Mar 16, 2021 · 0 comments

Comments

@SamVanheer
Copy link

The function CreateBaseline takes 2 vectors as input:

halflife/dlls/client.cpp

Lines 1284 to 1329 in c7240b9

void CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs )
{
baseline->origin = entity->v.origin;
baseline->angles = entity->v.angles;
baseline->frame = entity->v.frame;
baseline->skin = (short)entity->v.skin;
// render information
baseline->rendermode = (byte)entity->v.rendermode;
baseline->renderamt = (byte)entity->v.renderamt;
baseline->rendercolor.r = (byte)entity->v.rendercolor.x;
baseline->rendercolor.g = (byte)entity->v.rendercolor.y;
baseline->rendercolor.b = (byte)entity->v.rendercolor.z;
baseline->renderfx = (byte)entity->v.renderfx;
if ( player )
{
baseline->mins = player_mins;
baseline->maxs = player_maxs;
baseline->colormap = eindex;
baseline->modelindex = playermodelindex;
baseline->friction = 1.0;
baseline->movetype = MOVETYPE_WALK;
baseline->scale = entity->v.scale;
baseline->solid = SOLID_SLIDEBOX;
baseline->framerate = 1.0;
baseline->gravity = 1.0;
}
else
{
baseline->mins = entity->v.mins;
baseline->maxs = entity->v.maxs;
baseline->colormap = 0;
baseline->modelindex = entity->v.modelindex;//SV_ModelIndex(pr_strings + entity->v.model);
baseline->movetype = entity->v.movetype;
baseline->scale = entity->v.scale;
baseline->solid = entity->v.solid;
baseline->framerate = entity->v.framerate;
baseline->gravity = entity->v.gravity;
}
}

These are actually pointers to arrays of 4 vectors. The type used here - vec3_t - decays into a pointer and so when this code executes as intended it always assigns the first vector in each array to the baseline:

halflife/dlls/client.cpp

Lines 1301 to 1302 in c7240b9

baseline->mins = player_mins;
baseline->maxs = player_maxs;

But since vec3_t is aliased to Vector here:

halflife/dlls/extdll.h

Lines 79 to 80 in c7240b9

// Defining it as a (bogus) struct helps enforce type-checking
#define vec3_t Vector

The code instead treats the addresses passed as actual values. This results in the vectors assigned being invalid.

To fix this the function declaration and definition, and the interface need to be modified:

extern void CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs );

void CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs )

void (*pfnCreateBaseline) ( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs );

The vector parameters needs to be passed like this:

Vector* player_mins, Vector* player_maxs

And the vectors need to be de-referenced to assign them:

baseline->mins			= *player_mins;
baseline->maxs			= *player_maxs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants