//
// GJMGLayer::init from 0x7ecd08 to 0x7ed128 (1056 bytes)
//
// 2 xrefs:
// > GJMGLayer::create @ 0x7ed1d0
// > ??> @ 0xa09b0
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
bool GJMGLayer::init(GJMGLayer *a1, int a2)
{
bool v4; // w23
cocos2d::CCDirector *v6; // x0
GameManager *v7; // x0
char *MGTexture; // x0
cocos2d::CCSpriteBatchNode *v9; // x0
GJMGLayer_vtbl *v10; // x3
cocos2d::CCTexture2D *v11; // x0
cocos2d::CCSpriteBatchNode *m_mg1BatchNode; // x0
float v13; // s0
cocos2d::CCSpriteBatchNode_vtbl *v14; // x1
int v15; // w20
cocos2d::CCTexture2D *v16; // x0
cocos2d::CCSprite *v17; // x26
cocos2d::CCSprite_vtbl *v18; // x1
void (__fastcall *setPosition)(cocos2d::CCSprite *__hidden, const cocos2d::CCPoint *); // x27
cocos2d::CCString *v20; // x0
const char *CString; // x0
cocos2d::CCSpriteBatchNode *v22; // x0
GJMGLayer_vtbl *v23; // x3
cocos2d::CCTexture2D *v24; // x0
float v25; // s8
cocos2d::CCTexture2D *v26; // x0
float v27; // s8
cocos2d::CCTexture2D *v28; // x0
cocos2d::CCSprite *v29; // x24
cocos2d::CCSprite_vtbl *v30; // x1
void (__fastcall *v31)(cocos2d::CCSprite *__hidden, const cocos2d::CCPoint *); // x25
cocos2d::CCSpriteBatchNode *m_mg2BatchNode; // x24
void (__fastcall *v33)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x25
cocos2d::ccBlendFunc *p_m_blendFunc; // x0
unsigned int *p_m_bManualSortChildren; // x2
int v36; // w1
__int64 v37; // [xsp+68h] [xbp+68h] BYREF
float v38; // [xsp+70h] [xbp+70h]
cocos2d::CCSpriteBatchNode *v39; // [xsp+78h] [xbp+78h] BYREF
__int64 v40; // [xsp+80h] [xbp+80h] BYREF
__int64 v41; // [xsp+88h] [xbp+88h] BYREF
cocos2d::CCPoint v42; // [xsp+90h] [xbp+90h] BYREF
v4 = cocos2d::CCLayer::init(a1);
if ( v4 )
{
a1->setContentSize(a1, &stru_12429A8);
v6 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v6);
a1->m_ground2Offset = GJMGLayer::defaultYOffsetForBG2(a2);
v7 = GameManager::sharedState();
MGTexture = (char *)GameManager::getMGTexture(v7, a2);
sub_D153B8((int)&v39, MGTexture);
a1->m_showGround = 0;
LOWORD(v37) = 26112;
BYTE2(v37) = -1;
v9 = cocos2d::CCSpriteBatchNode::create((const char *)v39, (unsigned int)&off_18 + 5);
v10 = a1->cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_mg1BatchNode = v9;
v10->addChild_0(a1, v9, 2);
v11 = a1->m_mg1BatchNode->getTexture(a1->m_mg1BatchNode);
v11->getContentSize((cocos2d::CCTexture2D *)&v40);
m_mg1BatchNode = a1->m_mg1BatchNode;
v13 = v38 / *(float *)&v40;
v14 = m_mg1BatchNode->cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
LODWORD(a1->m_textureWidth) = v40;
v15 = (int)(ceilf(v13) + 1.0);
v16 = v14->getTexture(m_mg1BatchNode);
v17 = cocos2d::CCSprite::createWithTexture(v16);
a1->m_ground1Sprite = v17;
v18 = v17->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v17->m_bDontDraw = 1;
setPosition = v18->setPosition;
cocos2d::CCPoint::CCPoint(&v42, 0.0, 0.0);
setPosition(v17, &v42);
a1->m_ground1Sprite->setColor(a1->m_ground1Sprite, (const cocos2d::ccColor3B *)&v37);
a1->m_mg1BatchNode->addChild(a1->m_mg1BatchNode, a1->m_ground1Sprite);
GJMGLayer::loadGroundSprites(a1, v15, 1);
GJMGLayer::updateGroundColor(a1, (cocos2d::ccColor3B)v37, 1);
v20 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"fg_%02d_2_001.png",
(const char *)(unsigned int)a2);
CString = cocos2d::CCString::getCString(v20);
v22 = cocos2d::CCSpriteBatchNode::create(CString, (unsigned int)&off_18 + 5);
v23 = a1->cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_mg2BatchNode = v22;
v23->addChild_0(a1, v22, 3);
v24 = a1->m_mg1BatchNode->getTexture(a1->m_mg1BatchNode);
v24->getContentSize((cocos2d::CCTexture2D *)&v41);
v25 = *((float *)&v41 + 1);
v26 = a1->m_mg2BatchNode->getTexture(a1->m_mg2BatchNode);
v26->getContentSize(v26);
v27 = v25 - v42.y;
v28 = a1->m_mg2BatchNode->getTexture(a1->m_mg2BatchNode);
v29 = cocos2d::CCSprite::createWithTexture(v28);
a1->m_ground2Sprite = v29;
v30 = v29->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v29->m_bDontDraw = 1;
v31 = v30->setPosition;
cocos2d::CCPoint::CCPoint(&v42, 0.0, 0.0);
v31(v29, &v42);
a1->m_ground2Sprite->setColor(a1->m_ground2Sprite, (const cocos2d::ccColor3B *)&v37);
a1->m_mg2BatchNode->addChild(a1->m_mg2BatchNode, a1->m_ground2Sprite);
m_mg2BatchNode = a1->m_mg2BatchNode;
v33 = m_mg2BatchNode->setPosition;
cocos2d::CCPoint::CCPoint(&v42, 0.0, v27);
v33(m_mg2BatchNode, &v42);
GJMGLayer::loadGroundSprites(a1, v15, 0);
GJMGLayer::updateGroundColor(a1, (cocos2d::ccColor3B)v37, 0);
p_m_blendFunc = &v39[-1].m_blendFunc;
if ( &v39[-1].m_blendFunc != (cocos2d::ccBlendFunc *)&qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_bManualSortChildren = (unsigned int *)&v39[-1].m_bManualSortChildren;
do
v36 = __ldaxr(p_m_bManualSortChildren);
while ( __stlxr(v36 - 1, p_m_bManualSortChildren) );
}
else
{
v36 = *(_DWORD *)&v39[-1].m_bManualSortChildren;
*(_DWORD *)&v39[-1].m_bManualSortChildren = v36 - 1;
}
if ( v36 <= 0 )
operator delete(p_m_blendFunc);
}
}
return v4;
}