//
// LevelEditorLayer::getNextFreeGradientID from 0x1000ed410 to 0x1000ed655 (581 bytes)
//
// 2 xrefs:
// > EditorUI::dynamicGroupUpdate @ 0x1000449d9
// > SetupGradientPopup::onPlusButton @ 0x1005f3202
//
// 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
//
int __fastcall LevelEditorLayer::getNextFreeGradientID(LevelEditorLayer *a1, std::unordered_set *const a2)
{
double v2; // xmm1_8
double v3; // xmm2_8
std::__hash_node_base *>::__next_pointer i; // r15
cocos2d::CCArray *m_objects; // rax
cocos2d::ccArray *data; // rax
cocos2d::CCObject **arr; // r15
unsigned __int64 v8; // r12
cocos2d::CCObject *v9; // rax
void *v10; // rdi
int v11; // ebx
unsigned __int64 v12; // r8
unsigned __int64 v13; // rcx
__int64 *v14; // rsi
__int64 v15; // r9
unsigned __int64 v16; // rsi
__int64 **v17; // rax
__int64 *j; // r9
unsigned __int64 v19; // rax
_QWORD *v20; // rdi
_QWORD *v21; // r14
void *v23[2]; // [rsp+0h] [rbp-50h] BYREF
void *__p[2]; // [rsp+10h] [rbp-40h]
int v25; // [rsp+20h] [rbp-30h]
int v26[9]; // [rsp+2Ch] [rbp-24h] BYREF
*(_OWORD *)__p = 0;
*(_OWORD *)v23 = 0;
v25 = 1065353216;
for ( i = a2->__table_.__p1_.__value_.__next_; i; i = i->__next_ )
sub_100054F50((float *)v23, (int *)&i[2], &i[2], (__m128)0LL, v2, v3);
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
if ( data->num )
{
arr = data->arr;
v8 = (unsigned __int64)&arr[data->num - 1];
do
{
v9 = *arr;
if ( !*arr )
break;
if ( v9[18].m_uReference == 2903 )
{
v26[0] = v9[32].m_unknown5;
sub_100056510((float *)v23, v26, v26, (__m128)0LL);
}
++arr;
}
while ( (unsigned __int64)arr <= v8 );
}
}
v10 = v23[0];
v11 = 1;
if ( v23[1] )
{
if ( (((__int64)v23[1] - 1) & (__int64)v23[1]) == 0 )
{
v12 = (unsigned __int64)v23[1] + 0x7FFFFFFF;
v13 = 1;
v11 = 1000;
LABEL_13:
v14 = *((__int64 **)v23[0] + (v12 & v13));
if ( v14 )
{
while ( 1 )
{
v14 = (__int64 *)*v14;
if ( !v14 )
break;
v15 = v14[1];
if ( v15 == v13 )
{
if ( v13 == *((_DWORD *)v14 + 4) )
{
if ( ++v13 != 1001 )
goto LABEL_13;
goto LABEL_42;
}
}
else if ( (((unsigned __int64)v23[1] - 1) & v15) != (v12 & v13) )
{
goto LABEL_41;
}
}
}
goto LABEL_41;
}
v13 = 1;
v11 = 1000;
LABEL_22:
v16 = v13;
if ( v23[1] <= (void *)v13 )
{
if ( !(((unsigned __int64)v23[1] | v13) >> 32) )
{
v16 = (unsigned int)v13 % LODWORD(v23[1]);
v17 = *((__int64 ***)v23[0] + v16);
if ( v17 )
goto LABEL_26;
goto LABEL_41;
}
v16 = v13 % (unsigned __int64)v23[1];
}
v17 = *((__int64 ***)v23[0] + v16);
if ( v17 )
{
LABEL_26:
for ( j = *v17; j; j = (__int64 *)*j )
{
v19 = j[1];
if ( v19 == v13 )
{
if ( v13 == *((_DWORD *)j + 4) )
{
if ( ++v13 != 1001 )
goto LABEL_22;
goto LABEL_42;
}
}
else
{
if ( (void *)v19 < v23[1] )
goto LABEL_34;
if ( ((unsigned __int64)v23[1] | v19) >> 32 )
{
v19 %= (unsigned __int64)v23[1];
LABEL_34:
if ( v19 != v16 )
break;
continue;
}
if ( (unsigned int)v19 % LODWORD(v23[1]) != v16 )
break;
}
}
}
LABEL_41:
v11 = v13;
}
LABEL_42:
if ( __p[0] )
{
v20 = __p[0];
do
{
v21 = (_QWORD *)*v20;
operator delete(v20);
v20 = v21;
}
while ( v21 );
v10 = v23[0];
}
v23[0] = nullptr;
if ( v10 )
operator delete(v10);
return v11;
}