diff --git a/makefile b/makefile index 9d601e73..12309fa1 100644 --- a/makefile +++ b/makefile @@ -13,6 +13,14 @@ OUT_NAME = libcathook.so TARGET_DIR = bin TARGET = $(TARGET_DIR)/$(OUT_NAME) SOURCES = $(shell find $(SRC_DIR) -name "*.cpp" -print) +ifdef NOGUI +$(info GUI disabled) +SOURCES := $(filter-out $(shell find $(SRC_DIR)/gui -name "*.cpp" -print),$(SOURCES)) +$(info $(SOURCES)) +CXXFLAGS += -DNOGUI=1 +else +$(info GUI enabled) +endif SOURCES += $(shell find $(SIMPLE_IPC_DIR) -name "*.cpp" -print) OBJECTS = $(SOURCES:.cpp=.o) OBJECTS += $(shell find $(RES_DIR) -name "*.o" -print) @@ -24,11 +32,18 @@ GIT_COMMIT_DATE=$(shell git log -1 --pretty="%ai") CXXFLAGS += -DGIT_COMMIT_HASH="\"$(GIT_COMMIT_HASH)\"" -DGIT_COMMIT_DATE="\"$(GIT_COMMIT_DATE)\"" -.PHONY: clean directories +ifdef GAME +CXXFLAGS += -DGAME=$(GAME) +endif + +.PHONY: clean directories echo all: mkdir -p $(TARGET_DIR) $(MAKE) $(TARGET) + +echo: + echo $(SOURCES) .cpp.o: $(CXX) $(CXXFLAGS) -c $< -o $@ diff --git a/src/ItemManager b/src/ItemManager deleted file mode 100644 index e69de29b..00000000 diff --git a/src/common.h b/src/common.h index 9a405a95..c34c8675 100644 --- a/src/common.h +++ b/src/common.h @@ -62,11 +62,14 @@ #include "textfile.h" #include "EffectChams.hpp" #include "ipc.h" -#include "gui/GUI.h" #include "hooks/hookedmethods.h" #include "classid.h" #include "crits.h" +#if NOGUI != 1 +#include "gui/GUI.h" +#endif + #include "hacks/hacklist.h" #include "glowobjects.h" diff --git a/src/drawing.cpp b/src/drawing.cpp index c776587d..cc85696b 100644 --- a/src/drawing.cpp +++ b/src/drawing.cpp @@ -41,6 +41,7 @@ void DrawStrings() { draw::String(fonts::ESP, draw::width / 2, y, center_strings_colors[i], 2, center_strings[i]); y += 14; } + //logging::Info("Drawing strings done: %d %ul", y, fonts::ESP); } void AddCenterString(const std::string& string, int color) { @@ -54,42 +55,6 @@ void AddCenterString(const std::string& string, int color) { int draw::width = 0; int draw::height = 0; -namespace colors { - -int pink; - -int white; -int black; - -int red, blu; -int red_b, blu_b; // Background -int red_v, blu_v; // Invis -int red_u, blu_u; - -int yellow; // Deprecated -int orange; -int green; - -} - -void colors::Init() { - using namespace colors; - pink = Create(255, 105, 180, 255); - white = Create(255, 255, 255, 255); - black = Create(0, 0, 0, 255); - red = Create(237, 42, 42, 255); - blu = Create(28, 108, 237, 255); - red_b = Create(64, 32, 32, 178); - blu_b = Create(32, 32, 64, 178); - red_v = Create(196, 102, 108, 255); - blu_v = Create(102, 182, 196, 255); - red_u = Create(216, 34, 186, 255); - blu_u = Create(167, 75, 252, 255); - yellow = Create(255, 255, 0, 255); - green = Create(0, 255, 0, 255); - orange = Create(255, 120, 0, 255); -} - int colors::EntityF(CachedEntity* ent) { static int result, skin, plclr; static k_EItemType type; @@ -242,7 +207,7 @@ void draw::Initialize() { fonts::esp_height.OnRegister(install_callback_fn); fonts::Update(); - g_ISurface->SetFontGlyphSet(fonts::MENU, fonts::fonts[_clamp(0, 5, (int)fonts::esp_family)].c_str(), (int)fonts::esp_height, 0, 0, 0, 0); + g_ISurface->SetFontGlyphSet(fonts::ESP, fonts::fonts[_clamp(0, 5, (int)fonts::esp_family)].c_str(), (int)fonts::esp_height, 0, 0, 0, 0); g_ISurface->SetFontGlyphSet(fonts::MENU, "Verdana", 12, 0, 0, 0, 0); g_ISurface->SetFontGlyphSet(fonts::MENU_BIG, "Verdana Bold", 30, 0, 0, 0, 0x0); } diff --git a/src/drawing.h b/src/drawing.h index 03113f02..850855f9 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -37,20 +37,6 @@ extern CatVar esp_height; } namespace colors { -extern int pink; - -extern int white; -extern int black; - -extern int red, blu; -extern int red_b, blu_b; // Background -extern int red_v, blu_v; // Vaccinator -extern int red_u, blu_u; // Ubercharged -extern int yellow; // Deprecated -extern int orange; -extern int green; - -void Init(); constexpr int Create(int r, int g, int b, int a) { unsigned char _r = (r) & 0xFF; @@ -68,6 +54,19 @@ constexpr int Transparent(int base, float mod = 0.5f) { return Create(_r, _g, _b, (int)((float)(_a) * mod)); } +constexpr int pink = Create(255, 105, 180, 255); + +constexpr int white = Create(255, 255, 255, 255); +constexpr int black = Create(0, 0, 0, 255); + +constexpr int red = Create(237, 42, 42, 255), blu = Create(28, 108, 237, 255); +constexpr int red_b = Create(64, 32, 32, 178), blu_b = Create(32, 32, 64, 178); // Background +constexpr int red_v = Create(196, 102, 108, 255), blu_v = Create(102, 182, 196, 255); // Vaccinator +constexpr int red_u = Create(216, 34, 186, 255), blu_u = Create(167, 75, 252, 255); // Ubercharged +constexpr int yellow = Create(255, 255, 0, 255); +constexpr int orange = Create(255, 120, 0, 255); +constexpr int green = Create(0, 255, 0, 255); + int FromHSL(float h, float s, float l); int RainbowCurrent(); int Health(int health, int max); @@ -107,4 +106,10 @@ std::pair GetStringLength(unsigned long font, std::string string); } +#if NOGUI == 1 +constexpr int GUIColor() { + return colors::white; +} +#endif + #endif /* DRAWING_H_ */ diff --git a/src/gui/GUI.h b/src/gui/GUI.h index 7a811386..e610b4a3 100644 --- a/src/gui/GUI.h +++ b/src/gui/GUI.h @@ -11,8 +11,6 @@ class IWidget; class CatVar; -#define GUI_ENABLED true - #include "../beforecheaders.h" #include #include "../aftercheaders.h" diff --git a/src/hack.cpp b/src/hack.cpp index 9cfb2499..550ff8f2 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -34,10 +34,12 @@ #include "hooks.h" #include "netmessage.h" #include "profiler.h" -#include "gui/GUI.h" -//#include "gui/controls.h" #include "cvwrapper.h" +#if NOGUI != 1 +#include "gui/GUI.h" +#endif + #include "hooks/hookedmethods.h" #include "sdk.h" @@ -53,6 +55,25 @@ bool hack::shutdown = false; +const std::string& hack::GetVersion() { + static std::string version("Unknown Version"); + static bool version_set = false; + if (version_set) return version; +#if defined(GIT_COMMIT_HASH) && defined(GIT_COMMIT_DATE) + version = "Version: #" GIT_COMMIT_HASH " " GIT_COMMIT_DATE; +#if NOGUI == 1 + version += " NOGUI"; +#endif +#ifdef FORCE_SINGLE_GAME + version += " S"; +#else + version += " U"; +#endif +#endif + version_set = true; + return version; +} + std::mutex hack::command_stack_mutex; std::stack& hack::command_stack() { static std::stack stack; @@ -67,12 +88,12 @@ void hack::ExecuteCommand(const std::string command) { ConCommand* hack::c_Cat = 0; void hack::CC_Cat(const CCommand& args) { - g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&colors::white), "cathook"); - g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&colors::blu), " by "); - g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&colors::red), "nullifiedcat\n"); -#if defined(GIT_COMMIT_HASH) && defined(GIT_COMMIT_DATE) - g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&colors::white), "commit: #" GIT_COMMIT_HASH " " GIT_COMMIT_DATE "\n"); -#endif + int white = colors::white, blu = colors::blu, red = colors::red; + g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&white), "cathook"); + g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&blu), " by "); + g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&red), "nullifiedcat\n"); + g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&white), GetVersion().c_str()); + g_ICvar->ConsoleColorPrintf(*reinterpret_cast(&white), "\n"); } typedef bool(handlevent_t)(IMatSystemSurface* thisptr, const InputEvent_t& event); @@ -101,7 +122,6 @@ void hack::Initialize() { else if (TF2C) g_pClassID = new ClassIDTF2C(); else if (HL2DM) g_pClassID = new ClassIDHL2DM(); g_pClassID->Init(); - colors::Init(); if (TF2) { uintptr_t mmmf = (gSignatures.GetClientSignature("C7 44 24 04 09 00 00 00 BB ? ? ? ? C7 04 24 00 00 00 00 E8 ? ? ? ? BA ? ? ? ? 85 C0 B8 ? ? ? ? 0F 44 DA") + 37); if (mmmf) { @@ -121,8 +141,10 @@ void hack::Initialize() { g_Settings.Init(); EndConVars(); draw::Initialize(); +#if NOGUI != 1 g_pGUI = new CatGUI(); g_pGUI->Setup(); +#endif gNetvars.init(); InitNetVars(); g_pLocalPlayer = new LocalPlayer(); diff --git a/src/hack.h b/src/hack.h index 3f599efe..93ef3fb9 100644 --- a/src/hack.h +++ b/src/hack.h @@ -29,6 +29,7 @@ void ExecuteCommand(const std::string command); extern bool shutdown; +const std::string& GetVersion(); void Initialize(); void Think(); void Shutdown(); diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 6370e890..4ea53646 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -237,7 +237,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { if (CE_GOOD(g_pLocalPlayer->entity)) { speedapplied = false; - if (roll_speedhack && g_pGUI->m_bPressedState[(int)roll_speedhack] && !(cmd->buttons & IN_ATTACK)) { // FIXME OOB + if (roll_speedhack && g_IInputSystem->IsButtonDown((ButtonCode_t)((int)roll_speedhack)) && !(cmd->buttons & IN_ATTACK)) { speed = cmd->forwardmove; if (fabs(speed) > 0.0f) { cmd->forwardmove = -speed; diff --git a/src/hooks/PaintTraverse.cpp b/src/hooks/PaintTraverse.cpp index 4a55d939..68a1019e 100644 --- a/src/hooks/PaintTraverse.cpp +++ b/src/hooks/PaintTraverse.cpp @@ -9,12 +9,15 @@ #include "../common.h" #include "../hack.h" #include "hookedmethods.h" -#include "../gui/GUI.h" #include "../segvcatch/segvcatch.h" #include "../copypasted/CSignature.h" #include "../profiler.h" #include "../netmessage.h" +#if NOGUI != 1 +#include "../gui/GUI.h" +#endif + CatVar clean_screenshots(CV_SWITCH, "clean_screenshots", "1", "Clean screenshots", "Don't draw visuals while taking a screenshot"); CatVar disable_visuals(CV_SWITCH, "no_visuals", "0", "Disable ALL drawing", "Completely hides cathook"); CatVar no_zoom(CV_SWITCH, "no_zoom", "0", "Disable scope", "Disables black scope overlay"); @@ -71,6 +74,7 @@ void PaintTraverse_hook(void* _this, unsigned int vp, bool fr, bool ar) { case 2: if (software_cursor->GetBool()) software_cursor->SetValue(0); break; +#if NOGUI != 1 case 3: if (cur != g_pGUI->Visible()) { software_cursor->SetValue(g_pGUI->Visible()); @@ -80,6 +84,7 @@ void PaintTraverse_hook(void* _this, unsigned int vp, bool fr, bool ar) { if (cur == g_pGUI->Visible()) { software_cursor->SetValue(!g_pGUI->Visible()); } +#endif } } @@ -139,12 +144,16 @@ void PaintTraverse_hook(void* _this, unsigned int vp, bool fr, bool ar) { if (info_text) { AddSideString("cathook by nullifiedcat", colors::RainbowCurrent()); -#if defined(GIT_COMMIT_HASH) && defined(GIT_COMMIT_DATE) - AddSideString("Version: #" GIT_COMMIT_HASH " " GIT_COMMIT_DATE, GUIColor()); -#endif + AddSideString(hack::GetVersion(), GUIColor()); +#if NOGUI != 1 AddSideString("Press 'INSERT' or 'F11' key to open/close cheat menu.", GUIColor()); AddSideString("Use mouse to navigate in menu.", GUIColor()); - if (!g_IEngine->IsInGame() || g_pGUI->Visible()) { +#endif + if (!g_IEngine->IsInGame() +#if NOGUI != 1 + || g_pGUI->Visible() +#endif + ) { name_s = force_name.GetString(); if (name_s.length() < 3) name = "*Not Set*"; AddSideString(""); // foolish @@ -167,7 +176,7 @@ void PaintTraverse_hook(void* _this, unsigned int vp, bool fr, bool ar) { } -#if GUI_ENABLED == true +#if NOGUI != 1 g_pGUI->Update(); #endif diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index ad61be6e..36cab359 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -95,13 +95,14 @@ CUserCmd* GetUserCmd_hook(IInput* _this, int sequence_number) { int IN_KeyEvent_hook(void* _this, int eventcode, int keynum, const char* pszCurrentBinding) { static const IN_KeyEvent_t original = (IN_KeyEvent_t)hooks::client.GetMethod(offsets::IN_KeyEvent()); +#if NOGUI != 1 SEGV_BEGIN; if (g_pGUI->ConsumesKey((ButtonCode_t)keynum) && g_pGUI->Visible()) { return 0; } - return original(_this, eventcode, keynum, pszCurrentBinding); SEGV_END; - return 0; +#endif + return original(_this, eventcode, keynum, pszCurrentBinding); } static CatVar log_sent(CV_SWITCH, "debug_log_sent_messages", "0", "Log sent messages"); @@ -221,6 +222,7 @@ void FrameStageNotify_hook(void* _this, int stage) { } } if (TF && cathook && !g_Settings.bInvalid && stage == FRAME_RENDER_START) { +#if NOGUI != 1 if (cursor_fix_experimental) { if (gui_visible) { g_ISurface->SetCursorAlwaysVisible(true); @@ -228,6 +230,7 @@ void FrameStageNotify_hook(void* _this, int stage) { g_ISurface->SetCursorAlwaysVisible(false); } } +#endif if (CE_GOOD(LOCAL_E) && no_zoom) RemoveCondition(LOCAL_E, TFCond_Zoomed); if (glow_outline_effect->GetBool()) { if (glow_enabled) { diff --git a/src/profiler.cpp b/src/profiler.cpp index 150aacd8..9da36d5e 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -6,18 +6,21 @@ */ #include "profiler.h" - +#include "cvwrapper.h" #include "logging.h" -ProfilerSection::ProfilerSection(std::string name) { +ProfilerSection::ProfilerSection(std::string name, ProfilerSection* parent) { m_name = name; m_calls = 0; m_log = std::chrono::high_resolution_clock::now(); m_min = std::chrono::nanoseconds::zero(); m_max = std::chrono::nanoseconds::zero(); m_sum = std::chrono::nanoseconds::zero(); + m_parent = parent; } +static CatVar do_profiler_logging(CV_SWITCH, "profiler_log", "0", "Profiler Log"); + void ProfilerSection::OnNodeDeath(ProfilerNode& node) { auto dur = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - node.m_start); if (m_min == std::chrono::nanoseconds::zero()) m_min = dur; @@ -29,10 +32,11 @@ void ProfilerSection::OnNodeDeath(ProfilerNode& node) { m_calls++; if (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_log).count() > 3) { - logging::Info("[P] stats for '%-32s': MIN{%12llu} MAX{%12llu} AVG{%12llu}", m_name.c_str(), - std::chrono::duration_cast(m_min).count(), - std::chrono::duration_cast(m_max).count(), - std::chrono::duration_cast(m_sum).count() / (m_calls ? m_calls : 1)); + if (do_profiler_logging) + logging::Info("[P] stats for '%-32s': MIN{%12llu} MAX{%12llu} AVG{%12llu}", m_name.c_str(), + std::chrono::duration_cast(m_min).count(), + std::chrono::duration_cast(m_max).count(), + std::chrono::duration_cast(m_sum).count() / (m_calls ? m_calls : 1)); m_log = std::chrono::high_resolution_clock::now(); m_min = std::chrono::nanoseconds::zero(); m_max = std::chrono::nanoseconds::zero(); diff --git a/src/profiler.h b/src/profiler.h index 6af55637..556a4562 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -17,7 +17,7 @@ class ProfilerNode; class ProfilerSection { public: - ProfilerSection(std::string name); + ProfilerSection(std::string name, ProfilerSection* parent = nullptr); void OnNodeDeath(ProfilerNode& node); @@ -27,6 +27,7 @@ public: unsigned m_calls; std::chrono::time_point m_log; std::string m_name; + ProfilerSection* m_parent; }; class ProfilerNode { diff --git a/src/weaponprefs.cpp b/src/weaponprefs.cpp deleted file mode 100644 index 92011283..00000000 --- a/src/weaponprefs.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * weaponprefs.cpp - * - * Created on: Nov 25, 2016 - * Author: nullifiedcat - */ - -#include "weaponprefs.h" - -#include "fixsdk.h" -#include -#include "netvars.h" - -//bool IsAmbassador(IClientEntity* weapon) { -// return false; -//} - -/*int g_MeleeList[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 37, -}; - -bool IsMeleeWeapon(int defidx) { - return false; -}*/ diff --git a/src/weaponprefs.h b/src/weaponprefs.h deleted file mode 100644 index bf989887..00000000 --- a/src/weaponprefs.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * weaponprefs.h - * - * Created on: Nov 25, 2016 - * Author: nullifiedcat - */ - -#ifndef WEAPONPREFS_H_ -#define WEAPONPREFS_H_ - -class IClientEntity; - -//bool IsAmbassador(IClientEntity* entity); - -/*extern int g_MeleeList[]; - -bool IsMeleeWeapon(int defidx); -bool IsPistolWeapon(int defidx); -bool IsMinigunWeapon(int defidx); -bool IsShotgunWeapon(int defidx); -bool IsRifleWeapon(int defidx); -bool IsConsumableWeapon(int defidx); -bool IsPDAWeapon(int defidx);*/ - -#endif /* WEAPONPREFS_H_ */