port geode loader hooks to non macro modify

This commit is contained in:
altalk23 2022-11-09 21:03:53 +03:00 committed by alk
parent e349dc9b74
commit 6a9046d406
15 changed files with 342 additions and 402 deletions

View file

@ -79,7 +79,7 @@ IncludeCategories:
IndentAccessModifiers: false
AccessModifierOffset: -4
IndentCaseBlocks: true
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: true

View file

@ -62,7 +62,7 @@ public:
// proxy forwards
// clang-format off
#include <Geode/modify/CCNode.hpp>
class $modify(ProxyCCNode, CCNode) {
struct ProxyCCNode : Modify<ProxyCCNode, CCNode> {
virtual CCObject* getUserObject() {
return GeodeNodeMetadata::set(this)->m_userObject;
}

View file

@ -9,9 +9,11 @@
USE_GEODE_NAMESPACE();
#pragma warning(disable : 4217)
template <class T = CCNode>
requires std::is_base_of_v<CCNode, T> T* setIDSafe(CCNode* node, int index, char const* id) {
requires std::is_base_of_v<CCNode, T>
T* setIDSafe(CCNode* node, int index, char const* id) {
if constexpr (std::is_same_v<CCNode, T>) {
if (auto child = getChild(node, index)) {
child->setID(id);
@ -29,7 +31,7 @@ requires std::is_base_of_v<CCNode, T> T* setIDSafe(CCNode* node, int index, char
// clang-format off
#include <Geode/modify/LevelSearchLayer.hpp>
class $modify(LevelSearchLayer) {
struct LevelSearchLayerIDs : Modify<LevelSearchLayerIDs, LevelSearchLayer> {
bool init() {
if (!LevelSearchLayer::init())
return false;
@ -99,4 +101,5 @@ class $modify(LevelSearchLayer) {
return true;
}
};
// clang-format on

View file

@ -3,26 +3,23 @@
USE_GEODE_NAMESPACE();
// clang-format off
#include <Geode/modify/LoadingLayer.hpp>
class $modify(CustomLoadingLayer, LoadingLayer) {
struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
bool m_updatingResources;
CustomLoadingLayer() : m_updatingResources(false) {}
bool init(bool fromReload) {
if (!LoadingLayer::init(fromReload))
return false;
if (!LoadingLayer::init(fromReload)) return false;
auto winSize = CCDirector::sharedDirector()->getWinSize();
auto count = Loader::get()->getAllMods().size();
auto label = CCLabelBMFont::create(
CCString::createWithFormat(
"Geode: Loaded %lu mods",
static_cast<unsigned long>(count)
)->getCString(),
CCString::createWithFormat("Geode: Loaded %lu mods", static_cast<unsigned long>(count))
->getCString(),
"goldFont.fnt"
);
label->setPosition(winSize.width / 2, 30.f);
@ -31,13 +28,10 @@ class $modify(CustomLoadingLayer, LoadingLayer) {
this->addChild(label);
// verify loader resources
if (!InternalLoader::get()->verifyLoaderResources(
std::bind(
&CustomLoadingLayer::updateResourcesProgress, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3
)
)) {
if (!InternalLoader::get()->verifyLoaderResources(std::bind(
&CustomLoadingLayer::updateResourcesProgress, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3
))) {
// auto bg = CCScale9Sprite::create(
// "square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f }
// );
@ -73,17 +67,10 @@ class $modify(CustomLoadingLayer, LoadingLayer) {
// );
}
void updateResourcesProgress(
UpdateStatus status,
std::string const& info,
uint8_t progress
) {
void updateResourcesProgress(UpdateStatus status, std::string const& info, uint8_t progress) {
switch (status) {
case UpdateStatus::Progress: {
this->setUpdateText(
"Downloading Resources: " +
std::to_string(progress) + "%"
);
this->setUpdateText("Downloading Resources: " + std::to_string(progress) + "%");
} break;
case UpdateStatus::Finished: {
@ -95,9 +82,10 @@ class $modify(CustomLoadingLayer, LoadingLayer) {
case UpdateStatus::Failed: {
InternalLoader::platformMessageBox(
"Error updating resources",
"Unable to update Geode resources: " + info + ".\n"
"The game will be loaded as normal, but please be aware "
"that it may very likely crash."
"Unable to update Geode resources: " + info +
".\n"
"The game will be loaded as normal, but please be aware "
"that it may very likely crash."
);
this->setUpdateText("Resource Download Failed");
m_fields->m_updatingResources = false;
@ -106,12 +94,10 @@ class $modify(CustomLoadingLayer, LoadingLayer) {
}
}
void loadAssets() {
if (m_fields->m_updatingResources) {
void loadAssets() {
if (m_fields->m_updatingResources) {
return;
}
LoadingLayer::loadAssets();
}
}
LoadingLayer::loadAssets();
}
};
// clang-format on

View file

@ -59,7 +59,8 @@ static void updateIndexProgress(UpdateStatus status, std::string const& info, ui
template <class T = CCNode>
requires std::is_base_of_v<CCNode, T> T* setIDSafe(CCNode* node, int index, char const* id) {
requires std::is_base_of_v<CCNode, T>
T* setIDSafe(CCNode* node, int index, char const* id) {
if constexpr (std::is_same_v<CCNode, T>) {
if (auto child = getChild(node, index)) {
child->setID(id);
@ -75,172 +76,164 @@ requires std::is_base_of_v<CCNode, T> T* setIDSafe(CCNode* node, int index, char
return nullptr;
}
// clang-format off
#include <Geode/modify/MenuLayer.hpp>
class $modify(CustomMenuLayer, MenuLayer) {
void destructor() {
g_geodeButton = nullptr;
MenuLayer::~MenuLayer();
}
bool init() {
if (!MenuLayer::init())
return false;
// set IDs to everything
this->setID("main-menu-layer");
setIDSafe(this, 0, "main-menu-bg");
setIDSafe<CCSprite>(this, 0, "main-title");
struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
void destructor() {
g_geodeButton = nullptr;
MenuLayer::~MenuLayer();
}
if (PlatformToolbox::isControllerConnected()) {
setIDSafe<CCSprite>(this, 1, "play-gamepad-icon");
setIDSafe<CCSprite>(this, 2, "editor-gamepad-icon");
setIDSafe<CCSprite>(this, 3, "icon-kit-gamepad-icon");
bool init() {
if (!MenuLayer::init()) return false;
setIDSafe<CCSprite>(this, 4, "settings-gamepad-icon");
setIDSafe<CCSprite>(this, 5, "mouse-gamepad-icon");
setIDSafe<CCSprite>(this, 6, "click-gamepad-icon");
// set IDs to everything
this->setID("main-menu-layer");
setIDSafe(this, 0, "main-menu-bg");
setIDSafe<CCSprite>(this, 0, "main-title");
setIDSafe<CCLabelBMFont>(this, 0, "mouse-gamepad-label");
setIDSafe<CCLabelBMFont>(this, 1, "click-gamepad-label");
if (PlatformToolbox::isControllerConnected()) {
setIDSafe<CCSprite>(this, 1, "play-gamepad-icon");
setIDSafe<CCSprite>(this, 2, "editor-gamepad-icon");
setIDSafe<CCSprite>(this, 3, "icon-kit-gamepad-icon");
setIDSafe<CCLabelBMFont>(this, 2, "player-username");
} else {
setIDSafe<CCLabelBMFont>(this, 0, "player-username");
setIDSafe<CCSprite>(this, 4, "settings-gamepad-icon");
setIDSafe<CCSprite>(this, 5, "mouse-gamepad-icon");
setIDSafe<CCSprite>(this, 6, "click-gamepad-icon");
auto spriteId = 1;
setIDSafe<CCLabelBMFont>(this, 0, "mouse-gamepad-label");
setIDSafe<CCLabelBMFont>(this, 1, "click-gamepad-label");
if (!GameManager::get()->m_clickedGarage) {
setIDSafe<CCSprite>(this, spriteId++, "click-garage-message");
}
setIDSafe<CCLabelBMFont>(this, 2, "player-username");
}
else {
setIDSafe<CCLabelBMFont>(this, 0, "player-username");
if (!GameManager::get()->m_clickedEditor) {
setIDSafe<CCSprite>(this, spriteId++, "click-editor-message");
}
}
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
menu->setID("main-menu");
setIDSafe(menu, 0, "play-button");
setIDSafe(menu, 1, "icon-kit-button");
setIDSafe(menu, 2, "editor-button");
setIDSafe(menu, 3, "profile-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
menu->setID("bottom-menu");
setIDSafe(menu, 0, "achievements-button");
setIDSafe(menu, 1, "settings-button");
setIDSafe(menu, 2, "stats-button");
setIDSafe(menu, 3, "newgrounds-button");
setIDSafe(menu, -1,"daily-chest-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 2)) {
menu->setID("social-media-menu");
setIDSafe(menu, 0, "robtop-logo-button");
setIDSafe(menu, 1, "facebook-button");
setIDSafe(menu, 2, "twitter-button");
setIDSafe(menu, 3, "youtube-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 3)) {
menu->setID("more-games-menu");
setIDSafe(menu, 0, "more-games-button");
setIDSafe(menu, 1, "close-button");
}
auto spriteId = 1;
auto winSize = CCDirector::sharedDirector()->getWinSize();
if (!GameManager::get()->m_clickedGarage) {
setIDSafe<CCSprite>(this, spriteId++, "click-garage-message");
}
// add geode button
auto bottomMenu = static_cast<CCMenu*>(this->getChildByID("bottom-menu"));
// keep chest in the same position
auto chest = bottomMenu->getChildByID("daily-chest-button");
if (chest) {
chest->retain();
chest->removeFromParent();
}
auto y = getChild(bottomMenu, 0)->getPositionY();
g_geodeButton = SafeCreate<CCSprite>()
.with(CircleButtonSprite::createWithSpriteFrameName(
"geode-logo-outline-gold.png"_spr,
1.0f,
CircleBaseColor::Green,
CircleBaseSize::Medium2
))
.orMake<ButtonSprite>("!!");
addUpdateIcon();
auto btn = CCMenuItemSpriteExtra::create(
g_geodeButton.data(), this, menu_selector(CustomMenuLayer::onGeode)
);
btn->setID("geode-button");
bottomMenu->addChild(btn);
bottomMenu->alignItemsHorizontallyWithPadding(3.f);
for (auto node : CCArrayExt<CCNode>(bottomMenu->getChildren())) {
node->setPositionY(y);
}
if (chest) {
bottomMenu->addChild(chest);
chest->release();
}
if (auto node = this->getChildByID("settings-gamepad-icon")) {
node->setPositionX(bottomMenu->getChildByID(
"settings-button"
)->getPositionX() + winSize.width / 2);
}
// show if some mods failed to load
auto failed = Loader::get()->getFailedMods();
if (failed.size()) {
NotificationBuilder()
.title("Failed to load")
.text("Some mods failed to load")
.show();
if (!GameManager::get()->m_clickedEditor) {
setIDSafe<CCSprite>(this, spriteId++, "click-editor-message");
}
}
if (auto menu = getChildOfType<CCMenu>(this, 0)) {
menu->setID("main-menu");
setIDSafe(menu, 0, "play-button");
setIDSafe(menu, 1, "icon-kit-button");
setIDSafe(menu, 2, "editor-button");
setIDSafe(menu, 3, "profile-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 1)) {
menu->setID("bottom-menu");
setIDSafe(menu, 0, "achievements-button");
setIDSafe(menu, 1, "settings-button");
setIDSafe(menu, 2, "stats-button");
setIDSafe(menu, 3, "newgrounds-button");
setIDSafe(menu, -1, "daily-chest-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 2)) {
menu->setID("social-media-menu");
setIDSafe(menu, 0, "robtop-logo-button");
setIDSafe(menu, 1, "facebook-button");
setIDSafe(menu, 2, "twitter-button");
setIDSafe(menu, 3, "youtube-button");
}
if (auto menu = getChildOfType<CCMenu>(this, 3)) {
menu->setID("more-games-menu");
setIDSafe(menu, 0, "more-games-button");
setIDSafe(menu, 1, "close-button");
}
// show crash info
static bool shownLastCrash = false;
if (Loader::get()->didLastLaunchCrash() && !shownLastCrash) {
shownLastCrash = true;
auto popup = createQuickPopup(
"Crashed",
"It appears that the last session crashed. Would you like to "
"send a <cy>crash report</c>?",
"No", "Send",
[](auto, bool btn2) {
if (btn2) {
ModInfoLayer::showIssueReportPopup(
InternalMod::get()->getModInfo()
);
}
},
false
);
popup->m_scene = this;
popup->m_noElasticity = true;
popup->show();
}
auto winSize = CCDirector::sharedDirector()->getWinSize();
// update mods index
if (!g_indexUpdateNotif && !Index::get()->isIndexUpdated()) {
g_indexUpdateNotif = NotificationBuilder()
.title("Index Update")
.text("Updating index...")
.loading()
.stay()
.show();
// add geode button
auto bottomMenu = static_cast<CCMenu*>(this->getChildByID("bottom-menu"));
Index::get()->updateIndex(updateIndexProgress);
}
// keep chest in the same position
auto chest = bottomMenu->getChildByID("daily-chest-button");
if (chest) {
chest->retain();
chest->removeFromParent();
}
return true;
}
auto y = getChild(bottomMenu, 0)->getPositionY();
void onGeode(CCObject*) {
ModListLayer::scene();
}
g_geodeButton = SafeCreate<CCSprite>()
.with(CircleButtonSprite::createWithSpriteFrameName(
"geode-logo-outline-gold.png"_spr, 1.0f, CircleBaseColor::Green,
CircleBaseSize::Medium2
))
.orMake<ButtonSprite>("!!");
addUpdateIcon();
auto btn = CCMenuItemSpriteExtra::create(
g_geodeButton.data(), this, menu_selector(CustomMenuLayer::onGeode)
);
btn->setID("geode-button");
bottomMenu->addChild(btn);
bottomMenu->alignItemsHorizontallyWithPadding(3.f);
for (auto node : CCArrayExt<CCNode>(bottomMenu->getChildren())) {
node->setPositionY(y);
}
if (chest) {
bottomMenu->addChild(chest);
chest->release();
}
if (auto node = this->getChildByID("settings-gamepad-icon")) {
node->setPositionX(
bottomMenu->getChildByID("settings-button")->getPositionX() + winSize.width / 2
);
}
// show if some mods failed to load
auto failed = Loader::get()->getFailedMods();
if (failed.size()) {
NotificationBuilder().title("Failed to load").text("Some mods failed to load").show();
}
// show crash info
static bool shownLastCrash = false;
if (Loader::get()->didLastLaunchCrash() && !shownLastCrash) {
shownLastCrash = true;
auto popup = createQuickPopup(
"Crashed",
"It appears that the last session crashed. Would you like to "
"send a <cy>crash report</c>?",
"No", "Send",
[](auto, bool btn2) {
if (btn2) {
ModInfoLayer::showIssueReportPopup(InternalMod::get()->getModInfo());
}
},
false
);
popup->m_scene = this;
popup->m_noElasticity = true;
popup->show();
}
// update mods index
if (!g_indexUpdateNotif && !Index::get()->isIndexUpdated()) {
g_indexUpdateNotif = NotificationBuilder()
.title("Index Update")
.text("Updating index...")
.loading()
.stay()
.show();
Index::get()->updateIndex(updateIndexProgress);
}
return true;
}
void onGeode(CCObject*) {
ModListLayer::scene();
}
};
// clang-format on

View file

@ -1,15 +1,15 @@
USE_GEODE_NAMESPACE();
// clang-format off
#include <Geode/modify/CCTouchDispatcher.hpp>
class $modify(CCTouchDispatcher) {
void addTargetedDelegate(CCTouchDelegate *delegate, int priority, bool swallowsTouches) {
struct ForcePrioRevert : Modify<ForcePrioRevert, CCTouchDispatcher> {
void addTargetedDelegate(CCTouchDelegate* delegate, int priority, bool swallowsTouches) {
m_bForcePrio = false;
if (m_pTargetedHandlers->count() > 0) {
auto handler = static_cast<CCTouchHandler*>(m_pTargetedHandlers->objectAtIndex(0));
priority = handler->getPriority() - 2;
}
CCTouchDispatcher::addTargetedDelegate(delegate, priority, swallowsTouches);
}
@ -21,4 +21,3 @@ class $modify(CCTouchDispatcher) {
m_bForcePrio = false;
}
};
// clang-format on

View file

@ -1,14 +1,12 @@
// this is the fix for the dynamic_cast problems
// TODO: completely replace dynamic_cast on macos
using namespace cocos2d;
using namespace geode::modifier;
#include <Geode/DefaultInclude.hpp>
#if defined(GEODE_IS_IOS) || defined(GEODE_IS_MACOS)
using namespace geode::cast;
USE_GEODE_NAMESPACE();
#define HandlerFixFor(CCUtility) \
class $modify(CCUtility##HandlerTypeinfoFix, CCUtility##Handler) { \
struct CCUtility##HandlerFix : Modify<CCUtility##HandlerFix, CCUtility##Handler> { \
void destructor() { \
if (m_pDelegate) { \
cocos2d::CCObject* pObject = base_cast<cocos2d::CCObject*>(m_pDelegate); \
@ -55,7 +53,7 @@ HandlerFixFor(CCKeyboard);
HandlerFixFor(CCMouse);
#include <Geode/modify/CCTargetedTouchHandler.hpp>
class $modify(CCTargetedTouchHandlerTypeinfoFix, CCTargetedTouchHandler) {
struct CCTargetedTouchHandlerFix : Modify<CCTargetedTouchHandlerFix, CCTargetedTouchHandler> {
void destructor() {
if (m_pDelegate) {
cocos2d::CCObject* pObject = base_cast<cocos2d::CCObject*>(m_pDelegate);
@ -101,7 +99,7 @@ class $modify(CCTargetedTouchHandlerTypeinfoFix, CCTargetedTouchHandler) {
};
#include <Geode/modify/CCStandardTouchHandler.hpp>
class $modify(CCStandardTouchHandlerTypeinfoFix, CCStandardTouchHandler) {
struct CCStandardTouchHandlerFix : Modify<CCStandardTouchHandlerFix, CCStandardTouchHandler> {
void destructor() {
if (m_pDelegate) {
cocos2d::CCObject* pObject = base_cast<cocos2d::CCObject*>(m_pDelegate);
@ -140,6 +138,7 @@ class $modify(CCStandardTouchHandlerTypeinfoFix, CCStandardTouchHandler) {
return pHandler;
}
};
// clang-format on
#endif

View file

@ -2,12 +2,11 @@
USE_GEODE_NAMESPACE();
// clang-format off
#include <Geode/modify/AchievementNotifier.hpp>
class $modify(AchievementNotifier) {
struct SceneSwitch : Modify<SceneSwitch, AchievementNotifier> {
void willSwitchToScene(CCScene* scene) {
AchievementNotifier::willSwitchToScene(scene);
SceneManager::get()->willSwitchToScene(scene);
}
};
// clang-format on

View file

@ -2,9 +2,9 @@
USE_GEODE_NAMESPACE();
// clang-format off
#include <Geode/modify/AppDelegate.hpp>
class $modify(AppDelegate) {
struct SaveLoader : Modify<SaveLoader, AppDelegate> {
void trySaveGame() {
log::log(Severity::Info, Loader::getInternalMod(), "Saving...");
@ -14,8 +14,7 @@ class $modify(AppDelegate) {
}
log::log(Severity::Info, Loader::getInternalMod(), "Saved");
return AppDelegate::trySaveGame();
}
};
// clang-format on
};

View file

@ -1,12 +1,12 @@
#include <InternalLoader.hpp>
USE_GEODE_NAMESPACE();
// clang-format off
#include <Geode/modify/CCScheduler.hpp>
class $modify(CCScheduler) {
struct FunctionQueue : Modify<FunctionQueue, CCScheduler> {
void update(float dt) {
InternalLoader::get()->executeGDThreadQueue();
return CCScheduler::update(dt);
}
};
// clang-format on
};

View file

@ -2,14 +2,13 @@
#include <Geode/modify/LoadingLayer.hpp>
USE_GEODE_NAMESPACE();
// clang-format off
class $modify(LoadingLayer) {
void loadAssets() {
struct ResourcesUpdate : Modify<ResourcesUpdate, LoadingLayer> {
void loadAssets() {
LoadingLayer::loadAssets();
// this is in case the user refreshes texture quality at runtime
if (this->m_loadStep == 10) {
Loader::get()->updateResources();
}
}
};
// clang-format on
};

View file

@ -507,45 +507,33 @@ float TextRenderer::adjustLineAlignment() {
auto anchor = node->getAnchorPoint().y;
switch (this->getCurrentVerticalAlign()) {
case TextAlignment::Begin:
default:
{
node->setPositionY(m_cursor.y - height * (1.f - anchor));
}
break;
default: {
node->setPositionY(m_cursor.y - height * (1.f - anchor));
} break;
case TextAlignment::Center:
{
node->setPositionY(m_cursor.y - maxHeight / 2 + height * (.5f - anchor));
}
break;
case TextAlignment::Center: {
node->setPositionY(m_cursor.y - maxHeight / 2 + height * (.5f - anchor));
} break;
case TextAlignment::End:
{
node->setPositionY(m_cursor.y - maxHeight + height * anchor);
}
break;
case TextAlignment::End: {
node->setPositionY(m_cursor.y - maxHeight + height * anchor);
} break;
}
switch (this->getCurrentHorizontalAlign()) {
case TextAlignment::Begin:
default:
{
// already correct
}
break;
default: {
// already correct
} break;
case TextAlignment::Center:
{
node->setPositionX(node->getPositionX() + (m_size.width - maxWidth) / 2);
}
break;
case TextAlignment::Center: {
node->setPositionX(node->getPositionX() + (m_size.width - maxWidth) / 2);
} break;
case TextAlignment::End:
{
node->setPositionX(
node->getPositionX() + m_size.width - maxWidth - this->getCurrentIndent()
);
}
break;
case TextAlignment::End: {
node->setPositionX(
node->getPositionX() + m_size.width - maxWidth - this->getCurrentIndent()
);
} break;
}
}
return maxHeight;

View file

@ -126,37 +126,29 @@ Result<ccColor3B> geode::cocos::cc3bFromHexString(std::string const& hexValue) {
return Err("Invalid hex value");
}
switch (hexValue.size()) {
case 6:
{
auto r = static_cast<uint8_t>((numValue & 0xFF0000) >> 16);
auto g = static_cast<uint8_t>((numValue & 0x00FF00) >> 8);
auto b = static_cast<uint8_t>((numValue & 0x0000FF));
return Ok(ccc3(r, g, b));
}
break;
case 6: {
auto r = static_cast<uint8_t>((numValue & 0xFF0000) >> 16);
auto g = static_cast<uint8_t>((numValue & 0x00FF00) >> 8);
auto b = static_cast<uint8_t>((numValue & 0x0000FF));
return Ok(ccc3(r, g, b));
} break;
case 3:
{
auto r = static_cast<uint8_t>(((numValue & 0xF00) >> 8) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F0) >> 4) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F)) * 17);
return Ok(ccc3(r, g, b));
}
break;
case 3: {
auto r = static_cast<uint8_t>(((numValue & 0xF00) >> 8) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F0) >> 4) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F)) * 17);
return Ok(ccc3(r, g, b));
} break;
case 2:
{
auto num = static_cast<uint8_t>(numValue);
return Ok(ccc3(num, num, num));
}
break;
case 2: {
auto num = static_cast<uint8_t>(numValue);
return Ok(ccc3(num, num, num));
} break;
case 1:
{
auto num = static_cast<uint8_t>(numValue) * 17;
return Ok(ccc3(num, num, num));
}
break;
case 1: {
auto num = static_cast<uint8_t>(numValue) * 17;
return Ok(ccc3(num, num, num));
} break;
default: return Err("Invalid hex size, expected 1, 2, 3, or 6");
}
@ -177,57 +169,45 @@ Result<ccColor4B> geode::cocos::cc4bFromHexString(std::string const& hexValue) {
return Err("Invalid hex value");
}
switch (hexValue.size()) {
case 8:
{
auto r = static_cast<uint8_t>((numValue & 0xFF000000) >> 24);
auto g = static_cast<uint8_t>((numValue & 0x00FF0000) >> 16);
auto b = static_cast<uint8_t>((numValue & 0x0000FF00) >> 8);
auto a = static_cast<uint8_t>((numValue & 0x000000FF));
return Ok(ccc4(r, g, b, a));
}
break;
case 8: {
auto r = static_cast<uint8_t>((numValue & 0xFF000000) >> 24);
auto g = static_cast<uint8_t>((numValue & 0x00FF0000) >> 16);
auto b = static_cast<uint8_t>((numValue & 0x0000FF00) >> 8);
auto a = static_cast<uint8_t>((numValue & 0x000000FF));
return Ok(ccc4(r, g, b, a));
} break;
case 6:
{
auto r = static_cast<uint8_t>((numValue & 0xFF0000) >> 16);
auto g = static_cast<uint8_t>((numValue & 0x00FF00) >> 8);
auto b = static_cast<uint8_t>((numValue & 0x0000FF));
return Ok(ccc4(r, g, b, 255));
}
break;
case 6: {
auto r = static_cast<uint8_t>((numValue & 0xFF0000) >> 16);
auto g = static_cast<uint8_t>((numValue & 0x00FF00) >> 8);
auto b = static_cast<uint8_t>((numValue & 0x0000FF));
return Ok(ccc4(r, g, b, 255));
} break;
case 4:
{
auto r = static_cast<uint8_t>(((numValue & 0xF000) >> 12) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F00) >> 8) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F0) >> 4) * 17);
auto a = static_cast<uint8_t>(((numValue & 0x000F)) * 17);
return Ok(ccc4(r, g, b, a));
}
break;
case 4: {
auto r = static_cast<uint8_t>(((numValue & 0xF000) >> 12) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F00) >> 8) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F0) >> 4) * 17);
auto a = static_cast<uint8_t>(((numValue & 0x000F)) * 17);
return Ok(ccc4(r, g, b, a));
} break;
case 3:
{
auto r = static_cast<uint8_t>(((numValue & 0xF00) >> 8) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F0) >> 4) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F)) * 17);
return Ok(ccc4(r, g, b, 255));
}
break;
case 3: {
auto r = static_cast<uint8_t>(((numValue & 0xF00) >> 8) * 17);
auto g = static_cast<uint8_t>(((numValue & 0x0F0) >> 4) * 17);
auto b = static_cast<uint8_t>(((numValue & 0x00F)) * 17);
return Ok(ccc4(r, g, b, 255));
} break;
case 2:
{
auto num = static_cast<uint8_t>(numValue);
return Ok(ccc4(num, num, num, 255));
}
break;
case 2: {
auto num = static_cast<uint8_t>(numValue);
return Ok(ccc4(num, num, num, 255));
} break;
case 1:
{
auto num = static_cast<uint8_t>(numValue) * 17;
return Ok(ccc4(num, num, num, 255));
}
break;
case 1: {
auto num = static_cast<uint8_t>(numValue) * 17;
return Ok(ccc4(num, num, num, 255));
} break;
default: return Err("Invalid hex size, expected 1, 2, 3, 4, 6, or 8");
}

View file

@ -3,31 +3,26 @@
USE_GEODE_NAMESPACE();
#include <Geode/modify/MenuLayer.hpp>
class $modify(MenuLayer) {
void onMoreGames(CCObject*) {
if (Mod::get()->getSettingValue<bool>("its-raining-after-all")) {
FLAlertLayer::create(
"Damn",
":(",
"OK"
)->show();
} else {
FLAlertLayer::create(
"Yay",
"The weather report said it wouldn't rain today :)",
"OK"
)->show();
}
}
struct MyMenuLayer : Modify<MyMenuLayer, MenuLayer> {
void onMoreGames(CCObject*) {
if (Mod::get()->getSettingValue<bool>("its-raining-after-all")) {
FLAlertLayer::create("Damn", ":(", "OK")->show();
}
else {
FLAlertLayer::create("Yay", "The weather report said it wouldn't rain today :)", "OK")
->show();
}
}
};
GEODE_API bool GEODE_CALL geode_load(Mod*) {
// Dispatcher::get()->addFunction<void(GJGarageLayer*)>("test-garage-open", [](GJGarageLayer* gl) {
// auto label = CCLabelBMFont::create("Dispatcher works!", "bigFont.fnt");
// label->setPosition(100, 80);
// label->setScale(.4f);
// label->setZOrder(99999);
// gl->addChild(label);
// });
return true;
// Dispatcher::get()->addFunction<void(GJGarageLayer*)>("test-garage-open", [](GJGarageLayer*
// gl) { auto label = CCLabelBMFont::create("Dispatcher works!", "bigFont.fnt");
// label->setPosition(100, 80);
// label->setScale(.4f);
// label->setZOrder(99999);
// gl->addChild(label);
// });
return true;
}

View file

@ -2,90 +2,91 @@
USE_GEODE_NAMESPACE();
auto test = [](){
auto test = []() {
log::info("Static logged");
return 0;
};
// Exported functions
GEODE_API bool GEODE_CALL geode_enable() {
log::info("Enabled");
return true;
log::info("Enabled");
return true;
}
GEODE_API bool GEODE_CALL geode_disable() {
log::info("Disabled");
return true;
log::info("Disabled");
return true;
}
GEODE_API bool GEODE_CALL geode_load(Mod*) {
log::info("Loaded");
return true;
log::info("Loaded");
return true;
}
GEODE_API bool GEODE_CALL geode_unload() {
log::info("Unloaded");
return true;
log::info("Unloaded");
return true;
}
// Modify
#include <Geode/modify/GJGarageLayer.hpp>
class $modify(GJGarageLayerTest, GJGarageLayer) {
GJGarageLayerTest() :
myValue(1907) {}
int myValue;
std::string myString = "yeah have fun finding a better thing for this";
bool init() {
if (!GJGarageLayer::init()) return false;
struct GJGarageLayerTest : Modify<GJGarageLayerTest, GJGarageLayer> {
GJGarageLayerTest() : myValue(1907) {}
auto label = CCLabelBMFont::create("Modify works!", "bigFont.fnt");
label->setPosition(100, 110);
label->setScale(.4f);
label->setZOrder(99999);
addChild(label);
int myValue;
std::string myString = "yeah have fun finding a better thing for this";
if (m_fields->myValue == 1907 && m_fields->myString != "") {
auto label = CCLabelBMFont::create("Field default works!", "bigFont.fnt");
label->setPosition(100, 100);
label->setScale(.4f);
label->setZOrder(99999);
addChild(label);
}
bool init() {
if (!GJGarageLayer::init()) return false;
// Data Store
auto ds = Mod::get()->getDataStore();
int out = ds["times-opened"];
ds["times-opened"] = out + 1;
auto label = CCLabelBMFont::create("Modify works!", "bigFont.fnt");
label->setPosition(100, 110);
label->setScale(.4f);
label->setZOrder(99999);
addChild(label);
std::string text = std::string("Times opened: ") + std::to_string(out);
if (m_fields->myValue == 1907 && m_fields->myString != "") {
auto label = CCLabelBMFont::create("Field default works!", "bigFont.fnt");
label->setPosition(100, 100);
label->setScale(.4f);
label->setZOrder(99999);
addChild(label);
}
auto label2 = CCLabelBMFont::create(text.c_str(), "bigFont.fnt");
label2->setPosition(100, 90);
label2->setScale(.4f);
label2->setZOrder(99999);
addChild(label2);
// Data Store
auto ds = Mod::get()->getDataStore();
int out = ds["times-opened"];
ds["times-opened"] = out + 1;
// Dispatch system pt. 1
// auto fn = Dispatcher::get()->getFunction<void(GJGarageLayer*)>("test-garage-open");
// fn(this);
std::string text = std::string("Times opened: ") + std::to_string(out);
return true;
}
auto label2 = CCLabelBMFont::create(text.c_str(), "bigFont.fnt");
label2->setPosition(100, 90);
label2->setScale(.4f);
label2->setZOrder(99999);
addChild(label2);
// Dispatch system pt. 1
// auto fn = Dispatcher::get()->getFunction<void(GJGarageLayer*)>("test-garage-open");
// fn(this);
return true;
}
};
/*// Event system pt. 2
int a = (0, []() {
Dispatcher::get()->addSelector("test-garage-open", [](GJGarageLayer* gl) {
auto label = CCLabelBMFont::create("EventCenter works!", "bigFont.fnt");
label->setPosition(100, 80);
label->setScale(.4f);
label->setZOrder(99999);
gl->addChild(label);
Dispatcher::get()->addSelector("test-garage-open", [](GJGarageLayer* gl) {
auto label = CCLabelBMFont::create("EventCenter works!", "bigFont.fnt");
label->setPosition(100, 80);
label->setScale(.4f);
label->setZOrder(99999);
gl->addChild(label);
TestDependency::depTest(gl);
});
TestDependency::depTest(gl);
});
// Event system pt. 2
// $observe("test-garage-open", GJGarageLayer*, evt) {
@ -99,6 +100,5 @@ int a = (0, []() {
// // API pt. 2
// TestDependency::depTest(gl);
// }
return 0;
return 0;
}());*/