Advertisement
Guest User

time based backtrack

a guest
Jan 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. LagComp.cpp
  2.  
  3. #include "LagComp.h"
  4. using namespace SDK;
  5. void BackTrack::Update(int tick_count)
  6. {
  7. latest_tick = tick_count;
  8. for (int i = 0; i < 64; i++)
  9. {
  10. UpdateRecord(i);
  11. }
  12. }
  13.  
  14. int BackTrack::BacktrackTicks()
  15. {
  16. // Gets server tickrate
  17. float timepertick = Interfaces::GlobalVars()->interval_per_tick;
  18. if (timepertick == 0) timepertick += 0.001; // prevents game from crashing when unconnected
  19. float tickrate = 1 / timepertick;
  20.  
  21. // actual b1g calculations yay
  22. int BacktrackTicks = Settings::Aimbot::aim_Backtracktime / 200 * tickrate; // slider from 1-200ms
  23. if (BacktrackTicks < 1) return 1; //prevents crash, thank me l8r
  24. else return BacktrackTicks;
  25. }
  26.  
  27. bool BackTrack::IsTickValid(int tick)
  28. {
  29. int delta = latest_tick - tick;
  30. float deltaTime = delta * Interfaces::GlobalVars()->interval_per_tick;
  31. return (fabs(deltaTime) <= 0.2f); // edited, come back to this overtime.
  32. }
  33.  
  34. void BackTrack::UpdateRecord(int i)
  35. {
  36. CBaseEntity* pEntity = (CBaseEntity*)Interfaces::EntityList()->GetClientEntity(i);
  37. if (pEntity && !pEntity->IsDead() && !pEntity->IsDormant())
  38. {
  39. float lby = pEntity->GetLowerBodyYaw();
  40. if (lby != records[i].lby)
  41. {
  42. records[i].tick_count = latest_tick;
  43. records[i].lby = lby;
  44. records[i].headPosition = pEntity->GetHitboxPosition(0);
  45. }
  46. }
  47. else
  48. {
  49. records[i].tick_count = 0;
  50. }
  51. }
  52.  
  53. bool BackTrack::RunLBYBackTrack(int i, CUserCmd* cmd, Vector& aimPoint)
  54. {
  55. if (IsTickValid(records[i].tick_count))
  56. {
  57. aimPoint = records[i].headPosition;
  58. cmd->tick_count = records[i].tick_count;
  59. return true;
  60. }
  61. return false;
  62. }
  63.  
  64. void BackTrack::legitBackTrack(CUserCmd* cmd)
  65. {
  66. if (Settings::Aimbot::aim_Backtrack)
  67. {
  68. int bestTargetIndex = -1;
  69. float bestFov = FLT_MAX;
  70. CBaseEntity* pLocal = (CBaseEntity*)Interfaces::EntityList()->GetClientEntity(Interfaces::Engine()->GetLocalPlayer());
  71. PlayerInfo info;
  72. if (pLocal->IsDead())
  73. return;
  74.  
  75. for (int i = 0; i < Interfaces::Engine()->GetMaxClients(); i++)
  76. {
  77. auto entity = (CBaseEntity*)Interfaces::EntityList()->GetClientEntity(i);
  78.  
  79. if (!entity || !pLocal)
  80. continue;
  81.  
  82. if (entity == pLocal)
  83. continue;
  84.  
  85. if (!Interfaces::Engine()->GetPlayerInfo(i, &info))
  86. continue;
  87.  
  88. if (entity->IsDormant())
  89. continue;
  90.  
  91. if (entity->GetTeam() == pLocal->GetTeam())
  92. continue;
  93.  
  94. if (!entity->IsDead())
  95. {
  96.  
  97. float simtime = entity->GetSimTime();
  98. Vector hitboxPos = entity->GetHitboxPosition(0);
  99.  
  100. headPositions[i][cmd->command_number % BacktrackTicks()] = backtrackData{ simtime, hitboxPos };
  101. Vector ViewDir = angle_vector(cmd->viewangles + (pLocal->GetAimPunchAngle() * 2.f));
  102. float FOVDistance = distance_point_to_line(hitboxPos, pLocal->GetEyePosition(), ViewDir);
  103.  
  104. if (bestFov > FOVDistance)
  105. {
  106. bestFov = FOVDistance;
  107. bestTargetIndex = i;
  108. }
  109. }
  110. }
  111.  
  112. float bestTargetSimTime;
  113. if (bestTargetIndex != -1)
  114. {
  115. float tempFloat = FLT_MAX;
  116. Vector ViewDir = angle_vector(cmd->viewangles + (pLocal->GetAimPunchAngle() * 2.f));
  117. for (int t = 0; t < BacktrackTicks(); ++t)
  118. {
  119. float tempFOVDistance = distance_point_to_line(headPositions[bestTargetIndex][t].hitboxPos, pLocal->GetEyePosition(), ViewDir);
  120. if (tempFloat > tempFOVDistance && headPositions[bestTargetIndex][t].simtime > pLocal->GetSimTime() - 1)
  121. {
  122. tempFloat = tempFOVDistance;
  123. bestTargetSimTime = headPositions[bestTargetIndex][t].simtime;
  124. }
  125. }
  126.  
  127. cmd->tick_count = TIME_TO_TICKS(bestTargetSimTime);
  128. }
  129. }
  130. }
  131.  
  132. BackTrack* backtracking = new BackTrack();
  133. backtrackData headPositions[64][25]; //support for 128tick servers
  134.  
  135.  
  136.  
  137.  
  138.  
  139. LagComp.h
  140.  
  141.  
  142. #pragma once
  143. #include "../../Engine/Engine.h"
  144.  
  145. #define PI 3.14159265358979323846f
  146. #define MAXBACKTRACKTICKS ((int)Settings::Aimbot::aim_Backtracktime)
  147. #define TICK_INTERVAL (Interfaces::GlobalVars()->interval_per_tick)
  148. #define TIME_TO_TICKS( dt ) ( (int)( 0.5f + (float)(dt) / TICK_INTERVAL ) )
  149.  
  150.  
  151. inline Vector angle_vector(Vector meme)
  152. {
  153. auto sy = sin(meme.y / 180.f * static_cast<float>(PI));
  154. auto cy = cos(meme.y / 180.f * static_cast<float>(PI));
  155.  
  156. auto sp = sin(meme.x / 180.f * static_cast<float>(PI));
  157. auto cp = cos(meme.x / 180.f* static_cast<float>(PI));
  158.  
  159. return Vector(cp*cy, cp*sy, -sp);
  160. }
  161. inline float distance_point_to_line(Vector Point, Vector LineOrigin, Vector Dir)
  162. {
  163. auto PointDir = Point - LineOrigin;
  164.  
  165. auto TempOffset = PointDir.Dot(Dir) / (Dir.x*Dir.x + Dir.y*Dir.y + Dir.z*Dir.z);
  166. if (TempOffset < 0.000001f)
  167. return FLT_MAX;
  168.  
  169. auto PerpendicularPoint = LineOrigin + (Dir * TempOffset);
  170.  
  171. return (Point - PerpendicularPoint).Length();
  172. }
  173.  
  174. namespace SDK
  175. {
  176. struct lbyRecords
  177. {
  178. int tick_count;
  179. float lby;
  180. Vector headPosition;
  181. };
  182.  
  183. struct backtrackData
  184. {
  185. float simtime;
  186. Vector hitboxPos;
  187. };
  188.  
  189. class BackTrack
  190. {
  191. int latest_tick;
  192. bool IsTickValid(int tick);
  193. void UpdateRecord(int i);
  194. public:
  195. lbyRecords records[64];
  196. bool RunLBYBackTrack(int i, CUserCmd* cmd, Vector& aimPoint);
  197. void legitBackTrack(CUserCmd * cmd);
  198. void Update(int tick_count);
  199. int BacktrackTicks();
  200. };
  201. }
  202.  
  203. extern backtrackData headPositions[64][25]; //same
  204.  
  205. extern BackTrack* backtracking;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement