//
// LevelEditorLayer::getNextFreeItemID from 0x1402da980 to 0x1402daaa7 (295 bytes)
//
// 4 xrefs:
// > SetupInteractObjectPopup::onPlusButton @ 0x1404243ca
// > SetupPickupTriggerPopup::onPlusButton @ 0x1404372ae
// > ??> @ 0x1406d3260
// > ??> @ 0x1406d326c
//
// 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::getNextFreeItemID(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; // rdi
__int64 num; // rax
cocos2d::CCObject **arr; // rdi
cocos2d::CCObject **j; // rsi
cocos2d::CCObject *v12; // rbx
int v13; // ebx
_BYTE v15[16]; // [rsp+20h] [rbp-58h] BYREF
__int64 v16; // [rsp+30h] [rbp-48h] BYREF
void *v17; // [rsp+38h] [rbp-40h] BYREF
char v18[40]; // [rsp+48h] [rbp-30h] BYREF
int m_nTag; // [rsp+80h] [rbp+8h] BYREF
m_nTag = 0;
sub_14005E660((__int64)&v16, &m_nTag, v2);
Myhead = a2->_List._Mypair._Myval2._Myhead;
for ( i = *(unsigned __int8 **)Myhead; i != (unsigned __int8 *)Myhead; i = *(unsigned __int8 **)i )
sub_140060D70((__int64)&v16, (__int64)v15, 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 ( v12[22].m_uAutoReleaseCount == 1
&& (((unsigned int (__fastcall *)(cocos2d::CCObject *))v12->__vftable[22].canEncode)(*arr) == 30
&& LOBYTE(v12[30].m_uAutoReleaseCount)
|| v12[18].m_eObjType == 1817) )
{
m_nTag = v12[30].m_nTag;
sub_140060D70((__int64)&v16, (__int64)v15, (unsigned __int8 *)&m_nTag);
}
}
}
}
v13 = sub_1402D1460(1, 1000, &v16);
sub_14005D100((__int64)v18);
sub_14005D870(&v17);
return v13;
}