Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. #include "Ragebot.h"
  2. #include <chrono>
  3.  
  4. bool is_viable_target(IClientEntity* pEntity)
  5. {
  6. IClientEntity* m_local = game::localdata.localplayer();
  7. if (!pEntity) return false;
  8. if (pEntity->GetClientClass()->m_ClassID != (int)CSGOClassID::CCSPlayer) return false;
  9. if (pEntity == m_local) return false;
  10. if (pEntity->GetTeamNum() == m_local->GetTeamNum()) return false;
  11. if (pEntity->m_bGunGameImmunity()) return false;
  12. if (!pEntity->IsAlive() || pEntity->IsDormant()) return false;
  13. return true;
  14. }
  15.  
  16. void normalize_angle(float& flAngle)
  17. {
  18. if (std::isnan(flAngle)) flAngle = 0.0f;
  19. if (std::isinf(flAngle)) flAngle = 0.0f;
  20.  
  21. float flRevolutions = flAngle / 360;
  22.  
  23. if (flAngle > 180 || flAngle < -180)
  24. {
  25. if (flRevolutions < 0)
  26. flRevolutions = -flRevolutions;
  27.  
  28. flRevolutions = round(flRevolutions);
  29.  
  30. if (flAngle < 0)
  31. flAngle = (flAngle + 360 * flRevolutions);
  32. else
  33. flAngle = (flAngle - 360 * flRevolutions);
  34. }
  35. }
  36.  
  37. void Pitch_AntiAims::down(float& angle)
  38. {
  39. angle = 89.f;
  40. }
  41. void Pitch_AntiAims::fake_down(float& angle)
  42. {
  43. angle = -179.990005f;
  44. }
  45. void Pitch_AntiAims::up(float& angle)
  46. {
  47. angle = -89.f;
  48. }
  49. void Pitch_AntiAims::fake_up(float& angle)
  50. {
  51. angle = -270.f;
  52. }
  53. void Pitch_AntiAims::random(float& angle)
  54. {
  55. angle = game::math.random_float(-89, 89);
  56. }
  57. void Yaw_AntiAims::sideways(float& angle)
  58. {
  59. angle += 90;
  60. }
  61. void Yaw_AntiAims::backwards(float& angle)
  62. {
  63. angle -= 180;
  64. }
  65. void Yaw_AntiAims::crooked(float& angle)
  66. {
  67. angle += 145;
  68. }
  69. void Yaw_AntiAims::jitter(float& angle, CUserCmd* m_pcmd)
  70. {
  71. static bool flip = false; flip = !flip;
  72. float range = antiaimconfig.flJitterRange / 2;
  73. if (!flip)
  74. angle += 180 - range;
  75. else
  76. angle -= 180 - range;
  77. }
  78. void Yaw_AntiAims::swap(float& angle)
  79. {
  80. static bool flip = true;
  81.  
  82. if (flip) angle += 90.0f;
  83. else angle -= 90.0f;
  84.  
  85. static clock_t start_t = clock();
  86. double timeSoFar = (double)(clock() - start_t) / CLOCKS_PER_SEC;
  87. if (timeSoFar < .75)
  88. return;
  89. flip = !flip;
  90. start_t = clock();
  91. }
  92. void Yaw_AntiAims::rotate(float& angle)
  93. {
  94. angle += m_pGlobals->curtime * (antiaimconfig.flRotateSpeed * 1000);
  95. normalize_angle(angle);
  96. }
  97. void Yaw_AntiAims::corruption(float& angle)
  98. {
  99. long currentTime_ms = std::chrono::duration_cast< std::chrono::seconds >( std::chrono::system_clock::now( ).time_since_epoch( ) ).count( );
  100. static long timeStamp = currentTime_ms;
  101.  
  102. timeStamp = currentTime_ms;
  103.  
  104. switch ( timeStamp % 8 )
  105. {
  106. case 1: angle - 170 + rand( ) % ( ( 90 - 1 ) + 1 ) + 1; break;
  107. case 2: angle -= 180; break;
  108. case 3: angle -= 170 + rand( ) % ( ( 180 - 90 ) + 1 ) + 1; break;
  109. case 4: angle -= 180; break;
  110. case 5: angle -= 170 + rand( ) % ( ( ( -90 ) - ( -180 ) ) + 1 ) + 1; break;
  111. case 6: angle -= 180; break;
  112. case 7: angle -= 170 + rand( ) % ( ( ( -1 ) - ( -90 ) ) + 1 ) + 1; break;
  113. case 8: angle -= 180; break;
  114. }
  115. }
  116. void Yaw_AntiAims::lowerbody(float& angle)
  117. {
  118. auto m_local = game::localdata.localplayer();
  119. angle = m_local->GetLowerBodyYaw( );
  120. }
  121. enum ADAPTIVE_SIDE {
  122. ADAPTIVE_UNKNOWN,
  123. ADAPTIVE_LEFT,
  124. ADAPTIVE_RIGHT
  125. };
  126.  
  127. float AntiAim::curtime_fixed( CUserCmd* ucmd ) {
  128. auto local_player = game::localdata.localplayer( );
  129. static int g_tick = 0;
  130. static CUserCmd* g_pLastCmd = nullptr;
  131. if ( !g_pLastCmd || g_pLastCmd->hasbeenpredicted ) {
  132. g_tick = local_player->GetTickBase( );
  133. }
  134. else {
  135. // Required because prediction only runs on frames, not ticks
  136. // So if your framerate goes below tickrate, m_nTickBase won't update every tick
  137. ++g_tick;
  138. }
  139. g_pLastCmd = ucmd;
  140. float curtime = g_tick * m_pGlobals->interval_per_tick;
  141. return curtime;
  142. }
  143.  
  144. bool AntiAim::next_lby_update_func( CUserCmd* m_pcmd, const float yaw_to_break ) {
  145. auto m_local = game::localdata.localplayer( );
  146.  
  147. if ( m_local ) {
  148. static float last_attempted_yaw;
  149. static float old_lby;
  150. static float next_lby_update_time;
  151. const float current_time = curtime_fixed( m_pcmd ); // Fixes curtime to the frame so it breaks perfectly every time if delta is in range
  152.  
  153. if ( old_lby != m_local->GetLowerBodyYaw( ) && last_attempted_yaw != m_local->GetLowerBodyYaw( ) ) {
  154. old_lby = m_local->GetLowerBodyYaw( );
  155. if ( m_local->GetVelocity( ).Length2D( ) < 0.1 ) {
  156. auto latency = ( m_pEngine->GetNetChannelInfo( )->GetAvgLatency( FLOW_INCOMING ) + m_pEngine->GetNetChannelInfo( )->GetAvgLatency( FLOW_OUTGOING ) );
  157. next_lby_update_time = current_time + 1.1f;
  158. }
  159. }
  160.  
  161. if ( m_local->GetVelocity( ).Length2D( ) < 0.1 ) {
  162. if ( ( next_lby_update_time < current_time ) && m_local->GetFlags( ) & FL_ONGROUND ) {
  163. last_attempted_yaw = yaw_to_break;
  164. next_lby_update_time = current_time + 1.1f;
  165. return true;
  166. }
  167. }
  168. }
  169.  
  170. return false;
  171. }
  172.  
  173. void AntiAim::Manage(CUserCmd* pCmd, bool& bSendPacket)
  174. {
  175. static int ChokedPackets = -1;
  176. auto m_local = game::localdata.localplayer();
  177. auto m_weapon = m_local->GetWeapon();
  178. if (!m_local)
  179. return;
  180.  
  181. if (m_weapon->IsGrenade())
  182. return;
  183.  
  184. if (m_weapon->IsKnife() && pCmd->buttons & IN_ATTACK || m_weapon->IsKnife() && pCmd->buttons & IN_ATTACK2)
  185. return;
  186.  
  187. if (m_weapon->IsC4() && pCmd->buttons & IN_ATTACK)
  188. return;
  189.  
  190. if (pCmd->buttons & IN_USE)
  191. return;
  192.  
  193. if (m_local->GetMoveType() == 8 || m_local->GetMoveType() == 9)
  194. return;
  195.  
  196. if (ChokedPackets < 1 && m_local->IsAlive() && pCmd->buttons & IN_ATTACK && game::functions.can_shoot() && !m_weapon->IsKnife() && !m_weapon->IsGrenade())
  197. bSendPacket = false;
  198. else
  199. {
  200. if (m_local->IsAlive())
  201. {
  202. int MoveType = m_local->GetMoveType();
  203.  
  204. if (antiaimconfig.bDormantCheck)
  205. {
  206. bool dormant = true;
  207. for (int i = 1; i < m_pGlobals->maxClients; i++)
  208. {
  209. IClientEntity* ent = m_pEntityList->GetClientEntity(i);
  210. if (!ent || ent->GetClientClass()->m_ClassID != (int)CSGOClassID::CCSPlayer || ent->GetTeamNum() == m_local->GetTeamNum() || !ent->IsAlive()) continue;
  211. if (ent->IsDormant() == false)
  212. dormant = false;
  213. }
  214.  
  215. if (dormant)
  216. return;
  217. }
  218.  
  219. PitchOverrideTick(pCmd);
  220.  
  221. if (!game::globals.fakelag)
  222. bSendPacket = pCmd->command_number % 2;
  223.  
  224. if (!freestanding(pCmd, bSendPacket)) {
  225. if (bSendPacket) {
  226. FakeYawOverride(pCmd);
  227. } else {
  228. RealYawOverride(pCmd);
  229. }
  230.  
  231. bool clean_up;
  232. if (game::localdata.localplayer()->GetVelocity().Length() < 6)
  233. clean_up = antiaimconfig.stagnant.bCleanUp;
  234. else
  235. clean_up = antiaimconfig.moving.bCleanUp;
  236.  
  237. if (clean_up)
  238. {
  239. static float last_fake;
  240. static float last_real;
  241.  
  242. if (bSendPacket)
  243. last_fake = pCmd->viewangles.y;
  244. else
  245. last_real = pCmd->viewangles.y;
  246.  
  247. if (game::math.is_close(last_real, last_fake, 35) && !bSendPacket)
  248. pCmd->viewangles.y -= 90;
  249. }
  250. }
  251.  
  252. if ( !bSendPacket && antiaimconfig.bLbyBreaker ) {
  253. if ( next_lby_update_func( pCmd, pCmd->viewangles.y + antiaimconfig.flLbyDelta ) ) {
  254. pCmd->viewangles.y += antiaimconfig.flLbyDelta;
  255. }
  256. }
  257. }
  258. ChokedPackets = -1;
  259. }
  260. }
  261.  
  262. void AntiAim::PitchOverrideTick(CUserCmd* pCmd)
  263. {
  264. float pitch;
  265.  
  266. int type;
  267.  
  268. if (game::localdata.localplayer()->GetVelocity().Length() < 6)
  269. type = antiaimconfig.stagnant.iRealPitch;
  270. else
  271. type = antiaimconfig.moving.iRealPitch;
  272.  
  273. if (type == 1) pitches.down(pitch);
  274. else if (type == 3) pitches.fake_down(pitch);
  275. else if (type == 4) pitches.up(pitch);
  276. else if (type == 5) pitches.fake_up(pitch);
  277. else if (type == 5) pitches.random(pitch);
  278. else return;
  279.  
  280. pCmd->viewangles.x = pitch;
  281. }
  282.  
  283. void AntiAim::RealYawOverride(CUserCmd* pCmd)
  284. {
  285. float yaw = 0;
  286.  
  287. if (antiaimconfig.iRealYawDirection == 0)
  288. yaw = pCmd->viewangles.y;
  289. else if (antiaimconfig.iRealYawDirection == 1)
  290. yaw = 0;
  291. else if (antiaimconfig.iRealYawDirection == 2)
  292. {
  293. auto m_local = game::localdata.localplayer();
  294. int CurrentTarget = 0;
  295. float LastDistance = 999999999999.0f;
  296.  
  297. for (int i = 1; i < 65; i++)
  298. {
  299. auto pEntity = static_cast<IClientEntity*>(m_pEntityList->GetClientEntity(i));
  300. if (is_viable_target(pEntity))
  301. {
  302. float CurrentDistance = (pEntity->GetOrigin() - m_local->GetOrigin()).Length();
  303. if (!CurrentTarget || CurrentDistance < LastDistance)
  304. {
  305. CurrentTarget = i;
  306. LastDistance = CurrentDistance;
  307. }
  308. }
  309. }
  310.  
  311. if (!CurrentTarget)
  312. yaw = pCmd->viewangles.y;
  313. else
  314. {
  315. auto pEntity = static_cast<IClientEntity*>(m_pEntityList->GetClientEntity(CurrentTarget));
  316. Vector LookAtAngle = (pEntity->GetOrigin() - m_local->GetOrigin()).Angle();
  317. yaw = LookAtAngle.y;
  318. }
  319. }
  320.  
  321. int type;
  322.  
  323. if (game::localdata.localplayer()->GetVelocity().Length() < 6)
  324. type = antiaimconfig.stagnant.iRealYaw;
  325. else
  326. type = antiaimconfig.moving.iRealYaw;
  327.  
  328. if (type == 1) yaws.sideways(yaw);
  329. else if (type == 2) yaws.backwards(yaw);
  330. else if (type == 3) yaws.crooked(yaw);
  331. else if (type == 4) yaws.jitter(yaw, pCmd);
  332. else if (type == 5) yaws.swap(yaw);
  333. else if (type == 6) yaws.rotate(yaw);
  334. else if (type == 7) yaws.lowerbody(yaw);
  335. else if ( type == 8 ) yaws.corruption( yaw );
  336. else return;
  337.  
  338. if (game::localdata.localplayer()->GetVelocity().Length() < 6)
  339. yaw += antiaimconfig.stagnant.flRealYawOffset;
  340. else
  341. yaw += antiaimconfig.moving.flRealYawOffset;
  342.  
  343. pCmd->viewangles.y = yaw;
  344. }
  345.  
  346. void AntiAim::FakeYawOverride( CUserCmd* pCmd )
  347. {
  348. float yaw = 0;
  349.  
  350. if ( antiaimconfig.iRealYawDirection == 0 )
  351. yaw = pCmd->viewangles.y;
  352. else if ( antiaimconfig.iRealYawDirection == 1 )
  353. yaw = 0;
  354. else if ( antiaimconfig.iRealYawDirection == 2 )
  355. {
  356. auto m_local = game::localdata.localplayer( );
  357. int CurrentTarget = 0;
  358. float LastDistance = 999999999999.0f;
  359.  
  360. for ( int i = 1; i < 65; i++ )
  361. {
  362. auto pEntity = static_cast< IClientEntity* >( m_pEntityList->GetClientEntity( i ) );
  363. if ( is_viable_target( pEntity ) )
  364. {
  365. float CurrentDistance = ( pEntity->GetOrigin( ) - m_local->GetOrigin( ) ).Length( );
  366. if ( !CurrentTarget || CurrentDistance < LastDistance )
  367. {
  368. CurrentTarget = i;
  369. LastDistance = CurrentDistance;
  370. }
  371. }
  372. }
  373.  
  374. if ( !CurrentTarget )
  375. yaw = pCmd->viewangles.y;
  376. else
  377. {
  378. auto pEntity = static_cast< IClientEntity* >( m_pEntityList->GetClientEntity( CurrentTarget ) );
  379. Vector LookAtAngle = ( pEntity->GetOrigin( ) - m_local->GetOrigin( ) ).Angle( );
  380. yaw = LookAtAngle.y;
  381. }
  382. }
  383.  
  384. int type;
  385.  
  386. if ( game::localdata.localplayer( )->GetVelocity( ).Length( ) < 6 )
  387. type = antiaimconfig.stagnant.iFakeYaw;
  388. else
  389. type = antiaimconfig.moving.iFakeYaw;
  390.  
  391. if ( type == 1 ) yaws.sideways( yaw );
  392. else if ( type == 2 ) yaws.backwards( yaw );
  393. else if ( type == 3 ) yaws.crooked( yaw );
  394. else if ( type == 4 ) yaws.jitter( yaw, pCmd );
  395. else if ( type == 5 ) yaws.swap( yaw );
  396. else if ( type == 6 ) yaws.rotate( yaw );
  397. else if ( type == 7 ) yaws.lowerbody( yaw );
  398. else if ( type == 8 ) yaws.corruption( yaw );
  399. else return;
  400.  
  401. if ( game::localdata.localplayer( )->GetVelocity( ).Length( ) < 6 )
  402. yaw += antiaimconfig.stagnant.flFakeYawOffset;
  403. else
  404. yaw += antiaimconfig.moving.flFakeYawOffset;
  405.  
  406. pCmd->viewangles.y = yaw;
  407. }
  408.  
  409. bool AntiAim::freestanding( CUserCmd* m_pcmd, bool packet )
  410. {
  411. IClientEntity* m_local = game::localdata.localplayer( );
  412.  
  413. if ( antiaimconfig.edge.iWallDtc == 1 && m_local->GetVelocity( ).Length( ) < 300 ) {
  414.  
  415. auto fov_to_player = [ ] ( Vector view_offset, Vector view, IClientEntity* m_entity, int hitbox )
  416. {
  417. CONST FLOAT MaxDegrees = 180.0f;
  418. Vector Angles = view;
  419. Vector Origin = view_offset;
  420. Vector Delta( 0, 0, 0 );
  421. Vector Forward( 0, 0, 0 );
  422. game::math.angle_vectors( Angles, Forward );
  423. Vector AimPos = game::functions.get_hitbox_location( m_entity, hitbox );
  424. game::math.vector_subtract( AimPos, Origin, Delta );
  425. game::math.normalize( Delta, Delta );
  426. FLOAT DotProduct = Forward.Dot( Delta );
  427. return ( acos( DotProduct ) * ( MaxDegrees / PI ) );
  428. };
  429.  
  430. int target = -1;
  431. float mfov = 50;
  432.  
  433. Vector viewoffset = m_local->GetOrigin( ) + m_local->GetViewOffset( );
  434. Vector view; m_pEngine->GetViewAngles( view );
  435.  
  436. for ( int i = 0; i < m_pGlobals->maxClients; i++ ) {
  437. IClientEntity* m_entity = m_pEntityList->GetClientEntity( i );
  438.  
  439. if ( is_viable_target( m_entity ) ) {
  440.  
  441. float fov = fov_to_player( viewoffset, view, m_entity, 0 );
  442. if ( fov < mfov ) {
  443. mfov = fov;
  444. target = i;
  445. }
  446. }
  447. }
  448.  
  449. Vector at_target_angle;
  450.  
  451. if ( target ) {
  452. auto m_entity = m_pEntityList->GetClientEntity( target );
  453.  
  454. if ( is_viable_target( m_entity ) ) {
  455. Vector head_pos_screen;
  456.  
  457. if ( game::functions.world_to_screen( m_entity->GetHeadPos( ), head_pos_screen ) ) {
  458.  
  459. float pitch = m_pcmd->viewangles.x;
  460. int type = antiaimconfig.edge.iRealPitch;
  461. if ( type == 1 ) pitches.down( pitch );
  462. else if ( type == 3 ) pitches.fake_down( pitch );
  463. else if ( type == 4 ) pitches.up( pitch );
  464. else if ( type == 5 ) pitches.fake_up( pitch );
  465. else if ( type == 5 ) pitches.random( pitch );
  466. m_pcmd->viewangles.x = pitch;
  467.  
  468. float yaw = m_pcmd->viewangles.y;
  469. type = packet ? antiaimconfig.edge.iFakeYaw : antiaimconfig.edge.iRealYaw;
  470. if ( type == 1 ) yaws.sideways( yaw );
  471. else if ( type == 2 ) yaws.backwards( yaw );
  472. else if ( type == 3 ) yaws.crooked( yaw );
  473. else if ( type == 4 ) yaws.jitter( yaw, m_pcmd );
  474. else if ( type == 5 ) yaws.swap( yaw );
  475. else if ( type == 6 ) yaws.rotate( yaw );
  476. if ( game::localdata.localplayer( )->GetVelocity( ).Length( ) < 6 ) yaw += antiaimconfig.stagnant.flRealYawOffset;
  477. else yaw += antiaimconfig.moving.flRealYawOffset;
  478. m_pcmd->viewangles.y = yaw;
  479.  
  480. game::math.calculate_angle( m_local->GetOrigin( ), m_entity->GetOrigin( ), at_target_angle );
  481. at_target_angle.x = 0;
  482.  
  483. Vector src3D, dst3D, forward, right, up, src, dst;
  484. float back_two, right_two, left_two;
  485. trace_t tr;
  486. Ray_t ray, ray2, ray3, ray4, ray5;
  487. CTraceFilter filter;
  488.  
  489. const Vector to_convert = at_target_angle;
  490. game::math.angle_vectors( to_convert, &forward, &right, &up );
  491.  
  492. filter.pSkip = m_local;
  493. src3D = m_local->GetEyePosition( );
  494. dst3D = src3D + ( forward * 384 ); //Might want to experiment with other numbers, incase you don't know what the number does, its how far the trace will go. Lower = shorter.
  495.  
  496. ray.Init( src3D, dst3D );
  497. m_pTrace->TraceRay( ray, MASK_SHOT, &filter, &tr );
  498. back_two = ( tr.endpos - tr.startpos ).Length( );
  499.  
  500. ray2.Init( src3D + right * 35, dst3D + right * 35 );
  501. m_pTrace->TraceRay( ray2, MASK_SHOT, &filter, &tr );
  502. right_two = ( tr.endpos - tr.startpos ).Length( );
  503.  
  504. ray3.Init( src3D - right * 35, dst3D - right * 35 );
  505. m_pTrace->TraceRay( ray3, MASK_SHOT, &filter, &tr );
  506. left_two = ( tr.endpos - tr.startpos ).Length( );
  507.  
  508. if ( left_two > right_two ) {
  509. m_pcmd->viewangles.y -= 90;
  510. //Body should be right
  511. }
  512. else if ( right_two > left_two ) {
  513. m_pcmd->viewangles.y += 90;
  514. //Body should be left
  515. }
  516. //if (packet) m_pcmd->viewangles.y += 180;
  517. return true;
  518. }
  519. }
  520. }
  521. }
  522. return false;
  523. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement