//
// GJMGLayer::init from 0x140387b80 to 0x1403880a8 (1320 bytes)
//
// 2 xrefs:
// > GJBaseGameLayer::createMiddleground @ 0x140311d85
// > ??> @ 0x140922bd4
//
// This function is hookable on this platform (idp: pc, 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 11:31:08 +0000
//
// Hidden C++ exception states: #wind=2
bool __fastcall GJMGLayer::init(__int64 a1, int a2)
{
bool result; // al
__int64 v5; // rcx
__int64 v6; // rax
int v7; // xmm0_4
__int64 v8; // rcx
int v9; // eax
int v10; // ebx
cocos2d::CCString *v11; // rax
const char *CString; // rax
size_t v13; // r8
void **v14; // rcx
struct cocos2d::CCSpriteBatchNode *v15; // rax
__int64 v16; // rax
float v17; // xmm1_4
unsigned int v18; // r15d
struct cocos2d::CCTexture2D *v19; // rax
struct cocos2d::CCSprite *v20; // rax
__int64 v21; // rdi
__int64 v22; // rbx
__int64 v23; // rax
__int64 v24; // r8
__int64 v25; // rcx
cocos2d::CCArray *v26; // rdi
unsigned int i; // ebx
struct cocos2d::CCObject *v28; // rax
cocos2d::CCString *v29; // rax
const char *v30; // rax
struct cocos2d::CCSpriteBatchNode *v31; // rax
__int64 v32; // rbx
__int64 v33; // rdi
__int64 v34; // rbx
float v35; // xmm6_4
struct cocos2d::CCTexture2D *v36; // rax
struct cocos2d::CCSprite *v37; // rax
__int64 v38; // rdi
__int64 v39; // rbx
__int64 v40; // rax
__int64 v41; // rdi
__int64 v42; // rbx
__int64 v43; // rax
__int64 v44; // rcx
cocos2d::CCArray *v45; // rdi
unsigned int j; // ebx
struct cocos2d::CCObject *v47; // rax
void *v48; // rcx
__int16 v49; // [rsp+30h] [rbp-39h] BYREF
char v50; // [rsp+32h] [rbp-37h]
__int16 v51; // [rsp+40h] [rbp-29h] BYREF
char v52; // [rsp+42h] [rbp-27h]
void *v53; // [rsp+48h] [rbp-21h] BYREF
_BYTE v54[8]; // [rsp+50h] [rbp-19h] BYREF
float v55; // [rsp+58h] [rbp-11h] BYREF
float v56; // [rsp+60h] [rbp-9h] BYREF
void *Block[2]; // [rsp+68h] [rbp-1h] BYREF
__int64 v58; // [rsp+78h] [rbp+Fh]
unsigned __int64 v59; // [rsp+80h] [rbp+17h]
result = cocos2d::CCLayer::init((cocos2d::CCLayer *)a1);
if ( result )
{
(*(void (__fastcall **)(__int64, void *))(*(_QWORD *)a1 + 312LL))(a1, &unk_14090AB88);
v6 = cocos2d::CCDirector::sharedDirector(v5);
cocos2d::CCDirector::getWinSize(v6, &v56);
if ( a2 == 1 )
{
v7 = 1103626240;
}
else if ( (unsigned int)(a2 - 2) < 2 )
{
v7 = 1106247680;
}
else
{
v7 = 0;
}
*(_DWORD *)(a1 + 484) = v7;
v8 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v53 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v53);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v8 = qword_14090BFD0;
}
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;
v58 = 0;
v59 = 0;
v13 = -1;
do
++v13;
while ( CString[v13] );
sub_14003D230(Block, CString, v13);
*(_BYTE *)(a1 + 440) = 0;
v49 = 26112;
v51 = 26112;
v52 = -1;
v14 = Block;
if ( v59 > 0xF )
v14 = (void **)Block[0];
v15 = cocos2d::CCSpriteBatchNode::create((const char *)v14);
*(_QWORD *)(a1 + 464) = v15;
(*(void (__fastcall **)(__int64, struct cocos2d::CCSpriteBatchNode *, __int64))(*(_QWORD *)a1 + 456LL))(a1, v15, 2);
v16 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(*(_QWORD *)(a1 + 464) + 320LL) + 16LL))(*(_QWORD *)(a1 + 464) + 320LL);
(*(void (__fastcall **)(__int64, float *))(*(_QWORD *)v16 + 136LL))(v16, &v55);
v17 = v55;
*(float *)(a1 + 424) = v55;
v18 = (int)(float)(ceilf(v56 / v17) + 1.0);
v19 = (struct cocos2d::CCTexture2D *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(*(_QWORD *)(a1 + 464) + 320LL)
+ 16LL))(*(_QWORD *)(a1 + 464) + 320LL);
v20 = cocos2d::CCSprite::createWithTexture(v19, (const struct cocos2d::CCRect *)&unk_14090AB78);
*(_QWORD *)(a1 + 408) = v20;
*((_BYTE *)v20 + 559) = 1;
v21 = **(_QWORD **)(a1 + 408);
v22 = *(_QWORD *)(a1 + 408);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v53, 0.0, 0.0);
(*(void (__fastcall **)(__int64, __int64))(v21 + 184))(v22, v23);
(**(void (__fastcall ***)(__int64, __int16 *))(*(_QWORD *)(a1 + 408) + 320LL))(*(_QWORD *)(a1 + 408) + 320LL, &v51);
(*(void (__fastcall **)(_QWORD, _QWORD))(**(_QWORD **)(a1 + 464) + 464LL))(
*(_QWORD *)(a1 + 464),
*(_QWORD *)(a1 + 408));
LOBYTE(v24) = 1;
GJMGLayer::loadGroundSprites(a1, v18, v24);
v49 = v51;
v50 = v52;
v25 = *(_QWORD *)(a1 + 408);
if ( v25 )
{
v26 = (cocos2d::CCArray *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v25 + 480LL))(v25);
for ( i = 0; i < cocos2d::CCArray::count(v26); ++i )
{
v28 = cocos2d::CCArray::objectAtIndex(v26, i);
(**((void (__fastcall ***)(__int64, __int16 *))v28 + 40))((__int64)v28 + 320, &v49);
}
}
v29 = cocos2d::CCString::createWithFormat("fg_%02d_2_001.png", a2);
v30 = cocos2d::CCString::getCString(v29);
v31 = cocos2d::CCSpriteBatchNode::create(v30);
*(_QWORD *)(a1 + 472) = v31;
(*(void (__fastcall **)(__int64, struct cocos2d::CCSpriteBatchNode *, __int64))(*(_QWORD *)a1 + 456LL))(a1, v31, 3);
v32 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(*(_QWORD *)(a1 + 464) + 320LL) + 16LL))(*(_QWORD *)(a1 + 464) + 320LL);
v33 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(*(_QWORD *)(a1 + 472) + 320LL) + 16LL))(*(_QWORD *)(a1 + 472) + 320LL);
v34 = (*(__int64 (__fastcall **)(__int64, void **))(*(_QWORD *)v32 + 136LL))(v32, &v53);
v35 = *(float *)(v34 + 4)
- *(float *)((*(__int64 (__fastcall **)(__int64, _BYTE *))(*(_QWORD *)v33 + 136LL))(v33, v54) + 4);
v36 = (struct cocos2d::CCTexture2D *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)(*(_QWORD *)(a1 + 472) + 320LL)
+ 16LL))(*(_QWORD *)(a1 + 472) + 320LL);
v37 = cocos2d::CCSprite::createWithTexture(v36, (const struct cocos2d::CCRect *)&unk_14090AB78);
*(_QWORD *)(a1 + 416) = v37;
*((_BYTE *)v37 + 559) = 1;
v38 = **(_QWORD **)(a1 + 416);
v39 = *(_QWORD *)(a1 + 416);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v54, 0.0, 0.0);
(*(void (__fastcall **)(__int64, __int64))(v38 + 184))(v39, v40);
(**(void (__fastcall ***)(__int64, __int16 *))(*(_QWORD *)(a1 + 416) + 320LL))(*(_QWORD *)(a1 + 416) + 320LL, &v51);
(*(void (__fastcall **)(_QWORD, _QWORD))(**(_QWORD **)(a1 + 472) + 464LL))(
*(_QWORD *)(a1 + 472),
*(_QWORD *)(a1 + 416));
v41 = **(_QWORD **)(a1 + 472);
v42 = *(_QWORD *)(a1 + 472);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v54, 0.0, v35);
(*(void (__fastcall **)(__int64, __int64))(v41 + 184))(v42, v43);
GJMGLayer::loadGroundSprites(a1, v18, 0);
v49 = v51;
v50 = v52;
v44 = *(_QWORD *)(a1 + 416);
if ( v44 )
{
v45 = (cocos2d::CCArray *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v44 + 480LL))(v44);
for ( j = 0; j < cocos2d::CCArray::count(v45); ++j )
{
v47 = cocos2d::CCArray::objectAtIndex(v45, j);
(**((void (__fastcall ***)(__int64, __int16 *))v47 + 40))((__int64)v47 + 320, &v49);
}
}
if ( v59 > 0xF )
{
v48 = Block[0];
if ( v59 + 1 >= 0x1000 )
{
v48 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v48 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v48);
}
return 1;
}
return result;
}