//
// GJMGLayer::init from 0x14027f000 to 0x14027f4f7 (1271 bytes)
//
// 2 xrefs:
// > GJBaseGameLayer::createMiddleground @ 0x14020bbf5
// > ??> @ 0x1406d12bc
//
// 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
//
// Hidden C++ exception states: #wind=2
bool GJMGLayer::init(GJMGLayer *a1, int a2)
{
bool result; // al
__int64 v5; // rcx
cocos2d::CCDirector *v6; // rax
float v7; // xmm0_4
GameManager *v8; // rcx
int v9; // eax
int v10; // ebx
cocos2d::CCString *v11; // rax
const char *CString; // rax
unsigned int v13; // esi
size_t v14; // r8
void **v15; // rcx
cocos2d::CCSpriteBatchNode *v16; // rax
cocos2d::CCTexture2D *v17; // rax
float v18; // xmm1_4
float v19; // xmm0_4
int v20; // r12d
struct cocos2d::CCTexture2D *v21; // rax
struct cocos2d::CCSprite *v22; // rax
cocos2d::CCSprite_vtbl *v23; // rbx
double v24; // xmm0_8
const cocos2d::CCPoint *v25; // rax
cocos2d::CCSprite *m_ground1Sprite; // rcx
cocos2d::CCArray *v27; // rdi
unsigned int i; // ebx
struct cocos2d::CCObject *v29; // rax
cocos2d::CCString *v30; // rax
const char *v31; // rax
cocos2d::CCSpriteBatchNode *v32; // rax
cocos2d::CCTexture2D *v33; // rbx
cocos2d::CCTexture2D *v34; // rdi
struct cocos2d::CCTexture2D *v35; // rax
struct cocos2d::CCSprite *v36; // rax
cocos2d::CCSprite_vtbl *v37; // rbx
const cocos2d::CCPoint *v38; // rax
float v39; // xmm0_4
cocos2d::CCSpriteBatchNode_vtbl *v40; // rbx
const cocos2d::CCPoint *v41; // rax
cocos2d::CCSprite *m_ground2Sprite; // rcx
cocos2d::CCArray *v43; // rbx
struct cocos2d::CCObject *v44; // rax
void *v45; // rcx
__int16 v46; // [rsp+28h] [rbp-39h] BYREF
char v47; // [rsp+2Ah] [rbp-37h]
__int16 v48; // [rsp+38h] [rbp-29h] BYREF
char v49; // [rsp+3Ah] [rbp-27h]
void *v50; // [rsp+40h] [rbp-21h] BYREF
_BYTE v51[8]; // [rsp+48h] [rbp-19h] BYREF
_DWORD v52[4]; // [rsp+50h] [rbp-11h] BYREF
void *Block[2]; // [rsp+60h] [rbp-1h] BYREF
__int64 v54; // [rsp+70h] [rbp+Fh]
unsigned __int64 v55; // [rsp+78h] [rbp+17h]
result = cocos2d::CCLayer::init(a1);
if ( result )
{
a1->setContentSize(a1, &stru_1406C1E20);
v6 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v5);
cocos2d::CCDirector::getWinSize(v6);
if ( a2 == 1 )
{
v7 = 25.0;
}
else if ( (unsigned int)(a2 - 2) < 2 )
{
v7 = 30.0;
}
else
{
v7 = 0.0;
}
a1->m_ground2Offset = v7;
v8 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v50 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v50);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v8 = (GameManager *)qword_1406C2ED8;
}
v9 = 3;
if ( a2 < 3 )
v9 = a2;
v10 = 1;
if ( v9 > 1 )
v10 = v9;
GameManager::loadMiddleground(v8, v10);
v11 = cocos2d::CCString::createWithFormat("fg_%02d_001.png", v10);
CString = cocos2d::CCString::getCString(v11);
*(_OWORD *)Block = 0;
v13 = 0;
v54 = 0;
v55 = 0;
v14 = -1;
do
++v14;
while ( CString[v14] );
sub_14003A930(Block, CString, v14);
a1->m_showGround = 0;
v46 = 26112;
v48 = 26112;
v49 = -1;
v15 = Block;
if ( v55 > 0xF )
v15 = (void **)Block[0];
v16 = cocos2d::CCSpriteBatchNode::create((const char *)v15);
a1->m_mg1BatchNode = v16;
a1->addChild_0(a1, v16, 2);
v17 = a1->m_mg1BatchNode->getTexture(&a1->m_mg1BatchNode->cocos2d::CCTextureProtocol);
((void (__fastcall *)(cocos2d::CCTexture2D *, _DWORD *))v17->getContentSize)(v17, v52);
v18 = *(float *)v52;
LODWORD(a1->m_textureWidth) = v52[0];
v19 = ceilf(*(float *)&v52[2] / v18) + 1.0;
v20 = (int)v19;
v21 = a1->m_mg1BatchNode->getTexture(&a1->m_mg1BatchNode->cocos2d::CCTextureProtocol);
v22 = cocos2d::CCSprite::createWithTexture(v21, &stru_1406C1E10);
a1->m_ground1Sprite = v22;
v22->m_bDontDraw = 1;
v23 = a1->m_ground1Sprite->__vftable;
v24 = cocos2d::CCPoint::CCPoint(v19, 0.0);
v23->setPosition_0(a1->m_ground1Sprite, v25);
a1->m_ground1Sprite->setColor(&a1->m_ground1Sprite->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)&v48);
a1->m_mg1BatchNode->addChild_1(a1->m_mg1BatchNode, a1->m_ground1Sprite);
GJMGLayer::loadGroundSprites(a1, v20, 1);
v46 = v48;
v47 = v49;
m_ground1Sprite = a1->m_ground1Sprite;
if ( m_ground1Sprite )
{
v27 = m_ground1Sprite->getChildren(m_ground1Sprite);
for ( i = 0; i < cocos2d::CCArray::count(v27); ++i )
{
v29 = cocos2d::CCArray::objectAtIndex(v27, i);
(**(void (__fastcall ***)(__int64, __int16 *))&v29[5].m_unknown2)((__int64)&v29[5].m_unknown2, &v46);
}
}
v30 = cocos2d::CCString::createWithFormat("fg_%02d_2_001.png", a2);
v31 = cocos2d::CCString::getCString(v30);
v32 = cocos2d::CCSpriteBatchNode::create(v31);
a1->m_mg2BatchNode = v32;
a1->addChild_0(a1, v32, 3);
v33 = a1->m_mg1BatchNode->getTexture(&a1->m_mg1BatchNode->cocos2d::CCTextureProtocol);
v34 = a1->m_mg2BatchNode->getTexture(&a1->m_mg2BatchNode->cocos2d::CCTextureProtocol);
((void (__fastcall *)(cocos2d::CCTexture2D *, void **))v33->getContentSize)(v33, &v50);
((void (__fastcall *)(cocos2d::CCTexture2D *, _BYTE *))v34->getContentSize)(v34, v51);
v35 = a1->m_mg2BatchNode->getTexture(&a1->m_mg2BatchNode->cocos2d::CCTextureProtocol);
v36 = cocos2d::CCSprite::createWithTexture(v35, &stru_1406C1E10);
a1->m_ground2Sprite = v36;
v36->m_bDontDraw = 1;
v37 = a1->m_ground2Sprite->__vftable;
cocos2d::CCPoint::CCPoint(*(float *)&v24, 0.0);
v37->setPosition_0(a1->m_ground2Sprite, v38);
a1->m_ground2Sprite->setColor(&a1->m_ground2Sprite->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)&v48);
v39 = ((float (__fastcall *)(cocos2d::CCSpriteBatchNode *, cocos2d::CCSprite *))a1->m_mg2BatchNode->addChild_1)(
a1->m_mg2BatchNode,
a1->m_ground2Sprite);
v40 = a1->m_mg2BatchNode->__vftable;
cocos2d::CCPoint::CCPoint(v39, 0.0);
v40->setPosition_0(a1->m_mg2BatchNode, v41);
GJMGLayer::loadGroundSprites(a1, v20, 0);
v46 = v48;
v47 = v49;
m_ground2Sprite = a1->m_ground2Sprite;
if ( m_ground2Sprite )
{
v43 = m_ground2Sprite->getChildren(m_ground2Sprite);
if ( cocos2d::CCArray::count(v43) )
{
do
{
v44 = cocos2d::CCArray::objectAtIndex(v43, v13);
(**(void (__fastcall ***)(__int64, __int16 *))&v44[5].m_unknown2)((__int64)&v44[5].m_unknown2, &v46);
++v13;
}
while ( v13 < cocos2d::CCArray::count(v43) );
}
}
if ( v55 > 0xF )
{
v45 = Block[0];
if ( v55 + 1 >= 0x1000 )
{
v45 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v45 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v45);
}
return 1;
}
return result;
}