Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouca committed Jun 6, 2024
1 parent 0636c76 commit 8591240
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 148 deletions.
2 changes: 1 addition & 1 deletion src/MoreLeaderboards/MoreLeaderboardsCell.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MoreLeaderboardsCell.h"
#include <Geode/utils/web.hpp>

void MoreLeaderboardsCell::loadFromDict(cocos2d::CCDictionary* content) //
void MoreLeaderboardsCell::loadFromDict(cocos2d::CCDictionary* content)
{
auto winSize = CCDirector::sharedDirector()->getWinSize();
auto name = content->valueForKey("modstring")->getCString();
Expand Down
30 changes: 1 addition & 29 deletions src/Notifications/EventsPush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void EventsPush::onClickBtn(CCObject* ret) {
#else // mac os
int level_id = events_layer->levelId;
#endif
std::string const& fields = "secret=Wmfd2893gb7&gameVersion=22&type=0&binaryVersion=35&gdw=0&diff=-&len=-&count=1&str=" + std::to_string(level_id);
std::string const& fields = "secret=Wmfd2893gb7&type=0&str=" + std::to_string(level_id);

geode::utils::web::WebRequest request = web::WebRequest();
RUNNING_REQUESTS.emplace(
Expand Down Expand Up @@ -324,31 +324,12 @@ void EventsPush::onClickBtn(CCObject* ret) {
}
)
);

/*web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
.fetch(url).text()
.then([&](std::string & response) {
if (response != "-1") {
auto scene = CCScene::create();
auto layer = LevelInfoLayer::create(EventsPush::convertLevelToJSON(response), false);
layer->downloadLevel();
scene->addChild(layer);
CCDirector::sharedDirector()->pushScene(cocos2d::CCTransitionFade::create(0.5f, scene));
} else {
log::info("Level not found. (-1)");
}
}).expect([](std::string const& error) {
log::error("Error occured while doing a web request: {}", error);
});*/
} else { // copy to clipboard
#ifndef GEODE_IS_MACOS
clipboard::write(std::to_string(events_layer->level->m_levelID));
#else
clipboard::write(std::to_string(events_layer->levelId));
#endif
log::info("Copied ID to clipboard!");
}
}
bool EventsPush::init(sio::message::ptr const& data) {
Expand Down Expand Up @@ -436,10 +417,8 @@ bool EventsPush::init(sio::message::ptr const& data) {
return true;
}

log::debug("EventsPush::init");
auto director = CCDirector::sharedDirector();
auto winSize = director->getWinSize();
//auto label = CCSprite::createWithSpriteFrameName("GJ_checkOn_001.png");
auto bg = cocos2d::extension::CCScale9Sprite::create(sprite_name.c_str(), { .0f, .0f, 80.0f, 80.0f, });
auto bg_click_spr = cocos2d::extension::CCScale9Sprite::create(sprite_name.c_str(), { .0f, .0f, 80.0f, 80.0f, });
float lrScale = (float)Mod::get()->getSettingValue<double>("size");
Expand All @@ -457,7 +436,6 @@ bool EventsPush::init(sio::message::ptr const& data) {
menu->setPosition({ bg->getContentSize().width / 2, bg->getContentSize().height / 2 });
bg->addChild(menu);
this->addChild(bg);
//this->addChild(bg);

auto node = CCNode::create();

Expand Down Expand Up @@ -693,10 +671,7 @@ bool EventsPush::init(sio::message::ptr const& data) {
moveX = (bg->getContentSize().width) * lrScale;
break;
case 4: // bottom right
///bg->setPosition((winSize.width + (bg->getContentSize().width)) * lrScale, (bg->getContentSize().height / 2) * lrScale);
bg->setPosition({ winSize.width + ((bg->getContentSize().width / 2) * lrScale), (bg->getContentSize().height / 2) * lrScale});
//bg->setPosition((bg->getContentSize().width) * lrScale, (bg->getContentSize().height / 2) * lrScale);
//moveX = -(bg->getContentSize().width * lrScale);
moveX = -((bg->getContentSize().width) * lrScale);
break;
}
Expand All @@ -721,16 +696,13 @@ void EventsPush::stopNow(CCScene* scene) {
}

void EventsPush::pushRateLevel(CCScene* self, sio::message::ptr const& data) {
log::info("pushing rate level");
// Enqueue the event
eventQueue.push(data);

// If no event is being processed, start processing events
if (!processingEvents) {
EventsPush::processNextEvent(self);
}
//auto layer = EventsPush::create(data);
//self->addChild(layer);
}

void EventsPush::processNextEvent(CCScene* self) {
Expand Down
1 change: 0 additions & 1 deletion src/Secret/BadApple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ bool BadApple::init() {
player->setPosition(size.width / 2, size.height / 2);
player->setContentSize({ size.width - 40, size.height - 40 });
player->setZOrder(-1);
//reinterpret_cast<CCNode*>(layer->getChildren()->objectAtIndex(0))->setVisible(false);
this->addChild(player);
#endif
setKeypadEnabled(true);
Expand Down
20 changes: 0 additions & 20 deletions src/Settings/CreditsBetaMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ void CreditsBetaMenu::setup() {
setTouchEnabled(true);
setKeypadEnabled(true);
}
/*
void RedirectLink::goToURL(CCObject* ret) {
auto node = dynamic_cast<RedirectLink*>(ret);
if (node != nullptr) {
std::cout << node->redirectURI << std::endl;
}
}
RedirectLink* RedirectLink::createWithLink(std::string url, cocos2d::CCNode *sprite, cocos2d::CCObject *target) {
auto pRet = new RedirectLink(sprite, target, menu_selector(RedirectLink::goToURL));
if (pRet) {
pRet->redirectURI = url;
pRet->autorelease();
return pRet;
} else {
CC_SAFE_DELETE(pRet);
return nullptr;
}
}
*/

void CreditsBetaMenu::goToURL(CCObject* ret) {
auto node = reinterpret_cast<CCMenuItemSpriteExtra*>(ret);
Expand Down
13 changes: 0 additions & 13 deletions src/Settings/CreditsBetaMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,3 @@ class CreditsBetaMenu : public BrownAlertDelegate {
void nextPage(CCObject*);
void prevPage(CCObject*);
};
/*
class RedirectLink : public gd::CCMenuItemSpriteExtra {
std::string redirectURI;
public:
// i like and dislike inheritance, i cant even use redirectURI because "it doesnt exist in gd::CCMenuItemSpriteExtra", i mean its true but WHY
RedirectLink(CCNode* sprite, CCObject* target, SEL_MenuHandler callback) {
gd::CCMenuItemSpriteExtra::create(sprite, target, callback);
addChild(sprite);
}
void goToURL(CCObject*);
static RedirectLink* createWithLink(std::string url, cocos2d::CCNode *sprite, cocos2d::CCObject *target);
};
*/
3 changes: 0 additions & 3 deletions src/Settings/CustomSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,11 @@ class SettingAppNode : public SettingNode {
InputNode* defaultApp_input = InputNode::create(180.0F, "Application", "bigFont.fnt", "", 1);
void commit() override {
static_cast<SettingAppValue*>(m_value)->setApp(m_currentApp);
//if (m_resetBtn) m_resetBtn->setVisible(this->hasNonDefaultValue());
this->dispatchCommitted();
}
// Geode calls this to query if the setting value has been changed,
// and those changes haven't been committed
bool hasUncommittedChanges() override {
//if (m_resetBtn) m_resetBtn->setVisible(this->hasNonDefaultValue());
return m_currentApp != static_cast<SettingAppValue*>(m_value)->getApp();
}

Expand All @@ -541,7 +539,6 @@ class SettingAppNode : public SettingNode {
void resetToDefault() override {
m_currentApp = DEFAULT_APP;
static_cast<SettingAppValue*>(m_value)->setApp(m_currentApp);
//if (m_resetBtn) m_resetBtn->setVisible(false);
defaultApp_input->setString(DEFAULT_APP);
}
static SettingAppNode* create(SettingAppValue* value, float width) {
Expand Down
2 changes: 0 additions & 2 deletions src/Styles/IconLockColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class IconLockColors {
SimplePlayer* player = this->getPlayer(CCDirector::sharedDirector()->getRunningScene());
GameManager* gm = GameManager::sharedState();

log::info("Glow: {}", player->m_hasGlowOutline);

if (!player->m_hasGlowOutline) {
if (player->m_firstLayer->getColor() == gm->colorForIdx(gm->getPlayerColor2())) {
player->setGlowOutline(gm->colorForIdx(gm->getPlayerColor()));
Expand Down
6 changes: 1 addition & 5 deletions src/Utils/DemonList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class $modify(LevelInfoLayer) {
auto director = CCDirector::sharedDirector();
auto winSize = director->getWinSize();
auto demonSpr = CCSprite::createWithSpriteFrameName("diffIcon_06_btn_001.png");
//auto demonSpr = CCSprite::createWithSpriteFrameName("difficulty_06_btn_001.png");
demonSpr->setPosition({(winSize.width / 2) - 85, (winSize.height / 2) + 18});
demonSpr->setScale(0.5F);
auto positionLabel = CCLabelBMFont::create("N/A", "bigFont.fnt");
Expand Down Expand Up @@ -98,7 +97,6 @@ class $modify(LevelInfoLayer) {
}
loading_circle->setParentLayer(this);
loading_circle->show();
log::info("Sending a request to pointercrate...");
web::AsyncWebRequest()
.fetch(fmt::format("https://pointercrate.com/api/v2/demons/listed/?name={}", url_encode(level->m_levelName).c_str()))
.json()
Expand All @@ -107,8 +105,6 @@ class $modify(LevelInfoLayer) {
loading_circle->fadeAndRemove();
}
auto scene = CCDirector::sharedDirector()->getRunningScene();
//auto layer = misc::findNode("LevelInfoLayer");
//if (layer == nullptr) return;
if (json.dump() == "[]") { //idk how to check size, doing .count crashes
log::info("Level not found in pointercrate.");
this->release();
Expand Down Expand Up @@ -143,4 +139,4 @@ class $modify(LevelInfoLayer) {
return true;
}
};
// demon list
// demon list
9 changes: 1 addition & 8 deletions src/Utils/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
// ------
// 204 = MAX
// 0 = MIN
bool ProgressBar::init() { // on purpose im not even providing any params because why would we!?
//progressBar->setPosition({0, 200});
bool ProgressBar::init() { // on purpose im not even providing any params because why would we!?;
progressBar->setPosition({3, 8});
progressBar->setAnchorPoint({ 0, 0.5 });
//progressBar->setTextureRect(CCRect(0, 0, 200, 8));
progressBar->setTextureRect(CCRect(0, 0, 204, 8));
ccTexParams params = { GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT }; // tf is this nonsense mat
progressBar->getTexture()->setTexParameters(&params);
Expand Down Expand Up @@ -42,21 +40,17 @@ ProgressBar* ProgressBar::create() {
// ------
// credits https://stackoverflow.com/a/1639047
int DownloadManager::progress_func(void*, double totalDownload, double downloadAmount, double TotalToUpload, double NowUploaded) {
//std::cout << "progress_func(" << totalDownload << ", " << downloadAmount << ")" << std::endl;
if (totalDownload <= 0.0) return 0;
float amountDownloaded = round((downloadAmount / totalDownload) * 100);
auto scene = CCDirector::sharedDirector()->getRunningScene();
auto layer = reinterpret_cast<ProgressBar*>(reinterpret_cast<CCLayer*>(reinterpret_cast<CCLayer*>(scene->getChildByTag(6942084))->getChildren()->objectAtIndex(0))->getChildByTag(4592));
if (layer != nullptr) {
//std::cout << "Update progress " << amountDownloaded << "%" << std::endl;
layer->setProgress(amountDownloaded);
}
return 0;
}

void DownloadManager::setup() {
log::debug("DownloadManager::setup()");
//log::debug(m_sUrl);
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
loading_circle->setParentLayer(this);
loading_circle->setScale(0.675f);
Expand Down Expand Up @@ -88,7 +82,6 @@ void DownloadManager::setup() {
.fetch(this->m_sUrl)
.into(this->m_sDestination)
.then([this](auto) {
log::debug("dumpToFile");
ProcessLambdas::callMenuHandler(this, this->m_pSelector);
this->onClose(CCNode::create());
})
Expand Down
4 changes: 0 additions & 4 deletions src/Utils/SpotifyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,9 @@ void toggleSpotifyMute(bool automatic = false, bool muted = false) {
} else {
log::info("Unmuting Spotify...");
}
//std::wstring targetExeName = L"Spotify.exe";
std::wstring targetExeName = StringToWstring(Mod::get()->getSettingValue<SettingAppStruct>("spotifyApp").m_application);
log::info("Mute Application {}", Mod::get()->getSettingValue<SettingAppStruct>("spotifyApp").m_application);
DWORD processId = GetProcessIdByName(targetExeName);
if (processId) {
log::debug("Spotify process found (PID: {}", std::to_string(processId) + ").");
MuteAudioSessionByProcessId(processId, is_muted);
}
}
Expand Down Expand Up @@ -195,7 +192,6 @@ void MuteApplication() {
if (dotAppPos != std::string::npos) {
targetName.erase(dotAppPos, 4); // Remove the ".app" extension
}
log::info("Mute Application " + targetName);
// chat jippity, applescript is amazing, i wish i could do this on windows instead of having to do all of this IMM device stuff
std::string checkCommand = "osascript -e 'tell application \"System Events\" to (name of processes) contains \"" + targetName + "\"'";
if (isApplicationRunning(targetName)) { // will show a popup, also listen i am not responsible if some malicious user does stuff here regarding applescript. please consider disabling all spotify options if you dont want to be vulnerable, then again this would only happen if the attacker were to modify the .json file, which wouldnt they inject their own dylib file anyways? tldr; you are responsible if you install malware onto your mac system ok
Expand Down
62 changes: 0 additions & 62 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void start_socket_func() {
std::string currentLayer = "";
void processEvent(CCScene* self) {
if (!dataQueue.empty()) {
log::debug("process event");
auto data = dataQueue.front();
dataQueue.pop();
EventsPush::pushRateLevel(self, data);
Expand Down Expand Up @@ -233,7 +232,6 @@ class $modify(CCScheduler) { // GD Protocol part
)->show();
} else {
auto data = response->string().value();
log::debug("Data: {}", data);
if (data != "-1") {
auto scene = CCScene::create();

Expand Down Expand Up @@ -268,68 +266,13 @@ class $modify(CCScheduler) { // GD Protocol part
}
)
);

/*
web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
.fetch(url).text()
.then([&](std::string & response) {
if (response != "-1") {
auto scene = CCScene::create();
GJGameLevel* gjgl = EventsPush::convertLevelToJSON(response);
auto layer = LevelInfoLayer::create(gjgl, false);
layer->downloadLevel();
scene->addChild(layer);
CCDirector::sharedDirector()->pushScene(cocos2d::CCTransitionFade::create(0.5f, scene));
} else {
FLAlertLayer::create(nullptr,
"Error",
"Level not found.",
"OK",
nullptr,
180.0F
)->show();
}
}).expect([](std::string const& error) {
FLAlertLayer::create(nullptr,
"Error",
"An error happened when trying to fetch the level.",
"OK",
nullptr,
350.0F
)->show();
});*/
}
}
} catch (const std::exception& e) {}
}
};
#endif

// GDUtils online menu
/*class $modify(CreatorLayer) {
bool init() {
if (!CreatorLayer::init()) return false;
auto menu = CCMenu::create();
auto spr = CCSprite::create(Mod::get()->expandSpriteName("gdutils_badge.png"));
spr->setScale(.65f);
auto sprBtn = CCMenuItemSpriteExtra::create(
spr,
this,
nullptr
);
sprBtn->setPosition(262, -47);
menu->addChild(sprBtn);
this->addChild(menu);
return true;
}
};*/

// Backgrounds
class $modify(CCSprite) {
bool isGradient;
Expand All @@ -355,10 +298,6 @@ class $modify(CCSprite) {

// Child background
class $modify(CCScale9Sprite) {
/*
cocos2d::extension::CCScale9Sprite::create
("square02b_001.png",(CCRect)(CCSize *)&local_44);
*/
static cocos2d::extension::CCScale9Sprite* create(char const* name, CCRect rect) {
auto ret = cocos2d::extension::CCScale9Sprite::create(name, rect);
if (ret == nullptr) return ret;
Expand Down Expand Up @@ -466,7 +405,6 @@ class $modify(CCScale9Sprite) {
#else
Mod::get()->addCustomSetting<SettingAppValue>("spotifyApp", "Spotify.app");
#endif
//Mod::get()->addCustomSetting<class T>(const std::string &key, "Spotify.exe");
Mod::get()->addCustomSetting<SettingCreditsValue>("credit-buttons", "none");

#ifdef GEODE_IS_WINDOWS
Expand Down

0 comments on commit 8591240

Please sign in to comment.