From 77a939426f6460488653e9fab7175de698fbb6e8 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 24 Nov 2017 09:22:50 +0300 Subject: [PATCH] crithack progress --- include/crits.hpp | 25 +---- include/reclasses/C_TFWeaponBase.hpp | 2 +- include/sdk/CGameRules.h | 2 +- src/crits.cpp | 152 +++++++-------------------- 4 files changed, 42 insertions(+), 139 deletions(-) diff --git a/include/crits.hpp b/include/crits.hpp index 4d5d159c..11158e47 100644 --- a/include/crits.hpp +++ b/include/crits.hpp @@ -11,6 +11,7 @@ class CUserCmd; class IClientEntity; +// BUGBUG TODO this struct is outdated struct crithack_saved_state { float bucket; // 2612 bool unknown2831; @@ -24,41 +25,23 @@ struct crithack_saved_state { void Load(IClientEntity* entity); }; -extern bool weapon_can_crit_last; - -extern CatVar crit_hack_next; extern CatVar crit_info; -extern CatVar crit_hack; +extern CatVar crit_key; extern CatVar crit_melee; -extern CatVar crit_suppress; namespace criticals { -void unfuck_bucket(); -bool force_crit(); +void create_move(); +bool random_crits_enabled(); } -bool CritKeyDown(); -bool AllowAttacking(); -bool RandomCrits(); -bool WeaponCanCrit(); -bool IsAttackACrit(CUserCmd* cmd); -void ResetCritHack(); -void LoadSavedState(); -void ModifyCommandNumber(); - #include #include #include -class CatVar; -extern CatVar experimental_crit_hack; extern int* g_PredictionRandomSeed; extern std::unordered_map command_number_mod; -//bool CalcIsAttackCritical(IClientEntity* weapon); - - #endif /* CRITS_HPP_ */ diff --git a/include/reclasses/C_TFWeaponBase.hpp b/include/reclasses/C_TFWeaponBase.hpp index 28e63072..39a4a04f 100644 --- a/include/reclasses/C_TFWeaponBase.hpp +++ b/include/reclasses/C_TFWeaponBase.hpp @@ -55,7 +55,7 @@ public: // *(int *)(self + 2872) = g_GlobalVars->framecount; // *(char *)(self + 2839) = 0; - if (g_pGameRules->critmode == 5 || + if (g_pGameRules->roundmode == 5 && g_pGameRules->winning_team == NET_INT(owner, netvar.iTeamNum)) { // *(char *)(self + 2838) = 1; diff --git a/include/sdk/CGameRules.h b/include/sdk/CGameRules.h index 47120b0b..24bd3306 100644 --- a/include/sdk/CGameRules.h +++ b/include/sdk/CGameRules.h @@ -11,7 +11,7 @@ class CGameRules { public: int unknown_pad_0[12]; - int critmode; + int roundmode; int unknown_pad_1[1]; int winning_team; }; diff --git a/src/crits.cpp b/src/crits.cpp index b2976487..a5bbbdfc 100644 --- a/src/crits.cpp +++ b/src/crits.cpp @@ -8,15 +8,11 @@ #include "common.hpp" #include -CatVar crit_hack_next(CV_SWITCH, "crit_hack_next", "0", "Next crit info"); -CatVar crit_info(CV_SWITCH, "crit_info", "0", "Show crit info"); // TODO separate -CatVar crit_hack(CV_KEY, "crit_hack", "0", "Crit Key"); +CatVar crit_info(CV_SWITCH, "crit_info", "0", "Show crit info"); +CatVar crit_key(CV_KEY, "crit_key", "0", "Crit Key"); CatVar crit_melee(CV_SWITCH, "crit_melee", "0", "Melee crits"); -CatVar crit_suppress(CV_SWITCH, "crit_suppress", "0", "Disable random crits", "Can help saving crit bucket for forced crits"); -CatVar experimental_crit_hack(CV_KEY, "crit_hack_experimental", "0", "Unstable Crit Hack", "Experimental crit hack, use this **OR** old crit hack, do not use both!\nNEEDS NEXT CRIT INFO TO BE ACTIVE!"); std::unordered_map command_number_mod {}; - int* g_PredictionRandomSeed = nullptr; namespace criticals @@ -74,51 +70,49 @@ void unfuck_bucket(IClientEntity *weapon) last_bucket = bucket; } -bool force_crit() +struct cached_calculation_s { + int command_number; + int weapon_entity; +}; +cached_calculation_s cached_calculation {}; + +bool force_crit(IClientEntity *weapon) +{ + if (cached_calculation.weapon_entity == weapon->entindex()) + return bool(cached_calculation.command_number); + + int number = find_next_random_crit_for_weapon(weapon); + + cached_calculation.command_number = number; + cached_calculation.weapon_entity = LOCAL_W->m_IDX; return false; } +void create_move() +{ + if (!random_crits_enabled()) + return; + if (CE_BAD(LOCAL_W)) + return; + IClientEntity *weapon = RAW_ENT(LOCAL_W); + if (!re::C_TFWeaponBase::IsBaseCombatWeapon(weapon)) + return; + if (!re::C_TFWeaponBase::AreRandomCritsEnabled(weapon)) + return; + unfuck_bucket(weapon); + if (crit_key.KeyDown()) + { + force_crit(weapon); + } } -bool CritKeyDown() { - return g_IInputSystem->IsButtonDown(static_cast((int)hacks::shared::misc::crit_hack));// || g_IInputSystem->IsButtonDown(static_cast((int)experimental_crit_hack)); +bool random_crits_enabled() { + static ConVar* tf_weapon_criticals = g_ICvar->FindVar("tf_weapon_criticals"); + return tf_weapon_criticals->GetBool(); } -bool AllowAttacking() { - return true; - /* - if (!(CritKeyDown() || ((GetWeaponMode() == weapon_melee) && hacks::shared::misc::crit_melee)) && !hacks::shared::misc::crit_suppress) return true; - bool crit = IsAttackACrit(g_pUserCmd); - LoadSavedState(); - if (hacks::shared::misc::crit_suppress && !(CritKeyDown() || ((GetWeaponMode() == weapon_melee) && hacks::shared::misc::crit_melee))) { - if (crit && !IsPlayerCritBoosted(LOCAL_E)) { - return false; - } - } else if ((CritKeyDown() || ((GetWeaponMode() == weapon_melee) && hacks::shared::misc::crit_melee)) && RandomCrits() && WeaponCanCrit() && (g_pLocalPlayer->weapon()->m_iClassID != CL_CLASS(CTFKnife))) { - if (!crit) return false; - } - return true;*/ -} - -void ModifyCommandNumber() { - -} - -bool RandomCrits() { - static ConVar* tf_weapon_criticals = g_ICvar->FindVar("tf_weapon_criticals"); - return tf_weapon_criticals->GetBool(); -} - -bool weapon_can_crit_last = false; - -bool WeaponCanCrit() { - IF_GAME (!IsTF()) return false; - if (CE_BAD(LOCAL_W)) return false; - IClientEntity* weapon = RAW_ENT(LOCAL_W); - weapon_can_crit_last = vfunc(weapon, 190, 0)(weapon) && vfunc(weapon, 465 + 21, 0)(weapon); - return weapon_can_crit_last; } void crithack_saved_state::Load(IClientEntity* entity) { @@ -142,77 +136,3 @@ void crithack_saved_state::Save(IClientEntity* entity) { unknown2856 = *(float*)((uintptr_t)entity + 2856); unknown2860 = *(float*)((uintptr_t)entity + 2860); } - -static crithack_saved_state state; -static bool state_saved { false }; -void LoadSavedState() { - // TODO TF2C Crit Hack - IF_GAME (!IsTF2()) return; - if (!state_saved) return; - if (CE_GOOD(LOCAL_W)) { - IClientEntity* weapon = RAW_ENT(LOCAL_W); - state.Load(weapon); - } -} -void ResetCritHack() { - state_saved = false; -} - -bool IsAttackACrit(CUserCmd* cmd) { - // TODO TF2C Crit Hack - IF_GAME (!IsTF2()) return false; - if (CE_GOOD(LOCAL_W)) { - IClientEntity* weapon = RAW_ENT(LOCAL_W); - /*if (TF2C) { - if (vfunc(weapon, 1824 / 4, 0)(weapon)) { - static uintptr_t CalcIsAttackCritical_s = gSignatures.GetClientSignature("55 89 E5 56 53 83 EC 10 8B 5D 08 89 1C 24 E8 ? ? ? ? 85 C0 89 C6 74 59 8B 00 89 34 24 FF 90 E0 02 00 00 84 C0 74 4A A1 ? ? ? ? 8B 40 04 3B 83 A8 09 00 00 74 3A"); - typedef void(*CalcIsAttackCritical_t)(IClientEntity*); - CalcIsAttackCritical_t CIACFn = (CalcIsAttackCritical_t)(CalcIsAttackCritical_s); - *(float*)((uintptr_t)weapon + 2468ul) = 0.0f; - int tries = 0; - static int lcmdn = 0; - if (*(bool*)((uintptr_t)RAW_ENT(LOCAL_W) + 2454ul)) return true; - static int& seed = *(int*)(sharedobj::client->lmap->l_addr + 0x00D53F68ul); - bool cmds = false; - seed = MD5_PseudoRandom(cmd->command_number) & 0x7fffffff; - RandomSeed(seed); - CIACFn(RAW_ENT(LOCAL_W)); - return *(bool*)((uintptr_t)RAW_ENT(LOCAL_W) + 2454ul); - } - } else if (TF2) */ - { - if (vfunc(weapon, 1944 / 4, 0)(weapon)) { - static uintptr_t CalcIsAttackCritical_s = gSignatures.GetClientSignature("55 89 E5 83 EC 28 89 5D F4 8B 5D 08 89 75 F8 89 7D FC 89 1C 24 E8 ? ? ? ? 85 C0 89 C6 74 60 8B 00 89 34 24 FF 90 E0 02 00 00 84 C0 74 51 A1 ? ? ? ? 8B 40 04"); - typedef void(*CalcIsAttackCritical_t)(IClientEntity*); - CalcIsAttackCritical_t CIACFn = (CalcIsAttackCritical_t)(CalcIsAttackCritical_s); - if (cmd->command_number) { - int tries = 0; - static int cmdn = 0; - bool chc = false; - int md5seed = MD5_PseudoRandom(cmd->command_number) & 0x7fffffff; - int rseed = md5seed; - //float bucket = *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u); - - *g_PredictionRandomSeed = md5seed; - int c = LOCAL_W->m_IDX << 8; - int b = LOCAL_E->m_IDX; - rseed = rseed ^ (b | c); - RandomSeed(rseed); - if (GetWeaponMode() == weapon_melee) { - *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u) = 1000.0f; - } - state.Save(weapon); - - state_saved = true; - //float saved_time = *(float*)(weapon + 2872ul); - //*(float*)(weapon + 2872ul) = 0.0f; - bool crits = vfunc(weapon, 1836 / 4, 0)(weapon); - //*(float*)(weapon + 2872ul) = saved_time; - //if (!crits) *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u) = bucket; - return crits; - } - } - } - } - return false; -}