Skip to content

Commit

Permalink
yo
Browse files Browse the repository at this point in the history
  • Loading branch information
user95401 committed Oct 19, 2024
1 parent 818eb60 commit 955da74
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 137 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_OSX_ARCHITECTURES "arm64;x86_64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(UnpublishedMods VERSION 1.0.0)
project(UnverifiedMods VERSION 1.0.0)

INCLUDE_DIRECTORIES(src)
add_library(${PROJECT_NAME} SHARED
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# UnpublishedMods
add new button in geode mods menu that shows unpublished mods
# Unverified Mods
add new button in geode mods menu that shows unverified mods.
see for toggle in search filters!

- featuring *"integrated"* custom ui in geode mods layer
- ability to download unverified mods
Expand All @@ -17,7 +18,7 @@ uses [api.geode-sdk.org](https://geode-sdk.github.io/server/)/v1

## Support
- distribute this mod :>
- perform some activity in [github repo](https://github.com/user95401/UnpublishedMods)
- perform some activity in [github repo](https://github.com/user95401/Unverified-Mods)

## Develop

Expand Down
5 changes: 3 additions & 2 deletions about.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# UnpublishedMods
add new button in geode mods menu that shows unpublished mods
# Unverified Mods
add new button in geode mods menu that shows unverified mods.
see for toggle in search filters!

- featuring *"integrated"* custom ui in geode mods layer
- ability to download unverified mods
Expand Down
12 changes: 6 additions & 6 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"geode": "3.6.1",
"geode": "3.8.1",
"gd": {
"win": "2.206",
"android": "2.206",
"mac": "2.206",
"ios": "2.206"
},
"id": "user95401.unpublished_mods",
"name": "Unpublished Mods",
"version": "v1.4.0-beta.1",
"id": "user95401.unverified_mods",
"name": "Unverified Mods",
"version": "v1.4.0",
"developer": "user95401",
"description": "add new button in geode mods menu that shows unpublished mods",
"description": "add new button in geode mods menu that shows unverified mods",
"links": {
"community": "https://discord.com/invite/9e43WMKzhp",
"homepage": "https://geode-sdk.org/mods?status=pending&per_page=10&sort=downloads",
"source": "https://github.com/user95401/UnpublishedMods"
"source": "https://github.com/user95401/Unverified-Mods"
},
"resources": {
"sprites": [
Expand Down
204 changes: 80 additions & 124 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@ using namespace geode::prelude;
return c.get(reinterpret_cast<FriendeeClass__*>(v)); \
}(value)

std::map<std::string, Mod*> ALL_MODS;

auto enabled = false;

web::WebTask WebRequest_send(web::WebRequest* self, std::string_view method, std::string_view givenUrl) {
if (enabled and string::contains(givenUrl.data(), "api.geode-sdk.org/v1/mods")) {
self->param("status", "pending");

if (givenUrl == "https://api.geode-sdk.org/v1/mods") self->param("status", "pending");

CCNode* version = CCScene::get()->getChildByIDRecursive("version");
CCLabelBMFont* value_label = typeinfo_cast<CCLabelBMFont*>(
version ? version->getChildByIDRecursive("value-label") : nullptr
);
if (value_label) givenUrl = string::replace(
givenUrl.data(), "latest",
string::replace(value_label->getString(), "v", "")
);

}
log::debug("{}(std::string_view {}, std::string_view {})", __func__, method, givenUrl);
return self->send(method, givenUrl);
Expand Down Expand Up @@ -73,135 +86,78 @@ void TOGGLE_MAIN() {
}
}

class ModLogoLoader : public CCNode {
public:
EventListener<web::WebTask> m_listener;
Mod* m_mod;
Ref<CCNode> m_node = nullptr;
Ref<LoadingCircleSprite> m_loadinc = nullptr;
int m_methodID = 0;
auto static attach(Mod* mod, CCNode* node = nullptr, int methodID = 0) {
auto loader = new ModLogoLoader;
loader->init();
loader->setID("loader"_spr);
loader->m_mod = (mod);
loader->m_node = node ? node : geode::createModLogo(mod);
loader->m_methodID = (methodID);
auto na_label = loader->m_node->getChildByID("sprite");
if (typeinfo_cast<CCLabelBMFont*>(na_label)) {
loader->m_loadinc = LoadingCircleSprite::create();
loader->m_loadinc->setLayoutOptions(AnchorLayoutOptions::create()->setAnchor(Anchor::Center));
loader->m_loadinc->fadeInCircle(0);
loader->m_loadinc->setScale(0.7f);
loader->m_node->addChild(loader->m_loadinc);
loader->m_node->updateLayout();
loader->request();
}
loader->m_node->addChild(loader);
return loader->m_node;
}
void request() {
auto repo = m_mod->getMetadata().getRepository().value_or("");
auto raw = string::replace(repo,
"https://github.com/", "https://raw.githubusercontent.com/"
);
auto url = std::string();
if (m_methodID == 0) {
url = raw + "/" + m_mod->getVersion().toString() + "/logo.png";
}
if (m_methodID == 1) {
url = raw + "/main/logo.png";
}
if (m_methodID == 2) {
url = raw + "/master/logo.png";
}
if (m_methodID == 3) {
url = "https://api.geode-sdk.org/v1/mods/" + m_mod->getID() + "/logo";
}
m_listener.bind(
[this](web::WebTask::Event* e) {
if (web::WebResponse* res = e->getValue())
response(res);
}
);
auto req = web::WebRequest();
m_listener.setFilter(req.get(url));
};
void response(web::WebResponse* res) {
if (this == nullptr) return;
if (this->m_node == nullptr) return;
auto& rtn = this->m_node;

auto str = res->string().value_or("NO_DATA");
str = res->string().error_or(str);

if ((res->code() < 399) and (res->code() > 10)) {

if (auto na_label = rtn->getChildByID("sprite"))
na_label->removeFromParentAndCleanup(0);

auto error_code = std::error_code();
auto path = dirs::getTempDir() / (m_mod->getID() + ".temp.logo.png");

std::ofstream(path, std::ios::binary) << str;
auto sprite = CCSprite::create(path.string().c_str());
std::filesystem::remove(path, error_code);

if (dynamic_cast<CCSprite*>(sprite) and dynamic_cast<CCNode*>(sprite)) {
sprite->setLayoutOptions(AnchorLayoutOptions::create()->setAnchor(Anchor::Center));
sprite->setScale(rtn->getContentSize().width / sprite->getContentSize().width);
rtn->addChild(sprite);
rtn->updateLayout();
};
}
else {
log::error("code: {}, err: {}",
res->code(), res->string().error_or(str)
);
m_methodID = m_methodID + 1;
if (m_methodID <= 3) return request();
}

if (m_loadinc) m_loadinc->setVisible(0);
}
};

#include <Geode/modify/CCMenuItem.hpp>
class $modify(ModListButtons, CCMenuItem) {
$override void activate() {
CCMenuItem::activate();
if (!this->m_pListener) return;
if (!typeinfo_cast<CCNode*>(this->m_pListener)) return;

auto listener = typeinfo_cast<CCNode*>(this->m_pListener);
if (this->getID() == "filters-button" and listener->getID() == "ModList") {
findFirstChildRecursive<FLAlertLayer>(CCScene::get(),
[](FLAlertLayer* __this) {

//is "Search Filters"
if (!findFirstChildRecursive<CCLabelBMFont>(
__this, [](CCLabelBMFont* lbl) {
return lbl->getString() == std::string("Search Filters");
})) return false;

auto toggle = CCMenuItemExt::createTogglerWithStandardSprites(0.6,
[](auto) {
TOGGLE_MAIN();
}
);
toggle->toggle(enabled);
toggle->setPosition(20, 20);

__this->m_buttonMenu->addChild(toggle);

auto Label = CCLabelBMFont::create("Unverified", "bigFont.fnt");
Label->setScale(0.40f);
Label->setAnchorPoint({ 0.f, 0.5f });
Label->setPosition(32, 20);
__this->m_buttonMenu->addChild(Label);

return true;
}
);
}

if (listener->getID() == "ModList") {

if (this->getID() == "sort-button" or this->getID() == "filters-button") {

findFirstChildRecursive<FLAlertLayer>(CCScene::get(),
[](FLAlertLayer* __this) {

if (!findFirstChildRecursive<CCMenuItem>(
__this, [](CCMenuItem* item) {
auto& org_pfnSelector = item->m_pfnSelector;
auto& org_pListener = item->m_pListener;
CCMenuItemExt::assignCallback<CCMenuItem>(item,
[org_pfnSelector, org_pListener](CCMenuItem* item) {
(org_pListener->*org_pfnSelector)(item);
if (auto reload_btn = typeinfo_cast<CCMenuItem*>(
CCScene::get()->getChildByIDRecursive("reload-button")
)) reload_btn->activate();
}
);
return false;
}
));

return true;
}
);

}

if (this->getID() == "filters-button") {

findFirstChildRecursive<FLAlertLayer>(CCScene::get(),
[](FLAlertLayer* __this) {

//is "Search Filters"
/*if (!findFirstChildRecursive<CCLabelBMFont>(
__this, [](CCLabelBMFont* lbl) {
return lbl->getString() == std::string("Search Filters");
})) return false;*/

auto toggle = CCMenuItemExt::createTogglerWithStandardSprites(0.6,
[](auto) {
TOGGLE_MAIN();
}
);
toggle->toggle(enabled);
toggle->setPosition(20, 20);

__this->m_buttonMenu->addChild(toggle);

auto Label = CCLabelBMFont::create("Unverified", "bigFont.fnt");
Label->setScale(0.40f);
Label->setAnchorPoint({ 0.f, 0.5f });
Label->setPosition(32, 20);
__this->m_buttonMenu->addChild(Label);

return true;
}
);

}

};
}
};

Expand Down
2 changes: 1 addition & 1 deletion support.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Support
- distribute this mod! :>
- perform some activity in [github repo](https://github.com/user95401/UnpublishedMods)
- perform some activity in [github repo](https://github.com/user95401/Unverified-Mods)

0 comments on commit 955da74

Please sign in to comment.