//
// LevelTools::sortSpeedObjects from 0x606748 to 0x606adc (916 bytes)
//
// 3 xrefs:
// > PlayLayer::createObjectsFromSetupFinished @ 0x5d7d6c
// > DrawGridLayer::sortSpeedObjects @ 0x665340
// > ??> @ 0x91788
//
// 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; // x1
cocos2d::ccArray *v5; // x1
cocos2d::CCObject **v6; // x20
cocos2d::CCObject **v7; // x27
cocos2d::CCObject *v8; // x19
unsigned int v9; // w25
unsigned int v10; // w21
int v11; // w0
const cocos2d::CCRect *v12; // x0
float v13; // s0
float v14; // s1
int m_eObjType_high; // w0
cocos2d::CCObject **arr; // x20
cocos2d::CCObject **v17; // x24
cocos2d::CCObject *i; // x19
float v19; // s0
float v20; // s1
cocos2d::CCArray *Group; // x0
cocos2d::CCArray *v22; // x26
float v23; // s0
float v24; // s1
__int64 v25; // x0
cocos2d::CCPoint v26; // [xsp+78h] [xbp+78h] BYREF
cocos2d::CCPoint v27; // [xsp+80h] [xbp+80h] BYREF
cocos2d::CCRect v28; // [xsp+88h] [xbp+88h] BYREF
if ( (unsigned int)cocos2d::CCArray::count(a1) )
{
if ( a1 )
{
data = a1->data;
if ( data->num )
{
arr = data->arr;
v17 = &arr[data->num - 1];
if ( arr <= v17 )
{
for ( i = *arr; *arr; i = *arr )
{
v19 = ((float (__fastcall *)(cocos2d::CCObject *))i->__vftable[22].update)(i);
cocos2d::CCPoint::operator=(&i[31].m_uIndexInArray, v19, v20);
if ( SHIWORD(i[31].m_eObjType) == -5 )
{
Group = GJBaseGameLayer::getGroup(a2, i[25].m_uOrderOfArrival);
v22 = Group;
if ( Group
&& (unsigned int)cocos2d::CCArray::count(Group)
&& (v25 = cocos2d::CCArray::randomObject(v22)) != 0 )
{
(*(void (__fastcall **)(__int64))(*(_QWORD *)v25 + 1800LL))(v25);
}
else
{
v23 = ((float (__fastcall *)(cocos2d::CCObject *))i->__vftable[22].update)(i);
}
cocos2d::CCPoint::operator=(&i[33].m_eObjType, v23, v24);
}
if ( v17 < ++arr )
break;
}
}
}
LevelTools::sortChannelOrderObjects(a1, nullptr, (bool)&dword_0 + 1);
v5 = a1->data;
if ( v5->num )
{
v6 = v5->arr;
v7 = &v6[v5->num - 1];
if ( v6 <= v7 )
{
v8 = *v6;
if ( *v6 )
{
v9 = 0;
v10 = 0;
while ( 1 )
{
v11 = HIDWORD(v8[18].__vftable);
if ( v11 == 1330 )
goto LABEL_20;
if ( v11 <= 1330 )
{
if ( v11 == 141 )
goto LABEL_20;
if ( v11 <= 141 )
{
if ( v11 == 36 || v11 == 84 )
goto LABEL_20;
LABEL_15:
if ( LOBYTE(v8[26].__vftable) )
goto LABEL_16;
goto LABEL_20;
}
if ( v11 < 200 )
goto LABEL_15;
if ( v11 <= 203 )
goto LABEL_16;
if ( v11 != 1022 )
goto LABEL_15;
}
else
{
if ( v11 == 1704 )
goto LABEL_20;
if ( v11 <= 1704 )
{
if ( v11 == 1334 )
goto LABEL_16;
if ( v11 == 1594 || v11 == 1333 )
goto LABEL_20;
goto LABEL_15;
}
if ( v11 == 2902 )
{
LABEL_16:
if ( !BYTE2(v8[26].__vftable) )
{
v12 = (const cocos2d::CCRect *)((__int64 (__fastcall *)(cocos2d::CCObject *))v8->__vftable[16].acceptVisitor)(v8);
cocos2d::CCRect::CCRect(&v28, v12);
cocos2d::CCPoint::CCPoint(
&v26,
v28.origin.x + (float)(v28.size.width * 0.5),
v28.origin.y + (float)(v28.size.height * 0.5));
if ( v9 >= (v10 ^ 1) )
{
if ( v10 <= v9 )
{
if ( v10 >= v9 )
{
if ( v9 && v10 )
v26.y = (float)(v26.y - (float)(v28.size.height * 0.5)) - 15.0;
}
else
{
v26.y = (float)(v26.y + (float)(v28.size.height * 0.5)) + 15.0;
}
}
else
{
v26.x = (float)(v26.x + (float)(v28.size.width * 0.5)) + 15.0;
}
}
else
{
v26.x = (float)(v26.x - (float)(v28.size.width * 0.5)) - 15.0;
}
cocos2d::CCPoint::CCPoint(&v27, &v26);
cocos2d::CCPoint::operator=(&v8[31].m_uIndexInArray, v13, v14);
}
goto LABEL_20;
}
if ( v11 != 3027 && v11 != 1751 )
goto LABEL_15;
}
LABEL_20:
m_eObjType_high = SHIWORD(v8[31].m_eObjType);
if ( m_eObjType_high == -4 )
{
if ( !BYTE1(v8[32].m_uOrderOfArrival) )
{
v9 = (unsigned int)(v8[32].m_eObjType - 3) <= 1;
v10 = (v8[32].m_uIndexInArray & 0xFFFFFFFD) == 1;
}
}
else if ( m_eObjType_high == -1 )
{
v10 ^= 1u;
}
if ( v7 >= ++v6 )
{
v8 = *v6;
if ( *v6 )
continue;
}
break;
}
}
}
}
}
else
{
LevelTools::sortChannelOrderObjects(nullptr, nullptr, (bool)&dword_0 + 1);
}
LevelTools::sortChannelOrderObjects(a1, nullptr, (bool)&dword_0 + 1);
}
}