//
// LevelTools::sortChannelOrderObjects from 0x14032d6b0 to 0x14032d92a (634 bytes)
//
// 8 xrefs:
// > GJBaseGameLayer::orderSpawnObjects @ 0x140245e17
// > LevelEditorLayer::updateGameObjects @ 0x1402dc634
// > LevelTools::sortSpeedObjects @ 0x14032da5c
// > LevelTools::sortSpeedObjects @ 0x14032dc96
// > ??> @ 0x140693af8
// > ??> @ 0x140693b10
// > ??> @ 0x140693b20
// > ??> @ 0x1406d4ed4
//
// 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 LevelTools::sortChannelOrderObjects(cocos2d::CCArray *a1, cocos2d::CCDictionary *a2, bool a3)
{
__int64 v5; // rax
__int64 v6; // rcx
cocos2d::ccArray *data; // rdi
cocos2d::CCDictionary *v8; // r12
__int64 num; // rdx
cocos2d::CCObject **arr; // rdi
cocos2d::CCObject **i; // r14
cocos2d::CCObject *v12; // rbx
__int64 m_uIndexInArray; // rsi
int ObjectDirection; // eax
struct cocos2d::CCInteger *v15; // rax
cocos2d::ccArray *v16; // rbx
__int64 v17; // rax
cocos2d::CCObject **v18; // rbx
cocos2d::CCObject **j; // r15
cocos2d::CCObject *v20; // rsi
__int64 v21; // r14
__int64 v22; // rcx
cocos2d::CCArray *v23; // rdi
unsigned int v24; // r14d
cocos2d::CCArray *v25; // rdi
unsigned int v26; // esi
__int64 v27; // r15
struct cocos2d::CCObject *v28; // rax
int v29; // ebx
cocos2d::CCObject_vtbl *v30; // rcx
int v31; // ebx
int v32; // ebx
int (__cdecl *v33)(const void *, const void *); // r9
struct cocos2d::CCObject *v34; // rax
struct cocos2d::CCArray *v35; // rax
if ( a1 )
{
v5 = cocos2d::CCDictionary::create(a1);
data = a1->data;
v8 = (cocos2d::CCDictionary *)v5;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( i = &arr[num - 1]; arr <= i; ++arr )
{
v12 = *arr;
if ( !*arr )
break;
if ( v12[18].m_eObjType == 2900 )
{
if ( LOBYTE(v12[33].m_eObjType) )
{
m_uIndexInArray = v12[33].m_uIndexInArray;
if ( !cocos2d::CCDictionary::objectForKey(v8, m_uIndexInArray) )
{
ObjectDirection = GameObject::getObjectDirection((GameObject *)v12);
v15 = cocos2d::CCInteger::create(ObjectDirection);
cocos2d::CCDictionary::setObject(v8, v15, m_uIndexInArray);
}
}
}
}
}
if ( !a2 )
a2 = (cocos2d::CCDictionary *)cocos2d::CCDictionary::create(v6);
v16 = a1->data;
v17 = v16->num;
if ( (_DWORD)v17 )
{
v18 = v16->arr;
for ( j = &v18[v17 - 1]; v18 <= j; ++v18 )
{
v20 = *v18;
if ( !*v18 )
break;
v21 = SLODWORD(v20[32].__vftable);
v23 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a2, v21);
if ( !v23 )
{
v23 = (cocos2d::CCArray *)cocos2d::CCArray::create(v22);
cocos2d::CCDictionary::setObject(a2, v23, v21);
}
cocos2d::CCArray::addObject(v23, v20);
}
}
v24 = 0;
v25 = cocos2d::CCDictionary::allKeys(a2);
v26 = 0;
if ( cocos2d::CCArray::count(v25) )
{
while ( 1 )
{
v27 = SLODWORD(cocos2d::CCArray::objectAtIndex(v25, v26)[1].__vftable);
v28 = cocos2d::CCDictionary::objectForKey(v8, v27);
if ( !v28 )
break;
v29 = (int)v28[1].__vftable;
v30 = cocos2d::CCDictionary::objectForKey(a2, v27)[1].__vftable;
v31 = v29 - 1;
if ( v31 )
{
v32 = v31 - 1;
if ( v32 )
{
if ( v32 != 1 )
goto LABEL_27;
v33 = (int (__cdecl *)(const void *, const void *))sub_140324D20;
}
else
{
v33 = (int (__cdecl *)(const void *, const void *))sub_140324E60;
}
}
else
{
v33 = (int (__cdecl *)(const void *, const void *))sub_140324DC0;
}
LABEL_28:
qsort(v30->isEqual, LODWORD(v30->copyWithZone), 8u, v33);
if ( ++v26 >= cocos2d::CCArray::count(v25) )
goto LABEL_29;
}
v30 = cocos2d::CCDictionary::objectForKey(a2, v27)[1].__vftable;
LABEL_27:
v33 = (int (__cdecl *)(const void *, const void *))sub_140324C80;
goto LABEL_28;
}
LABEL_29:
if ( a3 )
{
cocos2d::CCArray::removeAllObjects(a1);
LevelTools::moveTriggerObjectsToArray(a1, a2, 0);
if ( cocos2d::CCArray::count(v25) )
{
do
{
v34 = cocos2d::CCArray::objectAtIndex(v25, v24);
v35 = (struct cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a2, SLODWORD(v34[1].__vftable));
cocos2d::CCArray::addObjectsFromArray(a1, v35);
++v24;
}
while ( v24 < cocos2d::CCArray::count(v25) );
}
}
}
}