//
// LevelEditorLayer::getNextFreeEditorLayer from 0x7b3d84 to 0x7b4258 (1236 bytes)
//
// 4 xrefs:
// > EditorUI::onGoToFreeLayer @ 0x7c6450
// > SetGroupIDLayer::onNextFreeEditorLayer1 @ 0xabb1e4
// > SetGroupIDLayer::onNextFreeEditorLayer2 @ 0xabb42c
// > ??> @ 0xf7ae0
//
// This function is hookable on this platform (idp: arm, 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:53:53 +0000
//
__int64 __fastcall LevelEditorLayer::getNextFreeEditorLayer(LevelEditorLayer *a1, __int64 a2)
{
__int64 AllObjects; // x0
unsigned int *v4; // x1
__int64 *v5; // x21
__int64 v6; // x0
char *v7; // x27
__int64 v8; // x24
int v9; // w3
unsigned __int64 v10; // x20
unsigned __int64 v11; // x19
unsigned __int64 v12; // x22
_QWORD *v13; // x6
__int64 *v14; // x0
unsigned __int64 v15; // x1
unsigned __int64 v16; // x1
float v17; // s0
_BOOL8 v18; // x2
__int64 v19; // x0
unsigned __int64 v20; // x2
unsigned __int64 v21; // x1
_QWORD *v22; // x0
int v23; // w3
unsigned __int64 v24; // x22
__int64 v25; // x20
__int64 *v26; // x0
unsigned __int64 v27; // x1
unsigned __int64 v28; // x1
float v29; // s0
_BOOL8 v30; // x2
__int64 v31; // x0
unsigned __int64 v32; // x2
unsigned __int64 v33; // x1
_QWORD *v34; // x0
unsigned int NextHighestID; // w20
_QWORD *v36; // x0
_QWORD *v37; // x19
void *v38; // x0
unsigned __int64 v40; // x2
unsigned __int64 v41; // x0
unsigned __int64 v42; // x2
unsigned __int64 v43; // x0
void *v44[3]; // [xsp+60h] [xbp+60h] BYREF
_QWORD v45[3]; // [xsp+78h] [xbp+78h] BYREF
void *v46; // [xsp+90h] [xbp+90h] BYREF
unsigned __int64 v47; // [xsp+98h] [xbp+98h]
void *v48; // [xsp+A0h] [xbp+A0h] BYREF
__int64 v49; // [xsp+A8h] [xbp+A8h]
float v50; // [xsp+B0h] [xbp+B0h]
v46 = nullptr;
v47 = 0;
v48 = nullptr;
v49 = 0;
v50 = 1.0;
LevelEditorLayer::addExclusionList((__int64)a1, a2, (unsigned __int64)&v46);
AllObjects = LevelEditorLayer::getAllObjects(a1);
if ( AllObjects )
{
v4 = *(unsigned int **)(AllObjects + 56);
if ( *v4 )
{
v5 = *((__int64 **)v4 + 2);
v6 = 8LL * *v4 - 8;
v7 = (char *)v5 + v6;
if ( v5 <= (__int64 *)((char *)v5 + v6) )
{
v8 = *v5;
if ( *v5 )
{
while ( 1 )
{
v9 = *(__int16 *)(v8 + 1202);
v10 = 0;
v11 = v47;
LODWORD(v45[0]) = v9;
v12 = (__int16)v9;
if ( v47 )
{
v10 = (__int16)v9 & (v47 - 1);
if ( ((v47 - 1) & v47) != 0 )
v10 = (__int16)v9 % v47;
v13 = v46;
v14 = *((__int64 **)v46 + v10);
if ( v14 )
{
while ( 1 )
{
v14 = (__int64 *)*v14;
if ( !v14 )
break;
v15 = v14[1];
v16 = ((v47 - 1) & v47) != 0 ? v15 % v47 : (v47 - 1) & v15;
if ( v10 != v16 )
break;
if ( v9 == *((_DWORD *)v14 + 4) )
{
v23 = *(__int16 *)(v8 + 1204);
LODWORD(v44[0]) = v23;
v24 = (__int16)v23;
goto LABEL_24;
}
}
}
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(__int64)&v46,
(__int16)v9,
v45,
(__int64)v44);
v17 = (float)(unsigned __int64)(v49 + 1);
if ( v17 > (float)((float)v11 * v50) )
{
v18 = 1;
v19 = 2 * v11;
if ( v11 > 2 )
v18 = ((v11 - 1) & v11) != 0;
}
else
{
if ( v11 )
goto LABEL_20;
v18 = 1;
v19 = 0;
}
v20 = v18 + v19;
v21 = vcvtps_u32_f32(v17 / v50);
if ( v21 < v20 )
v21 = v20;
std::__hash_table,std::equal_to,std::allocator>::rehash(
(unsigned __int64)&v46,
v21);
v11 = v47;
if ( ((v11 - 1) & v11) == 0 )
{
v10 = v12 & (v47 - 1);
LABEL_20:
v22 = *((_QWORD **)v46 + v10);
if ( v22 )
goto LABEL_21;
goto LABEL_60;
}
v10 = v12 % v47;
v22 = *((_QWORD **)v46 + v12 % v47);
if ( v22 )
{
LABEL_21:
*(_QWORD *)v44[0] = *v22;
*v22 = v44[0];
goto LABEL_22;
}
LABEL_60:
*(_QWORD *)v44[0] = v48;
v48 = v44[0];
*((_QWORD *)v46 + v10) = &v48;
if ( *(_QWORD *)v44[0] )
{
v40 = *(_QWORD *)(*(_QWORD *)v44[0] + 8LL);
if ( ((v11 - 1) & v11) != 0 )
v41 = v40 % v11;
else
v41 = (v11 - 1) & v40;
*((void **)v46 + v41) = v44[0];
}
LABEL_22:
v23 = *(__int16 *)(v8 + 1204);
v11 = v47;
LODWORD(v44[0]) = v23;
++v49;
v24 = (__int16)v23;
if ( v47 )
{
v13 = v46;
LABEL_24:
v25 = (v11 - 1) & v24;
if ( ((v11 - 1) & v11) != 0 )
v25 = v24 % v11;
v26 = (__int64 *)v13[v25];
if ( v26 )
{
while ( 1 )
{
v26 = (__int64 *)*v26;
if ( !v26 )
break;
v27 = v26[1];
v28 = ((v11 - 1) & v11) != 0 ? v27 % v11 : (v11 - 1) & v27;
if ( v25 != v28 )
break;
if ( v23 == *((_DWORD *)v26 + 4) )
goto LABEL_41;
}
}
}
else
{
v25 = 0;
v11 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(__int64)&v46,
v24,
v44,
(__int64)v45);
v29 = (float)(unsigned __int64)(v49 + 1);
if ( v29 > (float)((float)v11 * v50) )
{
v30 = 1;
v31 = 2 * v11;
if ( v11 > 2 )
v30 = ((v11 - 1) & v11) != 0;
}
else
{
if ( v11 )
goto LABEL_38;
v30 = 1;
v31 = 0;
}
v32 = v30 + v31;
v33 = vcvtps_u32_f32(v29 / v50);
if ( v33 < v32 )
v33 = v32;
std::__hash_table,std::equal_to,std::allocator>::rehash(
(unsigned __int64)&v46,
v33);
v11 = v47;
if ( ((v11 - 1) & v11) == 0 )
{
v25 = v24 & (v47 - 1);
LABEL_38:
v34 = *((_QWORD **)v46 + v25);
if ( v34 )
goto LABEL_39;
goto LABEL_65;
}
v25 = v24 % v47;
v34 = *((_QWORD **)v46 + v24 % v47);
if ( v34 )
{
LABEL_39:
*(_QWORD *)v45[0] = *v34;
*v34 = v45[0];
goto LABEL_40;
}
LABEL_65:
*(_QWORD *)v45[0] = v48;
v48 = (void *)v45[0];
*((_QWORD *)v46 + v25) = &v48;
if ( *(_QWORD *)v45[0] )
{
v42 = *(_QWORD *)(*(_QWORD *)v45[0] + 8LL);
if ( ((v11 - 1) & v11) != 0 )
v43 = v42 % v11;
else
v43 = (v11 - 1) & v42;
*((_QWORD *)v46 + v43) = v45[0];
}
LABEL_40:
++v49;
LABEL_41:
if ( v7 >= (char *)++v5 )
{
v8 = *v5;
if ( *v5 )
continue;
}
break;
}
}
}
}
}
NextHighestID = findNextHighestID(1, 1000, &v46);
v36 = v48;
if ( v48 )
{
do
{
v37 = (_QWORD *)*v36;
operator delete(v36);
v36 = v37;
}
while ( v37 );
}
v38 = v46;
v46 = nullptr;
if ( v38 )
operator delete(v38);
return NextHighestID;
}