//
// LevelEditorLayer::getNextColorChannel from 0x1402db070 to 0x1402db439 (969 bytes)
//
// 3 xrefs:
// > CustomizeObjectLayer::onNextColorChannel @ 0x1400a8f34
// > EditorUI::pasteObjects @ 0x140113930
// > ??> @ 0x1406d32b4
//
// 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::getNextColorChannel(LevelEditorLayer *a1)
{
__int64 v1; // r8
cocos2d::CCArray *m_objects; // rax
cocos2d::ccArray *data; // rdi
__int64 num; // rax
cocos2d::CCObject **arr; // rdi
cocos2d::CCObject **i; // rsi
cocos2d::CCObject *v8; // rcx
int *v9; // rax
int v10; // edx
int v11; // eax
int *v12; // rbx
int v13; // ecx
int v14; // ebx
cocos2d::CCArray *m_colorTriggers; // rax
cocos2d::ccArray *v16; // rbx
__int64 v17; // rax
cocos2d::CCObject **v18; // rbx
cocos2d::CCObject **j; // rdi
cocos2d::CCObject *v20; // rdx
int m_eObjType; // ecx
int v22; // ecx
int v23; // ecx
int v24; // ecx
int v25; // ecx
int k; // r14d
int v27; // r12d
__int64 v28; // rax
int v29; // esi
GJEffectManager *m_effectManager; // r15
std::_Vector_val>::pointer Myfirst; // rdi
ColorAction *v32; // rdi
ColorActionSprite *ColorSprite; // rax
char v35[16]; // [rsp+20h] [rbp-49h] BYREF
_BYTE v36[16]; // [rsp+30h] [rbp-39h] BYREF
char v37[8]; // [rsp+40h] [rbp-29h] BYREF
void *v38; // [rsp+48h] [rbp-21h] BYREF
__int64 v39[3]; // [rsp+58h] [rbp-11h] BYREF
__int64 v40; // [rsp+70h] [rbp+7h]
int m_uAutoReleaseCount; // [rsp+D0h] [rbp+67h] BYREF
int v42; // [rsp+D8h] [rbp+6Fh] BYREF
m_uAutoReleaseCount = 0;
sub_14005E660((__int64)v37, &m_uAutoReleaseCount, v1);
m_objects = a1->m_objects;
if ( m_objects )
{
data = m_objects->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( i = &arr[num - 1]; arr <= i; ++arr )
{
v8 = *arr;
if ( !*arr )
break;
v9 = *(int **)&v8[19].m_unknown2;
if ( v9 )
{
v10 = v9[1];
v11 = *v9;
if ( v10 == v11 || !v11 )
v11 = v10;
}
else
{
v11 = 0;
}
m_uAutoReleaseCount = v11;
v12 = *(int **)&v8[19].m_uOrderOfArrival;
if ( v12 )
{
v13 = v12[1];
v14 = *v12;
if ( v13 == v14 || !v14 )
v14 = v13;
}
else
{
v14 = 0;
}
v42 = v14;
if ( v11 < 1000 )
sub_140060D70((__int64)v37, (__int64)v35, (unsigned __int8 *)&m_uAutoReleaseCount);
if ( v14 < 1000 )
sub_140060D70((__int64)v37, (__int64)v36, (unsigned __int8 *)&v42);
}
}
}
m_colorTriggers = a1->m_colorTriggers;
if ( m_colorTriggers )
{
v16 = m_colorTriggers->data;
v17 = v16->num;
if ( (_DWORD)v17 )
{
v18 = v16->arr;
for ( j = &v18[v17 - 1]; v18 <= j; ++v18 )
{
v20 = *v18;
if ( !*v18 )
break;
m_eObjType = v20[18].m_eObjType;
if ( m_eObjType > 744 )
{
v24 = m_eObjType - 899;
if ( v24 )
{
v25 = v24 - 1;
if ( v25 )
{
if ( v25 != 15 )
{
LABEL_36:
m_uAutoReleaseCount = 0;
LABEL_40:
sub_140060D70((__int64)v37, (__int64)v36, (unsigned __int8 *)&m_uAutoReleaseCount);
continue;
}
m_uAutoReleaseCount = 1002;
}
else
{
m_uAutoReleaseCount = 1009;
}
}
else
{
m_uAutoReleaseCount = v20[18].m_uAutoReleaseCount;
if ( m_uAutoReleaseCount < 1000 )
goto LABEL_40;
}
}
else if ( m_eObjType == 744 )
{
m_uAutoReleaseCount = 1003;
}
else
{
v22 = m_eObjType - 29;
if ( v22 )
{
v23 = v22 - 1;
if ( v23 )
{
if ( v23 != 75 )
goto LABEL_36;
m_uAutoReleaseCount = 1004;
}
else
{
m_uAutoReleaseCount = 1001;
}
}
else
{
m_uAutoReleaseCount = 1000;
}
}
}
}
}
for ( k = 1; k <= 1000; ++k )
{
v27 = k;
v28 = *(_QWORD *)(v39[0]
+ 16
* ((0x100000001B3LL
* (((unsigned __int64)(unsigned int)k >> 24)
^ (0x100000001B3LL
* (BYTE2(k)
^ (0x100000001B3LL
* ((0x100000001B3LL * ((unsigned __int8)k ^ 0xCBF29CE484222325uLL)) ^ BYTE1(k)))))))
& v40)
+ 8);
if ( (void *)v28 != v38 )
{
if ( k == *(_DWORD *)(v28 + 16) )
goto LABEL_49;
while ( v28 != *(_QWORD *)(v39[0]
+ 16
* ((0x100000001B3LL
* (((unsigned __int64)(unsigned int)k >> 24)
^ (0x100000001B3LL
* (BYTE2(k)
^ (0x100000001B3LL
* ((0x100000001B3LL * ((unsigned __int8)k ^ 0xCBF29CE484222325uLL)) ^ BYTE1(k)))))))
& v40)) )
{
v28 = *(_QWORD *)(v28 + 8);
if ( k == *(_DWORD *)(v28 + 16) )
goto LABEL_49;
}
}
v28 = 0;
LABEL_49:
if ( !v28 )
{
v29 = k;
if ( k < 0 )
v29 = 0;
m_effectManager = a1->m_levelSettings->GJBaseGameLayer::m_effectManager;
Myfirst = m_effectManager->m_colorActionVector._Mypair._Myval2._Myfirst;
if ( !Myfirst[v29] )
break;
v32 = Myfirst[v29];
if ( !v32 )
{
v32 = ColorAction::create();
if ( v29 < 0 )
v29 = 0;
v32->m_colorID = v29;
cocos2d::CCDictionary::setObject(m_effectManager->m_unkObject148, v32, v29);
m_effectManager->m_colorActionVector._Mypair._Myval2._Myfirst[v29] = v32;
ColorSprite = GJEffectManager::getColorSprite(m_effectManager, v29);
v32->m_colorSprite = ColorSprite;
ColorSprite->m_colorAction = v32;
}
LOWORD(m_uAutoReleaseCount) = *(_WORD *)&v32->m_fromColor.r;
if ( (_WORD)m_uAutoReleaseCount == 0xFFFF
&& v32->m_fromColor.b == 0xFF
&& v32->m_fromOpacity == 1.0
&& !v32->m_copyID
&& !v32->m_blending
&& v32->m_playerColor <= 0 )
{
break;
}
}
}
if ( v27 > 999 )
v27 = 999;
sub_14005D100((__int64)v39);
sub_14005D870(&v38);
return v27;
}