//
// LevelEditorLayer::resetUnusedColorChannels from 0x1402db440 to 0x1402db79c (860 bytes)
//
// 2 xrefs:
// > EditorPauseLayer::FLAlert_Clicked @ 0x1400de54d
// > ??> @ 0x1406d32c0
//
// 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
void LevelEditorLayer::resetUnusedColorChannels(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
cocos2d::CCDictionary *m_unkObject148; // rax
cocos2d::CCDictElement *m_pElements; // rax
cocos2d::CCDictElement *k; // rsi
int m_uUnknown; // edx
unsigned __int64 v30; // r8
__int64 v31; // rax
GJEffectManager *m_effectManager; // rdi
__int64 v33; // rbx
char v34[16]; // [rsp+20h] [rbp-60h] BYREF
_BYTE v35[16]; // [rsp+30h] [rbp-50h] BYREF
char v36[8]; // [rsp+40h] [rbp-40h] BYREF
void *v37; // [rsp+48h] [rbp-38h] BYREF
__int64 v38[3]; // [rsp+58h] [rbp-28h] BYREF
__int64 v39; // [rsp+70h] [rbp-10h]
int m_uAutoReleaseCount; // [rsp+C0h] [rbp+40h] BYREF
int v41; // [rsp+C8h] [rbp+48h] BYREF
m_uAutoReleaseCount = 0;
sub_14005E660((__int64)v36, &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;
}
v41 = v14;
if ( v11 < 1000 )
sub_140060D70((__int64)v36, (__int64)v34, (unsigned __int8 *)&m_uAutoReleaseCount);
if ( v14 < 1000 )
sub_140060D70((__int64)v36, (__int64)v35, (unsigned __int8 *)&v41);
}
}
}
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)v36, (__int64)v35, (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;
}
}
}
}
}
m_unkObject148 = a1->m_levelSettings->GJBaseGameLayer::m_effectManager->m_unkObject148;
if ( m_unkObject148 )
{
m_pElements = m_unkObject148->m_pElements;
if ( m_pElements )
{
for ( k = (cocos2d::CCDictElement *)m_pElements->hh.next; ; k = (cocos2d::CCDictElement *)k->hh.next )
{
m_uUnknown = m_pElements->m_pObject[1].m_uUnknown;
if ( (unsigned int)(m_uUnknown - 1) > 0x3E6 )
goto LABEL_54;
v30 = 2
* ((0x100000001B3LL
* (HIBYTE(m_pElements->m_pObject[1].m_uUnknown)
^ (0x100000001B3LL
* (BYTE2(m_uUnknown)
^ (0x100000001B3LL
* (BYTE1(m_uUnknown) ^ (0x100000001B3LL * ((unsigned __int8)m_uUnknown ^ 0xCBF29CE484222325uLL))))))))
& v39);
v31 = *(_QWORD *)(v38[0]
+ 16
* ((0x100000001B3LL
* (HIBYTE(m_pElements->m_pObject[1].m_uUnknown)
^ (0x100000001B3LL
* (BYTE2(m_uUnknown)
^ (0x100000001B3LL
* (BYTE1(m_uUnknown)
^ (0x100000001B3LL * ((unsigned __int8)m_uUnknown ^ 0xCBF29CE484222325uLL))))))))
& v39)
+ 8);
if ( (void *)v31 != v37 )
{
if ( m_uUnknown == *(_DWORD *)(v31 + 16) )
goto LABEL_52;
while ( v31 != *(_QWORD *)(v38[0] + 8 * v30) )
{
v31 = *(_QWORD *)(v31 + 8);
if ( m_uUnknown == *(_DWORD *)(v31 + 16) )
goto LABEL_52;
}
}
v31 = 0;
LABEL_52:
if ( !v31 )
{
m_effectManager = a1->m_levelSettings->GJBaseGameLayer::m_effectManager;
v33 = m_uUnknown;
cocos2d::CCDictionary::removeObjectForKey(m_effectManager->m_unkObject148, m_uUnknown);
m_effectManager->m_colorActionVector._Mypair._Myval2._Myfirst[v33] = nullptr;
cocos2d::CCDictionary::removeObjectForKey(m_effectManager->m_colorActionDict, v33);
}
LABEL_54:
m_pElements = k;
if ( !k )
break;
}
}
}
sub_14005D100((__int64)v38);
sub_14005D870(&v37);
}