//
// GJBaseGameLayer::optimizeMoveGroups from 0x488c74 to 0x488e7c (520 bytes)
//
// 2 xrefs:
// > LevelEditorLayer::onResumePlaytest @ 0x36e934
// > GJBaseGameLayer::updateSpecialGroupData @ 0x4952da
//
// 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
//
void GJBaseGameLayer::optimizeMoveGroups(GJBaseGameLayer *a1)
{
cocos2d::CCArray *m_objects; // r3
cocos2d::ccArray *data; // r3
cocos2d::CCObject **arr; // r8
_DWORD *v5; // r4
_DWORD *v6; // t1
GameObject *MainObject; // r1
cocos2d::CCArray *Group; // r0
cocos2d::ccArray *v9; // r2
cocos2d::CCObject **v10; // r4
cocos2d::CCObject **v11; // r10
GameObject *v12; // r1
GameObject *v13; // t1
int v14; // r3
char *v15; // r0
std::set *v16; // r1
int v17; // r3
cocos2d::CCObject **v18; // [sp+0h] [bp-74h]
char v19; // [sp+Ch] [bp-68h] BYREF
char v20[8]; // [sp+14h] [bp-60h] BYREF
char v21; // [sp+1Ch] [bp-58h] BYREF
char v22[8]; // [sp+24h] [bp-50h] BYREF
char v23; // [sp+2Ch] [bp-48h] BYREF
char v24[8]; // [sp+34h] [bp-40h] BYREF
char v25[8]; // [sp+3Ch] [bp-38h] BYREF
char v26; // [sp+44h] [bp-30h] BYREF
_DWORD v27[2]; // [sp+4Ch] [bp-28h] BYREF
_DWORD v28[2]; // [sp+54h] [bp-20h] BYREF
std::set v29; // [sp+5Ch] [bp-18h] BYREF
std::set v30; // [sp+74h] [bp+0h] BYREF
std::_Rb_tree,std::less,std::allocator>::_Rb_tree_impl,true>::_Rb_tree_impl(&v29);
std::_Rb_tree,std::less,std::allocator>::_Rb_tree_impl,true>::_Rb_tree_impl(&v30);
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
if ( data->num )
{
arr = data->arr;
v18 = &arr[data->num] + 0x3FFFFFFF;
while ( 1 )
{
while ( 1 )
{
if ( arr > v18 )
goto LABEL_2;
v6 = *arr++;
v5 = v6;
if ( !v6 )
goto LABEL_2;
v14 = v5[221];
if ( v14 == 2915 )
{
v15 = (char *)v27;
v28[0] = v5[319];
LABEL_23:
v16 = &v29;
goto LABEL_24;
}
if ( v14 <= 2915 )
break;
if ( v14 == 3016 )
goto LABEL_33;
if ( v14 > 3016 )
{
if ( v14 == 3661 )
{
LABEL_33:
v15 = &v19;
v28[0] = v5[320];
goto LABEL_23;
}
}
else if ( (unsigned int)(v14 - 3006) <= 2 )
{
v17 = v5[338];
if ( !v17 )
v17 = v5[320];
v27[0] = v17;
if ( v17 > 0 )
std::_Rb_tree,std::less,std::allocator>::_M_insert_unique(
(int)v28,
(int)&v29,
v27);
}
}
if ( v14 == 1346 )
break;
if ( v14 > 1346 )
{
if ( v14 == 1347 )
goto LABEL_33;
if ( v14 == 2067 )
{
v28[0] = v5[320];
std::set::insert((int)v20, &v29, v28);
v15 = &v21;
v16 = &v30;
v28[0] = v5[319];
LABEL_24:
std::set::insert((int)v15, v16, v28);
}
}
else if ( v14 == 901 )
{
v28[0] = v5[320];
std::set::insert((int)v22, &v29, v28);
v15 = &v23;
v28[0] = v5[335];
goto LABEL_28;
}
}
v28[0] = v5[319];
std::set::insert((int)v24, &v30, v28);
v28[0] = v5[320];
std::set::insert((int)v25, &v29, v28);
v15 = &v26;
v28[0] = v5[342];
LABEL_28:
v16 = &v29;
goto LABEL_24;
}
}
LABEL_2:
GJBaseGameLayer::addRemapTargets(a1, &v29);
v28[0] = v29._M_t._M_impl._M_header._M_left;
while ( (std::_Rb_tree_node_base *)v28[0] != &v29._M_t._M_impl._M_header )
{
MainObject = GJBaseGameLayer::tryGetMainObject(a1, *(_DWORD *)(v28[0] + 16));
if ( MainObject )
GJBaseGameLayer::moveObjectToStaticGroup(a1, MainObject);
std::_Rb_tree_const_iterator::operator++(v28);
}
GJBaseGameLayer::addRemapTargets(a1, &v30);
v28[0] = v30._M_t._M_impl._M_header._M_left;
while ( (std::_Rb_tree_node_base *)v28[0] != &v30._M_t._M_impl._M_header )
{
Group = GJBaseGameLayer::getGroup(a1, *(_DWORD *)(v28[0] + 16));
if ( Group )
{
v9 = Group->data;
if ( v9->num )
{
v10 = v9->arr;
v11 = &v10[v9->num] + 0x3FFFFFFF;
while ( v10 <= v11 )
{
v13 = (GameObject *)*v10++;
v12 = v13;
if ( !v13 )
break;
GJBaseGameLayer::moveObjectToStaticGroup(a1, v12);
}
}
}
std::_Rb_tree_const_iterator::operator++(v28);
}
std::_Rb_tree,std::less,std::allocator>::~_Rb_tree((int)&v30);
std::_Rb_tree,std::less,std::allocator>::~_Rb_tree((int)&v29);
}