//
// LevelTools::sortSpeedObjects from 0x32c994 to 0x32cc04 (624 bytes)
//
// 2 xrefs:
// > PlayLayer::createObjectsFromSetupFinished @ 0x31ad12
// > DrawGridLayer::sortSpeedObjects @ 0x36a876
//
// 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::sortSpeedObjects(cocos2d::CCArray *a1, GJBaseGameLayer *a2)
{
cocos2d::ccArray *data; // r3
cocos2d::CCObject **arr; // r5
cocos2d::CCObject **v6; // r6
int v7; // r4
int v8; // t1
cocos2d::ccArray *v9; // r3
unsigned int num; // r4
cocos2d::CCObject **v11; // r3
cocos2d::CCObject **v12; // r2
_BOOL4 v13; // r7
cocos2d::CCObject **v14; // r6
int v15; // r4
int v16; // r5
int v17; // t1
cocos2d::CCArray *Group; // r0
cocos2d::CCArray *v19; // r10
int v20; // r1
int v21; // r2
int v22; // r2
int v23; // r7
bool v24; // zf
const cocos2d::CCRect *v25; // r0
float v26; // s15
float v27; // s15
int v28; // r1
bool v29[4]; // [sp+4h] [bp-38h]
cocos2d::CCPoint v30; // [sp+14h] [bp-28h] BYREF
cocos2d::CCPoint v31; // [sp+1Ch] [bp-20h] BYREF
cocos2d::CCRect v32; // [sp+24h] [bp-18h] BYREF
if ( cocos2d::CCArray::count(a1) )
{
if ( a1 )
{
data = a1->data;
if ( data->num )
{
arr = data->arr;
v6 = &arr[data->num] + 0x3FFFFFFF;
while ( arr <= v6 )
{
v8 = (int)*arr++;
v7 = v8;
if ( !v8 )
break;
(*(void (__fastcall **)(cocos2d::CCRect *, int))(*(_DWORD *)v7 + 900))(&v32, v7);
cocos2d::CCPoint::operator=(v7 + 1592, &v32);
if ( *(__int16 *)(v7 + 1590) == -5 )
{
Group = GJBaseGameLayer::getGroup(a2, *(_DWORD *)(v7 + 1276));
v19 = Group;
if ( Group && cocos2d::CCArray::count(Group) && (v20 = cocos2d::CCArray::randomObject(v19)) != 0 )
(*(void (__fastcall **)(cocos2d::CCRect *, int))(*(_DWORD *)v20 + 900))(&v32, v20);
else
(*(void (__fastcall **)(cocos2d::CCRect *, int))(*(_DWORD *)v7 + 900))(&v32, v7);
cocos2d::CCPoint::operator=(v7 + 1688, &v32);
}
}
}
}
LevelTools::sortChannelOrderObjects(a1, nullptr, (bool)&dword_0 + 1);
if ( a1 )
{
v9 = a1->data;
num = v9->num;
if ( v9->num )
{
v11 = v9->arr;
v12 = &v11[num] + 0x3FFFFFFF;
v13 = 0;
v14 = v11;
v15 = 0;
*(_DWORD *)v29 = v12;
while ( 1 )
{
if ( (unsigned int)v14 > *(_DWORD *)v29 )
goto LABEL_13;
v17 = (int)*v14++;
v16 = v17;
if ( !v17 )
goto LABEL_13;
v21 = *(_DWORD *)(v16 + 884);
if ( v21 != 1330 )
break;
LABEL_24:
v22 = *(__int16 *)(v16 + 1590);
if ( v22 == -4 )
{
if ( !*(_BYTE *)(v16 + 1657) )
{
v23 = *(_DWORD *)(v16 + 1636);
v13 = v23 == 3 || v23 == 4;
v15 = *(_DWORD *)(v16 + 1640);
if ( v15 != 1 )
v15 = v15 == 3;
}
}
else if ( v22 == -1 )
{
v15 = (unsigned __int8)v15 ^ 1;
}
}
if ( v21 > 1330 )
{
if ( v21 == 1704 )
goto LABEL_24;
if ( v21 > 1704 )
{
if ( v21 != 2902 )
{
if ( v21 == 3027 )
goto LABEL_24;
v28 = 1751;
goto LABEL_53;
}
}
else if ( v21 != 1334 )
{
if ( v21 == 1594 )
goto LABEL_24;
v28 = 1333;
goto LABEL_53;
}
}
else
{
if ( v21 == 141 )
goto LABEL_24;
if ( v21 <= 141 )
{
if ( v21 == 36 )
goto LABEL_24;
v24 = v21 == 84;
goto LABEL_54;
}
if ( v21 < 200 )
goto LABEL_39;
if ( v21 > 203 )
{
v28 = 1022;
LABEL_53:
v24 = v21 == v28;
LABEL_54:
if ( v24 )
goto LABEL_24;
LABEL_39:
if ( !*(_BYTE *)(v16 + 1284) )
goto LABEL_24;
}
}
if ( !*(_BYTE *)(v16 + 1286) )
{
v25 = (const cocos2d::CCRect *)(*(int (__fastcall **)(int))(*(_DWORD *)v16 + 656))(v16);
cocos2d::CCRect::CCRect(&v32, v25);
cocos2d::CCPoint::CCPoint(
&v30,
v32.origin.x + (float)(v32.size.width * 0.5),
v32.origin.y + (float)(v32.size.height * 0.5));
if ( v13 )
{
if ( v15 )
v27 = (float)(v30.y - (float)(v32.size.height * 0.5)) - 15.0;
else
v27 = (float)(v30.y + (float)(v32.size.height * 0.5)) + 15.0;
v30.y = v27;
}
else
{
if ( v15 )
v26 = (float)(v30.x + (float)(v32.size.width * 0.5)) + 15.0;
else
v26 = (float)(v30.x - (float)(v32.size.width * 0.5)) - 15.0;
v30.x = v26;
}
cocos2d::CCPoint::CCPoint(&v31, &v30);
cocos2d::CCPoint::operator=(v16 + 1592, &v31);
}
goto LABEL_24;
}
}
LABEL_13:
LevelTools::sortChannelOrderObjects(a1, nullptr, (bool)&dword_0 + 1);
}
}