From 4d529922cfd8cefc92e668ccf0d6056aa84b8ee8 Mon Sep 17 00:00:00 2001 From: Explodingbill Date: Tue, 2 Jul 2024 20:02:25 +1000 Subject: [PATCH 1/4] RIFT Modules beta 1 --- CMakeLists.txt | 6 +- src/Hacks/SafeMode/SafeMode.cpp | 4 +- src/Labels/LabelModule.cpp | 6 + src/Labels/LabelModule.hpp | 14 ++ src/Labels/LabelNode.cpp | 42 +++++ src/Labels/LabelNode.hpp | 21 +++ src/Labels/Labels.cpp | 287 +++++++------------------------- src/Labels/Labels.h | 64 ++----- 8 files changed, 161 insertions(+), 283 deletions(-) create mode 100644 src/Labels/LabelModule.cpp create mode 100644 src/Labels/LabelModule.hpp create mode 100644 src/Labels/LabelNode.cpp create mode 100644 src/Labels/LabelNode.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4b846..d8f394e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,12 +47,10 @@ foreach(MODULE ${MODULES_LIST}) endif() endforeach() -#if("$ENV{USERNAME}" STREQUAL "talgo") - #add_definitions(-DFREEMOVE) -#endif() - CPMAddPackage("gh:matcool/gd-imgui-cocos#4eb5777") # specify a commit! +CPMAddPackage("gh:EclipseMenu/RIFT#327c270") # specify a commit! target_link_libraries(${PROJECT_NAME} imgui-cocos) +target_link_libraries(${PROJECT_NAME} rift) setup_geode_mod(${PROJECT_NAME}) diff --git a/src/Hacks/SafeMode/SafeMode.cpp b/src/Hacks/SafeMode/SafeMode.cpp index 5473dea..f7a5858 100644 --- a/src/Hacks/SafeMode/SafeMode.cpp +++ b/src/Hacks/SafeMode/SafeMode.cpp @@ -92,8 +92,8 @@ void SafeMode::updateIndicator() if (auto a = StatusNode::get()) { - if (auto l = a->sLabels[0]) - l->setColor(colourForState()); + //if (auto l = a->sLabels[0]) + //l->setColor(colourForState()); a->update(1); a->reorderSides(); diff --git a/src/Labels/LabelModule.cpp b/src/Labels/LabelModule.cpp new file mode 100644 index 0000000..7345ddb --- /dev/null +++ b/src/Labels/LabelModule.cpp @@ -0,0 +1,6 @@ +#include "LabelModule.hpp" + +LabelModule::LabelModule(std::string format) +{ + this->format = format; +} \ No newline at end of file diff --git a/src/Labels/LabelModule.hpp b/src/Labels/LabelModule.hpp new file mode 100644 index 0000000..2b536ee --- /dev/null +++ b/src/Labels/LabelModule.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include "../Client/Client.h" + +using namespace geode::prelude; + +class LabelModule : public Module +{ + public: + std::string format; + + LabelModule(std::string format); +}; \ No newline at end of file diff --git a/src/Labels/LabelNode.cpp b/src/Labels/LabelNode.cpp new file mode 100644 index 0000000..8c22f4b --- /dev/null +++ b/src/Labels/LabelNode.cpp @@ -0,0 +1,42 @@ +#include "LabelNode.hpp" + +LabelNode* LabelNode::create(LabelModule* module) +{ + auto pRet = new LabelNode(); + + if (pRet && pRet->init(module)) + { + pRet->autorelease(); + return pRet; + } + + CC_SAFE_DELETE(pRet); + return nullptr; +} + +bool LabelNode::init(LabelModule* module) +{ + if (!CCLabelBMFont::initWithString("", "bigFont.fnt")) + return false; + + this->module = module; + + return true; +} + +void LabelNode::update(float delta) +{ + script = rift::compile(module->format); + + if (!script) + { + return this->setString("Error Compiling Script"); + } + + script->setVariable("number", 210); + script->setVariable("name", "World"); + + auto res = script->run(); + + this->setString(res.c_str()); +} \ No newline at end of file diff --git a/src/Labels/LabelNode.hpp b/src/Labels/LabelNode.hpp new file mode 100644 index 0000000..9e3f0d7 --- /dev/null +++ b/src/Labels/LabelNode.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include "../Client/Client.h" +#include "LabelModule.hpp" +#include + +using namespace geode::prelude; + +class LabelNode : public CCLabelBMFont +{ + public: + LabelModule* module; + rift::Script* script; + + static LabelNode* create(LabelModule* module); + + bool init(LabelModule* module); + + virtual void update(float delta); +}; \ No newline at end of file diff --git a/src/Labels/Labels.cpp b/src/Labels/Labels.cpp index dba4a8e..3b74b8e 100644 --- a/src/Labels/Labels.cpp +++ b/src/Labels/Labels.cpp @@ -33,24 +33,11 @@ bool StatusNode::init() bottomRight->setID("bottom-right"); this->addChild(bottomRight); - int count = 9; - - for (size_t i = 0; i < count; i++) - { - auto lbl = CCLabelBMFont::create("boobs", "bigFont.fnt"); - lbl->setAnchorPoint(ccp(0, 1)); - lbl->setPositionX(3); - lbl->setTag(i); - - sLabels.push_back(lbl); - } - - sLabels[0]->setString("."); - as(sLabels[0]->getChildren()->objectAtIndex(0))->setScale(2.25f); - as(sLabels[0]->getChildren()->objectAtIndex(0))->setAnchorPoint(ccp(0.2f, 0.35f)); - hidden = Mod::get()->getSavedValue("hide-labels"); + labels.push_back(LabelNode::create(new LabelModule("Test #{number * 2}, Hello {name}!"))); + topLeft->addChild(labels[0]); + update(1.0f); updateVis(); @@ -60,114 +47,60 @@ bool StatusNode::init() return true; } -void StatusNode::updateVis() +StatusNode* StatusNode::create() { - float op = 0.9f, scale = 1.0f; - - auto o = numFromString(StatusOpacity::instance->text); - if (o.isOk()) - op = o.value(); - - auto s = numFromString(StatusScale::instance->text); - if (s.isOk()) - scale = s.value(); - - op = clamp(op, 0.0f, 1.0f); + auto ret = new StatusNode(); - int y = 0; - - for (size_t i = 0; i < sLabels.size(); i++) + if (ret && ret->init()) { - sLabels[i]->setScale(0.5f * scale); - sLabels[i]->setOpacity((int)round(255 * op)); - - if (hidden) - sLabels[i]->setVisible(false); + ret->autorelease(); + return ret; } + + CC_SAFE_DELETE(ret); + return nullptr; } -void StatusNode::reorderSides() +StatusNode* StatusNode::get() { - for (auto label : sLabels) - { - label->retain(); - } - - topLeft->removeAllChildrenWithCleanup(false); - topRight->removeAllChildrenWithCleanup(false); - bottomLeft->removeAllChildrenWithCleanup(false); - bottomRight->removeAllChildrenWithCleanup(false); - - int i = 0; - - for (auto label : sLabels) - { - int side = as(window->modules[i + 2]->options[0])->index; - - label->setAnchorPoint(ccp((side == 0 || side == 2) ? 0 : 1, (side == 2 || side == 3) ? 0 : 1)); - label->setAlignment((side == 0 || side == 2) ? CCTextAlignment::kCCTextAlignmentLeft : CCTextAlignment::kCCTextAlignmentRight); - - (side == 0 ? topLeft : (side == 1 ? topRight : (side == 2 ? bottomLeft : bottomRight)))->addChild(label); - - i++; - - label->release(); - } + return instance; } -void StatusNode::reorderPosition() +void StatusNode::update(float dt) { - float op = 0.9f, scale = 1.0f; - - auto o = numFromString(StatusOpacity::instance->text); - if (o.isOk()) - op = o.value(); - - auto s = numFromString(StatusScale::instance->text); - if (s.isOk()) - scale = s.value(); - - op = clamp(op, 0.0f, 1.0f); - - int v = 0; - - for (size_t i = 0; i < bottomLeft->getChildrenCount(); i++) - { - as(bottomLeft->getChildren()->objectAtIndex(i))->setPosition(ccp(3, 3 + (32.5f * scale * 0.5f) * v)); + auto timeScale = CCScheduler::get()->getTimeScale() / SpeedhackTop::instance->getFloatValue(); - if (as(bottomLeft->getChildren()->objectAtIndex(i))->isVisible()) - v++; - } - - v = 0; + _timeLeft -= dt / timeScale; + _accum += 1 / (dt / timeScale); + _frames++; - for (size_t i = 0; i < bottomRight->getChildrenCount(); i++) - { - as(bottomRight->getChildren()->objectAtIndex(i))->setPosition(ccp(CCDirector::get()->getWinSize().width - 3, 3 + (32.5f * scale * 0.5f) * v)); + if (_timeLeft <= 0) { + this->fps = _accum / _frames; - if (as(bottomRight->getChildren()->objectAtIndex(i))->isVisible()) - v++; + _timeLeft = _updateInterval; + _accum = 0; + _frames = 0; } - v = 0; - - for (size_t i = 0; i < topLeft->getChildrenCount(); i++) + for (auto label : labels) { - as(topLeft->getChildren()->objectAtIndex(i))->setPosition(ccp(3, CCDirector::get()->getWinSize().height - (3 + (32.5f * scale * 0.5f) * v))); - - if (as(topLeft->getChildren()->objectAtIndex(i))->isVisible()) - v++; + label->update(dt); } +} - v = 0; +void StatusNode::updateVis() +{ + +} - for (size_t i = 0; i < topRight->getChildrenCount(); i++) - { - as(topRight->getChildren()->objectAtIndex(i))->setPosition(ccp(CCDirector::get()->getWinSize().width - 3, CCDirector::get()->getWinSize().height - (3 + (32.5f * scale * 0.5f) * v))); +void StatusNode::reorderSides() +{ + +} - if (as(topRight->getChildren()->objectAtIndex(i))->isVisible()) - v++; - } +void StatusNode::reorderPosition() +{ + } class LabelModuleDelegate : public ModuleChangeDelegate @@ -198,118 +131,28 @@ void StatusNode::postSetup(Window* wnd) } } -void StatusNode::update(float dt) +void StatusNode::updateCPS(float dt) { - if (!cheat) - cheat = Client::GetModule("cheat-indicator"); - if (!fps) - fps = Client::GetModule("status-fps"); - - if (!accuracy) - accuracy = Client::GetModule("status-accuracy"); - - if (!deaths) - deaths = Client::GetModule("status-deaths"); - - if (!noclip) - noclip = Client::GetModule("noclip"); - - if (!replay) - replay = Client::GetModule("status-replay"); - - if (!attempt) - attempt = Client::GetModule("status-attempt"); - - if (!message) - message = Client::GetModule("status-message"); - - if (!session) - session = Client::GetModule("status-session"); - - if (!cpsM) - cpsM = Client::GetModule("status-cps"); - - if (!attPL) - attPL = static_cast(PlayLayer::get()); - - float v = 100 * (1 - (PlayLayer::get()->m_gameState.m_currentProgress == 0 ? 0 : as(PlayLayer::get())->m_fields->t / static_cast(PlayLayer::get()->m_gameState.m_currentProgress))); - - - sLabels[0]->setVisible(cheat->enabled); - sLabels[1]->setVisible(fps->enabled); - sLabels[2]->setVisible(noclip->enabled && accuracy->enabled); - sLabels[3]->setVisible(noclip->enabled && deaths->enabled); - sLabels[4]->setVisible(attempt->enabled); - sLabels[5]->setVisible(replay->enabled && (GJReplayManager::recording || GJReplayManager::playing)); - //sLabels[6]->setVisible(replay->enabled && (GJReplayManager::recording || GJReplayManager::playing)); - //sLabels[7]->setVisible(replay->enabled && (GJReplayManager::recording || GJReplayManager::playing)); - sLabels[6]->setVisible(message->enabled); - sLabels[7]->setVisible(session->enabled); - sLabels[8]->setVisible(cpsM->enabled); - - - sLabels[2]->setString((numToString(v, 2) + std::string("%")).c_str()); - sLabels[3]->setString((numToString(as(PlayLayer::get())->m_fields->d, 0) + (as(PlayLayer::get())->m_fields->d == 1 ? std::string(" Death") : std::string(" Deaths"))).c_str()); - sLabels[4]->setString((std::string("Attempt ") + std::to_string(attPL->m_fields->attemptCount)).c_str()); - - std::stringstream ss; - ss << "Frame: " << numToString(GJReplayManager::frame) << ", Delta: " << numToString(GJReplayManager::dt, 4); - - std::stringstream inp; - inp << GJReplayManager::replay.inputs.size() << (GJReplayManager::replay.inputs.size() == 1 ? " Input" : " Inputs") << ", " << GJReplayManager::replay.frames.size() << (GJReplayManager::replay.frames.size() == 1 ? " Frame" : " Frames"); - - std::string b = (std::string("Frame Fixes: ") + (Mod::get()->getSavedValue("frame-fixes") ? "Enabled" : "Disabled") + std::string(", Click Fixes: ") + (Mod::get()->getSavedValue("click-fixes") ? "Enabled" : "Disabled")); - sLabels[5]->setString(ss.str().c_str()); - //sLabels[6]->setString(b.c_str()); - //sLabels[7]->setString(inp.str().c_str()); - auto v2 = as(message->options[1])->text.c_str(); - sLabels[6]->setString(v2); - sLabels[7]->setString(formatTime(ColourUtility::totalSessionTime).c_str()); - - if (as(PlayLayer::get())->m_fields->isDead) - { - sLabels[2]->stopAllActions(); - sLabels[2]->setColor(ccc3(255, 0, 0)); - sLabels[2]->runAction(CCTintTo::create(0.5f, 255, 255, 255)); - - sLabels[3]->stopAllActions(); - sLabels[3]->setColor(ccc3(255, 0, 0)); - sLabels[3]->runAction(CCTintTo::create(0.5f, 255, 255, 255)); - - as(PlayLayer::get())->m_fields->isDead = false; - } - - _timeLeft -= dt / CCScheduler::get()->getTimeScale(); - _accum += 1 / (dt / CCScheduler::get()->getTimeScale()); - _frames++; - - if (_timeLeft <= 0) { - float fps = _accum / _frames; - - sLabels[1]->setString((std::to_string(as(roundf(fps))) + std::string(" FPS")).c_str()); - //CCLOG("Average FPS: %.2f", fps); - - _timeLeft = _updateInterval; - _accum = 0; - _frames = 0; - } - - for (size_t i = 0; i < cps.size(); i++) - { - cps[i] -= dt / CCScheduler::get()->getTimeScale(); - } - - cps.erase(std::remove_if(cps.begin(), cps.end(), [](float i){ return i < 0; }), cps.end()); +} - sLabels[8]->setString((std::to_string(as(cps.size())) + std::string(" CPS")).c_str()); +void LabelPlayLayer::resetLevel() +{ + PlayLayer::resetLevel(); - updateVis(); + m_fields->attemptCount++; } -void StatusNode::updateCPS(float dt) +bool LabelPlayLayer::init(GJGameLevel* p0, bool p1, bool p2) { - + if (!PlayLayer::init(p0, p1, p2)) + return false; + + auto stn = StatusNode::create(); + stn->attPL = this; + m_uiLayer->addChild(stn); + + return true; } class $modify (PlayerObject) @@ -318,7 +161,7 @@ class $modify (PlayerObject) { PlayerObject::pushButton(p0); - if (p0 == PlayerButton::Jump && PlayLayer::get()) + /*if (p0 == PlayerButton::Jump && PlayLayer::get()) { if (auto stn = StatusNode::get()) { @@ -327,39 +170,21 @@ class $modify (PlayerObject) stn->sLabels[8]->stopAllActions(); stn->sLabels[8]->setColor(ccc3(0, 255, 0)); } - } + }*/ } void releaseButton(PlayerButton p0) { PlayerObject::releaseButton(p0); - if (p0 == PlayerButton::Jump && PlayLayer::get()) + /*if (p0 == PlayerButton::Jump && PlayLayer::get()) { if (auto stn = StatusNode::get()) { stn->sLabels[8]->stopAllActions(); stn->sLabels[8]->runAction(CCTintTo::create(1, 255, 255, 255)); } - } - } -}; - -class $modify (PlayLayer) -{ - bool init(GJGameLevel* p0, bool p1, bool p2) - { - if (!PlayLayer::init(p0, p1, p2)) - return false; - - if (getChildByID("status-node"_spr)) - return true; - - auto stn = StatusNode::create(); - stn->attPL = static_cast(PlayLayer::get()); - this->addChild(stn); - - return true; + }*/ } }; diff --git a/src/Labels/Labels.h b/src/Labels/Labels.h index b6db938..d083484 100644 --- a/src/Labels/Labels.h +++ b/src/Labels/Labels.h @@ -6,64 +6,43 @@ #include #include #include "../Client/Client.h" - +#include "LabelNode.hpp" #include "../Hacks/Noclip.cpp" using namespace geode::prelude; -class $modify (AttemptPlayLayer, PlayLayer) +class $modify (LabelPlayLayer, PlayLayer) { struct Fields { int attemptCount = 0; }; - void resetLevel() - { - PlayLayer::resetLevel(); - - m_fields->attemptCount++; - } + bool init(GJGameLevel* p0, bool p1, bool p2); + void resetLevel(); }; class StatusNode : public CCNode { + private: + static inline StatusNode* instance = nullptr; + float _updateInterval = 0.5f; + float _timeLeft = _updateInterval; + float _accum; + int _frames; + public: - static StatusNode* create() { - auto ret = new (std::nothrow) StatusNode; - if (ret && ret->init()) { - ret->autorelease(); - return ret; - } - delete ret; - return nullptr; - } + int fps; + std::vector labels; + + static StatusNode* create(); + static StatusNode* get(); ~StatusNode() { instance = nullptr; } - static inline StatusNode* instance = nullptr; - - static StatusNode* get() { return instance; } - - //NoclipLayer* v; - - bool mods; - - AttemptPlayLayer* attPL = nullptr; - - static inline Module* fps = nullptr; - static inline Module* cheat = nullptr; - static inline Module* accuracy = nullptr; - static inline Module* deaths = nullptr; - static inline Module* replay = nullptr; - static inline Module* attempt = nullptr; - static inline Module* message = nullptr; - static inline Module* session = nullptr; - static inline Module* cpsM = nullptr; - - static inline Module* noclip = nullptr; + LabelPlayLayer* attPL = nullptr; CCMenu* topLeft = nullptr; CCMenu* topRight = nullptr; @@ -72,15 +51,8 @@ class StatusNode : public CCNode static inline Window* window = nullptr; - std::vector sLabels = {}; - static inline bool hidden = false; - float _updateInterval = 0.5f; - float _timeLeft = _updateInterval; - float _accum; - int _frames; - std::vector cps; std::string formatTime(float time) { @@ -113,7 +85,7 @@ class StatusNode : public CCNode void reorderSides(); void reorderPosition(); - void update(float dt); + virtual void update(float dt); void updateCPS(float dt); }; From fb733dc674639a9931308052396b00b8ff43e219 Mon Sep 17 00:00:00 2001 From: Explodingbill Date: Thu, 4 Jul 2024 10:38:06 +1000 Subject: [PATCH 2/4] stuff --- src/Client/ClientSetup.h | 42 ++---------- src/CustomWindows/Labels.cpp | 73 +++++++++++++++++++- src/CustomWindows/Labels.h | 9 ++- src/Hacks/SafeMode/SafeMode.cpp | 1 - src/Labels/LabelModule.cpp | 66 +++++++++++++++++- src/Labels/LabelModule.hpp | 30 ++++++++- src/Labels/LabelNode.cpp | 14 +++- src/Labels/LabelNode.hpp | 3 +- src/Labels/Labels.cpp | 116 +++++++++++++++++++++++--------- src/Labels/Labels.h | 39 ++++++----- 10 files changed, 293 insertions(+), 100 deletions(-) diff --git a/src/Client/ClientSetup.h b/src/Client/ClientSetup.h index 153326c..9ac0911 100644 --- a/src/Client/ClientSetup.h +++ b/src/Client/ClientSetup.h @@ -307,47 +307,13 @@ class ClientUtils static void SetupStatus() { - #ifndef STATUS_TEXTS - return; - #endif - - Window* replay = new Labels(); - - replay->modules.push_back(new StatusOpacity()); - replay->modules.push_back(new StatusScale()); - - //replay->modules.push_back(new Module("Testmode", "status-testmode", "Show the test mode text if there's a startpos")); - replay->modules.push_back(new Module("Cheat Indicator", "cheat-indicator", "Shows if you are cheating")); - replay->modules.push_back(new Module("FPS Counter", "status-fps", "Shows your current game fps")); - replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your accuracy in noclip (hidden when noclip is disabled)")); - replay->modules.push_back(new Module("Noclip Deaths", "status-deaths", "Shows your deaths in noclip (hidden when noclip is disabled)")); - replay->modules.push_back(new Module("Attempts", "status-attempt", "Shows Attempt Count")); - //replay->modules.push_back(new Module("Clicks", "status-cps", "Shows Attempt Count")); - - replay->modules.push_back(new Module("Replay Status", "status-replay", "Replay debug info")); - //replay->modules.push_back(new Module("Noclip Deaths (not fully accurate)", "status-death", "Shows your death count (hidden when noclip is disabled)")); - //replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your death accuracy (hidden when noclip is disabled)")); - //replay->modules.push_back(new Module("Attempts", "status-attempts", "Shows your attempt count")); - //replay->modules.push_back(new Module("Clicks", "status-clicks", "Shows your click count")); - replay->modules.push_back(new Module("Message", "status-message", "Write a message of your choice to be shown")); - replay->modules.push_back(new Module("Session Time", "status-session", "Shows the time you've had the game open for in the format hh::mm::ss")); - replay->modules.push_back(new Module("Clicks Per Second", "status-cps", "Shows your clicks per second. Tints Green while you are clicking")); - //replay->modules.push_back(new StatusMessage()); - - Client::instance->windows.push_back(replay); + #ifdef STATUS_TEXTS - for (auto mod : replay->modules) - { - mod->options.push_back(new DropdownModule({"Top Left", "Top Right", "Bottom Left", "Bottom Right"}, mod->id + "-side", 0)); - } + Window* status = new Labels(); - auto messageOption = new InputModule("Message Text: ", "status-message-text", "Default Message"); - messageOption->allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{};:\'\",.<>/?|`~ "; - messageOption->maxSize = 48; // its just a bit before it overflows on 16:9, perfect - Client::GetModule("status-message")->options.push_back(messageOption); + Client::instance->windows.push_back(status); + StatusNode::postSetup(status); - #ifdef STATUS_TEXTS - StatusNode::postSetup(replay); #endif } diff --git a/src/CustomWindows/Labels.cpp b/src/CustomWindows/Labels.cpp index 1d2f1a8..9d145a8 100644 --- a/src/CustomWindows/Labels.cpp +++ b/src/CustomWindows/Labels.cpp @@ -1,8 +1,43 @@ #include "Labels.h" +/* +replay->modules.push_back(new StatusOpacity()); +replay->modules.push_back(new StatusScale()); + +//replay->modules.push_back(new Module("Testmode", "status-testmode", "Show the test mode text if there's a startpos")); +replay->modules.push_back(new Module("Cheat Indicator", "cheat-indicator", "Shows if you are cheating")); +replay->modules.push_back(new Module("FPS Counter", "status-fps", "Shows your current game fps")); +replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your accuracy in noclip (hidden when noclip is disabled)")); +replay->modules.push_back(new Module("Noclip Deaths", "status-deaths", "Shows your deaths in noclip (hidden when noclip is disabled)")); +replay->modules.push_back(new Module("Attempts", "status-attempt", "Shows Attempt Count")); +//replay->modules.push_back(new Module("Clicks", "status-cps", "Shows Attempt Count")); + +replay->modules.push_back(new Module("Replay Status", "status-replay", "Replay debug info")); +//replay->modules.push_back(new Module("Noclip Deaths (not fully accurate)", "status-death", "Shows your death count (hidden when noclip is disabled)")); +//replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your death accuracy (hidden when noclip is disabled)")); +//replay->modules.push_back(new Module("Attempts", "status-attempts", "Shows your attempt count")); +//replay->modules.push_back(new Module("Clicks", "status-clicks", "Shows your click count")); +replay->modules.push_back(new Module("Message", "status-message", "Write a message of your choice to be shown")); +replay->modules.push_back(new Module("Session Time", "status-session", "Shows the time you've had the game open for in the format hh::mm::ss")); +replay->modules.push_back(new Module("Clicks Per Second", "status-cps", "Shows your clicks per second. Tints Green while you are clicking")); +//replay->modules.push_back(new StatusMessage()); + + + +for (auto mod : replay->modules) +{ + mod->options.push_back(new DropdownModule({"Top Left", "Top Right", "Bottom Left", "Bottom Right"}, mod->id + "-side", 0)); +} + +auto messageOption = new InputModule("Message Text: ", "status-message-text", "Default Message"); +messageOption->allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{};:\'\",.<>/?|`~ "; +messageOption->maxSize = 48; // its just a bit before it overflows on 16:9, perfect +Client::GetModule("status-message")->options.push_back(messageOption); +*/ + void Labels::cocosCreate(CCMenu* menu) { - return Window::cocosCreate(menu); // todo: finish ui + //return Window::cocosCreate(menu); // todo: finish ui labels.clear(); @@ -85,6 +120,12 @@ void Labels::cocosCreate(CCMenu* menu) labels.push_back(name); scroll->m_contentLayer->addChild(cell); } + + error = TextArea::create("Nothing here yet :(", "bigFont.fnt", 1, 1000, ccp(0.5f, 0.5f), 10, false); + error->setVisible(modules.size() == 0); + error->setPosition(bg->getPosition() + bg->getContentSize() / 2); + error->setScale(0.65f); + menu->addChild(error); } void Labels::onHide(CCObject* sender) @@ -116,4 +157,32 @@ void Labels::onLabelOptions(CCObject* sender) auto mod = as(as(sender)->getUserData()); mod->onOptionsAndroid(sender); -} \ No newline at end of file +} + +void Labels::loadConfig() +{ + if (Mod::get()->hasSavedValue("labels-config")) + { + auto cfg = Mod::get()->getSavedValue("labels-config"); + + for (auto child : cfg) + { + auto obj = child.as_object(); + + auto mod = new LabelModule("", ""); + mod->name = obj["name"].as_string(); + mod->format = obj["format"].as_string(); + mod->setFont(obj["font"].as_string()); + mod->setSide(as(obj["side"].as_int())); + mod->setOpacity(obj["opacity"].as_double()); + mod->setScale(obj["scale"].as_double()); + + modules.push_back(mod); + } + } +} + +void Labels::saveConfig() +{ + +} diff --git a/src/CustomWindows/Labels.h b/src/CustomWindows/Labels.h index 20a3d55..877f7b8 100644 --- a/src/CustomWindows/Labels.h +++ b/src/CustomWindows/Labels.h @@ -2,6 +2,7 @@ #include "../Client/Client.h" #include "../Labels/Labels.h" +#include "../Labels/LabelModule.hpp" class Labels : public Window { @@ -10,15 +11,19 @@ class Labels : public Window { name = "Labels"; id = "labels-window"; + + loadConfig(); } std::vector labels = {}; + TextArea* error; void cocosCreate(CCMenu* menu); void onHide(CCObject*); - void onToggleLabel(CCObject* sender); - void onLabelOptions(CCObject* sender); + + void loadConfig(); + void saveConfig(); }; \ No newline at end of file diff --git a/src/Hacks/SafeMode/SafeMode.cpp b/src/Hacks/SafeMode/SafeMode.cpp index f7a5858..01d7d43 100644 --- a/src/Hacks/SafeMode/SafeMode.cpp +++ b/src/Hacks/SafeMode/SafeMode.cpp @@ -97,7 +97,6 @@ void SafeMode::updateIndicator() a->update(1); a->reorderSides(); - a->reorderPosition(); } #endif diff --git a/src/Labels/LabelModule.cpp b/src/Labels/LabelModule.cpp index 7345ddb..32a2dfa 100644 --- a/src/Labels/LabelModule.cpp +++ b/src/Labels/LabelModule.cpp @@ -1,6 +1,68 @@ #include "LabelModule.hpp" +#include "Labels.h" -LabelModule::LabelModule(std::string format) +LabelModule::LabelModule(std::string format, std::string font) { this->format = format; -} \ No newline at end of file + this->font = font; +} + +void LabelModule::setFont(std::string newFont) +{ + this->font = newFont; + + if (labelNode) + labelNode->setFntFile(getFont().c_str()); +} + +std::string LabelModule::getFont() +{ + return CCFileUtils::sharedFileUtils()->isFileExist(CCFileUtils::sharedFileUtils()->fullPathForFilename(font.c_str(), false)) ? font : "bigFont.fnt"; +} + +void LabelModule::setScale(float newScale) +{ + this->scale = newScale; + + if (labelNode) + { + labelNode->setScale(newScale * 0.5f); + labelNode->getParent()->updateLayout(); + } +} + +float LabelModule::getScale() +{ + return scale; +} + +void LabelModule::setOpacity(float newOpacity) +{ + this->opacity = newOpacity; + + if (labelNode) + { + labelNode->setScale(newOpacity * 255); + labelNode->getParent()->updateLayout(); + } +} + +float LabelModule::getOpacity() +{ + return opacity; +} + +void LabelModule::setSide(LabelSide newSide) +{ + this->side = newSide; + + if (StatusNode::get()) + { + StatusNode::get()->reorderSides(); + } +} + +LabelSide LabelModule::getSide() +{ + return side; +} diff --git a/src/Labels/LabelModule.hpp b/src/Labels/LabelModule.hpp index 2b536ee..2950bd9 100644 --- a/src/Labels/LabelModule.hpp +++ b/src/Labels/LabelModule.hpp @@ -5,10 +5,38 @@ using namespace geode::prelude; +enum LabelSide +{ + TopLeft, + TopRight, + BottomLeft, + BottomRight, + BottomCenter, +}; + class LabelModule : public Module { + private: + float scale = 1; + float opacity = 1; + std::string font = "bigFont.fnt"; + LabelSide side = LabelSide::TopLeft; + public: + CCLabelBMFont* labelNode; std::string format; - LabelModule(std::string format); + LabelModule(std::string format, std::string font); + + void setFont(std::string newFont); + std::string getFont(); + + void setScale(float newScale); + float getScale(); + + void setOpacity(float newOpacity); + float getOpacity(); + + void setSide(LabelSide newSide); + LabelSide getSide(); }; \ No newline at end of file diff --git a/src/Labels/LabelNode.cpp b/src/Labels/LabelNode.cpp index 8c22f4b..4ed2eb4 100644 --- a/src/Labels/LabelNode.cpp +++ b/src/Labels/LabelNode.cpp @@ -1,4 +1,5 @@ #include "LabelNode.hpp" +#include "Labels.h" LabelNode* LabelNode::create(LabelModule* module) { @@ -16,10 +17,14 @@ LabelNode* LabelNode::create(LabelModule* module) bool LabelNode::init(LabelModule* module) { - if (!CCLabelBMFont::initWithString("", "bigFont.fnt")) + if (!CCLabelBMFont::initWithString("", module->getFont().c_str())) return false; this->module = module; + module->labelNode = this; + + this->setScale(module->getScale() * 0.5f); + this->setOpacity(module->getOpacity() * 255); return true; } @@ -33,10 +38,15 @@ void LabelNode::update(float delta) return this->setString("Error Compiling Script"); } - script->setVariable("number", 210); + script->setVariable("fps", StatusNode::get()->fps); script->setVariable("name", "World"); auto res = script->run(); this->setString(res.c_str()); +} + +LabelNode::~LabelNode() +{ + module->labelNode = nullptr; } \ No newline at end of file diff --git a/src/Labels/LabelNode.hpp b/src/Labels/LabelNode.hpp index 9e3f0d7..2e2994c 100644 --- a/src/Labels/LabelNode.hpp +++ b/src/Labels/LabelNode.hpp @@ -11,9 +11,10 @@ class LabelNode : public CCLabelBMFont { public: LabelModule* module; - rift::Script* script; + rift::Script* script; static LabelNode* create(LabelModule* module); + ~LabelNode(); bool init(LabelModule* module); diff --git a/src/Labels/Labels.cpp b/src/Labels/Labels.cpp index 3b74b8e..5cc3084 100644 --- a/src/Labels/Labels.cpp +++ b/src/Labels/Labels.cpp @@ -15,35 +15,54 @@ bool StatusNode::init() topLeft = CCMenu::create(); topLeft->ignoreAnchorPointForPosition(false); + topLeft->setAnchorPoint(ccp(0, 1)); + topLeft->setPosition(CCDirector::get()->getWinSize() * ccp(0, 1) + ccp(2, 0)); + topLeft->setLayout(getLayout()); topLeft->setID("top-left"); - this->addChild(topLeft); topRight = CCMenu::create(); topRight->ignoreAnchorPointForPosition(false); + topRight->setAnchorPoint(ccp(1, 1)); + topRight->setPosition(CCDirector::get()->getWinSize() * ccp(1, 1) + ccp(-2, 0)); + topRight->setLayout(getLayout()->setCrossAxisAlignment(AxisAlignment::End)->setCrossAxisLineAlignment(AxisAlignment::End)); topRight->setID("top-right"); - this->addChild(topRight); bottomLeft = CCMenu::create(); bottomLeft->ignoreAnchorPointForPosition(false); + bottomLeft->setAnchorPoint(ccp(0, 0)); + bottomLeft->setPosition(ccp(2, 2)); + bottomLeft->setLayout(getLayout()->setAxisReverse(false)->setAxisAlignment(AxisAlignment::Start)); bottomLeft->setID("bottom-left"); - this->addChild(bottomLeft); bottomRight = CCMenu::create(); bottomRight->ignoreAnchorPointForPosition(false); + bottomRight->setAnchorPoint(ccp(1, 0)); + bottomRight->setPosition(CCDirector::get()->getWinSize() * ccp(1, 0) + ccp(-2, 2)); + bottomRight->setLayout(getLayout()->setAxisReverse(false)->setAxisAlignment(AxisAlignment::Start)->setCrossAxisAlignment(AxisAlignment::End)->setCrossAxisLineAlignment(AxisAlignment::End)); bottomRight->setID("bottom-right"); - this->addChild(bottomRight); - hidden = Mod::get()->getSavedValue("hide-labels"); + bottomCenter = CCMenu::create(); + bottomCenter->ignoreAnchorPointForPosition(false); + bottomCenter->setAnchorPoint(ccp(0.5f, 0)); + bottomCenter->setPosition(CCDirector::get()->getWinSize() * ccp(0.5f, 0) + ccp(0, 2)); + bottomCenter->setLayout(getLayout()->setAxisReverse(false)->setAxisAlignment(AxisAlignment::Start)->setCrossAxisAlignment(AxisAlignment::Center)->setCrossAxisLineAlignment(AxisAlignment::Center)); + bottomCenter->setID("bottom-center"); - labels.push_back(LabelNode::create(new LabelModule("Test #{number * 2}, Hello {name}!"))); - topLeft->addChild(labels[0]); + hidden = Mod::get()->getSavedValue("hide-labels"); - update(1.0f); - updateVis(); + for (auto label : window->modules) + { + labels.push_back(LabelNode::create(as(label))); + } reorderSides(); - reorderPosition(); + update(1.0f); + this->addChild(topLeft); + this->addChild(topRight); + this->addChild(bottomLeft); + this->addChild(bottomRight); + this->addChild(bottomCenter); return true; } @@ -68,7 +87,7 @@ StatusNode* StatusNode::get() void StatusNode::update(float dt) { - auto timeScale = CCScheduler::get()->getTimeScale() / SpeedhackTop::instance->getFloatValue(); + auto timeScale = CCScheduler::get()->getTimeScale() / (SpeedhackEnabled::instance->enabled ? SpeedhackTop::instance->getFloatValue() : 1); _timeLeft -= dt / timeScale; _accum += 1 / (dt / timeScale); @@ -86,37 +105,75 @@ void StatusNode::update(float dt) { label->update(dt); } + + topLeft->updateLayout(); + topRight->updateLayout(); + bottomLeft->updateLayout(); + bottomRight->updateLayout(); + bottomCenter->updateLayout(); } -void StatusNode::updateVis() +void StatusNode::reorderSides() { + for (auto label : labels) + { + label->retain(); + } + + topLeft->removeAllChildren(); + topRight->removeAllChildren(); + bottomLeft->removeAllChildren(); + bottomRight->removeAllChildren(); + bottomCenter->removeAllChildren(); + for (auto label : labels) + { + getNodeForSide(label->module->getSide())->addChild(label); + + label->release(); + } } -void StatusNode::reorderSides() +CCNode* StatusNode::getNodeForSide(LabelSide side) { - + switch(side) + { + default: + return topLeft; + + case LabelSide::TopRight: + return topRight; + + case LabelSide::BottomLeft: + return bottomLeft; + + case LabelSide::BottomRight: + return bottomRight; + + case LabelSide::BottomCenter: + return bottomCenter; + } } -void StatusNode::reorderPosition() +AxisLayout* StatusNode::getLayout() { - + return AxisLayout::create()->setAxis(Axis::Column)->setAxisReverse(true)->setAxisAlignment(AxisAlignment::End)->setCrossAxisAlignment(AxisAlignment::Start)->setCrossAxisLineAlignment(AxisAlignment::Start)->setAutoScale(false)->setGap(1); } -class LabelModuleDelegate : public ModuleChangeDelegate +StatusNode::~StatusNode() { - virtual void onModuleChanged(bool enabled) + instance = nullptr; +} + +// delegate :3 + +void LabelModuleDelegate::onModuleChanged(bool enabled) +{ + if (PlayLayer::get(); auto stn = StatusNode::get()) { - if (PlayLayer::get()) - { - if (auto stn = StatusNode::get()) - { - stn->reorderSides(); - stn->reorderPosition(); - } - } + stn->reorderSides(); } -}; +} void StatusNode::postSetup(Window* wnd) { @@ -131,10 +188,7 @@ void StatusNode::postSetup(Window* wnd) } } -void StatusNode::updateCPS(float dt) -{ - -} +// hooks :3 void LabelPlayLayer::resetLevel() { diff --git a/src/Labels/Labels.h b/src/Labels/Labels.h index d083484..6f11418 100644 --- a/src/Labels/Labels.h +++ b/src/Labels/Labels.h @@ -21,11 +21,16 @@ class $modify (LabelPlayLayer, PlayLayer) void resetLevel(); }; +class LabelModuleDelegate : public ModuleChangeDelegate +{ + virtual void onModuleChanged(bool enabled); +}; + class StatusNode : public CCNode { private: static inline StatusNode* instance = nullptr; - float _updateInterval = 0.5f; + float _updateInterval = 0.1f; float _timeLeft = _updateInterval; float _accum; int _frames; @@ -36,11 +41,9 @@ class StatusNode : public CCNode static StatusNode* create(); static StatusNode* get(); - - ~StatusNode() - { - instance = nullptr; - } + + static void postSetup(Window* wnd); + ~StatusNode(); LabelPlayLayer* attPL = nullptr; @@ -48,9 +51,18 @@ class StatusNode : public CCNode CCMenu* topRight = nullptr; CCMenu* bottomLeft = nullptr; CCMenu* bottomRight = nullptr; + CCMenu* bottomCenter = nullptr; - static inline Window* window = nullptr; + bool init(); + + AxisLayout* getLayout(); + void reorderSides(); + + virtual void update(float dt); + CCNode* getNodeForSide(LabelSide side); + + static inline Window* window = nullptr; static inline bool hidden = false; std::vector cps; @@ -74,19 +86,6 @@ class StatusNode : public CCNode return formattedTime.str(); } - - - bool init(); - - void updateVis(); - - static void postSetup(Window* wnd); - - void reorderSides(); - void reorderPosition(); - - virtual void update(float dt); - void updateCPS(float dt); }; #endif \ No newline at end of file From 8d9fc6905c7b57c54f35cf82dbcc72717b85a8af Mon Sep 17 00:00:00 2001 From: Explodingbill Date: Sun, 28 Jul 2024 14:42:43 +1000 Subject: [PATCH 3/4] gh --- CMakeLists.txt | 2 +- src/Labels/Labels.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b73f69..02b79d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ foreach(MODULE ${MODULES_LIST}) endif() endforeach() -CPMAddPackage("gh:EclipseMenu/RIFT#327c270") # specify a commit! +CPMAddPackage("gh:EclipseMenu/RIFT#b00bf2b") # specify a commit! target_link_libraries(${PROJECT_NAME} rift) diff --git a/src/Labels/Labels.cpp b/src/Labels/Labels.cpp index e36f710..84b6147 100644 --- a/src/Labels/Labels.cpp +++ b/src/Labels/Labels.cpp @@ -196,6 +196,11 @@ void LabelPlayLayer::resetLevel() PlayLayer::resetLevel(); m_fields->attemptCount++; + + if (auto status = StatusNode::get()) + { + status->totalClicks = 0; + } } bool LabelPlayLayer::init(GJGameLevel* p0, bool p1, bool p2) @@ -242,14 +247,6 @@ class $modify (PlayerObject) } }*/ } - - void resetLevel() - { - PlayLayer::resetLevel(); - - if (StatusNode::get()) - StatusNode::get()->totalClicks = 0; - } }; #endif \ No newline at end of file From a7da52846917cf3739fa07e3508b84fd3f48e9a8 Mon Sep 17 00:00:00 2001 From: Explodingbill Date: Tue, 20 Aug 2024 16:19:35 +1000 Subject: [PATCH 4/4] hhhhhhh --- CMakeLists.txt | 2 +- src/Labels/LabelNode.cpp | 14 ++++++++------ src/Labels/Labels.cpp | 6 +++--- src/Labels/Labels.h | 3 --- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e8a1f5..bc70533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ foreach(MODULE ${MODULES_LIST}) endif() endforeach() -CPMAddPackage("gh:EclipseMenu/RIFT#b00bf2b") # specify a commit! +CPMAddPackage("gh:EclipseMenu/RIFT#c3f1c29") # specify a commit! target_link_libraries(${PROJECT_NAME} rift) diff --git a/src/Labels/LabelNode.cpp b/src/Labels/LabelNode.cpp index 4ed2eb4..a4ea560 100644 --- a/src/Labels/LabelNode.cpp +++ b/src/Labels/LabelNode.cpp @@ -31,19 +31,21 @@ bool LabelNode::init(LabelModule* module) void LabelNode::update(float delta) { - script = rift::compile(module->format); + auto res = rift::compile(module->format); + + script = res.unwrapOr(nullptr); if (!script) { - return this->setString("Error Compiling Script"); + return this->setString(fmt::format("Error Compiling Script: {}", res.getMessage()).c_str()); } - script->setVariable("fps", StatusNode::get()->fps); - script->setVariable("name", "World"); + script->setVariable("fps", rift::Value::integer(StatusNode::get()->fps)); + //script->setVariable("name", "World"); - auto res = script->run(); + auto res2 = script->run(); - this->setString(res.c_str()); + this->setString(res2.c_str()); } LabelNode::~LabelNode() diff --git a/src/Labels/Labels.cpp b/src/Labels/Labels.cpp index 0b83546..19a825e 100644 --- a/src/Labels/Labels.cpp +++ b/src/Labels/Labels.cpp @@ -1,8 +1,8 @@ #ifdef STATUS_TEXTS #include "Labels.h" -#include "../Hacks/Noclip/Noclip.hpp" #include "../Hacks/SafeMode/SafeMode.hpp" +#include "../Hacks/Noclip/Noclip.hpp" bool StatusNode::init() { @@ -257,7 +257,7 @@ class $modify (PlayerObject) } }; -void AttemptBaseGameLayer::resetLevelVariables() +/*void AttemptBaseGameLayer::resetLevelVariables() { if (LevelEditorLayer::get() ? !LevelEditorLayer::get()->m_editorUI->m_playtestStopBtn->isVisible() : true) m_fields->attemptCount++; @@ -268,6 +268,6 @@ void AttemptBaseGameLayer::resetLevelVariables() GJBaseGameLayer::resetLevelVariables(); SafeMode::get()->resetOnNewAttempt(); -} +}*/ #endif \ No newline at end of file diff --git a/src/Labels/Labels.h b/src/Labels/Labels.h index 722c28e..ee4b5fd 100644 --- a/src/Labels/Labels.h +++ b/src/Labels/Labels.h @@ -75,9 +75,6 @@ class StatusNode : public CCNode std::vector cps; int totalClicks = 0; - NoclipBaseGameLayer* noclipLayer = nullptr; - BestPlayLayer* bestRunPlayLayer = nullptr; - std::string formatTime(float time) { // Convert float time to milliseconds std::chrono::milliseconds duration(static_cast(time * 1000));