From e203806dc28dd558868182e2473bf3e3413003ed Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Sun, 14 May 2017 13:57:48 +0300 Subject: [PATCH] improved triggerbot, crit hack still crashes the game --- src/crits.cpp | 6 ++- src/crits.h | 2 + src/gui/ncc/CritIndicator.cpp | 9 ++-- src/hacks/Misc.cpp | 14 ++++-- src/hacks/Misc.h | 2 + src/hacks/Trigger.cpp | 89 +++++++++++++++++++++++++---------- src/hacks/Trigger.h | 2 +- src/hooks/others.cpp | 2 +- 8 files changed, 88 insertions(+), 38 deletions(-) diff --git a/src/crits.cpp b/src/crits.cpp index 032f35bd..80db83db 100644 --- a/src/crits.cpp +++ b/src/crits.cpp @@ -45,9 +45,13 @@ bool RandomCrits() { return tf_weapon_criticals->GetBool(); } +bool weapon_can_crit_last = false; + bool WeaponCanCrit() { IF_GAME (!IsTF()) return false; - return CE_GOOD(LOCAL_W) && vfunc(RAW_ENT(LOCAL_W), 465 + 21, 0)(RAW_ENT(LOCAL_W)); + IClientEntity* weapon = RAW_ENT(LOCAL_W); + weapon_can_crit_last = CE_GOOD(LOCAL_W) && vfunc(weapon, 190, 0)(weapon) && vfunc(weapon, 465 + 21, 0)(weapon); + return weapon_can_crit_last; } void crithack_saved_state::Load(IClientEntity* entity) { diff --git a/src/crits.h b/src/crits.h index cd40cb63..f6301341 100644 --- a/src/crits.h +++ b/src/crits.h @@ -24,6 +24,8 @@ struct crithack_saved_state { void Load(IClientEntity* entity); }; +extern bool weapon_can_crit_last; + bool CritKeyDown(); bool AllowAttacking(); bool RandomCrits(); diff --git a/src/gui/ncc/CritIndicator.cpp b/src/gui/ncc/CritIndicator.cpp index 90f30597..c69b2ec7 100644 --- a/src/gui/ncc/CritIndicator.cpp +++ b/src/gui/ncc/CritIndicator.cpp @@ -34,7 +34,8 @@ void CritIndicator::Draw(int x, int y) { if (!crit_ready.id) crit_ready.Load(); Texture* tx = &crit_none; bool critkey { false }; - if (RandomCrits() && WeaponCanCrit()) { + bool crits { false }; + if (RandomCrits() && weapon_can_crit_last) { // It's safe to be 1 tick behind real values to prevent flickering. if (hacks::shared::misc::found_crit_number >= hacks::shared::misc::last_number - 1 && hacks::shared::misc::found_crit_weapon == RAW_ENT(LOCAL_W)) { tx = &crit_normal; @@ -42,6 +43,7 @@ void CritIndicator::Draw(int x, int y) { tx = &crit_ready; critkey = true; } + crits = true; } } else { tx = &crit_disabled; @@ -50,9 +52,8 @@ void CritIndicator::Draw(int x, int y) { tx->Draw(x, y, 64, 64); draw::OutlineRect(x, y, 64, 72, critkey ? colors::pink : GUIColor()); draw::DrawLine(x, y + 64, 64, 0, critkey ? colors::pink : GUIColor()); - if (CE_GOOD(LOCAL_W)) { - float bucket = *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u); - draw::DrawRect(x + 1, y + 65, 62.0f * (bucket / 1000.0f), 6, colors::Create(20, 235, 20, 255)); + if (crits) { + draw::DrawRect(x + 1, y + 65, 1 + 61.0f * (hacks::shared::misc::last_bucket / 1000.0f), 6, (!crits) ? colors::Create(235, 20, 20, 255) : colors::Create(20, 235, 20, 255)); } } diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index b6cc5f54..3b22d04a 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -131,6 +131,8 @@ int StartSceneEvent_hooked(IClientEntity* _this, int sceneInfo, int choreoScene, return StartSceneEvent_original(_this, sceneInfo, choreoScene, choreoEvent, choreoActor, unknown); } +float last_bucket = 0; + void CreateMove() { static bool flswitch = false; static IClientEntity *localplayer, *weapon, *last_weapon = nullptr; @@ -138,7 +140,6 @@ void CreateMove() { static int tries, cmdn, md5seed, rseed, c, b; static crithack_saved_state state; static bool chc; - static float last_bucket = 0.0f; static bool changed = false; static ConVar *pNoPush = g_ICvar->FindVar("tf_avoidteammates_pushaway"); @@ -189,8 +190,10 @@ void CreateMove() { if (crit_hack_next && CE_GOOD(LOCAL_W) && WeaponCanCrit() && RandomCrits()) { PROF_SECTION(CM_misc_crit_hack_prediction); weapon = RAW_ENT(LOCAL_W); - if (weapon && vfunc(weapon, 1944 / 4, 0)(weapon)) { - if (experimental_crit_hack.KeyDown()) { + // IsBaseCombatWeapon + if (weapon && + vfunc(weapon, 1944 / 4, 0)(weapon)) { + /*if (experimental_crit_hack.KeyDown()) { if (!g_pUserCmd->command_number || critWarmup < 8) { if (g_pUserCmd->buttons & IN_ATTACK) { critWarmup++; @@ -199,7 +202,7 @@ void CreateMove() { } g_pUserCmd->buttons &= ~(IN_ATTACK); } - } + }*/ if (g_pUserCmd->command_number && (last_checked_weapon != weapon || last_checked_command_number < g_pUserCmd->command_number)) { if (!g_PredictionRandomSeed) { uintptr_t sig = gSignatures.GetClientSignature("89 1C 24 D9 5D D4 FF 90 3C 01 00 00 89 C7 8B 06 89 34 24 C1 E7 08 FF 90 3C 01 00 00 09 C7 33 3D ? ? ? ? 39 BB 34 0B 00 00 74 0E 89 BB 34 0B 00 00 89 3C 24 E8 ? ? ? ? C7 44 24 04 0F 27 00 00"); @@ -228,6 +231,7 @@ void CreateMove() { last_checked_command_number = cmdn; last_checked_weapon = weapon; state.Load(weapon); + last_bucket = state.bucket; if (chc) { found_crit_weapon = weapon; found_crit_number = cmdn; @@ -249,7 +253,7 @@ void CreateMove() { if (!AllowAttacking()) g_pUserCmd->buttons &= ~IN_ATTACK; } - if (CE_GOOD(LOCAL_W)) { + if (WeaponCanCrit()) { PROF_SECTION(CM_misc_crit_hack_bucket_fixing); weapon = RAW_ENT(LOCAL_W); float& bucket = *(float*)((uintptr_t)(weapon) + 2612); diff --git a/src/hacks/Misc.h b/src/hacks/Misc.h index a8c84833..cd605314 100644 --- a/src/hacks/Misc.h +++ b/src/hacks/Misc.h @@ -40,6 +40,8 @@ extern CatCommand schema; extern CatCommand disconnect_vac; extern CatCommand set_value; +extern float last_bucket; + }}} /*class Misc : public IHack { diff --git a/src/hacks/Trigger.cpp b/src/hacks/Trigger.cpp index 9d103516..c25d5e32 100644 --- a/src/hacks/Trigger.cpp +++ b/src/hacks/Trigger.cpp @@ -25,16 +25,59 @@ CatEnum hitbox_enum({ "KNEE R", "FOOT R" }, -1); CatVar hitbox(hitbox_enum, "trigger_hitbox", "-1", "Hitbox", "Triggerbot hitbox. Only useful settings are ANY and HEAD. Use ANY for scatter or any other shotgun-based weapon, HEAD for ambassador/sniper rifle"); -CatVar bodyshot(CV_SWITCH, "trigger_bodyshot", "1", "Bodyshot", "Triggerbot will bodyshot enemies if you have enough charge to 1tap them"); +CatVar allow_bodyshot(CV_SWITCH, "trigger_bodyshot", "1", "Bodyshot", "Triggerbot will bodyshot enemies if you have enough charge to 1tap them"); CatVar finishing_hit(CV_SWITCH, "trigger_finish", "1", "Noscope weak enemies", "If enemy has <50 HP, noscope them"); CatVar max_range(CV_INT, "trigger_range", "0", "Max range", "Triggerbot won't shoot if enemy is too far away", true, 4096.0f); CatVar buildings(CV_SWITCH, "trigger_buildings", "1", "Trigger at buildings", "Shoot buildings"); CatVar ignore_vaccinator(CV_SWITCH, "trigger_respect_vaccinator", "1", "Respect vaccinator", "Don't shoot at bullet-vaccinated enemies"); CatVar ambassador(CV_SWITCH, "trigger_ambassador", "1", "Smart Ambassador", "Don't shoot if your ambassador can't headshot yet (Keep that enabled!)"); -CatVar accuracy(CV_SWITCH, "trigger_accuracy", "0", "Improve accuracy (NOT WORKING)", "Might cause more lag (NOT WORKING YET!)"); +CatVar accuracy(CV_INT, "trigger_accuracy", "0", "Improve accuracy", "Improves triggerbot accuracy when aiming for specific hitbox"); trace_t trace_object; +// TEMPORARY CODE. +// TODO + +bool GetIntersection(float fDst1, float fDst2, Vector P1, Vector P2, Vector& Hit) { + if ((fDst1 * fDst2) >= 0.0f) return false; + if (fDst1 == fDst2) return false; + Hit = P1 + (P2 - P1) * (-fDst1 / (fDst2 - fDst1)); + return true; +} + +bool InBox(Vector Hit, Vector B1, Vector B2, int Axis) { + if (Axis == 1 && Hit.z > B1.z && Hit.z < B2.z && Hit.y > B1.y && Hit.y < B2.y) return true; + if (Axis == 2 && Hit.z > B1.z && Hit.z < B2.z && Hit.x > B1.x && Hit.x < B2.x) return true; + if (Axis == 3 && Hit.x > B1.x && Hit.x < B2.x && Hit.y > B1.y && Hit.y < B2.y) return true; + return false; +} + +bool CheckLineBox(Vector B1, Vector B2, Vector L1, Vector L2, Vector& Hit) { + if (L2.x < B1.x && L1.x < B1.x) return false; + if (L2.x > B2.x && L1.x > B2.x) return false; + if (L2.y < B1.y && L1.y < B1.y) return false; + if (L2.y > B2.y && L1.y > B2.y) return false; + if (L2.z < B1.z && L1.z < B1.z) return false; + if (L2.z > B2.z && L1.z > B2.z) return false; + if (L1.x > B1.x && L1.x < B2.x && + L1.y > B1.y && L1.y < B2.y && + L1.z > B1.z && L1.z < B2.z) + { + Hit = L1; + return true; + } + if ((GetIntersection(L1.x - B1.x, L2.x - B1.x, L1, L2, Hit) && InBox(Hit, B1, B2, 1)) + || (GetIntersection(L1.y - B1.y, L2.y - B1.y, L1, L2, Hit) && InBox(Hit, B1, B2, 2)) + || (GetIntersection(L1.z - B1.z, L2.z - B1.z, L1, L2, Hit) && InBox(Hit, B1, B2, 3)) + || (GetIntersection(L1.x - B2.x, L2.x - B2.x, L1, L2, Hit) && InBox(Hit, B1, B2, 1)) + || (GetIntersection(L1.y - B2.y, L2.y - B2.y, L1, L2, Hit) && InBox(Hit, B1, B2, 2)) + || (GetIntersection(L1.z - B2.z, L2.z - B2.z, L1, L2, Hit) && InBox(Hit, B1, B2, 3))) + return true; + + return false; +} + + void CreateMove() { if (!enabled) return; if (GetWeaponMode() != weapon_hitscan) return; @@ -99,7 +142,7 @@ void CreateMove() { do_bodyshot = true; } // If we need charge... - if (!bodyshot && bodyshot) { + if (!allow_bodyshot) { float bdmg = CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flChargedDamage); if (CanHeadshot() && (bdmg) >= health) { do_bodyshot = true; @@ -111,33 +154,27 @@ void CreateMove() { !((g_pLocalPlayer->bZoomed) && CanHeadshot())) { return; } - //debug->AddBoxOverlay(enemy_trace->endpos, Vector(-1.0f, -1.0f, -1.0f), Vector(1.0f, 1.0f, 1.0f), QAngle(0, 0, 0), 255, 0, 0, 255, 2.0f); - //IClientEntity* weapon; + CachedHitbox* hb = entity->hitboxes.GetHitbox(trace_object.hitbox); - //logging::Info("hitbox: %i 0x%08x", enemy_trace->hitbox, hb); - /*if (v_bImproveAccuracy->GetBool()) { - if (hb) { - Vector siz = hb->max - hb->min; - Vector mns = hb->min + siz * 0.2f; - Vector mxs = hb->max - siz * 0.2f; - g_IVDebugOverlay->AddLineOverlay(enemy_trace->startpos, forward, 0, 0, 255, true, -1.0f); - if (LineIntersectsBox(mns, mxs, enemy_trace->startpos, forward)) { - g_IVDebugOverlay->AddBoxOverlay(mns, Vector(0, 0, 0), mxs - mns, QAngle(0, 0, 0), 0, 255, 0, 255, 1.0f); - g_IVDebugOverlay->AddLineOverlay(enemy_trace->startpos, forward, 255, 0, 0, true, 1.0f); - //logging::Info("%.2f %.2f %.2f", hb->center.DistToSqr(enemy_trace->endpos), SQR(hb->min.DistToSqr(hb->min)), SQR(hb->min.DistToSqr(hb->min) * 0.9f)); - - } else { - g_IVDebugOverlay->AddBoxOverlay(hb->min, Vector(0, 0, 0), hb->max - hb->min, QAngle(0, 0, 0), 0, 255, 255, 255, -1.0f); - g_IVDebugOverlay->AddBoxOverlay(mns, Vector(0, 0, 0), mxs - mns, QAngle(0, 0, 0), 255, 255, 0, 255, 0.5f); - return; - } - } else return; - }*/ - if ((int)hitbox >= 0 && !bodyshot) { + if ((int)hitbox >= 0 && !do_bodyshot) { if (trace_object.hitbox != (int)hitbox) return; } - g_pUserCmd->buttons |= IN_ATTACK; + + if (accuracy && hb) { + Vector minz(min(hb->min.x, hb->max.x), min(hb->min.y, hb->max.y), min(hb->min.z, hb->max.z)); + Vector maxz(max(hb->min.x, hb->max.x), max(hb->min.y, hb->max.y), max(hb->min.z, hb->max.z)); + Vector size = maxz - minz; + Vector smod = size * 0.05f * (int)accuracy; + minz += smod; + maxz -= smod; + Vector hit; + if (CheckLineBox(minz, maxz, g_pLocalPlayer->v_Eye, forward, hit)) { + g_pUserCmd->buttons |= IN_ATTACK; + } + } else { + g_pUserCmd->buttons |= IN_ATTACK; + } } void Draw() { diff --git a/src/hacks/Trigger.h b/src/hacks/Trigger.h index 00d34605..41a87785 100644 --- a/src/hacks/Trigger.h +++ b/src/hacks/Trigger.h @@ -18,7 +18,7 @@ extern CatVar enabled; extern CatVar respect_cloak; // TODO move to Targeting extern CatVar zoomed_only; extern CatVar hitbox; -extern CatVar bodyshot; +extern CatVar allow_bodyshot; extern CatVar finishing_hit; extern CatVar max_range; extern CatVar buildings; diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index d634a96b..0fe4e42e 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -196,7 +196,7 @@ const char* GetFriendPersonaName_hook(ISteamFriends* _this, CSteamID steamID) { return original(_this, steamID); } -static CatVar cursor_fix_experimental(CV_SWITCH, "experimental_cursor_fix", "0", "Cursor fix"); +static CatVar cursor_fix_experimental(CV_SWITCH, "experimental_cursor_fix", "1", "Cursor fix"); void FrameStageNotify_hook(void* _this, int stage) { static IClientEntity *ent;