From 7e3f9b8d8d17d9fed905f89ae2b847a0adf5babf Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Tue, 18 Apr 2017 17:48:33 +0300 Subject: [PATCH] add esp font change --- src/common.h | 5 +++++ src/drawing.cpp | 39 ++++++++++++++++++++++++++++++++------- src/drawing.h | 9 ++++++--- src/gui/ncc/Menu.cpp | 2 ++ src/hack.cpp | 6 +----- src/hack.h | 2 -- src/hacks/ESP.cpp | 12 ++++++------ 7 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/common.h b/src/common.h index b6f25261..4a23ddfa 100644 --- a/src/common.h +++ b/src/common.h @@ -62,6 +62,11 @@ #include "sdk.h" +template +constexpr T _clamp(T _min, T _max, T _val) { + return ((_val > _max) ? _max : ((_val < _min) ? _min : _val)); +} + #define TF2C (g_AppID == 243750) #define TF2 (g_AppID == 440) #define TF (TF2C || TF2) diff --git a/src/drawing.cpp b/src/drawing.cpp index 28a2a361..7bb5b664 100644 --- a/src/drawing.cpp +++ b/src/drawing.cpp @@ -51,9 +51,6 @@ void AddCenterString(const std::string& string, int color) { // TODO globals -unsigned long fonts::ESP = 0; -unsigned long fonts::MENU = 0; -unsigned long fonts::MENU_BIG = 0; int draw::width = 0; int draw::height = 0; @@ -204,18 +201,46 @@ void draw::DrawRect(int x, int y, int w, int h, int color) { g_ISurface->DrawFilledRect(x, y, x + w, y + h); } +namespace fonts { + +unsigned long ESP = 0; +unsigned long MENU = 0; +unsigned long MENU_BIG = 0; + +static const std::vector fonts = {"Tahoma Bold", "Tahoma", "TF2 Build", "Verdana", "Verdana Bold", "Arial", "Courier New", "Ubuntu Mono Bold"}; +static CatEnum family_enum(fonts); +CatVar esp_family(family_enum, "font_esp_family", "2", "ESP font", "ESP font family"); +CatVar esp_height(CV_INT, "font_esp_height", "14", "ESP height", "ESP font height"); + +void Update() { + fonts::ESP = g_ISurface->CreateFont(); + g_ISurface->SetFontGlyphSet(fonts::ESP, fonts::fonts[_clamp(0, 7, (int)fonts::esp_family)].c_str(), (int)fonts::esp_height, 0, 0, 0, 0); // or Ubuntu Mono Bold + //g_ISurface->ResetFontCaches(); +} + +} + void draw::Initialize() { fonts::ESP = g_ISurface->CreateFont(); fonts::MENU = g_ISurface->CreateFont(); fonts::MENU_BIG = g_ISurface->CreateFont(); - if (!draw::width || !draw::height) { g_IEngine->GetScreenSize(draw::width, draw::height); } - g_ISurface->SetFontGlyphSet(fonts::ESP, "TF2 Build", fonts::ESP_HEIGHT, 0, 0, 0, 0); // or Ubuntu Mono Bold - g_ISurface->SetFontGlyphSet(fonts::MENU, "Verdana", fonts::MENU_HEIGHT, 0, 0, 0, 0); - g_ISurface->SetFontGlyphSet(fonts::MENU_BIG, "Verdana Bold", fonts::MENU_BIG_HEIGHT, 0, 0, 0, 0x0); + const auto install_callback_fn = [](CatVar* var) { + var->convar_parent->InstallChangeCallback([](IConVar* var, const char* pOldValue, float flOldValue) { + fonts::Update(); + }); + }; + + fonts::esp_family.OnRegister(install_callback_fn); + 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::MENU, "Verdana", 12, 0, 0, 0, 0); + g_ISurface->SetFontGlyphSet(fonts::MENU_BIG, "Verdana Bold", 30, 0, 0, 0, 0x0); } void draw::DrawLine(int x, int y, int dx, int dy, int color) { diff --git a/src/drawing.h b/src/drawing.h index 9ee16702..685b7b17 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -15,17 +15,20 @@ class CachedEntity; class Vector; +class CatVar; class IClientEntity; namespace fonts { +// FIXME add menu fonts extern unsigned long ESP; extern unsigned long MENU; extern unsigned long MENU_BIG; -const int ESP_HEIGHT = 14; -const int MENU_HEIGHT = 12; -const int MENU_BIG_HEIGHT = 30; +void Update(); + +extern CatVar esp_family; +extern CatVar esp_height; } diff --git a/src/gui/ncc/Menu.cpp b/src/gui/ncc/Menu.cpp index 9e6a7694..2749578c 100644 --- a/src/gui/ncc/Menu.cpp +++ b/src/gui/ncc/Menu.cpp @@ -202,6 +202,8 @@ List& MainList() { "ESP" [ "ESP Menu" "esp_enabled" + "font_esp_family" + "font_esp_height" "esp_conds" "esp_class" "esp_name" diff --git a/src/hack.cpp b/src/hack.cpp index 94bde264..84b99066 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -64,9 +64,6 @@ void hack::ExecuteCommand(const std::string command) { hack::command_stack().push(command); } -void hack::InitHacks() { -} - ConCommand* hack::c_Cat = 0; void hack::CC_Cat(const CCommand& args) { @@ -110,7 +107,6 @@ void hack::Initialize() { else if (TF2C) g_pClassID = new ClassIDTF2C(); else if (HL2DM) g_pClassID = new ClassIDHL2DM(); g_pClassID->Init(); - draw::Initialize(); 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); @@ -128,9 +124,9 @@ void hack::Initialize() { } BeginConVars(); hack::c_Cat = CreateConCommand(CON_NAME, &hack::CC_Cat, "Info"); - hack::InitHacks(); g_Settings.Init(); EndConVars(); + draw::Initialize(); g_pGUI = new CatGUI(); g_pGUI->Setup(); gNetvars.init(); diff --git a/src/hack.h b/src/hack.h index 8719f7d2..3f599efe 100644 --- a/src/hack.h +++ b/src/hack.h @@ -33,8 +33,6 @@ void Initialize(); void Think(); void Shutdown(); -void InitHacks(); - void CC_Cat(const CCommand& args); extern ConCommand* c_Cat; diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index 3e69c36c..1f17cff6 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -178,12 +178,12 @@ void Draw3DBox(CachedEntity* ent, int clr, bool healthbar, int health, int healt data.at(ent->m_IDX).esp_origin = Vector(max_x + 1, min_y, 0); } break; case 1: { // BOTTOM RIGHT - data.at(ent->m_IDX).esp_origin = Vector(max_x + 1, max_y - data.at(ent->m_IDX).string_count * 13, 0); + data.at(ent->m_IDX).esp_origin = Vector(max_x + 1, max_y - data.at(ent->m_IDX).string_count * ((int)fonts::esp_height - 1), 0); } break; case 2: { // CENTER } break; case 3: { // ABOVE - data.at(ent->m_IDX).esp_origin = Vector(min_x, min_y - data.at(ent->m_IDX).string_count * 13, 0); + data.at(ent->m_IDX).esp_origin = Vector(min_x, min_y - data.at(ent->m_IDX).string_count * ((int)fonts::esp_height - 1), 0); } break; case 4: { // BELOW data.at(ent->m_IDX).esp_origin = Vector(min_x, max_y, 0); @@ -256,12 +256,12 @@ void DrawBox(CachedEntity* ent, int clr, float widthFactor, float addHeight, boo data.at(ent->m_IDX).esp_origin = Vector(max_x, min_y, 0); } break; case 1: { // BOTTOM RIGHT - data.at(ent->m_IDX).esp_origin = Vector(max_x, max_y - data.at(ent->m_IDX).string_count * 13, 0); + data.at(ent->m_IDX).esp_origin = Vector(max_x, max_y - data.at(ent->m_IDX).string_count * ((int)fonts::esp_height - 1), 0); } break; case 2: { // CENTER } break; case 3: { // ABOVE - data.at(ent->m_IDX).esp_origin = Vector(min_x, min_y - data.at(ent->m_IDX).string_count * 13, 0); + data.at(ent->m_IDX).esp_origin = Vector(min_x, min_y - data.at(ent->m_IDX).string_count * ((int)fonts::esp_height - 1), 0); } break; case 4: { // BELOW data.at(ent->m_IDX).esp_origin = Vector(min_x, max_y, 0); @@ -527,11 +527,11 @@ void ProcessEntityPT(CachedEntity* ent) { if (transparent) color = colors::Transparent(color); if (!origin_is_zero) { draw::String(fonts::ESP, draw_point.x, draw_point.y, color, 2, string.data); - draw_point.y += 11; + draw_point.y += (int)fonts::esp_height - 3; } else { auto l = draw::GetStringLength(fonts::ESP, string.data); draw::String(fonts::ESP, draw_point.x - l.first / 2, draw_point.y, color, 2, string.data); - draw_point.y += 11; + draw_point.y += (int)fonts::esp_height - 3; } } }