Skip to content

Commit

Permalink
TODO : Mod badge interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouca committed Jan 16, 2024
1 parent 008101e commit 8c39965
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NewProfilePage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "NewProfilePage.h"

void NewProfilePage::onBadgePressed(CCObject* pSender) {
return;
}
10 changes: 10 additions & 0 deletions src/NewProfilePage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <iostream>

using namespace cocos2d;
using namespace geode::prelude;

class NewProfilePage : public CCLayer {
public:
void onBadgePressed(CCObject* pSender);
};
14 changes: 14 additions & 0 deletions src/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ using namespace geode::prelude;
#include <synchapi.h>
#endif

#define public_cast(value, member) [](auto* v) { \
class FriendClass__; \
using T = std::remove_pointer<decltype(v)>::type; \
class FriendeeClass__: public T { \
protected: \
friend FriendClass__; \
}; \
class FriendClass__ { \
public: \
auto& get(FriendeeClass__* v) { return v->member; } \
} c; \
return c.get(reinterpret_cast<FriendeeClass__*>(v)); \
}(value)

class misc {
public:
// theres no including Geode Util class funcs so, https://github.com/geode-sdk/DevTools
Expand Down
59 changes: 59 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Geode/modify/LeaderboardsLayer.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>
#include <Geode/modify/InfoLayer.hpp>
#include <Geode/modify/ProfilePage.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/utils/web.hpp>
#include "includes.h"
Expand All @@ -19,6 +20,7 @@
#include "ProcessLambdas.h"
#include "MoreLeaderboards.h"
#include "InfoNewLayer.h"
#include "NewProfilePage.h"
#include "Discord.h"
#include <fmt/format.h>
#include <chrono>
Expand Down Expand Up @@ -1020,6 +1022,9 @@ class $modify(InfoLayer) {
bool init(GJGameLevel* level, GJUserScore* userscore, GJLevelList* levellist) {
if (!InfoLayer::init(level, userscore, levellist)) return false;

// Check if it's InfoLayer for level
if (level == nullptr) return true;

std::string levelID = std::to_string(level->m_levelID.value());

auto menu = this->m_buttonMenu;
Expand All @@ -1037,6 +1042,60 @@ class $modify(InfoLayer) {
}
};

// Mod badges descriptions
class $modify(ProfilePage) {
void loadPageFromUserInfo(GJUserScore* a2) {
ProfilePage::loadPageFromUserInfo(a2);

auto scene = CCDirector::sharedDirector()->getRunningScene();
if(auto layer = m_mainLayer) {
// inspecting all children of the layer to find the badge
CCSprite* badge = nullptr;
CCObject* obj = nullptr;
CCARRAY_FOREACH(layer->getChildren(), obj) {
auto sprite = dynamic_cast<CCSprite*>(obj);
if (sprite == nullptr) continue;

auto* texture = sprite->getTexture();
auto* frame_cache = CCSpriteFrameCache::sharedSpriteFrameCache();
auto* cached_frames = public_cast(frame_cache, frame_cache->m_pSpriteFrames);
const auto rect = sprite->getTextureRect();
CCDictElement* el = nullptr;
CCDICT_FOREACH(cached_frames, el) {
auto* frame = static_cast<CCSpriteFrame*>(el->getObject());
if (frame->getTexture() == texture && frame->getRect() == rect) {
if (el->getStrKey() == "modBadge_01_001.png" || el->getStrKey() == "modBadge_02_001.png" || el->getStrKey() == "modBadge_03_001.png") {
badge = sprite;
break;
}
}
}
}

if (badge != nullptr) {
CCMenu* menu = nullptr;
CCObject* obj2 = nullptr;
CCARRAY_FOREACH(layer->getChildren(), obj2) {
auto menu_ = dynamic_cast<CCMenu*>(obj2);
if (menu_ != nullptr) {
menu = menu_;
break;
}
}

auto badgeBtn = CCMenuItemSpriteExtra::create(
badge,
this,
menu_selector(NewProfilePage::onBadgePressed)
);
CCPoint pos = badge->getPosition();
badgeBtn->setPosition(pos);
menu->addChild(badgeBtn);
}
}
}
};

// When the socket connection is made
$on_mod(Loaded) {
log::info("GDUtils Mod Loaded");
Expand Down

0 comments on commit 8c39965

Please sign in to comment.