From 69e2d7ae8a71080012be1b3d002cd6fd3c001617 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 17 Mar 2017 17:30:58 +0300 Subject: [PATCH] improved airstuck? added achievement safety switch. --- src/cvwrapper.cpp | 14 +++++++++----- src/cvwrapper.h | 4 ++-- src/globals.cpp | 1 + src/globals.h | 2 ++ src/hack.cpp | 4 ---- src/hacks/Achievement.cpp | 37 +++++++++++++++++++------------------ src/hacks/Achievement.h | 17 ++++------------- src/hacks/Airstuck.cpp | 37 +++++++++++++++++++------------------ src/hacks/Airstuck.h | 16 +++++++--------- src/helpers.cpp | 3 ++- src/hooks/CreateMove.cpp | 3 ++- src/hooks/others.cpp | 6 +++--- 12 files changed, 70 insertions(+), 74 deletions(-) diff --git a/src/cvwrapper.cpp b/src/cvwrapper.cpp index c887a34e..a916e709 100644 --- a/src/cvwrapper.cpp +++ b/src/cvwrapper.cpp @@ -33,11 +33,15 @@ CatCommand::CatCommand(std::string name, std::string help, FnCommandCallbackVoid } void CatCommand::Register() { - char name_c[256] = { 0 }; - char help_c[256] = { 0 }; - strcpy(name_c, name.c_str()); - strcpy(help_c, help.c_str()); - cmd = new ConCommand(name_c, callback ? callback : callback_void, help_c); + char* name_c = new char[256]; + char* help_c = new char[256]; + strncpy(name_c, (CON_PREFIX + name).c_str(), 255); + strncpy(help_c, help.c_str(), 255); + if (callback) cmd = new ConCommand(name_c, callback, help_c); + else if (callback_void) cmd = new ConCommand(name_c, callback_void, help_c); + else throw std::logic_error("no callback in CatCommand"); + interfaces::cvar->RegisterConCommand(cmd); + // name_c and help_c are not freed because ConCommandBase doesn't copy them } void RegisterCatCommands() { diff --git a/src/cvwrapper.h b/src/cvwrapper.h index eb328f36..a92d5ba2 100644 --- a/src/cvwrapper.h +++ b/src/cvwrapper.h @@ -67,9 +67,9 @@ void RegisterCatCommands(); class CatVar { public: [[deprecated]] - CatVar(CatVar_t type, std::string name, std::string value, std::string help, CatEnum* enum_type = 0, std::string long_description = "no description", bool hasminmax = false, float max = 1.0f, float min = 0.0f); + CatVar(CatVar_t type, std::string name, std::string value, std::string help, CatEnum* enum_type, std::string long_description = "no description", bool hasminmax = false, float max = 1.0f, float min = 0.0f); - CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long); + CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long = "no description"); CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float max_val); CatVar(CatVar_t type, std::string name, std::string defaults, std::string desc_short, std::string desc_long, float min_val, float max_val); CatVar(CatEnum& cat_enum, std::string name, std::string defaults, std::string desc_short, std::string desc_long); diff --git a/src/globals.cpp b/src/globals.cpp index 46b62317..21a9ebbf 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -41,6 +41,7 @@ void GlobalSettings::Init() { bInvalid = true; } +CUserCmd* g_pUserCmd = nullptr; const char* g_pszTFPath = 0; GlobalSettings g_Settings; diff --git a/src/globals.h b/src/globals.h index c828be87..8dd635ca 100644 --- a/src/globals.h +++ b/src/globals.h @@ -38,6 +38,8 @@ public: bool bInvalid; }; +class CUserCmd; +extern CUserCmd* g_pUserCmd; extern const char* g_pszTFPath; extern GlobalSettings g_Settings; diff --git a/src/hack.cpp b/src/hack.cpp index 949a1268..320363ec 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -66,13 +66,11 @@ void hack::InitHacks() { ADD_HACK(ESP); ADD_HACK(Triggerbot); if (TF) ADD_HACK(AutoSticky); - ADD_HACK(Airstuck); if (TF) ADD_HACK(AutoHeal); if (TF) ADD_HACK(SpyAlert); if (TF2) ADD_HACK(Glow); ADD_HACK(KillSay); ADD_HACK(Spam); - if (TF) ADD_HACK(AchievementHack); if (TF2) ADD_HACK(Noisemaker); } @@ -205,12 +203,10 @@ void hack::Shutdown() { DELETE_HACK(ESP); DELETE_HACK(Triggerbot); if (TF) DELETE_HACK(AutoSticky); - DELETE_HACK(Airstuck); if (TF) DELETE_HACK(AutoHeal); DELETE_HACK(SpyAlert); if (TF) DELETE_HACK(Glow); DELETE_HACK(KillSay); - if (TF) DELETE_HACK(AchievementHack); if (TF2) DELETE_HACK(Noisemaker); DELETE_HACK(Spam); } diff --git a/src/hacks/Achievement.cpp b/src/hacks/Achievement.cpp index 4c1d2a48..3d9f811f 100644 --- a/src/hacks/Achievement.cpp +++ b/src/hacks/Achievement.cpp @@ -9,26 +9,16 @@ #include "../common.h" #include "../sdk.h" -DEFINE_HACK_SINGLETON(AchievementHack); +namespace hacks { namespace tf2 { namespace achievement { -AchievementHack::AchievementHack() { - c_Unlock = CreateConCommand(CON_PREFIX "achievement_unlock", &CC_Achievement_Unlock, "Unlocks all achievements."); - c_Lock = CreateConCommand(CON_PREFIX "achievement_lock", &CC_Achievement_Lock, "Locks all achievements."); -} +CatVar safety(CV_SWITCH, "achievement_safety", "1", "Achievement commands safety switch"); -void CC_Achievement_Unlock(const CCommand& args) { - g_phAchievementHack->UnlockAll(); -} - -void AchievementHack::UnlockAll() { - for (int i = 0; i < interfaces::achievements->GetAchievementCount(); i++) { - interfaces::achievements->AwardAchievement(interfaces::achievements->GetAchievementByIndex(i)->GetAchievementID()); +void Lock() { + if (safety) { + ConColorMsg({ 255, 0, 0, 255}, "Switch " CON_PREFIX "achievement_safety to 0 before using any achievement commands!\n"); + return; } -} - -void AchievementHack::LockAll() { interfaces::stats->RequestCurrentStats(); - //interfaces::stats->ResetAllStats(true); for (int i = 0; i < interfaces::achievements->GetAchievementCount(); i++) { interfaces::stats->ClearAchievement(interfaces::achievements->GetAchievementByIndex(i)->GetName()); } @@ -36,6 +26,17 @@ void AchievementHack::LockAll() { interfaces::stats->RequestCurrentStats(); } -void CC_Achievement_Lock(const CCommand& args) { - g_phAchievementHack->LockAll(); +void Unlock() { + if (safety) { + ConColorMsg({ 255, 0, 0, 255}, "Switch " CON_PREFIX "achievement_safety to 0 before using any achievement commands!\n"); + return; + } + for (int i = 0; i < interfaces::achievements->GetAchievementCount(); i++) { + interfaces::achievements->AwardAchievement(interfaces::achievements->GetAchievementByIndex(i)->GetAchievementID()); + } } + +CatCommand lock("achievement_lock", "Lock all achievements", Lock); +CatCommand unlock("achievement_unlock", "Unlock all achievements", Unlock); + +}}} diff --git a/src/hacks/Achievement.h b/src/hacks/Achievement.h index d8fc4214..14a81732 100644 --- a/src/hacks/Achievement.h +++ b/src/hacks/Achievement.h @@ -10,20 +10,11 @@ #include "IHack.h" -class AchievementHack : public IHack { -public: - AchievementHack(); +namespace hacks { namespace tf2 { namespace achievement { - void UnlockAll(); - void LockAll(); +void Lock(); +void Unlock(); - ConCommand* c_Unlock; - ConCommand* c_Lock; -}; - -void CC_Achievement_Unlock(const CCommand& args); -void CC_Achievement_Lock(const CCommand& args); - -DECLARE_HACK_SINGLETON(AchievementHack); +}}} #endif /* HACKS_ACHIEVEMENT_H_ */ diff --git a/src/hacks/Airstuck.cpp b/src/hacks/Airstuck.cpp index 4733471b..a102463e 100644 --- a/src/hacks/Airstuck.cpp +++ b/src/hacks/Airstuck.cpp @@ -12,32 +12,33 @@ #include "../netmessage.h" -DEFINE_HACK_SINGLETON(Airstuck); +namespace hacks { namespace shared { namespace airstuck { -Airstuck::Airstuck() { - v_bStuck = CreateConVar(CON_PREFIX "airstuck", "0", "Airstuck (BindToggle that to a key!)"); +CatVar stuck(CV_SWITCH, "airstuck", "0", "Airstuck active"); + +void SendNOP() { + INetChannel* ch = (INetChannel*)interfaces::engineClient->GetNetChannelInfo(); + NET_NOP packet; + packet.SetNetChannel(ch); + packet.SetReliable(false); + ch->SendNetMsg(packet); } -void Airstuck::ProcessUserCmd(CUserCmd* cmd) { - if (v_bStuck->GetBool()) { - if (cmd->buttons & (IN_ATTACK | IN_ATTACK2)) { - return; - } +void CreateMove() { + if (stuck) { if (interfaces::gvars->tickcount % 60 == 0) { - INetChannel* ch = (INetChannel*)interfaces::engineClient->GetNetChannelInfo(); - NET_NOP packet; - packet.SetNetChannel(ch); - packet.SetReliable(false); - ch->SendNetMsg(packet); + SendNOP(); } } - return; } -void Airstuck::OnLevelInit() { - v_bStuck->SetValue(false); +bool IsStuck() { + if (g_pUserCmd->buttons & (IN_ATTACK | IN_ATTACK2)) return false; + return stuck; } -void Airstuck::OnLevelShutdown() { - v_bStuck->SetValue(false); +void Reset() { + stuck = false; } + +}}} diff --git a/src/hacks/Airstuck.h b/src/hacks/Airstuck.h index 41c73273..4fe8b7bb 100644 --- a/src/hacks/Airstuck.h +++ b/src/hacks/Airstuck.h @@ -10,17 +10,15 @@ #include "IHack.h" -class Airstuck : public IHack { -public: - Airstuck(); +namespace hacks { namespace shared { namespace airstuck { - virtual void ProcessUserCmd(CUserCmd*) override; - virtual void OnLevelInit() override; - virtual void OnLevelShutdown() override; +extern CatVar stuck; - ConVar* v_bStuck; -}; +void SendNOP(); +void CreateMove(); +bool IsStuck(); +void Reset(); -DECLARE_HACK_SINGLETON(Airstuck); +}}} #endif /* HACKS_AIRSTUCK_H_ */ diff --git a/src/helpers.cpp b/src/helpers.cpp index 70a0664b..98f799f6 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -35,6 +35,7 @@ void BeginConVars() { void EndConVars() { RegisterCatVars(); + RegisterCatCommands(); if (hConVarsFile) { fprintf(hConVarsFile, "\nexec cat_autoexec\n"); fprintf(hConVarsFile, "cat_killsay_reload\ncat_spam_reload\n"); @@ -89,7 +90,7 @@ ConVar* CreateConVar(std::string name, std::string value, std::string help) { //logging::Info("Creating ConVar: %s %s %s", namec, valuec, helpc); ConVar* ret = new ConVar((const char*)namec, (const char*)valuec, 0, (const char*)helpc); if (hConVarsFile) - fprintf(hConVarsFile, "%s %s\n", name.c_str(), value.c_str()); + fprintf(hConVarsFile, "%s \"%s\"\n", name.c_str(), value.c_str()); interfaces::cvar->RegisterConCommand(ret); g_ConVars.push_back(ret); return ret; diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 2c81b74a..0c67024e 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -35,6 +35,8 @@ float AngleDiff( float destAngle, float srcAngle ) bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { SEGV_BEGIN; + g_pUserCmd = cmd; + if (TF2C && g_phMisc->v_bMinigunJump->GetBool() && CE_GOOD(LOCAL_W)) { //RemoveCondition(LOCAL_E, TFCond_Slowed); CE_INT(LOCAL_W, netvar.iWeaponState) = 0; @@ -100,7 +102,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { SAFE_CALL(HACK_PROCESS_USERCMD(Bunnyhop, cmd)); SAFE_CALL(HACK_PROCESS_USERCMD(AutoStrafe, cmd)); SAFE_CALL(HACK_PROCESS_USERCMD(Aimbot, cmd)); - SAFE_CALL(HACK_PROCESS_USERCMD(Airstuck, cmd)); SAFE_CALL(hacks::shared::antiaim::ProcessUserCmd(cmd)); if (TF) SAFE_CALL(HACK_PROCESS_USERCMD(AutoSticky, cmd)); if (TF) SAFE_CALL(HACK_PROCESS_USERCMD(AutoReflect, cmd)); diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index f74ae299..62196ec5 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -31,7 +31,7 @@ bool SendNetMsg_hook(void* thisptr, INetMessage& msg, bool bForceReliable = fals SEGV_BEGIN; //logging::Info("Sending NetMsg! %i", msg.GetType()); - if (g_phAirstuck->v_bStuck->GetBool() && g_Settings.bHackEnabled->GetBool() && !g_Settings.bInvalid) { + if (hacks::shared::airstuck::IsStuck() && g_Settings.bHackEnabled->GetBool() && !g_Settings.bInvalid) { switch (msg.GetType()) { case net_NOP: case net_SignonState: @@ -133,7 +133,7 @@ void LevelInit_hook(void* thisptr, const char* newmap) { ((LevelInit_t*) hooks::hkClientMode->GetMethod(hooks::offLevelInit))(thisptr, newmap); interfaces::engineClient->ExecuteClientCmd("exec cat_matchexec"); LEVEL_INIT(Aimbot); - LEVEL_INIT(Airstuck); + hacks::shared::airstuck::Reset(); if (TF) LEVEL_INIT(AntiDisguise); if (TF) LEVEL_INIT(AutoHeal); if (TF) LEVEL_INIT(AutoReflect); @@ -155,7 +155,7 @@ void LevelShutdown_hook(void* thisptr) { ((LevelShutdown_t*) hooks::hkClientMode->GetMethod(hooks::offLevelShutdown))(thisptr); g_Settings.bInvalid = true; LEVEL_SHUTDOWN(Aimbot); - LEVEL_SHUTDOWN(Airstuck); + hacks::shared::airstuck::Reset(); if (TF) LEVEL_SHUTDOWN(AntiDisguise); if (TF) LEVEL_SHUTDOWN(AutoHeal); if (TF) LEVEL_SHUTDOWN(AutoReflect);