Advertisement
Guest User

Client.cpp

a guest
Jul 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "../pch.h"
  4.  
  5. #include "Client.h"
  6. #include "Menu.h"
  7. #include "Interfaces.hpp"
  8.  
  9. #include <list>
  10.  
  11. void Client::for_every_listitem(std::list<int>& list, const std::function<bool(BaseEntity* pl)>& func)
  12. {
  13. if (m_bListReadProtection)
  14. return;
  15.  
  16. m_bListWriteProtection = true;
  17. for (auto i : list)
  18. {
  19. BaseEntity* ent = reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(i));
  20. if (!ent) continue;
  21.  
  22. if (ent->IsDormant()) continue;
  23.  
  24. if (!func(ent))
  25. return;
  26.  
  27. if (m_bListReadProtection)
  28. break;
  29. }
  30. m_bListWriteProtection = false;
  31. }
  32.  
  33. bool Client::Initialize()
  34. {
  35. m_bListReadProtection = true;
  36.  
  37. return getLocalPlayer();
  38. }
  39.  
  40. void Client::Shutdown()
  41. {
  42. cout << endl << "[i] Client::Shutdown()" << endl;
  43.  
  44. m_list_mateIndex.clear();
  45. m_list_enemyIndex.clear();
  46. m_list_specIndex.clear();
  47. m_list_chickenIndex.clear();
  48. m_list_grenadeIndex.clear();
  49. m_bombIndex = -1;
  50.  
  51. p_localPlayer = nullptr;
  52. }
  53.  
  54. bool Client::getLocalPlayer()
  55. {
  56. auto localPlayerIndex = g_EngineClient->GetLocalPlayer();
  57. auto localPlayer = g_EntityList->GetClientEntity(localPlayerIndex);
  58.  
  59. if (!localPlayer)
  60. return false;
  61.  
  62. p_localPlayer = reinterpret_cast<BaseEntity*>(localPlayer);
  63. return true;
  64. }
  65.  
  66. BaseEntity* Client::getBomb()
  67. {
  68. return (m_bombIndex == -1) ? NULL : reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(m_bombIndex));
  69. }
  70.  
  71. void Client::for_every_player(const function<bool(BaseEntity* ent)>& func)
  72. {
  73. for_every_listitem(m_list_mateIndex, func);
  74. for_every_listitem(m_list_enemyIndex, func);
  75. for_every_listitem(m_list_specIndex, func);
  76. }
  77.  
  78. void Client::for_every_mate(const std::function<bool(BaseEntity* ent)>& func)
  79. {
  80. for_every_listitem(m_list_mateIndex, func);
  81. }
  82.  
  83. void Client::for_every_enemy(const std::function<bool(BaseEntity* ent)>& func)
  84. {
  85. for_every_listitem(m_list_enemyIndex, func);
  86. }
  87.  
  88. void Client::for_every_chicken(const std::function<bool(BaseEntity* ent)>& func)
  89. {
  90. for_every_listitem(m_list_chickenIndex, func);
  91. }
  92.  
  93. void Client::for_every_grenade(const std::function<bool(BaseEntity* ent)>& func)
  94. {
  95. for_every_listitem(m_list_grenadeIndex, func);
  96. }
  97.  
  98. void Client::Update()
  99. {
  100. m_bListReadProtection = true;
  101.  
  102. while (m_bListWriteProtection)
  103. {
  104. }
  105.  
  106. m_list_mateIndex.clear();
  107. m_list_enemyIndex.clear();
  108. m_list_specIndex.clear();
  109. m_list_chickenIndex.clear();
  110. m_list_grenadeIndex.clear();
  111. m_bombIndex = -1;
  112.  
  113. for (auto i = 0; i < g_EntityList->GetHighestEntityIndex(); ++i)
  114. {
  115. auto ent = reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(i));
  116.  
  117. if (!ent)
  118. continue;
  119.  
  120. switch (ent->GetClientClass()->m_ClassID)
  121. {
  122. case (ClassId_CCSPlayer):
  123. if (ent == p_localPlayer || ent->IsDormant())
  124. break;
  125. if (ent->m_iTeamNum() == 0)
  126. m_list_specIndex.push_back(i);
  127. else if (ent->m_iTeamNum() == p_localPlayer->m_iTeamNum())
  128. m_list_mateIndex.push_back(i);
  129. else
  130. m_list_enemyIndex.push_back(i);
  131. break;
  132.  
  133. case (ClassId_CC4):
  134. case (ClassId_CPlantedC4):
  135. m_bombIndex = i;
  136. break;
  137.  
  138. case (ClassId_CChicken):
  139. m_list_chickenIndex.push_back(i);
  140. break;
  141.  
  142. case (ClassId_CBaseCSGrenadeProjectile):
  143. case (ClassId_CDecoyProjectile):
  144. case (ClassId_CMolotovProjectile):
  145. case (ClassId_CSmokeGrenadeProjectile):
  146. m_list_grenadeIndex.push_back(i);
  147. break;
  148. }
  149. }
  150. m_bListReadProtection = false;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement