Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/OmgRod/Geodify
Browse files Browse the repository at this point in the history
  • Loading branch information
OmgRod committed Dec 15, 2024
2 parents 91162cf + 8412eb3 commit 603a5d2
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 406 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class $modify(MyCreatorLayer, CreatorLayer) {
};
```


### External Mods

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.
Expand All @@ -70,21 +71,42 @@ For external mods that modify the background of a specific menu, you can use the
#include <Geode/Geode.hpp>
#include "../../SwelvyBG.hpp"
#include "../../Hooks/Hooker.hpp"
using namespace geode::prelude;

class GlobedLevelListLayer : public Betterhook::HookBetter {
void init(CCNode* _This) override {
if (auto bg = _This->getChildByID("background")) {
Viper_Hookclass(GlobedLevelListLayer) {
if (auto bg = this->getChildByID("background")) {
bg->setVisible(false);
}

SwelvyBG* swelvyBG = SwelvyBG::create();
swelvyBG->setZOrder(-1);
swelvyBG->setID("swelvy-background");
_This->addChild(swelvyBG);
}
this->addChild(swelvyBG);
}

const char* PutLayer() const override { return "GlobedLevelListLayer"; }
};
```
This way is new from v1.6.0+!
REGISTER_HookBetter(GlobedLevelListLayer);
```
### External Mods Fix
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.
Please do not do this unless like in this example it's the only way since Viper_Hookclass won't work on it!
```cpp
#include <Geode/Geode.hpp>
#include "../../SwelvyBG.hpp"
#include "../../Hooks/Hooker.hpp"
using namespace geode::prelude;
// class name to store in code, Hook to (the real layer id)
Viper_Hookclass_Scene(cvolton_betterinfo_CustomCreatorLayer,"cvolton.betterinfo/CustomCreatorLayer") {
if (auto bg = _This->getChildByID("cvolton.betterinfo/background")) {
bg->setVisible(false);
SwelvyBG* swelvyBG = SwelvyBG::create();
swelvyBG->setZOrder(-1);
swelvyBG->setID("swelvy-background");
_This->addChild(swelvyBG);
}
}
```
This way is new from v1.6.0+!
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v1.6.0

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

# v1.5.2

Expand Down
11 changes: 9 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "4.0.0",
"geode": "4.1.0",
"gd": {
"android": "2.2074",
"win": "2.2074",
Expand All @@ -15,11 +15,18 @@
"sprites": ["res/*.png"]
},
"settings": {
"enable-color": {
"name": "Enable Color Offset",
"description": "Enables color offset for the SwelvyBG.",
"type": "bool",
"default": false
},
"color": {
"name": "Color Offset",
"description": "The color offset of the background.",
"type": "color",
"default": "#FF0000"
"default": "#FF0000",
"enable-if": "enable-color"
},
"show-main": {
"name": "Show in main menu",
Expand Down
88 changes: 0 additions & 88 deletions src/Hooks/External_Mods_Manager.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions src/Hooks/Hooker.cpp

This file was deleted.

58 changes: 45 additions & 13 deletions src/Hooks/Hooker.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@

#pragma once
#include <Geode/Geode.hpp>
#include <Geode/modify/CCLayer.hpp>
#include <Geode/modify/CCDirector.hpp>
using namespace geode::prelude;


#define REGISTER_HookBetter(Class) $execute { Betterhook::HookBetter::registerHook<Class>(); }
namespace Betterhook {
class HookBetter {
public:
static void registerHook(HookBetter* hook);
template<typename T, typename = std::enable_if_t<std::is_base_of_v<HookBetter, T>>>
static void registerHook() { registerHook(new T()); }
static const std::vector<HookBetter*>& Hooks();
virtual void init(cocos2d::CCNode* Layer) = 0;
virtual const char* PutLayer() const = 0;
};
}
#define Viper_Hookclass(className) \
class className : public CCLayer { \
public: \
void ____________________DONOTUSE__________________________ViperHookInit(); \
}; \
class $modify(CCLayer) { \
bool init() { \
if (!CCLayer::init()) return false; \
if (!Mod::get()->getSettingValue<bool>("external-mods")) { \
return true; \
} \
if (auto x = typeinfo_cast<className*>(this)) { \
queueInMainThread([=] {x->____________________DONOTUSE__________________________ViperHookInit();}); return true; \
} \
return true; \
} \
}; \
void className::____________________DONOTUSE__________________________ViperHookInit()
// PLEASE DON'T USE THIS UNLESS FORCED APON
#define Viper_Hookclass_Scene(unique,className) \
class unique##Sillyclass { \
public: \
void ____________________DONOTUSE__________________________ViperHookInit(CCNode* _This); \
}; \
class $modify(CCDirector) { \
static void onModify(auto& self) { \
(void)self.setHookPriority("CCDirector::willSwitchToScene", -999); \
} \
void willSwitchToScene(CCScene* scene) { \
CCDirector::willSwitchToScene(scene); \
if (!Mod::get()->getSettingValue<bool>("external-mods")) { \
return; \
}; \
if (CCLayer* child = scene->getChildByType<CCLayer>(0)) { \
if (child->getID() == className) { \
unique##Sillyclass sillyInstance; \
sillyInstance.____________________DONOTUSE__________________________ViperHookInit(child); \
}; \
} \
} \
}; \
void unique##Sillyclass::____________________DONOTUSE__________________________ViperHookInit(CCNode* _This)
49 changes: 29 additions & 20 deletions src/SwelvyBG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
return false;

this->setID("SwelvyBG");

auto winSize = CCDirector::get()->getWinSize();
this->setContentSize(winSize);
this->setAnchorPoint({ 0.f, 0.f });
Expand All @@ -19,14 +19,19 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs

float y = m_obContentSize.height + 5;
int idx = 0;

// Retrieve the color offset setting
auto mod = Mod::get();
ccColor3B colorOffset = {255, 0, 0}; // Default color offset
ccColor3B colorOffset = { 0, 0, 0 }; // Default offset is zero (no adjustment)
bool enableColor = false;

if (mod) {
auto colorSetting = mod->getSettingValue<std::string>("color");
if (!colorSetting.empty()) {
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
enableColor = mod->getSettingValue<bool>("enable-color");
if (enableColor) {
auto colorSetting = mod->getSettingValue<std::string>("color");
if (!colorSetting.empty()) {
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
}
}
}

Expand All @@ -38,12 +43,16 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
{ ccc3(173, 84, 146), "geode.loader/swelve-layer1.png" },
{ ccc3(113, 74, 154), "geode.loader/swelve-layer0.png" },
}) {
// Apply the color offset
ccColor3B adjustedColor = {
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
};
ccColor3B adjustedColor = layer.first;

if (enableColor) {
// Apply the color offset
adjustedColor = {
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
};
}

float speed = dis(gen);
if (sign(gen) == 0) {
Expand All @@ -61,17 +70,17 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
sprite->getTexture()->setTexParameters(&params);
sprite->setTextureRect(rect);
sprite->setAnchorPoint({ 0, 1 });
sprite->setContentSize({winSize.width * widthmult, sprite->getContentSize().height});
sprite->setContentSize({ winSize.width * widthmult, sprite->getContentSize().height });
sprite->setColor(adjustedColor);
sprite->setPosition({0, y});
sprite->setPosition({ 0, y });
sprite->schedule(schedule_selector(SwelvyBG::updateSpritePosition));
sprite->setUserObject("speed", CCFloat::create(speed));
this->addChild(sprite);

y -= m_obContentSize.height / 6;
idx += 1;

}

return true;
}

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

float dX = rect.origin.x - speed * dt;
if(dX >= std::abs(width)) {
if (dX >= std::abs(width)) {
dX = 0;
}

rect.origin = CCPoint{dX, 0};
rect.origin = CCPoint{ dX, 0 };
sprite->setTextureRect(rect);
}

SwelvyBG* SwelvyBG::create(float widthmult, float m, float minspeed, float maxspeed) {
SwelvyBG* SwelvyBG::create(float widthmult, float hightmult, float minspeed, float maxspeed) {
auto ret = new SwelvyBG();
if (ret->init(widthmult,m,minspeed,maxspeed)) {
if (ret->init(widthmult, hightmult, minspeed, maxspeed)) {
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
}
2 changes: 1 addition & 1 deletion src/modify/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class $modify(MyPlayLayer, PlayLayer) {
bg->setVisible(false);
}

auto swelvyBG = SwelvyBG::create(1.5,3);
SwelvyBG* swelvyBG = SwelvyBG::create(1.5,3);
swelvyBG->setZOrder(-5);
swelvyBG->setID("swelvy-background");
swelvyBG->setScale(2);
Expand Down
Loading

0 comments on commit 603a5d2

Please sign in to comment.