From 94ed9518573423cead780c72caec0d045e8949d7 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:25:14 -0500 Subject: [PATCH] more fixes --- changelog.md | 2 +- src/UIModding.h | 3 +-- src/Utils.h | 10 ++++++---- src/nodes/CCSprite.h | 10 ++++------ src/nodes/LoadingLayer.h | 3 +-- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index b1f27e2..f11487a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ ## 1.8.5 - Cleanup filesystem code - Fix a crash when there is an invalid path (hopefully) -- Fix an issue with CCSpriteWithHue. Do note that changing the wraith textures is still broken and has inconsistent behavior +- Fix an issue with CCSpriteWithHue ## 1.8.4 - Actually fix loading individual sprites from init diff --git a/src/UIModding.h b/src/UIModding.h index 5a58045..7c2b4d5 100644 --- a/src/UIModding.h +++ b/src/UIModding.h @@ -21,8 +21,7 @@ class UIModding { std::map randomSprites; std::vector activePackCache; std::unordered_map filenameCache; - std::unordered_map spritesChanged; - std::unordered_map frameToNameMap; + std::unordered_map textureToNameMap; std::vector listeners; Ref removalQueue = CCArray::create(); diff --git a/src/Utils.h b/src/Utils.h index fcd2156..9432a23 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -142,10 +142,13 @@ namespace Utils { } static std::string getSpriteName(CCSpriteFrame* spriteFrame) { - if (UIModding::get()->frameToNameMap.contains(spriteFrame)) return UIModding::get()->frameToNameMap[spriteFrame]; + if (UIModding::get()->textureToNameMap.contains(spriteFrame->getTexture())) { + return UIModding::get()->textureToNameMap[spriteFrame->getTexture()]; + } + for (auto [key, frame] : CCDictionaryExt(CCSpriteFrameCache::sharedSpriteFrameCache()->m_pSpriteFrames)) { - if (spriteFrame == frame) { - UIModding::get()->frameToNameMap[spriteFrame] = key; + if (spriteFrame->getTexture() == frame->getTexture() && frame->getRect() == spriteFrame->getRect()) { + UIModding::get()->textureToNameMap[spriteFrame->getTexture()] = key; return key; } } @@ -241,7 +244,6 @@ namespace Utils { if (entry.is_regular_file()) { std::string pathStr = entry.path().string(); std::string subStr = pathStr.substr(packPath.string().size() + 1); - log::info("subStr: {}", subStr); UIModding::get()->filenameCache[qualityToNormal(utils::string::replace(subStr, "\\", "/"))] = true; } } diff --git a/src/nodes/CCSprite.h b/src/nodes/CCSprite.h index 1138b20..b8c8ee8 100644 --- a/src/nodes/CCSprite.h +++ b/src/nodes/CCSprite.h @@ -14,11 +14,11 @@ class $modify(MyCCSpriteWithHue, CCSpriteWithHue) { bool initWithSpriteFrame(cocos2d::CCSpriteFrame* p0) { std::string frameName = Utils::getSpriteName(p0); - if (Utils::spriteExistsInPacks(frameName) && !UIModding::get()->spritesChanged[frameName]) { + if (Utils::spriteExistsInPacks(frameName)) { CCSprite* spr = CCSprite::create(frameName.c_str()); auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str()); - UIModding::get()->spritesChanged[frameName] = true; + return CCSpriteWithHue::initWithSpriteFrame(spriteFrame); } return CCSpriteWithHue::initWithSpriteFrame(p0); @@ -33,23 +33,21 @@ class $modify(MyCCSprite, CCSprite) { } bool initWithSpriteFrameName(const char *pszSpriteFrameName) { - if (Utils::spriteExistsInPacks(pszSpriteFrameName) && !UIModding::get()->spritesChanged[pszSpriteFrameName]) { + if (Utils::spriteExistsInPacks(pszSpriteFrameName)) { CCSprite* spr = CCSprite::create(pszSpriteFrameName); auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, pszSpriteFrameName); - UIModding::get()->spritesChanged[pszSpriteFrameName] = true; } return CCSprite::initWithSpriteFrameName(pszSpriteFrameName); } static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName) { - if (Utils::spriteExistsInPacks(pszSpriteFrameName) && !UIModding::get()->spritesChanged[pszSpriteFrameName]) { + if (Utils::spriteExistsInPacks(pszSpriteFrameName)) { CCSprite* spr = CCSprite::create(pszSpriteFrameName); auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, pszSpriteFrameName); - UIModding::get()->spritesChanged[pszSpriteFrameName] = true; } return CCSprite::createWithSpriteFrameName(pszSpriteFrameName); diff --git a/src/nodes/LoadingLayer.h b/src/nodes/LoadingLayer.h index ce44079..479eb69 100644 --- a/src/nodes/LoadingLayer.h +++ b/src/nodes/LoadingLayer.h @@ -19,8 +19,7 @@ class $modify(MyLoadingLayer, LoadingLayer) { UIModding::get()->finishedLoad = false; UIModding::get()->uiCache.clear(); UIModding::get()->colorCache.clear(); - UIModding::get()->spritesChanged.clear(); - UIModding::get()->frameToNameMap.clear(); + UIModding::get()->textureToNameMap.clear(); queueInMainThread([] { Utils::clearActivePackCache();