From be4e5639934e6db2f00cb69d5c9edbf88c6c566a Mon Sep 17 00:00:00 2001 From: poweredbypie <67135060+poweredbypie@users.noreply.github.com> Date: Fri, 19 Feb 2021 16:56:05 -0800 Subject: [PATCH] FLAlertLayer, borders, and memory fix - uses FLAlertLayer when refreshing packs! - borders on sides of my scene - fixes XMLDocument allocating not enough space, leading to access violations (serves me right for doing hacky things, i guess) --- include/cocos2d.h | 17 ++++++++- include/gd.h | 60 +++++++++++++++++++++++++---- src/classes/list.cpp | 13 +++---- src/classes/options.cpp | 3 +- src/ldr.cpp | 83 ++++++++++++++++++----------------------- src/ldr.h | 10 ++--- 6 files changed, 116 insertions(+), 70 deletions(-) diff --git a/include/cocos2d.h b/include/cocos2d.h index eb34e70..b6d6575 100644 --- a/include/cocos2d.h +++ b/include/cocos2d.h @@ -98,6 +98,11 @@ namespace cocos2d { } }; + class CCLayer : public CCNode { + public: + //idk + }; + class CCScene : public CCNode { public: static CCScene* create() { @@ -200,6 +205,16 @@ namespace cocos2d { FIND_EXPORT("?setScaleY@CCSprite@cocos2d@@UAEXM@Z") )(this, fScaleY); } + void setFlipX(bool bFlipX) { + return as( + FIND_EXPORT("?setFlipX@CCSprite@cocos2d@@QAEX_N@Z") + )(this, bFlipX); + } + void setFlipY(bool bFlipY) { + return as( + FIND_EXPORT("?setFlipY@CCSprite@cocos2d@@QAEX_N@Z") + )(this, bFlipY); + } CCSize getTextureSize() { return *as( as(this) + 0x13C @@ -275,7 +290,7 @@ namespace cocos2d { class XMLDocument : public XMLNode { public: static XMLDocument* create(bool processEntities, int whitespaceMode) { - XMLDocument* pRet = as(new char[0x170]); + XMLDocument* pRet = as(new char[0x174]); if (pRet) { pRet->constructor(processEntities, whitespaceMode); } diff --git a/include/gd.h b/include/gd.h index c1d11cd..fcf5c7e 100644 --- a/include/gd.h +++ b/include/gd.h @@ -14,15 +14,19 @@ namespace gd { base + 0xC4A50 )(); } - void reloadAll(bool bSwitch, bool bFullscreen, bool bReloadedInSession) { return as( base + 0xCE950 )(this, bSwitch, bFullscreen, bReloadedInSession); } + void setQuality(cocos2d::TextureQuality quality) { + *reinterpret_cast( + reinterpret_cast(this) + 0x2E4 + ) = quality; + } }; - class MenuLayer : public cocos2d::CCScene { + class MenuLayer : public cocos2d::CCLayer { public: static inline auto pMoreGamesStr = as(base + 0x190EF2); static inline auto szMoreGamesBtn = as(base + 0x190F01); @@ -37,7 +41,6 @@ namespace gd { base + 0x190550 )(); } - static void fadeInMusic(const char* filename) { return as( base + 0xC4BD0 @@ -45,11 +48,22 @@ namespace gd { } }; + class LoadingLayer : public cocos2d::CCLayer { + public: + void setWillFadeIn(bool willFadeIn) { + *reinterpret_cast( + reinterpret_cast(this) + 0x138 + ) = willFadeIn; + } + }; + #pragma runtime_checks("s", off) class CCMenuItemSpriteExtra : public cocos2d::CCMenuItemSprite { public: - static CCMenuItemSpriteExtra* create(cocos2d::CCSprite* sprite, cocos2d::CCMenu* target, void(__stdcall* const callback)(void*)) { - auto pRet = as( + static CCMenuItemSpriteExtra* create(cocos2d::CCSprite* sprite, + cocos2d::CCMenu* target, void(__stdcall* const callback)(void*)) { + auto pRet = as( base + 0x18EE0 )(sprite, target, callback); //fix stack before returning @@ -69,11 +83,13 @@ namespace gd { * height - height of button. put 0 for auto. * scale - scale of the caption. */ - static ButtonSprite* create(const char* caption, int width, bool absolute, const char* font, const char* texture, float height, float scale) { + static ButtonSprite* create(const char* caption, int width, bool absolute, + const char* font, const char* texture, float height, float scale) { //scale is passed in lower 4 bytes of xmm3 __asm movss xmm3, scale //arg 3 is always 0. dunno why it's not optimized out as a param - auto pRet = as( + auto pRet = as( base + 0x137D0 )(caption, width, 0, absolute, font, texture, height); //clean stack before returning @@ -81,9 +97,37 @@ namespace gd { return pRet; } }; + + class FLAlertLayer : public cocos2d::CCLayer { + public: + /*FLAlertLayer supports colors of text for the caption. wrap desired text in "" + * where x is the color desired. colors are: + * r - red + * l - lime + * g - green + * y - yellow + * o - orange? + * and more that i'm too lazy to find. + */ + static FLAlertLayer* create(cocos2d::CCObject* target, const char* title, + const char* btn1, const char* btn2, std::string caption) { + static_assert(sizeof(std::string) == 24, "std::string in debug mode does not work correctly with FLAlertLayer!"); + auto pRet = as( + base + 0x22680 + )(target, title, btn1, btn2, caption); + //clean stack. + __asm add esp, 0x20 + } + void show() { + return as( + base + 0x23560 + )(this); + } + }; #pragma runtime_checks("s", restore) - class GJDropDownLayer : public cocos2d::CCNode { + class GJDropDownLayer : public cocos2d::CCLayer { public: static GJDropDownLayer* create(const char* title) { GJDropDownLayer* pRet = as(new char[0x1C0]()); diff --git a/src/classes/list.cpp b/src/classes/list.cpp index 718cce4..c879d3b 100644 --- a/src/classes/list.cpp +++ b/src/classes/list.cpp @@ -32,13 +32,12 @@ void list::update() { else { m_listLabels[0]->setString(m_listStrings[m_listOffset].c_str(), true); } - m_listLabels[0]->limitLabelWidth(115.0f, 0.0f, 0.0f); + m_listLabels[0]->limitLabelWidth(90.0f, 0.8f, 0.0f); } } void list::enter(cocos2d::CCScene* scene) { using namespace cocos2d; - using namespace gd; m_menu = CCMenu::create(); @@ -46,7 +45,7 @@ void list::enter(cocos2d::CCScene* scene) { m_titleLabel->setPosition(m_x, m_y + 30.0f); m_menu->addChild(m_titleLabel); - m_upBtn = CCMenuItemSpriteExtra::create( + m_upBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName(ARROW_PNG), m_menu, m_navFn @@ -55,7 +54,7 @@ void list::enter(cocos2d::CCScene* scene) { m_upBtn->setRotation(-180.0f); m_menu->addChild(m_upBtn); - m_downBtn = CCMenuItemSpriteExtra::create( + m_downBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName(ARROW_PNG), m_menu, m_navFn @@ -253,7 +252,6 @@ void listExt::updateLabels() { void listExt::updateSelector() { using namespace cocos2d; - using namespace gd; if (!m_entered) { m_moveBtn = CCMenuItemSprite::create( @@ -327,7 +325,6 @@ void listExt::updateSelector() { void listExt::enter(cocos2d::CCScene* scene) { using namespace cocos2d; - using namespace gd; m_menu = CCMenu::create(); @@ -335,7 +332,7 @@ void listExt::enter(cocos2d::CCScene* scene) { m_titleLabel->setPosition(m_x, m_y + 50.0f); m_menu->addChild(m_titleLabel); - m_upBtn = CCMenuItemSpriteExtra::create( + m_upBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName(ARROW_PNG), m_menu, m_navFn @@ -344,7 +341,7 @@ void listExt::enter(cocos2d::CCScene* scene) { m_upBtn->setRotation(-90.0f); m_menu->addChild(m_upBtn); - m_downBtn = CCMenuItemSpriteExtra::create( + m_downBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName(ARROW_PNG), m_menu, m_navFn diff --git a/src/classes/options.cpp b/src/classes/options.cpp index dea6d56..1b45222 100644 --- a/src/classes/options.cpp +++ b/src/classes/options.cpp @@ -2,10 +2,9 @@ #include "options.h" void options::enter(void* pSender) { - using namespace gd; using namespace cocos2d; - m_layer = GJDropDownLayer::create("Options"); + m_layer = gd::GJDropDownLayer::create("Options"); static_cast(pSender)->getParent()->addChild(m_layer); diff --git a/src/ldr.cpp b/src/ldr.cpp index 6a52bf9..564d22e 100644 --- a/src/ldr.cpp +++ b/src/ldr.cpp @@ -17,13 +17,13 @@ namespace ldr { } namespace hooks { - void COCOS_HOOK loadingFinished(cocos2d::CCScene* LoadingLayer) { - *reinterpret_cast(reinterpret_cast(LoadingLayer) + 0x138) = false; + void COCOS_HOOK loadingFinished(gd::LoadingLayer* This) { + This->setWillFadeIn(false); listManager::exit(); - return gates::loadingFinished(LoadingLayer); + return gates::loadingFinished(This); } - void COCOS_HOOK dataLoaded(cocos2d::CCObject* GameManager, void*, void* DS_Dictionary) { + void COCOS_HOOK dataLoaded(gd::GameManager* This, void*, void* DS_Dictionary) { using namespace cocos2d; using namespace vars; @@ -32,7 +32,7 @@ namespace ldr { fileUtils->removeAllPaths(); gates::addSearchPath(fileUtils, "Resources"); //call dataLoaded. - gates::dataLoaded(GameManager, DS_Dictionary); + gates::dataLoaded(This, DS_Dictionary); //add all of 'em back lol fileUtils->removeAllPaths(); for (std::string i : applied.getVector()) { @@ -46,15 +46,15 @@ namespace ldr { return gates::trySaveGame(AppDelegate); } - void COCOS_HOOK addSearchPath(cocos2d::CCFileUtils* CCFileUtils, void*, const char* path) { + void COCOS_HOOK addSearchPath(cocos2d::CCFileUtils* This, void*, const char* path) { using namespace vars; //to refresh menuLoop.mp3. gd::MenuLayer::fadeInMusic(" "); for (std::string i : applied.getVector()) { - gates::addSearchPath(CCFileUtils, ("packs/" + i).c_str()); + gates::addSearchPath(This, ("packs/" + i).c_str()); } - return gates::addSearchPath(CCFileUtils, path); + return gates::addSearchPath(This, path); } } @@ -123,43 +123,27 @@ namespace ldr { std::stringstream text = {}; if (added > 0 || removed > 0) { - text << added << ' ' << ((added == 1) ? "pack" : "packs") << " added.\n"; - text << removed << ' ' << ((removed == 1) ? "pack" : "packs") << " removed.\n"; + text << "" << added << " " << ((added == 1) ? "pack" : "packs") << " added.\n"; + //for some silly reason, color markers don't work directly after a newline! + //@robtop fix??? + text << " " << removed << " " << ((removed == 1) ? "pack" : "packs") << " removed.\n"; } else { - text << "Nothing changed!\n"; + text << "Nothing changed!\n"; } if (invalid > 0) { text << '\n'; if (invalid == 1) { - text << "1 pack had an invalid name, and was ignored.\n"; + text << "1 pack had an invalid name, and was ignored.\n"; } else { - text << invalid << " packs had invalid names, and were ignored.\n"; + text << invalid << " packs had invalid names, and were ignored.\n"; } } - auto label = CCLabelBMFont::create(text.str().c_str(), "goldFont.fnt"); - label->setScale(0.7f); - label->setAlignment(kCCTextAlignmentCenter); - label->setPosition(winSize.width / 2, winSize.height / 2 + 50.0f); - director->getRunningScene()->addChild(label); - - //workaround; idfk how va_arg functions work when compiled - auto arr = CCArray::create(); - arr->addObject(CCFadeIn::create(0.5f)); - arr->addObject(CCDelayTime::create(1.0f)); - arr->addObject(CCFadeOut::create(0.5f)); - arr->addObject(CCCallFunc::create( - label, - //this is a removeMeAndCleanup callback that rob setup so imma use it - reinterpret_cast(gd::base + 0x10A3A) - )); - //END workaround - - //change this to use CCSequence::create(CCObject*, ...) plz - label->runAction(CCSequence::create(arr)); + auto alert = gd::FLAlertLayer::create(nullptr, "Update", "OK", nullptr, text.str()); + alert->show(); } } @@ -168,37 +152,46 @@ namespace ldr { } BTN_CALLBACK(enterScene) { - using namespace gd; using namespace cocos2d; //create scene here auto director = CCDirector::sharedDirector(); - CCSize winSize = director->getWinSize(); + auto winSize = director->getWinSize(); auto ldrScene = CCScene::create(); auto bg = CCSprite::create("GJ_gradientBG.png"); auto bgSize = bg->getTextureSize(); bg->setAnchorPoint({ 0.0f, 0.0f }); - ldrScene->addChild(bg); bg->setScaleX((winSize.width + 10.0f) / bgSize.width); bg->setScaleY((winSize.height + 10.0f) / bgSize.height); bg->setPosition(-5.0f, -5.0f); bg->setColor({ 0, 102, 255 }); + ldrScene->addChild(bg); + auto bottomLeft = CCSprite::createWithSpriteFrameName("GJ_sideArt_001.png"); + auto cornerSize = bottomLeft->getTextureSize(); + bottomLeft->setPosition(cornerSize.width / 2, cornerSize.height / 2); + auto bottomRight = CCSprite::createWithSpriteFrameName("GJ_sideArt_001.png"); + bottomRight->setFlipX(true); + bottomRight->setPosition(winSize.width - cornerSize.width / 2, cornerSize.height / 2); + ldrScene->addChild(bottomLeft); + ldrScene->addChild(bottomRight); + listManager::enter(ldrScene); + //buttons auto miscBtns = CCMenu::create(); ldrScene->addChild(miscBtns); - CCMenuItemSpriteExtra* applyBtn = CCMenuItemSpriteExtra::create( - ButtonSprite::create("Apply", 0, false, "goldFont.fnt", "GJ_button_01.png", 0.0f, 1.0f), + auto applyBtn = gd::CCMenuItemSpriteExtra::create( + gd::ButtonSprite::create("Apply", 0, false, "goldFont.fnt", "GJ_button_01.png", 0.0f, 1.0f), miscBtns, apply ); + applyBtn->setPosition(0.0f, 0.0f); miscBtns->addChild(applyBtn); - //miscBtns->addChild(CCSprite::createWithSpriteFrameName("GJ_completesIcon_001.png")); - auto backBtn = CCMenuItemSpriteExtra::create( + auto backBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), miscBtns, exitScene @@ -206,7 +199,7 @@ namespace ldr { backBtn->setPosition(-winSize.width / 2 + 25.0f, winSize.height / 2 - 25.0f); miscBtns->addChild(backBtn); - auto reloadBtn = CCMenuItemSpriteExtra::create( + auto reloadBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName("GJ_updateBtn_001.png"), miscBtns, getPacks @@ -214,7 +207,7 @@ namespace ldr { reloadBtn->setPosition(winSize.width / 2 - 35.0f, -winSize.height / 2 + 35.0f); miscBtns->addChild(reloadBtn); - auto optionsBtn = CCMenuItemSpriteExtra::create( + auto optionsBtn = gd::CCMenuItemSpriteExtra::create( CCSprite::createWithSpriteFrameName("GJ_optionsBtn_001.png"), miscBtns, onOptions @@ -227,12 +220,11 @@ namespace ldr { BTN_CALLBACK(exitScene) { using namespace cocos2d; - using namespace gd; using namespace vars; listManager::exit(); - auto menuLayer = MenuLayer::create(); + auto menuLayer = gd::MenuLayer::create(); auto menuLayerScene = CCScene::create(); menuLayerScene->addChild(menuLayer); @@ -248,8 +240,7 @@ namespace ldr { director->updateContentScale(static_cast(quality.getCurrentIndex() + 1)); auto GameManager = gd::GameManager::sharedState(); - *reinterpret_cast - (reinterpret_cast(GameManager) + 0x2E4) = quality.getCurrentIndex() + 1; + GameManager->setQuality(static_cast(quality.getCurrentIndex() + 1)); GameManager->reloadAll(false, false, true); } diff --git a/src/ldr.h b/src/ldr.h index a635fcc..d26568d 100644 --- a/src/ldr.h +++ b/src/ldr.h @@ -8,17 +8,17 @@ namespace ldr { namespace gates { - inline void(__thiscall* loadingFinished)(cocos2d::CCScene*); - inline void(__thiscall* dataLoaded)(cocos2d::CCObject*, void*); + inline void(__thiscall* loadingFinished)(gd::LoadingLayer*); + inline void(__thiscall* dataLoaded)(gd::GameManager*, void*); inline void(__thiscall* trySaveGame)(cocos2d::CCObject*); inline void(__thiscall* addSearchPath)(cocos2d::CCFileUtils*, const char*); } namespace hooks { - void COCOS_HOOK loadingFinished(cocos2d::CCScene* LoadingLayer); - void COCOS_HOOK dataLoaded(cocos2d::CCObject* GameManager, void*, void* DS_Dictionary); + void COCOS_HOOK loadingFinished(gd::LoadingLayer* This); + void COCOS_HOOK dataLoaded(gd::GameManager* This, void*, void* DS_Dictionary); void COCOS_HOOK trySaveGame(cocos2d::CCObject* AppDelegate); - void COCOS_HOOK addSearchPath(cocos2d::CCFileUtils* _this, void*, const char* path); + void COCOS_HOOK addSearchPath(cocos2d::CCFileUtils* This, void*, const char* path); } BTN_CALLBACK(enterScene);