//
// EditorUI::createGradientFromSelection from 0x7ca8ec to 0x7caff8 (1804 bytes)
//
// 3 xrefs:
// > EditorUI::handleEditorAction @ 0xbd76a0
// > EditorCommandsPopup::onCommand @ 0xcbbfe0
// > ??> @ 0xd8c58
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:54:11 +0000
//
__int64 __fastcall EditorUI::createGradientFromSelection(EditorUI *this)
{
cocos2d::CCArray *v2; // x24
int v3; // w23
cocos2d::CCArray *v4; // x0
float v5; // s9
float v6; // s10
unsigned int v7; // w19
float v8; // s8
__int64 v9; // x0
cocos2d::CCArray *v10; // x25
__int64 v11; // x26
GameObject *v12; // x28
__int64 v13; // x19
__int64 v14; // x25
float v15; // s11
float v16; // s11
__int64 v17; // x0
LevelEditorLayer *v18; // x0
unsigned int NextFreeGroupID; // w24
_QWORD *v20; // x0
_QWORD *v21; // x27
void *v22; // x0
LevelEditorLayer *v23; // x0
unsigned int v24; // w27
_QWORD *v25; // x0
_QWORD *v26; // x28
void *v27; // x0
GameObject *v28; // x1
unsigned int v29; // w26
LevelEditorLayer *v30; // x0
unsigned int v31; // w27
_QWORD *v32; // x0
_QWORD *v33; // x28
void *v34; // x0
GameObject *v35; // x1
unsigned int v36; // w25
LevelEditorLayer *v37; // x0
unsigned int v38; // w27
_QWORD *v39; // x0
_QWORD *v40; // x28
void *v41; // x0
GameObject *v42; // x1
unsigned int v43; // w19
float *Object; // x23
LevelEditorLayer *v45; // x0
_QWORD *v46; // x0
_QWORD *v47; // x20
void *v48; // x0
GameObject *v50; // x0
GameObject *v51; // x0
char v52; // [xsp+8Ch] [xbp+8Ch]
_BYTE v53[8]; // [xsp+98h] [xbp+98h] BYREF
__int64 v54; // [xsp+A0h] [xbp+A0h] BYREF
__int64 v55; // [xsp+A8h] [xbp+A8h] BYREF
__int64 v56; // [xsp+B0h] [xbp+B0h]
void *v57; // [xsp+B8h] [xbp+B8h]
void *v58; // [xsp+C0h] [xbp+C0h] BYREF
__int64 v59; // [xsp+C8h] [xbp+C8h]
void *v60; // [xsp+D0h] [xbp+D0h]
__int64 v61; // [xsp+D8h] [xbp+D8h]
float v62; // [xsp+E0h] [xbp+E0h]
v2 = *((cocos2d::CCArray **)this + 112);
v3 = cocos2d::CCArray::count(v2);
v4 = (cocos2d::CCArray *)(unsigned int)(v3 - 2);
if ( ((unsigned int)v4 & 0xFFFFFFFD) != 0 )
{
v55 = 0;
v56 = 0;
v57 = nullptr;
std::string::__init(&v55, "Create gradient failed.", 0x17u);
EditorUI::showTextAlert((int)this, (int)&v55);
goto LABEL_48;
}
v5 = 0.0;
if ( v3 <= 0 )
{
v6 = 0.0;
v8 = 0.0;
LABEL_13:
v10 = (cocos2d::CCArray *)cocos2d::CCArray::create(v4);
cocos2d::CCArray::addObjectsFromArray(v10, v2);
qsort(
*(void **)(*((_QWORD *)v10 + 7) + 16LL),
**((unsigned int **)v10 + 7),
8u,
(int (*)(const void *, const void *))alignYSort);
v11 = cocos2d::CCArray::objectAtIndex(v10, 0);
v12 = (GameObject *)cocos2d::CCArray::objectAtIndex(v10, 1u);
v13 = cocos2d::CCArray::objectAtIndex(v10, 2u);
v14 = cocos2d::CCArray::objectAtIndex(v10, 3u);
(*(void (__fastcall **)(__int64 *__return_ptr, __int64))(*(_QWORD *)v11 + 1360LL))(&v54, v11);
v15 = *(float *)&v54;
(*(void (__fastcall **)(void **__return_ptr, GameObject *))(*(_QWORD *)v12 + 1360LL))(&v58, v12);
if ( v15 <= *(float *)&v58 || (GameObject *)v11 == v12 )
{
v50 = (GameObject *)v11;
v11 = (__int64)v12;
v12 = v50;
}
(*(void (__fastcall **)(__int64 *__return_ptr, __int64))(*(_QWORD *)v13 + 1360LL))(&v54, v13);
v16 = *(float *)&v54;
(*(void (__fastcall **)(void **__return_ptr, __int64))(*(_QWORD *)v14 + 1360LL))(&v58, v14);
if ( v16 <= *(float *)&v58 || v13 == v14 )
{
v17 = v14;
v14 = v13;
v13 = v17;
}
v52 = 1;
LABEL_18:
v18 = *((LevelEditorLayer **)this + 180);
v58 = nullptr;
v59 = 0;
v60 = nullptr;
v61 = 0;
v62 = 1.0;
NextFreeGroupID = LevelEditorLayer::getNextFreeGroupID(v18, (__int64)&v58);
v20 = v60;
if ( v60 )
{
do
{
v21 = (_QWORD *)*v20;
operator delete(v20);
v20 = v21;
}
while ( v21 );
}
v22 = v58;
v58 = nullptr;
if ( v22 )
operator delete(v22);
LevelEditorLayer::addObjectToGroup(*((LevelEditorLayer **)this + 180), v12, NextFreeGroupID);
if ( v11 )
{
v23 = *((LevelEditorLayer **)this + 180);
v58 = nullptr;
v59 = 0;
v60 = nullptr;
v61 = 0;
v62 = 1.0;
v24 = LevelEditorLayer::getNextFreeGroupID(v23, (__int64)&v58);
v25 = v60;
if ( v60 )
{
do
{
v26 = (_QWORD *)*v25;
operator delete(v25);
v25 = v26;
}
while ( v26 );
}
v27 = v58;
v58 = nullptr;
if ( v27 )
operator delete(v27);
v28 = (GameObject *)v11;
v29 = v24;
LevelEditorLayer::addObjectToGroup(*((LevelEditorLayer **)this + 180), v28, v24);
}
else
{
v29 = 0;
}
goto LABEL_28;
}
v6 = 0.0;
v7 = 0;
v8 = 0.0;
do
{
v9 = cocos2d::CCArray::objectAtIndex(v2, v7);
v4 = (cocos2d::CCArray *)(*(_QWORD *(__fastcall **)(void **__return_ptr))(*(_QWORD *)v9 + 1360LL))(&v58);
if ( v7 )
{
if ( *(float *)&v58 < v8 )
v8 = *(float *)&v58;
if ( *(float *)&v58 > v6 )
v6 = *(float *)&v58;
if ( *((float *)&v58 + 1) > v5 )
v5 = *((float *)&v58 + 1);
}
else
{
v5 = *((float *)&v58 + 1);
v8 = *(float *)&v58;
v6 = *(float *)&v58;
}
++v7;
}
while ( v3 != v7 );
if ( v3 != 2 )
goto LABEL_13;
v12 = (GameObject *)cocos2d::CCArray::objectAtIndex(v2, 0);
v11 = cocos2d::CCArray::objectAtIndex(v2, 1u);
(*(void (__fastcall **)(__int64 *__return_ptr, GameObject *))(*(_QWORD *)v12 + 1360LL))(&v54, v12);
(*(void (__fastcall **)(void **__return_ptr, __int64))(*(_QWORD *)v11 + 1360LL))(&v58, v11);
if ( vabds_f32(*(float *)&v54, *(float *)&v58) <= vabds_f32(*((float *)&v54 + 1), *((float *)&v58 + 1)) )
{
if ( *((float *)&v54 + 1) < *((float *)&v58 + 1) )
{
v51 = v12;
v12 = (GameObject *)v11;
v11 = (__int64)v51;
}
v52 = 0;
v13 = 0;
v14 = 0;
goto LABEL_18;
}
if ( *(float *)&v54 > *(float *)&v58 )
{
v14 = v11;
v13 = (__int64)v12;
v52 = 0;
v29 = 0;
NextFreeGroupID = 0;
goto LABEL_29;
}
v13 = v11;
v14 = (__int64)v12;
NextFreeGroupID = 0;
v52 = 0;
v29 = 0;
LABEL_28:
if ( v14 )
{
LABEL_29:
v30 = *((LevelEditorLayer **)this + 180);
v58 = nullptr;
v59 = 0;
v60 = nullptr;
v61 = 0;
v62 = 1.0;
v31 = LevelEditorLayer::getNextFreeGroupID(v30, (__int64)&v58);
v32 = v60;
if ( v60 )
{
do
{
v33 = (_QWORD *)*v32;
operator delete(v32);
v32 = v33;
}
while ( v33 );
}
v34 = v58;
v58 = nullptr;
if ( v34 )
operator delete(v34);
v35 = (GameObject *)v14;
v36 = v31;
LevelEditorLayer::addObjectToGroup(*((LevelEditorLayer **)this + 180), v35, v31);
goto LABEL_34;
}
v36 = 0;
LABEL_34:
if ( v13 )
{
v37 = *((LevelEditorLayer **)this + 180);
v58 = nullptr;
v59 = 0;
v60 = nullptr;
v61 = 0;
v62 = 1.0;
v38 = LevelEditorLayer::getNextFreeGroupID(v37, (__int64)&v58);
v39 = v60;
if ( v60 )
{
do
{
v40 = (_QWORD *)*v39;
operator delete(v39);
v39 = v40;
}
while ( v40 );
}
v41 = v58;
v58 = nullptr;
if ( v41 )
operator delete(v41);
v42 = (GameObject *)v13;
v43 = v38;
LevelEditorLayer::addObjectToGroup(*((LevelEditorLayer **)this + 180), v42, v38);
}
else
{
v43 = 0;
}
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v53, (float)(v8 + v6) * 0.5, v5 + 60.0);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v54, (const cocos2d::CCPoint *)v53);
EditorUI::getGridSnappedPos((__int64)this, (float *)&v54, (__int64)&v58);
cocos2d::CCPoint::operator=(v53, &v58);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v58, (const cocos2d::CCPoint *)v53);
Object = EditorUI::createObject((__int64)this, 0xB57u, (const cocos2d::CCPoint *)&v58);
if ( Object )
{
v45 = *((LevelEditorLayer **)this + 180);
v58 = nullptr;
v59 = 0;
v60 = nullptr;
v61 = 0;
v62 = 1.0;
*((_DWORD *)Object + 462) = LevelEditorLayer::getNextFreeGradientID(v45, (__int64)&v58);
v46 = v60;
if ( v60 )
{
do
{
v47 = (_QWORD *)*v46;
operator delete(v46);
v46 = v47;
}
while ( v47 );
}
v48 = v58;
v58 = nullptr;
if ( v48 )
operator delete(v48);
*((_BYTE *)Object + 1868) = v52;
*((_DWORD *)Object + 463) = NextFreeGroupID;
*((_DWORD *)Object + 464) = v29;
*((_DWORD *)Object + 465) = v36;
*((_DWORD *)Object + 466) = v43;
LevelEditorLayer::refreshSpecial(*((LevelEditorLayer **)this + 180), (GameObject *)Object);
EditorUI::deselectAll(this);
EditorUI::selectObject(this, (GameObject *)Object, 1);
EditorUI::updateSelectionUI(this);
return _stack_chk_guard;
}
v55 = 0;
v56 = 0;
v57 = nullptr;
std::string::__init(&v55, "Create gradient failed.", 0x17u);
EditorUI::showTextAlert((int)this, (int)&v55);
LABEL_48:
if ( (v55 & 1) != 0 )
operator delete(v57);
return _stack_chk_guard;
}