Advertisement
Guest User

Desync Not Steady

a guest
Mar 25th, 2020
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.80 KB | None | 0 0
  1. #include "AntiAim.hpp"
  2.  
  3. #include "../Structs.hpp"
  4. #include "../Options.hpp"
  5.  
  6. #include "AimRage.hpp"
  7. #include "Resolver.hpp"
  8. #include "RebuildGameMovement.hpp"
  9. #include "Miscellaneous.hpp"
  10. #include "PredictionSystem.hpp"
  11.  
  12. #include "../helpers/Utils.hpp"
  13. #include "../helpers/Math.hpp"
  14.  
  15. #include <time.h>
  16.  
  17. void AntiAim::Work(CUserCmd *usercmd)
  18. {
  19. if (!g_EngineClient->IsConnected() && !g_EngineClient->IsInGame())
  20. return;
  21.  
  22. if (!g_LocalPlayer->IsAlive())
  23. return;
  24.  
  25. this->usercmd = usercmd;
  26.  
  27. if (usercmd->buttons & IN_USE || g_LocalPlayer->m_fFlags() & FL_FROZEN || g_LocalPlayer->IsDormant())
  28. return;
  29.  
  30. auto weapon = g_LocalPlayer->m_hActiveWeapon().Get();
  31.  
  32. if (!weapon)
  33. return;
  34.  
  35. if (weapon->m_iItemDefinitionIndex() == WEAPON_REVOLVER)
  36. {
  37. if (usercmd->buttons & IN_ATTACK2)
  38. return;
  39.  
  40. if (weapon->CanFirePostPone() && (usercmd->buttons & IN_ATTACK))
  41. return;
  42. }
  43. else if (weapon->GetWeapInfo()->weapon_type() == WEAPONTYPE_GRENADE)
  44. {
  45. if (weapon->IsInThrow())
  46. return;
  47. }
  48. else
  49. {
  50. if (weapon->GetWeapInfo()->weapon_type() == WEAPONTYPE_KNIFE && ((usercmd->buttons & IN_ATTACK) || (usercmd->buttons & IN_ATTACK2)))
  51. return;
  52. else if ((usercmd->buttons & IN_ATTACK) && (weapon->m_iItemDefinitionIndex() != WEAPON_C4 || g_Options.hvh_antiaim_x != AA_PITCH_OFF))
  53. return;
  54. }
  55.  
  56. if (g_LocalPlayer->GetMoveType() == MOVETYPE_NOCLIP || g_LocalPlayer->GetMoveType() == MOVETYPE_LADDER)
  57. return;
  58.  
  59. if (!Global::bFakelag)
  60. Global::bSendPacket = usercmd->command_number % 2;
  61.  
  62. usercmd->viewangles.pitch = GetPitch();
  63.  
  64. if (!Global::bSendPacket)
  65. usercmd->viewangles.yaw = GetYaw();
  66. else
  67. usercmd->viewangles.yaw = GetFakeYaw();
  68. }
  69.  
  70. float AntiAim::GetPitch()
  71. {
  72. switch (g_Options.hvh_antiaim_x)
  73. {
  74. case AA_PITCH_OFF:
  75.  
  76. return usercmd->viewangles.pitch;
  77. break;
  78.  
  79. case AA_PITCH_DYNAMIC:
  80.  
  81. return g_LocalPlayer->m_hActiveWeapon().Get()->IsSniper() ? (g_LocalPlayer->m_hActiveWeapon().Get()->m_zoomLevel() != 0 ? 87.f : 85.f) : 88.99f;
  82. break;
  83.  
  84. case AA_PITCH_EMOTION:
  85.  
  86. return 88.99f;
  87. break;
  88.  
  89. case AA_PITCH_STRAIGHT:
  90.  
  91. return 0.f;
  92. break;
  93.  
  94. case AA_PITCH_UP:
  95.  
  96. return -88.99f;
  97. break;
  98. }
  99.  
  100. return usercmd->viewangles.pitch;
  101. }
  102.  
  103. float AntiAim::GetYaw()
  104. {
  105. static bool flip = false;
  106. flip = !flip;
  107.  
  108. if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_left_bind)) { Global::left = true; Global::right = false; Global::backwards = false; }
  109. else if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_right_bind)) { Global::left = false; Global::right = true; Global::backwards = false; }
  110. else if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_back_bind)) { Global::left = false; Global::right = false; Global::backwards = true; }
  111.  
  112. float_t pos = usercmd->viewangles.yaw;
  113. float_t desync_pos_left = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_left;
  114. float_t desync_pos_right = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_right;
  115. float_t desync_pos_back = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_back;
  116.  
  117. if (g_LocalPlayer->m_vecVelocity().Length2D() > g_Options.hvh_antiaim_y_move_trigger_speed && g_Options.hvh_antiaim_y_move != 0)
  118. {
  119. switch (g_Options.hvh_antiaim_y_move)
  120. {
  121. case 1:
  122.  
  123. return pos + 180.0f;
  124. break;
  125.  
  126. case 2:
  127.  
  128. return pos + 180.0f + Utils::RandomFloat(-25.5f, 25.5f);
  129.  
  130. break;
  131.  
  132. case 3:
  133.  
  134.  
  135. if (Global::left) // Global::left real
  136. return pos + 90.f;
  137.  
  138. else if (Global::right) // Global::right real
  139. return pos - 90.f;
  140.  
  141. else if (Global::backwards) // Global::backwards
  142. return pos + 180.f;
  143. break;
  144.  
  145. case 4:
  146.  
  147. if (Global::left)
  148. return pos + (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  149.  
  150. else if (Global::right)
  151. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  152.  
  153. else if (Global::backwards)
  154. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  155.  
  156. break;
  157. case 5:
  158.  
  159. if (Global::left)
  160. return pos + g_Options.hvh_antiaim_y_custom_realmove_left;
  161.  
  162. else if (Global::right)
  163. return pos + g_Options.hvh_antiaim_y_custom_realmove_right;
  164.  
  165. else if (Global::backwards)
  166. return pos + g_Options.hvh_antiaim_y_custom_realmove_back;
  167.  
  168. break;
  169. case 6:
  170.  
  171. if (Global::left)
  172. return pos + g_Options.hvh_antiaim_y_custom_realmove_left + (Utils::RandomFloat(-25.5f, 25.5f));
  173.  
  174. else if (Global::right)
  175. return pos + g_Options.hvh_antiaim_y_custom_realmove_right + (Utils::RandomFloat(-25.5f, 25.5f));
  176.  
  177. else if (Global::backwards)
  178. return pos + g_Options.hvh_antiaim_y_custom_realmove_back + (Utils::RandomFloat(-25.5f, 25.5f));
  179. break;
  180. }
  181. return pos;
  182. }
  183. else
  184. {
  185. switch (g_Options.hvh_antiaim_y)
  186. {
  187. case 1:
  188.  
  189. return pos + 180.0f;
  190. break;
  191.  
  192. case 2:
  193.  
  194. return pos + 180.0f + Utils::RandomFloat(-25.5f, 25.5f);
  195.  
  196. break;
  197.  
  198. case 3:
  199.  
  200.  
  201. if (Global::left) // Global::left real
  202. return pos + 90.f;
  203.  
  204. else if (Global::right) // Global::right real
  205. return pos - 90.f;
  206.  
  207. else if (Global::backwards) // Global::backwards
  208. return pos + 180.f;
  209. break;
  210.  
  211. case 4:
  212.  
  213. if (Global::left)
  214. return pos + (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  215.  
  216. else if (Global::right)
  217. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  218.  
  219. else if (Global::backwards)
  220. return pos - (180.f + Utils::RandomFloat(-25.5f, 25.5f));
  221.  
  222. break;
  223. case 5:
  224.  
  225. if (Global::left)
  226. return pos + g_Options.hvh_antiaim_y_custom_left;
  227.  
  228. else if (Global::right)
  229. return pos + g_Options.hvh_antiaim_y_custom_right;
  230.  
  231. else if (Global::backwards)
  232. return pos + g_Options.hvh_antiaim_y_custom_back;
  233.  
  234. break;
  235. case 6:
  236.  
  237. if (Global::left)
  238. return pos + g_Options.hvh_antiaim_y_custom_left + (Utils::RandomFloat(-25.5f, 25.5f));
  239.  
  240. else if (Global::right)
  241. return pos + g_Options.hvh_antiaim_y_custom_right + (Utils::RandomFloat(-25.5f, 25.5f));
  242.  
  243. else if (Global::backwards)
  244. return pos + g_Options.hvh_antiaim_y_custom_back + (Utils::RandomFloat(-25.5f, 25.5f));
  245.  
  246. break;
  247. case 7:
  248.  
  249. if (Global::left)
  250. return desync_pos_left;
  251. if (Global::right)
  252. return desync_pos_right;
  253. if (Global::backwards)
  254. return desync_pos_back;
  255. break;
  256. case 8:
  257.  
  258. if (Global::left)
  259. return desync_pos_left + (Utils::RandomFloat(-25.5f, 25.5f));
  260. if (Global::right)
  261. return desync_pos_right + (Utils::RandomFloat(-25.5f, 25.5f));
  262. if (Global::backwards)
  263. return desync_pos_back + (Utils::RandomFloat(-25.5f, 25.5f));
  264. break;
  265. }
  266. return pos;
  267. }
  268. }
  269.  
  270. float AntiAim::GetFakeYaw()
  271. {
  272. static bool flip = false;
  273. flip = !flip;
  274.  
  275. if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_left_bind)) { Global::left = true; Global::right = false; Global::backwards = false; }
  276. else if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_right_bind)) { Global::left = false; Global::right = true; Global::backwards = false; }
  277. else if (g_InputSystem->IsButtonDown(g_Options.hvh_aa_back_bind)) { Global::left = false; Global::right = false; Global::backwards = true; }
  278.  
  279. float_t pos = usercmd->viewangles.yaw;
  280. float_t desync_pos_left = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_left;
  281. float_t desync_pos_right = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_right;
  282. float_t desync_pos_back = usercmd->viewangles.yaw += g_Options.hvh_antiaim_y_desync_start_back;
  283. if (g_LocalPlayer->m_vecVelocity().Length2D() > g_Options.hvh_antiaim_y_move_trigger_speed && g_Options.hvh_antiaim_y_move != 0)
  284. {
  285. switch (g_Options.hvh_antiaim_y_move)
  286. {
  287. case 1:
  288.  
  289. return pos + 180.0f;
  290. break;
  291.  
  292. case 2:
  293.  
  294. return pos + 180.0f + Utils::RandomFloat(-25.5f, 25.5f);
  295.  
  296. break;
  297.  
  298. case 3:
  299.  
  300.  
  301. if (Global::left) // Global::left real
  302. return pos + 90.f;
  303.  
  304. else if (Global::right) // Global::right real
  305. return pos - 90.f;
  306.  
  307. else if (Global::backwards) // Global::backwards
  308. return pos + 180.f;
  309. break;
  310.  
  311. case 4:
  312.  
  313. if (Global::left)
  314. return pos + (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  315.  
  316. else if (Global::right)
  317. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  318.  
  319. else if (Global::backwards)
  320. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  321.  
  322. break;
  323. case 5:
  324.  
  325. if (Global::left)
  326. return pos + g_Options.hvh_antiaim_y_custom_realmove_left;
  327.  
  328. else if (Global::right)
  329. return pos + g_Options.hvh_antiaim_y_custom_realmove_right;
  330.  
  331. else if (Global::backwards)
  332. return pos + g_Options.hvh_antiaim_y_custom_realmove_back;
  333.  
  334. break;
  335. case 6:
  336.  
  337. if (Global::left)
  338. return pos + g_Options.hvh_antiaim_y_custom_realmove_left + (Utils::RandomFloat(-25.5f, 25.5f));
  339.  
  340. else if (Global::right)
  341. return pos + g_Options.hvh_antiaim_y_custom_realmove_right + (Utils::RandomFloat(-25.5f, 25.5f));
  342.  
  343. else if (Global::backwards)
  344. return pos + g_Options.hvh_antiaim_y_custom_realmove_back + (Utils::RandomFloat(-25.5f, 25.5f));
  345. break;
  346. }
  347. return pos;
  348. }
  349. else
  350. {
  351. switch (g_Options.hvh_antiaim_y)
  352. {
  353. case 1:
  354.  
  355. return pos + 180.0f;
  356. break;
  357.  
  358. case 2:
  359.  
  360. return pos + 180.0f + Utils::RandomFloat(-25.5f, 25.5f);
  361.  
  362. break;
  363.  
  364. case 3:
  365.  
  366.  
  367. if (Global::left) // Global::left real
  368. return pos + 90.f;
  369.  
  370. else if (Global::right) // Global::right real
  371. return pos - 90.f;
  372.  
  373. else if (Global::backwards) // Global::backwards
  374. return pos + 180.f;
  375. break;
  376.  
  377. case 4:
  378.  
  379. if (Global::left)
  380. return pos + (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  381.  
  382. else if (Global::right)
  383. return pos - (90.f + Utils::RandomFloat(-25.5f, 25.5f));
  384.  
  385. else if (Global::backwards)
  386. return pos - (180.f + Utils::RandomFloat(-25.5f, 25.5f));
  387.  
  388. break;
  389. case 5:
  390.  
  391. if (Global::left)
  392. return pos + g_Options.hvh_antiaim_y_custom_left;
  393.  
  394. else if (Global::right)
  395. return pos + g_Options.hvh_antiaim_y_custom_right;
  396.  
  397. else if (Global::backwards)
  398. return pos + g_Options.hvh_antiaim_y_custom_back;
  399.  
  400. break;
  401. case 6:
  402.  
  403. if (Global::left)
  404. return pos + g_Options.hvh_antiaim_y_custom_left + (Utils::RandomFloat(-25.5f, 25.5f));
  405.  
  406. else if (Global::right)
  407. return pos + g_Options.hvh_antiaim_y_custom_right + (Utils::RandomFloat(-25.5f, 25.5f));
  408.  
  409. else if (Global::backwards)
  410. return pos + g_Options.hvh_antiaim_y_custom_back + (Utils::RandomFloat(-25.5f, 25.5f));
  411.  
  412. break;
  413. case 7:
  414. if (Global::left)
  415. return flip ? desync_pos_left + g_Options.hvh_antiaim_y_desync : desync_pos_left - g_Options.hvh_antiaim_y_desync;
  416. if (Global::right)
  417. return flip ? desync_pos_right + g_Options.hvh_antiaim_y_desync : desync_pos_right - g_Options.hvh_antiaim_y_desync;
  418. if (Global::backwards)
  419. return flip ? desync_pos_back + g_Options.hvh_antiaim_y_desync : desync_pos_back - g_Options.hvh_antiaim_y_desync;
  420. break;
  421. case 8:
  422. if (Global::left)
  423. return flip ? desync_pos_left + g_Options.hvh_antiaim_y_desync : desync_pos_left - g_Options.hvh_antiaim_y_desync;
  424. if (Global::right)
  425. return flip ? desync_pos_right + g_Options.hvh_antiaim_y_desync : desync_pos_right - g_Options.hvh_antiaim_y_desync;
  426. if (Global::backwards)
  427. return flip ? desync_pos_back + g_Options.hvh_antiaim_y_desync : desync_pos_back - g_Options.hvh_antiaim_y_desync;
  428. break;
  429. }
  430. return pos;
  431. }
  432. }
  433.  
  434. void AntiAim::Accelerate(C_BasePlayer *player, Vector &wishdir, float wishspeed, float accel, Vector &outVel)
  435. {
  436. // See if we are changing direction a bit
  437. float currentspeed = outVel.Dot(wishdir);
  438.  
  439. // Reduce wishspeed by the amount of veer.
  440. float addspeed = wishspeed - currentspeed;
  441.  
  442. // If not going to add any speed, done.
  443. if (addspeed <= 0)
  444. return;
  445.  
  446. // Determine amount of accleration.
  447. float accelspeed = accel * g_GlobalVars->frametime * wishspeed * player->m_surfaceFriction();
  448.  
  449. // Cap at addspeed
  450. if (accelspeed > addspeed)
  451. accelspeed = addspeed;
  452.  
  453. // Adjust velocity.
  454. for (int i = 0; i < 3; i++)
  455. outVel[i] += accelspeed * wishdir[i];
  456. }
  457.  
  458. void AntiAim::WalkMove(C_BasePlayer *player, Vector &outVel)
  459. {
  460. Vector forward, right, up, wishvel, wishdir, dest;
  461. float_t fmove, smove, wishspeed;
  462.  
  463. Math::AngleVectors(player->m_angEyeAngles(), forward, right, up); // Determine movement angles
  464. // Copy movement amounts
  465. g_MoveHelper->SetHost(player);
  466. fmove = g_MoveHelper->m_flForwardMove;
  467. smove = g_MoveHelper->m_flSideMove;
  468. g_MoveHelper->SetHost(nullptr);
  469.  
  470. if (forward[2] != 0)
  471. {
  472. forward[2] = 0;
  473. Math::NormalizeVector(forward);
  474. }
  475.  
  476. if (right[2] != 0)
  477. {
  478. right[2] = 0;
  479. Math::NormalizeVector(right);
  480. }
  481.  
  482. for (int i = 0; i < 2; i++) // Determine x and y parts of velocity
  483. wishvel[i] = forward[i] * fmove + right[i] * smove;
  484.  
  485. wishvel[2] = 0; // Zero out z part of velocity
  486.  
  487. wishdir = wishvel; // Determine maginitude of speed of move
  488. wishspeed = wishdir.Normalize();
  489.  
  490. // Clamp to server defined max speed
  491. g_MoveHelper->SetHost(player);
  492. if ((wishspeed != 0.0f) && (wishspeed > g_MoveHelper->m_flMaxSpeed))
  493. {
  494. VectorMultiply(wishvel, player->m_flMaxspeed() / wishspeed, wishvel);
  495. wishspeed = player->m_flMaxspeed();
  496. }
  497. g_MoveHelper->SetHost(nullptr);
  498. // Set pmove velocity
  499. outVel[2] = 0;
  500. Accelerate(player, wishdir, wishspeed, g_CVar->FindVar("sv_accelerate")->GetFloat(), outVel);
  501. outVel[2] = 0;
  502.  
  503. // Add in any base velocity to the current velocity.
  504. VectorAdd(outVel, player->m_vecBaseVelocity(), outVel);
  505.  
  506. float spd = outVel.Length();
  507.  
  508. if (spd < 1.0f)
  509. {
  510. outVel.Init();
  511. // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?)
  512. VectorSubtract(outVel, player->m_vecBaseVelocity(), outVel);
  513. return;
  514. }
  515.  
  516. g_MoveHelper->SetHost(player);
  517. g_MoveHelper->m_outWishVel += wishdir * wishspeed;
  518. g_MoveHelper->SetHost(nullptr);
  519.  
  520. // Don't walk up stairs if not on ground.
  521. if (!(player->m_fFlags() & FL_ONGROUND))
  522. {
  523. // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?)
  524. VectorSubtract(outVel, player->m_vecBaseVelocity(), outVel);
  525. return;
  526. }
  527.  
  528. // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?)
  529. VectorSubtract(outVel, player->m_vecBaseVelocity(), outVel);
  530. }
  531.  
  532. void AntiAim::Fakewalk(CUserCmd *usercmd)
  533. {
  534. if (!g_LocalPlayer->IsAlive())
  535. return;
  536.  
  537. if (!g_InputSystem->IsButtonDown(g_Options.misc_fakewalk_bind))
  538. return;
  539.  
  540. Vector velocity = Global::vecUnpredictedVel;
  541. float_t speed = velocity.Length();
  542.  
  543. if (speed > g_Options.misc_fakewalk_speed)
  544. {
  545. QAngle direction;
  546. Math::VectorAngles(velocity, direction);
  547.  
  548. direction.yaw = usercmd->viewangles.yaw - direction.yaw;
  549.  
  550. Vector forward;
  551. Math::AngleVectors(direction, forward);
  552.  
  553. int divider = g_Options.misc_fakewalk_speed / speed;
  554. Vector slowedDirection = forward * divider * speed;
  555. usercmd->forwardmove = slowedDirection.x;
  556. usercmd->sidemove = slowedDirection.y;
  557. }
  558. }
  559.  
  560. void AntiAim::Friction(Vector &outVel)
  561. {
  562. float speed, newspeed, control;
  563. float friction;
  564. float drop;
  565.  
  566. speed = outVel.Length();
  567.  
  568. if (speed <= 0.1f)
  569. return;
  570.  
  571. drop = 0;
  572.  
  573. // apply ground friction
  574. if (g_LocalPlayer->m_fFlags() & FL_ONGROUND)
  575. {
  576. friction = g_CVar->FindVar("sv_friction")->GetFloat() * g_LocalPlayer->m_surfaceFriction();
  577.  
  578. // Bleed off some speed, but if we have less than the bleed
  579. // threshold, bleed the threshold amount.
  580. control = (speed < g_CVar->FindVar("sv_stopspeed")->GetFloat()) ? g_CVar->FindVar("sv_stopspeed")->GetFloat() : speed;
  581.  
  582. // Add the amount to the drop amount.
  583. drop += control * friction * g_GlobalVars->frametime;
  584. }
  585.  
  586. newspeed = speed - drop;
  587. if (newspeed < 0)
  588. newspeed = 0;
  589.  
  590. if (newspeed != speed)
  591. {
  592. // Determine proportion of old speed we are using.
  593. newspeed /= speed;
  594. // Adjust velocity according to proportion.
  595. VectorMultiply(outVel, newspeed, outVel);
  596. }
  597. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement