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)]] [[link(win)]]
class cocos2d { class cocos2d {
static auto FNTConfigLoadFile(char const*) = mac 0x344f10; static auto FNTConfigLoadFile(char const*) = mac 0x344f10;
static auto ccGLUseProgram(GLuint) = mac 0x1ae540;
static auto ccGLBlendFunc(GLenum, GLenum) = mac 0x1ae560; static auto ccGLBlendFunc(GLenum, GLenum) = mac 0x1ae560;
static auto ccDrawSolidRect(cocos2d::CCPoint, cocos2d::CCPoint, cocos2d::_ccColor4F) = mac 0xecf00; static auto ccDrawSolidRect(cocos2d::CCPoint, cocos2d::CCPoint, cocos2d::_ccColor4F) = mac 0xecf00;
static auto ccGLEnableVertexAttribs(unsigned int) = mac 0x1ae740; static auto ccGLEnableVertexAttribs(unsigned int) = mac 0x1ae740;

View file

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

View file

@ -16,7 +16,7 @@ struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
void updateLoadedModsLabel() { void updateLoadedModsLabel() {
auto allMods = Loader::get()->getAllMods(); auto allMods = Loader::get()->getAllMods();
auto count = std::count_if(allMods.begin(), allMods.end(), [&](auto& item) { 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()); auto str = fmt::format("Geode: Loaded {}/{} mods", count, allMods.size());
m_fields->m_loadedModsLabel->setCString(str.c_str()); 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) { static void printMods(std::stringstream& stream) {
auto mods = Loader::get()->getAllMods(); auto mods = Loader::get()->getAllMods();
if (!mods.size()) { if (mods.empty()) {
stream << "<None>\n"; stream << "<None>\n";
} }
using namespace std::string_view_literals; using namespace std::string_view_literals;
for (auto& mod : mods) { for (auto& mod : mods) {
stream << fmt::format("{:>8} | {:>8} | [{}] {}\n", stream << fmt::format("{} | [{}] {}\n",
mod->isLoaded() ? "Loaded"sv : "Unloaded"sv, mod->isEnabled() ? "x"sv : " "sv,
mod->isEnabled() ? "Enabled"sv : "Disabled"sv,
mod->getVersion().toString(), mod->getID() mod->getVersion().toString(), mod->getID()
); );
} }

View file

@ -8,6 +8,8 @@
#include <hash/hash.hpp> #include <hash/hash.hpp>
#include <Geode/utils/JsonValidation.hpp> #include <Geode/utils/JsonValidation.hpp>
#include <thread>
#ifdef GEODE_IS_WINDOWS #ifdef GEODE_IS_WINDOWS
#include <filesystem> #include <filesystem>
#endif #endif
@ -318,19 +320,25 @@ void Index::Impl::downloadIndex() {
return; return;
} }
// unzip new index std::thread([=, this]() {
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true) // unzip new index
.expect("Unable to unzip new index"); auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
if (!unzip) { .expect("Unable to unzip new index");
IndexUpdateEvent(UpdateFailed(unzip.unwrapErr())).post(); if (!unzip) {
return; Loader::get()->queueInMainThread([unzip] {
} IndexUpdateEvent(UpdateFailed(unzip.unwrapErr())).post();
});
return;
}
// remove the directory github adds to the root of the zip // remove the directory github adds to the root of the zip
(void)flattenGithubRepo(targetDir); (void)flattenGithubRepo(targetDir);
// update index Loader::get()->queueInMainThread([this] {
this->updateFromLocalTree(); // update index
this->updateFromLocalTree();
});
}).detach();
}) })
.expect([](std::string const& err) { .expect([](std::string const& err) {
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post(); IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
@ -448,7 +456,8 @@ void Index::update(bool force) {
// update sources // update sources
if (force) { if (force) {
m_impl->downloadIndex(); m_impl->downloadIndex();
} else { }
else {
m_impl->checkForUpdates(); 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 { 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 { Mod* Loader::Impl::getLoadedMod(std::string const& id) const {
if (m_mods.count(id)) { if (m_mods.count(id)) {
auto mod = m_mods.at(id); auto mod = m_mods.at(id);
if (mod->isLoaded()) { if (mod->isEnabled()) {
return mod; return mod;
} }
} }
@ -225,8 +225,6 @@ void Loader::Impl::updateModResources(Mod* mod) {
if (mod->getMetadata().getSpritesheets().empty()) if (mod->getMetadata().getSpritesheets().empty())
return; return;
auto searchPath = mod->getResourcesDir();
log::debug("Adding resources for {}", mod->getID()); log::debug("Adding resources for {}", mod->getID());
// add spritesheets // add spritesheets
@ -402,7 +400,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) {
log::debug("{} {}", node->getID(), node->getVersion()); log::debug("{} {}", node->getID(), node->getVersion());
log::pushNest(); log::pushNest();
if (node->isLoaded()) { if (node->isEnabled()) {
for (auto const& dep : node->m_impl->m_dependants) { for (auto const& dep : node->m_impl->m_dependants) {
this->loadModGraph(dep, early); this->loadModGraph(dep, early);
} }
@ -438,7 +436,7 @@ void Loader::Impl::findProblems() {
log::pushNest(); log::pushNest();
for (auto const& dep : mod->getMetadata().getDependencies()) { 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; continue;
switch(dep.importance) { switch(dep.importance) {
case ModMetadata::Dependency::Importance::Suggested: case ModMetadata::Dependency::Importance::Suggested:
@ -493,7 +491,7 @@ void Loader::Impl::findProblems() {
Mod* myEpicMod = mod; // clang fix Mod* myEpicMod = mod; // clang fix
// if the mod is not loaded but there are no problems related to it // 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) && Mod::get()->getSavedValue<bool>("should-load-" + mod->getID(), true) &&
!std::any_of(m_problems.begin(), m_problems.end(), [myEpicMod](auto& item) { !std::any_of(m_problems.begin(), m_problems.end(), [myEpicMod](auto& item) {
return std::holds_alternative<ModMetadata>(item.cause) && return std::holds_alternative<ModMetadata>(item.cause) &&

View file

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

View file

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

View file

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

View file

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

View file

@ -18,7 +18,7 @@ ModMetadata::Impl& ModMetadataImpl::getImpl(ModMetadata& info) {
bool ModMetadata::Dependency::isResolved() const { bool ModMetadata::Dependency::isResolved() const {
return this->importance != Importance::Required || 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 { bool ModMetadata::Incompatibility::isResolved() const {

View file

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

View file

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

View file

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