From 196c920ef9792a1c8cef167dc18b386a03d878d5 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Sat, 13 May 2017 12:25:11 +0300 Subject: [PATCH] pCritHack + reduced fps impact from it --- src/cvwrapper.h | 5 +++ src/hacks/Aimbot.cpp | 82 +++++++++++++++++++++++++------------------- src/hacks/ESP.cpp | 6 ++-- src/hacks/ESP.h | 8 ++--- src/hacks/Misc.cpp | 80 ++++++++++++++++++++++-------------------- 5 files changed, 101 insertions(+), 80 deletions(-) diff --git a/src/cvwrapper.h b/src/cvwrapper.h index 1a0e989a..093c833d 100644 --- a/src/cvwrapper.h +++ b/src/cvwrapper.h @@ -11,6 +11,7 @@ class ConVar; #include "sdk.h" +#include "interfaces.h" #include "beforecheaders.h" #include @@ -98,6 +99,10 @@ public: [[deprecated]] inline void SetValue(int value) { this->operator =(value); } + inline bool KeyDown() { + return g_IInputSystem->IsButtonDown((ButtonCode_t)((int)*this)); + } + bool restricted; float max; float min; diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index e06a3185..02f0d079 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -119,6 +119,8 @@ CachedEntity* CurrentTarget() { } int ClosestHitbox(CachedEntity* target) { + PROF_SECTION(CM_aimbot_closesthitbox); + // FIXME this will break multithreading if it will be ever implemented. When implementing it, these should be made non-static int closest; float closest_fov, fov; @@ -171,45 +173,48 @@ void CreateMove() { cur_proj_grav = (float)proj_gravity; // TODO priority modes (FOV, Smart, Distance, etc) target_highest_score = -256; - for (int i = 0; i < HIGHEST_ENTITY; i++) { - ent = ENTITY(i); - if (CE_BAD(ent)) continue; - tg = TargetState(ent); - if (tg == EAimbotTargetState::GOOD) { - if (GetWeaponMode() == weaponmode::weapon_melee || (int)priority_mode == 2) { - scr = 4096.0f - calculated_data_array[i].aim_position.DistTo(g_pLocalPlayer->v_Eye); - if (scr > target_highest_score) { - target_highest_score = scr; - target_highest = ent; + { + PROF_SECTION(CM_aimbot_finding_target); + for (int i = 0; i < HIGHEST_ENTITY; i++) { + ent = ENTITY(i); + if (CE_BAD(ent)) continue; + tg = TargetState(ent); + if (tg == EAimbotTargetState::GOOD) { + if (GetWeaponMode() == weaponmode::weapon_melee || (int)priority_mode == 2) { + scr = 4096.0f - calculated_data_array[i].aim_position.DistTo(g_pLocalPlayer->v_Eye); + if (scr > target_highest_score) { + target_highest_score = scr; + target_highest = ent; + } + } else { + switch ((int)priority_mode) { + case 0: { + scr = GetScoreForEntity(ent); + if (scr > target_highest_score) { + target_highest_score = scr; + target_highest = ent; + } + } break; + case 1: { + scr = 360.0f - calculated_data_array[ent->m_IDX].fov; + if (scr > target_highest_score) { + target_highest_score = scr; + target_highest = ent; + } + } break; + case 3: { + scr = 450.0f - ent->m_iHealth; + if (scr > target_highest_score) { + target_highest_score = scr; + target_highest = ent; + } + } + } } } else { - switch ((int)priority_mode) { - case 0: { - scr = GetScoreForEntity(ent); - if (scr > target_highest_score) { - target_highest_score = scr; - target_highest = ent; - } - } break; - case 1: { - scr = 360.0f - calculated_data_array[ent->m_IDX].fov; - if (scr > target_highest_score) { - target_highest_score = scr; - target_highest = ent; - } - } break; - case 3: { - scr = 450.0f - ent->m_iHealth; - if (scr > target_highest_score) { - target_highest_score = scr; - target_highest = ent; - } - } - } + //if (tg != 26) + // logging::Info("Shouldn't target ent %i %i", ent->m_IDX, tg); } - } else { - //if (tg != 26) - // logging::Info("Shouldn't target ent %i %i", ent->m_IDX, tg); } } if (huntsman_ticks) { @@ -221,6 +226,7 @@ void CreateMove() { state = EAimbotState::TARGET_FOUND; hacks::shared::esp::SetEntityColor(target_highest, colors::pink); if (local_state == EAimbotLocalState::GOOD) { + PROF_SECTION(CM_aimbot_aiming); last_target = target_highest->m_IDX; if (g_pLocalPlayer->weapon()->m_iClassID == g_pClassID->CTFCompoundBow) { // There is no Huntsman in TF2C. begincharge = CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flChargeBeginTime); @@ -578,6 +584,8 @@ float EffectiveShootingRange() { } EAimbotLocalState ShouldAim() { + PROF_SECTION(CM_aimbot_calc_localstate); + bool do_minigun_checks; int weapon_state; // Checks should be in order: cheap -> expensive @@ -654,6 +662,8 @@ EAimbotLocalState ShouldAim() { } int BestHitbox(CachedEntity* target) { + PROF_SECTION(CM_aimbot_besthitbox); + int preferred, ci, flags, bdmg; float cdmg; bool ground; diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index a050413e..64487361 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -230,7 +230,7 @@ void Draw3DBox(CachedEntity* ent, int clr, bool healthbar, int health, int healt static CatVar box_nodraw(CV_SWITCH, "esp_box_nodraw", "0", "Invisible 2D Box", "Don't draw 2D box"); static CatVar box_expand(CV_INT, "esp_box_expand", "0", "Expand 2D Box", "Expand 2D box by N units"); -void DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, bool healthbar, int health, int healthmax) { +void _FASTCALL DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, bool healthbar, int health, int healthmax) { PROF_SECTION(PT_esp_drawbox); Vector min, max, origin, so, omin, omax, smin, smax; float height, width, trf; @@ -307,7 +307,7 @@ void DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, boo } } -void ProcessEntity(CachedEntity* ent) { +void _FASTCALL ProcessEntity(CachedEntity* ent) { const model_t* model; int string_count_backup, level, pclass; bool shown; @@ -502,7 +502,7 @@ static CatVar box_healthbar(CV_SWITCH, "esp_box_healthbar", "1", "Box Healthbar" * According to profiler, this function is the most time-consuming (and gets called up to 200K times a second) */ -void ProcessEntityPT(CachedEntity* ent) { +void _FASTCALL ProcessEntityPT(CachedEntity* ent) { PROF_SECTION(PT_esp_process_entity); int fg, color; diff --git a/src/hacks/ESP.h b/src/hacks/ESP.h index f0de3270..3e08bcb9 100644 --- a/src/hacks/ESP.h +++ b/src/hacks/ESP.h @@ -72,15 +72,15 @@ public: extern std::array data; void ResetEntityStrings(); -void AddEntityString(CachedEntity* entity, const std::string& string, int color = 0x0) _FASTCALL; +void AddEntityString(CachedEntity* entity, const std::string& string, int color = 0x0); void SetEntityColor(CachedEntity* entity, int color); void CreateMove(); void Draw(); -void DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, bool healthbar, int health, int healthmax) _FASTCALL; -void ProcessEntity(CachedEntity* ent) _FASTCALL; -void ProcessEntityPT(CachedEntity* ent) _FASTCALL; +void __attribute__((fastcall)) DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, bool healthbar, int health, int healthmax); +void __attribute__((fastcall)) ProcessEntity(CachedEntity* ent); +void __attribute__((fastcall)) ProcessEntityPT(CachedEntity* ent); }}} diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index d861f424..e06f98c2 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -148,34 +148,31 @@ void CreateMove() { no_taunt_ticks--; } // TODO FIXME this should be moved out of here - localplayer = g_IEntityList->GetClientEntity(g_IEngine->GetLocalPlayer()); - if (localplayer && spycrab_mode) { - void** vtable = *(void***)(localplayer); - if (vtable[0x111] != StartSceneEvent_hooked) { - StartSceneEvent_original = (StartSceneEvent_t)vtable[0x111]; - void* page = (void*)((uintptr_t)vtable &~ 0xFFF); - mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); - vtable[0x111] = (void*)StartSceneEvent_hooked; - mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); + { + PROF_SECTION(CM_misc_hook_checks); + localplayer = g_IEntityList->GetClientEntity(g_IEngine->GetLocalPlayer()); + if (localplayer && spycrab_mode) { + void** vtable = *(void***)(localplayer); + if (vtable[0x111] != StartSceneEvent_hooked) { + StartSceneEvent_original = (StartSceneEvent_t)vtable[0x111]; + void* page = (void*)((uintptr_t)vtable &~ 0xFFF); + mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); + vtable[0x111] = (void*)StartSceneEvent_hooked; + mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); + } + } + if (TF && render_zoomed && localplayer) { + // Patchking local player + void** vtable = *(void***)(localplayer); + if (vtable[offsets::ShouldDraw()] != C_TFPlayer__ShouldDraw_hook) { + C_TFPlayer__ShouldDraw_original = vtable[offsets::ShouldDraw()]; + void* page = (void*)((uintptr_t)vtable &~ 0xFFF); + mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); + vtable[offsets::ShouldDraw()] = (void*)C_TFPlayer__ShouldDraw_hook; + mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); + } } } - if (TF && render_zoomed && localplayer) { - // Patchking local player - void** vtable = *(void***)(localplayer); - if (vtable[offsets::ShouldDraw()] != C_TFPlayer__ShouldDraw_hook) { - C_TFPlayer__ShouldDraw_original = vtable[offsets::ShouldDraw()]; - void* page = (void*)((uintptr_t)vtable &~ 0xFFF); - mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); - vtable[offsets::ShouldDraw()] = (void*)C_TFPlayer__ShouldDraw_hook; - mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); - } - } - - /*(if (TF2 && remove_conditions) { - RemoveCondition(LOCAL_E, TFCond_CloakFlicker); - RemoveCondition(LOCAL_E, TFCond_Jarated); - CE_FLOAT(LOCAL_E, netvar.m_flStealthNoAttackExpire) = 0.0f; - }*/ if (TF2C && tauntslide) RemoveCondition(LOCAL_E); @@ -183,10 +180,15 @@ void CreateMove() { if (g_pUserCmd->command_number && found_crit_number > g_pUserCmd->command_number + 66 * 20) found_crit_number = 0; if (g_pUserCmd->command_number) last_number = g_pUserCmd->command_number; - if (crit_hack_next && TF2 && CE_GOOD(LOCAL_W)) { + + static int last_checked_command_number = 0; + static IClientEntity* last_checked_weapon = nullptr; + + if (crit_hack_next && TF2 && CE_GOOD(LOCAL_W) && WeaponCanCrit() && RandomCrits()) { + PROF_SECTION(CM_misc_crit_hack_prediction); weapon = RAW_ENT(LOCAL_W); if (vfunc(weapon, 1944 / 4, 0)(weapon)) { - if (g_IInputSystem->IsButtonDown((ButtonCode_t)((int)experimental_crit_hack))) { + if (experimental_crit_hack.KeyDown()) { if (!g_pUserCmd->command_number || critWarmup < 8) { if (g_pUserCmd->buttons & IN_ATTACK) { critWarmup++; @@ -196,7 +198,7 @@ void CreateMove() { g_pUserCmd->buttons &= ~(IN_ATTACK); } } - if (g_pUserCmd->command_number && (found_crit_weapon != weapon || found_crit_number < g_pUserCmd->command_number)) { + 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"); g_PredictionRandomSeed = *reinterpret_cast(sig + (uintptr_t)32); @@ -221,26 +223,30 @@ void CreateMove() { cmdn++; } } + last_checked_command_number = cmdn; + last_checked_weapon = weapon; state.Load(weapon); if (chc) { found_crit_weapon = weapon; found_crit_number = cmdn; - //logging::Info("Found crit at: %i, original: %i", cmdn, g_pUserCmd->command_number); - if (g_IInputSystem->IsButtonDown((ButtonCode_t)((int)experimental_crit_hack))) { - //if (g_pUserCmd->buttons & IN_ATTACK) - command_number_mod[g_pUserCmd->command_number] = cmdn; - } - //*(int*)(sharedobj::engine->Pointer(0x00B6C91C)) = cmdn - 1; } - //if (!crits) *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u) = bucket; + } + if (g_pUserCmd->buttons & (IN_ATTACK)) { + if (found_crit_weapon == weapon && g_pUserCmd->command_number < found_crit_number) { + if (g_IInputSystem->IsButtonDown((ButtonCode_t)((int)experimental_crit_hack))) { + command_number_mod[g_pUserCmd->command_number] = cmdn; + } + } } } } { + PROF_SECTION(CM_misc_crit_hack_apply); if (!AllowAttacking()) g_pUserCmd->buttons &= ~IN_ATTACK; } if (CE_GOOD(LOCAL_W)) { + PROF_SECTION(CM_misc_crit_hack_bucket_fixing); weapon = RAW_ENT(LOCAL_W); float& bucket = *(float*)((uintptr_t)(weapon) + 2612); if (g_pUserCmd->command_number) { @@ -280,7 +286,7 @@ void Draw() { if (!vfunc(RAW_ENT(LOCAL_W), 465, 0)(RAW_ENT(LOCAL_W))) AddCenterString("Random crits are disabled", colors::yellow); else { - if (!vfunc(RAW_ENT(LOCAL_W), 465 + 21, 0)(RAW_ENT(LOCAL_W))) + if (!WeaponCanCrit()) AddCenterString("Weapon can't randomly crit", colors::yellow); else AddCenterString("Weapon can randomly crit");