2022-12-01 15:42:49 -05:00
|
|
|
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <Geode/modify/LoadingLayer.hpp>
|
2022-12-07 14:21:50 -05:00
|
|
|
#include <Geode/utils/cocos.hpp>
|
2022-12-10 11:30:14 -05:00
|
|
|
#include <array>
|
|
|
|
#include <fmt/format.h>
|
2022-12-14 06:50:46 -05:00
|
|
|
#include <loader/LoaderImpl.hpp>
|
2022-11-09 13:03:53 -05:00
|
|
|
|
2023-03-10 14:33:24 -05:00
|
|
|
using namespace geode::prelude;
|
2022-12-01 15:42:49 -05:00
|
|
|
|
2022-11-09 13:03:53 -05:00
|
|
|
struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
|
2023-09-12 11:12:46 -04:00
|
|
|
CCLabelBMFont* m_smallLabel = nullptr;
|
|
|
|
int m_geodeLoadStep = 0;
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2023-08-16 16:29:51 -04:00
|
|
|
void updateLoadedModsLabel() {
|
2023-08-09 11:55:14 -04:00
|
|
|
auto allMods = Loader::get()->getAllMods();
|
|
|
|
auto count = std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
|
2023-09-11 07:38:14 -04:00
|
|
|
return item->isEnabled();
|
2023-08-09 11:55:14 -04:00
|
|
|
});
|
2023-09-12 11:12:46 -04:00
|
|
|
auto totalCount = std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
|
|
|
|
return item->shouldLoad();
|
|
|
|
});
|
|
|
|
auto str = fmt::format("Geode: Loaded {}/{} mods", count, totalCount);
|
|
|
|
this->setSmallText(str);
|
2023-08-09 11:55:14 -04:00
|
|
|
}
|
2022-12-12 06:46:00 -05:00
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
void setSmallText(std::string const& text) {
|
|
|
|
m_fields->m_smallLabel->setString(text.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook
|
2023-08-09 11:55:14 -04:00
|
|
|
bool init(bool fromReload) {
|
2023-01-23 17:13:20 -05:00
|
|
|
if (!LoadingLayer::init(fromReload)) return false;
|
2023-08-09 11:55:14 -04:00
|
|
|
|
|
|
|
auto winSize = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
m_fields->m_smallLabel = CCLabelBMFont::create("", "goldFont.fnt");
|
|
|
|
m_fields->m_smallLabel->setPosition(winSize.width / 2, 30.f);
|
|
|
|
m_fields->m_smallLabel->setScale(.45f);
|
|
|
|
m_fields->m_smallLabel->setID("geode-small-label");
|
|
|
|
this->addChild(m_fields->m_smallLabel);
|
2023-08-09 11:55:14 -04:00
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-09 11:55:14 -04:00
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
void setupLoadingMods() {
|
2023-09-15 17:17:45 -04:00
|
|
|
CCFileUtils::get()->updatePaths();
|
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
if (Loader::get()->getLoadingState() != Loader::LoadingState::Done) {
|
|
|
|
this->updateLoadedModsLabel();
|
|
|
|
this->waitLoadAssets();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this->continueLoadAssets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setupLoaderResources() {
|
2023-09-15 17:17:45 -04:00
|
|
|
LoaderImpl::get()->addSearchPaths();
|
|
|
|
|
2023-08-09 11:55:14 -04:00
|
|
|
// verify loader resources
|
|
|
|
if (!LoaderImpl::get()->verifyLoaderResources()) {
|
2023-09-12 11:12:46 -04:00
|
|
|
this->setSmallText("Downloading Loader Resources");
|
|
|
|
this->addChild(EventListenerNode<ResourceDownloadFilter>::create(
|
|
|
|
this, &CustomLoadingLayer::updateResourcesProgress
|
|
|
|
));
|
2023-08-09 11:55:14 -04:00
|
|
|
}
|
|
|
|
else {
|
2023-09-12 11:12:46 -04:00
|
|
|
this->setSmallText("Loading Loader Resources");
|
2023-08-09 11:55:14 -04:00
|
|
|
LoaderImpl::get()->updateSpecialFiles();
|
2023-09-12 11:12:46 -04:00
|
|
|
this->continueLoadAssets();
|
2022-10-14 14:04:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 15:42:49 -05:00
|
|
|
void updateResourcesProgress(ResourceDownloadEvent* event) {
|
2022-12-06 14:22:03 -05:00
|
|
|
std::visit(makeVisitor {
|
|
|
|
[&](UpdateProgress const& progress) {
|
2023-09-12 11:12:46 -04:00
|
|
|
this->setSmallText(fmt::format(
|
|
|
|
"Downloading Loader Resources: {}%", progress.first
|
2022-12-06 14:22:03 -05:00
|
|
|
));
|
|
|
|
},
|
|
|
|
[&](UpdateFinished) {
|
2023-09-12 11:12:46 -04:00
|
|
|
this->setSmallText("Downloaded Loader Resources");
|
|
|
|
this->continueLoadAssets();
|
2022-12-06 14:22:03 -05:00
|
|
|
},
|
2022-12-09 05:53:49 -05:00
|
|
|
[&](UpdateFailed const& error) {
|
2022-12-14 06:50:46 -05:00
|
|
|
LoaderImpl::get()->platformMessageBox(
|
2022-12-06 14:22:03 -05:00
|
|
|
"Error updating resources",
|
|
|
|
error + ".\n"
|
2022-12-17 12:08:01 -05:00
|
|
|
"You will have to install resources manually by downloading resources.zip "
|
|
|
|
"from the latest release on GitHub: "
|
|
|
|
"https://github.com/geode-sdk/geode/releases/latest.\n"
|
2022-12-06 14:22:03 -05:00
|
|
|
"The game will be loaded as normal, but please be aware "
|
2022-12-17 12:08:01 -05:00
|
|
|
"that it is very likely to crash. "
|
2022-12-06 14:22:03 -05:00
|
|
|
);
|
2023-09-12 11:12:46 -04:00
|
|
|
this->setSmallText("Failed Loader Resources");
|
|
|
|
this->continueLoadAssets();
|
2022-12-06 14:22:03 -05:00
|
|
|
}
|
|
|
|
}, event->status);
|
2022-10-14 14:04:59 -04:00
|
|
|
}
|
|
|
|
|
2023-09-12 11:12:46 -04:00
|
|
|
void setupModResources() {
|
|
|
|
log::debug("Loading mod resources");
|
|
|
|
this->setSmallText("Loading mod resources");
|
|
|
|
Loader::get()->updateResources(true);
|
|
|
|
this->continueLoadAssets();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getCurrentStep() {
|
|
|
|
return m_fields->m_geodeLoadStep + m_loadStep + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTotalStep() {
|
2023-09-15 17:17:45 -04:00
|
|
|
return 17;
|
2023-09-12 11:12:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateLoadingBar() {
|
|
|
|
auto length = m_sliderGrooveXPos * this->getCurrentStep() / this->getTotalStep();
|
|
|
|
m_sliderBar->setTextureRect({0, 0, length, m_sliderGrooveHeight});
|
|
|
|
}
|
|
|
|
|
|
|
|
void waitLoadAssets() {
|
|
|
|
Loader::get()->queueInMainThread([this]() {
|
|
|
|
this->loadAssets();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void continueLoadAssets() {
|
|
|
|
++m_fields->m_geodeLoadStep;
|
|
|
|
Loader::get()->queueInMainThread([this]() {
|
|
|
|
this->loadAssets();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool skipOnRefresh() {
|
|
|
|
if (m_fromRefresh) {
|
|
|
|
this->continueLoadAssets();
|
2023-08-09 11:55:14 -04:00
|
|
|
}
|
2023-09-12 11:12:46 -04:00
|
|
|
return !m_fromRefresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook
|
2023-09-15 17:17:45 -04:00
|
|
|
void loadAssets() {
|
|
|
|
log::debug("Load step {}", this->getCurrentStep());
|
|
|
|
if (m_loadStep == 14) {
|
|
|
|
switch (m_fields->m_geodeLoadStep) {
|
|
|
|
case 0:
|
|
|
|
if (this->skipOnRefresh()) this->setupLoadingMods();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (this->skipOnRefresh()) this->setupLoaderResources();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this->setupModResources();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
LoadingLayer::loadAssets();
|
|
|
|
this->updateLoadingBar();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->setSmallText("Loading game resources");
|
|
|
|
LoadingLayer::loadAssets();
|
2023-09-12 11:12:46 -04:00
|
|
|
this->updateLoadingBar();
|
2022-11-09 13:03:53 -05:00
|
|
|
}
|
2022-08-01 11:18:03 -04:00
|
|
|
};
|