Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool CRage::CanPenetrate( Vector Destination, float * damage_given )
- {
- return CanHit( Destination, damage_given );
- }
- //myfixes
- #define HITGROUP_GENERIC 0
- #define HITGROUP_HEAD 1
- #define HITGROUP_CHEST 2
- #define HITGROUP_STOMACH 3
- #define HITGROUP_LEFTARM 4
- #define HITGROUP_RIGHTARM 5
- #define HITGROUP_LEFTLEG 6
- #define HITGROUP_RIGHTLEG 7
- #define HITGROUP_GEAR 10
- //letz twist again
- struct weaponParameters
- {
- float Penetration, Damage, Range, RangeModifier;
- };
- std::vector<weaponParameters> weaponParams;
- void getWeaponData( int weaponID, CCSWeaponInfo_t& data )
- {
- switch ( weaponID )
- {
- case WEAPON_AK47:
- data.WeaponArmorRatio = 1.55;
- data.flPenetrationPower = 2;
- data.iDamage = 36;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_AUG:
- data.WeaponArmorRatio = 1.8;
- data.flPenetrationPower = 2;
- data.iDamage = 28;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_AWP:
- data.WeaponArmorRatio = 1.95;
- data.flPenetrationPower = 2.5;
- data.iDamage = 115;
- data.flRange = 8192;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_BIZON:
- data.WeaponArmorRatio = 1.15;
- data.flPenetrationPower = 1;
- data.iDamage = 27;
- data.flRange = 3600;
- data.flRangeModifier = 0.80;
- break;
- case WEAPON_C4:
- data.WeaponArmorRatio = 1.0;
- data.flPenetrationPower = 1;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_DEAGLE:
- data.WeaponArmorRatio = 1.864;
- data.flPenetrationPower = 2;
- data.iDamage = 63;
- data.flRange = 4096;
- data.flRangeModifier = 0.81;
- break;
- case WEAPON_DECOY:
- data.WeaponArmorRatio = 1;
- data.flPenetrationPower = 1;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_DUAL:
- data.WeaponArmorRatio = 1.15;
- data.flPenetrationPower = 1;
- data.iDamage = 38;
- data.flRange = 4096;
- data.flRangeModifier = 0.79;
- break;
- case WEAPON_FAMAS:
- data.WeaponArmorRatio = 1.4;
- data.flPenetrationPower = 2;
- data.iDamage = 30;
- data.flRange = 8192;
- data.flRangeModifier = 0.96;
- break;
- case WEAPON_FIVE7:
- data.WeaponArmorRatio = 1.823;
- data.flPenetrationPower = 1;
- data.iDamage = 32;
- data.flRange = 4096;
- data.flRangeModifier = 0.81;
- break;
- case WEAPON_FLASHBANG:
- data.WeaponArmorRatio = 1;
- data.flPenetrationPower = 1;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_G3SG1:
- data.WeaponArmorRatio = 1.65;
- data.flPenetrationPower = 2.5;
- data.iDamage = 80;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_GALIL:
- data.WeaponArmorRatio = 1.55;
- data.flPenetrationPower = 2;
- data.iDamage = 30;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_GLOCK:
- data.WeaponArmorRatio = 0.94;
- data.flPenetrationPower = 1;
- data.iDamage = 28;
- data.flRange = 4096;
- data.flRangeModifier = 0.9;
- break;
- case WEAPON_HEGRENADE:
- data.WeaponArmorRatio = 1.2;
- data.iDamage = 99;
- data.flPenetrationPower = 1;
- data.flRange = 350;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_HKP2000:
- data.WeaponArmorRatio = 1.01;
- data.flPenetrationPower = 1;
- data.iDamage = 35;
- data.flRange = 4096;
- data.flRangeModifier = 0.91;
- break;
- case WEAPON_CT_MOLOTOV:
- data.WeaponArmorRatio = 1.475;
- data.flPenetrationPower = 1;
- data.iDamage = 40;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_KNIFE_T:
- data.WeaponArmorRatio = 1.7;
- data.flPenetrationPower = 1;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_KNIFEGG:
- data.WeaponArmorRatio = 1.7;
- data.flPenetrationPower = 1;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_M249:
- data.WeaponArmorRatio = 1.6;
- data.flPenetrationPower = 2;
- data.iDamage = 32;
- data.flRange = 8192;
- data.flRangeModifier = 0.97;
- break;
- case WEAPON_M4A1:
- data.WeaponArmorRatio = 1.4;
- data.flPenetrationPower = 2;
- data.iDamage = 33;
- data.flRange = 8192;
- data.flRangeModifier = 0.97;
- break;
- case WEAPON_MAC10:
- data.WeaponArmorRatio = 1.15;
- data.flPenetrationPower = 1;
- data.iDamage = 29;
- data.flRange = 3600;
- data.flRangeModifier = 0.80;
- break;
- case WEAPON_MAG7:
- data.WeaponArmorRatio = 1.5;
- data.flPenetrationPower = 1;
- data.iDamage = 30;
- data.flRange = 1400;
- data.flRangeModifier = 0.45;
- break;
- case WEAPON_T_MOLOTOV:
- data.WeaponArmorRatio = 1.8;
- data.flPenetrationPower = 1;
- data.iDamage = 40;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_MP7:
- data.WeaponArmorRatio = 1.25;
- data.flPenetrationPower = 1;
- data.iDamage = 29;
- data.flRange = 3600;
- data.flRangeModifier = 0.85;
- break;
- case WEAPON_MP9:
- data.WeaponArmorRatio = 1.20;
- data.flPenetrationPower = 1;
- data.iDamage = 26;
- data.flRange = 3600;
- data.flRangeModifier = 0.87;
- break;
- case WEAPON_NEGEV:
- data.WeaponArmorRatio = 1.5;
- data.flPenetrationPower = 2;
- data.iDamage = 35;
- data.flRange = 8192;
- data.flRangeModifier = 0.97;
- break;
- case WEAPON_NOVA:
- data.WeaponArmorRatio = 1.0;
- data.flPenetrationPower = 0;
- data.iDamage = 26;
- data.flRange = 3000;
- data.flRangeModifier = 0.70;
- break;
- case WEAPON_P250:
- data.WeaponArmorRatio = 1.553;
- data.flPenetrationPower = 1;
- data.iDamage = 35;
- data.flRange = 4096;
- data.flRangeModifier = 0.85;
- break;
- case WEAPON_CZ75:
- data.WeaponArmorRatio = 1.553;
- data.flPenetrationPower = 1;
- data.iDamage = 35;
- data.flRange = 4096;
- data.flRangeModifier = 0.85;
- break;
- case WEAPON_P90:
- data.WeaponArmorRatio = 1.38;
- data.flPenetrationPower = 1;
- data.iDamage = 26;
- data.flRange = 3700;
- data.flRangeModifier = 0.86;
- break;
- case WEAPON_SAWEDOFF:
- data.WeaponArmorRatio = 1.5;
- data.flPenetrationPower = 1;
- data.iDamage = 32;
- data.flRange = 650;
- data.flRangeModifier = 0.45;
- break;
- case WEAPON_SCAR20:
- data.WeaponArmorRatio = 1.65;
- data.flPenetrationPower = 2.5;
- data.iDamage = 80;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_SG553:
- data.WeaponArmorRatio = 2.0;
- data.flPenetrationPower = 2;
- data.iDamage = 30;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_SMOKE:
- data.WeaponArmorRatio = 1.0;
- data.flPenetrationPower = 0;
- data.iDamage = 50;
- data.flRange = 4096;
- data.flRangeModifier = 0.99;
- break;
- case WEAPON_SSG08:
- data.WeaponArmorRatio = 1.7;
- data.flPenetrationPower = 2.5;
- data.iDamage = 88;
- data.flRange = 8192;
- data.flRangeModifier = 0.98;
- break;
- case WEAPON_TASER:
- data.WeaponArmorRatio = 2;
- data.flPenetrationPower = 0;
- data.iDamage = 500;
- data.flRange = 190;
- data.flRangeModifier = 0.0049;
- break;
- case WEAPON_TEC9:
- data.WeaponArmorRatio = 1.812;
- data.flPenetrationPower = 1;
- data.iDamage = 33;
- data.flRange = 4096;
- data.flRangeModifier = 0.79;
- break;
- case WEAPON_UMP:
- data.WeaponArmorRatio = 1.3;
- data.flPenetrationPower = 1;
- data.iDamage = 35;
- data.flRange = 3700;
- data.flRangeModifier = 0.85;
- break;
- case WEAPON_XM1014:
- data.WeaponArmorRatio = 1.6;
- data.flPenetrationPower = 1;
- data.iDamage = 20;
- data.flRange = 3000;
- data.flRangeModifier = 0.70;
- break;
- case WEAPON_M4A1S:
- data.WeaponArmorRatio = 1.4;
- data.flPenetrationPower = 2;
- data.iDamage = 33;
- data.flRange = 8192;
- data.flRangeModifier = 0.97;
- default:
- data.WeaponArmorRatio = 0;
- data.flPenetrationPower = 0;
- data.iDamage = 0;
- data.flRange = 0;
- data.flRangeModifier = 0;
- break;
- }
- }
- float GetHitgroupDamageMultiplier( int iHitGroup )
- {
- switch ( iHitGroup )
- {
- case HITGROUP_HEAD:
- {
- return 4.0f;
- }
- case HITGROUP_CHEST:
- {
- return 1.0f;
- }
- case HITGROUP_LEFTARM:
- {
- return 1.0f;
- }
- case HITGROUP_RIGHTARM:
- {
- return 1.0f;
- }
- case HITGROUP_STOMACH:
- {
- return 1.25f;
- }
- case HITGROUP_LEFTLEG:
- {
- return 0.75f;
- }
- case HITGROUP_RIGHTLEG:
- {
- return 0.75f;
- }
- }
- return 1.0f;
- }
- struct FireBulletData
- {
- Vector src;
- trace_t enter_trace;
- Vector direction;
- CTraceFilter filter;
- float trace_length;
- float trace_length_remaining;
- float current_damage;
- int penetrate_count;
- };
- void ScaleDamage( int hitgroup, IClientEntity *enemy, float weapon_armor_ratio, float ¤t_damage )
- {
- current_damage *= GetHitgroupDamageMultiplier( hitgroup );
- if ( enemy->m_ArmorValue( ) > 0 )
- {
- if ( hitgroup == HITGROUP_HEAD )
- {
- if ( enemy->m_bHasHelmet( ) )
- current_damage *= ( weapon_armor_ratio * .5f );
- } else
- {
- current_damage *= ( weapon_armor_ratio * .5f );
- }
- }
- }
- bool SimulateFireBullet( IClientEntity *local, int weaponID, FireBulletData &data )
- {
- data.penetrate_count = 4;
- data.trace_length = 0.0f;
- CCSWeaponInfo_t wpn_data;
- getWeaponData( weaponID, wpn_data );
- data.current_damage = (float)wpn_data.iDamage;
- while ( ( data.penetrate_count > 0 ) && ( data.current_damage >= 1.0f ) )
- {
- data.trace_length_remaining = wpn_data.flRange - data.trace_length;
- Vector end = data.src + data.direction * data.trace_length_remaining;
- //TraceLine( data.src, end, 0x4600400B, local, &data.enter_trace );
- CTraceFilter filter;
- Ray_t ray;
- ray.Init( data.src, end );
- filter.pSkip = local;
- //data.enter_trace
- pEngineTrace->TraceRay( ray, 0x4600400B, &filter, &data.enter_trace );
- //UTIL_ClipTraceToPlayers( data.src, end + data.direction * 40.f, 0x4600400B, &data.filter, &data.enter_trace );
- ray.Init( data.src, end + data.direction*40.f );
- pEngineTrace->TraceRay( ray, 0x4600400B, &data.filter, &data.enter_trace );
- if ( data.enter_trace.fraction == 1.0f )
- break;
- if ( ( data.enter_trace.hitgroup <= 7 )
- && ( data.enter_trace.hitgroup > 0 )
- && ( Cvars.cfg_aimbot_aim_at_teammates || local->GetTeamNum( ) != data.enter_trace.m_pEnt->GetTeamNum( ) ) )
- {
- data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
- data.current_damage *= pow( wpn_data.flRangeModifier, data.trace_length * 0.002 );
- ScaleDamage( data.enter_trace.hitgroup, data.enter_trace.m_pEnt, wpn_data.WeaponArmorRatio, data.current_damage );
- return true;
- }
- if ( !Cvars.aimbot_rage_autowall )
- break;
- if ( !HandleBulletPenetration( &wpn_data, data ) )
- break;
- }
- return false;
- }
- #define SURF_HITBOX 0x8000
- bool DidHitWorld( IClientEntity* m_pEnt )
- {
- return m_pEnt == pClientEntList->GetClientEntity( 0 );
- }
- bool DidHitNonWorldEntity( IClientEntity* m_pEnt )
- {
- return m_pEnt != NULL && DidHitWorld( m_pEnt );
- }
- bool TraceToExit( Vector &end, trace_t *enter_trace, Vector start, Vector dir, trace_t *exit_trace )
- {
- float distance = 0.0f;
- while ( distance <= 90.0f )
- {
- distance += 4.0f;
- end = start + dir * distance;
- auto point_contents = pEngineTrace->GetPointContents( end, MASK_SHOT_HULL | CONTENTS_HITBOX, NULL );
- if ( point_contents & MASK_SHOT_HULL && ( !( point_contents & CONTENTS_HITBOX ) ) )
- continue;
- auto new_end = end - ( dir * 4.0f );
- //TraceLine( end, new_end, 0x4600400B, 0, exit_trace );
- Ray_t ray;
- ray.Init( end, new_end );
- pEngineTrace->TraceRay( ray, 0x4600400B, 0, exit_trace );
- // bool allsolid; @ TR + 54
- // bool startsolid; @ TR + 55
- if ( exit_trace->startsolid && exit_trace->surface.flags & SURF_HITBOX )
- {
- //TraceLine( end, start, 0x600400B, exit_trace->m_pEnt, exit_trace );
- ray.Init( end, start );
- CTraceFilter filter;
- filter.pSkip = exit_trace->m_pEnt;
- pEngineTrace->TraceRay( ray, 0x600400B, &filter, exit_trace );
- if ( ( exit_trace->fraction < 1.0f || exit_trace->allsolid ) && !exit_trace->startsolid )
- {
- end = exit_trace->endpos;
- return true;
- }
- continue;
- }
- if ( !( exit_trace->fraction < 1.0 || exit_trace->allsolid || exit_trace->startsolid ) || exit_trace->startsolid )
- {
- if ( exit_trace->m_pEnt )
- {
- if ( DidHitNonWorldEntity( enter_trace->m_pEnt ) )
- return true;
- }
- continue;
- }
- // checking for SURF_NODRAW perhaps
- if ( ( ( exit_trace->surface.flags >> 7 ) & 1 ) && !( ( enter_trace->surface.flags >> 7 ) & 1 ) )
- continue;
- //if ( exit_trace->plane.normal.Dot( dir, dir ) <= 1.0f )
- if ( cMath.DotProduct( exit_trace->plane.normal, dir ) <= 1.0f )
- {
- auto fraction = exit_trace->fraction * 4.0f;
- end = end - ( dir * fraction );
- return true;
- }
- }
- return false;
- }
- bool HandleBulletPenetration( CCSWeaponInfo_t *wpn_data, FireBulletData &data )
- {
- surfacedata_t *enter_surface_data = pPhysicsSurfaceProps->GetSurfaceData( data.enter_trace.surface.surfaceProps );
- int enter_material = enter_surface_data->game.material;
- float enter_surf_penetration_mod = enter_surface_data->game.flPenetrationModifier;
- data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
- data.current_damage *= pow( ( wpn_data->flRangeModifier ), ( data.trace_length * 0.002 ) );
- if ( ( data.trace_length > 3000.f ) || ( enter_surf_penetration_mod < 0.1f ) )
- data.penetrate_count = 0;
- if ( data.penetrate_count <= 0 )
- return false;
- Vector dummy;
- trace_t trace_exit;
- if ( !TraceToExit( dummy, &data.enter_trace, data.enter_trace.endpos, data.direction, &trace_exit ) )
- return false;
- surfacedata_t *exit_surface_data = pPhysicsSurfaceProps->GetSurfaceData( trace_exit.surface.surfaceProps );
- int exit_material = exit_surface_data->game.material;
- float exit_surf_penetration_mod = exit_surface_data->game.flPenetrationModifier;
- float final_damage_modifier = 0.16f;
- float combined_penetration_modifier = 0.0f;
- if ( ( ( data.enter_trace.contents & CONTENTS_GRATE ) != 0 ) || ( enter_material == 89 ) || ( enter_material == 71 ) )
- {
- combined_penetration_modifier = 3.0f;
- final_damage_modifier = 0.05f;
- } else
- {
- combined_penetration_modifier = ( enter_surf_penetration_mod + exit_surf_penetration_mod ) * 0.5f;
- }
- if ( enter_material == exit_material )
- {
- if ( exit_material == 87 || exit_material == 85 )
- combined_penetration_modifier = 3.0f;
- else if ( exit_material == 76 )
- combined_penetration_modifier = 2.0f;
- }
- float v34 = fmaxf( 0.f, 1.0f / combined_penetration_modifier );
- float v35 = ( data.current_damage * final_damage_modifier ) + v34 * 3.0f * fmaxf( 0.0f, ( 3.0f / wpn_data->flPenetrationPower ) * 1.25f );
- float thickness = cMath.VectorLength( trace_exit.endpos - data.enter_trace.endpos );
- thickness *= thickness;
- thickness *= v34;
- thickness /= 24.0f;
- float lost_damage = fmaxf( 0.0f, v35 + thickness );
- if ( lost_damage > data.current_damage )
- return false;
- if ( lost_damage >= 0.0f )
- data.current_damage -= lost_damage;
- if ( data.current_damage < 1.0f )
- return false;
- data.src = trace_exit.endpos;
- data.penetrate_count--;
- return true;
- }
- /*
- * CanHit() - example of how to use the code
- * @in point: target hitbox vector
- * @out damage_given: amount of damage the shot would do
- */
- bool CanHit( const Vector &point, float *damage_given )
- {
- IClientEntity* pLocalPlayer = pClientEntList->GetClientEntity( pEngine->GetLocalPlayer( ) );
- Vector dst = point;
- auto *local = pLocalPlayer;
- FireBulletData data;
- data.src = cEng.GetEyePosition( local );
- data.filter.pSkip = local;
- Vector angles = cEng.CalcAngle( data.src, dst );
- cMath.AngleVectors( angles, &data.direction );
- Vector dataNormalized;
- cMath.Normalize( data.direction, dataNormalized );
- data.direction = dataNormalized;
- IClientEntity* pWeap = pClientEntList->GetClientEntityFromHandle( local->GetActiveWeaponHandle( ) );
- if ( SimulateFireBullet( local, pWeap->ID( ), data ) )
- {
- *damage_given = data.current_damage;
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement