Skip to content

Commit 5e42a9f

Browse files
committed
Fix
1 parent 0b5adc1 commit 5e42a9f

File tree

3 files changed

+17
-66
lines changed

3 files changed

+17
-66
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.9.9
2+
- Fix sprite crash
3+
14
## 1.9.8
25
- Add basic support for SimpleAxisLayout
36
- Fix setDisplayFrame not using changed textures

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mac": "2.2074",
77
"ios": "2.2074"
88
},
9-
"version": "v1.9.8",
9+
"version": "v1.9.9",
1010
"id": "alphalaneous.happy_textures",
1111
"name": "Happy Textures :3",
1212
"developer": "Alphalaneous",

src/nodes/CCSprite.h

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,19 @@
11
#pragma once
22

33
#include <Geode/Geode.hpp>
4-
#include <Geode/modify/CCSprite.hpp>
5-
#include <Geode/modify/CCSpriteWithHue.hpp>
6-
#include "../Macros.h"
7-
8-
class $modify(MyCCSpriteWithHue, CCSpriteWithHue) {
9-
10-
static void onModify(auto& self) {
11-
(void) self.setHookPriority("cocos2d::CCSpriteWithHue::initWithSpriteFrame", Priority::VeryEarly);
12-
}
13-
14-
bool initWithSpriteFrame(cocos2d::CCSpriteFrame* p0) {
15-
std::string frameName = Utils::getSpriteName(p0);
16-
17-
if (Utils::spriteExistsInPacks(frameName)) {
18-
CCSprite* spr = CCSprite::create(frameName.c_str());
19-
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
20-
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str());
21-
return CCSpriteWithHue::initWithSpriteFrame(spriteFrame);
4+
#include <Geode/modify/CCSpriteFrameCache.hpp>
5+
6+
class $modify(MyCCSpriteFrameCache, CCSpriteFrameCache) {
7+
CCSpriteFrame* spriteFrameByName(const char *pszName) {
8+
9+
if (Utils::spriteExistsInPacks(pszName)) {
10+
CCTexture2D* pTexture = CCTextureCache::get()->addImage(pszName, false);
11+
if (pTexture){
12+
CCRect rect = CCRectZero;
13+
rect.size = pTexture->getContentSize();
14+
return CCSpriteFrame::createWithTexture(pTexture, rect);
15+
}
2216
}
23-
24-
return CCSpriteWithHue::initWithSpriteFrame(p0);
25-
}
26-
};
27-
28-
class $modify(MyCCSprite, CCSprite) {
29-
30-
static void onModify(auto& self) {
31-
(void) self.setHookPriority("cocos2d::CCSprite::initWithSpriteFrameName", Priority::VeryEarly);
32-
(void) self.setHookPriority("cocos2d::CCSprite::createWithSpriteFrameName", Priority::VeryEarly);
33-
(void) self.setHookPriority("cocos2d::CCSprite::setDisplayFrame", Priority::VeryEarly);
34-
}
35-
36-
void setDisplayFrame(CCSpriteFrame *pNewFrame) {
37-
std::string frameName = Utils::getSpriteName(pNewFrame);
38-
if (Utils::spriteExistsInPacks(frameName)) {
39-
CCSprite* spr = CCSprite::create(frameName.c_str());
40-
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
41-
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str());
42-
return CCSprite::setDisplayFrame(spriteFrame);
43-
}
44-
CCSprite::setDisplayFrame(pNewFrame);
45-
}
46-
47-
bool initWithSpriteFrameName(const char *pszSpriteFrameName) {
48-
std::string copy = pszSpriteFrameName;
49-
50-
if (Utils::spriteExistsInPacks(copy)) {
51-
CCSprite* spr = CCSprite::create(copy.c_str());
52-
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
53-
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, copy.c_str());
54-
}
55-
56-
return CCSprite::initWithSpriteFrameName(copy.c_str());
57-
}
58-
59-
static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName) {
60-
std::string copy = pszSpriteFrameName;
61-
62-
if (Utils::spriteExistsInPacks(copy)) {
63-
64-
CCSprite* spr = CCSprite::create(copy.c_str());
65-
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
66-
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, copy.c_str());
67-
}
68-
69-
return CCSprite::createWithSpriteFrameName(copy.c_str());
17+
return CCSpriteFrameCache::spriteFrameByName(pszName);
7018
}
7119
};

0 commit comments

Comments
 (0)