//
// LevelEditorLayer::getNextColorChannel from 0x1000ed670 to 0x1000ed995 (805 bytes)
//
// 2 xrefs:
// > EditorUI::pasteObjects @ 0x10003a99a
// > CustomizeObjectLayer::onNextColorChannel @ 0x1001f812d
//
// 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
//
int __fastcall LevelEditorLayer::getNextColorChannel(LevelEditorLayer *a1)
{
double v1; // xmm1_8
double v2; // xmm2_8
cocos2d::CCArray *m_objects; // rax
cocos2d::ccArray *data; // rax
GameObject **arr; // r14
unsigned __int64 v7; // r15
GameObject *v8; // r13
int SecondaryColorMode; // eax
cocos2d::CCArray *m_colorTriggers; // rax
cocos2d::ccArray *v11; // rax
GameObject **v12; // r12
unsigned __int64 v13; // r13
unsigned int i; // r14d
unsigned __int64 v15; // rdx
unsigned __int64 v16; // r8
unsigned __int64 v17; // rsi
__int64 **v18; // rax
__int64 *v19; // rdi
__int64 v20; // rax
ColorAction *ColorAction; // rax
unsigned __int64 v22; // rax
_QWORD *v23; // rdi
_QWORD *v24; // rbx
void *v25; // rdi
int result; // eax
void *v27[2]; // [rsp+0h] [rbp-60h] BYREF
void *__p[2]; // [rsp+10h] [rbp-50h]
int v29; // [rsp+20h] [rbp-40h]
int v30; // [rsp+30h] [rbp-30h] BYREF
int v31[11]; // [rsp+34h] [rbp-2Ch] BYREF
*(_OWORD *)__p = 0;
*(_OWORD *)v27 = 0;
v29 = 1065353216;
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
if ( data->num )
{
arr = (GameObject **)data->arr;
v7 = (unsigned __int64)&arr[data->num - 1];
do
{
v8 = *arr;
if ( !*arr )
break;
v31[0] = GameObject::getMainColorMode(*arr);
SecondaryColorMode = GameObject::getSecondaryColorMode(v8);
v30 = SecondaryColorMode;
if ( v31[0] <= 999 )
{
sub_100054F50((float *)v27, v31, v31, (__m128)0LL, v1, v2);
SecondaryColorMode = v30;
}
if ( SecondaryColorMode <= 999 )
sub_100054F50((float *)v27, &v30, &v30, (__m128)0LL, v1, v2);
++arr;
}
while ( (unsigned __int64)arr <= v7 );
}
}
m_colorTriggers = a1->m_colorTriggers;
if ( m_colorTriggers )
{
v11 = m_colorTriggers->data;
if ( v11->num )
{
v12 = (GameObject **)v11->arr;
v13 = (unsigned __int64)&v12[v11->num - 1];
do
{
if ( !*v12 )
break;
v31[0] = GameObject::getColorIndex(*v12);
if ( v31[0] <= 999 )
sub_100054F50((float *)v27, v31, v31, (__m128)0LL, v1, v2);
++v12;
}
while ( (unsigned __int64)v12 <= v13 );
}
}
for ( i = 1; ; ++i )
{
if ( v27[1] )
{
v15 = (((unsigned __int64)v27[1] - (((unsigned __int64)v27[1] >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ ((((unsigned __int64)v27[1] - (((unsigned __int64)v27[1] >> 1) & 0x5555555555555555LL)) >> 2)
& 0x3333333333333333LL);
v16 = (0x101010101010101LL * ((v15 + (v15 >> 4)) & 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v16 > 1 )
{
v17 = i;
if ( v27[1] <= (void *)i )
v17 = (unsigned __int16)((unsigned __int16)i % LOWORD(v27[1]));
}
else
{
v17 = (LODWORD(v27[1]) + 1023) & i;
}
v18 = *((__int64 ***)v27[0] + v17);
if ( v18 )
{
v19 = *v18;
if ( *v18 )
break;
}
}
LABEL_33:
if ( !GJEffectManager::colorExists(a1->m_levelSettings->GJBaseGameLayer::m_effectManager, i) )
goto LABEL_46;
ColorAction = GJEffectManager::getColorAction(a1->m_levelSettings->GJBaseGameLayer::m_effectManager, i);
if ( ((i < 0x3E8) & ColorAction::isInUse(ColorAction)) == 0 )
goto LABEL_46;
LABEL_19:
;
}
if ( (unsigned int)v16 < 2 )
{
while ( 1 )
{
v20 = v19[1];
if ( v20 == i )
{
if ( *((_DWORD *)v19 + 4) == i )
goto LABEL_18;
}
else if ( (((unsigned __int64)v27[1] - 1) & v20) != v17 )
{
goto LABEL_33;
}
v19 = (__int64 *)*v19;
if ( !v19 )
goto LABEL_33;
}
}
while ( 1 )
{
v22 = v19[1];
if ( v22 == i )
break;
if ( (void *)v22 < v27[1] )
goto LABEL_42;
if ( ((unsigned __int64)v27[1] | v22) >> 32 )
{
v22 %= (unsigned __int64)v27[1];
LABEL_42:
if ( v22 != v17 )
goto LABEL_33;
goto LABEL_37;
}
if ( (unsigned int)v22 % LODWORD(v27[1]) != v17 )
goto LABEL_33;
LABEL_37:
v19 = (__int64 *)*v19;
if ( !v19 )
goto LABEL_33;
}
if ( *((_DWORD *)v19 + 4) != i )
goto LABEL_37;
LABEL_18:
if ( i <= 0x3E7 )
goto LABEL_19;
LABEL_46:
v23 = __p[0];
if ( __p[0] )
{
do
{
v24 = (_QWORD *)*v23;
operator delete(v23);
v23 = v24;
}
while ( v24 );
}
v25 = v27[0];
v27[0] = nullptr;
if ( v25 )
operator delete(v25);
result = 999;
if ( (int)i < 999 )
return i;
return result;
}