Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "../pch.h"
- #include "Client.h"
- #include "Menu.h"
- #include "Interfaces.hpp"
- #include <list>
- void Client::for_every_listitem(std::list<int>& list, const std::function<bool(BaseEntity* pl)>& func)
- {
- if (m_bListReadProtection)
- return;
- m_bListWriteProtection = true;
- for (auto i : list)
- {
- BaseEntity* ent = reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(i));
- if (!ent) continue;
- if (ent->IsDormant()) continue;
- if (!func(ent))
- return;
- if (m_bListReadProtection)
- break;
- }
- m_bListWriteProtection = false;
- }
- bool Client::Initialize()
- {
- m_bListReadProtection = true;
- return getLocalPlayer();
- }
- void Client::Shutdown()
- {
- cout << endl << "[i] Client::Shutdown()" << endl;
- m_list_mateIndex.clear();
- m_list_enemyIndex.clear();
- m_list_specIndex.clear();
- m_list_chickenIndex.clear();
- m_list_grenadeIndex.clear();
- m_bombIndex = -1;
- p_localPlayer = nullptr;
- }
- bool Client::getLocalPlayer()
- {
- auto localPlayerIndex = g_EngineClient->GetLocalPlayer();
- auto localPlayer = g_EntityList->GetClientEntity(localPlayerIndex);
- if (!localPlayer)
- return false;
- p_localPlayer = reinterpret_cast<BaseEntity*>(localPlayer);
- return true;
- }
- BaseEntity* Client::getBomb()
- {
- return (m_bombIndex == -1) ? NULL : reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(m_bombIndex));
- }
- void Client::for_every_player(const function<bool(BaseEntity* ent)>& func)
- {
- for_every_listitem(m_list_mateIndex, func);
- for_every_listitem(m_list_enemyIndex, func);
- for_every_listitem(m_list_specIndex, func);
- }
- void Client::for_every_mate(const std::function<bool(BaseEntity* ent)>& func)
- {
- for_every_listitem(m_list_mateIndex, func);
- }
- void Client::for_every_enemy(const std::function<bool(BaseEntity* ent)>& func)
- {
- for_every_listitem(m_list_enemyIndex, func);
- }
- void Client::for_every_chicken(const std::function<bool(BaseEntity* ent)>& func)
- {
- for_every_listitem(m_list_chickenIndex, func);
- }
- void Client::for_every_grenade(const std::function<bool(BaseEntity* ent)>& func)
- {
- for_every_listitem(m_list_grenadeIndex, func);
- }
- void Client::Update()
- {
- m_bListReadProtection = true;
- while (m_bListWriteProtection)
- {
- }
- m_list_mateIndex.clear();
- m_list_enemyIndex.clear();
- m_list_specIndex.clear();
- m_list_chickenIndex.clear();
- m_list_grenadeIndex.clear();
- m_bombIndex = -1;
- for (auto i = 0; i < g_EntityList->GetHighestEntityIndex(); ++i)
- {
- auto ent = reinterpret_cast<BaseEntity*>(g_EntityList->GetClientEntity(i));
- if (!ent)
- continue;
- switch (ent->GetClientClass()->m_ClassID)
- {
- case (ClassId_CCSPlayer):
- if (ent == p_localPlayer || ent->IsDormant())
- break;
- if (ent->m_iTeamNum() == 0)
- m_list_specIndex.push_back(i);
- else if (ent->m_iTeamNum() == p_localPlayer->m_iTeamNum())
- m_list_mateIndex.push_back(i);
- else
- m_list_enemyIndex.push_back(i);
- break;
- case (ClassId_CC4):
- case (ClassId_CPlantedC4):
- m_bombIndex = i;
- break;
- case (ClassId_CChicken):
- m_list_chickenIndex.push_back(i);
- break;
- case (ClassId_CBaseCSGrenadeProjectile):
- case (ClassId_CDecoyProjectile):
- case (ClassId_CMolotovProjectile):
- case (ClassId_CSmokeGrenadeProjectile):
- m_list_grenadeIndex.push_back(i);
- break;
- }
- }
- m_bListReadProtection = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement