//
// EditorUI::alignObjects from 0x140121f20 to 0x1401223e0 (1216 bytes)
//
// 3 xrefs:
// > EditorPauseLayer::onAlignX @ 0x1400dcf3a
// > EditorPauseLayer::onAlignY @ 0x1400dcf6a
// > ??> @ 0x1406c9798
//
// 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
//
// Hidden C++ exception states: #wind=1
void EditorUI::alignObjects(EditorUI *a1, cocos2d::CCArray *a2, bool a3)
{
unsigned int v5; // eax
cocos2d::CCArray *v6; // rax
cocos2d::CCDictionary *v7; // rsi
unsigned int v8; // edi
struct cocos2d::CCObject *v9; // rbx
__int64 m_unknown2; // rbx
struct cocos2d::CCObject *v11; // rax
cocos2d::CCArray *v12; // r12
unsigned int v13; // esi
unsigned int i; // r15d
int v15; // ebx
struct cocos2d::CCObject *v16; // rax
EditorUI *v17; // rcx
GameObject *v18; // rax
GameObject *v19; // rdi
GameObject_vtbl *v20; // rbx
__int64 v21; // rax
cocos2d::ccArray *data; // rcx
bool v23; // si
size_t num; // rdx
cocos2d::CCObject **arr; // rcx
int (__cdecl *v26)(const void *, const void *); // r9
UndoCommand v27; // edx
char v28; // di
cocos2d::ccArray *v29; // rbx
__int64 v30; // rax
cocos2d::CCObject **v31; // rbx
cocos2d::CCObject **j; // rsi
GameObject *v33; // rbx
float v34; // xmm1_4
float y; // xmm2_4
float x; // xmm1_4
int *p_m_unknown2; // rcx
__int64 v38; // rax
cocos2d::CCArray *v39; // rax
cocos2d::CCArray *v40; // rsi
unsigned int v41; // edi
GameObject *v42; // rbx
cocos2d::CCPoint v43; // rax
cocos2d::CCPoint v44; // [rsp+20h] [rbp-50h] BYREF
cocos2d::CCArray v45; // [rsp+28h] [rbp-48h] BYREF
cocos2d::CCPoint v46; // [rsp+B8h] [rbp+48h] BYREF
bool v47; // [rsp+C0h] [rbp+50h]
cocos2d::CCPoint v48; // [rsp+C8h] [rbp+58h] BYREF
if ( a2 )
{
v47 = a3;
if ( cocos2d::CCArray::count(a2) >= 3 )
{
v5 = cocos2d::CCArray::count(a2);
v6 = cocos2d::CCArray::createWithCapacity(v5);
cocos2d::CCArray::addObjectsFromArray(v6, a2);
v7 = (cocos2d::CCDictionary *)cocos2d::CCDictionary::create();
v8 = 0;
while ( v8 < cocos2d::CCArray::count(a2) )
{
v9 = cocos2d::CCArray::objectAtIndex(a2, v8);
if ( v9[15].m_unknown2 <= 0 )
{
++v8;
}
else
{
cocos2d::CCArray::removeObjectAtIndex(a2, v8, 1);
if ( !cocos2d::CCDictionary::objectForKey(v7, v9[15].m_unknown2) )
{
m_unknown2 = v9[15].m_unknown2;
v11 = (struct cocos2d::CCObject *)cocos2d::CCNode::create();
cocos2d::CCDictionary::setObject(v7, v11, m_unknown2);
}
}
}
v12 = cocos2d::CCDictionary::allKeys(v7);
v13 = 0;
for ( i = 1; v13 < cocos2d::CCArray::count(v12); ++v13 )
{
v15 = (int)cocos2d::CCArray::objectAtIndex(v12, v13)[1].__vftable;
v16 = cocos2d::CCDictionary::objectForKey(a1->m_editorLayer->m_linkedGroupDict, v15);
if ( v16 )
{
EditorUI::getGroupCenter(v17, &v45, (bool)v16);
*(_QWORD *)&v45.m_uAutoReleaseCount = operator new(0x550u);
v18 = GameObject::GameObject(*(GameObject **)&v45.m_uAutoReleaseCount);
v19 = v18;
if ( v18 )
{
v18->m_eObjType = GameObjectObjectType;
if ( cocos2d::CCSprite::initWithSpriteFrameName(v18, "checkpoint_01_001.png") )
{
GameObject::commonSetup(v19);
v19->m_bUnkBool2 = 1;
cocos2d::CCObject::autorelease(v19);
}
else
{
((void (__fastcall *)(GameObject *, __int64))v19->~GameObject)(v19, 1);
v19 = nullptr;
}
}
v19->m_objectID = 44;
v19->m_linkedGroup = v15;
v20 = v19->CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v45.m_nTag);
((void (__fastcall *)(GameObject *, __int64))v20->setStartPos)(v19, v21);
cocos2d::CCArray::addObject(a2, v19);
}
}
data = a2->data;
v23 = v47;
num = data->num;
arr = data->arr;
v26 = (int (__cdecl *)(const void *, const void *))sub_1400DF250;
if ( !v47 )
v26 = (int (__cdecl *)(const void *, const void *))sub_1400DF200;
qsort(arr, num, 8u, v26);
cocos2d::CCPoint::CCPoint(&v46);
cocos2d::CCPoint::CCPoint(&v48);
v28 = 1;
v29 = a2->data;
v30 = v29->num;
if ( (_DWORD)v30 )
{
v31 = v29->arr;
for ( j = &v31[v30 - 1]; v31 <= j; ++v31 )
{
if ( !*v31 )
break;
(*v31)->__vftable[2].getTag(*v31);
cocos2d::CCPoint::CCPoint(&v44);
if ( v28 )
{
v28 = 0;
cocos2d::CCPoint::operator=(&v46, &v44);
cocos2d::CCPoint::operator=(&v48, &v44);
}
else
{
if ( v46.x > v44.x )
v46.x = v44.x;
if ( v44.x > v48.x )
v48.x = v44.x;
if ( v46.y > v44.y )
v46.y = v44.y;
if ( v44.y > v48.y )
v48.y = v44.y;
}
}
v23 = v47;
}
if ( v46.x != v48.x || v46.y != v48.y )
{
EditorUI::createUndoObject(a1, v27, 0);
cocos2d::CCPoint::operator-(&v48, &v45.m_uIndexInArray, &v46);
cocos2d::CCArray::count(a2);
cocos2d::CCPoint::operator*(&v45.m_uIndexInArray, &v45.m_uID);
if ( cocos2d::CCArray::count(a2) - 1 > 1 )
{
do
{
v33 = (GameObject *)cocos2d::CCArray::objectAtIndex(a2, i);
v33->getPosition_0(v33);
cocos2d::CCPoint::CCPoint(&v44);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v45);
v34 = (float)(int)i;
if ( v23 )
{
y = (float)(v34 * *(float *)&v45.m_nLuaID) + v46.y;
x = v44.x;
p_m_unknown2 = &v45.m_unknown2;
}
else
{
x = (float)(v34 * *(float *)&v45.m_uID) + v46.x;
y = v44.y;
p_m_unknown2 = &v45.m_uOrderOfArrival;
}
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)p_m_unknown2, x, y);
cocos2d::CCPoint::operator=(&v45, v38);
cocos2d::CCPoint::operator-(&v45, &v45.m_nTag, &v44);
if ( v33->m_objectID == 44 )
{
v39 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(
a1->m_editorLayer->m_linkedGroupDict,
v33->m_linkedGroup);
v40 = v39;
if ( v39 )
{
v41 = 0;
if ( cocos2d::CCArray::count(v39) )
{
do
{
v42 = (GameObject *)cocos2d::CCArray::objectAtIndex(v40, v41);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v45.data);
EditorUI::moveObject(a1, v42, v43);
++v41;
}
while ( v41 < cocos2d::CCArray::count(v40) );
}
}
v23 = v47;
}
else
{
cocos2d::CCPoint::operator-(&v45, &v45.m_uAutoReleaseCount, &v44);
EditorUI::moveObject(a1, v33, (cocos2d::CCPoint)&v45.m_uAutoReleaseCount);
}
++i;
}
while ( i < cocos2d::CCArray::count(a2) - 1 );
}
}
}
}
}