//
// GJGarageLayer::onArrow from 0x797cac to 0x797f38 (652 bytes)
//
// 4 xrefs:
// > ??> @ 0xa1418
// > GJGarageLayer::setupIconSelect @ 0x798b14
// > GJGarageLayer::setupIconSelect @ 0x798be4
// > ??> @ 0x122d8b8
//
// 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
//
void GJGarageLayer::onArrow(GJGarageLayer *a1, cocos2d::CCObject *a2)
{
std::_rb_tree_base *p_m_header; // x21
int v4; // w23
GameManager *v5; // x0
GameManager *v6; // x0
int v7; // w22
std::_rb_tree_base *m_parent; // x0
IconType m_iconType; // w2
__int64 insert_unique_pos; // x19
__int64 v11; // x0
IconType v12; // w26
int *v13; // x25
IconType v14; // w27
IconType v15; // w28
std::_rb_tree_base *m_right; // x2
int *v17; // x1
_BOOL8 v18; // x0
int v19; // w1
int v20; // w1
GJGarageLayer *v21; // x0
std::size_t m_nodecount; // x0
std::_rb_tree_base *v23; // x1
int *v24; // [xsp+68h] [xbp+68h]
int *v25; // [xsp+68h] [xbp+68h]
p_m_header = &a1->m_iconPages.m_header;
v4 = a2->getTag(a2);
v5 = GameManager::sharedState();
GameManager::activeIconForType(v5, a1->m_iconType);
v6 = GameManager::sharedState();
v7 = GameManager::countForType(v6, a1->m_iconType);
m_parent = a1->m_iconPages.m_header.m_parent;
if ( !m_parent )
goto LABEL_29;
m_iconType = a1->m_iconType;
insert_unique_pos = (__int64)&a1->m_iconPages.m_header;
do
{
while ( *(_DWORD *)&m_parent[1].m_isblack >= m_iconType )
{
insert_unique_pos = (__int64)m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_5;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_5:
if ( p_m_header == (std::_rb_tree_base *)insert_unique_pos )
{
LABEL_29:
v13 = (int *)operator new(0x28u);
v17 = v13 + 8;
v13[8] = a1->m_iconType;
m_nodecount = a1->m_iconPages.m_nodecount;
v13[9] = 0;
if ( m_nodecount )
{
m_right = a1->m_iconPages.m_header.m_right;
if ( *(_DWORD *)&m_right[1].m_isblack < v13[8] )
{
insert_unique_pos = 0;
goto LABEL_13;
}
}
goto LABEL_32;
}
if ( *(_DWORD *)(insert_unique_pos + 32) <= m_iconType )
goto LABEL_18;
v11 = operator new(0x28u);
v12 = a1->m_iconType;
*(_DWORD *)(v11 + 32) = v12;
v13 = (int *)v11;
*(_DWORD *)(v11 + 36) = 0;
v14 = *(_DWORD *)(insert_unique_pos + 32);
v15 = v12;
if ( v12 < v14 )
{
v24 = (int *)(v11 + 32);
if ( a1->m_iconPages.m_header.m_left == (std::_rb_tree_base *)insert_unique_pos )
{
m_right = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_13;
}
m_right = (std::_rb_tree_base *)sub_CFABD4(insert_unique_pos);
v17 = v24;
if ( v12 > *(_DWORD *)&m_right[1].m_isblack )
{
if ( m_right->m_right )
m_right = (std::_rb_tree_base *)insert_unique_pos;
else
insert_unique_pos = 0;
goto LABEL_13;
}
LABEL_32:
insert_unique_pos = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)&a1->m_iconPages,
v17);
m_right = v23;
if ( !v23 )
goto LABEL_28;
LABEL_13:
if ( insert_unique_pos || p_m_header == m_right )
{
insert_unique_pos = (__int64)v13;
v18 = 1;
goto LABEL_17;
}
v15 = v13[8];
v14 = *(_DWORD *)&m_right[1].m_isblack;
LABEL_16:
insert_unique_pos = (__int64)v13;
v18 = v15 < v14;
LABEL_17:
sub_CFAD74(v18, v13, m_right, &a1->m_iconPages.m_header);
m_iconType = a1->m_iconType;
++a1->m_iconPages.m_nodecount;
goto LABEL_18;
}
if ( v12 > v14 )
{
v25 = (int *)(v11 + 32);
if ( a1->m_iconPages.m_header.m_right != (std::_rb_tree_base *)insert_unique_pos )
{
m_right = (std::_rb_tree_base *)sub_CFAB14(insert_unique_pos);
v17 = v25;
if ( v12 >= *(_DWORD *)&m_right[1].m_isblack )
goto LABEL_32;
if ( *(_QWORD *)(insert_unique_pos + 24) )
{
insert_unique_pos = (__int64)m_right;
goto LABEL_13;
}
}
m_right = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_16;
}
LABEL_28:
operator delete(v13);
m_iconType = a1->m_iconType;
LABEL_18:
v19 = *(_DWORD *)(insert_unique_pos + 36);
if ( v4 != 1 )
{
v20 = v19 - 1;
if ( (v20 & 0x80000000) == 0 )
goto LABEL_20;
LABEL_26:
v20 = v7 / 36;
v21 = a1;
goto LABEL_22;
}
v20 = v19 + 1;
if ( v20 < 0 )
goto LABEL_26;
LABEL_20:
v21 = a1;
if ( v20 > v7 / 36 )
v20 = 0;
LABEL_22:
GJGarageLayer::setupPage(v21, v20, m_iconType);
}