diff --git a/.cproject b/.cproject index bf0bbc8a..355f8070 100644 --- a/.cproject +++ b/.cproject @@ -103,21 +103,10 @@ - - - - - - - - - - - @@ -171,7 +160,6 @@ - @@ -267,7 +255,6 @@ - @@ -361,7 +348,6 @@ - diff --git a/src/common.h b/src/common.h index d23e74f4..a47f1d21 100644 --- a/src/common.h +++ b/src/common.h @@ -10,7 +10,9 @@ #include "beforecheaders.h" #include - +#include +#include +#include #include "aftercheaders.h" #include "drawing.h" #include "entitycache.h" @@ -31,7 +33,6 @@ #include "prediction.h" #include "conditions.h" #include "itemtypes.h" -#include "ipc/ipcctl.h" #include "chatstack.h" #include "textfile.h" #include "gui/GUI.h" @@ -75,7 +76,6 @@ #else #define DEBUG_SEGV false #endif -#define NO_IPC true #define STR(c) #c #if DEBUG_SEGV == true diff --git a/src/drawing.cpp b/src/drawing.cpp index d873e5d2..85dc58da 100644 --- a/src/drawing.cpp +++ b/src/drawing.cpp @@ -8,77 +8,45 @@ #include "common.h" #include "sdk.h" -int g_nStringsSide = 0; -int g_nStringsCenter = 0; -ESPStringCompound* g_pStringsSide; -ESPStringCompound* g_pStringsCenter; +std::array side_strings; +std::array center_strings; +std::array side_strings_colors { 0 }; +std::array center_strings_colors { 0 }; +int side_strings_count { 0 }; +int center_strings_count { 0 }; void InitStrings() { - g_pStringsSide = new ESPStringCompound[32](); - g_pStringsCenter = new ESPStringCompound[32](); ResetStrings(); } void ResetStrings() { - g_nStringsSide = 0; - g_nStringsCenter = 0; + side_strings_count = 0; + center_strings_count = 0; } -void AddSideString(int fg, const char* fmt, ...) { - if (!g_pStringsSide) return; - if (g_pStringsSide[g_nStringsSide].m_String) { - delete g_pStringsSide[g_nStringsSide].m_String; - } - char* buffer = new char[1024](); - va_list list; - va_start(list, fmt); - vsprintf(buffer, fmt, list); - va_end(list); - if (g_nStringsSide >= 32) { - logging::Info("Can't attach more than %i strings to an entity", 32); - return; - } - g_pStringsSide[g_nStringsSide].m_nColor = fg; - g_pStringsSide[g_nStringsSide].m_String = buffer; - g_pStringsSide[g_nStringsSide].m_bColored = true; - g_nStringsSide++; +void AddSideString(const std::string& string, int color) { + side_strings[side_strings_count] = string; + side_strings_colors[side_strings_count] = color; + side_strings_count++; } void DrawStrings() { - int y = 8; - for (int i = 0; i < g_nStringsSide; i++) { - //draw::DrawString(8, y, g_pStringsSide[i].m_Color, g_pStringsSide[i].m_Background, false, g_pStringsSide[i].m_String); - draw::String(fonts::ESP, 8, y, g_pStringsSide[i].m_nColor, 2, g_pStringsSide[i].m_String); + int y { 8 }; + for (int i = 0; i < side_strings_count; i++) { + draw::String(fonts::ESP, 8, y, side_strings_colors[i], 2, side_strings[i]); y += 14; } y = draw::height / 2; - for (int i = 0; i < g_nStringsCenter; i++) { - draw::String(fonts::ESP, draw::width / 2, y, g_pStringsCenter[i].m_nColor, 2, g_pStringsCenter[i].m_String); + for (int i = 0; i < center_strings_count; i++) { + draw::String(fonts::ESP, draw::width / 2, y, center_strings_colors[i], 2, center_strings[i]); y += 14; } } -ESPStringCompound::~ESPStringCompound() { - //if (m_String) delete [] m_String; -} - -void AddCenterString(int fg, const char* fmt, ...) { - if (g_pStringsCenter[g_nStringsCenter].m_String) { - delete g_pStringsCenter[g_nStringsCenter].m_String; - } - char* buffer = new char[1024](); - va_list list; - va_start(list, fmt); - vsprintf(buffer, fmt, list); - va_end(list); - if (g_nStringsCenter >= 32) { - logging::Info("Can't attach more than %i strings to an entity", 32); - return; - } - g_pStringsCenter[g_nStringsCenter].m_nColor = fg; - g_pStringsCenter[g_nStringsCenter].m_String = buffer; - g_pStringsCenter[g_nStringsCenter].m_bColored = true; - g_nStringsCenter++; +void AddCenterString(const std::string& string, int color) { + center_strings[center_strings_count] = string; + center_strings_colors[center_strings_count] = color; + center_strings_count++; } @@ -256,12 +224,6 @@ void draw::DrawRect(int x, int y, int w, int h, int color) { g_ISurface->DrawFilledRect(x, y, x + w, y + h); } -ESPStringCompound::ESPStringCompound() { - m_String = nullptr; - m_bColored = false; - m_nColor = colors::white; -} - void draw::Initialize() { fonts::ESP = g_ISurface->CreateFont(); fonts::MENU = g_ISurface->CreateFont(); diff --git a/src/drawing.h b/src/drawing.h index cd063e32..91fb4de6 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -17,16 +17,6 @@ class CachedEntity; class Vector; class IClientEntity; -struct ESPStringCompound { - ESPStringCompound(); - ~ESPStringCompound(); - char* m_String; - bool m_bColored; - int m_nColor; - //Color m_Color; - //Color m_Background; -}; - namespace fonts { extern unsigned long ESP; @@ -67,16 +57,10 @@ int EntityF(CachedEntity* ent); void InitStrings(); void ResetStrings(); -void AddCenterString(int fg, const char* fmt, ...); -void AddSideString(int fg, const char* fmt, ...); +void AddCenterString(const std::string& string, int color = 0xFFFFFFFF); +void AddSideString(const std::string& string, int color = 0xFFFFFFFF); void DrawStrings(); -extern ESPStringCompound* g_pStringsSide; -extern int g_nStringsSide; -extern ESPStringCompound* g_pStringsCenter; -extern int g_nStringsCenter; - - namespace draw { extern int width; diff --git a/src/entitycache.cpp b/src/entitycache.cpp index d049ac24..97399f9c 100644 --- a/src/entitycache.cpp +++ b/src/entitycache.cpp @@ -13,8 +13,6 @@ CachedEntity::CachedEntity() { m_pEntity = nullptr; - m_Strings = new ESPStringCompound[MAX_STRINGS](); - m_nESPStrings = 0; m_Bones = 0; m_Bones = new matrix3x4_t[MAXSTUDIOBONES]; m_pHitboxCache = new EntityHitboxCache(this); @@ -23,7 +21,6 @@ CachedEntity::CachedEntity() { } CachedEntity::~CachedEntity() { - delete [] m_Strings; delete [] m_Bones; delete m_pHitboxCache; } @@ -40,8 +37,6 @@ void EntityCache::Invalidate() { void CachedEntity::Update(int idx) { SEGV_BEGIN - m_ESPOrigin.Zero(); - m_IDX = idx; m_pEntity = g_IEntityList->GetClientEntity(idx); if (!m_pEntity) { @@ -197,35 +192,6 @@ bool CachedEntity::IsVisible() { return false; } -void CachedEntity::AddESPString(const char* fmt, ...) { - if (m_Strings[m_nESPStrings].m_String) { - delete m_Strings[m_nESPStrings].m_String; - } - m_Strings[m_nESPStrings].m_bColored = false; - char* buffer = new char[1024](); - va_list list; - va_start(list, fmt); - vsprintf(buffer, fmt, list); - va_end(list); - if (m_nESPStrings >= MAX_STRINGS) { - logging::Info("Can't attach more than %i strings to an entity", MAX_STRINGS); - return; - } - if (m_nESPStrings < 0) { - logging::Info("Invalid string count !!!"); - return; - } - m_Strings[m_nESPStrings].m_String = buffer; - //logging::Info("String: %s", m_Strings[m_nESPStrings].m_String); - m_nESPStrings++; -} - -ESPStringCompound& CachedEntity::GetESPString(int idx) { - //if (idx >= 0 && idx < m_nESPStrings) { - return m_Strings[idx]; - -} - matrix3x4_t* CachedEntity::GetBones() { if (!m_bBonesSetup) { m_bBonesSetup = m_pEntity->SetupBones(m_Bones, MAXSTUDIOBONES, 0x100, 0); // gvars->curtime @@ -241,14 +207,6 @@ EntityCache::~EntityCache() { delete [] m_pArray; } -void CachedEntity::PruneStrings() { - m_nESPStrings = 0; -} - -void EntityCache::PruneStrings() { - for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) m_pArray[i].PruneStrings(); -} - void EntityCache::Update() { m_nMax = g_IEntityList->GetHighestEntityIndex(); for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) { diff --git a/src/entitycache.h b/src/entitycache.h index 01a84937..416045d7 100644 --- a/src/entitycache.h +++ b/src/entitycache.h @@ -16,7 +16,6 @@ struct matrix3x4_t; class IClientEntity; -struct ESPStringCompound; struct player_info_s; struct model_t; struct mstudiohitboxset_t; @@ -107,9 +106,6 @@ public: ~CachedEntity(); void Update(int idx); - void PruneStrings(); - void AddESPString(const char* string, ...); - ESPStringCompound& GetESPString(int idx); // Entity fields start here. @@ -151,10 +147,6 @@ public: int m_IDX; IClientEntity* InternalEntity(); IClientEntity* m_pEntity; - ESPStringCompound* m_Strings; - int m_ESPColorFG; - int m_nESPStrings; - Vector m_ESPOrigin; Vector m_vecVOrigin; Vector m_vecVelocity; Vector m_vecAcceleration; @@ -167,7 +159,6 @@ public: ~EntityCache(); void Update(); - void PruneStrings(); void Invalidate(); CachedEntity* GetEntity(int idx); diff --git a/src/entitywrap.cpp b/src/entitywrap.cpp new file mode 100644 index 00000000..6c9a20b7 --- /dev/null +++ b/src/entitywrap.cpp @@ -0,0 +1,22 @@ +/* + * entitywrap.cpp + * + * Created on: Mar 18, 2017 + * Author: nullifiedcat + */ + +#include "entitywrap.h" + +#include "common.h" + +EntityWrapper::EntityWrapper(int idx) : idx(idx) {} + +bool EntityWrapper::good() const { + return idx < g_IEntityList->GetHighestEntityIndex() && g_IEntityList->GetClientEntity(idx); +} + +IClientEntity* EntityWrapper::operator ->() const { + IClientEntity* ret = g_IEntityList->GetClientEntity(idx); + if (!ret) throw std::runtime_error("referencing null entity"); + return ret; +} diff --git a/src/entitywrap.h b/src/entitywrap.h new file mode 100644 index 00000000..aca17bce --- /dev/null +++ b/src/entitywrap.h @@ -0,0 +1,23 @@ +/* + * entitywrap.h + * + * Created on: Mar 18, 2017 + * Author: nullifiedcat + */ + +#ifndef ENTITYWRAP_H_ +#define ENTITYWRAP_H_ + +class IClientEntity; + +class EntityWrapper { +public: + EntityWrapper(int idx); + + bool good() const; + IClientEntity* operator->() const; + + const int idx; +}; + +#endif /* ENTITYWRAP_H_ */ diff --git a/src/hack.cpp b/src/hack.cpp index 4d45481d..21ec90c3 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -45,8 +45,6 @@ #include "copypasted/CSignature.h" #include "copypasted/Netvar.h" #include "CDumper.h" -#include "ipc/ipcctl.h" - #include /* diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 7eb8b3e8..fc131a5e 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -136,7 +136,7 @@ void CreateMove() { } } if (CE_GOOD(target_highest)) { - target_highest->m_ESPColorFG = colors::pink; + hacks::shared::esp::SetEntityColor(target_highest, colors::pink); if (ShouldAim(cmd)) { last_target = target_highest->m_IDX; if (g_pLocalPlayer->weapon()->m_iClassID == g_pClassID->CTFCompoundBow) { // There is no Huntsman in TF2C. diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index 0432708b..98dc8fb3 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -45,6 +45,26 @@ CatVar entity_model(CV_SWITCH, "esp_model_name", "0", "Model name ESP", "Model n CatVar item_weapon_spawners(CV_SWITCH, "esp_weapon_spawners", "1", "Show weapon spawners", "TF2C deathmatch weapon spawners"); CatVar item_adrenaline(CV_SWITCH, "esp_item_adrenaline", "0", "Show Adrenaline", "TF2C adrenaline pills"); +std::array data; + +void ResetEntityStrings() { + for (auto& i : data) { + i.string_count = 0; + i.color = 0; + } +} + +void SetEntityColor(CachedEntity* entity, int color) { + data[entity->m_IDX].color = color; +} + +void AddEntityString(CachedEntity* entity, const std::string& string, int color) { + ESPData& entity_data = data[entity->m_IDX]; + entity_data.strings[entity_data.string_count].data = string; + entity_data.strings[entity_data.string_count].color = color; + entity_data.string_count++; +} + const std::string classes[] = { "Scout", "Sniper", @@ -58,14 +78,16 @@ const std::string classes[] = { }; void CreateMove() { + ResetEntityStrings(); int limit = HIGHEST_ENTITY; if (!buildings && !proj_esp && !item_esp) limit = min(32, HIGHEST_ENTITY); for (int i = 0; i < limit; i++) { - ProcessEntity(ENTITY(i)); - if (ENTITY(i)->m_nESPStrings) { - ENTITY(i)->m_ESPColorFG = colors::EntityF(ENTITY(i)); - if (vischeck) { - if (!ENTITY(i)->IsVisible()) ENTITY(i)->m_ESPColorFG = colors::Transparent(ENTITY(i)->m_ESPColorFG); + CachedEntity* ent = ENTITY(i); + ProcessEntity(ent); + if (data[i].string_count) { + SetEntityColor(ent, colors::EntityF(ent)); + if (show_distance) { + AddEntityString(ent, format((int)(ENTITY(i)->m_flDistance / 64 * 1.22f), 'm')); } } } @@ -105,8 +127,8 @@ void DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, boo //draw::DrawString(min(smin.x, smax.x), min(smin.y, smax.y), clr, false, "min"); //draw::DrawString(max(smin.x, smax.x), max(smin.y, smax.y), clr, false, "max"); //draw::DrawString((int)so.x, (int)so.y, draw::white, false, "origin"); - ent->m_ESPOrigin.x = so.x + width / 2 + 1; - ent->m_ESPOrigin.y = so.y - height; + data[ent->m_IDX].esp_origin.x = so.x + width / 2 + 1; + data[ent->m_IDX].esp_origin.y = so.y - height; unsigned char alpha = clr >> 24; float trf = (float)((float)alpha / 255.0f); int border = cloak ? colors::Create(160, 160, 160, alpha) : colors::Transparent(colors::black, trf); @@ -128,17 +150,14 @@ void ProcessEntity(CachedEntity* ent) { if (!enabled) return; if (CE_BAD(ent)) return; - //if (ent->IsVisible()) ent->AddESPString("VISIBLE"); - if (entity_info) { - ent->AddESPString("%s [%i]", RAW_ENT(ent)->GetClientClass()->m_pNetworkName, ent->m_iClassID); + AddEntityString(ent, format(RAW_ENT(ent)->GetClientClass()->m_pNetworkName, " [", ent->m_iClassID, "]")); if (entity_id) { - ent->AddESPString("%i", ent->m_IDX); + AddEntityString(ent, std::to_string(ent->m_IDX)); } - //ent->AddESPString("Type: %i", ent->m_Type); if (entity_model) { const model_t* model = RAW_ENT(ent)->GetModel(); - if (model) ent->AddESPString("%s", g_IModelInfo->GetModelName(model)); + if (model) AddEntityString(ent, std::string(g_IModelInfo->GetModelName(model))); } } @@ -146,10 +165,7 @@ void ProcessEntity(CachedEntity* ent) { if (ent->m_iClassID == g_pClassID->CTFProjectile_Rocket || ent->m_iClassID == g_pClassID->CTFProjectile_SentryRocket) { if (proj_rockets) { if ((int)proj_rockets != 2 || ent->m_bCritProjectile) { - ent->AddESPString("[ ==> ]"); - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); - } + AddEntityString(ent, "[ ==> ]"); } } } else if (ent->m_iClassID == g_pClassID->CTFGrenadePipebombProjectile) { @@ -157,22 +173,16 @@ void ProcessEntity(CachedEntity* ent) { case 0: if (!proj_pipes) break; if ((int)proj_pipes == 2 && !ent->m_bCritProjectile) break; - ent->AddESPString("[ (PP) ]"); + AddEntityString(ent, "[ (PP) ]"); break; case 1: if (!proj_stickies) break; if ((int)proj_stickies == 2 && !ent->m_bCritProjectile) break; - ent->AddESPString("[ {*} ]"); - } - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); + AddEntityString(ent, "[ {*} ]"); } } else if (ent->m_iClassID == g_pClassID->CTFProjectile_Arrow) { if ((int)proj_arrows != 2 || ent->m_bCritProjectile) { - ent->AddESPString("[ >>---> ]"); - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); - } + AddEntityString(ent, "[ >>---> ]"); } } } @@ -180,88 +190,68 @@ void ProcessEntity(CachedEntity* ent) { if (HL2DM) { if (item_esp && item_dropped_weapons) { if (CE_BYTE(ent, netvar.hOwner) == (unsigned char)-1) { - int a = ent->m_nESPStrings; - if (ent->m_iClassID == g_pClassID->CWeapon_SLAM) ent->AddESPString("SLAM"); - else if (ent->m_iClassID == g_pClassID->CWeapon357) ent->AddESPString(".357"); - else if (ent->m_iClassID == g_pClassID->CWeaponAR2) ent->AddESPString("AR2"); - else if (ent->m_iClassID == g_pClassID->CWeaponAlyxGun) ent->AddESPString("Alyx Gun"); - else if (ent->m_iClassID == g_pClassID->CWeaponAnnabelle) ent->AddESPString("Annabelle"); - else if (ent->m_iClassID == g_pClassID->CWeaponBinoculars) ent->AddESPString("Binoculars"); - else if (ent->m_iClassID == g_pClassID->CWeaponBugBait) ent->AddESPString("Bug Bait"); - else if (ent->m_iClassID == g_pClassID->CWeaponCrossbow) ent->AddESPString("Crossbow"); - else if (ent->m_iClassID == g_pClassID->CWeaponShotgun) ent->AddESPString("Shotgun"); - else if (ent->m_iClassID == g_pClassID->CWeaponSMG1) ent->AddESPString("SMG"); - else if (ent->m_iClassID == g_pClassID->CWeaponRPG) ent->AddESPString("RPG"); - if (a != ent->m_nESPStrings) { - ent->m_ESPColorFG = colors::yellow; - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); - } + int a = data[ent->m_IDX].string_count; + if (ent->m_iClassID == g_pClassID->CWeapon_SLAM) AddEntityString(ent, "SLAM"); + else if (ent->m_iClassID == g_pClassID->CWeapon357) AddEntityString(ent, ".357"); + else if (ent->m_iClassID == g_pClassID->CWeaponAR2) AddEntityString(ent, "AR2"); + else if (ent->m_iClassID == g_pClassID->CWeaponAlyxGun) AddEntityString(ent, "Alyx Gun"); + else if (ent->m_iClassID == g_pClassID->CWeaponAnnabelle) AddEntityString(ent, "Annabelle"); + else if (ent->m_iClassID == g_pClassID->CWeaponBinoculars) AddEntityString(ent, "Binoculars"); + else if (ent->m_iClassID == g_pClassID->CWeaponBugBait) AddEntityString(ent, "Bug Bait"); + else if (ent->m_iClassID == g_pClassID->CWeaponCrossbow) AddEntityString(ent, "Crossbow"); + else if (ent->m_iClassID == g_pClassID->CWeaponShotgun) AddEntityString(ent, "Shotgun"); + else if (ent->m_iClassID == g_pClassID->CWeaponSMG1) AddEntityString(ent, "SMG"); + else if (ent->m_iClassID == g_pClassID->CWeaponRPG) AddEntityString(ent, "RPG"); + if (a != data[ent->m_IDX].string_count) { + SetEntityColor(ent, colors::yellow); } } } } if (ent->m_iClassID == g_pClassID->CTFTankBoss && tank) { - ent->AddESPString("Tank"); + AddEntityString(ent, "Tank"); } else if (ent->m_iClassID == g_pClassID->CTFDroppedWeapon && item_esp && item_dropped_weapons) { - ent->AddESPString("WEAPON %s", ent->m_pEntity->GetClientClass()->GetName()); - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); - } + AddEntityString(ent, format("WEAPON ", ent->m_pEntity->GetClientClass()->GetName())); } else if (ent->m_iClassID == g_pClassID->CCurrencyPack && item_money) { if (CE_BYTE(ent, netvar.bDistributed)) { if (item_money_red) { - ent->AddESPString("$$$"); - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); + AddEntityString(ent, "~$~"); } } else { - ent->AddESPString("$$$"); - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); + AddEntityString(ent, "$$$"); } } else if (ent->m_ItemType != ITEM_NONE && item_esp) { bool shown = false; if (item_health_packs && (ent->m_ItemType >= ITEM_HEALTH_SMALL && ent->m_ItemType <= ITEM_HEALTH_LARGE || ent->m_ItemType == ITEM_HL_BATTERY)) { - if (ent->m_ItemType == ITEM_HEALTH_SMALL) ent->AddESPString("[+]"); - if (ent->m_ItemType == ITEM_HEALTH_MEDIUM) ent->AddESPString("[++]"); - if (ent->m_ItemType == ITEM_HEALTH_LARGE) ent->AddESPString("[+++]"); - if (ent->m_ItemType == ITEM_HL_BATTERY) ent->AddESPString("[Z]"); + if (ent->m_ItemType == ITEM_HEALTH_SMALL) AddEntityString(ent, "[+]"); + if (ent->m_ItemType == ITEM_HEALTH_MEDIUM) AddEntityString(ent, "[++]"); + if (ent->m_ItemType == ITEM_HEALTH_LARGE) AddEntityString(ent, "[+++]"); + if (ent->m_ItemType == ITEM_HL_BATTERY) AddEntityString(ent, "[Z]"); } else if (item_adrenaline && ent->m_ItemType == ITEM_TF2C_PILL) { - ent->AddESPString("[a]"); + AddEntityString(ent, "[a]"); } else if (item_ammo_packs && ent->m_ItemType >= ITEM_AMMO_SMALL && ent->m_ItemType <= ITEM_AMMO_LARGE) { - if (ent->m_ItemType == ITEM_AMMO_SMALL) ent->AddESPString("{i}"); - if (ent->m_ItemType == ITEM_AMMO_MEDIUM) ent->AddESPString("{ii}"); - if (ent->m_ItemType == ITEM_AMMO_LARGE) ent->AddESPString("{iii}"); + if (ent->m_ItemType == ITEM_AMMO_SMALL) AddEntityString(ent, "{i}"); + if (ent->m_ItemType == ITEM_AMMO_MEDIUM) AddEntityString(ent, "{ii}"); + if (ent->m_ItemType == ITEM_AMMO_LARGE) AddEntityString(ent, "{iii}"); } else if (item_powerups && ent->m_ItemType >= ITEM_POWERUP_FIRST && ent->m_ItemType <= ITEM_POWERUP_LAST) { - ent->AddESPString("%s PICKUP", powerups[ent->m_ItemType - ITEM_POWERUP_FIRST]); + AddEntityString(ent, format(powerups[ent->m_ItemType - ITEM_POWERUP_FIRST], " PICKUP")); } else if (item_weapon_spawners && ent->m_ItemType >= ITEM_TF2C_W_FIRST && ent->m_ItemType <= ITEM_TF2C_W_LAST) { - ent->AddESPString("%s SPAWNER", tf2c_weapon_names[ent->m_ItemType - ITEM_TF2C_W_FIRST].c_str()); - if (CE_BYTE(ent, netvar.bRespawning)) ent->AddESPString("-- RESPAWNING --"); - } - if (show_distance && shown) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); + AddEntityString(ent, format(tf2c_weapon_names[ent->m_ItemType - ITEM_TF2C_W_FIRST], " SPAWNER")); + if (CE_BYTE(ent, netvar.bRespawning)) AddEntityString(ent, "-- RESPAWNING --"); } } else if (ent->m_Type == ENTITY_BUILDING && buildings) { if (!ent->m_bEnemy && !teammates) return; int level = CE_INT(ent, netvar.iUpgradeLevel); - const char* name = (ent->m_iClassID == g_pClassID->CObjectTeleporter ? "Teleporter" : (ent->m_iClassID == g_pClassID->CObjectSentrygun ? "Sentry Gun" : "Dispenser")); + const std::string& name = (ent->m_iClassID == g_pClassID->CObjectTeleporter ? "Teleporter" : (ent->m_iClassID == g_pClassID->CObjectSentrygun ? "Sentry Gun" : "Dispenser")); if (legit && ent->m_iTeam != g_pLocalPlayer->team) { /*if (ent->m_lLastSeen > v_iLegitSeenTicks->GetInt()) { return; }*/ } - ent->AddESPString("LV %i %s", level, name); + AddEntityString(ent, format("LV ", level, ' ', name)); if (show_health) { - ent->AddESPString("%i / %i HP", ent->m_iHealth, ent->m_iMaxHealth); - ent->GetESPString(ent->m_nESPStrings - 1).m_bColored = true; - if (vischeck) { - ent->GetESPString(ent->m_nESPStrings - 1).m_nColor = colors::Transparent(colors::Health(ent->m_iHealth, ent->m_iMaxHealth), ent->IsVisible() ? 1.0 : 0.5f); - } else { - ent->GetESPString(ent->m_nESPStrings - 1).m_nColor = colors::Health(ent->m_iHealth, ent->m_iMaxHealth); - } - } - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); + AddEntityString(ent, format(ent->m_iHealth, '/', ent->m_iMaxHealth, " HP"), colors::Health(ent->m_iHealth, ent->m_iMaxHealth)); } return; } else if (ent->m_Type == ENTITY_PLAYER && ent->m_bAlivePlayer) { @@ -280,44 +270,35 @@ void ProcessEntity(CachedEntity* ent) { }*/ } if (power >= 0 && (ent->m_bEnemy || teammates)) { - ent->AddESPString("HAS [%s]", powerups[power]); + AddEntityString(ent, format("HAS ", powerups[power])); } if (ent->m_bEnemy || teammates || GetRelation(ent)) { if (show_name) - ent->AddESPString("%s", info.name); + AddEntityString(ent, std::string(info.name)); if (show_class) { if (pclass > 0 && pclass < 10) - ent->AddESPString("%s", classes[pclass - 1].c_str()); + AddEntityString(ent, classes[pclass - 1]); } if (show_health) { - ent->AddESPString("%i / %i HP", ent->m_iHealth, ent->m_iMaxHealth); - ent->GetESPString(ent->m_nESPStrings - 1).m_bColored = true; - if (vischeck) { - ent->GetESPString(ent->m_nESPStrings - 1).m_nColor = colors::Transparent(colors::Health(ent->m_iHealth, ent->m_iMaxHealth), ent->IsVisible() ? 1.0 : 0.5f); - } else { - ent->GetESPString(ent->m_nESPStrings - 1).m_nColor = colors::Health(ent->m_iHealth, ent->m_iMaxHealth); - } + AddEntityString(ent, format(ent->m_iHealth, '/', ent->m_iMaxHealth, " HP"), colors::Health(ent->m_iHealth, ent->m_iMaxHealth)); } if (show_conditions && TF) { if (IsPlayerInvisible(ent)) { - ent->AddESPString("INVISIBLE"); + AddEntityString(ent, "INVISIBLE"); } if (IsPlayerInvulnerable(ent)) { - ent->AddESPString("INVULNERABLE"); + AddEntityString(ent, "INVULNERABLE"); } if (HasCondition(ent, TFCond_UberBulletResist)) { - ent->AddESPString("VACCINATOR ACTIVE"); + AddEntityString(ent, "VACCINATOR ACTIVE"); } if (HasCondition(ent, TFCond_SmallBulletResist)) { - ent->AddESPString("VACCINATOR PASSIVE"); + AddEntityString(ent, "VACCINATOR PASSIVE"); } if (IsPlayerCritBoosted(ent)) { - ent->AddESPString("CRIT BOOSTED"); + AddEntityString(ent, "CRIT BOOSTED"); } } - if (show_distance) { - ent->AddESPString("%im", (int)(ent->m_flDistance / 64 * 1.22f)); - } } return; } @@ -329,7 +310,9 @@ void ProcessEntityPT(CachedEntity* ent) { if (CE_BAD(ent)) return; if (!(local_esp && g_IInput->CAM_IsThirdPerson()) && ent->m_IDX == g_IEngine->GetLocalPlayer()) return; - int fg = ent->m_ESPColorFG; + const ESPData& ent_data = data[ent->m_IDX]; + int fg = ent_data.color; + bool transparent { false }; switch (ent->m_Type) { case ENTITY_PLAYER: { bool cloak = IsPlayerInvisible(ent); @@ -339,9 +322,11 @@ void ProcessEntityPT(CachedEntity* ent) { return; }*/ } + if (!ent->m_bEnemy && !teammates && !GetRelation(ent)) break; if (!ent->m_bAlivePlayer) break; - + if (vischeck && !ent->IsVisible()) transparent = true; + if (transparent) fg = colors::Transparent(fg); DrawBox(ent, fg, 3.0f, -15.0f, true, CE_INT(ent, netvar.iHealth), ent->m_iMaxHealth); break; } @@ -352,10 +337,35 @@ void ProcessEntityPT(CachedEntity* ent) { }*/ } if (CE_INT(ent, netvar.iTeamNum) == g_pLocalPlayer->team && !teammates) break; + if (!transparent && vischeck && !ent->IsVisible()) transparent = true; + if (transparent) fg = colors::Transparent(fg); DrawBox(ent, fg, 1.0f, 0.0f, true, CE_INT(ent, netvar.iBuildingHealth), CE_INT(ent, netvar.iBuildingMaxHealth)); break; } } + + if (ent_data.string_count) { + Vector screen; + bool origin_is_zero = ent_data.esp_origin.IsZero(1.0f); + if (!origin_is_zero || draw::EntityCenterToScreen(ent, screen)) { + if (vischeck && !ent->IsVisible()) transparent = true; + Vector draw_point = origin_is_zero ? screen : ent_data.esp_origin; + for (int j = 0; j < ent_data.string_count; j++) { + const ESPString& string = ent_data.strings[j]; + int color = string.color ? string.color : ent_data.color; + if (transparent) color = colors::Transparent(color); + if (!origin_is_zero) { + draw::String(fonts::ESP, draw_point.x, draw_point.y, color, 2, string.data); + draw_point.y += 11; + } else { + auto l = draw::GetStringLength(fonts::ESP, string.data); + draw::String(fonts::ESP, draw_point.x - l.first / 2, draw_point.y, color, 2, string.data); + draw_point.y += 11; + } + } + } + } + } }}} diff --git a/src/hacks/ESP.h b/src/hacks/ESP.h index 6db66850..f55bf1ee 100644 --- a/src/hacks/ESP.h +++ b/src/hacks/ESP.h @@ -13,6 +13,13 @@ class ConVar; class CachedEntity; +#include "../sdk.h" // VECTOR + +#include "../beforecheaders.h" +#include +#include +#include "../aftercheaders.h" + namespace hacks { namespace shared { namespace esp { extern CatVar local_esp; @@ -47,6 +54,25 @@ extern CatVar entity_model; extern CatVar item_weapon_spawners; extern CatVar item_adrenaline; +class ESPString { +public: + std::string data { "" }; + int color { 0 }; +}; + +class ESPData { +public: + int color { 0 }; + int string_count { 0 }; + std::array strings {}; + Vector esp_origin { 0, 0, 0 }; +}; + +extern std::array data; +void ResetEntityStrings(); +void AddEntityString(CachedEntity* entity, const std::string& string, int color = 0x0); +void SetEntityColor(CachedEntity* entity, int color); + void CreateMove(); void Draw(); diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp deleted file mode 100644 index faf5eb4a..00000000 --- a/src/hacks/FollowBot.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * HPyroBot.cpp - * - * Created on: Oct 30, 2016 - * Author: nullifiedcat - */ -/* -#include "FollowBot.h" - -#include - -#include "../common.h" -#include "../ipc/ipcctl.h" -#include "../sdk.h" - - - -DEFINE_HACK_SINGLETON(FollowBot); - -unsigned long g_nTick = 0; - -const char* FollowBot::GetName() { - return "FOLLOWBOT"; -} - -// TODO -bool FollowBot::ShouldPopUber(bool force) { - int health_my = g_pLocalPlayer->health; - //int health_tr = NET_INT(ENTITY(this->m_hTargetHealing), eoffsets.iHealth); - if (health_my < 30) return true; - //bool other_bots_have_uber = false; - for (int i = 0; i < 64 && i < HIGHEST_ENTITY; i++) { - CachedEntity* ent = ENTITY(i); - if (ent == g_pLocalPlayer->entity) continue; - if (IsFriendlyBot(ent)) { - if (CE_BYTE(ent, netvar.iLifeState)) continue; - //IClientEntity* medigun; - // TODO - } - } - return false; -} - -class MedicCallListener : public IGameEventListener2 { -public: - MedicCallListener() {} - void FireGameEvent(IGameEvent* pEvent) { - if (!g_phFollowBot->v_bEnabled->GetBool()) return; - if (strcmp("player_calledformedic", pEvent->GetName())) return; - int id = engineClient->GetPlayerForUserID(pEvent->GetInt("userid", -1)); - logging::Info("%i called for medic"); - player_info_s info; - engineClient->GetPlayerInfo(id, &info); - if (info.friendsID == g_phFollowBot->m_nOwnerID) { - g_phFollowBot->m_iShouldUbercharge = 1; - } - } -}; - -void CC_ResetList(const CCommand& args) { - g_phFollowBot->ResetBotList(); -} - -MedicCallListener* g_pListener; - -// TODO -void FollowBot::ProcessEntity(CachedEntity* entity, bool enemy) { - return; -} - -/* - * pick target - * if can't pick target: - * forward - * follow - * if can't follow: - * goto pick target - * if at shooting distance: - * shoot - *//* - -// TODO -int FollowBot::ShouldNotTarget(CachedEntity* ent, bool notrace) { - if (CE_BAD(ent)) return 1; - if (ent->m_Type != ENTITY_PLAYER) return 2; - if (!ent->m_bAlivePlayer) return 3; - if (ent->m_bEnemy) return 4; - - // TODO temporary! W+m1 bot should be back! - if (!this->IsOwner(ent)) { - return 7; - } - - if (!notrace) { - bool a = false; - for (int i = 0; i < 17; i++) { - if (IsEntityVisible(ent, i)) a = true; - } - if (!a) return 6; - } - - return 0; -} - -void FollowBot::Tick(CUserCmd* cmd) { - if (CE_BAD(g_pLocalPlayer->entity)) return; - if (g_pLocalPlayer->life_state) return; - - CachedEntity* owner_entity = 0; - for (int i = 0; i < 64 && i < HIGHEST_ENTITY; i++) { - if (IsOwner(ENTITY(i))) { - m_hTargetFollowing = i; - owner_entity = ENTITY(i); - } - } - if (CE_BAD(owner_entity)) return; - if (m_iForceHealTicks && m_iForceHealTicks < 20) { - m_iForceHealTicks++; - cmd->buttons |= IN_ATTACK; - } else m_iForceHealTicks = 0; - switch (v_iBotPackage->GetInt()) { - case botpackage::BOT_FOLLOW: { - - break; - } - case botpackage::BOT_MEDIC: { - cmd->buttons |= IN_ATTACK; - if ((g_nTick % 100) == 0) { - engineClient->ExecuteClientCmd("slot2"); - cmd->buttons &= ~IN_ATTACK; - } - if (this->m_iShouldUbercharge && this->m_iShouldUbercharge < 30) { - cmd->buttons |= IN_ATTACK2; - engineClient->ExecuteClientCmd("voicemenu 2 1"); - this->m_iShouldUbercharge++; - } else { - this->m_iShouldUbercharge = 0; - } - break; - } - case botpackage::BOT_SNIPER: { - if (!owner_entity) break; - //bool owner_zoomed = (NET_INT(owner_entity, eoffsets.iCond) & cond::zoomed); - // - CachedEntity* owner_weapon = ENTITY(CE_INT(owner_entity, netvar.hActiveWeapon) & 0xFFF); - if (CE_GOOD(owner_weapon)) { - if (owner_weapon->m_iClassID == g_pClassID->CTFSniperRifle || owner_weapon->m_iClassID == g_pClassID->CTFSniperRifle) { - if (!g_pLocalPlayer->bZoomed) { - cmd->buttons |= IN_ATTACK2; - } - } else { - if (g_pLocalPlayer->bZoomed) { - cmd->buttons |= IN_ATTACK2; - } - } - } - break; - } - } - if (v_iBotPackage->GetInt() == botpackage::BOT_DUMMY) return; - - - if (v_iBotPackage->GetInt() == botpackage::BOT_MEDIC) { - CachedEntity* healtr = this->GetBestHealingTarget(); - m_hTargetHealing = (healtr ? healtr->m_IDX : 0); - if (healtr) { - if (CE_INT(healtr, netvar.iHealth) < 35 && !CE_BYTE(healtr, netvar.iLifeState)) { - m_iShouldUbercharge = 1; - } - if (g_pLocalPlayer->health < 35) { - m_iShouldUbercharge = 1; - } - } - } - - if (owner_entity && (0 == (g_nTick % 20))) { - static bool forward = false; - static bool jump = false; - if (!jump && CE_VECTOR(g_pLocalPlayer->entity, netvar.vVelocity).IsZero(10.0f) && !g_pLocalPlayer->bZoomed) { - engineClient->ExecuteClientCmd("+jump"); - jump = true; - } else if (jump) { - engineClient->ExecuteClientCmd("-jump"); - jump = false; - } - - if (forward && DistToSqr(owner_entity) < (60 * 60)) { - engineClient->ExecuteClientCmd("-forward"); - forward = false; - } else if (!forward) { - engineClient->ExecuteClientCmd("+forward"); - forward = true; - } - } - - return; -} - -void FollowBot::ActuallyCreateMove(CUserCmd* cmd) { - CachedEntity* tr_follow = ENTITY(this->m_hTargetFollowing); - QAngle angles = VectorToQAngle(cmd->viewangles); - if (CE_GOOD(tr_follow)) { - AimAtHitbox(tr_follow, 4, cmd); - angles = VectorToQAngle(cmd->viewangles); - g_pLocalPlayer->v_OrigViewangles = cmd->viewangles; - } - - if (v_iBotPackage->GetInt() == botpackage::BOT_MEDIC) { - CachedEntity* tr_heal = ENTITY(this->m_hTargetHealing); - if (CE_GOOD(tr_heal)) { - AimAtHitbox(tr_heal, 4, cmd); - g_pLocalPlayer->bUseSilentAngles = true; - } - } - engineClient->SetViewAngles(angles); -} - -// TODO optimize, cache or something -bool FollowBot::IsOwner(CachedEntity* ent) { - if (CE_BAD(ent)) return false; - return (ent->m_pPlayerInfo && ent->m_pPlayerInfo->friendsID == this->m_nOwnerID); -} - -void FollowBot::ResetBotList() { - this->m_nOtherBots = 0; -} - -bool FollowBot::IsFriendlyBot(CachedEntity* ent) { - if (CE_BAD(ent)) return false; - if (!ent->m_pPlayerInfo) return false; - for (unsigned i = 0; i < this->m_nOtherBots && i < 32; i++) { - if (ent->m_pPlayerInfo->friendsID == this->m_OtherBots[i]) return true; - } - return false; -} - -CachedEntity* FollowBot::GetBestHealingTarget() { - CachedEntity* best = 0; - int best_score = -65536; - - for (int i = 0; i < 64 && i < HIGHEST_ENTITY; i++) { - CachedEntity* cur = ENTITY(i); - if (CE_BAD(cur)) continue; - if (cur->m_Type == ENTITY_PLAYER) { - if (cur->m_bEnemy) continue; - if (!cur->m_bAlivePlayer) continue; - if (cur == g_pLocalPlayer->entity) continue; - int score = this->GetHealingPriority(cur); - if (score > best_score && score != 0) { - best = cur; - best_score = score; - } - } - } - - return best; -} - -bool FollowBot::CreateMove(void*, float, CUserCmd* cmd) { - if (!v_bEnabled->GetBool()) return true; - Tick(cmd); - g_nTick++; - this->ActuallyCreateMove(cmd); - return false; -} - -int FollowBot::GetHealingPriority(CachedEntity* ent) { - if (!ent) return 0; - int result = 0; - - if (ent->m_bEnemy) return 0; - if (!ent->m_bAlivePlayer) return 0; - if (!IsEntityVisible(ent, 4)) return 0; - - int health = CE_INT(ent, netvar.iHealth); - int maxhealth = g_pPlayerResource->GetMaxHealth(ent); - int maxbuffedhealth = maxhealth * 1.5; - int maxoverheal = maxbuffedhealth - maxhealth; - int overheal = maxoverheal - (maxbuffedhealth - health); - float overhealp = ((float)overheal / (float)maxoverheal); - float healthp = ((float)health / (float)maxhealth); - if (ent->m_flDistance > 1000) return 0; - - if (this->IsFriendlyBot(ent)) { - // Friendly bot medics must be constantly at 100%+ hp - if (healthp < 0.75) { - result += 60; - } - result += (maxbuffedhealth - health); - } else if (this->IsOwner(ent)) { - if (overhealp > 0.75) result -= 25; - result += (maxbuffedhealth - health) * 1.25; - } else { - result += (maxhealth - health); - if (result > 50) result = 50; - } - - //logging::Info("idx %i score %i | HP %i MH %i MBH %i MO %i O %i", ent->entindex(), result, health, maxhealth, maxbuffedhealth, maxoverheal, overheal); - return result; -} - -void FollowBot::AddBotID(uint32 id) { - logging::Info("Added bot: %lu", id); - this->m_OtherBots[this->m_nOtherBots++] = id; -} - -void FollowBot::SetOwner(uint32 id) { - logging::Info("Owner set: %lu", id); - this->m_nOwnerID = id; -} - -// TODO -void CC_BotStatus(const CCommand& args) { - //logging::Info("Bot Status: %i, ID: %i, Search: %i", g_bState, g_nTargetID, nPilotSearch); -} - -void CC_AddBotID(const CCommand& args) { - if (args.ArgC() < 1) return; - uint32 id = strtoul(args.Arg(1), 0, 0); - if (!id) return; - g_phFollowBot->AddBotID(id); -} - -void CC_SetOwner(const CCommand& args) { - if (args.ArgC() < 1) return; - uint32 id = strtoul(args.Arg(1), 0, 0); - if (!id) return; - g_phFollowBot->m_nOwnerID = id; -} - -void CC_HealOwner(const CCommand& args) { - g_phFollowBot->m_hTargetHealing = g_phFollowBot->m_nOwnerID; - g_phFollowBot->m_iForceHealTicks = 1; -} - -void CC_BotCommand(const CCommand& args) { - if (args.ArgC() < 2) return; - int bot_id = strtol(args.Arg(1), 0, 0); - char* buf = new char[256]; - for (int i = 2; i < args.ArgC(); i++) { - strcat(buf, strfmt("%s ", args.Arg(i))); - } - if (!bot_id) { - logging::Info("Executing command `%s` on EACH bot.", buf); - } else { - logging::Info("Executing command `%s` on bot %i.", buf, bot_id); - } - g_phFollowBot->m_pIPC->SetCommand(bot_id, (char*)buf); - delete [] buf; -} - -void CC_IPCList(const CCommand& args) { - for (int i = 1; i < MAX_SEGS; i++) { - ipc_client_seg seg = g_phFollowBot->m_pIPC->mem->segments[i]; - if (seg.initialized && (time(0) - seg.last_access_time < ACCESS_TIMEOUT)) { - if (kill(seg.owner_pid, 0) == -1) { - if (errno == ESRCH) continue; - } - logging::Info("[%i]: pid=%i name=`%s`", i, seg.owner_pid, seg.name); - } - } -} - -FollowBot::FollowBot() { - v_bEnabled = CreateConVar(CON_PREFIX "bot_enabled", "0", "Enables followbot"); - v_iBotPackage = CreateConVar(CON_PREFIX "bot_ai", "0", "AI Package (FOLLOW, MEDIC, SNIPER)"); - c_AddBotID = CreateConCommand(CON_PREFIX "bot_addbot", CC_AddBotID, "Adds another bot's ID"); - c_SetOwner = CreateConCommand(CON_PREFIX "bot_owner", CC_SetOwner, "Set followbot owner"); - c_ResetList = CreateConCommand(CON_PREFIX "bot_reset", CC_ResetList, "Resets bot list"); - c_BotCommand = CreateConCommand(CON_PREFIX "bot_command", CC_BotCommand, "Sends bot commands"); - c_IPCList = CreateConCommand(CON_PREFIX "bot_ipclist", CC_IPCList, "Lists IPC status"); - c_HealOwner = CreateConCommand(CON_PREFIX "bot_healowner", CC_HealOwner, "Heals owner"); - m_nOwnerID = 0; - - this->last_command_global = 0; - this->last_command_local = 0; - - m_hTargetFollowing = 0; - m_hTargetHealing = 0; - - cmd_Status = CreateConCommand(CON_PREFIX "bot_status", CC_BotStatus, "Status"); - g_pListener = new MedicCallListener(); - eventManager->AddListener(g_pListener, "player_calledformedic", false); - - logging::Info("Creating shared memory for bot"); - m_pIPC = new ipcctl(); - if (m_pIPC->Init()) { - logging::Info("Successfully allocated shared memory!"); - logging::Info("Bot ID: %i", m_pIPC->client_id); - } else { - logging::Info("Failed to allocate shared memory for bot."); - } -} - -FollowBot::~FollowBot() { - eventManager->RemoveListener(g_pListener); - m_pIPC->Detach(); -} - -void FollowBot::PaintTraverse(void*, unsigned int, bool, bool) {} - -void FollowBot::LevelInit(const char*) {} -void FollowBot::LevelShutdown() {} -*/ diff --git a/src/hacks/FollowBot.h b/src/hacks/FollowBot.h deleted file mode 100644 index bbb1a2da..00000000 --- a/src/hacks/FollowBot.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * HPyroBot.h - * - * Created on: Oct 30, 2016 - * Author: nullifiedcat - */ - -#ifndef HPYROBOT_H_ -#define HPYROBOT_H_ - -#include "IHack.h" -/* -class ipcctl; -class IClientEntity; - -void CC_ResetList(const CCommand& args); -void CC_AddBotID(const CCommand& args); -void CC_BotStatus(const CCommand& args); -void CC_SetOwner(const CCommand& args); - -enum botpackage { - BOT_FOLLOW = 0, - BOT_MEDIC, - BOT_SNIPER, - BOT_DUMMY -}; - -class FollowBot : public IHack { -public: - DECLARE_HACK_METHODS(); - FollowBot(); - ~FollowBot(); - void ProcessEntity(CachedEntity* entity, bool enemy); - void Tick(CUserCmd*); - int ShouldNotTarget(CachedEntity* ent, bool notrace); - - bool ShouldPopUber(bool force); - void ActuallyCreateMove(CUserCmd*); - CachedEntity* GetBestHealingTarget(); - int GetHealingPriority(CachedEntity* ent); - bool IsFriendlyBot(CachedEntity* ent); - bool IsOwner(CachedEntity* ent); - void ResetBotList(); - void AddBotID(uint32 id); - void SetOwner(uint32 id); - void UpdateOwner(); - - int m_hTargetFollowing; - int m_hTargetHealing; - - ConCommand* cmd_Status; - - ConVar* v_bEnabled; - int m_iForceHealTicks; - int m_iShouldUbercharge; - ConVar* v_iBotPackage; - ConCommand* c_AddBotID; - ConCommand* c_SetOwner; - ConCommand* c_ResetList; - ConCommand* c_HealOwner; - ConCommand* c_BotCommand; - ConCommand* c_IPCList; - uint32 m_nOwnerID; - uint32 m_OtherBots[32]; - uint32 m_nOtherBots; - ipcctl* m_pIPC; - unsigned last_command_global; - unsigned last_command_local; -}; - -DECLARE_HACK_SINGLETON(FollowBot) -*/ -#endif /* HPYROBOT_H_ */ diff --git a/src/hacks/KillSay.cpp b/src/hacks/KillSay.cpp index d2c54984..b6eca3e8 100644 --- a/src/hacks/KillSay.cpp +++ b/src/hacks/KillSay.cpp @@ -41,11 +41,11 @@ const std::string tf_teams_killsay[] = { TextFile file {}; std::string ComposeKillSay(IGameEvent* event) { - if (file.LineCount() == 0) return 0; - if (!event) return 0; + if (file.LineCount() == 0) return ""; + if (!event) return ""; int vid = event->GetInt("userid"); int kid = event->GetInt("attacker"); - if (kid == vid) return 0; + if (kid == vid) return ""; if (g_IEngine->GetPlayerForUserID(kid) != g_IEngine->GetLocalPlayer()) return 0; std::string msg = file.Line(rand() % file.LineCount()); player_info_s info; diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 4578e1d3..c3ed155c 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -59,25 +59,25 @@ void CreateMove() { void Draw() { if (crit_info && CE_GOOD(LOCAL_W)) { if (crit_hack) { - AddCenterString(colors::red, "FORCED CRITS: ON"); + AddCenterString("FORCED CRITS!", colors::red); } if (TF2) { if (!vfunc(RAW_ENT(LOCAL_W), 465, 0)(RAW_ENT(LOCAL_W))) - AddCenterString(colors::white, "Random crits are disabled"); + AddCenterString("Random crits are disabled", colors::yellow); else { if (!vfunc(RAW_ENT(LOCAL_W), 465 + 21, 0)(RAW_ENT(LOCAL_W))) - AddCenterString(colors::white, "Weapon can't randomly crit"); + AddCenterString("Weapon can't randomly crit", colors::yellow); else - AddCenterString(colors::white, "Weapon can randomly crit"); + AddCenterString("Weapon can randomly crit"); } - AddCenterString(colors::white, "Bucket: %.2f", *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u)); + AddCenterString(format("Bucket: %.2f", *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u))); } } if (!debug_info) return; if (CE_GOOD(g_pLocalPlayer->weapon())) { - AddSideString(colors::white, "Weapon: %s [%i]", RAW_ENT(g_pLocalPlayer->weapon())->GetClientClass()->GetName(), g_pLocalPlayer->weapon()->m_iClassID); + /*AddSideString(colors::white, "Weapon: %s [%i]", RAW_ENT(g_pLocalPlayer->weapon())->GetClientClass()->GetName(), g_pLocalPlayer->weapon()->m_iClassID); //AddSideString(colors::white, "flNextPrimaryAttack: %f", CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack)); //AddSideString(colors::white, "nTickBase: %f", (float)(CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * gvars->interval_per_tick); AddSideString(colors::white, "CanShoot: %i", CanShoot()); @@ -118,7 +118,7 @@ void Draw() { //AddSideString(draw::white, draw::black, "VecPunchAngle: %f %f %f", pa.x, pa.y, pa.z); //draw::DrawString(10, y, draw::white, draw::black, false, "VecPunchAngleVel: %f %f %f", pav.x, pav.y, pav.z); //y += 14; - //AddCenterString(draw::font_handle, input->GetAnalogValue(AnalogCode_t::MOUSE_X), input->GetAnalogValue(AnalogCode_t::MOUSE_Y), draw::white, L"S\u0FD5"); + //AddCenterString(draw::font_handle, input->GetAnalogValue(AnalogCode_t::MOUSE_X), input->GetAnalogValue(AnalogCode_t::MOUSE_Y), draw::white, L"S\u0FD5");*/ } } diff --git a/src/hacks/SpyAlert.cpp b/src/hacks/SpyAlert.cpp index 9076faa4..16e62190 100644 --- a/src/hacks/SpyAlert.cpp +++ b/src/hacks/SpyAlert.cpp @@ -26,9 +26,9 @@ void Draw() { if (CE_INT(ent, netvar.iTeamNum) == g_pLocalPlayer->team) continue; float distance = ent->m_flDistance; if (distance < (float)distance_backstab) { - AddCenterString(colors::red, "BACKSTAB WARNING! %im", (int)(distance / 64 * 1.22f)); + AddCenterString(format("BACKSTAB WARNING! ", (int)(distance / 64 * 1.22f), 'm'), colors::red); } else if (distance < (float)distance_warning) { - AddCenterString(colors::yellow, "Incoming spy! %im", (int)(distance / 64 * 1.22f)); + AddCenterString(format("Incoming spy! ", (int)(distance / 64 * 1.22f), 'm'), colors::yellow); } } } diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index a42bb74f..b178fe0f 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -75,7 +75,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { bool time_replaced = false; float curtime_old = g_GlobalVars->curtime;; - if (CE_GOOD(g_pLocalPlayer->entity)) { + if (!g_Settings.bInvalid &&CE_GOOD(g_pLocalPlayer->entity)) { float servertime = (float)CE_INT(g_pLocalPlayer->entity, netvar.nTickBase) * g_GlobalVars->interval_per_tick; g_GlobalVars->curtime = servertime; time_replaced = true; @@ -91,7 +91,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { g_Settings.bInvalid = false; // Disabled because this causes EXTREME aimbot inaccuracy //if (!cmd->command_number) return ret; - gEntityCache.PruneStrings(); if (CE_GOOD(g_pLocalPlayer->entity)) { g_pLocalPlayer->v_OrigViewangles = cmd->viewangles; // PROF_BEGIN(); diff --git a/src/hooks/PaintTraverse.cpp b/src/hooks/PaintTraverse.cpp index dd7fdbbb..318dfdea 100644 --- a/src/hooks/PaintTraverse.cpp +++ b/src/hooks/PaintTraverse.cpp @@ -82,32 +82,13 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) { draw_flag = false; if (logo) { - AddSideString(colors::RainbowCurrent(), "cathook by d4rkc4t"); + AddSideString("cathook by d4rkc4t", colors::RainbowCurrent()); } if (CE_GOOD(g_pLocalPlayer->entity) && !g_Settings.bInvalid) { if (TF) SAFE_CALL(hacks::tf2::antidisguise::Draw()); SAFE_CALL(hacks::shared::misc::Draw()); SAFE_CALL(hacks::shared::esp::Draw()); if (TF) SAFE_CALL(hacks::tf::spyalert::Draw()); - Vector screen; - for (int i = 0; i < HIGHEST_ENTITY; i++) { - CachedEntity* ce = gEntityCache.GetEntity(i); - if (CE_BAD(ce)) continue; - if (ce->m_ESPOrigin.IsZero(1.0f)) - if (!draw::EntityCenterToScreen(ce, screen)) continue; - for (int j = 0; j < ce->m_nESPStrings; j++) { - ESPStringCompound str = ce->GetESPString(j); - int color = str.m_bColored ? str.m_nColor : ce->m_ESPColorFG; - if (!ce->m_ESPOrigin.IsZero(1.0)) { - draw::String(fonts::ESP, ce->m_ESPOrigin.x, ce->m_ESPOrigin.y, color, 2, str.m_String); - ce->m_ESPOrigin.y += 12; - } else { - auto l = draw::GetStringLength(fonts::ESP, std::string(str.m_String)); - draw::String(fonts::ESP, screen.x - l.first / 2, screen.y, color, 2, str.m_String); - screen.y += 11; - } - } - } } #if GUI_ENABLED == true diff --git a/src/ipc/ipcctl.cpp b/src/ipc/ipcctl.cpp deleted file mode 100644 index c0dc74b0..00000000 --- a/src/ipc/ipcctl.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ipcctl.cpp - * - * Created on: Nov 23, 2016 - * Author: nullifiedcat - */ - -#include "../ipc/ipcctl.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../logging.h" -#include "../interfaces.h" - -bool ipcctl::Init() { - broken = true; - key = 0x0D34DC47; - logging::Info("IPC Total Size: %i", sizeof(ipc_mem_layout)); - shmid = shmget(key, sizeof(ipc_mem_layout), 0666 | IPC_CREAT); - if (shmid == -1) { - logging::Info("shmget error: %i", errno); - return false; - } - mem = (ipc_mem_layout*)shmat(shmid, (void*)0, 0); - if (mem == (ipc_mem_layout*)-1) { - logging::Info("shmat error: %i", errno); - return false; - } - client_id = NextClientID(); - memset(&mem->segments[client_id], 0, sizeof(ipc_client_seg)); - mem->segments[client_id].initialized = true; - mem->segments[client_id].owner_pid = getpid(); - mem->segments[client_id].command_number = 0; - memcpy(mem->segments[client_id].name, g_ISteamFriends->GetPersonaName(), 32); - if (client_id == -1) return false; - broken = false; - return true; -} - -int ipcctl::NextClientID() { - /* Segment 0 is reserved for broadcast commands */ - for (int i = 1; i < MAX_SEGS; i++) { - ipc_client_seg seg = mem->segments[i]; - if (seg.initialized) { - logging::Info("Segment %i is owned by `%s`, PID %i", i, seg.name, seg.owner_pid); - if (kill(seg.owner_pid, 0) == -1 && errno == ESRCH) { - logging::Info("Dead process: %i", seg.owner_pid); - return i; - } - if ((time(0) - seg.last_access_time) > ACCESS_TIMEOUT) { - logging::Info("Segment timeout: %i", i); - return i; - } - } else { - return i; - } - } - logging::Info("Ran out of segments for bots."); - return -1; -} - -void ipcctl::SetCommand(int client, char* cmd) { - if (broken) return; - if (client < 0 || client >= MAX_SEGS) return; - char buffer[CMD_LENGTH]; - snprintf(buffer, CMD_LENGTH, "%s", cmd); - logging::Info("Executing command `%s`, #CMD %i", cmd, mem->segments[client].command_number); - mem->segments[client].command_number++; - memcpy(mem->segments[client].command_buffer, buffer, sizeof(char) * CMD_LENGTH); -} - -ipc_client_seg* ipcctl::GetClientSegment(int client) { - if (broken) return (ipc_client_seg*)0; - if (client < 0 || client >= MAX_SEGS) return (ipc_client_seg*)0; - if (client != 0 && mem->segments[client].owner_pid != getpid()) { - logging::Info("Warning: Shared memory violation! BotID: %i ; PID: %i ; OWNER: %i", client, getpid(), mem->segments[client].owner_pid); - this->client_id = NextClientID(); - if (client == -1) { - logging::Info("FAILED TO ASSIGN NEW BOT ID !!!"); - return 0; - } - logging::Info("New BotID: %i", client); - memset(&mem->segments[client], 0, sizeof(ipc_client_seg)); - mem->segments[client].initialized = true; - mem->segments[client].owner_pid = getpid(); - mem->segments[client].command_number = 0; - memcpy(mem->segments[client].name, g_ISteamFriends->GetPersonaName(), 32); - return 0; - } - mem->segments[client].last_access_time = time(0); - return &mem->segments[client]; -} - -bool ipcctl::Detach() { - if (broken) return true; - if (mem != (ipc_mem_layout*)-1) { - shmdt(mem); - } - return true; -} diff --git a/src/ipc/ipcctl.h b/src/ipc/ipcctl.h deleted file mode 100644 index 241ba987..00000000 --- a/src/ipc/ipcctl.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ipcctl.h - * - * Created on: Nov 23, 2016 - * Author: nullifiedcat - */ - -#ifndef IPCCTL_H_ -#define IPCCTL_H_ - -#include - -#define MAX_SEGS 16 -#define CMD_LENGTH 256 -#define ACCESS_TIMEOUT 10000 -#define NAME_LENGTH 32 - -typedef struct ipc_client_seg { - bool initialized; - time_t last_access_time; - pid_t owner_pid; - unsigned command_number; - char name[NAME_LENGTH]; - char command_buffer[CMD_LENGTH]; -} ipc_client_seg; - -typedef struct ipc_mem_layout { - /* 0: Global commands; 1-15: Bot-Specific commands */ - ipc_client_seg segments[MAX_SEGS]; -} ipc_mem_layout; - -class ipcctl { -public: - bool broken; - int key; - int shmid; - ipc_mem_layout* mem; - int client_id; - - bool Init(); - void SetCommand(int client, char* cmd); - ipc_client_seg* GetClientSegment(int client); - int NextClientID(); - bool Detach(); -}; - -#endif /* IPCCTL_H_ */ diff --git a/src/localplayer.h b/src/localplayer.h index 1b0a4e82..a417908b 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -28,7 +28,7 @@ public: Vector v_Origin; Vector v_Eye; int entity_idx; - CachedEntity* entity; + CachedEntity* entity { 0 }; CachedEntity* weapon(); Vector v_OrigViewangles; Vector v_SilentAngles;