//
// EditorUI::alignObjects from 0x39d29c to 0x39d5da (830 bytes)
//
// 2 xrefs:
// > EditorPauseLayer::onAlignX @ 0x3ff332
// > EditorPauseLayer::onAlignY @ 0x3ff352
//
// 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 EditorUI::alignObjects(EditorUI *a1, cocos2d::CCArray *a2, bool a3)
{
unsigned int v5; // r5
cocos2d::CCArray *v6; // r0
unsigned int v7; // r1
cocos2d::CCArray *v8; // r0
cocos2d::CCDictionary *v9; // r7
int v10; // r8
cocos2d::CCNode *v11; // r0
unsigned int v12; // r5
cocos2d::CCArray *v13; // r7
int v14; // r9
cocos2d::CCArray *StickyGroup; // r2
GameObject *v16; // r0
cocos2d::CCObject *v17; // r11
GameObject_vtbl *v18; // r2
cocos2d::ccArray *data; // r3
cocos2d::CCObject **arr; // r0
size_t num; // r1
int (*v22)(const void *, const void *); // r3
cocos2d::ccArray *v23; // r2
unsigned int v24; // r3
cocos2d::CCObject **v25; // r2
unsigned int v26; // r9
int v27; // r3
unsigned int v28; // r5
cocos2d::CCObject **v29; // r10
int v30; // r0
int v31; // t1
int v32; // r0
unsigned int v33; // r7
GameObject *v34; // r9
const cocos2d::CCPoint *v35; // r0
float v36; // s15
float x; // r1
float y; // r2
int v39; // r2
bool v40; // r3
cocos2d::CCArray *v41; // r9
unsigned int v42; // r11
GameObject *v43; // r0
cocos2d::CCPoint v44; // r2
cocos2d::CCPoint v45; // r2
const cocos2d::CCPoint *v46; // r0
int v47; // r2
int v48; // r2
bool v49; // r3
_BOOL4 v50; // [sp+0h] [bp-5Ch]
cocos2d::CCPoint *setStartPos; // [sp+4h] [bp-58h]
cocos2d::CCPoint *v52; // [sp+4h] [bp-58h]
GameObject *v53; // [sp+Ch] [bp-50h]
cocos2d::CCPoint v54; // [sp+14h] [bp-48h] BYREF
cocos2d::CCPoint v55; // [sp+1Ch] [bp-40h] BYREF
_BYTE v56[8]; // [sp+24h] [bp-38h] BYREF
float v57[2]; // [sp+2Ch] [bp-30h] BYREF
cocos2d::CCPoint v58; // [sp+34h] [bp-28h] BYREF
cocos2d::CCPoint v59; // [sp+3Ch] [bp-20h] BYREF
cocos2d::CCPoint v60; // [sp+44h] [bp-18h] BYREF
cocos2d::CCPoint v61; // [sp+4Ch] [bp-10h] BYREF
v50 = a3;
if ( a2 && cocos2d::CCArray::count(a2) > 2u )
{
v5 = 0;
v6 = (cocos2d::CCArray *)cocos2d::CCArray::count(a2);
v8 = (cocos2d::CCArray *)cocos2d::CCArray::createWithCapacity(v6, v7);
cocos2d::CCArray::addObjectsFromArray(v8, a2);
v9 = cocos2d::CCDictionary::create();
while ( v5 < cocos2d::CCArray::count(a2) )
{
v10 = cocos2d::CCArray::objectAtIndex(a2, v5);
if ( *(int *)(v10 + 732) <= 0 )
{
++v5;
}
else
{
cocos2d::CCArray::removeObjectAtIndex(a2, v5, 1);
if ( !cocos2d::CCDictionary::objectForKey(v9, *(_DWORD *)(v10 + 732)) )
{
v11 = cocos2d::CCNode::create();
cocos2d::CCDictionary::setObject(v9, v11, *(_DWORD *)(v10 + 732));
}
}
}
v12 = 0;
v13 = cocos2d::CCDictionary::allKeys(v9);
while ( v12 < cocos2d::CCArray::count(v13) )
{
v14 = *(_DWORD *)(cocos2d::CCArray::objectAtIndex(v13, v12) + 52);
StickyGroup = GJBaseGameLayer::getStickyGroup(a1->m_editorLayer, v14);
if ( StickyGroup )
{
EditorUI::getGroupCenter(&v60, a1, StickyGroup, 1);
v16 = GameObject::createWithFrame("checkpoint_01_001.png");
v16->m_objectID = 44;
v17 = v16;
v18 = v16->CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v16->m_linkedGroup = v14;
setStartPos = (cocos2d::CCPoint *)v18->setStartPos;
cocos2d::CCPoint::CCPoint(&v61, &v60);
((void (__fastcall *)(cocos2d::CCObject *, cocos2d::CCPoint *))setStartPos)(v17, &v61);
cocos2d::CCArray::addObject(a2, v17);
}
++v12;
}
data = a2->data;
arr = data->arr;
num = data->num;
if ( v50 )
v22 = (int (*)(const void *, const void *))alignYSort;
else
v22 = (int (*)(const void *, const void *))alignXSort;
qsort(arr, num, 4u, v22);
cocos2d::CCPoint::CCPoint(&v54);
cocos2d::CCPoint::CCPoint(&v55);
v23 = a2->data;
v24 = v23->num;
if ( v23->num )
{
v25 = v23->arr;
v26 = v24 + 0x3FFFFFFF;
v27 = 1;
v28 = (unsigned int)&v25[v26];
v29 = v25;
while ( (unsigned int)v29 <= v28 )
{
v31 = (int)*v29++;
v30 = v31;
if ( !v31 )
break;
v52 = (cocos2d::CCPoint *)v27;
v46 = (const cocos2d::CCPoint *)(*(int (__fastcall **)(int))(*(_DWORD *)v30 + 96))(v30);
cocos2d::CCPoint::CCPoint(&v61, v46);
if ( v52 )
{
cocos2d::CCPoint::operator=((PlayerObject *)&v54, COERCE_FLOAT(&v61), v47, (bool)v52);
cocos2d::CCPoint::operator=((PlayerObject *)&v55, COERCE_FLOAT(&v61), v48, v49);
}
else
{
if ( v61.x < v54.x )
v54.x = v61.x;
if ( v61.x > v55.x )
v55.x = v61.x;
if ( v61.y < v54.y )
v54.y = v61.y;
if ( v61.y > v55.y )
v55.y = v61.y;
}
v27 = 0;
}
}
if ( v54.x != v55.x || v54.y != v55.y )
{
EditorUI::createUndoObject(a1, Transform, 0);
cocos2d::CCPoint::operator-(v56, &v55, &v54);
v32 = cocos2d::CCArray::count(a2);
v33 = 1;
cocos2d::CCPoint::operator*(v57, v56, 1.0 / (float)(unsigned int)(v32 - 1));
while ( v33 < cocos2d::CCArray::count(a2) - 1 )
{
v34 = (GameObject *)cocos2d::CCArray::objectAtIndex(a2, v33);
v35 = v34->getPosition(v34);
cocos2d::CCPoint::CCPoint(&v58, v35);
cocos2d::CCPoint::CCPoint(&v59);
v36 = (float)(int)v33;
if ( v50 )
{
x = v58.x;
y = v54.y + (float)(v36 * v57[1]);
}
else
{
y = v58.y;
x = v54.x + (float)(v36 * v57[0]);
}
cocos2d::CCPoint::CCPoint(&v61, x, y);
cocos2d::CCPoint::operator=((PlayerObject *)&v59, COERCE_FLOAT(&v61), v39, v40);
cocos2d::CCPoint::operator-(&v60, &v59, &v58);
if ( v34->m_objectID == 44 )
{
v41 = GJBaseGameLayer::getStickyGroup(a1->m_editorLayer, v34->m_linkedGroup);
if ( v41 )
{
v42 = 0;
while ( v42 < cocos2d::CCArray::count(v41) )
{
v43 = (GameObject *)cocos2d::CCArray::objectAtIndex(v41, v42++);
v53 = v43;
cocos2d::CCPoint::CCPoint(&v61, &v60);
LODWORD(v44.x) = &v61;
EditorUI::moveObject(a1, v53, v44);
}
}
}
else
{
cocos2d::CCPoint::operator-(&v61, &v59, &v58);
LODWORD(v45.x) = &v61;
EditorUI::moveObject(a1, v34, v45);
}
++v33;
}
}
}
}