diff --git a/include/hooks.hpp b/include/hooks.hpp index cb8017e..0f90cf6 100644 --- a/include/hooks.hpp +++ b/include/hooks.hpp @@ -5,7 +5,7 @@ #pragma once #include "include.hpp" -#include "layer/MultiplayerLayer.hpp" +#include "layer/GDMPMultiplayerLayer.hpp" #include "utils.hpp" std::vector> functionQueue; @@ -44,7 +44,7 @@ class $modify(MenuLayer) { auto button = CCMenuItemSpriteExtra::create( buttonSprite, this, - menu_selector(MultiplayerLayer::switchToCustomLayerButton)); + menu_selector(GDMPMultiplayerLayer::switchToCustomLayerButton)); auto menu = cocos2d::CCMenu::create(); menu->addChild(button); @@ -57,8 +57,8 @@ class $modify(MenuLayer) { }; class $modify(PlayLayer) { - bool init(GJGameLevel* level) { - if (!PlayLayer::init(level)) return false; + bool init(GJGameLevel* level, bool p1, bool p2) { + if (!PlayLayer::init(level, p1, p2)) return false; auto global = Global::get(); @@ -92,9 +92,9 @@ class $modify(PlayLayer) { uint32_t secondaryColor = 0; // hope this works c: - if (this->m_player1->m_iconSprite) { + /*if (this->m_player1->m_iconSprite) { secondaryColor = getIntFromCCColor(this->m_player1->m_iconSprite->getColor()); - } + }*/ #endif color_p1.set_primary(getIntFromCCColor(this->m_player1->getColor())); @@ -131,9 +131,10 @@ class $modify(PlayLayer) { } void onQuit() { + fmt::print("onQuit\n"); auto global = Global::get(); for (auto &item: global->players) { - item.second.p1->removeMeAndCleanup(); + //item.second.p1->removeMeAndCleanup(); // THIS CRASHES IN 2.2 } global->players.clear(); @@ -178,7 +179,7 @@ class $modify(PlayLayer) { auto gameMode1 = getGameModeFromGamemode(getGamemodeFromPlayer(this->m_player1)); player_move->set_gamemode_p1(gameMode1); - if (this->m_player2 && this->m_isDualMode) { + if (this->m_player2 && /*this->m_isDualMode*/ false) { // todo auto pos2 = getPositionDataFromPlayer(this->m_player2); player_move->set_allocated_pos_p2(&pos2); @@ -201,22 +202,13 @@ class $modify(PlayLayer) { }; class $modify(GJBaseGameLayer) { - void pushButton(int i, bool pl) { - GJBaseGameLayer::pushButton(i, pl); - - auto global = Global::get(); - - if (pl) global->P1_pushing = true; - if (!pl) global->P2_pushing = true; - } - - void releaseButton(int i, bool pl) { - GJBaseGameLayer::releaseButton(i, pl); + void handleButton(bool push, int button, bool player1) { + GJBaseGameLayer::handleButton(push, button, player1); auto global = Global::get(); - if (pl) global->P1_pushing = false; - if (!pl) global->P2_pushing = false; + if (player1) global->P1_pushing = push; + if (!player1) global->P2_pushing = push; } }; diff --git a/include/layer/MultiplayerLayer.hpp b/include/layer/MultiplayerLayer.hpp deleted file mode 100644 index 8937333..0000000 --- a/include/layer/MultiplayerLayer.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * If you ever feel worthless, remember that I am more worthless than you - */ - -#pragma once - -#include "global.hpp" -#include "include.hpp" - -using namespace geode::prelude; - -struct Room { - bool isPrivate; - std::string roomCode; - bool passProtected; - - int playerCapacity; - int currentPlayers; - - int levelID; - std::string hostName; - std::string roomName; -}; - -class MultiplayerLayer : public cocos2d::CCLayer { -protected: - virtual bool init(); - - virtual void update(float); - - virtual void keyBackClicked(); - - void backButtonCallback(cocos2d::CCObject*); - - void connectButtonCallback(cocos2d::CCObject*); - - void disconnectButtonCallback(cocos2d::CCObject*); - - cocos2d::CCArray* getRoomListing(); - - cocos2d::CCLabelBMFont* connectionStatus; - CCTextInputNode* ipInput; - CCTextInputNode* portInput; - - Room currentRoom; - -public: - static MultiplayerLayer* create(); - - void switchToCustomLayerButton(cocos2d::CCObject*); -}; - -class RoomListCell : public CCLayer, public FLAlertLayerProtocol { -protected: - float m_width; - float m_height; - CCLayer* m_layer; - - bool init(CCLayer* layer, CCSize const& size); - - void draw() override; -}; - -class RoomCell : public RoomListCell { -protected: - Room roomInfo; - CCLabelBMFont* roomName; - CCLabelBMFont* hostName; - CCLayer* theLayer; - - MultiplayerLayer* theOriginalLayer; - - bool init(Room info, MultiplayerLayer* originalLayer, CCSize const& size, bool selected); - - virtual void FLAlert_Clicked(FLAlertLayer*, bool btn2); - -public: - static RoomCell* create(Room info, MultiplayerLayer* originalLayer, CCSize const& size, bool selected); - - void onSet(CCObject*); - - void deleteSong(CCObject*); -}; - -class RoomPage : public FLAlertLayer { -public: - CCLabelBMFont* m_path_label; - Room room; - - static RoomPage* create(Room roomInfo, int state); - - bool init(Room roomInfo, int state); -}; \ No newline at end of file diff --git a/mod.json b/mod.json index 8179183..63f8784 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "v1.0.0", + "geode": "v2.0.0", "version": "v0.0.0", "id": "rooot.gdmp", "name": "gdmp", diff --git a/proto b/proto index e720d91..37719cc 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit e720d91f23deb58d856b6ae53a51b0a3fb86b85b +Subproject commit 37719cc46e82a183bf642608c281d9fa2d5bde97 diff --git a/src/layer/MultiplayerLayer.cpp b/src/layer/MultiplayerLayer.cpp deleted file mode 100644 index 853b0fb..0000000 --- a/src/layer/MultiplayerLayer.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * When people ask "why did you make this mod?", I tell 'em, "for fun" - */ - -#include "layer/MultiplayerLayer.hpp" - -using namespace geode::prelude; - -// TODO: Rewrite this entire thing - -void MultiplayerLayer::disconnectButtonCallback(CCObject* object) { - auto global = Global::get(); - - if (global->peer) return enet_peer_disconnect(global->peer, 0); -} - -void MultiplayerLayer::connectButtonCallback(CCObject* object) { - auto global = Global::get(); - - if (global->peer) enet_peer_disconnect(global->peer, 0); - - ENetAddress addr; - enet_address_set_host(&addr, "rooot.gay"); - addr.port = std::stoi("34154"); - - global->peer = enet_host_connect(global->host, &addr, 1, 0); - if (!global->peer) { - Notification::create("Failed to connect to the server!", NotificationIcon::Error)->show(); - return; - }; -} - -cocos2d::CCArray* MultiplayerLayer::getRoomListing() { - cocos2d::CCArray* array = cocos2d::CCArray::create(); - array->addObject(RoomCell::create( - {false, "i dont know", false, 10, 10, 736, "ninXout", "a room thats full"}, this, {400, 68}, false - )); - array->addObject(RoomCell::create( - {false, "i dont know", false, 10, 4, 166, "ninXout", "a room that isn't full"}, this, {400, 68}, false - )); - return array; -} - -MultiplayerLayer* MultiplayerLayer::create() { - auto ret = new MultiplayerLayer(); - if (ret && ret->init()) { - ret->autorelease(); - return ret; - } - CC_SAFE_DELETE(ret); - return nullptr; -} - -bool MultiplayerLayer::init() { - if (!CCLayer::init()) return false; - - auto global = Global::get(); - - auto director = CCDirector::get(); - auto winSize = director->getWinSize(); - - auto cells = this->getRoomListing(); - - auto listLayer = CCLayer::create(); - auto list = ListView::create(cells, 60, 400, 190); - - list->setPositionY(-10.f); - - auto sideLeft = CCSprite::createWithSpriteFrameName("GJ_table_side_001.png"); - sideLeft->setAnchorPoint(ccp(0, 0)); - sideLeft->setScaleY(2.475f); - sideLeft->setScaleX(1.2f); - sideLeft->setPosition({-30, 24}); - sideLeft->setZOrder(9); - - auto sideTop = CCSprite::createWithSpriteFrameName("GJ_table_top02_001.png"); - sideTop->setAnchorPoint(ccp(0, 0)); - sideTop->setScaleX(1.15f); - sideTop->setScaleY(1.5f); - sideTop->setPosition(ccp(-29.f, 164.f)); - sideTop->setZOrder(9); - - auto sideBottom = CCSprite::createWithSpriteFrameName("GJ_table_bottom_001.png"); - // sideBottom->setFlipY(true); - sideBottom->setAnchorPoint(ccp(0, 0)); - sideBottom->setPosition(ccp(-24.f, -17.f)); - sideBottom->setScaleX(1.14f); - sideBottom->setZOrder(10); - - auto sideRight = CCSprite::createWithSpriteFrameName("GJ_table_side_001.png"); - sideRight->setFlipX(true); - sideRight->setScaleY(2.475f); - sideRight->setScaleX(1.2f); - sideRight->setAnchorPoint(ccp(0, 0)); - sideRight->setPosition({389, 22}); - sideRight->setZOrder(9); - - listLayer->addChild(sideLeft); - listLayer->addChild(sideTop); - listLayer->addChild(sideBottom); - listLayer->addChild(sideRight); - listLayer->addChild(list); - listLayer->setPosition(winSize / 2 - list->getScaledContentSize() / 2); - addChild(listLayer); - - auto label = CCLabelBMFont::create("Multiplayer", "goldFont.fnt"); - label->setPosition(ccp(director->getWinSize().width / 2, director->getWinSize().height - 25)); - addChild(label); - - /* - auto ipLabel = CCLabelBMFont::create("IP", "bigFont.fnt"); - ipLabel->setPosition(ccp((director->getWinSize().width / 2) - 150, - (director->getWinSize().height / 2) + 50)); - addChild(ipLabel); - - auto portLabel = CCLabelBMFont::create("Port", "bigFont.fnt"); - portLabel->setPosition(ccp((director->getWinSize().width / 2) + 150, - (director->getWinSize().height / 2) + 50)); - addChild(portLabel); - - ipInput = CCTextInputNode::create(100, 100, "Address", "bigFont.fnt"); - ipInput->setPosition(ccp((director->getWinSize().width / 2) - 150, - director->getWinSize().height / 2)); - ipInput->setAllowedChars("0123456789abcdefghijklmnopqrstuvwxyz.-"); - ipInput->setString("rooot.gay"); - addChild(ipInput); - - portInput = CCTextInputNode::create(100, 100, "Port", "bigFont.fnt"); - portInput->setPosition(ccp((director->getWinSize().width / 2) + 150, - director->getWinSize().height / 2)); - portInput->setAllowedChars("0123456789"); - portInput->setString("34154"); - addChild(portInput); - */ - - connectionStatus = CCLabelBMFont::create( - fmt::format("Status: {}", global->connected ? "Connected" : "Not connected").c_str(), - "bigFont.fnt" - ); - connectionStatus->setPosition( - ccp((director->getWinSize().width / 2), (director->getWinSize().height / 2) - 120) - ); - connectionStatus->setScaleX(0.5); - connectionStatus->setScaleY(0.5); - addChild(connectionStatus); - - auto disconnectButtonSprite = CCSprite::createWithSpriteFrameName("GJ_stopEditorBtn_001.png"); - - auto connectButtonSprite = CCSprite::createWithSpriteFrameName("GJ_playBtn2_001.png"); - connectButtonSprite->setScaleX(0.5); - connectButtonSprite->setScaleY(0.5); - - auto disconnectButton = CCMenuItemSpriteExtra::create( - disconnectButtonSprite, this, menu_selector(MultiplayerLayer::disconnectButtonCallback) - ); - - auto connectButton = CCMenuItemSpriteExtra::create( - connectButtonSprite, this, menu_selector(MultiplayerLayer::connectButtonCallback) - ); - - auto backButton = CCMenuItemSpriteExtra::create( - CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), - this, - menu_selector(MultiplayerLayer::backButtonCallback) - ); - - auto backgroundSprite = CCSprite::create("game_bg_01_001.png"); - auto backgroundSize = backgroundSprite->getContentSize(); - - backgroundSprite->setScaleX(winSize.width / backgroundSize.width); - backgroundSprite->setScaleY(winSize.height / backgroundSize.height); - backgroundSprite->setAnchorPoint({0, 0}); - backgroundSprite->setColor({40, 125, 255}); - - backgroundSprite->setZOrder(-1); - addChild(backgroundSprite); - - auto menu = CCMenu::create(); - menu->addChild(backButton); - menu->setPosition({25, winSize.height - 25}); - addChild(menu); - - menu = CCMenu::create(); - menu->addChild(connectButton); - menu->setPosition({(winSize.width / 2) - 50, winSize.height / 2 - 75}); - addChild(menu); - - menu = CCMenu::create(); - menu->addChild(disconnectButton); - menu->setPosition({(winSize.width / 2) + 50, winSize.height / 2 - 75}); - addChild(menu); - - setKeypadEnabled(true); - - scheduleUpdate(); - - return true; -} - -void exitMenu() { - CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade); -} - -void MultiplayerLayer::keyBackClicked() { - exitMenu(); -} - -void MultiplayerLayer::backButtonCallback(CCObject* object) { - exitMenu(); -} - -void MultiplayerLayer::switchToCustomLayerButton(CCObject* object) { - auto layer = MultiplayerLayer::create(); - auto scene = CCScene::create(); - scene->addChild(layer); - - CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene)); -} - -void MultiplayerLayer::update(float dt) { - auto global = Global::get(); - connectionStatus->setString( - fmt::format("Status: {}", global->connected ? "Connected" : "Not connected").c_str() - ); -} \ No newline at end of file diff --git a/src/layer/RoomCell.cpp b/src/layer/RoomCell.cpp index 059f397..b26bb00 100644 --- a/src/layer/RoomCell.cpp +++ b/src/layer/RoomCell.cpp @@ -1,4 +1,4 @@ -#include "layer/MultiplayerLayer.hpp" +#include "layer/GDMPMultiplayerLayer.hpp" bool RoomListCell::init(CCLayer* layer, CCSize const& size) { m_width = size.width; @@ -12,7 +12,7 @@ void RoomListCell::draw() { reinterpret_cast(this)->StatsCell::draw(); } -bool RoomCell::init(Room info, MultiplayerLayer* originalLayer, CCSize const& size, bool selected) { +bool RoomCell::init(Room info, GDMPMultiplayerLayer* originalLayer, CCSize const& size, bool selected) { if (!RoomListCell::init(originalLayer, size)) return false; this->roomInfo = info; @@ -103,7 +103,7 @@ bool RoomCell::init(Room info, MultiplayerLayer* originalLayer, CCSize const& si void RoomCell::onSet(CCObject* target) {} -RoomCell* RoomCell::create(Room info, MultiplayerLayer* originalLayer, CCSize const& size, bool selected) { +RoomCell* RoomCell::create(Room info, GDMPMultiplayerLayer* originalLayer, CCSize const& size, bool selected) { auto ret = new RoomCell(); if (ret && ret->init(info, originalLayer, size, selected)) { return ret; diff --git a/src/layer/RoomPage.cpp b/src/layer/RoomPage.cpp index fc2244e..d508214 100644 --- a/src/layer/RoomPage.cpp +++ b/src/layer/RoomPage.cpp @@ -1,4 +1,4 @@ -#include "layer/MultiplayerLayer.hpp" +#include "layer/GDMPMultiplayerLayer.hpp" static RoomPage* create(Room roomInfo, int state) { auto node = new RoomPage; diff --git a/src/main.cpp b/src/main.cpp index a54511e..0710a4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,30 +27,32 @@ using namespace geode::prelude; executeInGDThread([player_join]() { auto playLayer = GameManager::sharedState()->getPlayLayer(); + auto gameLayer = GameManager::sharedState()->getGameLayer(); if (!playLayer) return; + if (!gameLayer) return; const auto& visuals = player_join.visual(); - auto p1 = PlayerObject::create(1, 1, 0); - p1->setPosition({0, 105}); + auto p1 = PlayerObject::create(1, 1, gameLayer, gameLayer, false); // meow , (idk) + //p1->setPosition({0, 105}); // todo auto col_primary_p1 = visuals.colors().color_p1().primary(); auto col_secondary_p1 = visuals.colors().color_p1().secondary(); auto glowy = visuals.colors().glowy(); - p1->setColor(ccc3( + /*p1->setColor(ccc3( (col_primary_p1 >> 16) & 0xff, (col_primary_p1 >> 8) & 0xff, col_primary_p1 & 0xff - )); + ));*/ // todo p1->setSecondColor(ccc3( (col_secondary_p1 >> 16) & 0xff, (col_secondary_p1 >> 8) & 0xff, col_secondary_p1 & 0xff )); - p1->m_iconGlow->setVisible(glowy); + //p1->m_iconGlow->setVisible(glowy); // todo - playLayer->getObjectLayer()->addChild(p1); + playLayer->addChild(p1); // todo Player p{ p1, @@ -68,12 +70,8 @@ using namespace geode::prelude; p1->updatePlayerRollFrame(visuals.icon_ball()); p1->updatePlayerShipFrame(visuals.icon_ship()); p1->updatePlayerFrame(visuals.icon_cube()); - p1->updatePlayerRobotFrame(visuals.icon_robot()); -#if __APPLE__ && TARGET_OS_MAC - p1->updatePlayerSpiderFrame(visuals.icon_spider()); -#else - p1->m_spiderSprite->updateFrame(visuals.icon_spider()); -#endif + //p1->updatePlayerRobotFrame(visuals.icon_robot()); // todo + //p1->updatePlayerSpiderFrame(visuals.icon_spider()); // todo Global::get()->players[player_join.p_id()] = p; }); @@ -101,20 +99,21 @@ using namespace geode::prelude; auto iconType_p1 = getIconType(getGamemodeFromGameMode(player_move.gamemode_p1())); - p1->toggleFlyMode(iconType_p1 == IconType::Ship); - p1->toggleRollMode(iconType_p1 == IconType::Ball); - p1->toggleBirdMode(iconType_p1 == IconType::Ufo); - p1->toggleDartMode(iconType_p1 == IconType::Wave); - p1->toggleRobotMode(iconType_p1 == IconType::Robot); - p1->toggleSpiderMode(iconType_p1 == IconType::Spider); + // TODO: i have no idea what the 2nd bool does + p1->toggleFlyMode(iconType_p1 == IconType::Ship, false); + p1->toggleRollMode(iconType_p1 == IconType::Ball, false); + p1->toggleBirdMode(iconType_p1 == IconType::Ufo, false); + p1->toggleDartMode(iconType_p1 == IconType::Wave, false); + p1->toggleRobotMode(iconType_p1 == IconType::Robot, false); + p1->toggleSpiderMode(iconType_p1 == IconType::Spider, false); if (scale_p1 > 1.0f || scale_p1 < 0.0f) scale_p1 = 1.0f; executeInGDThread([pos_p1_x, pos_p1_y, rot_p1, scale_p1, button_p1, p1]() { auto global = Global::get(); - p1->setPosition({pos_p1_x, pos_p1_y}); - p1->setRotation(rot_p1); + //p1->setPosition({pos_p1_x, pos_p1_y}); // todo + //p1->setRotation(rot_p1); // todo p1->setScale(scale_p1); if (!global->P1_pushing && button_p1) { p1->pushButton(static_cast(1));