From f1c4c83acd30b6a9fcbf6cfaf51fdec8c2bfb897 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Mon, 10 Jun 2019 12:53:09 +0200 Subject: [PATCH] Add better drawapi selection to cmake --- CMakeLists.txt | 37 ++++++++++++++++++-------- include/config.h.in | 10 ++++--- include/visual/colors.hpp | 6 ++--- include/visual/drawing.hpp | 4 +-- src/hooks/Paint.cpp | 3 +-- src/hooks/visual/PaintTraverse.cpp | 2 +- src/hooks/visual/SDL_GL_SwapWindow.cpp | 2 +- src/visual/drawing.cpp | 24 ++++++++--------- src/visual/drawmgr.cpp | 12 ++++----- 9 files changed, 58 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 797eae1b..a677b042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,12 +29,32 @@ set(Game "tf2" CACHE STRING "Target game") set(GameValues "tf2;hl2dm;dab;tf2c;css;dynamic" CACHE INTERNAL "List of supported game types") set_property(CACHE Game PROPERTY STRINGS ${GameValues}) +set(DrawType "IMGUI" CACHE STRING "Target drawing api") +set(DrawTypes "No Visuals;Glez;Engine;IMGUI;IMGUI Streamproof" CACHE INTERNAL "Select the drawing api that cathook should use") +set_property(CACHE DrawType PROPERTY STRINGS ${DrawTypes}) + +set(EnableVisuals 0) +set(EnableGlezDrawing 0) +set(EnableEngineDrawing 0) +set(EnableImGuiDrawing 0) +set(ExternalDrawing 0) + +if(NOT DrawType STREQUAL "No Visuals") + set(EnableVisuals 1) +endif() +if(DrawType STREQUAL "Glez") + set(EnableGlezDrawing 1) +elseif(DrawType STREQUAL "Engine") + set(EnableEngineDrawing 1) +elseif(DrawType STREQUAL "IMGUI") + set(EnableImGuiDrawing 1) +elseif(DrawType STREQUAL "IMGUI Streamproof") + set(EnableImGuiDrawing 1) + set(ExternalDrawing 1) +endif() + set(EnableUnityBuilds 1 CACHE BOOL "Enable Profiler") set(EnableProfiler 0 CACHE BOOL "Enable Profiler") -set(EnableVisuals 1 CACHE BOOL "Enable Visuals") -set(ExternalDrawing 0 CACHE BOOL "External Visuals") -set(EnableEngineDrawing 0 CACHE BOOL "Draw using engine and disable libglez whenever possible") -set(EnableImGuiDrawing 1 CACHE BOOL "Draw using ImGui's drawlists") set(EnableGUI 1 CACHE BOOL "Enable GUI") set(EnableIPC 1 CACHE BOOL "Enable IPC") set(DataPath "/opt/cathook/data" CACHE FILEPATH "Data location") @@ -52,12 +72,7 @@ if(NOT EnableVisuals) endif() if (EnableVisuals) -# Bruh moment - if (ExternalDrawing AND EnableEngineDrawing) - set(ExternalDrawing 0) - endif() if (EnableImGuiDrawing) - set(EnableEngineDrawing 0) find_package(Freetype REQUIRED) target_include_directories(cathook PRIVATE "${FREETYPE_INCLUDE_DIRS}") target_link_libraries(cathook ${FREETYPE_LIBRARIES}) @@ -97,7 +112,7 @@ if(EnableOnlineFeatures) endif() if(EnableVisuals) - if (NOT EnableEngineDrawing AND NOT EnableImGuiDrawing) + if (EnableGlezDrawing) add_subdirectory(external/libglez) endif() target_include_directories(cathook PRIVATE include/visual) @@ -109,7 +124,7 @@ if(EnableVisuals) target_include_directories(cathook PRIVATE external/libxoverlay/include) endif() target_include_directories(cathook PRIVATE "${SDL2_INCLUDE_DIRS}") - if (NOT EnableEngineDrawing AND NOT EnableImGuiDrawing) + if (EnableGlezDrawing) target_link_libraries(cathook glez) endif() target_link_libraries(cathook ${ValveLibrarySDL2} ${GLEW_LIBRARIES}) diff --git a/include/config.h.in b/include/config.h.in index 0b873f85..27ba5447 100755 --- a/include/config.h.in +++ b/include/config.h.in @@ -5,10 +5,6 @@ #define GAME_SPECIFIC @GameSpecific@ #define GAME @Game@ -#define ENABLE_VISUALS @EnableVisuals@ -#define EXTERNAL_DRAWING @ExternalDrawing@ -#define ENABLE_ENGINE_DRAWING @EnableEngineDrawing@ -#define ENABLE_IMGUI_DRAWING @EnableImGuiDrawing@ #define ENABLE_GUI @EnableGUI@ #define ENABLE_IPC @EnableIPC@ #define DATA_PATH "@DataPath@" @@ -20,3 +16,9 @@ #define ENABLE_IRC @EnableIRC@ #define ENABLE_LOGGING @EnableLogging@ #define ENABLE_CLIP @EnableClip@ + +#define ENABLE_VISUALS @EnableVisuals@ +#define ENABLE_GLEZ_DRAWING @EnableGlezDrawing@ +#define ENABLE_ENGINE_DRAWING @EnableEngineDrawing@ +#define ENABLE_IMGUI_DRAWING @EnableImGuiDrawing@ +#define EXTERNAL_DRAWING @ExternalDrawing@ diff --git a/include/visual/colors.hpp b/include/visual/colors.hpp index dbf1c40e..f508c988 100644 --- a/include/visual/colors.hpp +++ b/include/visual/colors.hpp @@ -7,7 +7,7 @@ #pragma once #include "config.h" -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING #include "glez/color.hpp" #endif @@ -50,11 +50,11 @@ struct rgba_t constexpr rgba_t(float _r, float _g, float _b, float _a = 1.0f) : r(_r), g(_g), b(_b), a(_a){}; explicit rgba_t(const char hex[6]); -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING constexpr rgba_t(const glez::rgba &other) : r(other.r), g(other.g), b(other.b), a(other.a){}; #endif -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING #if __clang__ operator glez::rgba() const { diff --git a/include/visual/drawing.hpp b/include/visual/drawing.hpp index fa5d6529..da922987 100644 --- a/include/visual/drawing.hpp +++ b/include/visual/drawing.hpp @@ -10,7 +10,7 @@ #include "config.h" #if ENABLE_IMGUI_DRAWING #include "imgui/imrenderer.hpp" -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING #include #include #endif @@ -46,7 +46,7 @@ struct font }; #elif ENABLE_IMGUI_DRAWING typedef im_renderer::font font; -#else +#elif ENABLE_GLEZ_DRAWING typedef glez::font font; #endif diff --git a/src/hooks/Paint.cpp b/src/hooks/Paint.cpp index af98a876..8fe97588 100644 --- a/src/hooks/Paint.cpp +++ b/src/hooks/Paint.cpp @@ -82,10 +82,9 @@ DEFINE_HOOKED_METHOD(Paint, void, IEngineVGui *this_, PaintMode_t mode) } #endif // MOVED BACK because glez and imgui flicker in painttraveerse -#if ENABLE_VISUALS && (ENABLE_IMGUI_DRAWING || !ENABLE_ENGINE_DRAWING) +#if ENABLE_IMGUI_DRAWING || ENABLE_GLEZ_DRAWING render_cheat_visuals(); #endif - // Call all paint functions EC::run(EC::Paint); } diff --git a/src/hooks/visual/PaintTraverse.cpp b/src/hooks/visual/PaintTraverse.cpp index ca4d3481..ae71fcb2 100644 --- a/src/hooks/visual/PaintTraverse.cpp +++ b/src/hooks/visual/PaintTraverse.cpp @@ -117,7 +117,7 @@ DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_, unsigned int pane if (!health_panel) if (!strcmp(g_IPanel->GetName(panel), "HudPlayerHealth")) health_panel = panel; -#if ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_ENGINE_DRAWING if (!FocusOverlayPanel) { const char *szName = g_IPanel->GetName(panel); diff --git a/src/hooks/visual/SDL_GL_SwapWindow.cpp b/src/hooks/visual/SDL_GL_SwapWindow.cpp index 865b52cb..26b5a801 100644 --- a/src/hooks/visual/SDL_GL_SwapWindow.cpp +++ b/src/hooks/visual/SDL_GL_SwapWindow.cpp @@ -78,7 +78,7 @@ DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window) } { PROF_SECTION(SWAPWINDOW_tf2); -#if EXTERNAL_DRAWING || ENABLE_IMGUI_DRAWING +#if ENABLE_IMGUI_DRAWING SDL_GL_MakeCurrent(window, tf2_sdl); #endif original::SDL_GL_SwapWindow(window); diff --git a/src/visual/drawing.cpp b/src/visual/drawing.cpp index 3a9b1237..92874daf 100644 --- a/src/visual/drawing.cpp +++ b/src/visual/drawing.cpp @@ -13,10 +13,10 @@ #include "common.hpp" #if ENABLE_IMGUI_DRAWING #include "imgui/imrenderer.hpp" -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING #include #include -#else +#elif ENABLE_ENGINE_DRAWING #include "picopng.hpp" #endif #include "menu/GuiInterface.hpp" @@ -138,7 +138,7 @@ static InitRoutine font_size([]() { esp_font_size.installChangeCallback([](settings::VariableBase &var, int after) { if (after > 0 && after < 100) { -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING fonts::esp->unload(); fonts::esp.reset(new fonts::font(DATA_PATH "/fonts/verasans.ttf", after)); #else @@ -149,7 +149,7 @@ static InitRoutine font_size([]() { center_font_size.installChangeCallback([](settings::VariableBase &var, int after) { if (after > 0 && after < 100) { -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING fonts::center_screen->unload(); fonts::center_screen.reset(new fonts::font(DATA_PATH "/fonts/verasans.ttf", after)); #else @@ -169,7 +169,7 @@ void Initialize() { g_IEngine->GetScreenSize(draw::width, draw::height); } -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING // add proper glez support tf +#if ENABLE_GLEZ_DRAWING glez::preInit(); fonts::menu.reset(new fonts::font(DATA_PATH "/fonts/verasans.ttf", 13)); fonts::esp.reset(new fonts::font(DATA_PATH "/fonts/verasans.ttf", 13)); @@ -283,7 +283,7 @@ void Line(float x1, float y1, float x2_offset, float y2_offset, rgba_t color, fl { g_ISurface->DrawLine(x1, y1, x1 + x2_offset, y1 + y2_offset); } -#else +#elif ENABLE_GLEZ_DRAWING glez::draw::line(x1, y1, x2_offset, y2_offset, color, thickness); #endif } @@ -304,7 +304,7 @@ void Rectangle(float x, float y, float w, float h, rgba_t color) vertices[3].m_Position = { x + w, y }; g_ISurface->DrawTexturedPolygon(4, vertices); -#else +#elif ENABLE_GLEZ_DRAWING glez::draw::rect(x, y, w, h, color); #endif } @@ -386,7 +386,7 @@ void RectangleTextured(float x, float y, float w, float h, rgba_t color, Texture vertices[3].Init(scr_botton_left, tex_botton_left); g_ISurface->DrawTexturedPolygon(4, vertices); -#else +#elif ENABLE_GLEZ_DRAWING glez::draw::rect_textured(x, y, w, h, color, texture, tx, ty, tw, th, angle); #endif } @@ -507,7 +507,7 @@ void InitGL() } xoverlay_show(); xoverlay_draw_begin(); -#if !ENABLE_IMGUI_DRAWING && !ENABLE_ENGINE_DRAWING +#if ENABLE_GLEZ_DRAWING glez::init(xoverlay_library.width, xoverlay_library.height); #elif ENABLE_IMGUI_DRAWING im_renderer::init(); @@ -517,7 +517,7 @@ void InitGL() #if ENABLE_IMGUI_DRAWING glewInit(); im_renderer::init(); -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING || ENABLE_IMGUI_DRAWING glClearColor(1.0, 0.0, 0.0, 0.5); glewExperimental = GL_TRUE; glewInit(); @@ -537,7 +537,7 @@ void BeginGL() xoverlay_draw_begin(); #endif im_renderer::renderStart(); -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING glColor3f(1, 1, 1); #if EXTERNAL_DRAWING xoverlay_draw_begin(); @@ -564,7 +564,7 @@ void EndGL() xoverlay_draw_end(); SDL_GL_MakeCurrent(sdl_hooks::window, nullptr); #endif -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING PROF_SECTION(DRAWEX_draw_end); { PROF_SECTION(draw_end__glez_end); diff --git a/src/visual/drawmgr.cpp b/src/visual/drawmgr.cpp index 7d8591a7..59bc4473 100644 --- a/src/visual/drawmgr.cpp +++ b/src/visual/drawmgr.cpp @@ -10,7 +10,7 @@ #include #if ENABLE_IMGUI_DRAWING #include "imgui/imrenderer.hpp" -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING #include #include #include @@ -41,7 +41,7 @@ void render_cheat_visuals() EndCheatVisuals(); } } -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING glez::record::Record bufferA{}; glez::record::Record bufferB{}; @@ -53,7 +53,7 @@ void BeginCheatVisuals() { #if ENABLE_IMGUI_DRAWING im_renderer::bufferBegin(); -#elif !ENABLE_ENGINE_DRAWING +#elif ENABLE_GLEZ_DRAWING buffers[currentBuffer]->begin(); #endif ResetStrings(); @@ -127,17 +127,17 @@ void DrawCheatVisuals() void EndCheatVisuals() { -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING buffers[currentBuffer]->end(); #endif -#if !ENABLE_ENGINE_DRAWING || ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING || ENABLE_IMGUI_DRAWING currentBuffer = !currentBuffer; #endif } void DrawCache() { -#if !ENABLE_ENGINE_DRAWING && !ENABLE_IMGUI_DRAWING +#if ENABLE_GLEZ_DRAWING buffers[!currentBuffer]->replay(); #endif }