From e7908e2e905904c5d3a412ee7b8f678486be550a Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Wed, 19 Dec 2018 22:02:11 +0100 Subject: [PATCH] WIP Stuff Fix glow and chams (kind of, todo) Add detach (todo) --- include/hack.hpp | 1 + include/hacks/DominateSay.hpp | 1 - include/visual/EffectChams.hpp | 5 ----- include/visual/EffectGlow.hpp | 5 ----- src/core/entry.cpp | 16 +++++++++++++--- src/core/logging.cpp | 3 ++- src/hack.cpp | 17 ++++++++++++++--- src/hacks/DominateSay.cpp | 16 ---------------- src/visual/EffectChams.cpp | 8 ++++---- src/visual/EffectGlow.cpp | 7 ++----- src/visual/SDLHooks.cpp | 3 ++- 11 files changed, 38 insertions(+), 44 deletions(-) diff --git a/include/hack.hpp b/include/hack.hpp index 5465a0aa..e778cb11 100644 --- a/include/hack.hpp +++ b/include/hack.hpp @@ -25,6 +25,7 @@ extern std::mutex command_stack_mutex; std::stack &command_stack(); void ExecuteCommand(const std::string command); +extern bool game_shutdown; extern bool shutdown; extern bool initialized; diff --git a/include/hacks/DominateSay.hpp b/include/hacks/DominateSay.hpp index 92e01f2d..a2495abe 100644 --- a/include/hacks/DominateSay.hpp +++ b/include/hacks/DominateSay.hpp @@ -16,5 +16,4 @@ void shutdown(); void reload(); extern const std::vector builtin_default; -extern const std::vector jp_anime; } // namespace hacks::shared::dominatesay diff --git a/include/visual/EffectChams.hpp b/include/visual/EffectChams.hpp index 868edc44..67c4a433 100644 --- a/include/visual/EffectChams.hpp +++ b/include/visual/EffectChams.hpp @@ -16,8 +16,6 @@ namespace effect_chams class EffectChams : public IScreenSpaceEffect { - std::vector chams_keyvalues; - public: virtual void Init(); virtual void Shutdown() @@ -28,9 +26,6 @@ public: mat_unlit_z.Shutdown(); mat_lit.Shutdown(); mat_lit_z.Shutdown(); - for (auto kv : chams_keyvalues) - if (kv) - kv->deleteThis(); init = false; } } diff --git a/include/visual/EffectGlow.hpp b/include/visual/EffectGlow.hpp index 9b2b0a1a..15817717 100644 --- a/include/visual/EffectGlow.hpp +++ b/include/visual/EffectGlow.hpp @@ -15,8 +15,6 @@ namespace effect_glow class EffectGlow : public IScreenSpaceEffect { - std::vector glow_keyvalues; - public: virtual void Init(); virtual void Shutdown() @@ -30,9 +28,6 @@ public: mat_unlit_z.Shutdown(); mat_blur_x.Shutdown(); mat_blur_y.Shutdown(); - for (auto kv : glow_keyvalues) - if (kv) - kv->deleteThis(); init = false; } } diff --git a/src/core/entry.cpp b/src/core/entry.cpp index 9a1081b8..2704fd69 100755 --- a/src/core/entry.cpp +++ b/src/core/entry.cpp @@ -5,7 +5,7 @@ * Author: nullifiedcat */ -#include +#include "common.hpp" #include #include "hack.hpp" @@ -40,7 +40,7 @@ void *MainThread(void *arg) logging::Info("Shutting down..."); hack::Shutdown(); logging::Shutdown(); - return 0; + return nullptr; } void __attribute__((constructor)) attach() @@ -51,9 +51,19 @@ void __attribute__((constructor)) attach() pthread_create(&thread_main, 0, MainThread, &mutex_quit); } -void __attribute__((destructor)) detach() +void detach() { logging::Info("Detaching"); pthread_mutex_unlock(&mutex_quit); pthread_join(thread_main, 0); } + +void __attribute__((destructor)) deconstruct() +{ + detach(); +} + +CatCommand cat_detach("detach", "Detach cathook from TF2", []() { + hack::game_shutdown = false; + detach(); +}); diff --git a/src/core/logging.cpp b/src/core/logging.cpp index a7855c77..e7852a6a 100644 --- a/src/core/logging.cpp +++ b/src/core/logging.cpp @@ -12,6 +12,7 @@ #include #include "common.hpp" +#include "hack.hpp" settings::Bool log_to_console{ "hack.log-console", "false" }; @@ -45,7 +46,7 @@ void logging::Info(const char *fmt, ...) fprintf(logging::handle, "%s", result); fflush(logging::handle); #if ENABLE_VISUALS - if (g_ICvar) + if (!hack::game_shutdown && g_ICvar) { if (*log_to_console) g_ICvar->ConsolePrintf("%s", result); diff --git a/src/hack.cpp b/src/hack.cpp index b04ef984..29ed5f6b 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -32,6 +32,8 @@ * Linux */ +// game_shutdown = Is full game shutdown or just detach +bool hack::game_shutdown = true; bool hack::shutdown = false; bool hack::initialized = false; @@ -367,6 +369,8 @@ void hack::Shutdown() if (hack::shutdown) return; hack::shutdown = true; + // Stop cathook stuff + settings::RVarLock.store(true); playerlist::Save(); #if ENABLE_VISUALS sdl_hooks::cleanSdlHooks(); @@ -374,8 +378,15 @@ void hack::Shutdown() logging::Info("Unregistering convars.."); ConVar_Unregister(); logging::Info("Shutting down killsay..."); - hacks::shared::killsay::shutdown(); - hacks::shared::dominatesay::shutdown(); - hacks::shared::announcer::shutdown(); + if (!hack::game_shutdown) + { + hacks::shared::killsay::shutdown(); + hacks::shared::dominatesay::shutdown(); + hacks::shared::announcer::shutdown(); +#if ENABLE_VISUALS + g_pScreenSpaceEffects->DisableScreenSpaceEffect("_cathook_glow"); + g_pScreenSpaceEffects->DisableScreenSpaceEffect("_cathook_chams"); +#endif + } logging::Info("Success.."); } diff --git a/src/hacks/DominateSay.cpp b/src/hacks/DominateSay.cpp index dc652cd7..45436f7e 100644 --- a/src/hacks/DominateSay.cpp +++ b/src/hacks/DominateSay.cpp @@ -35,9 +35,6 @@ std::string ComposeDominateSay(IGameEvent *event) case 2: source = &builtin_default; break; - case 3: - source = &jp_anime; - break; default: break; } @@ -115,17 +112,4 @@ const std::vector builtin_default = { "%killer% is dominating the server with %dominum% dominations!", }; -// same goes to this one -const std::vector jp_anime = { - "Get d-dominated %name%-senpai >:3", - "g- gomenasai! %name%-san!", - "Wow! hey hey hey H~ ey !!! I found you again~~!", - "%name%-san please don't get mad at me.. ><", - // https://youtu.be/sW3RT0tF020?t=207 - "kore kara mo douzo yoroshiku ne.", - "konna watashi dakedo waratte yurushite ne.", - "zutto taisetsu ni shite ne.", - "eikyuu hoshou no watashi dakara.", -}; - } // namespace hacks::shared::dominatesay diff --git a/src/visual/EffectChams.cpp b/src/visual/EffectChams.cpp index 1652a11a..f2cf7f60 100644 --- a/src/visual/EffectChams.cpp +++ b/src/visual/EffectChams.cpp @@ -38,20 +38,20 @@ CatCommand fix_black_chams("fix_black_chams", "Fix Black Chams", []() { void EffectChams::Init() { + if (init) + return; logging::Info("Init EffectChams..."); { KeyValues *kv = new KeyValues("UnlitGeneric"); kv->SetString("$basetexture", "vgui/white_additive"); kv->SetInt("$ignorez", 0); mat_unlit.Init("__cathook_echams_unlit", kv); - chams_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("UnlitGeneric"); kv->SetString("$basetexture", "vgui/white_additive"); kv->SetInt("$ignorez", 1); mat_unlit_z.Init("__cathook_echams_unlit_z", kv); - chams_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("VertexLitGeneric"); @@ -59,7 +59,6 @@ void EffectChams::Init() kv->SetInt("$ignorez", 0); kv->SetInt("$halflambert", 1); mat_lit.Init("__cathook_echams_lit", kv); - chams_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("VertexLitGeneric"); @@ -67,7 +66,6 @@ void EffectChams::Init() kv->SetInt("$ignorez", 1); kv->SetInt("$halflambert", 1); mat_lit_z.Init("__cathook_echams_lit_z", kv); - chams_keyvalues.push_back(kv); } logging::Info("Init done!"); init = true; @@ -335,6 +333,8 @@ void EffectChams::Render(int x, int y, int w, int h) return; if (!enable) return; + if (g_Settings.bInvalid) + return; if (!init) Init(); if (!isHackActive() || (g_IEngine->IsTakingScreenshot() && clean_screenshots)) diff --git a/src/visual/EffectGlow.cpp b/src/visual/EffectGlow.cpp index f4338ebd..c1111964 100644 --- a/src/visual/EffectGlow.cpp +++ b/src/visual/EffectGlow.cpp @@ -129,20 +129,20 @@ CatCommand fix_black_glow("fix_black_glow", "Fix Black Glow", []() { void EffectGlow::Init() { + if (init) + return; logging::Info("Init Glow..."); { KeyValues *kv = new KeyValues("UnlitGeneric"); kv->SetString("$basetexture", "vgui/white_additive"); kv->SetInt("$ignorez", 0); mat_unlit.Init("__cathook_glow_unlit", kv); - glow_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("UnlitGeneric"); kv->SetString("$basetexture", "vgui/white_additive"); kv->SetInt("$ignorez", 1); mat_unlit_z.Init("__cathook_glow_unlit_z", kv); - glow_keyvalues.push_back(kv); } // Initialize 2 buffers GetBuffer(1); @@ -153,7 +153,6 @@ void EffectGlow::Init() kv->SetInt("$additive", 1); mat_blit.Init("__cathook_glow_blit", TEXTURE_GROUP_CLIENT_EFFECTS, kv); mat_blit->Refresh(); - glow_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("BlurFilterX"); @@ -163,7 +162,6 @@ void EffectGlow::Init() kv->SetInt("$alphatest", 1); mat_blur_x.Init("_cathook_blurx", kv); mat_blur_x->Refresh(); - glow_keyvalues.push_back(kv); } { KeyValues *kv = new KeyValues("BlurFilterY"); @@ -174,7 +172,6 @@ void EffectGlow::Init() kv->SetInt("$alphatest", 1); mat_blur_y.Init("_cathook_blury", kv); mat_blur_y->Refresh(); - glow_keyvalues.push_back(kv); } { SS_NeverSolid.m_bEnable = true; diff --git a/src/visual/SDLHooks.cpp b/src/visual/SDLHooks.cpp index 9b74b7a1..83d2cc3a 100644 --- a/src/visual/SDLHooks.cpp +++ b/src/visual/SDLHooks.cpp @@ -33,5 +33,6 @@ void applySdlHooks() void cleanSdlHooks() { *pointers::SDL_GL_SwapWindow = hooked_methods::original::SDL_GL_SwapWindow; + *pointers::SDL_PollEvent = hooked_methods::original::SDL_PollEvent; } -} // namespace sdl_hooks \ No newline at end of file +} // namespace sdl_hooks