//
// LevelTools::sortChannelOrderObjects from 0x32c7bc to 0x32c97c (448 bytes)
//
// 4 xrefs:
// > LevelTools::sortSpeedObjects @ 0x32c9c4
// > LevelTools::sortSpeedObjects @ 0x32ca2a
// > LevelEditorLayer::updateGameObjects @ 0x375bac
// > GJBaseGameLayer::orderSpawnObjects @ 0x479008
//
// 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)
{
cocos2d::CCDictionary *v5; // r0
cocos2d::ccArray *data; // r2
cocos2d::CCDictionary *v7; // r9
cocos2d::CCObject **arr; // r7
cocos2d::CCObject **v9; // r11
int v10; // r8
int v11; // t1
cocos2d::ccArray *v12; // r2
cocos2d::CCObject **v13; // r7
cocos2d::CCObject **v14; // r8
int v15; // r11
int v16; // t1
unsigned int v17; // r8
cocos2d::CCArray *v18; // r7
intptr_t v19; // r11
cocos2d::CCObject *v20; // r0
int v21; // r10
cocos2d::CCObject_vtbl *v22; // r3
int (**v23)(const void *, const void *); // r2
unsigned int v24; // r6
int v25; // r0
cocos2d::CCArray *v26; // r0
intptr_t v27; // r10
cocos2d::CCObject *v28; // r8
intptr_t v29; // r10
cocos2d::CCArray *v30; // r3
int (*ObjectDirection)(const void *, const void *); // [sp+0h] [bp-Ch]
int (*v32)(const void *, const void *); // [sp+0h] [bp-Ch]
_BOOL4 v33; // [sp+4h] [bp-8h]
v33 = a3;
if ( !a1 )
return;
v5 = cocos2d::CCDictionary::create();
data = a1->data;
v7 = v5;
if ( data->num )
{
arr = data->arr;
v9 = &arr[data->num] + 0x3FFFFFFF;
while ( arr <= v9 )
{
v11 = (int)*arr++;
v10 = v11;
if ( !v11 )
break;
if ( *(_DWORD *)(v10 + 884) == 2900 )
{
if ( *(_BYTE *)(v10 + 1656) )
{
v27 = *(_DWORD *)(v10 + 1660);
if ( !cocos2d::CCDictionary::objectForKey(v7, v27) )
{
ObjectDirection = (int (*)(const void *, const void *))GameObject::getObjectDirection((GameObject *)v10);
v28 = (cocos2d::CCObject *)operator new(0x38u);
cocos2d::CCObject::CCObject(v28);
v28->__vftable = (cocos2d::CCObject_vtbl *)&off_A45350;
v28[1].__vftable = (cocos2d::CCObject_vtbl *)ObjectDirection;
cocos2d::CCObject::autorelease(v28);
cocos2d::CCDictionary::setObject(v7, v28, v27);
}
}
}
}
if ( a2 )
goto LABEL_8;
goto LABEL_7;
}
if ( !a2 )
{
LABEL_7:
a2 = cocos2d::CCDictionary::create();
LABEL_8:
v12 = a1->data;
if ( v12->num )
{
v13 = v12->arr;
v14 = &v13[v12->num] + 0x3FFFFFFF;
while ( v13 <= v14 )
{
v16 = (int)*v13++;
v15 = v16;
if ( !v16 )
break;
v29 = *(_DWORD *)(v15 + 1584);
v30 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a2, v29);
if ( !v30 )
{
v32 = (int (*)(const void *, const void *))cocos2d::CCArray::create(nullptr);
cocos2d::CCDictionary::setObject(a2, (cocos2d::CCObject *)v32, v29);
v30 = (cocos2d::CCArray *)v32;
}
cocos2d::CCArray::addObject(v30, (cocos2d::CCObject *)v15);
}
}
}
v17 = 0;
v18 = cocos2d::CCDictionary::allKeys(a2);
while ( v17 < cocos2d::CCArray::count(v18) )
{
v19 = *(_DWORD *)(cocos2d::CCArray::objectAtIndex(v18, v17) + 52);
v20 = cocos2d::CCDictionary::objectForKey(v7, v19);
if ( v20 )
v21 = (int)v20[1].__vftable;
else
v21 = 4;
v22 = cocos2d::CCDictionary::objectForKey(a2, v19)[1].__vftable;
switch ( v21 )
{
case 2:
v23 = (int (**)(const void *, const void *))&compOrderYInv;
break;
case 3:
v23 = (int (**)(const void *, const void *))&compOrderXInv;
break;
case 1:
v23 = (int (**)(const void *, const void *))&compOrderY;
break;
default:
v23 = (int (**)(const void *, const void *))&compOrder;
break;
}
++v17;
qsort(v22->isEqual, (size_t)v22->copyWithZone, 4u, *v23);
}
if ( v33 )
{
v24 = 0;
cocos2d::CCArray::removeAllObjects(a1);
LevelTools::moveTriggerObjectsToArray(a1, a2, 0);
while ( v24 < cocos2d::CCArray::count(v18) )
{
v25 = cocos2d::CCArray::objectAtIndex(v18, v24++);
v26 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a2, *(_DWORD *)(v25 + 52));
cocos2d::CCArray::addObjectsFromArray(a1, v26);
}
}
}