//
// EditorUI::createGradientFromSelection from 0x4878a0 to 0x487bee (846 bytes)
//
// 2 xrefs:
// > EditorUI::handleEditorAction @ 0x6f2008
// > EditorCommandsPopup::onCommand @ 0x77a862
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 11:49:26 +0000
//
int __fastcall EditorUI::createGradientFromSelection(EditorUI *this)
{
cocos2d::CCArray *v2; // r4
cocos2d::CCArray *v3; // r0
cocos2d::CCArray *v4; // r8
float v5; // s16
signed int v6; // r7
float v7; // s18
float v8; // s17
int v9; // r0
GameObject *v10; // r9
GameObject *v11; // r4
GameObject *v12; // r3
GameObject *v13; // r8
GameObject *v14; // r11
char v15; // r7
size_t **v16; // r8
GameObject *v17; // r11
GameObject *v18; // r7
float v19; // s19
float v20; // s19
int v21; // r9
int v22; // r8
GameObject *Object; // r4
LevelEditorLayer *v25; // r0
int v26; // [sp+8h] [bp-4Ch]
int v27; // [sp+Ch] [bp-48h]
EditorUI *v28; // [sp+18h] [bp-3Ch] BYREF
_BYTE v29[8]; // [sp+1Ch] [bp-38h] BYREF
float v30; // [sp+24h] [bp-30h] BYREF
float v31; // [sp+28h] [bp-2Ch]
int v32; // [sp+2Ch] [bp-28h] BYREF
int v33; // [sp+30h] [bp-24h]
int v34; // [sp+34h] [bp-20h]
float v35; // [sp+38h] [bp-1Ch] BYREF
float v36; // [sp+3Ch] [bp-18h]
int v37; // [sp+40h] [bp-14h]
int v38; // [sp+44h] [bp-10h]
int v39; // [sp+48h] [bp-Ch]
v2 = *((cocos2d::CCArray **)this + 167);
v3 = (cocos2d::CCArray *)cocos2d::CCArray::count(v2);
v4 = v3;
if ( v3 != (cocos2d::CCArray *)((char *)&dword_0 + 2) && v3 != (cocos2d::CCArray *)&byte_4 )
{
v32 = 0;
v33 = 0;
v34 = 0;
std::string::__init(&v32, "Create gradient failed.", 0x17u);
EditorUI::showTextAlert((int)this, (int)&v32, 0, 1, 0);
return std::string::~string((int)&v32);
}
v5 = 0.0;
v6 = 0;
v7 = 0.0;
v8 = 0.0;
while ( v6 < (int)v4 )
{
v9 = cocos2d::CCArray::objectAtIndex(v2, v6);
v3 = (cocos2d::CCArray *)(*(int (__fastcall **)(float *, int))(*(_DWORD *)v9 + 680))(&v35, v9);
if ( v6 )
{
if ( v35 < v8 )
v8 = v35;
if ( v35 > v7 )
v7 = v35;
if ( v36 > v5 )
v5 = v36;
}
else
{
v8 = v35;
v5 = v36;
v7 = v35;
}
++v6;
}
if ( v4 == (cocos2d::CCArray *)((char *)&dword_0 + 2) )
{
v10 = (GameObject *)cocos2d::CCArray::objectAtIndex(v2, 0);
v11 = (GameObject *)cocos2d::CCArray::objectAtIndex(v2, 1u);
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v10 + 680))(&v30, v10);
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v11 + 680))(&v35, v11);
if ( fabsf(v31 - v36) < fabsf(v30 - v35) )
{
if ( v30 <= v35 )
{
v13 = v11;
v14 = v10;
}
else
{
v13 = v10;
v14 = v11;
}
v11 = nullptr;
v10 = nullptr;
}
else
{
if ( v31 < v36 )
{
v12 = v10;
v10 = v11;
v11 = v12;
}
v13 = nullptr;
v14 = nullptr;
}
v15 = 0;
}
else
{
v16 = (size_t **)cocos2d::CCArray::create(v3);
cocos2d::CCArray::addObjectsFromArray((cocos2d::CCArray *)v16, v2);
qsort((void *)v16[13][3], *v16[13], 4u, alignYSort);
v17 = (GameObject *)cocos2d::CCArray::objectAtIndex((cocos2d::CCArray *)v16, 0);
v11 = (GameObject *)cocos2d::CCArray::objectAtIndex((cocos2d::CCArray *)v16, 1u);
v18 = (GameObject *)cocos2d::CCArray::objectAtIndex((cocos2d::CCArray *)v16, 2u);
v13 = (GameObject *)cocos2d::CCArray::objectAtIndex((cocos2d::CCArray *)v16, 3u);
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v17 + 680))(&v30, v17);
v19 = v30;
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v11 + 680))(&v35, v11);
if ( v19 > v35 )
v10 = v11;
else
v10 = v17;
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v18 + 680))(&v30, v18);
v20 = v30;
if ( v10 != v17 )
v11 = v17;
(*(void (__fastcall **)(float *, GameObject *))(*(_DWORD *)v13 + 680))(&v35, v13);
if ( v20 > v35 )
v14 = v13;
else
v14 = v18;
if ( v14 != v18 )
v13 = v18;
v15 = 1;
}
v28 = this;
v26 = sub_4856E8((int *)&v28, v10);
v27 = sub_4856E8((int *)&v28, v11);
v21 = sub_4856E8((int *)&v28, v14);
v22 = sub_4856E8((int *)&v28, v13);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v29, (float)(v8 + v7) * 0.5, v5 + 60.0);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v30, (const cocos2d::CCPoint *)v29);
EditorUI::getGridSnappedPos((int)&v35, (int)this, &v30);
cocos2d::CCPoint::operator=(v29, &v35);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v35, (const cocos2d::CCPoint *)v29);
Object = EditorUI::createObject(
(int)this,
(GameObject *)((char *)&stru_B4C.st_size + 3),
(const cocos2d::CCPoint *)&v35);
if ( !Object )
{
v32 = 0;
v33 = 0;
v34 = 0;
std::string::__init(&v32, "Create gradient failed.", 0x17u);
EditorUI::showTextAlert((int)this, (int)&v32, 0, 1, 0);
return std::string::~string((int)&v32);
}
v25 = *((LevelEditorLayer **)this + 236);
v35 = 0.0;
v36 = 0.0;
v37 = 0;
v38 = 0;
v39 = 1065353216;
*((_DWORD *)Object + 414) = LevelEditorLayer::getNextFreeGradientID(v25, (int)&v35);
std::__hash_table,std::equal_to,std::allocator>::~__hash_table((int)&v35);
*((_BYTE *)Object + 1676) = v15;
*((_DWORD *)Object + 417) = v21;
*((_DWORD *)Object + 415) = v26;
*((_DWORD *)Object + 418) = v22;
*((_DWORD *)Object + 416) = v27;
LevelEditorLayer::refreshSpecial(*((LevelEditorLayer **)this + 236), Object);
EditorUI::deselectAll(this);
EditorUI::selectObject(this, Object, 1);
return EditorUI::updateSelectionUI(this);
}