//
// GJMGLayer::init from 0x1005ebd60 to 0x1005ec1be (1118 bytes)
//
// 1 xrefs:
// > GJMGLayer::create @ 0x1005ebd24
//
// 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 __fastcall GJMGLayer::init(GJMGLayer *a1, int a2)
{
double v3; // xmm0_8
GameManager *v4; // rax
const char *MGTexture; // r13
size_t v6; // rax
size_t v7; // r12
char *v8; // rbx
size_t v9; // r15
const char *v10; // rdi
cocos2d::CCSpriteBatchNode *v11; // rax
__int64 v12; // rax
cocos2d::CCTexture2D *v13; // rax
cocos2d::CCSprite *v14; // rbx
__m128 v15; // xmm0
cocos2d::CCSprite *m_ground1Sprite; // rdi
__int64 v17; // r13
unsigned int v18; // ebx
__int64 v19; // rax
cocos2d::CCString *v20; // rax
const char *CString; // rax
cocos2d::CCSpriteBatchNode *v22; // rax
__int64 v23; // rax
__int64 v24; // rax
cocos2d::CCTexture2D *v25; // rax
cocos2d::CCSprite *v26; // rbx
cocos2d::CCSpriteBatchNode *m_mg2BatchNode; // rbx
cocos2d::CCSprite *m_ground2Sprite; // rdi
__int64 v29; // r14
unsigned int v30; // ebx
__int64 v31; // rax
char v33; // [rsp+0h] [rbp-80h]
unsigned int v34; // [rsp+8h] [rbp-78h] BYREF
float v35; // [rsp+10h] [rbp-70h] BYREF
_BYTE v36[4]; // [rsp+18h] [rbp-68h] BYREF
float v37; // [rsp+1Ch] [rbp-64h]
_QWORD __dst[2]; // [rsp+20h] [rbp-60h] BYREF
void *__p; // [rsp+30h] [rbp-50h]
unsigned int v40; // [rsp+3Ch] [rbp-44h]
__int64 v41; // [rsp+40h] [rbp-40h]
float v42[2]; // [rsp+48h] [rbp-38h] BYREF
bool v43; // [rsp+53h] [rbp-2Dh]
__int16 v44; // [rsp+54h] [rbp-2Ch] BYREF
char v45; // [rsp+56h] [rbp-2Ah]
v43 = cocos2d::CCLayer::init(a1);
if ( !v43 )
return v43;
((void (__fastcall *)(GJMGLayer *, void *))a1->setContentSize)(a1, &unk_1009A2FC0);
cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize((cocos2d::CCDirector *)&v34);
v3 = 0.0;
if ( (unsigned int)(a2 - 1) <= 2 )
*(_QWORD *)&v3 = LODWORD(flt_1008219FC[a2 - 1]);
a1->m_ground2Offset = *(float *)&v3;
v4 = GameManager::sharedState();
MGTexture = GameManager::getMGTexture(v4, a2);
v6 = strlen(MGTexture);
if ( v6 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v3);
v7 = v6;
if ( v6 >= 0x17 )
{
v41 = (unsigned int)a2;
v9 = 26;
if ( (v6 | 7) != 0x17 )
v9 = (v6 | 7) + 1;
v8 = (char *)operator new(v9);
__p = v8;
__dst[0] = v9 + 1;
__dst[1] = v7;
}
else
{
LOBYTE(__dst[0]) = 2 * v6;
v8 = (char *)__dst + 1;
if ( !v6 )
goto LABEL_12;
}
memmove(v8, MGTexture, v7);
LABEL_12:
v8[v7] = 0;
a1->m_showGround = 0;
v45 = -1;
v44 = 26112;
if ( (__dst[0] & 1) != 0 )
v10 = (const char *)__p;
else
v10 = (char *)__dst + 1;
v11 = cocos2d::CCSpriteBatchNode::create(v10, 0x1Du);
a1->m_mg1BatchNode = v11;
((void (__fastcall *)(GJMGLayer *, cocos2d::CCSpriteBatchNode *, __int64))a1->addChild_0)(a1, v11, 2);
v12 = ((__int64 (__fastcall *)(cocos2d::CCSpriteBatchNode *))a1->m_mg1BatchNode->getTexture)(a1->m_mg1BatchNode);
(*(void (__fastcall **)(float *, __int64))(*(_QWORD *)v12 + 144LL))(&v35, v12);
*(float *)&v41 = v35;
a1->m_textureWidth = v35;
v40 = v34;
v13 = (cocos2d::CCTexture2D *)((__int64 (__fastcall *)(cocos2d::CCSpriteBatchNode *))a1->m_mg1BatchNode->getTexture)(a1->m_mg1BatchNode);
v14 = cocos2d::CCSprite::createWithTexture(v13, &stru_1009A2FC8);
a1->m_ground1Sprite = v14;
v14->m_bDontDraw = 1;
sub_10028CBE0(v42, 0.0, 0.0);
((void (__fastcall *)(cocos2d::CCSprite *, float *))v14->setPosition)(v14, v42);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))a1->m_ground1Sprite->setColor)(a1->m_ground1Sprite, &v44);
((void (__fastcall *)(cocos2d::CCSpriteBatchNode *, cocos2d::CCSprite *))a1->m_mg1BatchNode->addChild)(
a1->m_mg1BatchNode,
a1->m_ground1Sprite);
v15 = (__m128)v40;
v15.f32[0] = *(float *)&v40 / *(float *)&v41;
v40 = (int)(float)(_mm_round_ss(v15, v15, 10).f32[0] + 1.0);
GJMGLayer::loadGroundSprites(a1, v40, 1);
BYTE2(v42[0]) = v45;
LOWORD(v42[0]) = v44;
m_ground1Sprite = a1->m_ground1Sprite;
if ( m_ground1Sprite )
{
v17 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))m_ground1Sprite->getChildren)(m_ground1Sprite);
if ( (unsigned int)sub_100720070(v17) )
{
v18 = 0;
do
{
v19 = sub_1007200C0(v17, v18);
(*(void (__fastcall **)(__int64, float *))(*(_QWORD *)v19 + 944LL))(v19, v42);
++v18;
}
while ( v18 < (unsigned int)sub_100720070(v17) );
}
}
v20 = (cocos2d::CCString *)sub_1007AB580("fg_%02d_2_001.png", v33);
CString = cocos2d::CCString::getCString(v20);
v22 = cocos2d::CCSpriteBatchNode::create(CString, 0x1Du);
a1->m_mg2BatchNode = v22;
((void (__fastcall *)(GJMGLayer *, cocos2d::CCSpriteBatchNode *, __int64))a1->addChild_0)(a1, v22, 3);
v23 = ((__int64 (__fastcall *)(cocos2d::CCSpriteBatchNode *))a1->m_mg1BatchNode->getTexture)(a1->m_mg1BatchNode);
(*(void (__fastcall **)(float *, __int64))(*(_QWORD *)v23 + 144LL))(v42, v23);
*(float *)&v41 = v42[1];
v24 = ((__int64 (__fastcall *)(cocos2d::CCSpriteBatchNode *))a1->m_mg2BatchNode->getTexture)(a1->m_mg2BatchNode);
(*(void (__fastcall **)(_BYTE *, __int64))(*(_QWORD *)v24 + 144LL))(v36, v24);
*(float *)&v41 = *(float *)&v41 - v37;
v25 = (cocos2d::CCTexture2D *)((__int64 (__fastcall *)(cocos2d::CCSpriteBatchNode *))a1->m_mg2BatchNode->getTexture)(a1->m_mg2BatchNode);
v26 = cocos2d::CCSprite::createWithTexture(v25, &stru_1009A2FC8);
a1->m_ground2Sprite = v26;
v26->m_bDontDraw = 1;
sub_10028CBE0(v42, 0.0, 0.0);
((void (__fastcall *)(cocos2d::CCSprite *, float *))v26->setPosition)(v26, v42);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))a1->m_ground2Sprite->setColor)(a1->m_ground2Sprite, &v44);
((void (__fastcall *)(cocos2d::CCSpriteBatchNode *, cocos2d::CCSprite *))a1->m_mg2BatchNode->addChild)(
a1->m_mg2BatchNode,
a1->m_ground2Sprite);
m_mg2BatchNode = a1->m_mg2BatchNode;
sub_10028CBE0(v42, 0.0, *(float *)&v41);
((void (__fastcall *)(cocos2d::CCSpriteBatchNode *, float *))m_mg2BatchNode->setPosition)(m_mg2BatchNode, v42);
GJMGLayer::loadGroundSprites(a1, v40, 0);
BYTE2(v42[0]) = v45;
LOWORD(v42[0]) = v44;
m_ground2Sprite = a1->m_ground2Sprite;
if ( m_ground2Sprite )
{
v29 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))m_ground2Sprite->getChildren)(m_ground2Sprite);
if ( (unsigned int)sub_100720070(v29) )
{
v30 = 0;
do
{
v31 = sub_1007200C0(v29, v30);
(*(void (__fastcall **)(__int64, float *))(*(_QWORD *)v31 + 944LL))(v31, v42);
++v30;
}
while ( v30 < (unsigned int)sub_100720070(v29) );
}
}
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
return v43;
}