//
// LevelEditorLayer::getNextFreeGradientID from 0x47a8f4 to 0x47ac34 (832 bytes)
//
// 4 xrefs:
// > EditorUI::createGradientFromSelection @ 0x487b7a
// > EditorUI::dynamicGroupUpdate @ 0x48ceea
// > IDNameBrowserPopup::onFormNextFree @ 0x78fed8
// > IDNameInput::onNextFree @ 0x793c20
//
// 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:14 +0000
//
int __fastcall LevelEditorLayer::getNextFreeGradientID(LevelEditorLayer *a1, int a2)
{
unsigned int v3; // r2
LevelSettingsObject *v4; // r0
int AllObjects; // r0
_DWORD *i; // r8
unsigned int v7; // r4
unsigned int v8; // r7
unsigned int v9; // r11
int v10; // r5
_DWORD *v11; // r3
unsigned int v12; // r0
int v13; // r1
float v14; // s15
bool v15; // r5
unsigned int v16; // r5
unsigned int v17; // r1
_DWORD *v18; // r3
unsigned int v19; // r0
int v20; // r1
int *v21; // r3
int v22; // r5
int *v23; // r3
unsigned int v24; // r11
int *v25; // r8
int NextHighestID; // r4
int v28; // r3
int v29; // t1
unsigned int v30; // r7
unsigned int v31; // r4
unsigned int v32; // r9
int v33; // r5
_DWORD *v34; // r3
unsigned int v35; // r0
int v36; // r1
float v37; // s15
bool v38; // r5
unsigned int v39; // r5
unsigned int v40; // r1
void **v41; // r3
unsigned int v42; // r0
int v43; // r1
_DWORD v44[3]; // [sp+10h] [bp-34h] BYREF
void *v45; // [sp+1Ch] [bp-28h] BYREF
int v46; // [sp+28h] [bp-1Ch] BYREF
unsigned int v47; // [sp+2Ch] [bp-18h]
void *v48; // [sp+30h] [bp-14h] BYREF
int v49; // [sp+34h] [bp-10h]
float v50; // [sp+38h] [bp-Ch]
v46 = 0;
v47 = 0;
v48 = nullptr;
v49 = 0;
v50 = 1.0;
LevelEditorLayer::addExclusionList((int)a1, a2, (int)&v46);
v4 = *((LevelSettingsObject **)a1 + 521);
if ( v4 )
{
for ( i = (_DWORD *)LevelSettingsObject::getIDNames(v4, 7u, v3)[2]; ; i = (_DWORD *)*i )
{
if ( !i )
goto LABEL_2;
v7 = v47;
v8 = i[2];
if ( v47 )
{
v9 = v47 - 1;
if ( ((v47 - 1) & v47) != 0 )
v10 = v8 % v47;
else
v10 = v8 & v9;
v11 = *(_DWORD **)(v46 + 4 * v10);
if ( v11 )
{
while ( 1 )
{
v11 = (_DWORD *)*v11;
if ( !v11 )
break;
v12 = v11[1];
v13 = ((v47 - 1) & v47) != 0 ? v12 % v47 : v9 & v12;
if ( v13 != v10 )
break;
if ( v11[2] == v8 )
goto LABEL_34;
}
}
}
else
{
v10 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(int)v44,
(int)&v46,
v8,
i + 2);
v14 = (float)(unsigned int)(v49 + 1);
if ( v14 > (float)((float)v7 * v50) )
break;
if ( !v7 )
{
v15 = 0;
LABEL_21:
v16 = 2 * v7 + !v15;
v17 = (unsigned int)ceilf(v14 / v50);
if ( v17 < v16 )
v17 = v16;
std::__hash_table,std::equal_to,std::allocator>::rehash((int)&v46, v17);
v7 = v47;
if ( ((v47 - 1) & v47) != 0 )
v10 = v8 % v47;
else
v10 = (v47 - 1) & v8;
}
v18 = *(_DWORD **)(v46 + 4 * v10);
if ( v18 )
{
*(_DWORD *)v44[0] = *v18;
*v18 = v44[0];
}
else
{
*(_DWORD *)v44[0] = v48;
v48 = (void *)v44[0];
*(_DWORD *)(v46 + 4 * v10) = &v48;
if ( *(_DWORD *)v44[0] )
{
v19 = *(_DWORD *)(*(_DWORD *)v44[0] + 4);
if ( ((v7 - 1) & v7) != 0 )
v20 = v19 % v7;
else
v20 = (v7 - 1) & v19;
*(_DWORD *)(v46 + 4 * v20) = v44[0];
}
}
++v49;
LABEL_34:
;
}
v15 = v7 > 2 && ((v7 - 1) & v7) == 0;
goto LABEL_21;
}
LABEL_2:
AllObjects = LevelEditorLayer::getAllObjects(a1);
if ( AllObjects )
{
v21 = *(int **)(AllObjects + 52);
v22 = *v21;
if ( *v21 )
{
v23 = (int *)v21[3];
v24 = (unsigned int)&v23[v22 - 1];
v25 = v23;
while ( 1 )
{
do
{
LABEL_37:
if ( (unsigned int)v25 <= v24 )
{
v29 = *v25++;
v28 = v29;
if ( v29 )
continue;
}
goto LABEL_38;
}
while ( *(_DWORD *)(v28 + 892) != 2903 );
v30 = *(_DWORD *)(v28 + 1656);
v31 = v47;
v44[0] = v30;
if ( v47 )
{
v32 = v47 - 1;
if ( ((v47 - 1) & v47) != 0 )
v33 = v30 % v47;
else
v33 = v30 & v32;
v34 = *(_DWORD **)(v46 + 4 * v33);
if ( v34 )
{
while ( 1 )
{
v34 = (_DWORD *)*v34;
if ( !v34 )
break;
v35 = v34[1];
v36 = ((v47 - 1) & v47) != 0 ? v35 % v47 : v32 & v35;
if ( v36 != v33 )
break;
if ( v34[2] == v30 )
goto LABEL_37;
}
}
}
else
{
v33 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(int)&v45,
(int)&v46,
v30,
v44);
v37 = (float)(unsigned int)(v49 + 1);
if ( v37 > (float)((float)v31 * v50) )
{
v38 = v31 > 2 && ((v31 - 1) & v31) == 0;
}
else
{
if ( v31 )
goto LABEL_67;
v38 = 0;
}
v39 = 2 * v31 + !v38;
v40 = (unsigned int)ceilf(v37 / v50);
if ( v40 < v39 )
v40 = v39;
std::__hash_table,std::equal_to,std::allocator>::rehash((int)&v46, v40);
v31 = v47;
if ( ((v47 - 1) & v47) != 0 )
v33 = v30 % v47;
else
v33 = (v47 - 1) & v30;
LABEL_67:
v41 = *(void ***)(v46 + 4 * v33);
if ( v41 )
{
*(_DWORD *)v45 = *v41;
*v41 = v45;
}
else
{
*(_DWORD *)v45 = v48;
v48 = v45;
*(_DWORD *)(v46 + 4 * v33) = &v48;
if ( *(_DWORD *)v45 )
{
v42 = *(_DWORD *)(*(_DWORD *)v45 + 4);
if ( ((v31 - 1) & v31) != 0 )
v43 = v42 % v31;
else
v43 = (v31 - 1) & v42;
*(_DWORD *)(v46 + 4 * v43) = v45;
}
}
++v49;
}
}
}
LABEL_38:
NextHighestID = findNextHighestID(1, 1000, &v46);
std::__hash_table,std::equal_to,std::allocator>::~__hash_table((int)&v46);
return NextHighestID;
}