From eef689b01bda4eaa59c846fb018a4e3352586e6e Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Tue, 31 Jan 2017 18:04:55 +0300 Subject: [PATCH] Works! --- cathook/src/gui/CBaseContainer.cpp | 19 +++++-- cathook/src/gui/CBaseWidget.cpp | 5 +- cathook/src/gui/CBaseWidget.h | 2 + cathook/src/gui/CBaseWindow.cpp | 15 ++++-- cathook/src/gui/CBaseWindow.h | 2 + cathook/src/gui/CCVarContainer.h | 1 - cathook/src/gui/CDropdown.cpp | 77 +++++++++++++++++++++++++++++ cathook/src/gui/CDropdown.h | 41 +++++++++++++++ cathook/src/gui/CDropdownEntry.cpp | 30 +++++++++++ cathook/src/gui/CDropdownEntry.h | 24 +++++++++ cathook/src/gui/CDropdownList.cpp | 53 ++++++++++++++++++++ cathook/src/gui/CDropdownList.h | 32 ++++++++++++ cathook/src/gui/CSlider.cpp | 2 +- cathook/src/gui/CSplitContainer.cpp | 6 +-- cathook/src/gui/CTitleBar.cpp | 5 +- cathook/src/gui/CTooltip.cpp | 4 +- cathook/src/gui/GUI.cpp | 3 +- cathook/src/gui/GUI.h | 5 +- cathook/src/gui/IWidget.h | 2 + cathook/src/gui/RootWindow.cpp | 18 +++++-- cathook/src/gui/RootWindow.h | 4 ++ cathook/src/hacks/Misc.cpp | 2 + cathook/src/hacks/Misc.h | 2 + cathook/src/hooks/PaintTraverse.cpp | 4 +- cathook/src/hooks/others.cpp | 24 ++++----- 25 files changed, 345 insertions(+), 37 deletions(-) create mode 100644 cathook/src/gui/CDropdown.cpp create mode 100644 cathook/src/gui/CDropdown.h create mode 100644 cathook/src/gui/CDropdownEntry.cpp create mode 100644 cathook/src/gui/CDropdownEntry.h create mode 100644 cathook/src/gui/CDropdownList.cpp create mode 100644 cathook/src/gui/CDropdownList.h diff --git a/cathook/src/gui/CBaseContainer.cpp b/cathook/src/gui/CBaseContainer.cpp index 52db69b4..45cfae9c 100644 --- a/cathook/src/gui/CBaseContainer.cpp +++ b/cathook/src/gui/CBaseContainer.cpp @@ -72,9 +72,11 @@ void CBaseContainer::DrawBounds(int x, int y) { } void CBaseContainer::FocusOn(IWidget* child) { - if (GetFocusedChild()) GetFocusedChild()->OnFocusLose(); - m_pFocusedChild = child; - if (child) child->OnFocusGain(); + if (GetFocusedChild() != child) { + if (GetFocusedChild()) GetFocusedChild()->OnFocusLose(); + if (child) child->OnFocusGain(); + m_pFocusedChild = child; + } } IWidget* CBaseContainer::GetFocusedChild() { @@ -138,7 +140,12 @@ void CBaseContainer::OnMouseRelease() { void CBaseContainer::PressOn(IWidget* child) { m_pPressedChild = child; - if (child) child->OnMousePress(); + if (child) { + logging::Info("> MousePress %s", child->GetName().c_str()); + child->OnMousePress(); + if (child->DoesStealFocus()) + FocusOn(child); + } } void CBaseContainer::SortByZIndex() { @@ -157,7 +164,11 @@ void CBaseContainer::UpdateHovers() { void CBaseContainer::Update() { SortByZIndex(); + MoveChildren(); UpdateHovers(); + for (auto child : m_children) { + child->Update(); + } } diff --git a/cathook/src/gui/CBaseWidget.cpp b/cathook/src/gui/CBaseWidget.cpp index 60f43b61..a09e8875 100644 --- a/cathook/src/gui/CBaseWidget.cpp +++ b/cathook/src/gui/CBaseWidget.cpp @@ -9,15 +9,18 @@ #include "../common.h" void CBaseWidget::DrawBounds(int x, int y) { - if (!m_KeyValues->IsEmpty("bounds_color")) { + if (m_KeyValues->IsEmpty("bounds_color")) { m_KeyValues->SetInt("bounds_color", colors::Create(rand() % 255, rand() % 255, rand() % 255, 255)); } auto size = GetSize(); + draw::DrawRect(x, y, size.first, size.second, colors::Transparent(m_KeyValues->GetInt("bounds_color"), 0.25f)); draw::OutlineRect(x, y, size.first, size.second, m_KeyValues->GetInt("bounds_color")); } CBaseWidget::CBaseWidget(std::string name, IWidget* parent) : m_KeyValues(std::string("cat_widget_" + name).c_str()) { m_pParent = parent; + Props()->SetString("name", name.c_str()); + SetPositionMode(INLINE); Show(); } diff --git a/cathook/src/gui/CBaseWidget.h b/cathook/src/gui/CBaseWidget.h index c976b3ce..9ec232d0 100644 --- a/cathook/src/gui/CBaseWidget.h +++ b/cathook/src/gui/CBaseWidget.h @@ -51,6 +51,8 @@ public: inline virtual bool IsFocused() { return m_KeyValues->GetBool("focus"); } inline virtual bool IsPressed() { return m_KeyValues->GetBool("press"); } + inline virtual bool DoesStealFocus() { return true; } + inline virtual void SetOffset(int x, int y) { if (x >= 0) m_KeyValues->SetInt("offset_x", x); if (y >= 0) m_KeyValues->SetInt("offset_y", y); diff --git a/cathook/src/gui/CBaseWindow.cpp b/cathook/src/gui/CBaseWindow.cpp index e67db329..5874c17e 100644 --- a/cathook/src/gui/CBaseWindow.cpp +++ b/cathook/src/gui/CBaseWindow.cpp @@ -22,21 +22,30 @@ void CBaseWindow::MoveChildren() { size.first += off.first; size.second += off.second; } - if (c->GetPositionMode() != FLOATING) + if (c->GetPositionMode() != FLOATING && c->GetPositionMode() != ABSOLUTE) if (size.first > mx) mx = size.first; if (c->GetPositionMode() != FLOATING) my += (size.second + 2); - c->Update(); } if (GetParent()) { SetSize(mx + 4, my + 2); } } +void CBaseWindow::OnFocusGain() { + SetZIndex(GetZIndex() + 1); + CBaseContainer::OnFocusGain(); +} + +void CBaseWindow::OnFocusLose() { + SetZIndex(GetZIndex() - 1); + CBaseContainer::OnFocusLose(); +} + void CBaseWindow::Draw(int x, int y) { auto abs = AbsolutePosition(); auto size = GetSize(); - draw::DrawRect(abs.first, abs.second, size.first, size.second, colors::Transparent(colors::black)); + draw::DrawRect(abs.first, abs.second, size.first, size.second, colors::Transparent(colors::black, 0.75)); draw::OutlineRect(abs.first, abs.second, size.first, size.second, colors::pink); CBaseContainer::Draw(x, y); } diff --git a/cathook/src/gui/CBaseWindow.h b/cathook/src/gui/CBaseWindow.h index 3b38ce04..0740fa41 100644 --- a/cathook/src/gui/CBaseWindow.h +++ b/cathook/src/gui/CBaseWindow.h @@ -15,6 +15,8 @@ public: inline CBaseWindow(std::string name = "unnamed", IWidget* parent = nullptr) : CBaseContainer(name, parent) {} inline virtual ~CBaseWindow() {}; + virtual void OnFocusGain() override; + virtual void OnFocusLose() override; virtual void Draw(int x, int y) override; virtual void MoveChildren() override; }; diff --git a/cathook/src/gui/CCVarContainer.h b/cathook/src/gui/CCVarContainer.h index 2c6e485f..9806d422 100644 --- a/cathook/src/gui/CCVarContainer.h +++ b/cathook/src/gui/CCVarContainer.h @@ -18,7 +18,6 @@ public: IWidget* m_pControl; IWidget* m_pLabel; - IWidget* m_pTooltip; CatVar* m_pVar; }; diff --git a/cathook/src/gui/CDropdown.cpp b/cathook/src/gui/CDropdown.cpp new file mode 100644 index 00000000..19df0276 --- /dev/null +++ b/cathook/src/gui/CDropdown.cpp @@ -0,0 +1,77 @@ +/* + * CDropdown.cpp + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#include "CDropdown.h" +#include "CDropdownList.h" +#include "RootWindow.h" + +#include "../common.h" +#include "../sdk.h" + +CDropdown::CDropdown(std::string name, IWidget* parent) : CBaseButton(name, parent) { + list = new CDropdownList(name + "_list", this); + g_pGUI->GetRootWindow()->AddChild(list); + SetSize(80, 18); + list->SetSize(80, 0); + CBaseButton::SetCallback([this](CBaseButton*) -> void { + ShowList(); + }); +} + +CDropdown::~CDropdown() { + delete list; +} + +void CDropdown::SetCallback(DropdownCallbackFn_t callback) { + m_pDropdownCallback = callback; +} + +void CDropdown::AddValue(std::string string) { + list->AddEntry(string); + m_values.push_back(string); +} + +std::string CDropdown::ValueName(int idx) { + if (idx < 0 || idx >= m_values.size()) return "unknown"; + return m_values.at(idx); +} + +void CDropdown::Draw(int x, int y) { + auto size = GetSize(); + auto ssize = draw::GetStringLength(fonts::MENU, ValueName(Value())); + draw::DrawRect(x, y, size.first, size.second, colors::Transparent(colors::black)); + draw::OutlineRect(x, y, size.first, size.second, colors::pink); + draw::String(fonts::MENU, x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, colors::pink, 1, ValueName(Value())); + auto asize = draw::GetStringLength(fonts::MENU, ">"); + draw::String(fonts::MENU, x + size.first - asize.first - 2, y + (size.second - asize.second) / 2, colors::pink, 1, ">"); +} + +void CDropdown::OnFocusLose() { + list->Hide(); +} + +void CDropdown::SetValue(int value) { + Props()->SetInt("value", value); + if (m_pDropdownCallback) + m_pDropdownCallback(this, value); +} + +void CDropdown::ShowList() { + logging::Info("Showing Menu!"); + auto pos = AbsolutePosition(); + auto size = GetSize(); + list->SetOffset(pos.first + size.first, pos.second); + list->Show(); +} + +int CDropdown::Value() { + return Props()->GetInt("value"); +} + +int CDropdown::ValueCount() { + return m_values.size(); +} diff --git a/cathook/src/gui/CDropdown.h b/cathook/src/gui/CDropdown.h new file mode 100644 index 00000000..d9a61a96 --- /dev/null +++ b/cathook/src/gui/CDropdown.h @@ -0,0 +1,41 @@ +/* + * CDropdown.h + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#ifndef CDROPDOWN_H_ +#define CDROPDOWN_H_ + +#include "CBaseButton.h" +#include "CDropdownList.h" + +class CDropdown; + +typedef std::function DropdownCallbackFn_t; + +class CDropdown : public CBaseButton { +public: + CDropdown(std::string name = "unnamed", IWidget* parent = nullptr); + ~CDropdown(); + + void AddValue(std::string); + int ValueCount(); + std::string ValueName(int idx); + void SetValue(int value); + int Value(); + + void ShowList(); + void SetCallback(DropdownCallbackFn_t callback); + + virtual void Draw(int x, int y); + virtual void OnFocusLose(); + + DropdownCallbackFn_t m_pDropdownCallback; + CDropdownList* list; + std::vector m_values; +}; + + +#endif /* CDROPDOWN_H_ */ diff --git a/cathook/src/gui/CDropdownEntry.cpp b/cathook/src/gui/CDropdownEntry.cpp new file mode 100644 index 00000000..8aff2cc6 --- /dev/null +++ b/cathook/src/gui/CDropdownEntry.cpp @@ -0,0 +1,30 @@ +/* + * CDropdownEntry.cpp + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#include "CDropdownEntry.h" + +#include "../common.h" +#include "../sdk.h" + +CDropdownEntry::CDropdownEntry(std::string name, CDropdownList* parent, std::string text, int value) : CBaseButton(name, parent, text) { + Props()->SetInt("value", value); + SetCallback([this](CBaseButton*) -> void { + CDropdownList* parent = dynamic_cast(GetParent()); + if (!parent) return; + parent->SetValue(Props()->GetInt("value")); + }); +} + +void CDropdownEntry::Draw(int x, int y) { + auto ssize = draw::GetStringLength(fonts::MENU, GetText()); + auto size = GetSize(); + draw::String(fonts::MENU, x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, colors::pink, 1, GetText()); +} + +CDropdownEntry::~CDropdownEntry() { + +} diff --git a/cathook/src/gui/CDropdownEntry.h b/cathook/src/gui/CDropdownEntry.h new file mode 100644 index 00000000..44c6c07e --- /dev/null +++ b/cathook/src/gui/CDropdownEntry.h @@ -0,0 +1,24 @@ +/* + * CDropdownEntry.h + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#ifndef CDROPDOWNENTRY_H_ +#define CDROPDOWNENTRY_H_ + +#include "CBaseButton.h" +#include "CDropdownList.h" + +class CDropdownEntry : public CBaseButton { +public: + CDropdownEntry(std::string name = "unnamed", CDropdownList* parent = nullptr, std::string text = "unset", int value = 0); + ~CDropdownEntry(); + + virtual void Draw(int x, int y); +}; + + + +#endif /* CDROPDOWNENTRY_H_ */ diff --git a/cathook/src/gui/CDropdownList.cpp b/cathook/src/gui/CDropdownList.cpp new file mode 100644 index 00000000..8d0c97a8 --- /dev/null +++ b/cathook/src/gui/CDropdownList.cpp @@ -0,0 +1,53 @@ +/* + * CDropdownList.cpp + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#include "CDropdownList.h" +#include "CDropdownEntry.h" +#include "CDropdown.h" + +#include "../common.h" +#include "../sdk.h" + +CDropdownList::CDropdownList(std::string name, CDropdown* menu) : CBaseContainer(name, nullptr) { + m_pMenu = menu; + Hide(); + SetZIndex(5); +} + +CDropdownList::~CDropdownList() { + for (auto entry : m_entries) { + delete entry; + } +} + +void CDropdownList::AddEntry(std::string name) { + CDropdownEntry* entry = new CDropdownEntry("entry", this, name, m_entries.size()); + auto size = GetSize(); + entry->SetSize(size.first, 18); + AddChild(entry); + m_entries.push_back(entry); + SetSize(size.first, m_entries.size() * 18); +} + +void CDropdownList::SetValue(int value) { + m_pMenu->SetValue(value); + Hide(); +} + +void CDropdownList::Draw(int x, int y) { + auto size = GetSize(); + draw::DrawRect(x, y, size.first, size.second, colors::Transparent(colors::black, 0.85)); + draw::OutlineRect(x, y, size.first, size.second, colors::pink); + CBaseContainer::Draw(x, y); +} + +void CDropdownList::MoveChildren() { + for (int i = 0; i < ChildCount(); i++) { + auto child = ChildByIndex(i); + child->SetOffset(0, i * 18); + } +} diff --git a/cathook/src/gui/CDropdownList.h b/cathook/src/gui/CDropdownList.h new file mode 100644 index 00000000..467d310b --- /dev/null +++ b/cathook/src/gui/CDropdownList.h @@ -0,0 +1,32 @@ +/* + * CDropdownList.h + * + * Created on: Jan 31, 2017 + * Author: nullifiedcat + */ + +#ifndef CDROPDOWNLIST_H_ +#define CDROPDOWNLIST_H_ + +#include "CBaseContainer.h" + +class CDropdown; +class CDropdownEntry; + +class CDropdownList : public CBaseContainer { +public: + CDropdownList(std::string name = "unnamed", CDropdown* menu = nullptr); + ~CDropdownList(); + + virtual void Draw(int x, int y); + virtual void MoveChildren(); + inline virtual bool DoesStealFocus() { return false; } + + void AddEntry(std::string name); + void SetValue(int value); + + CDropdown* m_pMenu; + std::vector m_entries; +}; + +#endif /* CDROPDOWNLIST_H_ */ diff --git a/cathook/src/gui/CSlider.cpp b/cathook/src/gui/CSlider.cpp index 27fc1f8f..675afbfb 100644 --- a/cathook/src/gui/CSlider.cpp +++ b/cathook/src/gui/CSlider.cpp @@ -20,7 +20,7 @@ CSlider::CSlider(std::string name, IWidget* parent) : CBaseWidget(name, parent) void CSlider::Setup(float min, float max) { Props()->SetFloat("value_min", min); - Props()->SetFloat("value_max", min); + Props()->SetFloat("value_max", max); SetValue((min + max) / 2.0f); } diff --git a/cathook/src/gui/CSplitContainer.cpp b/cathook/src/gui/CSplitContainer.cpp index 74babc24..12532750 100644 --- a/cathook/src/gui/CSplitContainer.cpp +++ b/cathook/src/gui/CSplitContainer.cpp @@ -17,10 +17,10 @@ void CSplitContainer::MoveChildren() { int width = ((size.first - 4) / ChildCount()) - 2; // TODO padding! for (int i = 0; i < ChildCount(); i++) { auto child = ChildByIndex(i); - child->SetOffset(2 + i * width, newsize.second + 2); + child->SetOffset(2 + i * width, 2); child->SetMaxSize(width, -1); - child->Update(); auto csize = child->GetSize(); - if (csize.second + 2 > newsize.second) newsize.second += csize.second + 2; + if (csize.second + 2 > newsize.second) newsize.second = csize.second + 2; } + SetSize(-1, newsize.second); } diff --git a/cathook/src/gui/CTitleBar.cpp b/cathook/src/gui/CTitleBar.cpp index bc93a7eb..9f51f623 100644 --- a/cathook/src/gui/CTitleBar.cpp +++ b/cathook/src/gui/CTitleBar.cpp @@ -16,6 +16,7 @@ TitleBar::TitleBar(IWidget* parent, std::string title) : CBaseWidget("titlebar", m_iDraggingStage = 0; m_nLastX = 0; m_nLastY = 0; + SetPositionMode(ABSOLUTE); } void TitleBar::Draw(int x, int y) { @@ -30,7 +31,7 @@ void TitleBar::Update() { auto psize = GetParent()->GetSize(); int l, h; draw::GetStringLength(fonts::MENU, (char*)m_strTitle.c_str(), l, h); - SetSize(max(2 * TITLEBAR_PADDING_W + l, psize.first), 2 * TITLEBAR_PADDING_H + h); + SetSize(psize.first, 2 * TITLEBAR_PADDING_H + h); if (!IsPressed()) { m_iDraggingStage = 0; return; @@ -40,7 +41,7 @@ void TitleBar::Update() { } else { int dx = g_pGUI->m_iMouseX - m_nLastX; int dy = g_pGUI->m_iMouseY - m_nLastY; - auto offset = GetOffset(); + auto offset = GetParent()->GetOffset(); GetParent()->SetOffset(offset.first + dx, offset.second + dy); } m_nLastX = g_pGUI->m_iMouseX; diff --git a/cathook/src/gui/CTooltip.cpp b/cathook/src/gui/CTooltip.cpp index b80ebdf2..547c88fe 100644 --- a/cathook/src/gui/CTooltip.cpp +++ b/cathook/src/gui/CTooltip.cpp @@ -11,7 +11,9 @@ #include -CTooltip::CTooltip(IWidget* parent) : CTextLabel("tooltip", parent) {} +CTooltip::CTooltip(IWidget* parent) : CTextLabel("tooltip", parent) { + SetZIndex(999); +} void CTooltip::Draw(int x, int y) { auto size = GetSize(); diff --git a/cathook/src/gui/GUI.cpp b/cathook/src/gui/GUI.cpp index 1c48e525..0fc286c2 100644 --- a/cathook/src/gui/GUI.cpp +++ b/cathook/src/gui/GUI.cpp @@ -30,6 +30,7 @@ CatGUI::~CatGUI() { void CatGUI::Setup() { m_pRootWindow = new RootWindow(); + m_pRootWindow->Setup(); v_bGUIVisible->m_pConVar->InstallChangeCallback(GUIVisibleCallback); } @@ -106,7 +107,7 @@ bool CatGUI::ConsumesKey(ButtonCode_t key) { else return false; } -IWidget* CatGUI::GetRootWindow() { +RootWindow* CatGUI::GetRootWindow() { return m_pRootWindow; } diff --git a/cathook/src/gui/GUI.h b/cathook/src/gui/GUI.h index b8416036..ac7ba0c0 100644 --- a/cathook/src/gui/GUI.h +++ b/cathook/src/gui/GUI.h @@ -17,6 +17,7 @@ class CatVar; #include "../inputsystem/ButtonCode.h" class CTooltip; +class RootWindow; class CatGUI { public: @@ -25,13 +26,13 @@ public: void Update(); void Setup(); - IWidget* GetRootWindow(); + RootWindow* GetRootWindow(); bool ConsumesKey(ButtonCode_t key); void ShowTooltip(const char* text); CTooltip* m_pTooltip; - IWidget* m_pRootWindow; + RootWindow* m_pRootWindow; CatVar* v_bGUIVisible; CatVar* v_bDrawBounds; diff --git a/cathook/src/gui/IWidget.h b/cathook/src/gui/IWidget.h index 4e9b5b36..a74605c9 100644 --- a/cathook/src/gui/IWidget.h +++ b/cathook/src/gui/IWidget.h @@ -53,6 +53,8 @@ public: virtual bool IsFocused() = 0; virtual bool IsPressed() = 0; + virtual bool DoesStealFocus() = 0; + virtual void SetOffset(int x, int y) = 0; virtual void SetMaxSize(int x, int y) = 0; virtual std::pair GetOffset() = 0; diff --git a/cathook/src/gui/RootWindow.cpp b/cathook/src/gui/RootWindow.cpp index 110cbf4f..0434e6c5 100644 --- a/cathook/src/gui/RootWindow.cpp +++ b/cathook/src/gui/RootWindow.cpp @@ -14,6 +14,7 @@ #include "CSlider.h" #include "CTooltip.h" #include "CBaseContainer.h" +#include "CDropdown.h" #include "../common.h" #include "CTitleBar.h" @@ -39,6 +40,10 @@ void TICallback(CTextInput* thisptr, std::string olds, std::string news) { } RootWindow::RootWindow() : CBaseWindow("root") { + +} + +void RootWindow::Setup() { g_pGUI->m_pTooltip = new CTooltip(); AddChild(g_pGUI->m_pTooltip); CBaseWindow* ws = new CBaseWindow("splitwindow"); @@ -49,17 +54,17 @@ RootWindow::RootWindow() : CBaseWindow("root") { ws->SetMaxSize(500, 0); //ws->SetMaxSize(500, 300); CSplitContainer* sc1 = new CSplitContainer("sc1", ws); - ws->AddChild(wst); ws->AddChild(sc1); sc1->SetMaxSize(480, -1); sc1->SetSize(480, -1); sc1->SetMaxSize(480, -1); sc1->AddChild(new CTextLabel("tl1", sc1, ":thinking:")); CBaseButton* ccb1 = new CBaseButton("b1", sc1); - ccb1->SetText("Ayy Lmao"); + ccb1->SetText("nut"); CSlider* sl = new CSlider("sl", ws); sl->Props()->SetString("cvar", "cat_fov"); sl->Setup(10.0f, 150.0f); + sl->SetValue(13.37f); sl->SetCallback([](CSlider* slider, float oldv, float newv) { interfaces::cvar->FindVar(slider->Props()->GetString("cvar"))->SetValue(newv); }); @@ -77,8 +82,13 @@ RootWindow::RootWindow() : CBaseWindow("root") { CSplitContainer* sc3 = new CSplitContainer("sc3", ws); sc3->SetMaxSize(480, -1); sc3->SetSize(480, -1); - sc3->AddChild(new CTextLabel("tl1", sc3, "ayy")); - sc3->AddChild(new CTextLabel("tl2", sc3, "lmao")); + sc3->AddChild(new CTextLabel("tl1", sc3, ":ok_hand:")); + sc3->AddChild(new CTextLabel("tl2", sc3, ":skin-tone-1:")); + CDropdown* dr = new CDropdown("dr1", sc3); + dr->AddValue("testing"); + dr->AddValue("dropdown?!"); + dr->AddValue("wow!"); + sc3->AddChild(dr); ws->AddChild(sc3); AddChild(ws); ws->AddChild(sl); diff --git a/cathook/src/gui/RootWindow.h b/cathook/src/gui/RootWindow.h index 3fa707e1..9c7ad05e 100644 --- a/cathook/src/gui/RootWindow.h +++ b/cathook/src/gui/RootWindow.h @@ -14,6 +14,10 @@ class RootWindow : public CBaseWindow { public: RootWindow(); ~RootWindow(); + + void Setup(); + + inline virtual void MoveChildren() override {}; }; #endif /* ROOTWINDOW_H_ */ diff --git a/cathook/src/hacks/Misc.cpp b/cathook/src/hacks/Misc.cpp index 769d83ea..20f3f3c8 100644 --- a/cathook/src/hacks/Misc.cpp +++ b/cathook/src/hacks/Misc.cpp @@ -261,6 +261,8 @@ Misc::Misc() { v_bFastCrouch = CreateConVar(CON_PREFIX "fakecrouch", "0", "Fast crouch"); //v_bDumpEventInfo = CreateConVar(CON_PREFIX "debug_event_info", "0", "Show event info"); CreateConCommand(CON_PREFIX "set", CC_SetValue, "Set ConVar value (if third argument is 1 the ^'s will be converted into newlines)"); + + v_bCleanChat = CREATE_CV(CV_SWITCH, "clean_chat", "1", "Remove newlines from messages"); //interfaces::eventManager->AddListener(&listener, "player_death", false); } diff --git a/cathook/src/hacks/Misc.h b/cathook/src/hacks/Misc.h index 132265ad..43c88777 100644 --- a/cathook/src/hacks/Misc.h +++ b/cathook/src/hacks/Misc.h @@ -37,6 +37,8 @@ public: ConCommand* c_Reset; ConCommand* c_Disconnect; ConCommand* c_DisconnectVAC; + + CatVar* v_bCleanChat; }; DECLARE_HACK_SINGLETON(Misc); diff --git a/cathook/src/hooks/PaintTraverse.cpp b/cathook/src/hooks/PaintTraverse.cpp index c6c98664..9eff71e9 100644 --- a/cathook/src/hooks/PaintTraverse.cpp +++ b/cathook/src/hooks/PaintTraverse.cpp @@ -109,10 +109,8 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) { g_pGUI->Draw();*/ g_pGUI->Update(); #endif - - if (g_Settings.bShowLogo->GetBool()) { - AddSideString(colors::green, "cathook by d4rkc4t"); + AddSideString(colors::RainbowCurrent(), "cathook by d4rkc4t"); #if _DEVELOPER AddSideString(colors::red, "[developer build]"); #else diff --git a/cathook/src/hooks/others.cpp b/cathook/src/hooks/others.cpp index 180f1aef..6349e1bc 100644 --- a/cathook/src/hooks/others.cpp +++ b/cathook/src/hooks/others.cpp @@ -171,19 +171,21 @@ void OverrideView_hook(void* thisptr, CViewSetup* setup) { bool DispatchUserMessage_hook(void* thisptr, int type, bf_read& buf) { SEGV_BEGIN; - if (type == 4) { - int s = buf.GetNumBytesLeft(); - char* data = new char[s]; - for (int i = 0; i < s; i++) - data[i] = buf.ReadByte(); - int j = 0; - for (int i = 0; i < 3; i++) { - while (char c = data[j++]) { - if (c == '\n') data[j - 1] = ' '; + if (g_phMisc->v_bCleanChat->GetBool()) { + if (type == 4) { + int s = buf.GetNumBytesLeft(); + char* data = new char[s]; + for (int i = 0; i < s; i++) + data[i] = buf.ReadByte(); + int j = 0; + for (int i = 0; i < 3; i++) { + while (char c = data[j++]) { + if (c == '\n' && (i == 1 || i == 2)) data[j - 1] = ' '; + } } + buf = bf_read(data, s); + buf.Seek(0); } - buf = bf_read(data, s); - buf.Seek(0); } return ((DispatchUserMessage_t*)hooks::hkClient->GetMethod(hooks::offFrameStageNotify + 1))(thisptr, type, buf); SEGV_END; return false;