Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"geode": "4.7.0",
"geode": "5.0.0-beta.3",
"gd": {
"win": "2.2074",
"mac": "2.2074",
"ios": "2.2074",
"android": "2.2074"
"win": "2.2081",
"mac": "2.2081",
"ios": "2.2081",
"android": "2.2081"
},
"id": "dulak.wraith-help",
"name": "Wraith Helper",
Expand Down
60 changes: 35 additions & 25 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#include <Geode/modify/SecretLayer5.hpp>
#include <matjson.hpp>


using namespace geode::prelude;

class MyPopup : public geode::Popup<> {
class MyPopup : public geode::Popup {
protected:
EventListener<web::WebTask> m_listener;
async::TaskHolder<geode::utils::web::WebResponse> m_listener;
size_t m_currentPage = 0;
static constexpr size_t kPerPage = 5;
CCMenu* m_contentMenu = nullptr;
Expand All @@ -20,13 +19,15 @@ class MyPopup : public geode::Popup<> {
CCLabelBMFont* m_titleLabel = nullptr;
CCLabelBMFont* m_codeLabel = nullptr;
std::map<std::string, std::tuple<std::string, std::string> > codes = {};
std::vector<std::string> m_keys;
bool setup() override {
std::vector<std::string> m_keys;

bool init() {
if (!Popup::init(320.f, 260.f)) return false;

this->setTitle("Wraith helper");

m_contentMenu = CCMenu::create();
m_contentMenu->setContentSize({ m_size.width - 4.f, 140.f });
m_contentMenu = CCMenu::create();
m_contentMenu->setContentSize({ m_size.width - 4.f, 140.f });
m_contentMenu->ignoreAnchorPointForPosition(false);
m_contentMenu->setAnchorPoint({ 0.5f, 0.5f });
m_contentMenu->setPosition({ m_size.width / 2, m_size.height / 2 - 10.f });
Expand All @@ -37,6 +38,7 @@ class MyPopup : public geode::Popup<> {
updatePageUI();
return true;
}

void updatePageUI() {
auto totalItems = m_keys.size();
if (totalItems == 0) {
Expand All @@ -54,7 +56,7 @@ class MyPopup : public geode::Popup<> {
size_t start = m_currentPage * kPerPage;
size_t end = std::min(start + kPerPage, totalItems);

float containerW = m_contentMenu ? m_contentMenu->getContentSize().width : (m_size.width - 4.f);
float containerW = m_contentMenu ? m_contentMenu->getContentSize().width : (m_size.width - 4.f);
float yTop = (m_contentMenu ? m_contentMenu->getContentSize().height : 140.f) + 20.f;
float lineH = 28.f;

Expand Down Expand Up @@ -119,6 +121,7 @@ class MyPopup : public geode::Popup<> {

updateProgressDisplay();
}

void rebuildIndex() {
m_keys.clear();
m_keys.reserve(codes.size());
Expand All @@ -131,11 +134,14 @@ class MyPopup : public geode::Popup<> {
auto const& codeB = std::get<1>(tb);
if (codeA != codeB) return codeA < codeB;
return a < b;
});
}
);
}

size_t totalPages() const {
return (m_keys.size() + kPerPage - 1) / kPerPage;
}

void onInfo(CCObject* sender) {
auto button = static_cast<CCMenuItemSpriteExtra*>(sender);
int index = button ? button->getTag() : -1;
Expand All @@ -145,10 +151,24 @@ class MyPopup : public geode::Popup<> {
auto const& reward = std::get<0>(tup);
FLAlertLayer::create("Code Info", reward.c_str(), "OK")->show();
}

void downloadCodes() {
m_listener.bind([this](web::WebTask::Event* e) {
if (auto* res = e->getValue()) {
auto body = res->string().unwrapOr("");
auto req = web::WebRequest();
bool codesSecret = Mod::get()->getSettingValue<bool>("secret");
bool soggy = Mod::get()->getSettingValue<bool>("soggy");
std::string url;
if (codesSecret) {
url = "https://raw.githubusercontent.com/dulakgg/codes/main/secretcodes.json";
} else if (soggy) {
url = "https://raw.githubusercontent.com/dulakgg/codes/main/soggycodes.json";
} else {
url = "https://raw.githubusercontent.com/dulakgg/codes/main/codes.json";
}

m_listener.spawn(
req.get(url),
[this](web::WebResponse res) {
auto body = res.string().unwrapOr("");
auto parsed = matjson::parse(body);
if (!parsed) {
log::error("JSON failed (interesting reset your dns pls)): {}", parsed.unwrapErr());
Expand All @@ -171,18 +191,7 @@ class MyPopup : public geode::Popup<> {
updatePageUI();
updateProgressDisplay();
}
});

auto req = web::WebRequest();
bool codesSecret = Mod::get()->getSettingValue<bool>("secret");
bool soggy = Mod::get()->getSettingValue<bool>("soggy");
if (codesSecret) {
m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/secretcodes.json"));
} else if (soggy) {
m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/soggycodes.json"));
} else {
m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/codes.json"));
}
);
}
void setupPaginationControls() {
auto paginationMenu = CCMenu::create();
Expand Down Expand Up @@ -283,7 +292,8 @@ class MyPopup : public geode::Popup<> {
public:
static MyPopup* create() {
auto ret = new MyPopup();
if (ret->initAnchored(320.f, 260.f, "GJ_square07.png")) {
ret->m_bgSprite = NineSlice::create("GJ_square07.png");
if (ret->init()) {
ret->autorelease();
return ret;
}
Expand Down
Loading