//
// GJBaseGameLayer::optimizeMoveGroups from 0x1001dff04 to 0x1001e020c (776 bytes)
//
// 2 xrefs:
// > GJBaseGameLayer::updateSpecialGroupData @ 0x1001dfbe4
// > LevelEditorLayer::onResumePlaytest @ 0x1003631d8
//
// 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 __fastcall GJBaseGameLayer::optimizeMoveGroups(GJBaseGameLayer *a1)
{
cocos2d::CCArray *m_objects; // x8
cocos2d::ccArray *data; // x9
__int64 num; // x8
cocos2d::CCObject **arr; // x22
unsigned __int64 v6; // x23
cocos2d::CCObject *v7; // x24
int m_uReference; // w8
int m_eObjType; // w8
std::__tree::__iter_pointer begin_node; // x22
GameObject *MainObject; // x1
std::set *left; // x9
std::set *v13; // x8
bool v14; // zf
std::__tree::__iter_pointer v15; // x21
cocos2d::CCArray *Group; // x0
cocos2d::ccArray *v17; // x9
__int64 v18; // x8
GameObject **v19; // x22
unsigned __int64 v20; // x23
std::set *v21; // x9
std::set *v22; // x8
unsigned int m_nLuaID; // [xsp+Ch] [xbp-64h] BYREF
std::set v24; // [xsp+10h] [xbp-60h] BYREF
std::set v25; // [xsp+28h] [xbp-48h] BYREF
v25.__tree_.__pair1_.__value_.__left_ = nullptr;
v25.__tree_.__pair3_.__value_ = 0;
v24.__tree_.__pair3_.__value_ = 0;
v25.__tree_.__begin_node_ = &v25.__tree_.__pair1_.__value_;
v24.__tree_.__begin_node_ = &v24.__tree_.__pair1_.__value_;
v24.__tree_.__pair1_.__value_.__left_ = nullptr;
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
v6 = (unsigned __int64)&arr[num - 1];
while ( 1 )
{
v7 = *arr;
if ( !*arr )
goto LABEL_25;
m_uReference = v7[18].m_uReference;
if ( m_uReference <= 3005 )
break;
if ( (unsigned int)(m_uReference - 3006) < 3 )
{
m_eObjType = v7[27].m_eObjType;
if ( !m_eObjType )
m_eObjType = v7[26].m_nLuaID;
m_nLuaID = m_eObjType;
if ( m_eObjType >= 1 )
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
goto LABEL_24;
}
if ( m_uReference == 3661 || m_uReference == 3016 )
goto LABEL_18;
LABEL_24:
if ( (unsigned __int64)++arr > v6 )
goto LABEL_25;
}
if ( m_uReference <= 1346 )
{
if ( m_uReference == 901 )
{
m_nLuaID = v7[26].m_nLuaID;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
m_nLuaID = v7[27].m_nTag;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
}
else if ( m_uReference == 1346 )
{
m_nLuaID = v7[26].m_uID;
sub_1000B4D20((__int64)&v24, (int *)&m_nLuaID, &m_nLuaID);
m_nLuaID = v7[26].m_nLuaID;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
m_nLuaID = v7[27].m_nZOrder;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
}
goto LABEL_24;
}
if ( m_uReference != 1347 )
{
if ( m_uReference == 2067 )
{
m_nLuaID = v7[26].m_nLuaID;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
m_nLuaID = v7[26].m_uID;
sub_1000B4D20((__int64)&v24, (int *)&m_nLuaID, &m_nLuaID);
}
else if ( m_uReference == 2915 )
{
m_nLuaID = v7[26].m_uID;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
}
goto LABEL_24;
}
LABEL_18:
m_nLuaID = v7[26].m_nLuaID;
sub_1000B4D20((__int64)&v25, (int *)&m_nLuaID, &m_nLuaID);
goto LABEL_24;
}
}
LABEL_25:
GJBaseGameLayer::addRemapTargets(a1, &v25);
begin_node = v25.__tree_.__begin_node_;
if ( (std::__compressed_pair *>> *)v25.__tree_.__begin_node_ != &v25.__tree_.__pair1_ )
{
do
{
MainObject = GJBaseGameLayer::tryGetMainObject(a1, HIDWORD(begin_node[3].__left_));
if ( MainObject )
GJBaseGameLayer::moveObjectToStaticGroup(a1, MainObject);
left = (std::set *)begin_node[1].__left_;
if ( left )
{
do
{
v13 = left;
left = (std::set *)left->__tree_.__begin_node_;
}
while ( left );
}
else
{
do
{
v13 = (std::set *)begin_node[2].__left_;
v14 = v13->__tree_.__begin_node_ == begin_node;
begin_node = (std::__tree::__iter_pointer)v13;
}
while ( !v14 );
}
begin_node = (std::__tree::__iter_pointer)v13;
}
while ( v13 != (std::set *)&v25.__tree_.__pair1_ );
}
GJBaseGameLayer::addRemapTargets(a1, &v24);
v15 = v24.__tree_.__begin_node_;
if ( (std::__compressed_pair *>> *)v24.__tree_.__begin_node_ != &v24.__tree_.__pair1_ )
{
do
{
Group = GJBaseGameLayer::getGroup(a1, HIDWORD(v15[3].__left_));
if ( Group )
{
v17 = Group->data;
v18 = v17->num;
if ( (_DWORD)v18 )
{
v19 = (GameObject **)v17->arr;
v20 = (unsigned __int64)&v19[v18 - 1];
do
{
if ( !*v19 )
break;
GJBaseGameLayer::moveObjectToStaticGroup(a1, *v19++);
}
while ( (unsigned __int64)v19 <= v20 );
}
}
v21 = (std::set *)v15[1].__left_;
if ( v21 )
{
do
{
v22 = v21;
v21 = (std::set *)v21->__tree_.__begin_node_;
}
while ( v21 );
}
else
{
do
{
v22 = (std::set *)v15[2].__left_;
v14 = v22->__tree_.__begin_node_ == v15;
v15 = (std::__tree::__iter_pointer)v22;
}
while ( !v14 );
}
v15 = (std::__tree::__iter_pointer)v22;
}
while ( v22 != (std::set *)&v24.__tree_.__pair1_ );
}
sub_100017D70((__int64)&v24, (_QWORD *)v24.__tree_.__pair1_.__value_.__left_);
sub_100017D70((__int64)&v25, (_QWORD *)v25.__tree_.__pair1_.__value_.__left_);
}