Skip to content

Commit

Permalink
Fixed bugs, optimized the code and moved the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
SMJSGaming committed Jun 22, 2024
1 parent b71faad commit 25e508e
Show file tree
Hide file tree
Showing 21 changed files with 388 additions and 283 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
17 changes: 9 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
22 changes: 14 additions & 8 deletions mod.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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.",
Expand All @@ -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
}
}
}
2 changes: 1 addition & 1 deletion src/include.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 8 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
}, InvokeBindFilter(nullptr, "open_capture_menu"_spr));

new EventListener([=](InvokeBindEvent* event) {
InterceptPopup* popup = InterceptPopup::get();

if (event->isDown() && popup) {
as<JSONCodeBlock*>(popup->m_mainLayer->getChildByID("info_code"_spr))->copyCode();
if (event->isDown()) {
OPT(InterceptPopup::get())->copyCode();
}

return ListenerResult::Propagate;
Expand All @@ -60,6 +58,12 @@
if (HttpInfo::requests.size() > 1) {
HttpInfo::requests.resize(1);
}

OPT(InterceptPopup::get())->reload();
}
});

listenForAllSettingChanges(+[](SettingValue* event) {
OPT(InterceptPopup::get())->reload();
});
}
14 changes: 8 additions & 6 deletions src/mods/CCHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("log-requests")) {
log::info("Sending request:\n{}\nQuery: {}\nHeaders: {}\nBody: {}",
requestInfo->generateBasicInfo(false),
requestInfo->formatQuery(),
requestInfo->formatHeaders(),
requestInfo->formatBody().second
);
}

CCHttpClient::send(request);
}
99 changes: 99 additions & 0 deletions src/nodes/CodeBlock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "CodeBlock.hpp"
#include <vector>

std::vector<std::pair<char, SEL_MenuHandler>> 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<CCMenuItemSpriteExtra*> 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<CCSprite>(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;
}
}
28 changes: 28 additions & 0 deletions src/nodes/CodeBlock.hpp
Original file line number Diff line number Diff line change
@@ -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<std::pair<char, SEL_MenuHandler>> dataTypes;
static char currentDataType;

std::unordered_map<char, CCLabelBMFont*> 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);
};
40 changes: 40 additions & 0 deletions src/nodes/InfoArea.cpp
Original file line number Diff line number Diff line change
@@ -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<SimpleTextArea*>(this->getNode()->getChildByID("info_text"_spr))->setText(request->generateBasicInfo());
}
12 changes: 12 additions & 0 deletions src/nodes/InfoArea.hpp
Original file line number Diff line number Diff line change
@@ -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);
};
Loading

0 comments on commit 25e508e

Please sign in to comment.