Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. #pragma once
  2. #include "options.hpp"
  3. #include "../CSGOSimple/valve_sdk/csgostructs.hpp"
  4. #include "../CSGOSimple/helpers/utils.hpp"
  5. #include "../CSGOSimple/helpers/math.hpp"
  6. #include <DirectXMath.h>
  7. #include "features\chams.hpp"
  8. #define MDRRRAD2DEG(x) DirectX::XMConvertToDegrees(x)
  9. #define MDRRDEG2RAD(x) DirectX::XMConvertToRadians(x)
  10. #define MDRRM_PI 3.14159265358979323846f
  11.  
  12. //math stuff
  13.  
  14. void inline MDRRSinCos(float radians, float* sine, float* cosine)
  15. {
  16. *sine = sin(radians);
  17. *cosine = cos(radians);
  18. }
  19.  
  20. void MDRRAngleVectors(const QAngle& angles, Vector* forward)
  21. {
  22. float sp, sy, cp, cy;
  23.  
  24. MDRRSinCos(MDRRDEG2RAD(angles.yaw), &sy, &cy);
  25. MDRRSinCos(MDRRDEG2RAD(angles.pitch), &sp, &cp);
  26.  
  27. forward->x = cp * cy;
  28. forward->y = cp * sy;
  29. forward->z = -sp;
  30. }
  31. float MDRRGetFov(const QAngle& viewAngle, const QAngle& aimAngle)
  32. {
  33. Vector ang, aim;
  34.  
  35. MDRRAngleVectors(viewAngle, &aim);
  36. MDRRAngleVectors(aimAngle, &ang);
  37.  
  38. return MDRRRAD2DEG(acos(aim.Dot(ang) / aim.LengthSqr()));
  39. }
  40. void MDRRVectorAngles(const Vector& forward, QAngle& angles)
  41. {
  42. if (forward[1] == 0.0f && forward[0] == 0.0f)
  43. {
  44. angles[0] = (forward[2] > 0.0f) ? 270.0f : 90.0f; // Pitch (up/down)
  45. angles[1] = 0.0f; //yaw left/right
  46. }
  47. else
  48. {
  49. angles[0] = atan2(-forward[2], forward.Length2D()) * -180 / MDRRM_PI;
  50. angles[1] = atan2(forward[1], forward[0]) * 180 / MDRRM_PI;
  51.  
  52. if (angles[1] > 90)
  53. angles[1] -= 180; //forcing angles
  54. else if (angles[1] < 90)
  55. angles[1] += 180; //the same
  56. else if (angles[1] == 90)
  57. angles[1] = 0; //same
  58. }
  59.  
  60. angles[2] = 0.0f;
  61. }
  62.  
  63. //calculation
  64.  
  65. QAngle MDRRCalcAngle(Vector src, Vector dst)
  66. {
  67. QAngle angles;
  68. Vector delta = src - dst;
  69. MDRRVectorAngles(delta, angles);
  70. delta.Normalized();
  71. return angles;
  72. }
  73.  
  74. //here the backtracking starts
  75.  
  76. struct BacktrackRecord
  77. {
  78. C_BasePlayer* entity;
  79. Vector head;
  80. Vector origin;
  81. };
  82.  
  83. struct BacktrackTick
  84. {
  85. int tickcount;
  86. std::vector<BacktrackRecord> records;
  87. };
  88.  
  89. class CBacktracking
  90. {
  91. std::vector<BacktrackTick> ticks;
  92. C_BasePlayer* entity;
  93. Vector prevOrig;
  94.  
  95. public:
  96. void RegisterTick(CUserCmd* cmd)
  97. {
  98. ticks.insert(ticks.begin(), BacktrackTick{ cmd->tick_count });
  99. auto& cur = ticks[0];
  100.  
  101. while (ticks.size() > g_Options.Backtracking_ticks)
  102. ticks.pop_back(); //lets pop them heads
  103.  
  104.  
  105.  
  106.  
  107. for (int i = 1; i < g_EngineClient->GetMaxClients(); i++)
  108. {
  109. auto entity = C_BasePlayer::GetPlayerByIndex(i);
  110. if (!entity ||
  111. entity->IsDormant() ||
  112. entity->m_iHealth() <= 0 ||
  113. entity->m_iTeamNum() == g_LocalPlayer->m_iTeamNum() ||
  114. entity->m_bGunGameImmunity())
  115. continue;
  116.  
  117. cur.records.emplace_back(BacktrackRecord{ entity, entity->GetBonePos(/* not found out how but add here the bone u wanna backtrack*/), entity->m_vecOrigin() });
  118. }
  119. }
  120.  
  121. void Begin(CUserCmd* cmd)
  122. {
  123. entity = nullptr;
  124.  
  125. float serverTime = g_LocalPlayer->m_nTickBase() * g_GlobalVars->interval_per_tick;
  126. auto weapon = g_LocalPlayer->m_hActiveWeapon();
  127. if (weapon) {
  128. if (cmd->buttons & IN_ATTACK && weapon->m_flNextPrimaryAttack() < serverTime + 0.001)
  129. {
  130. float fov = 170.5f;
  131. int tickcount = 0;
  132. bool hasTarget = false;
  133. Vector orig;
  134.  
  135. for (auto& tick : ticks)
  136. {
  137. for (auto& record : tick.records)
  138. {
  139. QAngle angle = MDRRCalcAngle(g_LocalPlayer->GetEyePos(), record.head);
  140. float tmpFOV = MDRRGetFov(cmd->viewangles, angle);
  141.  
  142. if (tmpFOV < fov)
  143. {
  144. fov = tmpFOV;
  145. tickcount = tick.tickcount;
  146. hasTarget = true;
  147. entity = record.entity;
  148. orig = record.origin;
  149.  
  150. static auto invalidateBoneCache = Utils::PatternScan(GetModuleHandleA("client.dll"), "80 3D ? ? ? ? ? 74 16 A1 ? ? ? ? 48 C7 81");
  151. unsigned long modelBoneCounter = **(unsigned long**)(invalidateBoneCache + 10);
  152. *(unsigned int*)((DWORD)entity + 0x2914) = 0xFF7FFFFF;
  153. *(unsigned int*)((DWORD)entity + 0x2680) = (modelBoneCounter - 1);
  154. }
  155. }
  156. }
  157.  
  158.  
  159. if (entity && hasTarget)
  160. {
  161. cmd->tick_count = tickcount;
  162. prevOrig = entity->m_vecOrigin();
  163. entity->m_vecOrigin() = orig;
  164. }
  165. }
  166. }
  167. }
  168. void End()
  169. {
  170. if (entity)
  171. entity->m_vecOrigin() = prevOrig;
  172.  
  173. entity = nullptr;
  174. }
  175. void Draw()
  176. {
  177. for (auto& tick : ticks)
  178. {
  179. for (auto& record : tick.records)
  180. {
  181. Vector screenPos;
  182. if (Math::WorldToScreen(record.head, screenPos))
  183. {
  184. g_VGuiSurface->DrawSetColor(63, 255, 223, 255);
  185. g_VGuiSurface->DrawFilledRect(screenPos.x, screenPos.y, screenPos.x + 2, screenPos.y + 1.5);
  186. // g_VGuiSurface->DrawOutlinedRect(screenPos.x, screenPos.y, screenPos.x + 3, screenPos.y + 45);
  187. // g_VGuiSurface->DrawOutlinedCircle(screenPos.x, screenPos.y, screenPos.x, screenPos.y);
  188. }
  189. }
  190. }
  191. }
  192. };
  193.  
  194. CBacktracking Backtracking;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement