This commit is contained in:
altalk23 2023-09-12 16:26:48 +03:00
commit 5c4694a740
14 changed files with 55 additions and 75 deletions

View file

@ -1250,6 +1250,7 @@ class cocos2d::extension::CCScrollView {
[[link(win)]]
class cocos2d {
static auto FNTConfigLoadFile(char const*) = mac 0x344f10;
static auto ccGLUseProgram(GLuint) = mac 0x1ae540;
static auto ccGLBlendFunc(GLenum, GLenum) = mac 0x1ae560;
static auto ccDrawSolidRect(cocos2d::CCPoint, cocos2d::CCPoint, cocos2d::_ccColor4F) = mac 0xecf00;
static auto ccGLEnableVertexAttribs(unsigned int) = mac 0x1ae740;

View file

@ -85,14 +85,14 @@ namespace geode {
ghc::filesystem::path getPackagePath() const;
VersionInfo getVersion() const;
bool isEnabled() const;
bool isLoaded() const;
[[deprecated("use isEnabled instead")]] bool isLoaded() const;
bool supportsDisabling() const;
bool canDisable() const;
bool canEnable() const;
[[deprecated("always true")]] bool canDisable() const;
[[deprecated("always true")]] bool canEnable() const;
bool needsEarlyLoad() const;
[[deprecated]] bool supportsUnloading() const;
[[deprecated("use wasSuccessfullyLoaded instead")]] bool wasSuccesfullyLoaded() const;
bool wasSuccessfullyLoaded() const;
[[deprecated("always false")]] bool supportsUnloading() const;
[[deprecated("use isEnabled instead")]] bool wasSuccesfullyLoaded() const;
[[deprecated("use isEnabled instead")]] bool wasSuccessfullyLoaded() const;
[[deprecated("use getMetadata instead")]] ModInfo getModInfo() const;
ModMetadata getMetadata() const;
ghc::filesystem::path getTempDir() const;

View file

@ -16,7 +16,7 @@ struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
void updateLoadedModsLabel() {
auto allMods = Loader::get()->getAllMods();
auto count = std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
return item->isLoaded();
return item->isEnabled();
});
auto str = fmt::format("Geode: Loaded {}/{} mods", count, allMods.size());
m_fields->m_loadedModsLabel->setCString(str.c_str());

View file

@ -24,14 +24,13 @@ static void printGeodeInfo(std::stringstream& stream) {
static void printMods(std::stringstream& stream) {
auto mods = Loader::get()->getAllMods();
if (!mods.size()) {
if (mods.empty()) {
stream << "<None>\n";
}
using namespace std::string_view_literals;
for (auto& mod : mods) {
stream << fmt::format("{:>8} | {:>8} | [{}] {}\n",
mod->isLoaded() ? "Loaded"sv : "Unloaded"sv,
mod->isEnabled() ? "Enabled"sv : "Disabled"sv,
stream << fmt::format("{} | [{}] {}\n",
mod->isEnabled() ? "x"sv : " "sv,
mod->getVersion().toString(), mod->getID()
);
}

View file

@ -8,6 +8,8 @@
#include <hash/hash.hpp>
#include <Geode/utils/JsonValidation.hpp>
#include <thread>
#ifdef GEODE_IS_WINDOWS
#include <filesystem>
#endif
@ -318,19 +320,25 @@ void Index::Impl::downloadIndex() {
return;
}
// unzip new index
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
.expect("Unable to unzip new index");
if (!unzip) {
IndexUpdateEvent(UpdateFailed(unzip.unwrapErr())).post();
return;
}
std::thread([=, this]() {
// unzip new index
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
.expect("Unable to unzip new index");
if (!unzip) {
Loader::get()->queueInMainThread([unzip] {
IndexUpdateEvent(UpdateFailed(unzip.unwrapErr())).post();
});
return;
}
// remove the directory github adds to the root of the zip
(void)flattenGithubRepo(targetDir);
// remove the directory github adds to the root of the zip
(void)flattenGithubRepo(targetDir);
// update index
this->updateFromLocalTree();
Loader::get()->queueInMainThread([this] {
// update index
this->updateFromLocalTree();
});
}).detach();
})
.expect([](std::string const& err) {
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
@ -448,7 +456,8 @@ void Index::update(bool force) {
// update sources
if (force) {
m_impl->downloadIndex();
} else {
}
else {
m_impl->checkForUpdates();
}
}

View file

@ -201,13 +201,13 @@ Mod* Loader::Impl::getInstalledMod(std::string const& id) const {
}
bool Loader::Impl::isModLoaded(std::string const& id) const {
return m_mods.count(id) && m_mods.at(id)->isLoaded();
return m_mods.count(id) && m_mods.at(id)->isEnabled();
}
Mod* Loader::Impl::getLoadedMod(std::string const& id) const {
if (m_mods.count(id)) {
auto mod = m_mods.at(id);
if (mod->isLoaded()) {
if (mod->isEnabled()) {
return mod;
}
}
@ -225,8 +225,6 @@ void Loader::Impl::updateModResources(Mod* mod) {
if (mod->getMetadata().getSpritesheets().empty())
return;
auto searchPath = mod->getResourcesDir();
log::debug("Adding resources for {}", mod->getID());
// add spritesheets
@ -402,7 +400,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) {
log::debug("{} {}", node->getID(), node->getVersion());
log::pushNest();
if (node->isLoaded()) {
if (node->isEnabled()) {
for (auto const& dep : node->m_impl->m_dependants) {
this->loadModGraph(dep, early);
}
@ -438,7 +436,7 @@ void Loader::Impl::findProblems() {
log::pushNest();
for (auto const& dep : mod->getMetadata().getDependencies()) {
if (dep.mod && dep.mod->isLoaded() && dep.version.compare(dep.mod->getVersion()))
if (dep.mod && dep.mod->isEnabled() && dep.version.compare(dep.mod->getVersion()))
continue;
switch(dep.importance) {
case ModMetadata::Dependency::Importance::Suggested:
@ -493,7 +491,7 @@ void Loader::Impl::findProblems() {
Mod* myEpicMod = mod; // clang fix
// if the mod is not loaded but there are no problems related to it
if (!mod->isLoaded() &&
if (!mod->isEnabled() &&
Mod::get()->getSavedValue<bool>("should-load-" + mod->getID(), true) &&
!std::any_of(m_problems.begin(), m_problems.end(), [myEpicMod](auto& item) {
return std::holds_alternative<ModMetadata>(item.cause) &&

View file

@ -47,7 +47,7 @@ bool Mod::isEnabled() const {
}
bool Mod::isLoaded() const {
return m_impl->isLoaded();
return this->isEnabled();
}
bool Mod::supportsDisabling() const {
@ -55,11 +55,11 @@ bool Mod::supportsDisabling() const {
}
bool Mod::canDisable() const {
return m_impl->canDisable();
return true;
}
bool Mod::canEnable() const {
return m_impl->canEnable();
return true;
}
bool Mod::needsEarlyLoad() const {
@ -71,10 +71,10 @@ bool Mod::supportsUnloading() const {
}
bool Mod::wasSuccesfullyLoaded() const {
return this->wasSuccessfullyLoaded();
return this->isEnabled();
}
bool Mod::wasSuccessfullyLoaded() const {
return m_impl->wasSuccessfullyLoaded();
return this->isEnabled();
}
ModInfo Mod::getModInfo() const {

View file

@ -42,8 +42,9 @@ Result<> Mod::Impl::setup() {
if (!loadRes) {
log::warn("Unable to load data for \"{}\": {}", m_metadata.getID(), loadRes.unwrapErr());
}
if (LoaderImpl::get()->m_isSetup) {
Loader::get()->updateResources(false);
if (!m_resourcesLoaded) {
LoaderImpl::get()->updateModResources(m_self);
m_resourcesLoaded = true;
}
return Ok();
@ -112,22 +113,10 @@ bool Mod::Impl::isEnabled() const {
return m_enabled;
}
bool Mod::Impl::isLoaded() const {
return m_binaryLoaded;
}
bool Mod::Impl::supportsDisabling() const {
return m_metadata.getID() != "geode.loader";
}
bool Mod::Impl::canDisable() const {
return true;
}
bool Mod::Impl::canEnable() const {
return true;
}
bool Mod::Impl::needsEarlyLoad() const {
auto deps = m_dependants;
return getMetadata().needsEarlyLoad() ||
@ -136,10 +125,6 @@ bool Mod::Impl::needsEarlyLoad() const {
});
}
bool Mod::Impl::wasSuccessfullyLoaded() const {
return !this->isEnabled() || this->isLoaded();
}
std::vector<Hook*> Mod::Impl::getHooks() const {
return m_hooks;
}
@ -321,7 +306,7 @@ bool Mod::Impl::hasSetting(std::string const& key) const {
Result<> Mod::Impl::loadBinary() {
log::debug("Loading binary for mod {}", m_metadata.getID());
if (m_binaryLoaded)
if (m_enabled)
return Ok();
LoaderImpl::get()->provideNextMod(m_self);
@ -333,7 +318,6 @@ Result<> Mod::Impl::loadBinary() {
log::error("Failed to load binary for mod {}: {}", m_metadata.getID(), res.unwrapErr());
return res;
}
m_binaryLoaded = true;
LoaderImpl::get()->releaseNextMod();
@ -612,8 +596,9 @@ ModJson Mod::Impl::getRuntimeInfo() const {
for (auto patch : m_patches) {
obj["patches"].as_array().push_back(ModJson(patch->getRuntimeInfo()));
}
// TODO: so which one is it
// obj["enabled"] = m_enabled;
obj["loaded"] = m_binaryLoaded;
obj["loaded"] = m_enabled;
obj["temp-dir"] = this->getTempDir();
obj["save-dir"] = this->getSaveDir();
obj["config-dir"] = this->getConfigDir(false);
@ -652,7 +637,6 @@ Mod* Loader::Impl::createInternalMod() {
else {
mod = new Mod(infoRes.unwrap());
}
mod->m_impl->m_binaryLoaded = true;
mod->m_impl->m_enabled = true;
m_mods.insert({ mod->getID(), mod });
return mod;

View file

@ -26,10 +26,6 @@ namespace geode {
* Whether the mod is enabled or not
*/
bool m_enabled = false;
/**
* Whether the mod binary is loaded or not
*/
bool m_binaryLoaded = false;
/**
* Mod temp directory name
*/
@ -62,7 +58,6 @@ namespace geode {
*/
bool m_resourcesLoaded = false;
ModRequestedAction m_requestedAction = ModRequestedAction::None;
Impl(Mod* self, ModMetadata const& metadata);
@ -84,12 +79,8 @@ namespace geode {
ghc::filesystem::path getPackagePath() const;
VersionInfo getVersion() const;
bool isEnabled() const;
bool isLoaded() const;
bool supportsDisabling() const;
bool canDisable() const;
bool canEnable() const;
bool needsEarlyLoad() const;
bool wasSuccessfullyLoaded() const;
ModMetadata getMetadata() const;
ghc::filesystem::path getTempDir() const;
ghc::filesystem::path getBinaryPath() const;

View file

@ -15,7 +15,7 @@ ModInfo::Impl& ModInfoImpl::getImpl(ModInfo& info) {
bool Dependency::isResolved() const {
return !this->required ||
(this->mod && this->mod->isLoaded() && this->mod->isEnabled() &&
(this->mod && this->mod->isEnabled() &&
this->version.compare(this->mod->getVersion()));
}

View file

@ -18,7 +18,7 @@ ModMetadata::Impl& ModMetadataImpl::getImpl(ModMetadata& info) {
bool ModMetadata::Dependency::isResolved() const {
return this->importance != Importance::Required ||
this->mod && this->mod->isLoaded() && this->version.compare(this->mod->getVersion());
this->mod && this->mod->isEnabled() && this->version.compare(this->mod->getVersion());
}
bool ModMetadata::Incompatibility::isResolved() const {

View file

@ -151,7 +151,7 @@ static Mod* modFromAddress(void const* addr) {
}
for (auto& mod : Loader::get()->getAllMods()) {
if (!mod->isLoaded() || !ghc::filesystem::exists(mod->getBinaryPath())) {
if (!mod->isEnabled() || !ghc::filesystem::exists(mod->getBinaryPath())) {
continue;
}
if (ghc::filesystem::equivalent(imagePath, mod->getBinaryPath())) {

View file

@ -126,7 +126,7 @@ void Loader::Impl::setupIPC() {
if (ConnectNamedPipe(pipe, nullptr)) {
// log::debug("Got connection, creating thread");
std::thread pipeThread(&ipcPipeThread, pipe);
SetThreadDescription(pipeThread.native_handle(), L"Geode IPC Pipe");
// SetThreadDescription(pipeThread.native_handle(), L"Geode IPC Pipe");
pipeThread.detach();
}
else {
@ -135,7 +135,7 @@ void Loader::Impl::setupIPC() {
}
}
});
SetThreadDescription(ipcThread.native_handle(), L"Geode Main IPC");
// SetThreadDescription(ipcThread.native_handle(), L"Geode Main IPC");
ipcThread.detach();
log::debug("IPC set up");

View file

@ -291,7 +291,7 @@ bool ModCell::init(
auto viewBtn = CCMenuItemSpriteExtra::create(viewSpr, this, menu_selector(ModCell::onInfo));
m_menu->addChild(viewBtn);
if (m_mod->wasSuccessfullyLoaded()) {
if (m_mod->isEnabled()) {
auto latestIndexItem = Index::get()->getMajorItem(
mod->getMetadata().getID()
);
@ -314,7 +314,7 @@ bool ModCell::init(
}
}
if (m_mod->wasSuccessfullyLoaded() && m_mod->getMetadata().getID() != "geode.loader") {
if (m_mod->getMetadata().getID() != "geode.loader") {
m_enableToggle =
CCMenuItemToggler::createWithStandardSprites(this, menu_selector(ModCell::onEnable), .7f);
m_enableToggle->setPosition(-45.f, 0.f);
@ -322,8 +322,6 @@ bool ModCell::init(
}
}
auto exMark = CCSprite::createWithSpriteFrameName("exMark_001.png");
exMark->setScale(.5f);