Advertisement
Guest User

Untitled

a guest
Jul 6th, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "../FEATURES/Hitmarker.h"
  4. #include "../includes.h"
  5. #include "../UTILS/INTERFACES.h"
  6. #include "../SDK/CClientEntityList.h"
  7. #include "../SDK/IEngine.h"
  8. #include "../SDK/CBaseEntity.h"
  9. #include "../SDK/CGlobalVars.h"
  10. #include "../SDK/CBaseWeapon.h"
  11. #include "../SDK/ISurface.h"
  12. #include "../SDK/ConVar.h"
  13. #include "../FEATURES/Backtracking.h"
  14. #include "../FEATURES/Resolver.h"
  15. #include "../FEATURES/Visuals.h"
  16. #include "../UTILS\render.h"
  17. #include <ctime>
  18. #include <chrono>
  19.  
  20. Hitmarker* pHitmarker = new Hitmarker();
  21.  
  22. int64 GetEpochMS() {
  23. int64 now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  24. return now;
  25. }
  26.  
  27. void Hitmarker::Initialize() {
  28.  
  29. INTERFACES::GameEventManager->AddListener(this, "player_hurt", false);
  30. INTERFACES::GameEventManager->AddListener(this, "bullet_impact", false);
  31. }
  32.  
  33. SDK::CBaseEntity* Hitmarker::GetPlayer(int userid) {
  34.  
  35. int index = INTERFACES::Engine->GetPlayerForUserID(userid);
  36. return INTERFACES::ClientEntityList->GetClientEntity(index);
  37. }
  38.  
  39. void Hitmarker::Paint() {
  40.  
  41. auto pLocal = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
  42.  
  43. if (SETTINGS::settings.aw_hitmarker != 2)
  44. return;
  45.  
  46. if (!INTERFACES::Engine->IsConnected() || !INTERFACES::Engine->IsInGame() || !pLocal) {
  47.  
  48. if (!pImpacts.empty()) { pImpacts.clear(); }
  49.  
  50. if (!pHitmarkers.empty()) { pHitmarkers.clear(); }
  51.  
  52. return;
  53. }
  54.  
  55. long long pTime = GetEpochMS();
  56.  
  57. std::vector<pHitmarkerInfo>::iterator pIter;
  58.  
  59. for (pIter = pHitmarkers.begin(); pIter != pHitmarkers.end(); ) {
  60.  
  61. bool pExpired = pTime > pIter->pImpact.time + 2000;
  62. static int pAlphaInterval = 255 / 50;
  63.  
  64. if (pExpired)
  65. pIter -= pAlphaInterval;
  66.  
  67. if (pExpired && pIter->alpha <= 0) {
  68.  
  69. pIter = pHitmarkers.erase(pIter);
  70. continue;
  71. }
  72.  
  73. Vector pos3D = Vector(pIter->pImpact.x, pIter->pImpact.y, pIter->pImpact.z), pos2D;
  74.  
  75. if (!RENDER::WorldToScreen(pos3D, pos2D)) {
  76.  
  77. ++pIter;
  78. continue;
  79. }
  80.  
  81. CColor pWhite = CColor(255, 255, 255);
  82. pWhite.SetAlpha(pIter->alpha);
  83.  
  84. int pLineSize = 8;
  85.  
  86. INTERFACES::Surface->DrawSetColor(pWhite);
  87. INTERFACES::Surface->DrawLine(pos2D.x - pLineSize, pos2D.y - pLineSize, pos2D.x - (pLineSize / 4), pos2D.y - (pLineSize / 4));
  88. INTERFACES::Surface->DrawLine(pos2D.x - pLineSize, pos2D.y + pLineSize, pos2D.x - (pLineSize / 4), pos2D.y + (pLineSize / 4));
  89. INTERFACES::Surface->DrawLine(pos2D.x + pLineSize, pos2D.y - pLineSize, pos2D.x + (pLineSize / 4), pos2D.y - (pLineSize / 4));
  90. INTERFACES::Surface->DrawLine(pos2D.x + pLineSize, pos2D.y + pLineSize, pos2D.x + (pLineSize / 4), pos2D.y + (pLineSize / 4));
  91.  
  92. ++pIter;
  93. }
  94. }
  95.  
  96. void Hitmarker::FireGameEvent(SDK::IGameEvent* pEvent) {
  97.  
  98. auto pLocal = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
  99.  
  100. if (SETTINGS::settings.aw_hitmarker != 2)
  101. return;
  102.  
  103. if (!pEvent || !pLocal)
  104. return;
  105.  
  106. if (!strcmp(pEvent->GetName(), "player_hurt"))
  107. PlayerHurt(pEvent);
  108.  
  109. if (!strcmp(pEvent->GetName(), "bullet_impact"))
  110. BulletImpact(pEvent);
  111. }
  112.  
  113. int Hitmarker::GetEventDebugID(void) { return 0x2A; }
  114.  
  115. void Hitmarker::PlayerHurt(SDK::IGameEvent* pEvent) {
  116.  
  117. auto pLocal = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
  118.  
  119. SDK::CBaseEntity* pAttacker = GetPlayer(pEvent->GetInt("attacker"));
  120. SDK::CBaseEntity* pVictim = GetPlayer(pEvent->GetInt("userid"));
  121.  
  122. if (!pAttacker || !pVictim || pAttacker != pLocal)
  123. return;
  124.  
  125. Vector pEnemyPos = pVictim->GetEyeAngles();
  126. pImpactInfo pBestImpact;
  127.  
  128. float pBestImpactDistance = -1;
  129. long long pTime = GetEpochMS();
  130.  
  131. std::vector<pImpactInfo>::iterator pIter;
  132.  
  133. for (pIter = pImpacts.begin(); pIter != pImpacts.end(); ) {
  134.  
  135. if (pTime > pIter->time + 25) {
  136.  
  137. pIter = pImpacts.erase(pIter);
  138. continue;
  139. }
  140.  
  141. Vector Position = Vector(pIter->x, pIter->y, pIter->z);
  142.  
  143. float pDistance = Position.DistTo(pEnemyPos);
  144.  
  145. if (pDistance < pBestImpactDistance || pBestImpactDistance == -1) {
  146.  
  147. pBestImpactDistance = pDistance;
  148. pBestImpact = *pIter;
  149. }
  150. pIter++;
  151. }
  152.  
  153. if (pBestImpactDistance == -1)
  154. return;
  155.  
  156. pHitmarkerInfo pInfo;
  157. pInfo.pImpact = pBestImpact;
  158. pInfo.alpha = 255;
  159. pHitmarkers.push_back(pInfo);
  160. }
  161.  
  162. void Hitmarker::BulletImpact(SDK::IGameEvent* pEvent) {
  163.  
  164. auto pLocal = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
  165.  
  166. SDK::CBaseEntity* pShooter = GetPlayer(pEvent->GetInt("userid"));
  167.  
  168. if (!pShooter || pShooter != pLocal)
  169. return;
  170.  
  171. pImpactInfo pInfo;
  172. pInfo.x = pEvent->GetFloat("x");
  173. pInfo.y = pEvent->GetFloat("y");
  174. pInfo.z = pEvent->GetFloat("z");
  175. pInfo.time = GetEpochMS();
  176. pImpacts.push_back(pInfo);
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement