//
// LevelEditorLayer::getNextFreeEditorLayer from 0x1000bfed0 to 0x1000c0127 (599 bytes)
//
// 3 xrefs:
// > EditorUI::onGoToFreeLayer @ 0x10000ab7d
// > SetGroupIDLayer::onNextFreeEditorLayer1 @ 0x1002ff320
// > SetGroupIDLayer::onNextFreeEditorLayer2 @ 0x1002ff430
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// 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 12:20:33 +0000
//
__int64 __fastcall LevelEditorLayer::getNextFreeEditorLayer(__int64 a1, __int64 a2)
{
int *i; // r15
__int64 v3; // rax
unsigned int *v4; // rax
__int64 *v5; // r15
unsigned __int64 v6; // r12
__int64 v7; // r13
void *v8; // rdi
unsigned int v9; // ebx
unsigned __int64 v10; // r8
unsigned __int64 v11; // rcx
__int64 *v12; // rsi
__int64 v13; // r9
unsigned __int64 v14; // rsi
__int64 **v15; // rax
__int64 *j; // r9
unsigned __int64 v17; // rax
_QWORD *v18; // rdi
_QWORD *v19; // r14
void *v21[2]; // [rsp+0h] [rbp-60h] BYREF
void *__p[2]; // [rsp+10h] [rbp-50h]
int v23; // [rsp+20h] [rbp-40h]
int v24[11]; // [rsp+34h] [rbp-2Ch] BYREF
*(_OWORD *)__p = 0;
*(_OWORD *)v21 = 0;
v23 = 1065353216;
for ( i = *(int **)(a2 + 16); i; i = *(int **)i )
sub_10001B800((float *)v21, i + 4, i + 4, (__m128)0LL);
v3 = *(_QWORD *)(a1 + 3280);
if ( v3 )
{
v4 = *(unsigned int **)(v3 + 56);
if ( *v4 )
{
v5 = *((__int64 **)v4 + 2);
v6 = (unsigned __int64)&v5[*v4 - 1];
do
{
v7 = *v5;
if ( !*v5 )
break;
v24[0] = *(__int16 *)(v7 + 1202);
sub_10001BC90((float *)v21, v24, v24, (__m128)0LL);
v24[0] = *(__int16 *)(v7 + 1204);
sub_10001BC90((float *)v21, v24, v24, (__m128)0LL);
++v5;
}
while ( (unsigned __int64)v5 <= v6 );
}
}
v8 = v21[0];
v9 = 1;
if ( v21[1] )
{
if ( (((__int64)v21[1] - 1) & (__int64)v21[1]) == 0 )
{
v10 = (unsigned __int64)v21[1] + 0x7FFFFFFF;
v11 = 1;
v9 = 1000;
LABEL_11:
v12 = *((__int64 **)v21[0] + (v10 & v11));
if ( v12 )
{
while ( 1 )
{
v12 = (__int64 *)*v12;
if ( !v12 )
break;
v13 = v12[1];
if ( v13 == v11 )
{
if ( v11 == *((_DWORD *)v12 + 4) )
{
if ( ++v11 != 1001 )
goto LABEL_11;
goto LABEL_40;
}
}
else if ( (((unsigned __int64)v21[1] - 1) & v13) != (v10 & v11) )
{
goto LABEL_39;
}
}
}
goto LABEL_39;
}
v11 = 1;
v9 = 1000;
LABEL_20:
v14 = v11;
if ( v21[1] <= (void *)v11 )
{
if ( !(((unsigned __int64)v21[1] | v11) >> 32) )
{
v14 = (unsigned int)v11 % LODWORD(v21[1]);
v15 = *((__int64 ***)v21[0] + v14);
if ( v15 )
goto LABEL_24;
goto LABEL_39;
}
v14 = v11 % (unsigned __int64)v21[1];
}
v15 = *((__int64 ***)v21[0] + v14);
if ( v15 )
{
LABEL_24:
for ( j = *v15; j; j = (__int64 *)*j )
{
v17 = j[1];
if ( v17 == v11 )
{
if ( v11 == *((_DWORD *)j + 4) )
{
if ( ++v11 != 1001 )
goto LABEL_20;
goto LABEL_40;
}
}
else
{
if ( (void *)v17 < v21[1] )
goto LABEL_32;
if ( ((unsigned __int64)v21[1] | v17) >> 32 )
{
v17 %= (unsigned __int64)v21[1];
LABEL_32:
if ( v17 != v14 )
break;
continue;
}
if ( (unsigned int)v17 % LODWORD(v21[1]) != v14 )
break;
}
}
}
LABEL_39:
v9 = v11;
}
LABEL_40:
if ( __p[0] )
{
v18 = __p[0];
do
{
v19 = (_QWORD *)*v18;
operator delete(v18);
v18 = v19;
}
while ( v19 );
v8 = v21[0];
}
v21[0] = nullptr;
if ( v8 )
operator delete(v8);
return v9;
}