All pastes #994056 Raw Edit

Anonymous

public text v1 · immutable
#994056 ·published 2008-04-23 02:18 UTC
rendered paste body
tagorientation_t tag;
vec3_t	aimSpot;

VOID GetTag( centity_t *cent, tagorientation_t *tag, INT hModel, LPCSTR tagname )
{
	int *getTag     = (INT*)    0x3001D540;
	_asm push [tag]
	_asm push [cent]
	_asm mov ecx, [hModel]
	_asm mov eax, [tagname]
	_asm call[getTag]

	_asm pop eax
	_asm pop eax;
}


int CheckFov( vec3_t origin )
{
    vec3_t vec, ang;
    VectorSubtract( origin, cg->refdef.vieworg, vec );
    VectorAngles( vec, ang );
    ANG_CLIP( ang[YAW] );
    ANG_CLIP( ang[PITCH] );
    ang[PITCH] = -ang[PITCH];
    ang[0] -= cg->refdefViewAngles[0];
    ang[1] -= cg->refdefViewAngles[1];
    ANG_CLIP( ang[YAW] );
    ANG_CLIP( ang[PITCH] );
    
	if( ( ang[0] * ang[0] + ang[1] * ang[1] )<=( cod_fov.value * cod_fov.value ) )
	{
	    return 1;
	}

    return 0;
}


VOID PingPredict( centity_t *ent, vec3_t origin, vec3_t predictedorigin ) 
{
	vec3_t vel;
	VectorCopy( ent->currentState.pos.trDelta, vel );
	VectorMA( origin, ( cg->snap->ping/1000.0f )* cg->snap->ping, vel, predictedorigin );
}


INT NearestCHTarget( )
{
	FLOAT	CHDist			= 0;
	FLOAT   lastCHDist		= 9999;
	FLOAT	AngleX, AngleY;
	INT		iBestTargetCH	= -1;

	for ( INT i = 0; i < 64; i++ ) 
	{
		if( cg_entities[i].currentValid && cg_entities[i].currentState.clientNum != cg->clientNum )
		{
			if( clientInfo[ cg_entities[i].currentState.clientNum ].team != clientInfo[ cg->clientNum ].team || clientInfo[ cg_entities[i].currentState.clientNum ].team == TEAM_DEATHMATCH )
			{
				INT hModel = trap_GetEntityModelHandle( i );

				if ( !hModel )
					return NULL;

				GetTag( &cg_entities[i], &tag, hModel, "Bip01 Head" );
				VectorCopy( tag.origin, aimSpot );

				aimSpot[0] += cod_aimvecX.value;
				aimSpot[1] += cod_aimvecY.value;
				aimSpot[2] += cod_aimvecZ.value;

				if( IsVisible( aimSpot ) )
				{
					if( CheckFov( aimSpot ) )
					{
						VectorMA( aimSpot, cg->snap->ping, cg_entities[i].currentState.pos.trDelta, aimSpot );
						PingPredict( &cg_entities[i], aimSpot, aimSpot );

						GetAngleToOrigin( aimSpot, AngleX, AngleY );

						CHDist   = sqrt( AngleX*AngleX + AngleY*AngleY );

						if ( (CHDist < lastCHDist)  )
						{
							lastCHDist	= CHDist;
							iBestTargetCH	= i;
						}
					}
				}
			}
		}
	}

	return iBestTargetCH;
}


VOID DoAim( INT i )
{
	FLOAT	AngleX, AngleY;

	if( i < 0 )
	{
		return;
	}

	INT hModel = trap_GetEntityModelHandle( i );
		
	if ( !hModel )
		return;

	GetTag( &cg_entities[i], &tag, hModel, "Bip01 Head" );
	VectorCopy( tag.origin, aimSpot );

	GetAngleToOrigin( aimSpot, AngleX, AngleY );
	
	*ViewAngleX += AngleX;
	*ViewAngleY += AngleY;
}