//
// GJBaseGameLayer::optimizeMoveGroups from 0x5a6858 to 0x5a6ab4 (604 bytes)
//
// 2 xrefs:
// > LevelEditorLayer::onResumePlaytest @ 0x468182
// > GJBaseGameLayer::updateSpecialGroupData @ 0x5c150e
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:53:21 +0000
//
int __fastcall GJBaseGameLayer::optimizeMoveGroups(GJBaseGameLayer *this)
{
int v2; // r2
int *i; // r4
_DWORD *v4; // r3
_DWORD *v5; // r6
_DWORD *v6; // r4
_DWORD *v7; // t1
GameObject *MainObject; // r1
int *j; // r4
cocos2d::CCObject *Group; // r0
_DWORD *v11; // r2
GameObject **v12; // r7
GameObject **v13; // r6
GameObject *v14; // r1
GameObject *v15; // t1
int k; // r6
int v17; // r3
unsigned int *v18; // r8
unsigned int v19; // r4
unsigned int v20; // r7
unsigned int v21; // r3
cocos2d::CCObject *v22; // r0
int v24; // r3
int *v25; // r0
int **v26; // r1
int v27; // r3
_DWORD *v28; // [sp+0h] [bp-7Ch]
char v29; // [sp+Ch] [bp-70h] BYREF
char v30[8]; // [sp+14h] [bp-68h] BYREF
char v31; // [sp+1Ch] [bp-60h] BYREF
char v32[8]; // [sp+24h] [bp-58h] BYREF
char v33; // [sp+2Ch] [bp-50h] BYREF
char v34[8]; // [sp+34h] [bp-48h] BYREF
char v35[8]; // [sp+3Ch] [bp-40h] BYREF
char v36; // [sp+44h] [bp-38h] BYREF
int v37[2]; // [sp+4Ch] [bp-30h] BYREF
int v38[2]; // [sp+54h] [bp-28h] BYREF
int *v39; // [sp+5Ch] [bp-20h] BYREF
_DWORD v40[2]; // [sp+60h] [bp-1Ch] BYREF
int *v41; // [sp+68h] [bp-14h] BYREF
_DWORD v42[2]; // [sp+6Ch] [bp-10h] BYREF
v39 = v40;
v41 = v42;
v40[0] = 0;
v40[1] = 0;
v42[0] = 0;
v42[1] = 0;
v2 = *((_DWORD *)this + 522);
if ( v2 )
{
v4 = *(_DWORD **)(v2 + 52);
if ( *v4 )
{
v5 = (_DWORD *)v4[3];
v28 = &v5[*v4 - 1];
while ( 1 )
{
while ( 1 )
{
if ( v5 > v28 )
goto LABEL_2;
v7 = (_DWORD *)*v5++;
v6 = v7;
if ( !v7 )
goto LABEL_2;
v24 = v6[223];
if ( v24 == 2915 )
{
v25 = v37;
v38[0] = v6[321];
LABEL_33:
v26 = &v39;
goto LABEL_34;
}
if ( v24 <= 2915 )
break;
if ( v24 == 3016 )
goto LABEL_43;
if ( v24 > 3016 )
{
if ( v24 == 3661 )
{
LABEL_43:
v25 = (int *)&v29;
v38[0] = v6[322];
goto LABEL_33;
}
}
else if ( (unsigned int)(v24 - 3006) <= 2 )
{
v27 = v6[340];
if ( !v27 )
v27 = v6[322];
v37[0] = v27;
if ( v27 > 0 )
std::__tree::__emplace_unique_key_args((int)v38, (int)&v39, v37, v37);
}
}
if ( v24 == 1346 )
break;
if ( v24 > 1346 )
{
if ( v24 == 1347 )
goto LABEL_43;
if ( v24 == 2067 )
{
v38[0] = v6[322];
std::__tree::__emplace_unique_key_args((int)v30, &v39, v38, v38);
v25 = (int *)&v31;
v26 = &v41;
v38[0] = v6[321];
LABEL_34:
std::__tree::__emplace_unique_key_args((int)v25, v26, v38, v38);
}
}
else if ( v24 == 901 )
{
v38[0] = v6[322];
std::__tree::__emplace_unique_key_args((int)v32, &v39, v38, v38);
v25 = (int *)&v33;
v38[0] = v6[337];
goto LABEL_38;
}
}
v38[0] = v6[321];
std::__tree::__emplace_unique_key_args((int)v34, &v41, v38, v38);
v38[0] = v6[322];
std::__tree::__emplace_unique_key_args((int)v35, &v39, v38, v38);
v25 = (int *)&v36;
v38[0] = v6[344];
LABEL_38:
v26 = &v39;
goto LABEL_34;
}
}
LABEL_2:
GJBaseGameLayer::addRemapTargets((int)this, &v39);
for ( i = v39; i != v40; i = std::__tree_next *>(i) )
{
MainObject = (GameObject *)GJBaseGameLayer::tryGetMainObject((cocos2d::CCDictionary **)this, i[4]);
if ( MainObject )
GJBaseGameLayer::moveObjectToStaticGroup((int)this, MainObject);
}
GJBaseGameLayer::addRemapTargets((int)this, &v41);
for ( j = v41; j != v42; j = std::__tree_next *>(j) )
{
Group = GJBaseGameLayer::getGroup(this, j[4]);
if ( Group )
{
v11 = *((_DWORD **)Group + 13);
if ( *v11 )
{
v12 = (GameObject **)v11[3];
v13 = &v12[*v11] + 0x3FFFFFFF;
while ( v12 <= v13 )
{
v15 = *v12++;
v14 = v15;
if ( !v15 )
break;
GJBaseGameLayer::moveObjectToStaticGroup((int)this, v14);
}
}
}
}
for ( k = 0; k != 40000; k += 4 )
{
v17 = *(_DWORD *)(*((_DWORD *)this + 577) + k);
if ( v17 )
{
v18 = *(unsigned int **)(v17 + 52);
v19 = 0;
v20 = 0;
while ( v19 < *v18 )
{
v21 = v18[3];
v22 = *(cocos2d::CCObject **)(v21 + 4 * v19);
if ( *((_BYTE *)v22 + 1110) )
*(_DWORD *)(v21 + 4 * v20++) = v22;
else
cocos2d::CCObject::release(v22);
++v19;
}
*v18 = v20;
}
}
std::__tree::~__tree((int)&v41);
return std::__tree::~__tree((int)&v39);
}