//
// LevelEditorLayer::getNextFreeGroupID from 0x1402da7a0 to 0x1402da980 (480 bytes)
//
// 8 xrefs:
// > EditorUI::dynamicGroupUpdate @ 0x140118e81
// > EditorUI::assignNewGroups @ 0x140119316
// > EditorUI::createLoop @ 0x1401198a2
// > EditorUI::createLoop @ 0x140119b21
// > EditorUI::editGroup @ 0x14011f438
// > EditorUI::onAssignNewGroupID @ 0x1401225be
// > SetGroupIDLayer::onNextGroupID1 @ 0x1403fc0e8
// > ??> @ 0x1406d3260
//
// 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
//
// Hidden C++ exception states: #wind=1
int LevelEditorLayer::getNextFreeGroupID(LevelEditorLayer *a1, std::unordered_set *const a2)
{
__int64 v2; // r8
std::_List_val>::_Nodeptr Myhead; // rdi
unsigned __int8 *i; // rbx
cocos2d::CCArray *m_objects; // rax
cocos2d::ccArray *data; // r15
__int64 num; // rax
cocos2d::CCObject **arr; // r15
cocos2d::CCObject **j; // r12
cocos2d::CCObject *v12; // rbx
int v13; // r14d
__int64 v14; // rsi
unsigned __int64 v15; // rdi
__int64 v16; // rax
int v17; // ecx
int m_eObjType; // edi
int m_nTag; // esi
int v20; // ebx
int v21; // ebx
__int64 v23; // [rsp+20h] [rbp-79h] BYREF
void *v24; // [rsp+28h] [rbp-71h] BYREF
char v25[40]; // [rsp+38h] [rbp-61h] BYREF
_BYTE v26[16]; // [rsp+60h] [rbp-39h] BYREF
char v27[16]; // [rsp+70h] [rbp-29h] BYREF
char v28[16]; // [rsp+80h] [rbp-19h] BYREF
char v29[16]; // [rsp+90h] [rbp-9h] BYREF
char v30[80]; // [rsp+A0h] [rbp+7h] BYREF
int m_uAutoReleaseCount; // [rsp+100h] [rbp+67h] BYREF
int v32; // [rsp+108h] [rbp+6Fh] BYREF
int v33; // [rsp+110h] [rbp+77h] BYREF
int v34; // [rsp+118h] [rbp+7Fh] BYREF
m_uAutoReleaseCount = 0;
sub_14005E660((__int64)&v23, &m_uAutoReleaseCount, v2);
Myhead = a2->_List._Mypair._Myval2._Myhead;
for ( i = *(unsigned __int8 **)Myhead; i != (unsigned __int8 *)Myhead; i = *(unsigned __int8 **)i )
sub_140060D70((__int64)&v23, (__int64)v26, i + 16);
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( j = &arr[num - 1]; arr <= j; ++arr )
{
v12 = *arr;
if ( !*arr )
break;
if ( SLOWORD(v12[21].__vftable) > 0 )
{
v13 = 0;
v14 = 0;
v15 = 0;
do
{
if ( v15 <= 9 && (v16 = *(_QWORD *)&v12[20].m_uOrderOfArrival) != 0 )
v17 = *(__int16 *)(v14 + v16);
else
v17 = 0;
m_uAutoReleaseCount = v17;
sub_140060D70((__int64)&v23, (__int64)v26, (unsigned __int8 *)&m_uAutoReleaseCount);
++v13;
++v15;
v14 += 2;
}
while ( v13 < SLOWORD(v12[21].__vftable) );
}
if ( v12[22].m_uAutoReleaseCount == 1 && (v12[18].m_eObjType != 1006 || LODWORD(v12[29].__vftable) == 1) )
{
m_uAutoReleaseCount = v12[26].m_uAutoReleaseCount;
m_eObjType = v12[26].m_eObjType;
v32 = m_eObjType;
m_nTag = v12[30].m_nTag;
v33 = m_nTag;
v20 = HIDWORD(v12[30].__vftable);
v34 = v20;
if ( m_uAutoReleaseCount > 0 )
sub_140060D70((__int64)&v23, (__int64)v27, (unsigned __int8 *)&m_uAutoReleaseCount);
if ( m_eObjType > 0 )
sub_140060D70((__int64)&v23, (__int64)v28, (unsigned __int8 *)&v32);
if ( m_nTag > 0 )
sub_140060D70((__int64)&v23, (__int64)v29, (unsigned __int8 *)&v33);
if ( v20 > 0 )
sub_140060D70((__int64)&v23, (__int64)v30, (unsigned __int8 *)&v34);
}
}
}
}
v21 = sub_1402D1460(a1->m_levelSettings->m_nextFreeID, 9999, &v23);
sub_14005D100((__int64)v25);
sub_14005D870(&v24);
return v21;
}