diff --git a/loader/src/cocos2d-ext/CCFileUtils.cpp b/loader/src/cocos2d-ext/CCFileUtils.cpp index 29ead161..b28ffd78 100644 --- a/loader/src/cocos2d-ext/CCFileUtils.cpp +++ b/loader/src/cocos2d-ext/CCFileUtils.cpp @@ -8,7 +8,6 @@ using namespace geode::prelude; static std::vector<CCTexturePack> REMOVED_PACKS; static std::vector<CCTexturePack> PACKS; static std::vector<std::string> PATHS; -static bool DONT_ADD_PATHS = false; #pragma warning(push) #pragma warning(disable : 4273) @@ -31,13 +30,13 @@ void CCFileUtils::addTexturePack(CCTexturePack const& pack) { void CCFileUtils::removeTexturePack(std::string const& id) { std::optional<CCTexturePack> pack = getTexturePack(id); - if(pack.has_value()) { + if (pack.has_value()) { REMOVED_PACKS.push_back(pack.value()); + ranges::remove(PACKS, [id](CCTexturePack const& pack) { + return pack.m_id == id; + }); + this->updatePaths(); } - ranges::remove(PACKS, [id](CCTexturePack const& pack) { - return pack.m_id == id; - }); - this->updatePaths(); } void CCFileUtils::addPriorityPath(char const* path) { @@ -45,31 +44,38 @@ void CCFileUtils::addPriorityPath(char const* path) { this->updatePaths(); } +// cocos adds a trailing / to paths, so we need to check for that +bool isPathEqual(std::filesystem::path const& cocosPath, std::filesystem::path const& ourPath) { + return cocosPath == ourPath || (cocosPath == (ourPath / "")); +} + void CCFileUtils::updatePaths() { // add search paths that aren't in PATHS or PACKS to PATHS for (auto& path : m_searchPathArray) { + std::filesystem::path const cocosPath = path; bool isKnown = false; for (auto& pack : PACKS) { for (auto& packPath : pack.m_paths) { - if (std::filesystem::path(path.c_str()) == packPath) { + if (isPathEqual(cocosPath, packPath)) { isKnown = true; break; } } if (isKnown) break; } + if (isKnown) continue; for (auto& pack : REMOVED_PACKS) { for (auto& packPath : pack.m_paths) { - if (std::filesystem::path(path.c_str()) == packPath) { + if (isPathEqual(cocosPath, packPath)) { isKnown = true; break; } } if (isKnown) break; } - if (isKnown) break; + if (isKnown) continue; for (auto& p : PATHS) { - if (std::filesystem::path(path.c_str()) == p) { + if (isPathEqual(cocosPath, p)) { isKnown = true; break; } @@ -83,9 +89,6 @@ void CCFileUtils::updatePaths() { REMOVED_PACKS.clear(); m_searchPathArray.clear(); - // make sure addSearchPath doesn't add to PACKS or PATHS - DONT_ADD_PATHS = true; - // add texture packs first for (auto& pack : PACKS) { for (auto& path : pack.m_paths) { @@ -96,7 +99,6 @@ void CCFileUtils::updatePaths() { for (auto& path : PATHS) { this->addSearchPath(path.c_str()); } - DONT_ADD_PATHS = false; } #pragma warning(pop) diff --git a/loader/src/loader/LoaderImpl.cpp b/loader/src/loader/LoaderImpl.cpp index 0217b182..994cfe89 100644 --- a/loader/src/loader/LoaderImpl.cpp +++ b/loader/src/loader/LoaderImpl.cpp @@ -215,11 +215,7 @@ Mod* Loader::Impl::getLoadedMod(std::string const& id) const { } void Loader::Impl::updateModResources(Mod* mod) { - if (mod != Mod::get()) { - // geode.loader resource is stored somewhere else, which is already added anyway - auto searchPathRoot = dirs::getModRuntimeDir() / mod->getID() / "resources"; - CCFileUtils::get()->addSearchPath(searchPathRoot.string().c_str()); - } + // search path is added in Mod::Impl::setup // only thing needs previous setup is spritesheets if (mod->getMetadata().getSpritesheets().empty()) diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index 00277e02..cffd842b 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -58,7 +58,7 @@ Result<> Mod::Impl::setup() { if (!loadRes) { log::warn("Unable to load data for \"{}\": {}", m_metadata.getID(), loadRes.unwrapErr()); } - if (!m_resourcesLoaded) { + if (!m_resourcesLoaded && !this->isInternal()) { auto searchPathRoot = dirs::getModRuntimeDir() / m_metadata.getID() / "resources"; // Hi, linux bros!