Advertisement
encoree1996

Untitled

Sep 29th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.80 KB | None | 0 0
  1.  
  2. bool CRage::CanPenetrate( Vector Destination, float * damage_given )
  3. {
  4. return CanHit( Destination, damage_given );
  5. }
  6.  
  7. //myfixes
  8.  
  9. #define HITGROUP_GENERIC 0
  10. #define HITGROUP_HEAD 1
  11. #define HITGROUP_CHEST 2
  12. #define HITGROUP_STOMACH 3
  13. #define HITGROUP_LEFTARM 4
  14. #define HITGROUP_RIGHTARM 5
  15. #define HITGROUP_LEFTLEG 6
  16. #define HITGROUP_RIGHTLEG 7
  17. #define HITGROUP_GEAR 10
  18.  
  19.  
  20.  
  21. //letz twist again
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. struct weaponParameters
  30. {
  31. float Penetration, Damage, Range, RangeModifier;
  32. };
  33.  
  34. std::vector<weaponParameters> weaponParams;
  35.  
  36. void getWeaponData( int weaponID, CCSWeaponInfo_t& data )
  37. {
  38. switch ( weaponID )
  39. {
  40.  
  41. case WEAPON_AK47:
  42. data.WeaponArmorRatio = 1.55;
  43. data.flPenetrationPower = 2;
  44. data.iDamage = 36;
  45. data.flRange = 8192;
  46. data.flRangeModifier = 0.98;
  47. break;
  48. case WEAPON_AUG:
  49. data.WeaponArmorRatio = 1.8;
  50. data.flPenetrationPower = 2;
  51. data.iDamage = 28;
  52. data.flRange = 8192;
  53. data.flRangeModifier = 0.98;
  54. break;
  55. case WEAPON_AWP:
  56. data.WeaponArmorRatio = 1.95;
  57. data.flPenetrationPower = 2.5;
  58. data.iDamage = 115;
  59. data.flRange = 8192;
  60. data.flRangeModifier = 0.99;
  61. break;
  62. case WEAPON_BIZON:
  63. data.WeaponArmorRatio = 1.15;
  64. data.flPenetrationPower = 1;
  65. data.iDamage = 27;
  66. data.flRange = 3600;
  67. data.flRangeModifier = 0.80;
  68. break;
  69. case WEAPON_C4:
  70. data.WeaponArmorRatio = 1.0;
  71. data.flPenetrationPower = 1;
  72. data.iDamage = 50;
  73. data.flRange = 4096;
  74. data.flRangeModifier = 0.99;
  75. break;
  76. case WEAPON_DEAGLE:
  77. data.WeaponArmorRatio = 1.864;
  78. data.flPenetrationPower = 2;
  79. data.iDamage = 63;
  80. data.flRange = 4096;
  81. data.flRangeModifier = 0.81;
  82. break;
  83. case WEAPON_DECOY:
  84. data.WeaponArmorRatio = 1;
  85. data.flPenetrationPower = 1;
  86. data.iDamage = 50;
  87. data.flRange = 4096;
  88. data.flRangeModifier = 0.99;
  89. break;
  90. case WEAPON_DUAL:
  91. data.WeaponArmorRatio = 1.15;
  92. data.flPenetrationPower = 1;
  93. data.iDamage = 38;
  94. data.flRange = 4096;
  95. data.flRangeModifier = 0.79;
  96. break;
  97. case WEAPON_FAMAS:
  98. data.WeaponArmorRatio = 1.4;
  99. data.flPenetrationPower = 2;
  100. data.iDamage = 30;
  101. data.flRange = 8192;
  102. data.flRangeModifier = 0.96;
  103. break;
  104. case WEAPON_FIVE7:
  105. data.WeaponArmorRatio = 1.823;
  106. data.flPenetrationPower = 1;
  107. data.iDamage = 32;
  108. data.flRange = 4096;
  109. data.flRangeModifier = 0.81;
  110. break;
  111. case WEAPON_FLASHBANG:
  112. data.WeaponArmorRatio = 1;
  113. data.flPenetrationPower = 1;
  114. data.iDamage = 50;
  115. data.flRange = 4096;
  116. data.flRangeModifier = 0.99;
  117. break;
  118. case WEAPON_G3SG1:
  119. data.WeaponArmorRatio = 1.65;
  120. data.flPenetrationPower = 2.5;
  121. data.iDamage = 80;
  122. data.flRange = 8192;
  123. data.flRangeModifier = 0.98;
  124. break;
  125. case WEAPON_GALIL:
  126. data.WeaponArmorRatio = 1.55;
  127. data.flPenetrationPower = 2;
  128. data.iDamage = 30;
  129. data.flRange = 8192;
  130. data.flRangeModifier = 0.98;
  131. break;
  132. case WEAPON_GLOCK:
  133. data.WeaponArmorRatio = 0.94;
  134. data.flPenetrationPower = 1;
  135. data.iDamage = 28;
  136. data.flRange = 4096;
  137. data.flRangeModifier = 0.9;
  138. break;
  139. case WEAPON_HEGRENADE:
  140. data.WeaponArmorRatio = 1.2;
  141. data.iDamage = 99;
  142. data.flPenetrationPower = 1;
  143. data.flRange = 350;
  144. data.flRangeModifier = 0.99;
  145. break;
  146. case WEAPON_HKP2000:
  147. data.WeaponArmorRatio = 1.01;
  148. data.flPenetrationPower = 1;
  149. data.iDamage = 35;
  150. data.flRange = 4096;
  151. data.flRangeModifier = 0.91;
  152. break;
  153. case WEAPON_CT_MOLOTOV:
  154. data.WeaponArmorRatio = 1.475;
  155. data.flPenetrationPower = 1;
  156. data.iDamage = 40;
  157. data.flRange = 4096;
  158. data.flRangeModifier = 0.99;
  159. break;
  160. case WEAPON_KNIFE_T:
  161. data.WeaponArmorRatio = 1.7;
  162. data.flPenetrationPower = 1;
  163. data.iDamage = 50;
  164. data.flRange = 4096;
  165. data.flRangeModifier = 0.99;
  166. break;
  167. case WEAPON_KNIFEGG:
  168. data.WeaponArmorRatio = 1.7;
  169. data.flPenetrationPower = 1;
  170. data.iDamage = 50;
  171. data.flRange = 4096;
  172. data.flRangeModifier = 0.99;
  173. break;
  174. case WEAPON_M249:
  175. data.WeaponArmorRatio = 1.6;
  176. data.flPenetrationPower = 2;
  177. data.iDamage = 32;
  178. data.flRange = 8192;
  179. data.flRangeModifier = 0.97;
  180. break;
  181. case WEAPON_M4A1:
  182. data.WeaponArmorRatio = 1.4;
  183. data.flPenetrationPower = 2;
  184. data.iDamage = 33;
  185. data.flRange = 8192;
  186. data.flRangeModifier = 0.97;
  187. break;
  188. case WEAPON_MAC10:
  189. data.WeaponArmorRatio = 1.15;
  190. data.flPenetrationPower = 1;
  191. data.iDamage = 29;
  192. data.flRange = 3600;
  193. data.flRangeModifier = 0.80;
  194. break;
  195. case WEAPON_MAG7:
  196. data.WeaponArmorRatio = 1.5;
  197. data.flPenetrationPower = 1;
  198. data.iDamage = 30;
  199. data.flRange = 1400;
  200. data.flRangeModifier = 0.45;
  201. break;
  202. case WEAPON_T_MOLOTOV:
  203. data.WeaponArmorRatio = 1.8;
  204. data.flPenetrationPower = 1;
  205. data.iDamage = 40;
  206. data.flRange = 4096;
  207. data.flRangeModifier = 0.99;
  208. break;
  209. case WEAPON_MP7:
  210. data.WeaponArmorRatio = 1.25;
  211. data.flPenetrationPower = 1;
  212. data.iDamage = 29;
  213. data.flRange = 3600;
  214. data.flRangeModifier = 0.85;
  215. break;
  216. case WEAPON_MP9:
  217. data.WeaponArmorRatio = 1.20;
  218. data.flPenetrationPower = 1;
  219. data.iDamage = 26;
  220. data.flRange = 3600;
  221. data.flRangeModifier = 0.87;
  222. break;
  223. case WEAPON_NEGEV:
  224. data.WeaponArmorRatio = 1.5;
  225. data.flPenetrationPower = 2;
  226. data.iDamage = 35;
  227. data.flRange = 8192;
  228. data.flRangeModifier = 0.97;
  229. break;
  230. case WEAPON_NOVA:
  231. data.WeaponArmorRatio = 1.0;
  232. data.flPenetrationPower = 0;
  233. data.iDamage = 26;
  234. data.flRange = 3000;
  235. data.flRangeModifier = 0.70;
  236. break;
  237. case WEAPON_P250:
  238. data.WeaponArmorRatio = 1.553;
  239. data.flPenetrationPower = 1;
  240. data.iDamage = 35;
  241. data.flRange = 4096;
  242. data.flRangeModifier = 0.85;
  243. break;
  244. case WEAPON_CZ75:
  245. data.WeaponArmorRatio = 1.553;
  246. data.flPenetrationPower = 1;
  247. data.iDamage = 35;
  248. data.flRange = 4096;
  249. data.flRangeModifier = 0.85;
  250. break;
  251. case WEAPON_P90:
  252. data.WeaponArmorRatio = 1.38;
  253. data.flPenetrationPower = 1;
  254. data.iDamage = 26;
  255. data.flRange = 3700;
  256. data.flRangeModifier = 0.86;
  257. break;
  258. case WEAPON_SAWEDOFF:
  259. data.WeaponArmorRatio = 1.5;
  260. data.flPenetrationPower = 1;
  261. data.iDamage = 32;
  262. data.flRange = 650;
  263. data.flRangeModifier = 0.45;
  264. break;
  265. case WEAPON_SCAR20:
  266. data.WeaponArmorRatio = 1.65;
  267. data.flPenetrationPower = 2.5;
  268. data.iDamage = 80;
  269. data.flRange = 8192;
  270. data.flRangeModifier = 0.98;
  271. break;
  272. case WEAPON_SG553:
  273. data.WeaponArmorRatio = 2.0;
  274. data.flPenetrationPower = 2;
  275. data.iDamage = 30;
  276. data.flRange = 8192;
  277. data.flRangeModifier = 0.98;
  278. break;
  279. case WEAPON_SMOKE:
  280. data.WeaponArmorRatio = 1.0;
  281. data.flPenetrationPower = 0;
  282. data.iDamage = 50;
  283. data.flRange = 4096;
  284. data.flRangeModifier = 0.99;
  285. break;
  286. case WEAPON_SSG08:
  287. data.WeaponArmorRatio = 1.7;
  288. data.flPenetrationPower = 2.5;
  289. data.iDamage = 88;
  290. data.flRange = 8192;
  291. data.flRangeModifier = 0.98;
  292. break;
  293. case WEAPON_TASER:
  294. data.WeaponArmorRatio = 2;
  295. data.flPenetrationPower = 0;
  296. data.iDamage = 500;
  297. data.flRange = 190;
  298. data.flRangeModifier = 0.0049;
  299. break;
  300. case WEAPON_TEC9:
  301. data.WeaponArmorRatio = 1.812;
  302. data.flPenetrationPower = 1;
  303. data.iDamage = 33;
  304. data.flRange = 4096;
  305. data.flRangeModifier = 0.79;
  306. break;
  307. case WEAPON_UMP:
  308. data.WeaponArmorRatio = 1.3;
  309. data.flPenetrationPower = 1;
  310. data.iDamage = 35;
  311. data.flRange = 3700;
  312. data.flRangeModifier = 0.85;
  313. break;
  314. case WEAPON_XM1014:
  315. data.WeaponArmorRatio = 1.6;
  316. data.flPenetrationPower = 1;
  317. data.iDamage = 20;
  318. data.flRange = 3000;
  319. data.flRangeModifier = 0.70;
  320. break;
  321. case WEAPON_M4A1S:
  322. data.WeaponArmorRatio = 1.4;
  323. data.flPenetrationPower = 2;
  324. data.iDamage = 33;
  325. data.flRange = 8192;
  326. data.flRangeModifier = 0.97;
  327. default:
  328. data.WeaponArmorRatio = 0;
  329. data.flPenetrationPower = 0;
  330. data.iDamage = 0;
  331. data.flRange = 0;
  332. data.flRangeModifier = 0;
  333. break;
  334. }
  335. }
  336.  
  337. float GetHitgroupDamageMultiplier( int iHitGroup )
  338. {
  339. switch ( iHitGroup )
  340. {
  341. case HITGROUP_HEAD:
  342. {
  343. return 4.0f;
  344. }
  345. case HITGROUP_CHEST:
  346. {
  347. return 1.0f;
  348. }
  349. case HITGROUP_LEFTARM:
  350. {
  351. return 1.0f;
  352. }
  353. case HITGROUP_RIGHTARM:
  354. {
  355. return 1.0f;
  356. }
  357. case HITGROUP_STOMACH:
  358. {
  359. return 1.25f;
  360. }
  361. case HITGROUP_LEFTLEG:
  362. {
  363. return 0.75f;
  364. }
  365. case HITGROUP_RIGHTLEG:
  366. {
  367. return 0.75f;
  368. }
  369. }
  370. return 1.0f;
  371. }
  372. struct FireBulletData
  373. {
  374. Vector src;
  375. trace_t enter_trace;
  376. Vector direction;
  377. CTraceFilter filter;
  378. float trace_length;
  379. float trace_length_remaining;
  380. float current_damage;
  381. int penetrate_count;
  382. };
  383.  
  384. void ScaleDamage( int hitgroup, IClientEntity *enemy, float weapon_armor_ratio, float &current_damage )
  385. {
  386. current_damage *= GetHitgroupDamageMultiplier( hitgroup );
  387.  
  388. if ( enemy->m_ArmorValue( ) > 0 )
  389. {
  390. if ( hitgroup == HITGROUP_HEAD )
  391. {
  392. if ( enemy->m_bHasHelmet( ) )
  393. current_damage *= ( weapon_armor_ratio * .5f );
  394. } else
  395. {
  396. current_damage *= ( weapon_armor_ratio * .5f );
  397. }
  398. }
  399. }
  400.  
  401. bool SimulateFireBullet( IClientEntity *local, int weaponID, FireBulletData &data )
  402. {
  403. data.penetrate_count = 4;
  404. data.trace_length = 0.0f;
  405. CCSWeaponInfo_t wpn_data;
  406. getWeaponData( weaponID, wpn_data );
  407.  
  408. data.current_damage = (float)wpn_data.iDamage;
  409.  
  410. while ( ( data.penetrate_count > 0 ) && ( data.current_damage >= 1.0f ) )
  411. {
  412. data.trace_length_remaining = wpn_data.flRange - data.trace_length;
  413.  
  414. Vector end = data.src + data.direction * data.trace_length_remaining;
  415.  
  416. //TraceLine( data.src, end, 0x4600400B, local, &data.enter_trace );
  417. CTraceFilter filter;
  418. Ray_t ray;
  419. ray.Init( data.src, end );
  420. filter.pSkip = local;
  421. //data.enter_trace
  422. pEngineTrace->TraceRay( ray, 0x4600400B, &filter, &data.enter_trace );
  423.  
  424.  
  425. //UTIL_ClipTraceToPlayers( data.src, end + data.direction * 40.f, 0x4600400B, &data.filter, &data.enter_trace );
  426. ray.Init( data.src, end + data.direction*40.f );
  427. pEngineTrace->TraceRay( ray, 0x4600400B, &data.filter, &data.enter_trace );
  428.  
  429. if ( data.enter_trace.fraction == 1.0f )
  430. break;
  431.  
  432. if ( ( data.enter_trace.hitgroup <= 7 )
  433. && ( data.enter_trace.hitgroup > 0 )
  434. && ( Cvars.cfg_aimbot_aim_at_teammates || local->GetTeamNum( ) != data.enter_trace.m_pEnt->GetTeamNum( ) ) )
  435. {
  436. data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
  437. data.current_damage *= pow( wpn_data.flRangeModifier, data.trace_length * 0.002 );
  438. ScaleDamage( data.enter_trace.hitgroup, data.enter_trace.m_pEnt, wpn_data.WeaponArmorRatio, data.current_damage );
  439.  
  440. return true;
  441. }
  442.  
  443. if ( !Cvars.aimbot_rage_autowall )
  444. break;
  445.  
  446. if ( !HandleBulletPenetration( &wpn_data, data ) )
  447. break;
  448. }
  449.  
  450. return false;
  451. }
  452.  
  453. #define SURF_HITBOX 0x8000
  454.  
  455.  
  456. bool DidHitWorld( IClientEntity* m_pEnt )
  457. {
  458. return m_pEnt == pClientEntList->GetClientEntity( 0 );
  459. }
  460.  
  461. bool DidHitNonWorldEntity( IClientEntity* m_pEnt )
  462. {
  463. return m_pEnt != NULL && DidHitWorld( m_pEnt );
  464. }
  465.  
  466. bool TraceToExit( Vector &end, trace_t *enter_trace, Vector start, Vector dir, trace_t *exit_trace )
  467. {
  468. float distance = 0.0f;
  469.  
  470. while ( distance <= 90.0f )
  471. {
  472. distance += 4.0f;
  473. end = start + dir * distance;
  474.  
  475. auto point_contents = pEngineTrace->GetPointContents( end, MASK_SHOT_HULL | CONTENTS_HITBOX, NULL );
  476.  
  477. if ( point_contents & MASK_SHOT_HULL && ( !( point_contents & CONTENTS_HITBOX ) ) )
  478. continue;
  479.  
  480. auto new_end = end - ( dir * 4.0f );
  481.  
  482. //TraceLine( end, new_end, 0x4600400B, 0, exit_trace );
  483. Ray_t ray;
  484. ray.Init( end, new_end );
  485. pEngineTrace->TraceRay( ray, 0x4600400B, 0, exit_trace );
  486.  
  487. // bool allsolid; @ TR + 54
  488. // bool startsolid; @ TR + 55
  489.  
  490. if ( exit_trace->startsolid && exit_trace->surface.flags & SURF_HITBOX )
  491. {
  492. //TraceLine( end, start, 0x600400B, exit_trace->m_pEnt, exit_trace );
  493. ray.Init( end, start );
  494. CTraceFilter filter;
  495. filter.pSkip = exit_trace->m_pEnt;
  496. pEngineTrace->TraceRay( ray, 0x600400B, &filter, exit_trace );
  497.  
  498. if ( ( exit_trace->fraction < 1.0f || exit_trace->allsolid ) && !exit_trace->startsolid )
  499. {
  500. end = exit_trace->endpos;
  501. return true;
  502. }
  503. continue;
  504. }
  505.  
  506. if ( !( exit_trace->fraction < 1.0 || exit_trace->allsolid || exit_trace->startsolid ) || exit_trace->startsolid )
  507. {
  508. if ( exit_trace->m_pEnt )
  509. {
  510. if ( DidHitNonWorldEntity( enter_trace->m_pEnt ) )
  511. return true;
  512. }
  513. continue;
  514. }
  515.  
  516. // checking for SURF_NODRAW perhaps
  517. if ( ( ( exit_trace->surface.flags >> 7 ) & 1 ) && !( ( enter_trace->surface.flags >> 7 ) & 1 ) )
  518. continue;
  519.  
  520. //if ( exit_trace->plane.normal.Dot( dir, dir ) <= 1.0f )
  521. if ( cMath.DotProduct( exit_trace->plane.normal, dir ) <= 1.0f )
  522. {
  523. auto fraction = exit_trace->fraction * 4.0f;
  524. end = end - ( dir * fraction );
  525. return true;
  526. }
  527. }
  528. return false;
  529. }
  530.  
  531. bool HandleBulletPenetration( CCSWeaponInfo_t *wpn_data, FireBulletData &data )
  532. {
  533. surfacedata_t *enter_surface_data = pPhysicsSurfaceProps->GetSurfaceData( data.enter_trace.surface.surfaceProps );
  534. int enter_material = enter_surface_data->game.material;
  535. float enter_surf_penetration_mod = enter_surface_data->game.flPenetrationModifier;
  536.  
  537. data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
  538. data.current_damage *= pow( ( wpn_data->flRangeModifier ), ( data.trace_length * 0.002 ) );
  539.  
  540. if ( ( data.trace_length > 3000.f ) || ( enter_surf_penetration_mod < 0.1f ) )
  541. data.penetrate_count = 0;
  542.  
  543. if ( data.penetrate_count <= 0 )
  544. return false;
  545.  
  546. Vector dummy;
  547. trace_t trace_exit;
  548. if ( !TraceToExit( dummy, &data.enter_trace, data.enter_trace.endpos, data.direction, &trace_exit ) )
  549. return false;
  550.  
  551. surfacedata_t *exit_surface_data = pPhysicsSurfaceProps->GetSurfaceData( trace_exit.surface.surfaceProps );
  552. int exit_material = exit_surface_data->game.material;
  553.  
  554. float exit_surf_penetration_mod = exit_surface_data->game.flPenetrationModifier;
  555. float final_damage_modifier = 0.16f;
  556. float combined_penetration_modifier = 0.0f;
  557.  
  558. if ( ( ( data.enter_trace.contents & CONTENTS_GRATE ) != 0 ) || ( enter_material == 89 ) || ( enter_material == 71 ) )
  559. {
  560. combined_penetration_modifier = 3.0f;
  561. final_damage_modifier = 0.05f;
  562. } else
  563. {
  564. combined_penetration_modifier = ( enter_surf_penetration_mod + exit_surf_penetration_mod ) * 0.5f;
  565. }
  566.  
  567. if ( enter_material == exit_material )
  568. {
  569. if ( exit_material == 87 || exit_material == 85 )
  570. combined_penetration_modifier = 3.0f;
  571. else if ( exit_material == 76 )
  572. combined_penetration_modifier = 2.0f;
  573. }
  574.  
  575. float v34 = fmaxf( 0.f, 1.0f / combined_penetration_modifier );
  576. float v35 = ( data.current_damage * final_damage_modifier ) + v34 * 3.0f * fmaxf( 0.0f, ( 3.0f / wpn_data->flPenetrationPower ) * 1.25f );
  577. float thickness = cMath.VectorLength( trace_exit.endpos - data.enter_trace.endpos );
  578.  
  579. thickness *= thickness;
  580. thickness *= v34;
  581. thickness /= 24.0f;
  582.  
  583. float lost_damage = fmaxf( 0.0f, v35 + thickness );
  584.  
  585. if ( lost_damage > data.current_damage )
  586. return false;
  587.  
  588. if ( lost_damage >= 0.0f )
  589. data.current_damage -= lost_damage;
  590.  
  591. if ( data.current_damage < 1.0f )
  592. return false;
  593.  
  594. data.src = trace_exit.endpos;
  595. data.penetrate_count--;
  596.  
  597. return true;
  598. }
  599.  
  600.  
  601. /*
  602. * CanHit() - example of how to use the code
  603. * @in point: target hitbox vector
  604. * @out damage_given: amount of damage the shot would do
  605. */
  606. bool CanHit( const Vector &point, float *damage_given )
  607. {
  608. IClientEntity* pLocalPlayer = pClientEntList->GetClientEntity( pEngine->GetLocalPlayer( ) );
  609. Vector dst = point;
  610. auto *local = pLocalPlayer;
  611. FireBulletData data;
  612. data.src = cEng.GetEyePosition( local );
  613. data.filter.pSkip = local;
  614.  
  615. Vector angles = cEng.CalcAngle( data.src, dst );
  616. cMath.AngleVectors( angles, &data.direction );
  617. Vector dataNormalized;
  618. cMath.Normalize( data.direction, dataNormalized );
  619. data.direction = dataNormalized;
  620. IClientEntity* pWeap = pClientEntList->GetClientEntityFromHandle( local->GetActiveWeaponHandle( ) );
  621. if ( SimulateFireBullet( local, pWeap->ID( ), data ) )
  622. {
  623. *damage_given = data.current_damage;
  624.  
  625. return true;
  626. }
  627.  
  628. return false;
  629. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement