//
// LevelEditorLayer::getNextFreeGroupID from 0x1000ebcf0 to 0x1000ec027 (823 bytes)
//
// 7 xrefs:
// > EditorUI::editGroup @ 0x10002c29f
// > EditorUI::dynamicGroupUpdate @ 0x100044cec
// > EditorUI::assignNewGroups @ 0x1000453f8
// > EditorUI::createLoop @ 0x100045aac
// > EditorUI::createLoop @ 0x100045e3b
// > EditorUI::onAssignNewGroupID @ 0x10004e0cd
// > SetGroupIDLayer::onNextGroupID1 @ 0x100315270
//
// 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::getNextFreeGroupID(LevelEditorLayer *a1, std::unordered_set *const a2)
{
double v2; // xmm1_8
double v3; // xmm2_8
std::__hash_node_base *>::__next_pointer i; // rbx
cocos2d::CCArray *m_objects; // rax
cocos2d::ccArray *data; // rax
cocos2d::CCObject **arr; // rbx
cocos2d::CCObject *v8; // r13
int v9; // r12d
int m_nLuaID; // eax
int m_nextFreeID; // eax
unsigned int v12; // ebx
unsigned __int64 v13; // rcx
unsigned __int64 v14; // rdi
__int64 *v15; // rsi
unsigned __int64 v16; // r9
unsigned __int64 v17; // rsi
__int64 **v18; // rax
__int64 *j; // r9
unsigned __int64 v20; // rax
_QWORD *v21; // rdi
_QWORD *v22; // r14
void *v23; // rdi
unsigned __int64 v25; // [rsp+0h] [rbp-70h]
void *v26[2]; // [rsp+10h] [rbp-60h] BYREF
void *__p[2]; // [rsp+20h] [rbp-50h]
int v28; // [rsp+30h] [rbp-40h]
int GroupID; // [rsp+38h] [rbp-38h] BYREF
int v30; // [rsp+3Ch] [rbp-34h] BYREF
int v31; // [rsp+40h] [rbp-30h] BYREF
int v32[11]; // [rsp+44h] [rbp-2Ch] BYREF
*(_OWORD *)__p = 0;
*(_OWORD *)v26 = 0;
v28 = 1065353216;
for ( i = a2->__table_.__p1_.__value_.__next_; i; i = i->__next_ )
sub_100054F50((float *)v26, (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;
v25 = (unsigned __int64)&arr[data->num - 1];
do
{
v8 = *arr;
if ( !*arr )
break;
if ( SLOWORD(v8[20].m_uOrderOfArrival) > 0 )
{
v9 = 0;
do
{
GroupID = GameObject::getGroupID((GameObject *)v8, v9);
sub_100056510((float *)v26, &GroupID, &GroupID, (__m128)0LL);
++v9;
}
while ( v9 < SLOWORD(v8[20].m_uOrderOfArrival) );
}
if ( v8[22].m_nTag == 1 && (v8[18].m_uReference != 1006 || v8[28].m_unknown2 == 1) )
{
GroupID = v8[26].m_uID;
m_nLuaID = v8[26].m_nLuaID;
v30 = m_nLuaID;
v31 = (int)v8[30].__vftable;
v32[0] = v8[29].m_nZOrder;
if ( GroupID > 0 )
{
sub_100054F50((float *)v26, &GroupID, &GroupID, (__m128)0LL, v2, v3);
m_nLuaID = v30;
}
if ( m_nLuaID > 0 )
sub_100054F50((float *)v26, &v30, &v30, (__m128)0LL, v2, v3);
if ( v31 > 0 )
sub_100054F50((float *)v26, &v31, &v31, (__m128)0LL, v2, v3);
if ( v32[0] > 0 )
sub_100054F50((float *)v26, v32, v32, (__m128)0LL, v2, v3);
}
++arr;
}
while ( (unsigned __int64)arr <= v25 );
}
}
m_nextFreeID = a1->m_levelSettings->m_nextFreeID;
v12 = 1;
if ( m_nextFreeID >= 2 )
v12 = a1->m_levelSettings->m_nextFreeID;
if ( m_nextFreeID <= 9999 && v26[1] )
{
v13 = v12;
if ( (((__int64)v26[1] - 1) & (__int64)v26[1]) == 0 )
{
v14 = (unsigned __int64)v26[1] + 0x7FFFFFFF;
v12 = 9999;
LABEL_28:
v15 = *((__int64 **)v26[0] + (v14 & v13));
if ( v15 )
{
while ( 1 )
{
v15 = (__int64 *)*v15;
if ( !v15 )
break;
v16 = v15[1];
if ( v16 == v13 )
{
if ( v13 == *((_DWORD *)v15 + 4) )
{
if ( ++v13 != 10000 )
goto LABEL_28;
goto LABEL_57;
}
}
else if ( (((unsigned __int64)v26[1] - 1) & v16) != (v14 & v13) )
{
goto LABEL_56;
}
}
}
goto LABEL_56;
}
v12 = 9999;
LABEL_37:
v17 = v13;
if ( v26[1] <= (void *)v13 )
{
if ( !(((unsigned __int64)v26[1] | v13) >> 32) )
{
v17 = (unsigned int)v13 % LODWORD(v26[1]);
v18 = *((__int64 ***)v26[0] + v17);
if ( v18 )
goto LABEL_41;
goto LABEL_56;
}
v17 = v13 % (unsigned __int64)v26[1];
}
v18 = *((__int64 ***)v26[0] + v17);
if ( v18 )
{
LABEL_41:
for ( j = *v18; j; j = (__int64 *)*j )
{
v20 = j[1];
if ( v20 == v13 )
{
if ( v13 == *((_DWORD *)j + 4) )
{
if ( ++v13 != 10000 )
goto LABEL_37;
goto LABEL_57;
}
}
else
{
if ( (void *)v20 < v26[1] )
goto LABEL_49;
if ( ((unsigned __int64)v26[1] | v20) >> 32 )
{
v20 %= (unsigned __int64)v26[1];
LABEL_49:
if ( v20 != v17 )
break;
continue;
}
if ( (unsigned int)v20 % LODWORD(v26[1]) != v17 )
break;
}
}
}
LABEL_56:
v12 = v13;
}
LABEL_57:
v21 = __p[0];
if ( __p[0] )
{
do
{
v22 = (_QWORD *)*v21;
operator delete(v21);
v21 = v22;
}
while ( v22 );
}
v23 = v26[0];
v26[0] = nullptr;
if ( v23 )
operator delete(v23);
return v12;
}