Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 27, 2024
1 parent 455a75e commit 1dda2e0
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 24 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/Callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ FakeNodeLayer<T> Callbacks::createUBDummyLayer() {

void Callbacks::generateAll() {
if (m_generated) return;
m_ignoreUICheck = true;
generateMenuLayerCallbacks();
generateCreatorLayerCallbacks();
generateGarageCallbacks();
m_ignoreUICheck = false;
m_generated = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Callbacks {
static Callbacks* instance;
bool m_generated = false;
public:

bool m_ignoreUICheck = false;
std::map<std::string, std::map<std::string, std::pair<CCNode*, cocos2d::SEL_MenuHandler>>> m_callbacks;
std::map<std::string, Ref<CCNode>> m_layers;
Ref<CCMenuItemSpriteExtra> m_dummyButton;
Expand Down
3 changes: 2 additions & 1 deletion src/NodeModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "UIModding.h"
#include "Utils.h"
#include "Macros.h"
#include "Callbacks.h"

using namespace geode::prelude;

Expand All @@ -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<CCNode*>(this)) {
Expand Down
44 changes: 44 additions & 0 deletions src/TextureLoader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <Geode/loader/Dispatch.hpp>

#include <filesystem>
#include <vector>
#include <string>

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<std::string> 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<std::vector<Pack>*>;
using EventGetAppliedPacks = geode::DispatchEvent<std::vector<Pack>*>;
}

inline std::vector<Pack> getAvailablePacks() {
std::vector<Pack> result;
impl::EventGetAvailablePacks("geode.texture-loader/v1/get-available-packs", &result).post();
return result;
}

inline std::vector<Pack> getAppliedPacks() {
std::vector<Pack> result;
impl::EventGetAppliedPacks("geode.texture-loader/v1/get-applied-packs", &result).post();
return result;
}

}
14 changes: 11 additions & 3 deletions src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void UIModding::recursiveModify(CCNode* node, matjson::Value elements) {
}

for (CCNode* node : CCArrayExt<CCNode*>(children)) {

std::string id = node->getID();

if (elements.contains("_pack-name") && elements["_pack-name"].isString()) {
Expand Down Expand Up @@ -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();
}
}
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 36 additions & 10 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "UIModding.h"
#include <random>
#include "Macros.h"
#include "TextureLoader.hpp"

using namespace geode::prelude;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -183,36 +184,61 @@ namespace Utils {

Mod* textureLoader = Loader::get()->getLoadedMod("geode.texture-loader");
if (textureLoader) {
for (matjson::Value value : textureLoader->getSavedValue<std::vector<matjson::Value>>("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<std::vector<matjson::Value>>("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 + "/");
}
}
}

return UIModding::get()->activePackCache;
}

static std::string qualityToNormal(std::string str) {
std::vector<std::string> 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) {
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/CCScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Geode/modify/CCScene.hpp>
#include "../UIModding.h"
#include "../Macros.h"
#include "../Callbacks.h"

using namespace geode::prelude;

Expand Down Expand Up @@ -32,7 +33,7 @@ class $modify(MyCCScene, CCScene) {

for (CCNode* node : CCArrayExt<CCNode*>(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);
}
Expand Down
18 changes: 11 additions & 7 deletions src/nodes/LoadingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
2 changes: 2 additions & 0 deletions src/nodes/MenuLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("ui-modifications");
Expand Down

0 comments on commit 1dda2e0

Please sign in to comment.