What events do you think these functions can be called upon?
Code:
//-----------------------------------------------------------------------------
// Purpose: Returns whether the player should autoaim or not
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CBasePlayer::ShouldAutoaim( void )
{
// cannot be in multiplayer
if ( gpGlobals->maxClients > 1 )
return false;
// autoaiming is only for easy and medium skill
return ( IsX360() || !g_pGameRules->IsSkillLevel(SKILL_HARD) );
}
void CBasePlayer::GetAutoaimVector( autoaim_params_t ¶ms )
{
// Assume autoaim will not be assisting.
params.m_bAutoAimAssisting = false;
if ( ( ShouldAutoaim() == false ) || ( params.m_fScale == AUTOAIM_SCALE_DIRECT_ONLY ) )
{
Vector forward;
AngleVectors( EyeAngles() + m_Local.m_vecPunchAngle, &forward );
params.m_vecAutoAimDir = forward;
params.m_hAutoAimEntity.Set(NULL);
params.m_vecAutoAimPoint = vec3_invalid;
params.m_bAutoAimAssisting = false;
return; /************* CRASH *************/
}
Vector vecSrc = Weapon_ShootPosition( );
m_vecAutoAim.Init( 0.0f, 0.0f, 0.0f );
QAngle angles = AutoaimDeflection( vecSrc, params );
// update ontarget if changed
if ( !g_pGameRules->AllowAutoTargetCrosshair() )
m_fOnTarget = false;
if (angles.x > 180)
angles.x -= 360;
if (angles.x < -180)
angles.x += 360;
if (angles.y > 180)
angles.y -= 360;
if (angles.y < -180)
angles.y += 360;
if (angles.x > 25)
angles.x = 25;
if (angles.x < -25)
angles.x = -25;
if (angles.y > 12)
angles.y = 12;
if (angles.y < -12)
angles.y = -12;
Vector forward;
if( IsInAVehicle() && g_pGameRules->GetAutoAimMode() == AUTOAIM_ON_CONSOLE )
{
m_vecAutoAim = angles;
AngleVectors( EyeAngles() + m_vecAutoAim, &forward );
}
else
{
// always use non-sticky autoaim
m_vecAutoAim = angles * 0.9f;
AngleVectors( EyeAngles() + m_Local.m_vecPunchAngle + m_vecAutoAim, &forward );
}
params.m_vecAutoAimDir = forward;
}
QAngle CBasePlayer::AutoaimDeflection( Vector &vecSrc, autoaim_params_t ¶ms )
{
float bestscore;
float score;
QAngle eyeAngles;
Vector bestdir;
CBaseEntity *bestent;
trace_t tr;
Vector v_forward, v_right, v_up;
if ( ShouldAutoaim() == false )
{
m_fOnTarget = false;
return vec3_angle;
}
eyeAngles = EyeAngles();
AngleVectors( eyeAngles + m_Local.m_vecPunchAngle + m_vecAutoAim, &v_forward, &v_right, &v_up );
// try all possible entities
bestdir = v_forward;
bestscore = 0.0f;
bestent = NULL;
//Reset this data
m_fOnTarget = false;
params.m_bOnTargetNatural = false;
CBaseEntity *pIgnore = NULL;
if( IsInAVehicle() )
{
pIgnore = GetVehicleEntity();
}
CTraceFilterSkipTwoEntities traceFilter( this, pIgnore, COLLISION_GROUP_NONE );
UTIL_TraceLine( vecSrc, vecSrc + bestdir * MAX_COORD_FLOAT, MASK_SHOT, &traceFilter, &tr );
CBaseEntity *pEntHit = tr.m_pEnt;
if ( pEntHit && pEntHit->m_takedamage != DAMAGE_NO && pEntHit->GetHealth() > 0 )
{
// don't look through water
if (!((GetWaterLevel() != 3 && pEntHit->GetWaterLevel() == 3) || (GetWaterLevel() == 3 && pEntHit->GetWaterLevel() == 0)))
{
if( pEntHit->ShouldAttractAutoAim(this) )
{
bool bAimAtThis = true;
if( pEntHit->IsNPC() && g_pGameRules->GetAutoAimMode() > AUTOAIM_NONE )
{
int iRelationType = GetDefaultRelationshipDisposition( pEntHit->Classify() );
if( iRelationType != D_HT )
{
bAimAtThis = false;
}
}
if( bAimAtThis )
{
if ( pEntHit->GetFlags() & FL_AIMTARGET )
{
m_fOnTarget = true;
}
// Player is already on target naturally, don't autoaim.
// Fill out the autoaim_params_t struct, though.
params.m_hAutoAimEntity.Set(pEntHit);
params.m_vecAutoAimDir = bestdir;
params.m_vecAutoAimPoint = tr.endpos;
params.m_bAutoAimAssisting = false;
params.m_bOnTargetNatural = true;
return vec3_angle;
}
}
//Fall through and look for an autoaim ent.
}
}
int count = AimTarget_ListCount();
if ( count )
{
CBaseEntity **pList = (CBaseEntity **)stackalloc( sizeof(CBaseEntity *) * count );
AimTarget_ListCopy( pList, count );
for ( int i = 0; i < count; i++ )
{
Vector center;
Vector dir;
CBaseEntity *pEntity = pList[i];
// Don't autoaim at anything that doesn't want to be.
if( !pEntity->ShouldAttractAutoAim(this) )
continue;
// Don't shoot yourself
if ( pEntity == this )
continue;
if ( (pEntity->IsNPC() && !pEntity->IsAlive()) || !pEntity->edict() )
continue;
if ( !g_pGameRules->ShouldAutoAim( this, pEntity->edict() ) )
continue;
// don't look through water
if ((GetWaterLevel() != 3 && pEntity->GetWaterLevel() == 3) || (GetWaterLevel() == 3 && pEntity->GetWaterLevel() == 0))
continue;
if( pEntity->MyNPCPointer() )
{
// If this entity is an NPC, only aim if it is an enemy.
if ( IRelationType( pEntity ) != D_HT )
{
if ( !pEntity->IsPlayer() && !g_pGameRules->IsDeathmatch())
// Msg( "friend\n");
continue;
}
}
// Don't autoaim at the noisy bodytarget, this makes the autoaim crosshair wobble.
//center = pEntity->BodyTarget( vecSrc, false );
center = pEntity->WorldSpaceCenter();
dir = (center - vecSrc);
float dist = dir.Length2D();
VectorNormalize( dir );
// Skip if out of range.
if( dist > params.m_fMaxDist )
continue;
float dot = DotProduct (dir, v_forward );
// make sure it's in front of the player
if( dot < 0 )
continue;
if( !(pEntity->GetFlags() & FL_FLY) )
{
// Refuse to take wild shots at targets far from reticle.
if( GetActiveWeapon() != NULL && dot < GetActiveWeapon()->GetMaxAutoAimDeflection() )
{
// Be lenient if the player is looking down, though. 30 degrees through 90 degrees of pitch.
// (90 degrees is looking down at player's own 'feet'. Looking straight ahead is 0 degrees pitch.
// This was done for XBox to make it easier to fight headcrabs around the player's feet.
if( eyeAngles.x < 30.0f || eyeAngles.x > 90.0f || g_pGameRules->GetAutoAimMode() != AUTOAIM_ON_CONSOLE )
{
continue;
}
}
}
score = GetAutoaimScore(vecSrc, v_forward, pEntity->GetAutoAimCenter(), pEntity, params.m_fScale, GetActiveWeapon() );
if( score <= bestscore )
{
continue;
}
UTIL_TraceLine( vecSrc, center, MASK_SHOT, &traceFilter, &tr );
if (tr.fraction != 1.0 && tr.m_pEnt != pEntity )
{
// Msg( "hit %s, can't see %s\n", STRING( tr.u.ent->classname ), STRING( pEdict->classname ) );
continue;
}
// This is the best candidate so far.
bestscore = score;
bestent = pEntity;
bestdir = dir;
}
if ( bestent )
{
QAngle bestang;
VectorAngles( bestdir, bestang );
if( IsInAVehicle() )
{
bestang -= EyeAngles();
}
else
{
bestang -= EyeAngles() - m_Local.m_vecPunchAngle;
}
m_fOnTarget = true;
// Autoaim detected a target for us. Aim automatically at its bodytarget.
params.m_hAutoAimEntity.Set(bestent);
params.m_vecAutoAimDir = bestdir;
params.m_vecAutoAimPoint = bestent->BodyTarget( vecSrc, false );
params.m_bAutoAimAssisting = true;
return bestang;
}
}
return vec3_angle;
}
(c)
https://github.com/ValveSoftware/sou...ver/player.cpp
I am still getting server crashes due to these two functions...
Code:
server_srv.so CBasePlayer::AutoaimDeflection(Vector &,autoaim_params_t &) -> 0x774f26
server_srv.so CBasePlayer::GetAutoaimVector(autoaim_params_t &) -> 0x775555
This is the code where the crash occurs:
Code:
int __cdecl CBasePlayer::GetAutoaimVector(int a1, int a2)
{
[...]
if ( !(*(unsigned __int8 (__cdecl **)(int))(*(_DWORD *)a1 + 1808))(a1) || *(float *)(a2 + 28) == 0.0 )
{
v3 = (float *)(*(int (__cdecl **)(int))(*(_DWORD *)a1 + 568))(a1);
v12 = *(float *)(a1 + 6864) + *v3;
v13 = *(float *)(a1 + 6868) + v3[1];
v14 = *(float *)(a1 + 6872) + v3[2];
AngleVectors(&v12, &v9);
LABEL_3:
*(_DWORD *)a2 = v9;
*(_DWORD *)(a2 + 4) = v10;
result = v11;
*(_DWORD *)(a2 + 8) = v11;
return result; /*********************** FAULT POINTER 0x775555 ***********************/
}
[...]
v5 = *(_DWORD *)(a2 + 24);
if ( v5 == -1
|| (v6 = (char *)g_pEntityList + 16 * (*(_DWORD *)(a2 + 24) & 0xFFF), *((_DWORD *)v6 + 2) != v5 >> 12)
|| (result = *((_DWORD *)v6 + 1)) == 0 )
{
v7 = (float *)(*(int (__fastcall **)(void *))(*(_DWORD *)a1 + 568))(g_pEntityList);
v17 = *(float *)(a1 + 6864) + *v7;
v18 = *(float *)(a1 + 6868) + v7[1];
v19 = *(float *)(a1 + 6872) + v7[2];
AngleVectors(&v17, &v9);
goto LABEL_3;
}
return result;
}
They are associated with a weapon shot (FireBullets looking the stack). but I have nothing on the server related to shots. I ask for help.
__________________