//
// GJMGLayer::init from 0x917b28 to 0x917f84 (1116 bytes)
//
// 2 xrefs:
// > GJMGLayer::create @ 0x91802c
// > ??> @ 0xd34b0
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:57:20 +0000
//
__int64 __fastcall GJMGLayer::init(GJMGLayer *this, unsigned int a2)
{
unsigned __int8 v4; // w0
unsigned int v5; // w23
cocos2d::CCDirector *v7; // x0
cocos2d::CCDirector *v8; // x0
GameManager *v9; // x0
GameManager *v10; // x0
const char *MGTexture; // x0
const char *v12; // x27
size_t v13; // x0
size_t v14; // x22
unsigned __int64 v15; // x0
__int64 v16; // x26
cocos2d::CCSpriteBatchNode *v17; // x0
char *v18; // x3
cocos2d::CCSpriteBatchNode *v19; // x0
__int64 v20; // x0
__int64 v21; // x3
__int64 v22; // x0
__int64 v23; // x0
float v24; // s0
unsigned int v25; // w21
cocos2d::CCSprite *v26; // x0
const cocos2d::CCRect *v27; // x2
__int64 v28; // x0
__int64 v29; // x26
void (__fastcall *v30)(__int64, _BYTE *); // x27
cocos2d::CCString *v31; // x0
cocos2d::CCSpriteBatchNode *CString; // x0
unsigned int v33; // w2
__int64 v34; // x0
__int64 v35; // x3
__int64 v36; // x0
float v37; // s8
__int64 v38; // x0
float v39; // s8
cocos2d::CCSprite *v40; // x0
const cocos2d::CCRect *v41; // x2
__int64 v42; // x0
__int64 v43; // x24
void (__fastcall *v44)(__int64, _BYTE *); // x25
__int64 v45; // x24
void (__fastcall *v46)(__int64, _BYTE *); // x25
std::logic_error *exception; // x19
__int64 v48; // [xsp+68h] [xbp+68h] BYREF
__int64 v49; // [xsp+70h] [xbp+70h] BYREF
__int64 v50; // [xsp+78h] [xbp+78h] BYREF
__int64 v51; // [xsp+80h] [xbp+80h] BYREF
_BYTE v52[4]; // [xsp+88h] [xbp+88h] BYREF
float v53; // [xsp+8Ch] [xbp+8Ch]
__int64 v54; // [xsp+90h] [xbp+90h] BYREF
size_t v55; // [xsp+98h] [xbp+98h]
cocos2d::CCSpriteBatchNode *v56; // [xsp+A0h] [xbp+A0h]
v4 = cocos2d::CCLayer::init(this);
v5 = v4;
if ( !v4 )
return v5;
v7 = (cocos2d::CCDirector *)(*(__int64 (__fastcall **)(GJMGLayer *, void *))(*(_QWORD *)this + 320LL))(
this,
&unk_155CF08);
v8 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v7);
cocos2d::CCDirector::getWinSize(&v49, v8);
*((float *)this + 121) = GJMGLayer::defaultYOffsetForBG2((GJMGLayer *)a2);
v10 = (GameManager *)GameManager::sharedState(v9);
MGTexture = (const char *)GameManager::getMGTexture(v10, a2);
v54 = 0;
v12 = MGTexture;
v55 = 0;
v56 = nullptr;
v13 = strlen(MGTexture);
v14 = v13;
if ( v13 > 0xFFFFFFFFFFFFFFEFLL )
{
exception = (std::logic_error *)_cxa_allocate_exception(0x10u);
std::logic_error::logic_error(exception, "basic_string");
*(_QWORD *)exception = off_1536D28;
_cxa_throw(
exception,
(struct type_info *)&`typeinfo for'std::length_error,
(void (*)(void *))std::logic_error::~logic_error);
}
if ( v13 <= 0x16 )
{
LOBYTE(v54) = 2 * v13;
v18 = (char *)&v54 + 1;
if ( !v13 )
goto LABEL_7;
}
else
{
v15 = (v13 + 16) & 0xFFFFFFFFFFFFFFF0LL;
v16 = v15 | 1;
v17 = (cocos2d::CCSpriteBatchNode *)operator new(v15);
v54 = v16;
v18 = (char *)v17;
v56 = v17;
v55 = v14;
}
v18 = (char *)memcpy(v18, v12, v14);
LABEL_7:
v18[v14] = 0;
*((_BYTE *)this + 440) = 0;
v19 = (cocos2d::CCSpriteBatchNode *)((char *)&v54 + 1);
LOWORD(v48) = 26112;
BYTE2(v48) = -1;
if ( (v54 & 1) != 0 )
v19 = v56;
v20 = cocos2d::CCSpriteBatchNode::create(v19, (const char *)&off_18 + 5, 0xFFFFFFFF);
v21 = *(_QWORD *)this;
*((_QWORD *)this + 58) = v20;
(*(void (__fastcall **)(GJMGLayer *, __int64, __int64))(v21 + 464))(this, v20, 2);
v22 = (*(__int64 (__fastcall **)(_QWORD))(**((_QWORD **)this + 58) + 896LL))(*((_QWORD *)this + 58));
(*(void (__fastcall **)(__int64 *__return_ptr))(*(_QWORD *)v22 + 144LL))(&v50);
v23 = *((_QWORD *)this + 58);
v24 = *(float *)&v49 / *(float *)&v50;
*((_DWORD *)this + 106) = v50;
v25 = (int)(float)(ceilf(v24) + 1.0);
v26 = (cocos2d::CCSprite *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v23 + 896LL))(v23);
v28 = cocos2d::CCSprite::createWithTexture(v26, (cocos2d::CCTexture2D *)&unk_155CF10, v27);
*((_QWORD *)this + 51) = v28;
*(_BYTE *)(v28 + 559) = 1;
v29 = *((_QWORD *)this + 51);
v30 = *(void (__fastcall **)(__int64, _BYTE *))(*(_QWORD *)v29 + 184LL);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v52, 0.0, 0.0);
v30(v29, v52);
(*(void (__fastcall **)(_QWORD, __int64 *))(**((_QWORD **)this + 51) + 960LL))(*((_QWORD *)this + 51), &v48);
(*(void (__fastcall **)(_QWORD, _QWORD))(**((_QWORD **)this + 58) + 456LL))(
*((_QWORD *)this + 58),
*((_QWORD *)this + 51));
GJMGLayer::loadGroundSprites(this, v25, 1);
GJMGLayer::updateGroundColor((__int64)this, v48, 1);
v31 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"fg_%02d_2_001.png",
(const char *)a2);
CString = (cocos2d::CCSpriteBatchNode *)cocos2d::CCString::getCString(v31);
v34 = cocos2d::CCSpriteBatchNode::create(CString, (const char *)&off_18 + 5, v33);
v35 = *(_QWORD *)this;
*((_QWORD *)this + 59) = v34;
(*(void (__fastcall **)(GJMGLayer *, __int64, __int64))(v35 + 464))(this, v34, 3);
v36 = (*(__int64 (__fastcall **)(_QWORD))(**((_QWORD **)this + 58) + 896LL))(*((_QWORD *)this + 58));
(*(void (__fastcall **)(__int64 *__return_ptr))(*(_QWORD *)v36 + 144LL))(&v51);
v37 = *((float *)&v51 + 1);
v38 = (*(__int64 (__fastcall **)(_QWORD))(**((_QWORD **)this + 59) + 896LL))(*((_QWORD *)this + 59));
(*(void (__fastcall **)(__int64))(*(_QWORD *)v38 + 144LL))(v38);
v39 = v37 - v53;
v40 = (cocos2d::CCSprite *)(*(__int64 (__fastcall **)(_QWORD))(**((_QWORD **)this + 59) + 896LL))(*((_QWORD *)this + 59));
v42 = cocos2d::CCSprite::createWithTexture(v40, (cocos2d::CCTexture2D *)&unk_155CF10, v41);
*((_QWORD *)this + 52) = v42;
*(_BYTE *)(v42 + 559) = 1;
v43 = *((_QWORD *)this + 52);
v44 = *(void (__fastcall **)(__int64, _BYTE *))(*(_QWORD *)v43 + 184LL);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v52, 0.0, 0.0);
v44(v43, v52);
(*(void (__fastcall **)(_QWORD, __int64 *))(**((_QWORD **)this + 52) + 960LL))(*((_QWORD *)this + 52), &v48);
(*(void (__fastcall **)(_QWORD, _QWORD))(**((_QWORD **)this + 59) + 456LL))(
*((_QWORD *)this + 59),
*((_QWORD *)this + 52));
v45 = *((_QWORD *)this + 59);
v46 = *(void (__fastcall **)(__int64, _BYTE *))(*(_QWORD *)v45 + 184LL);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v52, 0.0, v39);
v46(v45, v52);
GJMGLayer::loadGroundSprites(this, v25, 0);
GJMGLayer::updateGroundColor((__int64)this, v48, 0);
if ( (v54 & 1) != 0 )
operator delete(v56);
return v5;
}