From 25e508ed4fe710a8d8b9a1a6a5146970457578eb Mon Sep 17 00:00:00 2001 From: SMJSGaming Date: Sat, 22 Jun 2024 19:34:02 +0200 Subject: [PATCH] Fixed bugs, optimized the code and moved the settings --- CMakeLists.txt | 2 +- TODO | 17 +- mod.json | 22 ++- src/include.hpp | 2 +- src/main.cpp | 12 +- src/mods/CCHttpClient.cpp | 14 +- src/nodes/CodeBlock.cpp | 99 ++++++++++ src/nodes/CodeBlock.hpp | 28 +++ src/nodes/InfoArea.cpp | 40 +++++ src/nodes/InfoArea.hpp | 12 ++ src/nodes/lists/CaptureList.cpp | 59 +++--- src/nodes/lists/CaptureList.hpp | 12 +- src/nodes/lists/JSONCodeBlock.cpp | 20 +-- src/nodes/lists/JSONCodeBlock.hpp | 6 +- src/nodes/lists/TouchFixList.cpp | 36 ++++ src/nodes/lists/TouchFixList.hpp | 9 + src/objects/HttpInfo.cpp | 13 +- src/objects/HttpInfo.hpp | 2 +- src/objects/converters/RobTopToJson.cpp | 2 +- src/scenes/InterceptPopup.cpp | 228 +++++++----------------- src/scenes/InterceptPopup.hpp | 36 ++-- 21 files changed, 388 insertions(+), 283 deletions(-) create mode 100644 src/nodes/CodeBlock.cpp create mode 100644 src/nodes/CodeBlock.hpp create mode 100644 src/nodes/InfoArea.cpp create mode 100644 src/nodes/InfoArea.hpp create mode 100644 src/nodes/lists/TouchFixList.cpp create mode 100644 src/nodes/lists/TouchFixList.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 88ad2d7..3bb7b27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64") -project(GDIntercept VERSION 0.1.2) +project(GDIntercept VERSION 0.2.0) file(GLOB_RECURSE SOURCES "src/*.cpp") add_library(${PROJECT_NAME} SHARED ${SOURCES}) diff --git a/TODO b/TODO index 1be3855..2f38a81 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -Beta Todo: +Alpha 1 Todo: ✔ @today Add a RobTop API response parser @done(24-06-16 01:08) ✔ @high Convert json objects to strings @done(24-06-16 01:25) ✔ @critical Add a menu icon @done(24-06-19 12:04) @@ -9,15 +9,16 @@ Beta Todo: ✔ @high Replace the rate limit button with a raw data button @done(24-06-17 18:42) ✔ @high Truncase data per line @done(24-06-17 18:42) ✔ @low Add a copy keybind @done(24-06-19 12:04) +Alpha 2 Todo: + ✔ @high Add a settings button @done(24-06-22 13:24) + ✔ @low Replace the popup init with initAnchored @done(24-06-22 13:29) + ✔ @low Paths overflow in the info section, obscuring the status code @done(24-06-22 19:32) + ☐ @high Add a send button + ☐ @critical Add a pause/resume button + ☐ @high Add more keybinds Release Todo: - ☐ Paths overflow in the info section, obscuring the status code ☐ Add inputs to the json code block + # TODO: Figure out wtf I meant by this ☐ Add a format to original in the converters - ☐ Add a send button - ☐ Add a settings button - ☐ Add more keybinds - ☐ Make a proper menu icon - ☐ Add a proper transition - ☐ Replace the popup init with initAnchored Nice To Haves: ☐ Custom theme support diff --git a/mod.json b/mod.json index a946454..9ef8a98 100644 --- a/mod.json +++ b/mod.json @@ -1,6 +1,6 @@ { - "geode": "3.0.0-beta.2", - "version": "v0.1.2-alpha.1", + "geode": "3.0.0-beta.5", + "version": "v0.2.0-alpha.2", "id": "smjs.gdintercept", "name": "GDIntercept", "developers": [ @@ -52,6 +52,13 @@ ] }, "settings": { + "theme": { + "name": "Theme", + "description": "The theme of the code block.", + "type": "string", + "default": "dark", + "one-of": [ "dark", "light" ] + }, "pause-requests": { "name": "Pause Requests", "description": "Pauses all requests and set their timeout to infinite.", @@ -76,12 +83,11 @@ "type": "bool", "default": false }, - "theme": { - "name": "Theme", - "description": "The theme of the code block.", - "type": "string", - "default": "dark", - "match": "dark|light" + "log-requests": { + "name": "Log Requests", + "description": "Logs all requests made in the current session to the Geode console.", + "type": "bool", + "default": false } } } \ No newline at end of file diff --git a/src/include.hpp b/src/include.hpp index d821bc3..67a5ca8 100644 --- a/src/include.hpp +++ b/src/include.hpp @@ -6,7 +6,7 @@ using namespace geode::prelude; using namespace nlohmann; -#define PADDING 5 +#define PADDING 5.0f #define FULL_OPACITY 0xFF #define ZERO_POINT { 0, 0 } diff --git a/src/main.cpp b/src/main.cpp index 52aa047..ebd0cfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,10 +39,8 @@ }, InvokeBindFilter(nullptr, "open_capture_menu"_spr)); new EventListener([=](InvokeBindEvent* event) { - InterceptPopup* popup = InterceptPopup::get(); - - if (event->isDown() && popup) { - as(popup->m_mainLayer->getChildByID("info_code"_spr))->copyCode(); + if (event->isDown()) { + OPT(InterceptPopup::get())->copyCode(); } return ListenerResult::Propagate; @@ -60,6 +58,12 @@ if (HttpInfo::requests.size() > 1) { HttpInfo::requests.resize(1); } + + OPT(InterceptPopup::get())->reload(); } }); + + listenForAllSettingChanges(+[](SettingValue* event) { + OPT(InterceptPopup::get())->reload(); + }); } \ No newline at end of file diff --git a/src/mods/CCHttpClient.cpp b/src/mods/CCHttpClient.cpp index 14e28f3..b8b7362 100644 --- a/src/mods/CCHttpClient.cpp +++ b/src/mods/CCHttpClient.cpp @@ -3,12 +3,14 @@ void ModCCHttpClient::send(CCHttpRequest* request) { HttpInfo* requestInfo = HttpInfo::create(request); - log::info("Sending request:\n{}\nQuery: {}\nHeaders: {}\nBody: {}", - requestInfo->generateBasicInfo(), - requestInfo->formatQuery(), - requestInfo->formatHeaders(), - requestInfo->formatBody().second - ); + if (Mod::get()->getSettingValue("log-requests")) { + log::info("Sending request:\n{}\nQuery: {}\nHeaders: {}\nBody: {}", + requestInfo->generateBasicInfo(false), + requestInfo->formatQuery(), + requestInfo->formatHeaders(), + requestInfo->formatBody().second + ); + } CCHttpClient::send(request); } \ No newline at end of file diff --git a/src/nodes/CodeBlock.cpp b/src/nodes/CodeBlock.cpp new file mode 100644 index 0000000..938afdf --- /dev/null +++ b/src/nodes/CodeBlock.cpp @@ -0,0 +1,99 @@ +#include "CodeBlock.hpp" +#include + +std::vector> CodeBlock::dataTypes({ + { 'B', menu_selector(CodeBlock::onBody) }, + { 'Q', menu_selector(CodeBlock::onQuery) }, + { 'H', menu_selector(CodeBlock::onHeaders) }, + { 'R', menu_selector(CodeBlock::onResponse) } +}); + +size_t CodeBlock::buttonCount = CodeBlock::dataTypes.size(); + +char CodeBlock::currentDataType = CodeBlock::dataTypes.at(0).first; + +CodeBlock* CodeBlock::create(const CCSize& size, const CCSize& buttonBarSize) { + CodeBlock* instance = new CodeBlock(); + + if (instance && instance->init(size, buttonBarSize)) { + instance->autorelease(); + + return instance; + } else { + CC_SAFE_DELETE(instance); + + return nullptr; + } +} + +bool CodeBlock::init(const CCSize& size, const CCSize& buttonBarSize) { + const size_t buttonCount = CodeBlock::dataTypes.size(); + std::vector buttons; + + if (!JSONCodeBlock::init({ HttpInfo::UNKNOWN_CONTENT, "" }, size)) { + return false; + } + + for (size_t i = 0; i < buttonCount; i++) { + const auto& [key, selector] = CodeBlock::dataTypes.at(i); + std::string keyStr(1, key); + CCLabelBMFont* label = CCLabelBMFont::create(keyStr.c_str(), "consola.fnt"_spr); + + buttons.push_back(CCMenuItemSpriteExtra::create(label, this, selector)); + label->setScale(0.8f); + label->setAnchorPoint(CENTER); + label->setColor(ThemeStyle::getTheme().line); + label->setPosition(ccp(buttonBarSize.width / buttonCount, buttonBarSize.height) / 2); + m_labels.insert({ key, label }); + + cocos::getChild(label, 0)->setPositionY(buttonBarSize.height / 2); + } + + ButtonBar* buttonBar = ButtonBar::create("square02_001.png", 0.2f, buttonBarSize, buttons); + + buttonBar->setPosition({ size.width - PADDING * 1.5f, size.height - PADDING }); + buttonBar->setAnchorPoint(TOP_RIGHT); + this->addChild(buttonBar); + + return true; +} + +void CodeBlock::onBody(CCObject* sender) { + this->setCode(m_request->formatBody()); + this->updateDataTypeColor('B'); +} + +void CodeBlock::onQuery(CCObject* sender) { + this->setCode({ HttpInfo::JSON, m_request->formatQuery() }); + this->updateDataTypeColor('Q'); +} + +void CodeBlock::onHeaders(CCObject* sender) { + this->setCode({ HttpInfo::JSON, m_request->formatHeaders() }); + this->updateDataTypeColor('H'); +} + +void CodeBlock::onResponse(CCObject* sender) { + this->setCode(m_request->formatResponse()); + this->updateDataTypeColor('R'); +} + +void CodeBlock::updateDataTypeColor(char type) { + const ThemeStyle& theme = ThemeStyle::getTheme(); + currentDataType = type; + + for (const auto& [key, _] : CodeBlock::dataTypes) { + m_labels.at(key)->setColor(key == type ? theme.text : theme.line); + } +} + +void CodeBlock::updateRequest(HttpInfo* request) { + m_request = request; + + switch (currentDataType) { + case 'B': this->onBody(nullptr); break; + case 'Q': this->onQuery(nullptr); break; + case 'H': this->onHeaders(nullptr); break; + case 'R': this->onResponse(nullptr); break; + } +} \ No newline at end of file diff --git a/src/nodes/CodeBlock.hpp b/src/nodes/CodeBlock.hpp new file mode 100644 index 0000000..72bbd1d --- /dev/null +++ b/src/nodes/CodeBlock.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "ButtonBar.hpp" +#include "../include.hpp" +#include "../objects/HttpInfo.hpp" +#include "lists/JSONCodeBlock.hpp" +#include "../objects/ThemeStyle.hpp" + +struct CodeBlock : public JSONCodeBlock { + static size_t buttonCount; + + static CodeBlock* create(const CCSize& size, const CCSize& buttonBarSize); + + void updateRequest(HttpInfo* request); +private: + static std::vector> dataTypes; + static char currentDataType; + + std::unordered_map m_labels; + HttpInfo* m_request; + + bool init(const CCSize& size, const CCSize& buttonBarSize); + void onBody(CCObject* sender); + void onQuery(CCObject* sender); + void onHeaders(CCObject* sender); + void onResponse(CCObject* sender); + void updateDataTypeColor(char type); +}; \ No newline at end of file diff --git a/src/nodes/InfoArea.cpp b/src/nodes/InfoArea.cpp new file mode 100644 index 0000000..dd1dfde --- /dev/null +++ b/src/nodes/InfoArea.cpp @@ -0,0 +1,40 @@ +#include "InfoArea.hpp" + +InfoArea* InfoArea::create(const CCSize& size) { + InfoArea* instance = new InfoArea(); + + if (instance && instance->init(size)) { + instance->autorelease(); + + return instance; + } else { + CC_SAFE_DELETE(instance); + + return nullptr; + } +} + +bool InfoArea::init(const CCSize& size) { + SimpleTextArea* infoText = SimpleTextArea::create("", "chatFont.fnt", 0.5f, size.width - PADDING * 4); + CCScale9Sprite* infoBg = CCScale9Sprite::create("square02b_001.png"); + + if (!BorderFix::init(infoBg, LIGHTER_BROWN_4B, size)) { + return false; + } + + this->setPadding(PADDING); + infoBg->addChild(infoText); + infoBg->setColor(LIGHT_BROWN_3B); + infoText->setID("info_text"_spr); + infoText->setAnchorPoint(CENTER_LEFT); + infoText->setPosition({ PADDING, infoBg->getContentHeight() / 2 }); + infoText->setMaxLines(5); + infoText->setLinePadding(2); + infoText->setWrappingMode(CUTOFF_WRAP); + + return true; +} + +void InfoArea::updateRequest(HttpInfo* request) { + as(this->getNode()->getChildByID("info_text"_spr))->setText(request->generateBasicInfo()); +} \ No newline at end of file diff --git a/src/nodes/InfoArea.hpp b/src/nodes/InfoArea.hpp new file mode 100644 index 0000000..2e26e37 --- /dev/null +++ b/src/nodes/InfoArea.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "BorderFix.hpp" +#include "../include.hpp" +#include "../objects/HttpInfo.hpp" + +struct InfoArea : public BorderFix { + static InfoArea* create(const CCSize& size); + void updateRequest(HttpInfo* request); +private: + bool init(const CCSize& size); +}; \ No newline at end of file diff --git a/src/nodes/lists/CaptureList.cpp b/src/nodes/lists/CaptureList.cpp index 91b4f0a..1da0c37 100644 --- a/src/nodes/lists/CaptureList.cpp +++ b/src/nodes/lists/CaptureList.cpp @@ -1,9 +1,11 @@ #include "CaptureList.hpp" +#include "Geode/cocos/touch_dispatcher/CCTouchDispatcher.h" +#include CaptureList* CaptureList::create(const CCSize& size, const float cellHeight, const std::function& switchInfo) { - CaptureList* instance = new CaptureList(size, cellHeight, switchInfo); + CaptureList* instance = new CaptureList(); - if (instance && instance->init()) { + if (instance && instance->init(size, cellHeight, switchInfo)) { instance->autorelease(); return instance; @@ -14,19 +16,28 @@ CaptureList* CaptureList::create(const CCSize& size, const float cellHeight, con } } -CaptureList::CaptureList(const CCSize& size, const float cellHeight, const std::function& switchInfo) : m_itemSeparation(cellHeight), m_switchInfo(switchInfo) { - this->setContentSize(size); -} +bool CaptureList::init(const CCSize& size, const float cellHeight, const std::function& switchInfo) { + if (!CCNode::init()) { + return false; + } -void CaptureList::createCells() { - const float width = this->getContentWidth(); + CCTouchDispatcher* dispatcher = CCTouchDispatcher::get(); CCArrayExt entries; bool active = false; for (HttpInfo* request : HttpInfo::requests) { - CaptureCell* capture = CaptureCell::create(request, { width, this->m_itemSeparation }, [this, request](CaptureCell* cell) { - m_switchInfo(request); - this->switchCell(cell); + CaptureCell* capture = CaptureCell::create(request, { size.width, cellHeight }, [this, request, switchInfo](CaptureCell* cell) { + switchInfo(request); + + if (m_list) { + CCArrayExt entries(m_list->m_entries); + + for (CaptureCell* entry : entries) { + if (entry != cell) { + entry->deactivate(); + } + } + } }); if (request->isActive() && !active) { @@ -41,30 +52,8 @@ void CaptureList::createCells() { entries[0]->activate(); } - ListView* list = ListView::create(entries.inner(), m_itemSeparation, width, this->getContentHeight()); - - OPT(this->getChildByID("capture_list"_spr))->removeFromParentAndCleanup(true); - - list->setID("capture_list"_spr); - this->addChild(list); -} - -void CaptureList::switchCell(CaptureCell* cell) { - ListView* list = as(this->getChildByID("capture_list"_spr)); - - if (list != nullptr) { - CCArrayExt entries(list->m_entries); - - for (CaptureCell* entry : entries) { - if (entry != cell) { - entry->deactivate(); - } - } - } -} - -bool CaptureList::init() { - this->createCells(); + this->setContentSize(size); + this->addChild(m_list = TouchFixList::create(entries.inner(), cellHeight, size.width, this->getContentHeight())); - return CCNode::init(); + return true; } \ No newline at end of file diff --git a/src/nodes/lists/CaptureList.hpp b/src/nodes/lists/CaptureList.hpp index 1c40367..8d2ddf9 100644 --- a/src/nodes/lists/CaptureList.hpp +++ b/src/nodes/lists/CaptureList.hpp @@ -1,18 +1,14 @@ #pragma once #include "../../include.hpp" -#include "../../objects/HttpInfo.hpp" +#include "TouchFixList.hpp" #include "../cells/CaptureCell.hpp" +#include "../../objects/HttpInfo.hpp" struct CaptureList : public CCNode { static CaptureList* create(const CCSize& size, const float cellHeight, const std::function& switchInfo); - - void createCells(); private: - float m_itemSeparation; - std::function m_switchInfo; + TouchFixList* m_list; - CaptureList(const CCSize& size, const float cellHeight, const std::function& switchInfo); - void switchCell(CaptureCell* cell); - bool init() override; + bool init(const CCSize& size, const float cellHeight, const std::function& switchInfo); }; \ No newline at end of file diff --git a/src/nodes/lists/JSONCodeBlock.cpp b/src/nodes/lists/JSONCodeBlock.cpp index cadc40a..66b1ab8 100644 --- a/src/nodes/lists/JSONCodeBlock.cpp +++ b/src/nodes/lists/JSONCodeBlock.cpp @@ -1,20 +1,7 @@ #include "JSONCodeBlock.hpp" +#include "Geode/cocos/CCDirector.h" -JSONCodeBlock* JSONCodeBlock::create(const std::pair& code, const CCSize& size, bool readonly) { - JSONCodeBlock* instance = new JSONCodeBlock(); - - if (instance && instance->init(code, size, readonly)) { - instance->autorelease(); - - return instance; - } else { - CC_SAFE_DELETE(instance); - - return nullptr; - } -} - -bool JSONCodeBlock::init(const std::pair& code, const CCSize& size, bool readonly) { +bool JSONCodeBlock::init(const std::pair& code, const CCSize& size) { if (!BorderFix::init({ 0, 0, 0, FULL_OPACITY }, size)) { return false; } @@ -41,6 +28,7 @@ void JSONCodeBlock::setCode(const std::pair& const CCSize& size = this->getContentSize() - ccp(this->getPaddingX(), this->getPaddingY()) * 2; const float cellHeight = fontSize.height + theme.lineHeight; const float lineNumberWidth = fontSize.width * 4; + CCTouchDispatcher* dispatcher = CCTouchDispatcher::get(); CCArray* cells = CCArray::create(); std::stringstream stream(m_code = code.second); std::string line; @@ -52,7 +40,7 @@ void JSONCodeBlock::setCode(const std::pair& cells->addObject(CodeLineCell::create({ code.first, line }, i, lineNumberWidth, color)); } - ListView* list = ListView::create(cells, cellHeight, size.width, size.height); + TouchFixList* list = TouchFixList::create(cells, cellHeight, size.width, size.height); TracklessScrollbar* scrollbar = TracklessScrollbar::create({ PADDING, this->getContentHeight() - 2 }, list); list->setCellOpacity(0); diff --git a/src/nodes/lists/JSONCodeBlock.hpp b/src/nodes/lists/JSONCodeBlock.hpp index 2863154..fb4a171 100644 --- a/src/nodes/lists/JSONCodeBlock.hpp +++ b/src/nodes/lists/JSONCodeBlock.hpp @@ -1,6 +1,7 @@ #pragma once #include "../../include.hpp" +#include "TouchFixList.hpp" #include "../BorderFix.hpp" #include "../cells/CodeLineCell.hpp" #include "../TracklessScrollbar.hpp" @@ -9,13 +10,12 @@ #include "../../objects/ThemeStyle.hpp" struct JSONCodeBlock : public BorderFix { - static JSONCodeBlock* create(const std::pair& code, const CCSize& size, bool readonly = true); - void copyCode(); void setCode(const std::pair& code); +protected: + bool init(const std::pair& code, const CCSize& size); private: std::string m_code; - bool init(const std::pair& code, const CCSize& size, bool readonly); void draw() override; }; \ No newline at end of file diff --git a/src/nodes/lists/TouchFixList.cpp b/src/nodes/lists/TouchFixList.cpp new file mode 100644 index 0000000..2482cf5 --- /dev/null +++ b/src/nodes/lists/TouchFixList.cpp @@ -0,0 +1,36 @@ +#include "TouchFixList.hpp" +#include "Geode/ui/ListView.hpp" + +TouchFixList* TouchFixList::create(CCArray* cells, const float cellHeight, const float width, const float height) { + TouchFixList* instance = new TouchFixList(); + + if (instance) { + instance->m_itemSeparation = cellHeight; + instance->m_primaryCellColor = BROWN_3B; + instance->m_secondaryCellColor = BROWN_3B; + instance->m_cellOpacity = 0xFF; + instance->m_cellBorderColor = ccc4(0x00, 0x00, 0x00, 0x4B); + + if (instance->init(cells, BoomListType::Default, width, height)) { + instance->autorelease(); + + return instance; + } + } + + CC_SAFE_DELETE(instance); + + return nullptr; +} + +void TouchFixList::draw() { + CCTouchDispatcher* dispatcher = CCTouchDispatcher::get(); + CCTouchHandler* popupHandler = dispatcher->findHandler(as*>(CCDirector::sharedDirector()->getRunningScene()->getChildByID("intercept_popup"_spr))); + CCTouchHandler* listHandler = dispatcher->findHandler(m_tableView); + + ListView::draw(); + + if (popupHandler && listHandler) { + dispatcher->setPriority(popupHandler->getPriority(), listHandler->getDelegate()); + } +} \ No newline at end of file diff --git a/src/nodes/lists/TouchFixList.hpp b/src/nodes/lists/TouchFixList.hpp new file mode 100644 index 0000000..2419247 --- /dev/null +++ b/src/nodes/lists/TouchFixList.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "../../include.hpp" + +struct TouchFixList : public ListView { + static TouchFixList* create(CCArray* cells, const float cellHeight, const float width, const float height); +private: + void draw() override; +}; \ No newline at end of file diff --git a/src/objects/HttpInfo.cpp b/src/objects/HttpInfo.cpp index 3f90a70..f6c48e8 100644 --- a/src/objects/HttpInfo.cpp +++ b/src/objects/HttpInfo.cpp @@ -148,13 +148,18 @@ unsigned int HttpInfo::getResponseCode() { return m_responseCode; } -std::string HttpInfo::generateBasicInfo() { - return fmt::format("Method: {}\nProtocol: {}\nHost: {}\nPath: {}\nStatus Code: {}", +std::string HttpInfo::generateBasicInfo(const bool withStatus) { + const std::string info(fmt::format("Method: {}\nProtocol: {}\nHost: {}\nPath: {}", this->formatMethod(), this->formatProtocol(), m_host, - m_path, - m_responseCode); + m_path)); + + if (withStatus) { + return fmt::format("Status Code: {}\n{}", m_responseCode, info); + } else { + return info; + } } ccColor3B HttpInfo::colorForMethod() { diff --git a/src/objects/HttpInfo.hpp b/src/objects/HttpInfo.hpp index 62fbeb7..4318611 100644 --- a/src/objects/HttpInfo.hpp +++ b/src/objects/HttpInfo.hpp @@ -38,7 +38,7 @@ struct HttpInfo : public CCObject { std::pair formatBody(); std::pair formatResponse(); unsigned int getResponseCode(); - std::string generateBasicInfo(); + std::string generateBasicInfo(const bool withStatus = true); ccColor3B colorForMethod(); private: static FormToJson formToJson; diff --git a/src/objects/converters/RobTopToJson.cpp b/src/objects/converters/RobTopToJson.cpp index fa6e00b..a961e84 100644 --- a/src/objects/converters/RobTopToJson.cpp +++ b/src/objects/converters/RobTopToJson.cpp @@ -49,7 +49,7 @@ const std::unordered_map RobTopToJson::parser }) }, // Socials { "/database/downloadGJMessage20.php", RobTopToJson::Parser(":") }, - { "/database/getGJFriendRequests20", RobTopToJson::Parser(":", "|", { + { "/database/getGJFriendRequests20.php", RobTopToJson::Parser(":", "|", { { "pagination", RobTopToJson::ObjParser({ "total", "offset", "amount" }, ":") } }) }, { "/database/getGJMessages20.php", RobTopToJson::Parser(":", "|", { diff --git a/src/scenes/InterceptPopup.cpp b/src/scenes/InterceptPopup.cpp index c9dc55f..ba7e310 100644 --- a/src/scenes/InterceptPopup.cpp +++ b/src/scenes/InterceptPopup.cpp @@ -1,4 +1,5 @@ #include "InterceptPopup.hpp" +#include "Geode/cocos/touch_dispatcher/CCTouchDispatcher.h" float InterceptPopup::uiWidth = 500; @@ -18,24 +19,6 @@ float InterceptPopup::codeBlockButtonHeight = 15; float InterceptPopup::middleColumnXPosition = InterceptPopup::uiPadding + PADDING + InterceptPopup::captureCellWidth; -std::vector> InterceptPopup::dataTypes({ - { 'B', menu_selector(InterceptPopup::onBody) }, - { 'Q', menu_selector(InterceptPopup::onQuery) }, - { 'H', menu_selector(InterceptPopup::onHeaders) }, - { 'R', menu_selector(InterceptPopup::onResponse) } -}); - -char InterceptPopup::currentDataType = InterceptPopup::dataTypes.at(0).first; - -float InterceptPopup::codeBlockButtonWidth = InterceptPopup::dataTypes.size() * InterceptPopup::codeBlockButtonHeight; - -std::vector> InterceptPopup::toggles({ - { "Pause requests", "pause-requests", menu_selector(InterceptPopup::onPauseRequest) }, - { "Censor sensitive data", "censor-data", menu_selector(InterceptPopup::onCensorData) }, - { "Remember requests", "remember-requests", menu_selector(InterceptPopup::onRememberRequests) }, - { "Raw Data", "raw-data", menu_selector(InterceptPopup::onRawData) } -}); - InterceptPopup* InterceptPopup::get() { return as(CCDirector::sharedDirector()->getRunningScene()->getChildByID("intercept_popup"_spr)); } @@ -57,131 +40,93 @@ void InterceptPopup::scene() { bool InterceptPopup::setup() { this->setTitle("Intercepted Requests"); - this->setupCodeBlock(); - this->setupInfo(); - this->setupSettings(); - this->setupList(); + this->reload(); + + CCSprite* settingsSprite = CCSprite::createWithSpriteFrameName("GJ_optionsBtn_001.png"); + + settingsSprite->setScale(0.4f); + + CCMenu* menu = CCMenu::createWithItem(CCMenuItemSpriteExtra::create(settingsSprite, this, menu_selector(InterceptPopup::onSettings))); + + menu->setAnchorPoint(BOTTOM_LEFT); + menu->setPosition({ + InterceptPopup::uiWidth - InterceptPopup::uiPadding - settingsSprite->getContentWidth() * settingsSprite->getScale() / 2, + m_title->getPositionY() + }); + m_mainLayer->addChild(menu); return true; } -void InterceptPopup::onClose(CCObject* obj) { - this->removeFromParent(); +void InterceptPopup::reload() { + OPT(m_infoArea)->removeFromParentAndCleanup(true); + OPT(m_settings)->removeFromParentAndCleanup(true); + OPT(m_codeBlock)->removeFromParentAndCleanup(true); + OPT(m_list)->removeFromParentAndCleanup(true); + + m_infoArea = this->setupInfo(); + m_settings = this->setupSettings(); + m_codeBlock = this->setupCodeBlock(); + m_list = this->setupList(); } -void InterceptPopup::setupList() { - const CCSize listSize(ccp(InterceptPopup::captureCellWidth, this->getPageHeight())); - BorderFix* captures = BorderFix::create(m_captureList = CaptureList::create(listSize - 2, InterceptPopup::captureCellHeight, [this](HttpInfo* request) { - m_currentRequest = request; +void InterceptPopup::copyCode() { + m_codeBlock->copyCode(); +} - this->updateInfo(); +InfoArea* InterceptPopup::setupInfo() { + InfoArea* infoArea = InfoArea::create({ InterceptPopup::infoWidth, InterceptPopup::infoRowHeight }); + + m_mainLayer->addChild(infoArea); + infoArea->setPosition({ + InterceptPopup::middleColumnXPosition, + this->getComponentYPosition(0, InterceptPopup::infoRowHeight) + }); + + return infoArea; +} + +BorderFix* InterceptPopup::setupList() { + const CCSize listSize(ccp(InterceptPopup::captureCellWidth, this->getPageHeight())); + BorderFix* captures = BorderFix::create(CaptureList::create(listSize - 2, InterceptPopup::captureCellHeight, [this](HttpInfo* request) { + m_infoArea->updateRequest(request); + m_codeBlock->updateRequest(request); }), LIGHTER_BROWN_4B, listSize, { 1, 1 }); captures->setAnchorPoint(BOTTOM_LEFT); captures->setPosition({ InterceptPopup::uiPadding, InterceptPopup::uiPadding }); m_mainLayer->addChild(captures); + + return captures; } -void InterceptPopup::setupSettings() { - CCNode* info = m_mainLayer->getChildByID("info"_spr); +BorderFix* InterceptPopup::setupSettings() { CCSize padding(ccp(PADDING, PADDING)); - const float xPosition = info->getPositionX() + info->getContentWidth() + PADDING; + const float xPosition = m_infoArea->getPositionX() + m_infoArea->getContentWidth() + PADDING; const float width = InterceptPopup::uiWidth - xPosition - InterceptPopup::uiPadding; CCScale9Sprite* settingsBg = CCScale9Sprite::create("square02b_001.png"); BorderFix* settings = BorderFix::create(settingsBg, LIGHTER_BROWN_4B, { width, InterceptPopup::infoRowHeight }, padding); - CCMenu* toggleMenu = CCMenu::create(); - Mod* mod = Mod::get(); - - toggleMenu->setPosition(ZERO_POINT); - toggleMenu->setContentSize(settingsBg->getContentSize() - padding * 2); - for (int i = 0; i < InterceptPopup::toggles.size(); i++) { - const auto& [name, key, selector] = InterceptPopup::toggles.at(i); - - GameToolbox::createToggleButton(name, selector, mod->getSettingValue(key), toggleMenu, { - PADDING, - toggleMenu->getContentHeight() - PADDING * (i * 2.4f + 1) - }, this, toggleMenu, 0.3f, 0.3f, width - PADDING * 2, { 2, 0 }, "bigFont.fnt", false, 0, nullptr)->setID(""_spr + key); - } - - toggleMenu->setPosition(padding); settings->setPosition({ xPosition, this->getComponentYPosition(0, InterceptPopup::infoRowHeight) }); settingsBg->setColor(LIGHT_BROWN_3B); - settingsBg->addChild(toggleMenu); m_mainLayer->addChild(settings); -} -void InterceptPopup::setupInfo() { - const float xPosition = InterceptPopup::uiPadding + PADDING + InterceptPopup::captureCellWidth; - SimpleTextArea* infoText = SimpleTextArea::create("", "chatFont.fnt", 0.5f, InterceptPopup::infoWidth - 20); - CCScale9Sprite* infoBg = CCScale9Sprite::create("square02b_001.png"); - BorderFix* info = BorderFix::create(infoBg, LIGHTER_BROWN_4B, { - InterceptPopup::infoWidth, - InterceptPopup::infoRowHeight - }, { PADDING, PADDING }); - - info->setID("info"_spr); - info->setPosition({ xPosition, this->getComponentYPosition(0, InterceptPopup::infoRowHeight) }); - infoBg->addChild(infoText); - infoBg->setColor(LIGHT_BROWN_3B); - infoText->setID("info_text"_spr); - infoText->setAnchorPoint(CENTER_LEFT); - infoText->setPosition({ 5, infoBg->getContentHeight() / 2 }); - infoText->setMaxLines(5); - infoText->setLinePadding(2); - infoText->setWrappingMode(NO_WRAP); - - m_mainLayer->addChild(info); + return settings; } -void InterceptPopup::setupCodeBlock() { - const float width = InterceptPopup::uiWidth - InterceptPopup::middleColumnXPosition - InterceptPopup::uiPadding; - const float codeBlockHeight = this->getPageHeight() - InterceptPopup::infoRowHeight - PADDING; - const size_t buttonCount = InterceptPopup::dataTypes.size(); - JSONCodeBlock* codeBlock = JSONCodeBlock::create({ HttpInfo::UNKNOWN_CONTENT, "" }, { width, codeBlockHeight }); - std::vector buttons; - - for (size_t i = 0; i < buttonCount; i++) { - const float buttonWidth = width / 3; - const auto& [key, selector] = InterceptPopup::dataTypes.at(i); - std::string keyStr(1, key); - CCLabelBMFont* label = CCLabelBMFont::create(keyStr.c_str(), "consola.fnt"_spr); - CCMenuItemSpriteExtra* button = CCMenuItemSpriteExtra::create(label, this, selector); - - label->setID(""_spr + keyStr); - label->setScale(0.8f); - label->setAnchorPoint(CENTER); - label->setColor(ThemeStyle::getTheme().line); - label->setPosition(ccp(InterceptPopup::codeBlockButtonWidth / buttonCount, InterceptPopup::codeBlockButtonHeight) / 2); - button->setSizeMult(0); - buttons.push_back(button); - - cocos::getChild(label, 0)->setPositionY(InterceptPopup::codeBlockButtonHeight / 2); - } - - ButtonBar* buttonBar = ButtonBar::create("square02_001.png", 0.2f, { - InterceptPopup::codeBlockButtonWidth, +CodeBlock* InterceptPopup::setupCodeBlock() { + CodeBlock* codeBlock = CodeBlock::create({ + InterceptPopup::uiWidth - InterceptPopup::middleColumnXPosition - InterceptPopup::uiPadding, + this->getPageHeight() - InterceptPopup::infoRowHeight - PADDING + }, { + CodeBlock::buttonCount * InterceptPopup::codeBlockButtonHeight, InterceptPopup::codeBlockButtonHeight - }, buttons); + }); - codeBlock->setID("info_code"_spr); codeBlock->setPosition({ InterceptPopup::middleColumnXPosition, InterceptPopup::uiPadding }); - buttonBar->setID("code_buttons"_spr); - buttonBar->setPosition({ InterceptPopup::middleColumnXPosition + width - PADDING * 1.5f, codeBlockHeight + InterceptPopup::uiPadding - PADDING }); - buttonBar->setAnchorPoint(TOP_RIGHT); m_mainLayer->addChild(codeBlock); - m_mainLayer->addChild(buttonBar); -} - -void InterceptPopup::updateInfo() { - as(m_mainLayer->getChildByIDRecursive("info_text"_spr))->setText(m_currentRequest->generateBasicInfo()); - switch (currentDataType) { - case 'B': this->onBody(nullptr); break; - case 'Q': this->onQuery(nullptr); break; - case 'H': this->onHeaders(nullptr); break; - case 'R': this->onResponse(nullptr); break; - } + return codeBlock; } float InterceptPopup::getPageHeight() { @@ -192,59 +137,10 @@ float InterceptPopup::getComponentYPosition(float offset, float itemHeight) { return InterceptPopup::uiPadding + this->getPageHeight() - itemHeight - offset; } -void InterceptPopup::updateDataTypeColor(char type) { - const ThemeStyle& theme = ThemeStyle::getTheme(); - currentDataType = type; - - for (const auto& [key, _] : InterceptPopup::dataTypes) { - as( - m_mainLayer->getChildByID("code_buttons"_spr)->getChildByIDRecursive(""_spr + std::string(1, key)) - )->setColor(key == type ? theme.text : theme.line); - } -} - -void InterceptPopup::onPauseRequest(CCObject* sender) { - Mod::get()->setSettingValue("pause-requests", !as(sender)->isOn()); -} - -void InterceptPopup::onCensorData(CCObject* sender) { - Mod::get()->setSettingValue("censor-data", !as(sender)->isOn()); - - this->updateInfo(); -} - -void InterceptPopup::onRememberRequests(CCObject* sender) { - const bool value = !as(sender)->isOn(); - - Mod::get()->setSettingValue("remember-requests", value); - - if (!value) { - m_captureList->createCells(); - } -} - -void InterceptPopup::onRawData(CCObject* sender) { - Mod::get()->setSettingValue("raw-data", !as(sender)->isOn()); - - this->updateInfo(); -} - -void InterceptPopup::onBody(CCObject* sender) { - as(m_mainLayer->getChildByID("info_code"_spr))->setCode(m_currentRequest->formatBody()); - this->updateDataTypeColor('B'); -} - -void InterceptPopup::onQuery(CCObject* sender) { - as(m_mainLayer->getChildByID("info_code"_spr))->setCode({ HttpInfo::JSON, m_currentRequest->formatQuery() }); - this->updateDataTypeColor('Q'); -} - -void InterceptPopup::onHeaders(CCObject* sender) { - as(m_mainLayer->getChildByID("info_code"_spr))->setCode({ HttpInfo::JSON, m_currentRequest->formatHeaders() }); - this->updateDataTypeColor('H'); +void InterceptPopup::onClose(CCObject* obj) { + this->removeFromParent(); } -void InterceptPopup::onResponse(CCObject* sender) { - as(m_mainLayer->getChildByID("info_code"_spr))->setCode(m_currentRequest->formatResponse()); - this->updateDataTypeColor('R'); +void InterceptPopup::onSettings(CCObject* obj) { + openSettingsPopup(Mod::get()); } \ No newline at end of file diff --git a/src/scenes/InterceptPopup.hpp b/src/scenes/InterceptPopup.hpp index 5987d30..38da65f 100644 --- a/src/scenes/InterceptPopup.hpp +++ b/src/scenes/InterceptPopup.hpp @@ -1,8 +1,11 @@ #pragma once +#include #include "../include.hpp" +#include "../nodes/InfoArea.hpp" #include "../nodes/ButtonBar.hpp" #include "../nodes/BorderFix.hpp" +#include "../nodes/CodeBlock.hpp" #include "../objects/HttpInfo.hpp" #include "../objects/ThemeStyle.hpp" #include "../nodes/lists/CaptureList.hpp" @@ -11,11 +14,13 @@ struct InterceptPopup : public Popup<> { static InterceptPopup* get(); static void scene(); + + void reload(); + void copyCode(); protected: bool setup() override; void onClose(CCObject* obj) override; private: - static char currentDataType; static float uiWidth; static float uiHeight; static float uiPadding; @@ -24,29 +29,18 @@ struct InterceptPopup : public Popup<> { static float infoWidth; static float infoRowHeight; static float middleColumnXPosition; - static float codeBlockButtonWidth; static float codeBlockButtonHeight; - static std::vector> dataTypes; - static std::vector> toggles; - CaptureList* m_captureList; - HttpInfo* m_currentRequest; + InfoArea* m_infoArea; + CodeBlock* m_codeBlock; + BorderFix* m_settings; + BorderFix* m_list; - void setupList(); - void setupSettings(); - void setupInfo(); - void setupCodeBlock(); - void updateInfo(); + InfoArea* setupInfo(); + BorderFix* setupList(); + BorderFix* setupSettings(); + CodeBlock* setupCodeBlock(); float getPageHeight(); - float getYPadding(); float getComponentYPosition(float offset, float itemHeight); - void updateDataTypeColor(char type); - void onPauseRequest(CCObject* sender); - void onCensorData(CCObject* sender); - void onRememberRequests(CCObject* sender); - void onRawData(CCObject* sender); - void onBody(CCObject* sender); - void onQuery(CCObject* sender); - void onHeaders(CCObject* sender); - void onResponse(CCObject* sender); + void onSettings(CCObject* obj); }; \ No newline at end of file