Skip to content

Commit

Permalink
FLAlertLayer, borders, and memory fix
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
poweredbypie committed Feb 20, 2021
1 parent 851df23 commit be4e563
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 70 deletions.
17 changes: 16 additions & 1 deletion include/cocos2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ namespace cocos2d {
}
};

class CCLayer : public CCNode {
public:
//idk
};

class CCScene : public CCNode {
public:
static CCScene* create() {
Expand Down Expand Up @@ -200,6 +205,16 @@ namespace cocos2d {
FIND_EXPORT("?setScaleY@CCSprite@cocos2d@@UAEXM@Z")
)(this, fScaleY);
}
void setFlipX(bool bFlipX) {
return as<void(__thiscall*)(CCSprite*, bool)>(
FIND_EXPORT("?setFlipX@CCSprite@cocos2d@@QAEX_N@Z")
)(this, bFlipX);
}
void setFlipY(bool bFlipY) {
return as<void(__thiscall*)(CCSprite*, bool)>(
FIND_EXPORT("?setFlipY@CCSprite@cocos2d@@QAEX_N@Z")
)(this, bFlipY);
}
CCSize getTextureSize() {
return *as<CCSize*>(
as<char*>(this) + 0x13C
Expand Down Expand Up @@ -275,7 +290,7 @@ namespace cocos2d {
class XMLDocument : public XMLNode {
public:
static XMLDocument* create(bool processEntities, int whitespaceMode) {
XMLDocument* pRet = as<decltype(pRet)>(new char[0x170]);
XMLDocument* pRet = as<decltype(pRet)>(new char[0x174]);
if (pRet) {
pRet->constructor(processEntities, whitespaceMode);
}
Expand Down
60 changes: 52 additions & 8 deletions include/gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ namespace gd {
base + 0xC4A50
)();
}

void reloadAll(bool bSwitch, bool bFullscreen, bool bReloadedInSession) {
return as<void(__thiscall*)(GameManager*, bool, bool, bool)>(
base + 0xCE950
)(this, bSwitch, bFullscreen, bReloadedInSession);
}
void setQuality(cocos2d::TextureQuality quality) {
*reinterpret_cast<cocos2d::TextureQuality*>(
reinterpret_cast<char*>(this) + 0x2E4
) = quality;
}
};

class MenuLayer : public cocos2d::CCScene {
class MenuLayer : public cocos2d::CCLayer {
public:
static inline auto pMoreGamesStr = as<void const**>(base + 0x190EF2);
static inline auto szMoreGamesBtn = as<float const**>(base + 0x190F01);
Expand All @@ -37,19 +41,29 @@ namespace gd {
base + 0x190550
)();
}

static void fadeInMusic(const char* filename) {
return as<void(__stdcall*)(const char*)>(
base + 0xC4BD0
)(filename);
}
};

class LoadingLayer : public cocos2d::CCLayer {
public:
void setWillFadeIn(bool willFadeIn) {
*reinterpret_cast<bool*>(
reinterpret_cast<char*>(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<CCMenuItemSpriteExtra*(__thiscall*)(cocos2d::CCSprite*, cocos2d::CCMenu*, void(__stdcall* const)(void*))>(
static CCMenuItemSpriteExtra* create(cocos2d::CCSprite* sprite,
cocos2d::CCMenu* target, void(__stdcall* const callback)(void*)) {
auto pRet = as<CCMenuItemSpriteExtra*(__thiscall*)(cocos2d::CCSprite*,
cocos2d::CCMenu*, void(__stdcall* const)(void*))>(
base + 0x18EE0
)(sprite, target, callback);
//fix stack before returning
Expand All @@ -69,21 +83,51 @@ 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<ButtonSprite* (__fastcall*)(const char*, int, int, bool, const char*, const char*, float)>(
auto pRet = as<ButtonSprite* (__fastcall*)(const char*,
int, int, bool, const char*, const char*, float)>(
base + 0x137D0
)(caption, width, 0, absolute, font, texture, height);
//clean stack before returning
__asm add esp, 0x14
return pRet;
}
};

class FLAlertLayer : public cocos2d::CCLayer {
public:
/*FLAlertLayer supports colors of text for the caption. wrap desired text in "<cx></c>"
* 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<FLAlertLayer* (__fastcall*)(cocos2d::CCObject*, const char*,
const char*, const char*, std::string)>(
base + 0x22680
)(target, title, btn1, btn2, caption);
//clean stack.
__asm add esp, 0x20
}
void show() {
return as<void(__thiscall*)(FLAlertLayer*)>(
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<decltype(pRet)>(new char[0x1C0]());
Expand Down
13 changes: 5 additions & 8 deletions src/classes/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@ 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();

m_titleLabel = CCLabelBMFont::create(m_titleStr, "goldFont.fnt");
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
Expand All @@ -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
Expand Down Expand Up @@ -253,7 +252,6 @@ void listExt::updateLabels() {

void listExt::updateSelector() {
using namespace cocos2d;
using namespace gd;

if (!m_entered) {
m_moveBtn = CCMenuItemSprite::create(
Expand Down Expand Up @@ -327,15 +325,14 @@ void listExt::updateSelector() {

void listExt::enter(cocos2d::CCScene* scene) {
using namespace cocos2d;
using namespace gd;

m_menu = CCMenu::create();

m_titleLabel = CCLabelBMFont::create(m_titleStr, "goldFont.fnt");
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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/classes/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CCNode*>(pSender)->getParent()->addChild(m_layer);


Expand Down

0 comments on commit be4e563

Please sign in to comment.