Skip to content

Commit

Permalink
some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Nov 7, 2023
1 parent a95e09d commit ce226dd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.1.1
- Allowed use of partially searching usernames. (Like "fi" instead of "Fire")
- Fixed Pointercrate issue on levels with spaces (Mac Only)
- Fixed issue with friend list searching not working.
# v1.1.0
- More Leaderboards added (Diamonds, User Coins, Demons)
- Added Moderator List
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "1.3.4",
"version": "v1.1.0",
"version": "v1.1.1",
"id": "gdutilsdevs.gdutils",
"name": "GDUtils",
"developer": "Jouca & Firee",
Expand Down
53 changes: 37 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <thread>
#include <queue>
#include <unordered_map>
#include <algorithm>

using namespace geode::prelude;

Expand Down Expand Up @@ -478,7 +479,6 @@ class SearchUserLayer : public BrownAlertDelegate {
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
input_username->setPositionY(10);
this->m_buttonMenu->addChild(input_username);

auto validate_spr = ButtonSprite::create("Search", 60, true, "bigFont.fnt", "GJ_button_01.png", 30, .5F);
auto validate_btn = CCMenuItemSpriteExtra::create(
validate_spr,
Expand Down Expand Up @@ -582,12 +582,20 @@ class $modify(FriendPage, FriendsProfilePage) {
SearchUserLayer::create()->show();
}
static void searchUser(const char* username) {
auto sceneChildCount = CCDirector::sharedDirector()->getRunningScene()->getChildrenCount();
auto self = reinterpret_cast<CCLayer*>(
CCDirector::sharedDirector()->getRunningScene()->getChildren()->objectAtIndex(sceneChildCount - 2)
); // other geode mods adding themselves onto the scene is great.
auto test1 = reinterpret_cast<CCLayer*>(self->getChildren()->objectAtIndex(0));
if (test1->getChildrenCount() < 18) {
auto scene = CCDirector::sharedDirector()->getRunningScene();
auto sceneChildren = scene->getChildren();
CCLayer* test1 = nullptr;
for (unsigned int i = 0; i < scene->getChildrenCount(); i++) {
auto layer = dynamic_cast<CCLayer*>(sceneChildren->objectAtIndex(i));
if (layer != nullptr) {
std::string layerName = typeid(*layer).name() + 6;
if (layerName == "FriendsProfilePage") {
test1 = dynamic_cast<CCLayer*>(layer->getChildren()->objectAtIndex(0));
break; // assume its FriendsProfilePage
}
}
}
if (test1 == nullptr) {
// safeguard from crashing
FLAlertLayer::create(nullptr,
"Error",
Expand All @@ -598,9 +606,8 @@ class $modify(FriendPage, FriendsProfilePage) {
)->show();
return;
}
auto test2 = reinterpret_cast<CCLayer*>(test1->getChildren()->objectAtIndex(1));
auto test3 = reinterpret_cast<CCLayer*>(test2->getChildren()->objectAtIndex(0));
// ^^ this might look bad, sorry.
auto test2 = static_cast<CCLayer*>(test1->getChildren()->objectAtIndex(1));
auto test3 = static_cast<CCLayer*>(test2->getChildren()->objectAtIndex(0));
if (test3->getChildrenCount() <= 0) {
// another safeguard
FLAlertLayer::create(nullptr,
Expand All @@ -612,8 +619,8 @@ class $modify(FriendPage, FriendsProfilePage) {
)->show();
return;
}
auto customList = reinterpret_cast<TableView*>(test3->getChildren()->objectAtIndex(0));
CCContentLayer* contentLayer = reinterpret_cast<CCContentLayer*>(
auto customList = static_cast<TableView*>(test3->getChildren()->objectAtIndex(0));
CCContentLayer* contentLayer = static_cast<CCContentLayer*>(
customList->getChildren()->objectAtIndex(0)
);
int counter_page = 0;
Expand Down Expand Up @@ -655,18 +662,16 @@ class $modify(FriendPage, FriendsProfilePage) {
);
}
const char* str1 = label->getString();
if (strcmp(toLowerCase(str1), toLowerCase(username)) == 0) {
if (strstr(toLowerCase(str1), toLowerCase(username)) != nullptr) {
customList->scrollLayer(-9999999);
customList->scrollLayer(counter_page);

found = true;

break;
}

counter_page += 45;
}

if (!found) {
std::string str = username;
FLAlertLayer::create(nullptr,
Expand Down Expand Up @@ -800,6 +805,22 @@ class $modify(SecretVault, SecretLayer2) {

std::unordered_map<int, int> demonListCache; // Will clear after game exit, or if user deletes level

// love url encoded characters :D
// also for some reason this is required on mac because Geode's web requests doesnt automatically append this for some reason.
// SURELY THIS WONT AFFECT LEVELS WITH SOME OTHER BREAKING SYMBOLS.
std::string url_encode(const std::string& value) {
std::string encoded;
encoded.reserve(value.size());
for (char c : value) {
if (c == ' ') {
encoded += "%20";
} else {
encoded += c;
}
}
return encoded;
}

class $modify(CustomLevelInfo, LevelInfoLayer) {
// chat jippity
void set(int key, int value) {
Expand Down Expand Up @@ -928,7 +949,7 @@ class $modify(CustomLevelInfo, LevelInfoLayer) {
log::info("Sending a request to pointercrate...");
web::AsyncWebRequest()
.join("pointercrate-level")
.fetch(fmt::format("https://pointercrate.com/api/v2/demons/listed/?name={}", level->m_levelName.c_str()))
.fetch(fmt::format("https://pointercrate.com/api/v2/demons/listed/?name={}", url_encode(level->m_levelName).c_str()))
.json()
.then([this, level, levelID, loading_circle, positionLabel, demonSpr, winSize](json::Value const& json) {
loading_circle->fadeAndRemove();
Expand Down

0 comments on commit ce226dd

Please sign in to comment.