From 9776c4c8abd833746726869fa14ff8bbecfa1aeb Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Sun, 30 Oct 2016 21:20:56 +0300 Subject: [PATCH] zz --- uran/TODO | 4 +- uran/src/drawing.cpp | 1 + uran/src/entity.cpp | 1 + uran/src/entity.h | 2 + uran/src/entry.cpp | 1 + uran/src/hack.cpp | 2 + uran/src/hacks/HPyroBot.cpp | 116 ++++++++++++++++++++++++--------- uran/src/hacks/HPyroBot.h | 2 + uran/src/hacks/HSaySpecial.cpp | 6 ++ uran/src/hacks/HSaySpecial.h | 1 + 10 files changed, 105 insertions(+), 31 deletions(-) diff --git a/uran/TODO b/uran/TODO index b9219c7d..8e73cfd5 100644 --- a/uran/TODO +++ b/uran/TODO @@ -17,7 +17,9 @@ priority system amby body Target system respect mannpower powerups -Aimbot charge detection respect powerups +Aimbot charge detection respect powerups + +FIX UNLOAD Entity::AddEntityString optimize diff --git a/uran/src/drawing.cpp b/uran/src/drawing.cpp index 37e90a4e..951188e6 100644 --- a/uran/src/drawing.cpp +++ b/uran/src/drawing.cpp @@ -14,6 +14,7 @@ #include #include +// TODO globals unsigned long draw::font_handle = 0; unsigned long draw::panel_top = 0; unsigned long draw::font_handle_large = 0; diff --git a/uran/src/entity.cpp b/uran/src/entity.cpp index 642196b9..4e9d504b 100644 --- a/uran/src/entity.cpp +++ b/uran/src/entity.cpp @@ -9,6 +9,7 @@ a * entity.cpp #include "copypasted/Netvar.h" #include "logging.h" +// TODO globals EntityVariables eoffsets; void EntityVariables::Init() { diff --git a/uran/src/entity.h b/uran/src/entity.h index fcdfe053..7401e339 100644 --- a/uran/src/entity.h +++ b/uran/src/entity.h @@ -12,6 +12,7 @@ class IClientEntity; +// TODO globals typedef unsigned int offset_t; template @@ -53,6 +54,7 @@ public: offset_t iGlowIndex; }; +// TODO globals extern EntityVariables eoffsets; #endif /* ENTITY_H_ */ diff --git a/uran/src/entry.cpp b/uran/src/entry.cpp index 0ce0e551..4d52f1d1 100644 --- a/uran/src/entry.cpp +++ b/uran/src/entry.cpp @@ -13,6 +13,7 @@ #include "fixsdk.h" #include +// TODO globals pthread_mutex_t mutex_quit; pthread_t thread_main; diff --git a/uran/src/hack.cpp b/uran/src/hack.cpp index 93a55d29..6a6aab2b 100644 --- a/uran/src/hack.cpp +++ b/uran/src/hack.cpp @@ -92,6 +92,7 @@ bool hack::Hk_CreateMove(void* thisptr, float inputSample, CUserCmd* cmd) { return ret; } +// TODO globals std::vector hack::hacks; void hack::AddHack(IHack* hack) { @@ -99,6 +100,7 @@ void hack::AddHack(IHack* hack) { hack::hacks.push_back(hack); } +// TODO globals ICvar* g_pCVar = 0; diff --git a/uran/src/hacks/HPyroBot.cpp b/uran/src/hacks/HPyroBot.cpp index 3e08377e..f6207fc5 100644 --- a/uran/src/hacks/HPyroBot.cpp +++ b/uran/src/hacks/HPyroBot.cpp @@ -20,11 +20,19 @@ #include #include +enum bot_state_t { + IDLE = 0, + FOLLOWING_TEAMMATE, + FOLLOWING_ENEMY, + PILOT_SEARCH, + TARGET_LOST +}; + unsigned long g_nTick = 0; int g_nTargetID = 0; -//IClientEntity* eTarget; -bool bFollowingTeammate; unsigned long nPilotSearch = 0; +unsigned long SEARCH_TICKS = 250; +bot_state_t g_bState = IDLE; void SetTarget(IClientEntity* ent) { if (!ent) { @@ -43,34 +51,49 @@ void HPyroBot::ProcessEntity(IClientEntity* entity, bool enemy) { IClientEntity* target = GetTarget(); if (!target) { - if (!enemy && v_iForceFollow->GetInt() != -1 && v_bForceFollowOnly->GetBool() && entity->entindex() != v_iForceFollow->GetInt()) return; + if (!enemy) { + if (v_iForceFollow->GetInt() != -1) { + if (v_bForceFollowOnly->GetBool() && (v_iForceFollow->GetInt() != entity->entindex())) { + return; + } + } + } target = entity; - bFollowingTeammate = !enemy; + SetTarget(target); } + if (enemy) { - if (!bFollowingTeammate) { + if (g_bState == bot_state_t::FOLLOWING_ENEMY) { if (DistToSqr(entity) <= DistToSqr(target)) { target = entity; + SetTarget(target); } } else { target = entity; + SetTarget(target); } - bFollowingTeammate = false; + g_bState = bot_state_t::FOLLOWING_ENEMY; } else { - //if (nPilotSearch < 100) return; + //if (g_bState == bot_state_t::PILOT_SEARCH) { + + //} + if (g_bState == bot_state_t::FOLLOWING_ENEMY) return; + if (GetEntityValue(entity, eoffsets.vVelocity).IsZero(1.0f)) return; if (v_iForceFollow->GetInt() != -1) { - if (bFollowingTeammate && entity->entindex() == v_iForceFollow->GetInt()) { + if (entity->entindex() == v_iForceFollow->GetInt()) { target = entity; + SetTarget(target); + g_bState = bot_state_t::FOLLOWING_TEAMMATE; } else { return; } } - if (GetEntityValue(entity, eoffsets.vVelocity).IsZero(1.0f)) return; - if (bFollowingTeammate && DistToSqr(entity) < DistToSqr(target)) { + if (DistToSqr(entity) <= DistToSqr(target)) { target = entity; + SetTarget(target); + g_bState = bot_state_t::FOLLOWING_TEAMMATE; } } - SetTarget(target); } void AimAt(IClientEntity* entity, CUserCmd* cmd) { @@ -97,7 +120,11 @@ bool HPyroBot::ShouldTarget(IClientEntity* ent) { if (IsPlayerInvulnerable(ent)) return false; } if (DistToSqr(ent) > (v_iMaxDistance->GetInt() * v_iMaxDistance->GetInt())) return false; - if (!IsEntityVisible(ent, 4)) return false; + bool a = false; + for (int i = 0; i < 17; i++) { + if (IsEntityVisible(ent, i)) a = true; + } + if (!a) return false; if (abs(ent->GetAbsOrigin().z - g_pLocalPlayer->v_Origin.z) > v_iMaxDeltaY->GetInt()) return false; return true; } @@ -105,25 +132,37 @@ bool HPyroBot::ShouldTarget(IClientEntity* ent) { void HPyroBot::Tick(CUserCmd* cmd) { if (!g_pLocalPlayer->entity || g_pLocalPlayer->entity->IsDormant()) return; if (g_pLocalPlayer->life_state) return; + IClientEntity* target = GetTarget(); IClientEntity* target_old = target; - if (!ShouldTarget(target) && !bFollowingTeammate) { - //logging::Info("Current target lost."); + + bool target_lost = (!target || !ShouldTarget(target) || g_bState == bot_state_t::PILOT_SEARCH); + + if (target_lost) logging::Info("Target lost! Target: %i, State: %i, ShouldTarget: %i", target, g_bState, ShouldTarget(target)); + + if (target_lost && g_bState == bot_state_t::FOLLOWING_ENEMY) { + g_bState = bot_state_t::PILOT_SEARCH; + nPilotSearch++; SetTarget(0); target = 0; } - if (!ShouldTarget(target) && bFollowingTeammate) { + if (target_lost && (g_bState == bot_state_t::FOLLOWING_TEAMMATE || g_bState == bot_state_t::PILOT_SEARCH)) { + g_bState = bot_state_t::PILOT_SEARCH; nPilotSearch++; - if (nPilotSearch >= 100) { - interfaces::engineClient->ExecuteClientCmd("-forward"); - interfaces::engineClient->ExecuteClientCmd("-attack"); - } } - nPilotSearch = 0; - interfaces::engineClient->ExecuteClientCmd("+forward"); - if ((g_nTick % 150 == 0) || !target) { - bFollowingTeammate = true; - //SetTarget(0); + + if (!target_lost) { + nPilotSearch = 0; + } + + if (nPilotSearch < SEARCH_TICKS) { + interfaces::engineClient->ExecuteClientCmd("+forward"); + } else { + interfaces::engineClient->ExecuteClientCmd("-forward"); + } + + + if ((g_nTick % 400 == 0) || target_lost) { for (int i = 0; i < 64 && i < interfaces::entityList->GetMaxEntities(); i++) { IClientEntity* ent = interfaces::entityList->GetClientEntity(i); if (!ShouldTarget(ent)) continue; @@ -131,39 +170,51 @@ void HPyroBot::Tick(CUserCmd* cmd) { ProcessEntity(ent, enemy); } } + target = GetTarget(); - if (!target) { + target_lost = (!target || !ShouldTarget(target) || g_bState == bot_state_t::IDLE || g_bState == bot_state_t::PILOT_SEARCH || g_bState == bot_state_t::TARGET_LOST); + + if (target_lost) { if (target_old != 0) { - //logging::Info("Target lost!"); if (v_bChat->GetBool()) { - interfaces::engineClient->ServerCmd("say Target lost!"); + //char* cmd = new char[256]; + //sprintf(cmd, "say Target lost!", g_bState); + //interfaces::engineClient->ServerCmd(cmd); + } + else { + //logging::Info("Target lost! State: %i, %i", !!target, !!ShouldTarget(target)); } } return; } + if (target != target_old) { player_info_s info; interfaces::engineClient->GetPlayerInfo(target->entindex(), &info); logging::Info("Following %s", info.name); if (v_bChat->GetBool()) { char* cmd = new char[256]; - if (bFollowingTeammate) + if (g_bState == bot_state_t::FOLLOWING_TEAMMATE) sprintf(cmd, "say Following: %s", info.name); else sprintf(cmd, "say Attacking: %s", info.name); interfaces::engineClient->ServerCmd(cmd); } } + if (GetEntityValue(g_pLocalPlayer->entity, eoffsets.vVelocity).IsZero(10.0f)) { interfaces::engineClient->ExecuteClientCmd("+jump"); } else { interfaces::engineClient->ExecuteClientCmd("-jump"); } + AimAt(target, cmd); - if (DistToSqr(target) < 200 * 200 && bFollowingTeammate) { + + if (DistToSqr(target) < (200 * 200) && g_bState == bot_state_t::FOLLOWING_TEAMMATE) { interfaces::engineClient->ExecuteClientCmd("-forward"); } - if (DistToSqr(target) < (v_iShootDistance->GetInt() * v_iShootDistance->GetInt()) && !bFollowingTeammate) { + + if (DistToSqr(target) < (v_iShootDistance->GetInt() * v_iShootDistance->GetInt()) && g_bState == bot_state_t::FOLLOWING_ENEMY) { interfaces::engineClient->ExecuteClientCmd("+attack"); } else { interfaces::engineClient->ExecuteClientCmd("-attack"); @@ -177,6 +228,10 @@ bool HPyroBot::CreateMove(void*, float, CUserCmd* cmd) { return true; } +void CC_Status(const CCommand& args) { + logging::Info("W+M1 State: %i, ID: %i, Search: %i", g_bState, g_nTargetID, nPilotSearch); +} + void HPyroBot::Create() { logging::Info("Creating PyroBot"); v_bEnabled = CreateConVar("u_pyrobot_enabled", "0", "Enables WM1 bot"); @@ -186,6 +241,7 @@ void HPyroBot::Create() { v_iMaxDistance = CreateConVar("u_pyrobot_aim_distance", "1300", "Distance"); v_iShootDistance = CreateConVar("u_pyrobot_shoot_distance", "800", "Shoot distance"); v_bChat = CreateConVar("u_pyrobot_chat", "0", "Enable chat"); + cmd_Status = CreateConCommand("u_pyrobot_status", CC_Status, "Status"); } void HPyroBot::Destroy() {} diff --git a/uran/src/hacks/HPyroBot.h b/uran/src/hacks/HPyroBot.h index a9f3e68a..af0a4c65 100644 --- a/uran/src/hacks/HPyroBot.h +++ b/uran/src/hacks/HPyroBot.h @@ -12,6 +12,7 @@ class ConVar; class IClientEntity; +class ConCommand; class HPyroBot : public IHack { public: @@ -22,6 +23,7 @@ public: void ProcessEntity(IClientEntity* entity, bool enemy); void Tick(CUserCmd*); bool ShouldTarget(IClientEntity* ent); + ConCommand* cmd_Status; ConVar* v_bEnabled; ConVar* v_iForceFollow; ConVar* v_bForceFollowOnly; diff --git a/uran/src/hacks/HSaySpecial.cpp b/uran/src/hacks/HSaySpecial.cpp index 8bef8f47..cbd74ad3 100644 --- a/uran/src/hacks/HSaySpecial.cpp +++ b/uran/src/hacks/HSaySpecial.cpp @@ -14,6 +14,7 @@ #include "../usercmd.h" #include "../interfaces.h" #include "../helpers.h" +#include "../hack.h" #include "../fixsdk.h" #include @@ -27,9 +28,14 @@ void CC_SayLines(const CCommand& args) { interfaces::engineClient->ServerCmd(str.c_str()); } +void CC_Shutdown(const CCommand& args) { + hack::Shutdown(); +} + void HSaySpecial::Create() { logging::Info("Setting up command"); this->c_SayLine = CreateConCommand("u_say_lines", CC_SayLines, "Uses ^ as a newline character"); + this->c_Shutdown = CreateConCommand("u_shutdown", CC_Shutdown, "Detaches the hack"); } bool HSaySpecial::CreateMove(void*, float, CUserCmd*) { return true; } diff --git a/uran/src/hacks/HSaySpecial.h b/uran/src/hacks/HSaySpecial.h index 3bdc5a71..27ab8034 100644 --- a/uran/src/hacks/HSaySpecial.h +++ b/uran/src/hacks/HSaySpecial.h @@ -21,6 +21,7 @@ public: void Create(); void Destroy(); ConCommand* c_SayLine; + ConCommand* c_Shutdown; }; #endif /* HSAYSPECIAL_H_ */