Skip to content

Commit 603a5d2

Browse files
committed
Merge branch 'master' of https://github.com/OmgRod/Geodify
2 parents 91162cf + 8412eb3 commit 603a5d2

File tree

29 files changed

+234
-406
lines changed

29 files changed

+234
-406
lines changed

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class $modify(MyCreatorLayer, CreatorLayer) {
6262
};
6363
```
6464

65+
6566
### External Mods
6667

6768
For external mods that modify the background of a specific menu, you can use the following example. This shows how to hook into `GlobedLevelListLayer` to add a custom background.
@@ -70,21 +71,42 @@ For external mods that modify the background of a specific menu, you can use the
7071
#include <Geode/Geode.hpp>
7172
#include "../../SwelvyBG.hpp"
7273
#include "../../Hooks/Hooker.hpp"
74+
using namespace geode::prelude;
7375

74-
class GlobedLevelListLayer : public Betterhook::HookBetter {
75-
void init(CCNode* _This) override {
76-
if (auto bg = _This->getChildByID("background")) {
76+
Viper_Hookclass(GlobedLevelListLayer) {
77+
if (auto bg = this->getChildByID("background")) {
7778
bg->setVisible(false);
7879
}
7980

8081
SwelvyBG* swelvyBG = SwelvyBG::create();
8182
swelvyBG->setZOrder(-1);
8283
swelvyBG->setID("swelvy-background");
83-
_This->addChild(swelvyBG);
84-
}
84+
this->addChild(swelvyBG);
85+
}
8586

86-
const char* PutLayer() const override { return "GlobedLevelListLayer"; }
87-
};
87+
```
88+
This way is new from v1.6.0+!
8889
89-
REGISTER_HookBetter(GlobedLevelListLayer);
90-
```
90+
### External Mods Fix
91+
92+
For external mods that really don't like you to modify the background of a specific menu, you can use the following example. This shows how to hook into `cvolton.betterinfo/CustomCreatorLayer` to add a custom background.
93+
94+
Please do not do this unless like in this example it's the only way since Viper_Hookclass won't work on it!
95+
96+
```cpp
97+
#include <Geode/Geode.hpp>
98+
#include "../../SwelvyBG.hpp"
99+
#include "../../Hooks/Hooker.hpp"
100+
using namespace geode::prelude;
101+
// class name to store in code, Hook to (the real layer id)
102+
Viper_Hookclass_Scene(cvolton_betterinfo_CustomCreatorLayer,"cvolton.betterinfo/CustomCreatorLayer") {
103+
if (auto bg = _This->getChildByID("cvolton.betterinfo/background")) {
104+
bg->setVisible(false);
105+
SwelvyBG* swelvyBG = SwelvyBG::create();
106+
swelvyBG->setZOrder(-1);
107+
swelvyBG->setID("swelvy-background");
108+
_This->addChild(swelvyBG);
109+
}
110+
}
111+
```
112+
This way is new from v1.6.0+!

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v1.6.0
22

33
- Added color offset option
4+
- remade the external mods hooks function `Fixing the PackSelectLayer apply bug`
45

56
# v1.5.2
67

mod.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.0.0",
2+
"geode": "4.1.0",
33
"gd": {
44
"android": "2.2074",
55
"win": "2.2074",
@@ -15,11 +15,18 @@
1515
"sprites": ["res/*.png"]
1616
},
1717
"settings": {
18+
"enable-color": {
19+
"name": "Enable Color Offset",
20+
"description": "Enables color offset for the SwelvyBG.",
21+
"type": "bool",
22+
"default": false
23+
},
1824
"color": {
1925
"name": "Color Offset",
2026
"description": "The color offset of the background.",
2127
"type": "color",
22-
"default": "#FF0000"
28+
"default": "#FF0000",
29+
"enable-if": "enable-color"
2330
},
2431
"show-main": {
2532
"name": "Show in main menu",

src/Hooks/External_Mods_Manager.cpp

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Hooks/Hooker.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Hooks/Hooker.hpp

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11

22
#pragma once
33
#include <Geode/Geode.hpp>
4+
#include <Geode/modify/CCLayer.hpp>
5+
#include <Geode/modify/CCDirector.hpp>
6+
using namespace geode::prelude;
47

5-
6-
#define REGISTER_HookBetter(Class) $execute { Betterhook::HookBetter::registerHook<Class>(); }
7-
namespace Betterhook {
8-
class HookBetter {
9-
public:
10-
static void registerHook(HookBetter* hook);
11-
template<typename T, typename = std::enable_if_t<std::is_base_of_v<HookBetter, T>>>
12-
static void registerHook() { registerHook(new T()); }
13-
static const std::vector<HookBetter*>& Hooks();
14-
virtual void init(cocos2d::CCNode* Layer) = 0;
15-
virtual const char* PutLayer() const = 0;
16-
};
17-
}
8+
#define Viper_Hookclass(className) \
9+
class className : public CCLayer { \
10+
public: \
11+
void ____________________DONOTUSE__________________________ViperHookInit(); \
12+
}; \
13+
class $modify(CCLayer) { \
14+
bool init() { \
15+
if (!CCLayer::init()) return false; \
16+
if (!Mod::get()->getSettingValue<bool>("external-mods")) { \
17+
return true; \
18+
} \
19+
if (auto x = typeinfo_cast<className*>(this)) { \
20+
queueInMainThread([=] {x->____________________DONOTUSE__________________________ViperHookInit();}); return true; \
21+
} \
22+
return true; \
23+
} \
24+
}; \
25+
void className::____________________DONOTUSE__________________________ViperHookInit()
26+
// PLEASE DON'T USE THIS UNLESS FORCED APON
27+
#define Viper_Hookclass_Scene(unique,className) \
28+
class unique##Sillyclass { \
29+
public: \
30+
void ____________________DONOTUSE__________________________ViperHookInit(CCNode* _This); \
31+
}; \
32+
class $modify(CCDirector) { \
33+
static void onModify(auto& self) { \
34+
(void)self.setHookPriority("CCDirector::willSwitchToScene", -999); \
35+
} \
36+
void willSwitchToScene(CCScene* scene) { \
37+
CCDirector::willSwitchToScene(scene); \
38+
if (!Mod::get()->getSettingValue<bool>("external-mods")) { \
39+
return; \
40+
}; \
41+
if (CCLayer* child = scene->getChildByType<CCLayer>(0)) { \
42+
if (child->getID() == className) { \
43+
unique##Sillyclass sillyInstance; \
44+
sillyInstance.____________________DONOTUSE__________________________ViperHookInit(child); \
45+
}; \
46+
} \
47+
} \
48+
}; \
49+
void unique##Sillyclass::____________________DONOTUSE__________________________ViperHookInit(CCNode* _This)

src/SwelvyBG.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
77
return false;
88

99
this->setID("SwelvyBG");
10-
10+
1111
auto winSize = CCDirector::get()->getWinSize();
1212
this->setContentSize(winSize);
1313
this->setAnchorPoint({ 0.f, 0.f });
@@ -19,14 +19,19 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
1919

2020
float y = m_obContentSize.height + 5;
2121
int idx = 0;
22-
22+
2323
// Retrieve the color offset setting
2424
auto mod = Mod::get();
25-
ccColor3B colorOffset = {255, 0, 0}; // Default color offset
25+
ccColor3B colorOffset = { 0, 0, 0 }; // Default offset is zero (no adjustment)
26+
bool enableColor = false;
27+
2628
if (mod) {
27-
auto colorSetting = mod->getSettingValue<std::string>("color");
28-
if (!colorSetting.empty()) {
29-
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
29+
enableColor = mod->getSettingValue<bool>("enable-color");
30+
if (enableColor) {
31+
auto colorSetting = mod->getSettingValue<std::string>("color");
32+
if (!colorSetting.empty()) {
33+
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
34+
}
3035
}
3136
}
3237

@@ -38,12 +43,16 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
3843
{ ccc3(173, 84, 146), "geode.loader/swelve-layer1.png" },
3944
{ ccc3(113, 74, 154), "geode.loader/swelve-layer0.png" },
4045
}) {
41-
// Apply the color offset
42-
ccColor3B adjustedColor = {
43-
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
44-
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
45-
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
46-
};
46+
ccColor3B adjustedColor = layer.first;
47+
48+
if (enableColor) {
49+
// Apply the color offset
50+
adjustedColor = {
51+
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
52+
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
53+
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
54+
};
55+
}
4756

4857
float speed = dis(gen);
4958
if (sign(gen) == 0) {
@@ -61,17 +70,17 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
6170
sprite->getTexture()->setTexParameters(&params);
6271
sprite->setTextureRect(rect);
6372
sprite->setAnchorPoint({ 0, 1 });
64-
sprite->setContentSize({winSize.width * widthmult, sprite->getContentSize().height});
73+
sprite->setContentSize({ winSize.width * widthmult, sprite->getContentSize().height });
6574
sprite->setColor(adjustedColor);
66-
sprite->setPosition({0, y});
75+
sprite->setPosition({ 0, y });
6776
sprite->schedule(schedule_selector(SwelvyBG::updateSpritePosition));
6877
sprite->setUserObject("speed", CCFloat::create(speed));
6978
this->addChild(sprite);
7079

7180
y -= m_obContentSize.height / 6;
7281
idx += 1;
73-
7482
}
83+
7584
return true;
7685
}
7786

@@ -83,20 +92,20 @@ void SwelvyBG::updateSpritePosition(float dt) {
8392
auto rect = sprite->getTextureRect();
8493

8594
float dX = rect.origin.x - speed * dt;
86-
if(dX >= std::abs(width)) {
95+
if (dX >= std::abs(width)) {
8796
dX = 0;
8897
}
8998

90-
rect.origin = CCPoint{dX, 0};
99+
rect.origin = CCPoint{ dX, 0 };
91100
sprite->setTextureRect(rect);
92101
}
93102

94-
SwelvyBG* SwelvyBG::create(float widthmult, float m, float minspeed, float maxspeed) {
103+
SwelvyBG* SwelvyBG::create(float widthmult, float hightmult, float minspeed, float maxspeed) {
95104
auto ret = new SwelvyBG();
96-
if (ret->init(widthmult,m,minspeed,maxspeed)) {
105+
if (ret->init(widthmult, hightmult, minspeed, maxspeed)) {
97106
ret->autorelease();
98107
return ret;
99108
}
100109
delete ret;
101110
return nullptr;
102-
}
111+
}

src/modify/PlayLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class $modify(MyPlayLayer, PlayLayer) {
1717
bg->setVisible(false);
1818
}
1919

20-
auto swelvyBG = SwelvyBG::create(1.5,3);
20+
SwelvyBG* swelvyBG = SwelvyBG::create(1.5,3);
2121
swelvyBG->setZOrder(-5);
2222
swelvyBG->setID("swelvy-background");
2323
swelvyBG->setScale(2);

0 commit comments

Comments
 (0)