Add better drawapi selection to cmake

This commit is contained in:
TotallyNotElite 2019-06-10 12:53:09 +02:00
parent e296e67d3e
commit f1c4c83acd
9 changed files with 58 additions and 42 deletions

View File

@ -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})

View File

@ -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@

View File

@ -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
{

View File

@ -10,7 +10,7 @@
#include "config.h"
#if ENABLE_IMGUI_DRAWING
#include "imgui/imrenderer.hpp"
#elif !ENABLE_ENGINE_DRAWING
#elif ENABLE_GLEZ_DRAWING
#include <glez/font.hpp>
#include <glez/draw.hpp>
#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

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -13,10 +13,10 @@
#include "common.hpp"
#if ENABLE_IMGUI_DRAWING
#include "imgui/imrenderer.hpp"
#elif !ENABLE_ENGINE_DRAWING
#elif ENABLE_GLEZ_DRAWING
#include <glez/draw.hpp>
#include <glez/glez.hpp>
#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<int> &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<int> &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);

View File

@ -10,7 +10,7 @@
#include <hacks/hacklist.hpp>
#if ENABLE_IMGUI_DRAWING
#include "imgui/imrenderer.hpp"
#elif !ENABLE_ENGINE_DRAWING
#elif ENABLE_GLEZ_DRAWING
#include <glez/glez.hpp>
#include <glez/record.hpp>
#include <glez/draw.hpp>
@ -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
}