//
// LevelEditorLayer::getNextColorChannel from 0x1000c0e00 to 0x1000c1125 (805 bytes)
//
// 2 xrefs:
// > CustomizeObjectLayer::onNextColorChannel @ 0x1001da63d
// > EditorUI::pasteObjects @ 0x1005b69fa
//
// 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:34 +0000
//
__int64 __fastcall LevelEditorLayer::getNextColorChannel(_QWORD *a1)
{
__int64 v2; // rax
unsigned int *v3; // rax
_QWORD *v4; // r14
unsigned __int64 v5; // r15
__int64 v6; // r13
int SecondaryColorMode; // eax
__int64 v8; // rax
unsigned int *v9; // rax
_QWORD *v10; // r12
unsigned __int64 v11; // r13
unsigned int i; // r14d
unsigned __int64 v13; // rdx
unsigned __int64 v14; // r8
unsigned __int64 v15; // rsi
__int64 **v16; // rax
__int64 *v17; // rdi
__int64 v18; // rax
__int64 ColorAction; // rax
unsigned __int64 v20; // rax
_QWORD *v21; // rdi
_QWORD *v22; // rbx
void *v23; // rdi
__int64 result; // rax
void *v25[2]; // [rsp+0h] [rbp-60h] BYREF
void *__p[2]; // [rsp+10h] [rbp-50h]
int v27; // [rsp+20h] [rbp-40h]
int v28; // [rsp+30h] [rbp-30h] BYREF
int v29[11]; // [rsp+34h] [rbp-2Ch] BYREF
*(_OWORD *)__p = 0;
*(_OWORD *)v25 = 0;
v27 = 1065353216;
v2 = a1[410];
if ( v2 )
{
v3 = *(unsigned int **)(v2 + 56);
if ( *v3 )
{
v4 = *((_QWORD **)v3 + 2);
v5 = (unsigned __int64)&v4[*v3 - 1];
do
{
v6 = *v4;
if ( !*v4 )
break;
v29[0] = GameObject::getMainColorMode(*v4);
SecondaryColorMode = GameObject::getSecondaryColorMode(v6, 0.0);
v28 = SecondaryColorMode;
if ( v29[0] <= 999 )
{
sub_10001B800((float *)v25, v29, v29, (__m128)0LL);
SecondaryColorMode = v28;
}
if ( SecondaryColorMode <= 999 )
sub_10001B800((float *)v25, &v28, &v28, (__m128)0LL);
++v4;
}
while ( (unsigned __int64)v4 <= v5 );
}
}
v8 = a1[1756];
if ( v8 )
{
v9 = *(unsigned int **)(v8 + 56);
if ( *v9 )
{
v10 = *((_QWORD **)v9 + 2);
v11 = (unsigned __int64)&v10[*v9 - 1];
do
{
if ( !*v10 )
break;
v29[0] = GameObject::getColorIndex();
if ( v29[0] <= 999 )
sub_10001B800((float *)v25, v29, v29, (__m128)0LL);
++v10;
}
while ( (unsigned __int64)v10 <= v11 );
}
}
for ( i = 1; ; ++i )
{
if ( v25[1] )
{
v13 = (((unsigned __int64)v25[1] - (((unsigned __int64)v25[1] >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ ((((unsigned __int64)v25[1] - (((unsigned __int64)v25[1] >> 1) & 0x5555555555555555LL)) >> 2)
& 0x3333333333333333LL);
v14 = (0x101010101010101LL * ((v13 + (v13 >> 4)) & 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v14 > 1 )
{
v15 = i;
if ( v25[1] <= (void *)i )
v15 = (unsigned __int16)((unsigned __int16)i % LOWORD(v25[1]));
}
else
{
v15 = (LODWORD(v25[1]) + 1023) & i;
}
v16 = *((__int64 ***)v25[0] + v15);
if ( v16 )
{
v17 = *v16;
if ( *v16 )
break;
}
}
LABEL_33:
if ( !(unsigned __int8)GJEffectManager::colorExists(*(_QWORD *)(a1[409] + 320LL), i) )
goto LABEL_46;
ColorAction = GJEffectManager::getColorAction(*(_QWORD *)(a1[409] + 320LL), i);
if ( ((i < 0x3E8) & (unsigned __int8)ColorAction::isInUse(ColorAction)) == 0 )
goto LABEL_46;
LABEL_19:
;
}
if ( (unsigned int)v14 < 2 )
{
while ( 1 )
{
v18 = v17[1];
if ( v18 == i )
{
if ( *((_DWORD *)v17 + 4) == i )
goto LABEL_18;
}
else if ( (((unsigned __int64)v25[1] - 1) & v18) != v15 )
{
goto LABEL_33;
}
v17 = (__int64 *)*v17;
if ( !v17 )
goto LABEL_33;
}
}
while ( 1 )
{
v20 = v17[1];
if ( v20 == i )
break;
if ( (void *)v20 < v25[1] )
goto LABEL_42;
if ( ((unsigned __int64)v25[1] | v20) >> 32 )
{
v20 %= (unsigned __int64)v25[1];
LABEL_42:
if ( v20 != v15 )
goto LABEL_33;
goto LABEL_37;
}
if ( (unsigned int)v20 % LODWORD(v25[1]) != v15 )
goto LABEL_33;
LABEL_37:
v17 = (__int64 *)*v17;
if ( !v17 )
goto LABEL_33;
}
if ( *((_DWORD *)v17 + 4) != i )
goto LABEL_37;
LABEL_18:
if ( i <= 0x3E7 )
goto LABEL_19;
LABEL_46:
v21 = __p[0];
if ( __p[0] )
{
do
{
v22 = (_QWORD *)*v21;
operator delete(v21);
v21 = v22;
}
while ( v22 );
}
v23 = v25[0];
v25[0] = nullptr;
if ( v23 )
operator delete(v23);
result = 999;
if ( (int)i < 999 )
return i;
return result;
}