Skip to content

Commit 59f2801

Browse files
committed
Bug fixes and cleanup
1 parent 5977b3c commit 59f2801

File tree

11 files changed

+197
-212
lines changed

11 files changed

+197
-212
lines changed

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"geode": "4.4.0",
2+
"geode": "4.5.0",
33
"gd": {
44
"win": "2.2074",
55
"android": "2.2074",
66
"mac": "2.2074",
77
"ios": "2.2074"
88
},
9-
"version": "v1.9.8",
9+
"version": "v1.9.10",
1010
"id": "alphalaneous.happy_textures",
1111
"name": "Happy Textures :3",
1212
"developer": "Alphalaneous",

src/Callbacks.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
#include "Callbacks.h"
22
#include "Macros.h"
3+
#include "UIModding.h"
34

45
Callbacks* Callbacks::instance = nullptr;
56

6-
//do cursed UB stuff, currently unused but may be useful in the future
7-
8-
template <typename T>
9-
FakeNodeLayer<T> Callbacks::createUBDummyLayer() {
10-
return FakeNodeLayer<T>();
11-
}
12-
137
void Callbacks::generateAll() {
148
if (m_generated) return;
15-
m_ignoreUICheck = true;
9+
UIModding::get()->skipCheck = true;
1610
generateMenuLayerCallbacks();
1711
generateCreatorLayerCallbacks();
1812
generateGarageCallbacks();
19-
m_ignoreUICheck = false;
13+
UIModding::get()->skipCheck = false;
2014
m_generated = true;
2115
}
2216

src/Callbacks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Callbacks {
2222
static Callbacks* instance;
2323
bool m_generated = false;
2424
public:
25-
bool m_ignoreUICheck = false;
2625
std::map<std::string, std::map<std::string, std::pair<CCNode*, cocos2d::SEL_MenuHandler>>> m_callbacks;
2726
std::map<std::string, Ref<CCNode>> m_layers;
2827
Ref<CCMenuItemSpriteExtra> m_dummyButton;

src/Macros.h

Lines changed: 103 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,131 @@
11

2-
#define HOOK_LATEST(method) queueInMainThread([&self] {\
3-
(void) self.setHookPriority(method, INT_MIN + 1);\
2+
#define HOOK_LATEST(method) \
3+
queueInMainThread([&self] { \
4+
(void) self.setHookPriority(method, INT_MIN + 1); \
45
});
56

6-
#define public_cast(value, member) [](auto* v) { \
7-
class FriendClass__; \
8-
using T = std::remove_pointer<decltype(v)>::type; \
9-
class FriendeeClass__: public T { \
10-
protected: \
11-
friend FriendClass__; \
12-
}; \
13-
class FriendClass__ { \
14-
public: \
15-
auto& get(FriendeeClass__* v) { return v->member; } \
16-
} c; \
17-
return c.get(reinterpret_cast<FriendeeClass__*>(v)); \
7+
#define public_cast(value, member) [](auto* v) { \
8+
class FriendClass__; \
9+
using T = std::remove_pointer<decltype(v)>::type; \
10+
class FriendeeClass__: public T { \
11+
protected: \
12+
friend FriendClass__; \
13+
}; \
14+
class FriendClass__ { \
15+
public: \
16+
auto& get(FriendeeClass__* v) { return v->member; } \
17+
} c; \
18+
return c.get(reinterpret_cast<FriendeeClass__*>(v)); \
1819
}(value)
1920

20-
#define typeForEaseCC(easingTypeName) \
21-
if (name == #easingTypeName) {\
21+
#define typeForEaseCC(easingTypeName) \
22+
if (name == #easingTypeName) { \
2223
easingType = CC##easingTypeName::create(action, rate);\
2324
}
2425

25-
#define typeForEaseRate(easingTypeName) \
26-
if (name == #easingTypeName) {\
27-
easingType = CCEase##easingTypeName::create(action, rate);\
26+
#define typeForEaseRate(easingTypeName) \
27+
if (name == #easingTypeName) { \
28+
easingType = CCEase##easingTypeName::create(action, rate); \
2829
}
2930

30-
#define typeForEase(easingTypeName) \
31-
if (name == #easingTypeName) {\
32-
easingType = CCEase##easingTypeName::create(action);\
31+
#define typeForEase(easingTypeName) \
32+
if (name == #easingTypeName) { \
33+
easingType = CCEase##easingTypeName::create(action); \
3334
}
3435

35-
#define nodesFor(methodName) if(node) UIModding::get()->methodName(node, attributes)
36-
37-
#define actionCase(name, ...) \
38-
else if (type == #name) { actionToDo = CC##name::create(__VA_ARGS__); }
36+
#define nodesFor(methodName) \
37+
if (node) { \
38+
UIModding::get()->methodName(node, attributes); \
39+
}
3940

41+
#define actionCase(name, ...) \
42+
else if (type == #name) { \
43+
actionToDo = CC##name::create(__VA_ARGS__); \
44+
}
4045

41-
#define setSpriteVar(varName, jsonName, type, unwrap)\
42-
if (infoVal.contains(#jsonName)) {\
43-
matjson::Value val = infoVal[#jsonName];\
44-
if (val.is##type()) {\
45-
varName = val.as##type().unwrapOr(unwrap);\
46-
}\
46+
#define setSpriteVar(varName, jsonName, type, unwrap) \
47+
if (infoVal.contains(#jsonName)) { \
48+
matjson::Value val = infoVal[#jsonName]; \
49+
if (val.is##type()) { \
50+
varName = val.as##type().unwrapOr(unwrap); \
51+
} \
4752
}
4853

49-
#define setSpriteVarNum(varName, jsonName, type, unwrap)\
50-
if (infoVal.contains(#jsonName)) {\
51-
matjson::Value val = infoVal[#jsonName];\
52-
if (val.isNumber()) {\
53-
varName = val.as##type().unwrapOr(unwrap);\
54-
}\
54+
#define setSpriteVarNum(varName, jsonName, type, unwrap) \
55+
if (infoVal.contains(#jsonName)) { \
56+
matjson::Value val = infoVal[#jsonName]; \
57+
if (val.isNumber()) { \
58+
varName = val.as##type().unwrapOr(unwrap); \
59+
} \
5560
}
5661

57-
#define forEvent(type, method)\
58-
if (eventVal.contains(#type)) {\
59-
matjson::Value eventType = eventVal[#type];\
60-
if (eventType.isObject()) {\
61-
eventType["_pack-name"] = eventVal["_pack-name"];\
62-
button->set##method(eventType);\
63-
}\
62+
#define forEvent(type, method) \
63+
if (eventVal.contains(#type)) { \
64+
matjson::Value eventType = eventVal[#type]; \
65+
if (eventType.isObject()) { \
66+
eventType["_pack-name"] = eventVal["_pack-name"]; \
67+
button->set##method(eventType); \
68+
} \
6469
}
6570

66-
#define setCellColors(class, method, paramType) \
67-
struct My##class : geode::Modify<My##class, class> { \
68-
static void onModify(auto& self) {\
69-
HOOK_LATEST(#class "::" #method);\
70-
}\
71-
struct Fields {\
72-
ccColor3B m_lastBG;\
73-
};\
74-
void method(paramType* p0){\
75-
class::method(p0);\
76-
if (UIModding::get()->doModify) {\
77-
checkBG(0);\
78-
this->schedule(schedule_selector(My##class::checkBG));\
79-
}\
80-
}\
81-
void checkBG(float dt) {\
82-
CCLayerColor* child = this->getChildByType<CCLayerColor>(0);\
83-
if (child) {\
84-
if (m_fields->m_lastBG != child->getColor()) {\
85-
m_fields->m_lastBG = child->getColor();\
86-
if (child->getColor() == ccColor3B{161,88,44}) {\
87-
std::optional<ColorData> dataOpt = UIModding::get()->getColors("list-cell-odd");\
88-
if (dataOpt.has_value()) {\
89-
ColorData data = dataOpt.value();\
90-
child->setColor(data.color);\
91-
child->setOpacity(data.alpha);\
92-
}\
93-
}\
94-
else if (child->getColor() == ccColor3B{194,114,62}) {\
95-
std::optional<ColorData> dataOpt = UIModding::get()->getColors("list-cell-even");\
96-
if (dataOpt.has_value()) {\
97-
ColorData data = dataOpt.value();\
98-
child->setColor(data.color);\
99-
child->setOpacity(data.alpha);\
100-
}\
101-
}\
102-
else if (child->getColor() == ccColor3B{230,150,10}) {\
103-
std::optional<ColorData> dataOpt = UIModding::get()->getColors("list-cell-selected");\
104-
if (dataOpt.has_value()) {\
105-
ColorData data = dataOpt.value();\
106-
child->setColor(data.color);\
107-
child->setOpacity(data.alpha);\
108-
}\
109-
}\
110-
}\
111-
}\
112-
}\
71+
#define setCellColors(class, method, paramType) \
72+
struct My##class : geode::Modify<My##class, class> { \
73+
static void onModify(auto& self) { \
74+
HOOK_LATEST(#class "::" #method); \
75+
} \
76+
struct Fields { \
77+
ccColor3B m_lastBG; \
78+
}; \
79+
void method(paramType* p0) { \
80+
class::method(p0); \
81+
if (UIModding::get()->doModify) { \
82+
checkBG(0); \
83+
this->schedule(schedule_selector(My##class::checkBG)); \
84+
} \
85+
} \
86+
void checkBG(float dt) { \
87+
auto* child = this->getChildByType<CCLayerColor>(0); \
88+
if (!child) return; \
89+
\
90+
auto color = child->getColor(); \
91+
auto fields = m_fields.self(); \
92+
if (fields->m_lastBG == color) return; \
93+
fields->m_lastBG = color; \
94+
\
95+
struct ColorMap { \
96+
ccColor3B match; \
97+
const char* ID; \
98+
}; \
99+
\
100+
constexpr ColorMap mappings[] = { \
101+
{{161, 88, 44}, "list-cell-odd"}, \
102+
{{194, 114, 62}, "list-cell-even"}, \
103+
{{230, 150, 10}, "list-cell-selected"}, \
104+
}; \
105+
\
106+
for (const auto& entry : mappings) { \
107+
if (color == entry.match) { \
108+
if (auto dataOpt = UIModding::get()->getColors(entry.ID)) { \
109+
const auto& data = *dataOpt; \
110+
child->setColor(data.color); \
111+
child->setOpacity(data.alpha); \
112+
} \
113+
break; \
114+
} \
115+
} \
116+
} \
113117
};
114118

115-
#define SAFE_RUN(method) retain(); method release();
116-
117119
#define LABEL(name, value) {name, rift::Value::from(value)}
118120

119121
#define STAT(key) Utils::getValidStat(#key)
120122

121-
#define CREATE_DUMMY(clazz) m_layers[#clazz] = createUBDummyLayer<clazz>().get(); CCNode* self = m_layers[#clazz]; \
122-
std::map<std::string, std::pair<CCNode*, cocos2d::SEL_MenuHandler>> callbacks; \
123-
m_callbacks[#clazz] = callbacks
124-
125-
#define CREATE_NORMAL(clazz) m_layers[#clazz] = clazz::create(); CCNode* self = m_layers[#clazz]; \
126-
std::map<std::string, std::pair<CCNode*, cocos2d::SEL_MenuHandler>> callbacks; \
123+
#define CREATE_NORMAL(clazz) \
124+
m_layers[#clazz] = clazz::create(); \
125+
CCNode* self = m_layers[#clazz]; \
126+
std::map<std::string, std::pair<CCNode*, cocos2d::SEL_MenuHandler>> callbacks; \
127127
m_callbacks[#clazz] = callbacks
128128

129-
#define REGISTER_CALLBACK(clazz, method) m_callbacks[#clazz][#method] = std::pair<CCNode*, cocos2d::SEL_MenuHandler>(self, menu_selector(clazz::method))
129+
#define REGISTER_CALLBACK(clazz, method) \
130+
m_callbacks[#clazz][#method] = std::pair<CCNode*, cocos2d::SEL_MenuHandler> \
131+
(self, menu_selector(clazz::method))

0 commit comments

Comments
 (0)