|
1 | 1 |
|
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); \ |
4 | 5 | }); |
5 | 6 |
|
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)); \ |
18 | 19 | }(value) |
19 | 20 |
|
20 | | -#define typeForEaseCC(easingTypeName) \ |
21 | | -if (name == #easingTypeName) {\ |
| 21 | +#define typeForEaseCC(easingTypeName) \ |
| 22 | +if (name == #easingTypeName) { \ |
22 | 23 | easingType = CC##easingTypeName::create(action, rate);\ |
23 | 24 | } |
24 | 25 |
|
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); \ |
28 | 29 | } |
29 | 30 |
|
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); \ |
33 | 34 | } |
34 | 35 |
|
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 | +} |
39 | 40 |
|
| 41 | +#define actionCase(name, ...) \ |
| 42 | +else if (type == #name) { \ |
| 43 | + actionToDo = CC##name::create(__VA_ARGS__); \ |
| 44 | +} |
40 | 45 |
|
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 | + } \ |
47 | 52 | } |
48 | 53 |
|
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 | + } \ |
55 | 60 | } |
56 | 61 |
|
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 | + } \ |
64 | 69 | } |
65 | 70 |
|
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 | + } \ |
113 | 117 | }; |
114 | 118 |
|
115 | | -#define SAFE_RUN(method) retain(); method release(); |
116 | | - |
117 | 119 | #define LABEL(name, value) {name, rift::Value::from(value)} |
118 | 120 |
|
119 | 121 | #define STAT(key) Utils::getValidStat(#key) |
120 | 122 |
|
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; \ |
127 | 127 | m_callbacks[#clazz] = callbacks |
128 | 128 |
|
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