//
// LevelTools::sortChannelOrderObjects from 0x1005023c0 to 0x100502681 (705 bytes)
//
// 5 xrefs:
// > LevelEditorLayer::updateGameObjects @ 0x1000dde6b
// > GJBaseGameLayer::orderSpawnObjects @ 0x1001624b7
// > LevelTools::sortSpeedObjects @ 0x1005027ae
// > LevelTools::sortSpeedObjects @ 0x100502a59
// > LevelTools::sortSpeedObjects @ 0x100502a68
//
// 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 LevelTools::sortChannelOrderObjects(cocos2d::CCArray *a1, cocos2d::CCDictionary *a2, bool a3)
{
cocos2d::ccArray *data; // rax
cocos2d::CCObject **arr; // r12
unsigned __int64 v5; // rbx
cocos2d::CCObject *v6; // r13
intptr_t m_nLuaID; // r15
cocos2d::CCObject *v8; // r13
cocos2d::CCDictionary *v9; // rax
cocos2d::ccArray *v10; // rax
cocos2d::CCObject **v11; // r12
unsigned __int64 v12; // r14
cocos2d::CCObject *v13; // r15
intptr_t m_unknown2; // r13
cocos2d::CCObject *v15; // rax
cocos2d::CCObject *v16; // rbx
cocos2d::CCArray *v17; // r13
unsigned int v18; // r15d
int (__cdecl *v19)(const void *, const void *); // rcx
intptr_t v20; // rbx
cocos2d::CCObject *v21; // rax
int v22; // r14d
cocos2d::CCObject *v23; // rax
unsigned int v24; // r15d
__int64 v25; // rax
cocos2d::CCObject *v26; // rax
cocos2d::CCDictionary *v28; // [rsp+18h] [rbp-38h]
int ObjectDirection; // [rsp+20h] [rbp-30h]
cocos2d::CCDictionary *v30; // [rsp+20h] [rbp-30h]
if ( a1 )
{
v28 = cocos2d::CCDictionary::create();
data = a1->data;
if ( data->num )
{
arr = data->arr;
v5 = (unsigned __int64)&arr[data->num - 1];
do
{
v6 = *arr;
if ( !*arr )
break;
if ( v6[18].m_uReference == 2900 && LOBYTE(v6[33].m_uID) == 1 )
{
m_nLuaID = v6[33].m_nLuaID;
if ( !cocos2d::CCDictionary::objectForKey(v28, m_nLuaID) )
{
ObjectDirection = GameObject::getObjectDirection((GameObject *)v6);
v8 = (cocos2d::CCObject *)operator new(0x40u);
cocos2d::CCObject::CCObject((__int64)v8);
v8->__vftable = (cocos2d::CCObject_vtbl *)off_1008B8348;
LODWORD(v8[1].__vftable) = ObjectDirection;
cocos2d::CCObject::autorelease(v8);
cocos2d::CCDictionary::setObject(v28, v8, m_nLuaID);
}
}
++arr;
}
while ( (unsigned __int64)arr <= v5 );
}
v9 = a2;
if ( !a2 )
v9 = cocos2d::CCDictionary::create();
v30 = v9;
v10 = a1->data;
if ( v10->num )
{
v11 = v10->arr;
v12 = (unsigned __int64)&v11[v10->num - 1];
do
{
v13 = *v11;
if ( !*v11 )
break;
m_unknown2 = v13[31].m_unknown2;
v15 = cocos2d::CCDictionary::objectForKey(v30, m_unknown2);
if ( !v15 )
{
v16 = (cocos2d::CCObject *)sub_10071F9E0(v30, m_unknown2);
cocos2d::CCDictionary::setObject(v30, v16, m_unknown2);
v15 = v16;
}
sub_10071FCD0(v15, v13);
++v11;
}
while ( (unsigned __int64)v11 <= v12 );
}
v17 = cocos2d::CCDictionary::allKeys(v30);
if ( (unsigned int)sub_100720070(v17) )
{
v18 = 0;
while ( 1 )
{
v20 = *(int *)(sub_1007200C0(v17, v18) + 56);
v21 = cocos2d::CCDictionary::objectForKey(v28, v20);
if ( !v21 )
break;
v22 = (int)v21[1].__vftable;
v23 = cocos2d::CCDictionary::objectForKey(v30, v20);
switch ( v22 )
{
case 1:
v19 = (int (__cdecl *)(const void *, const void *))sub_1004FB4A0;
break;
case 3:
v19 = (int (__cdecl *)(const void *, const void *))sub_1004FB410;
break;
case 2:
v19 = (int (__cdecl *)(const void *, const void *))sub_1004FB530;
break;
default:
goto LABEL_28;
}
LABEL_21:
qsort(v23[1].~CCObject_0, (size_t)v23[1].copyWithZone, 8u, v19);
if ( ++v18 >= (unsigned int)sub_100720070(v17) )
goto LABEL_30;
}
v23 = cocos2d::CCDictionary::objectForKey(v30, v20);
LABEL_28:
v19 = (int (__cdecl *)(const void *, const void *))sub_1004FB380;
goto LABEL_21;
}
LABEL_30:
if ( a3 )
{
sub_100720270(a1);
v24 = 0;
LevelTools::moveTriggerObjectsToArray(a1, v30, 0);
if ( (unsigned int)sub_100720070(v17) )
{
do
{
v25 = sub_1007200C0(v17, v24);
v26 = cocos2d::CCDictionary::objectForKey(v30, *(int *)(v25 + 56));
sub_100720050(a1, v26);
++v24;
}
while ( v24 < (unsigned int)sub_100720070(v17) );
}
}
}
}