Skip to content

Commit

Permalink
Added a bug fix for Geode requests
Browse files Browse the repository at this point in the history
  • Loading branch information
SMJSGaming committed Jul 12, 2024
1 parent d472892 commit 7ed37a2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# GDIntercept Changelog

## v0.3.0-alpha.3 (2024-07-11) - API, Geode and Request Flow Support
## v0.3.1-alpha.3 (2024-07-12) - Bugfix Update

- Added support for Geode web API
- Fixed a bug where certain requests would cause an unallocated reference exception
- Optimized the content loading

## v0.3.0-alpha.3 (2024-07-12) - API, Geode and Request Flow Support

- Added support for the Geode web API
- Added support for request pausing, resuming and resending
- Added API support for other mods
- Added a lot more keybinds
Expand Down
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.2.3)
project(GDIntercept VERSION 0.3.1)

file(GLOB_RECURSE SOURCES "src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
Expand Down
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ Release Todo:
☐ Add a formatted text to original converter in the converters
☐ Add a copy button to the code block and info block
☐ Add badges to the capture cells (e.g. pause, finished, source)
☐ Add a way to variably limit the amount of requests cached
☐ Add window ratio support
Nice To Haves:
☐ Custom theme support
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "3.2.0",
"version": "v0.3.0-alpha.3",
"version": "v0.3.1-alpha.3",
"id": "smjs.gdintercept",
"name": "GDIntercept",
"api": {
Expand Down
28 changes: 14 additions & 14 deletions src/nodes/cells/CodeLineCell.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "CodeLineCell.hpp"

CodeLineCell* CodeLineCell::create(const HttpInfo::HttpContent& code, const size_t lineNumber, const float lineNumberWidth, JSONColor& color) {
CodeLineCell* instance = new CodeLineCell(lineNumberWidth, color);
CodeLineCell* instance = new CodeLineCell();

if (instance && instance->init(code.type, code.contents, lineNumber)) {
if (instance && instance->init(code, lineNumber, lineNumberWidth, color)) {
instance->autorelease();

return instance;
Expand All @@ -14,35 +14,35 @@ CodeLineCell* CodeLineCell::create(const HttpInfo::HttpContent& code, const size
}
}

CodeLineCell::CodeLineCell(const float lineNumberWidth, JSONColor& color) : m_lineNumberWidth(lineNumberWidth), m_color(color) { }
bool CodeLineCell::init(const HttpInfo::HttpContent& code, const size_t lineNumber, const float lineNumberWidth, JSONColor& color) {
const ThemeStyle& theme = ThemeStyle::getTheme();
// Fuck it, we're truncating this bitch
std::string truncatedCode = code.contents.size() >= 300 ? code.contents.substr(0, 300) : std::string(code.contents);
CCLabelBMFont* lineNumberLabel = CCLabelBMFont::create(std::to_string(lineNumber).c_str(), theme.fontName);

bool CodeLineCell::init(const HttpInfo::ContentType content, std::string code, const size_t lineNumber) {
if (!CCLayer::init()) {
return false;
}

for (size_t index = code.find('\t'); index != std::string::npos; index = code.find('\t')) {
code.replace(index, 1, " ");
for (size_t index = truncatedCode.find('\t'); index != std::string::npos; index = truncatedCode.find('\t')) {
truncatedCode.replace(index, 1, " ");
}

const ThemeStyle& theme = ThemeStyle::getTheme();
CCLabelBMFont* lineNumberLabel = CCLabelBMFont::create(std::to_string(lineNumber).c_str(), theme.fontName);
// Fuck it, we're truncating this bitch
CCLabelBMFont* codeLabel = CCLabelBMFont::create((code.size() >= 300 ? code.substr(0, 297) + "..." : code).c_str(), theme.fontName);
CCLabelBMFont* codeLabel = CCLabelBMFont::create(truncatedCode.c_str(), theme.fontName);

if (content == HttpInfo::JSON) {
m_color.parseLine(code, codeLabel);
if (code.type == HttpInfo::JSON) {
color.parseLine(code.contents, codeLabel);
} else {
codeLabel->setColor(theme.text);
}

lineNumberLabel->setScale(theme.fontSize);
lineNumberLabel->setAnchorPoint(BOTTOM_RIGHT);
lineNumberLabel->setColor(theme.lineNum);
lineNumberLabel->setPosition({ m_lineNumberWidth, theme.lineHeight / 2 });
lineNumberLabel->setPosition({ lineNumberWidth, theme.lineHeight / 2 });
codeLabel->setScale(theme.fontSize);
codeLabel->setAnchorPoint(BOTTOM_LEFT);
codeLabel->setPosition({ m_lineNumberWidth + PADDING, theme.lineHeight / 2 });
codeLabel->setPosition({ lineNumberWidth + PADDING, theme.lineHeight / 2 });
this->addChild(lineNumberLabel);
this->addChild(codeLabel);

Expand Down
6 changes: 1 addition & 5 deletions src/nodes/cells/CodeLineCell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ class CodeLineCell : public CCLayer {
public:
static CodeLineCell* create(const HttpInfo::HttpContent& code, const size_t lineNumber, const float lineNumberWidth, JSONColor& color);
private:
float m_lineNumberWidth;
JSONColor& m_color;

CodeLineCell(const float lineNumberWidth, JSONColor& color);
bool init(const HttpInfo::ContentType content, std::string code, const size_t lineNumber);
bool init(const HttpInfo::HttpContent& code, const size_t lineNumber, const float lineNumberWidth, JSONColor& color);
};
17 changes: 10 additions & 7 deletions src/proxy/ProxyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ ProxyHandler* ProxyHandler::create(CCHttpRequest* request) {

request->retain();
instance->retain();
ProxyHandler::registerProxy(instance);
RequestEvent(instance->getInfo()).post();

return instance;
Expand All @@ -58,7 +57,6 @@ ProxyHandler* ProxyHandler::create(web::WebRequest* request, const std::string&
ProxyHandler* instance = new ProxyHandler(request, method, url);

instance->retain();
ProxyHandler::registerProxy(instance);
RequestEvent(instance->getInfo()).post();

return instance;
Expand All @@ -74,13 +72,15 @@ void ProxyHandler::registerProxy(ProxyHandler* proxy) {
ProxyHandler::cachedProxies.insert(ProxyHandler::cachedProxies.begin(), proxy);
}

ProxyHandler::ProxyHandler(CCHttpRequest* request) : m_info(new HttpInfo(request)),
ProxyHandler::ProxyHandler(CCHttpRequest* request) : m_modRequest(nullptr),
m_cocosRequest(request),
m_modRequest(nullptr),
m_info(new HttpInfo(request)),
m_originalTarget(request->getTarget()),
m_originalProxy(request->getSelector()) {
request->setResponseCallback(this, httpresponse_selector(ProxyHandler::onCocosResponse));

ProxyHandler::registerProxy(this);

std::thread([this, request]() {
while (Mod::get()->getSettingValue<bool>("pause-requests")) {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
Expand All @@ -91,10 +91,13 @@ m_originalProxy(request->getSelector()) {
}).detach();
}

ProxyHandler::ProxyHandler(web::WebRequest* request, const std::string& method, const std::string& url) : m_cocosRequest(nullptr),
ProxyHandler::ProxyHandler(web::WebRequest* request, const std::string& method, const std::string& url) : m_modRequest(new web::WebRequest(*request)),
m_cocosRequest(nullptr),
m_originalTarget(nullptr),
m_originalProxy(nullptr) {
m_info = new HttpInfo(m_modRequest = new web::WebRequest(*request), method, url);
m_info = new HttpInfo(m_modRequest, method, url);

ProxyHandler::registerProxy(this);

m_modTask = web::WebTask::run([this, method, url](auto progress, auto cancelled) -> web::WebTask::Result {
web::WebResponse* response = nullptr;
Expand All @@ -109,7 +112,7 @@ m_originalProxy(nullptr) {

m_modRequest->send(m_info->getRequest().getURL().getMethod(), url).listen([&response](web::WebResponse* taskResponse) {
response = new web::WebResponse(*taskResponse);
}, [&progress](web::WebProgress* taskProgress) {
}, [progress](web::WebProgress* taskProgress) {
progress(*taskProgress);
});
m_info->resume();
Expand Down

0 comments on commit 7ed37a2

Please sign in to comment.