From 1dda2e0d0b012bc836bf4c22f75281db45374cb8 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:12:03 -0500 Subject: [PATCH] Bug fixes --- changelog.md | 6 ++++++ mod.json | 2 +- src/Callbacks.cpp | 2 ++ src/Callbacks.h | 2 +- src/NodeModding.cpp | 3 ++- src/TextureLoader.hpp | 44 ++++++++++++++++++++++++++++++++++++++ src/UIModding.cpp | 14 +++++++++--- src/Utils.h | 46 +++++++++++++++++++++++++++++++--------- src/nodes/CCScene.h | 3 ++- src/nodes/LoadingLayer.h | 18 ++++++++++------ src/nodes/MenuLayer.h | 2 ++ 11 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 src/TextureLoader.hpp diff --git a/changelog.md b/changelog.md index 35eb900..55db7d8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## 1.8.2 +- Fix some layouting issues +- Fix duplicated node modifications for certain layers +- Fix individual sprites not working if only some qualities are present +- Fix applied packs not updating (uses a new Texture Loader API, make sure Texture Loader is up to date if you experience this issue!) + ## 1.8.1 - Fix crash on non-windows - Change individual sprite changing logic diff --git a/mod.json b/mod.json index 1ba1901..ae58b0c 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "android": "2.2074", "mac": "2.2074" }, - "version": "v1.8.1", + "version": "v1.8.2", "id": "alphalaneous.happy_textures", "name": "Happy Textures :3", "developer": "Alphalaneous", diff --git a/src/Callbacks.cpp b/src/Callbacks.cpp index cc4f3ab..8cd9205 100644 --- a/src/Callbacks.cpp +++ b/src/Callbacks.cpp @@ -12,9 +12,11 @@ FakeNodeLayer Callbacks::createUBDummyLayer() { void Callbacks::generateAll() { if (m_generated) return; + m_ignoreUICheck = true; generateMenuLayerCallbacks(); generateCreatorLayerCallbacks(); generateGarageCallbacks(); + m_ignoreUICheck = false; m_generated = true; } diff --git a/src/Callbacks.h b/src/Callbacks.h index 0a8f2d3..20a13c8 100644 --- a/src/Callbacks.h +++ b/src/Callbacks.h @@ -22,7 +22,7 @@ class Callbacks { static Callbacks* instance; bool m_generated = false; public: - + bool m_ignoreUICheck = false; std::map>> m_callbacks; std::map> m_layers; Ref m_dummyButton; diff --git a/src/NodeModding.cpp b/src/NodeModding.cpp index f3ccb10..6a38d0a 100644 --- a/src/NodeModding.cpp +++ b/src/NodeModding.cpp @@ -3,6 +3,7 @@ #include "UIModding.h" #include "Utils.h" #include "Macros.h" +#include "Callbacks.h" using namespace geode::prelude; @@ -13,7 +14,7 @@ class $modify(MyCCObject, CCObject) { } CCObject* autorelease() { - if (!UIModding::get()->finishedLoad || !UIModding::get()->doModify) + if (!UIModding::get()->finishedLoad || !UIModding::get()->doModify || Callbacks::get()->m_ignoreUICheck) return CCObject::autorelease(); if (CCNode* node = typeinfo_cast(this)) { diff --git a/src/TextureLoader.hpp b/src/TextureLoader.hpp new file mode 100644 index 0000000..f7f1623 --- /dev/null +++ b/src/TextureLoader.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include +#include +#include + +namespace geode::texture_loader { + +inline bool isLoaded() { + return geode::Loader::get()->isModLoaded("geode.texture-loader"); +} + +struct Pack { + std::string id; + std::string name; + VersionInfo version; + std::vector authors; + + /// Path from where the pack originates from. May be a file (apk, zip) or a folder + std::filesystem::path path; + /// Path where the resources are located. This is what is added to the search path + std::filesystem::path resourcesPath; +}; + +namespace impl { + using EventGetAvailablePacks = geode::DispatchEvent*>; + using EventGetAppliedPacks = geode::DispatchEvent*>; +} + +inline std::vector getAvailablePacks() { + std::vector result; + impl::EventGetAvailablePacks("geode.texture-loader/v1/get-available-packs", &result).post(); + return result; +} + +inline std::vector getAppliedPacks() { + std::vector result; + impl::EventGetAppliedPacks("geode.texture-loader/v1/get-applied-packs", &result).post(); + return result; +} + +} \ No newline at end of file diff --git a/src/UIModding.cpp b/src/UIModding.cpp index 5fe9381..61e2892 100644 --- a/src/UIModding.cpp +++ b/src/UIModding.cpp @@ -97,7 +97,7 @@ void UIModding::recursiveModify(CCNode* node, matjson::Value elements) { } for (CCNode* node : CCArrayExt(children)) { - + std::string id = node->getID(); if (elements.contains("_pack-name") && elements["_pack-name"].isString()) { @@ -1121,6 +1121,15 @@ void UIModding::updateLayout(CCNode* node, matjson::Value attributes) { if (CCNode* parent = node->getParent()) parent->updateLayout(); } } + if (update.isString()) { + std::string updateStr = update.asString().unwrapOr("self"); + if (updateStr == "self") { + node->updateLayout(); + } + else if (updateStr == "parent") { + if (CCNode* parent = node->getParent()) parent->updateLayout(); + } + } } } @@ -1250,7 +1259,6 @@ void UIModding::handleModifications(CCNode* node, matjson::Value nodeObject) { nodeAttributes["_pack-name"] = nodeObject["_pack-name"]; nodesFor(setDisablePages); - nodesFor(setLayout); nodesFor(setScale); nodesFor(setRotation); nodesFor(setSkew); @@ -1272,6 +1280,7 @@ void UIModding::handleModifications(CCNode* node, matjson::Value nodeObject) { nodesFor(setBlending); nodesFor(setShow); nodesFor(removeChild); + nodesFor(setLayout); nodesFor(updateLayout); nodesFor(runScrollToTop); nodesFor(setLocked); @@ -1521,7 +1530,6 @@ void UIModding::doUICheck(CCNode* node) { std::string nodeID = node->getID(); std::replace(nodeID.begin(), nodeID.end(), '/', '$'); std::string path = "ui/" + nodeID + ".json"; - unsigned long fileSize = 0; unsigned char* buffer = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "rb", &fileSize); diff --git a/src/Utils.h b/src/Utils.h index 719ea6a..8d5709b 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -4,6 +4,7 @@ #include "UIModding.h" #include #include "Macros.h" +#include "TextureLoader.hpp" using namespace geode::prelude; @@ -143,7 +144,7 @@ namespace Utils { } static std::string getHookPrioLatest(const std::string& name) { - int minPriority = INT_MAX - 1; + int minPriority = 0; const Mod* currentMod = Mod::get(); std::string latestModID = currentMod->getID(); @@ -183,14 +184,22 @@ namespace Utils { Mod* textureLoader = Loader::get()->getLoadedMod("geode.texture-loader"); if (textureLoader) { - for (matjson::Value value : textureLoader->getSavedValue>("applied")) { - if (value.isObject() && value.contains("path") && value["path"].isString()) { - std::string path = value["path"].asString().unwrapOr(""); - if (utils::string::endsWith(path, ".zip")) { - std::filesystem::path pathFs{path}; - path = (textureLoader->getSaveDir() / "unzipped" / pathFs.filename()).string(); + if (textureLoader->getVersion() >= VersionInfo{1, 7, 0}) { + for(geode::texture_loader::Pack pack : geode::texture_loader::getAppliedPacks()) { + UIModding::get()->activePackCache.push_back(pack.resourcesPath.string() + "/"); + } + } + else { + log::info("Using old pack method. Update Texture Loader!"); + for (matjson::Value value : textureLoader->getSavedValue>("applied")) { + if (value.isObject() && value.contains("path") && value["path"].isString()) { + std::string path = value["path"].asString().unwrapOr(""); + if (utils::string::endsWith(path, ".zip")) { + std::filesystem::path pathFs{path}; + path = (textureLoader->getSaveDir() / "unzipped" / pathFs.filename()).string(); + } + UIModding::get()->activePackCache.push_back(path + "/"); } - UIModding::get()->activePackCache.push_back(path + "/"); } } } @@ -198,21 +207,38 @@ namespace Utils { return UIModding::get()->activePackCache; } + static std::string qualityToNormal(std::string str) { + std::vector fileParts = utils::string::split(str, "."); + + std::string suffix = fileParts[fileParts.size()-1]; + std::string prefix = str.substr(0, str.size() - suffix.size() - 1); + + if (utils::string::endsWith(prefix, "-uhd")) { + prefix = prefix.substr(0, prefix.size() - 4); + } + else if (utils::string::endsWith(prefix, "-hd")) { + prefix = prefix.substr(0, prefix.size() - 3); + } + + return fmt::format("{}.{}", prefix, suffix); + } + static void reloadFileNames() { UIModding::get()->filenameCache.clear(); for (std::string packPath : Utils::getActivePacks()) { + for (const auto& entry : std::filesystem::recursive_directory_iterator(packPath)) { if (entry.is_regular_file()) { std::string pathStr = entry.path().string(); std::string subStr = pathStr.substr(packPath.size()); - UIModding::get()->filenameCache[utils::string::replace(subStr, "\\", "/")] = true; + UIModding::get()->filenameCache[qualityToNormal(utils::string::replace(subStr, "\\", "/"))] = true; } } } } static bool spriteExistsInPacks(std::string fileName) { - return UIModding::get()->filenameCache[fileName]; + return UIModding::get()->filenameCache[qualityToNormal(fileName)]; } static CCNode* getChildByTypeName(CCNode* node, int index, std::string name) { diff --git a/src/nodes/CCScene.h b/src/nodes/CCScene.h index c576c49..6f6b383 100644 --- a/src/nodes/CCScene.h +++ b/src/nodes/CCScene.h @@ -4,6 +4,7 @@ #include #include "../UIModding.h" #include "../Macros.h" +#include "../Callbacks.h" using namespace geode::prelude; @@ -32,7 +33,7 @@ class $modify(MyCCScene, CCScene) { for (CCNode* node : CCArrayExt(this->getChildren())) { idx++; - if (node->getID() == "MenuLayer") continue; + if (node->getID() == "MenuLayer" || Callbacks::get()->m_ignoreUICheck) continue; if (idx > m_fields->m_currentCount) { UIModding::get()->doUICheck(node); } diff --git a/src/nodes/LoadingLayer.h b/src/nodes/LoadingLayer.h index d54ff6d..ed53f3e 100644 --- a/src/nodes/LoadingLayer.h +++ b/src/nodes/LoadingLayer.h @@ -9,20 +9,24 @@ using namespace geode::prelude; class $modify(MyLoadingLayer, LoadingLayer) { - bool init(bool p0) { + void loadAssets() { + + if (m_loadStep > 0) { + LoadingLayer::loadAssets(); + return; + } + UIModding::get()->finishedLoad = false; UIModding::get()->uiCache.clear(); UIModding::get()->colorCache.clear(); - Utils::clearActivePackCache(); - - if (!LoadingLayer::init(p0)) return false; - + queueInMainThread([] { + Utils::clearActivePackCache(); Utils::reloadFileNames(); UIModding::get()->loadNodeFiles(); Config::get()->loadPackJsons(); }); - - return true; + + LoadingLayer::loadAssets(); } }; \ No newline at end of file diff --git a/src/nodes/MenuLayer.h b/src/nodes/MenuLayer.h index c3326e1..6632f6d 100644 --- a/src/nodes/MenuLayer.h +++ b/src/nodes/MenuLayer.h @@ -44,6 +44,8 @@ class $modify(MyMenuLayer, MenuLayer) { } bool init() { + if (Callbacks::get()->m_ignoreUICheck) return MenuLayer::init(); + UIModding::get()->finishedLoad = true; if (!MenuLayer::init()) return false; UIModding::get()->doModify = Mod::get()->getSettingValue("ui-modifications");