//
// LevelEditorLayer::getNextColorChannel from 0x473400 to 0x4738ec (1260 bytes)
//
// 2 xrefs:
// > CustomizeObjectLayer::onNextColorChannel @ 0x57eb18
// > EditorUI::pasteObjects @ 0x6f2f72
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 11:49:06 +0000
//
int __fastcall LevelEditorLayer::getNextColorChannel(LevelEditorLayer *this)
{
int AllObjects; // r0
int v3; // r3
_DWORD *v4; // r3
GameObject **v5; // r6
GameObject *v6; // r4
GameObject *v7; // t1
_DWORD *v8; // r3
GameObject **v9; // r7
GameObject **v10; // r11
void *i; // r3
GameObject *v12; // r0
GameObject *v13; // t1
void *v14; // r4
ColorAction *ColorAction; // r0
int result; // r0
GJSpriteColor *SecondaryColorMode; // r0
unsigned int v18; // r10
unsigned int v19; // r4
unsigned int v20; // r11
unsigned int v21; // r5
_DWORD *v22; // r3
unsigned int v23; // r0
int v24; // r1
float v25; // s15
bool v26; // r5
unsigned int v27; // r5
unsigned int v28; // r1
_DWORD *v29; // r3
unsigned int v30; // r0
int v31; // r1
unsigned int v32; // r10
unsigned int v33; // r4
unsigned int v34; // r11
unsigned int v35; // r5
int **v36; // r3
int *v37; // r0
int v38; // r1
float v39; // s15
bool v40; // r5
unsigned int v41; // r5
unsigned int v42; // r1
_DWORD *v43; // r3
unsigned int v44; // r0
int v45; // r1
int ColorIndex; // r0
unsigned int v47; // r6
unsigned int v48; // r4
unsigned int v49; // r10
int v50; // r5
_DWORD *v51; // r3
unsigned int v52; // r0
int v53; // r1
float v54; // s15
bool v55; // r5
unsigned int v56; // r5
unsigned int v57; // r1
_DWORD *v58; // r3
unsigned int v59; // r0
int v60; // r1
GameObject **v61; // [sp+0h] [bp-54h]
unsigned int MainColorMode; // [sp+10h] [bp-44h] BYREF
void *v63; // [sp+14h] [bp-40h] BYREF
_DWORD v64[3]; // [sp+20h] [bp-34h] BYREF
void *v65[3]; // [sp+2Ch] [bp-28h] BYREF
int v66; // [sp+38h] [bp-1Ch] BYREF
unsigned int v67; // [sp+3Ch] [bp-18h]
void *v68; // [sp+40h] [bp-14h] BYREF
int v69; // [sp+44h] [bp-10h]
float v70; // [sp+48h] [bp-Ch]
v66 = 0;
v67 = 0;
v68 = nullptr;
v69 = 0;
v70 = 1.0;
AllObjects = LevelEditorLayer::getAllObjects(this);
if ( AllObjects )
{
v4 = *(_DWORD **)(AllObjects + 52);
if ( *v4 )
{
v5 = (GameObject **)v4[3];
v61 = &v5[*v4] + 0x3FFFFFFF;
while ( 1 )
{
LABEL_6:
if ( v5 > v61 )
goto LABEL_2;
v7 = *v5++;
v6 = v7;
if ( !v7 )
goto LABEL_2;
MainColorMode = (unsigned int)GameObject::getMainColorMode(v6);
SecondaryColorMode = GameObject::getSecondaryColorMode(v6);
v18 = MainColorMode;
v65[0] = SecondaryColorMode;
if ( (int)MainColorMode >= 1000 )
goto LABEL_54;
v19 = v67;
if ( v67 )
{
v20 = v67 - 1;
if ( ((v67 - 1) & v67) != 0 )
v21 = MainColorMode % v67;
else
v21 = v20 & MainColorMode;
v22 = *(_DWORD **)(v66 + 4 * v21);
if ( v22 )
{
while ( 1 )
{
v22 = (_DWORD *)*v22;
if ( !v22 )
break;
v23 = v22[1];
v24 = ((v67 - 1) & v67) != 0 ? v23 % v67 : v20 & v23;
if ( v24 != v21 )
break;
if ( v22[2] == MainColorMode )
goto LABEL_54;
}
}
}
else
{
v21 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(int)&v63,
(int)&v66,
MainColorMode,
&MainColorMode);
v25 = (float)(unsigned int)(v69 + 1);
if ( v25 > (float)((float)v19 * v70) )
break;
if ( !v19 )
{
v26 = 0;
LABEL_40:
v27 = 2 * v19 + !v26;
v28 = (unsigned int)ceilf(v25 / v70);
if ( v28 < v27 )
v28 = v27;
std::__hash_table,std::equal_to,std::allocator>::rehash((int)&v66, v28);
v19 = v67;
if ( ((v67 - 1) & v67) != 0 )
v21 = v18 % v67;
else
v21 = (v67 - 1) & v18;
}
v29 = *(_DWORD **)(v66 + 4 * v21);
if ( v29 )
{
*(_DWORD *)v63 = *v29;
*v29 = v63;
}
else
{
*(_DWORD *)v63 = v68;
v68 = v63;
*(_DWORD *)(v66 + 4 * v21) = &v68;
if ( *(_DWORD *)v63 )
{
v30 = *(_DWORD *)(*(_DWORD *)v63 + 4);
if ( ((v19 - 1) & v19) != 0 )
v31 = v30 % v19;
else
v31 = (v19 - 1) & v30;
*(_DWORD *)(v66 + 4 * v31) = v63;
}
}
++v69;
LABEL_54:
v32 = (unsigned int)v65[0];
if ( (int)v65[0] < 1000 )
{
v33 = v67;
if ( v67 )
{
v34 = v67 - 1;
if ( ((v67 - 1) & v67) != 0 )
v35 = (unsigned int)v65[0] % v67;
else
v35 = v34 & (unsigned int)v65[0];
v36 = *(int ***)(v66 + 4 * v35);
if ( v36 )
{
while ( 1 )
{
v36 = (int **)*v36;
if ( !v36 )
break;
v37 = v36[1];
v38 = ((v67 - 1) & v67) != 0 ? (unsigned int)v37 % v67 : v34 & (unsigned int)v37;
if ( v38 != v35 )
break;
if ( v36[2] == v65[0] )
goto LABEL_6;
}
}
}
else
{
v35 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(int)v64,
(int)&v66,
(int)v65[0],
v65);
v39 = (float)(unsigned int)(v69 + 1);
if ( v39 > (float)((float)v33 * v70) )
{
v40 = v33 > 2 && ((v33 - 1) & v33) == 0;
}
else
{
if ( v33 )
goto LABEL_75;
v40 = 0;
}
v41 = 2 * v33 + !v40;
v42 = (unsigned int)ceilf(v39 / v70);
if ( v42 < v41 )
v42 = v41;
std::__hash_table,std::equal_to,std::allocator>::rehash((int)&v66, v42);
v33 = v67;
if ( ((v67 - 1) & v67) != 0 )
v35 = v32 % v67;
else
v35 = (v67 - 1) & v32;
LABEL_75:
v43 = *(_DWORD **)(v66 + 4 * v35);
if ( v43 )
{
*(_DWORD *)v64[0] = *v43;
*v43 = v64[0];
}
else
{
*(_DWORD *)v64[0] = v68;
v68 = (void *)v64[0];
*(_DWORD *)(v66 + 4 * v35) = &v68;
if ( *(_DWORD *)v64[0] )
{
v44 = *(_DWORD *)(*(_DWORD *)v64[0] + 4);
if ( ((v33 - 1) & v33) != 0 )
v45 = v44 % v33;
else
v45 = (v33 - 1) & v44;
*(_DWORD *)(v66 + 4 * v45) = v64[0];
}
}
++v69;
}
}
v26 = v19 > 2 && ((v19 - 1) & v19) == 0;
goto LABEL_40;
}
}
LABEL_2:
v3 = *((_DWORD *)this + 2933);
if ( v3 )
{
v8 = *(_DWORD **)(v3 + 52);
if ( *v8 )
{
v9 = (GameObject **)v8[3];
v10 = &v9[*v8] + 0x3FFFFFFF;
while ( 1 )
{
do
{
LABEL_11:
if ( v9 > v10 )
goto LABEL_12;
v13 = *v9++;
v12 = v13;
if ( !v13 )
goto LABEL_12;
ColorIndex = GameObject::getColorIndex(v12);
v47 = ColorIndex;
v64[0] = ColorIndex;
}
while ( ColorIndex >= 1000 );
v48 = v67;
if ( v67 )
{
v49 = v67 - 1;
if ( ((v67 - 1) & v67) != 0 )
v50 = ColorIndex % v67;
else
v50 = ColorIndex & v49;
v51 = *(_DWORD **)(v66 + 4 * v50);
if ( v51 )
{
while ( 1 )
{
v51 = (_DWORD *)*v51;
if ( !v51 )
break;
v52 = v51[1];
v53 = ((v67 - 1) & v67) != 0 ? v52 % v67 : v49 & v52;
if ( v53 != v50 )
break;
if ( v51[2] == v47 )
goto LABEL_11;
}
}
}
else
{
v50 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(int)v65,
(int)&v66,
v47,
v64);
v54 = (float)(unsigned int)(v69 + 1);
if ( v54 > (float)((float)v48 * v70) )
{
v55 = v48 > 2 && ((v48 - 1) & v48) == 0;
}
else
{
if ( v48 )
goto LABEL_112;
v55 = 0;
}
v56 = 2 * v48 + !v55;
v57 = (unsigned int)ceilf(v54 / v70);
if ( v57 < v56 )
v57 = v56;
std::__hash_table,std::equal_to,std::allocator>::rehash((int)&v66, v57);
v48 = v67;
if ( ((v67 - 1) & v67) != 0 )
v50 = v47 % v67;
else
v50 = (v67 - 1) & v47;
LABEL_112:
v58 = *(_DWORD **)(v66 + 4 * v50);
if ( v58 )
{
*(_DWORD *)v65[0] = *v58;
*v58 = v65[0];
}
else
{
*(_DWORD *)v65[0] = v68;
v68 = v65[0];
*(_DWORD *)(v66 + 4 * v50) = &v68;
if ( *(_DWORD *)v65[0] )
{
v59 = *(_DWORD *)(*(_DWORD *)v65[0] + 4);
if ( ((v48 - 1) & v48) != 0 )
v60 = v59 % v48;
else
v60 = (v48 - 1) & v59;
*(void **)(v66 + 4 * v60) = v65[0];
}
}
++v69;
}
}
}
LABEL_12:
v65[0] = &dword_0 + 1;
for ( i = nullptr; ; i = v14 )
{
v14 = v65[0];
if ( (int)v65[0] > 1000 )
break;
if ( !std::__hash_table,std::equal_to,std::allocator>::find(
&v66,
(unsigned int *)v65) )
{
if ( !GJEffectManager::colorExists(*(GJEffectManager **)(*((_DWORD *)this + 521) + 264), (int)v65[0]) )
goto LABEL_21;
ColorAction = (ColorAction *)GJEffectManager::getColorAction(
*(GJEffectManager **)(*((_DWORD *)this + 521) + 264),
(int)v14);
if ( !ColorAction::isInUse(ColorAction) )
goto LABEL_21;
}
++v65[0];
}
v14 = i;
LABEL_21:
std::__hash_table,std::equal_to,std::allocator>::~__hash_table((int)&v66);
result = 999;
if ( (int)v14 <= 999 )
return (int)v14;
return result;
}