//
// GJGarageLayer::setupPage from 0x797480 to 0x797c90 (2064 bytes)
//
// 5 xrefs:
// > GJGarageLayer::onArrow @ 0x797e38
// > GJGarageLayer::onArrow @ 0x797e70
// > GJGarageLayer::onNavigate @ 0x797f6c
// > GJGarageLayer::selectTab @ 0x7980f8
// > ??> @ 0x634f8
//
// 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::setupPage(GJGarageLayer *a1, int a2, IconType a3)
{
cocos2d::CCPoint v5; // x3
void (*setVisible)(void); // x2
GameManager *v8; // x0
int active; // w26
GameManager *v10; // x0
int v11; // w23
std::_rb_tree_base *m_parent; // x0
std::_rb_tree_base *p_m_header; // x28
__int64 insert_unique_pos; // x22
cocos2d::CCDirector *v15; // x0
cocos2d::CCArray *Items; // x20
ListButtonBar *m_iconSelection; // x0
float v18; // s4
float v19; // s5
ListButtonBar *v20; // x0
CCMenuItemSpriteExtra *m_currentIcon; // x1
cocos2d::CCSprite *m_cursor1; // x20
void (__fastcall *setPosition)(cocos2d::CCSprite *__hidden, const cocos2d::CCPoint *); // x22
cocos2d::CCNode *v24; // x26
const cocos2d::CCPoint *v25; // x0
cocos2d::CCMenu *m_navDotMenu; // x2
int v27; // w23
cocos2d::CCSprite *v28; // x20
CCMenuItemSpriteExtra *v29; // x20
void (__fastcall *setTag)(cocos2d::CCObject *__hidden, int); // x28
int v31; // w0
unsigned int v32; // w20
cocos2d::CCNode *v33; // x22
__int64 v34; // x22
void (__fastcall *v35)(__int64, cocos2d::CCSpriteFrame *); // x28
cocos2d::CCSpriteFrameCache *v36; // x0
cocos2d::CCSpriteFrame *v37; // x0
cocos2d::CCMenu *v38; // x23
GameManager *v39; // x0
bool v40; // w20
ListButtonBar *v41; // x19
void *v42; // x0
unsigned int *v43; // x3
int v44; // w1
__int64 v45; // x0
int *v46; // x20
__int64 v47; // x4
char *v48; // x1
char *v49; // x3
std::_rb_tree_base *m_left; // x0
std::_rb_tree_base *m_right; // x2
int *v52; // x1
_BOOL8 v53; // x0
std::_rb_tree_base *v54; // x0
std::_rb_tree_base *v55; // x1
__int64 v56; // [xsp+30h] [xbp+0h] BYREF
char *v57; // [xsp+B8h] [xbp+88h]
__int64 v58; // [xsp+C0h] [xbp+90h]
char *v59; // [xsp+C8h] [xbp+98h]
float v60; // [xsp+E0h] [xbp+B0h]
float v61; // [xsp+E4h] [xbp+B4h]
cocos2d::CCPoint v62; // [xsp+E8h] [xbp+B8h] BYREF
cocos2d::CCPoint v63; // [xsp+F0h] [xbp+C0h] BYREF
__int64 v64; // [xsp+F8h] [xbp+C8h] BYREF
cocos2d::CCPoint v65[2]; // [xsp+100h] [xbp+D0h] BYREF
cocos2d::CCPoint v66; // 0:kr08_8.8
cocos2d::SEL_MenuHandler v67; // 0:x2.16
cocos2d::CCPoint v68; // 0:s0.4,4:s1.4
v5 = (cocos2d::CCPoint)_stack_chk_guard;
setVisible = (void (*)(void))a1->m_cursor2->setVisible;
a1->m_iconType = a3;
v65[1] = v5;
setVisible();
if ( a1->m_iconType == Special )
{
GJGarageLayer::setupSpecialPage(a1);
return;
}
v8 = GameManager::sharedState();
active = GameManager::activeIconForType(v8, a3);
v10 = GameManager::sharedState();
v11 = GameManager::countForType(v10, a3);
if ( a2 == -1 )
{
a2 = vcvtms_s32_f32((float)((active - 1) / 36));
if ( a2 < 0 )
a2 = 0;
}
m_parent = a1->m_iconPages.m_header.m_parent;
p_m_header = &a1->m_iconPages.m_header;
if ( !m_parent )
goto LABEL_48;
insert_unique_pos = (__int64)&a1->m_iconPages.m_header;
do
{
while ( a3 <= *(_DWORD *)&m_parent[1].m_isblack )
{
insert_unique_pos = (__int64)m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_7;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_7:
if ( p_m_header == (std::_rb_tree_base *)insert_unique_pos )
{
LABEL_48:
v46 = (int *)operator new(0x28u);
v52 = v46 + 8;
v46[8] = a3;
v46[9] = 0;
if ( a1->m_iconPages.m_nodecount )
{
m_right = a1->m_iconPages.m_header.m_right;
if ( *(_DWORD *)&m_right[1].m_isblack < a3 )
{
insert_unique_pos = 0;
goto LABEL_38;
}
}
goto LABEL_53;
}
if ( a3 >= *(_DWORD *)(insert_unique_pos + 32) )
goto LABEL_9;
v59 = (char *)(unsigned int)a3;
v45 = operator new(0x28u);
*(_DWORD *)(v45 + 32) = a3;
*(_DWORD *)(v45 + 36) = 0;
v46 = (int *)v45;
v47 = *(unsigned int *)(insert_unique_pos + 32);
v48 = (char *)(v45 + 32);
v49 = v59;
if ( a3 < (int)v47 )
{
m_left = a1->m_iconPages.m_header.m_left;
v59 = v48;
if ( m_left == (std::_rb_tree_base *)insert_unique_pos )
{
m_right = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_38;
}
m_right = (std::_rb_tree_base *)sub_CFABD4(insert_unique_pos);
v52 = (int *)v59;
if ( a3 > *(_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_38;
}
LABEL_53:
insert_unique_pos = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)&a1->m_iconPages,
v52);
m_right = v55;
if ( !v55 )
goto LABEL_47;
LABEL_38:
if ( insert_unique_pos || p_m_header == m_right )
{
insert_unique_pos = (__int64)v46;
v53 = 1;
goto LABEL_42;
}
LODWORD(v49) = v46[8];
LODWORD(v47) = *(_DWORD *)&m_right[1].m_isblack;
LABEL_41:
insert_unique_pos = (__int64)v46;
v53 = (int)v47 > (int)v49;
LABEL_42:
sub_CFAD74(v53, v46, m_right, &a1->m_iconPages.m_header);
++a1->m_iconPages.m_nodecount;
goto LABEL_9;
}
if ( a3 > (int)v47 )
{
v54 = a1->m_iconPages.m_header.m_right;
v59 = v48;
if ( v54 != (std::_rb_tree_base *)insert_unique_pos )
{
v57 = v49;
v58 = v47;
m_right = (std::_rb_tree_base *)sub_CFAB14(insert_unique_pos);
v52 = (int *)v59;
if ( a3 >= *(_DWORD *)&m_right[1].m_isblack )
goto LABEL_53;
LODWORD(v47) = v58;
LODWORD(v49) = (_DWORD)v57;
if ( *(_QWORD *)(insert_unique_pos + 24) )
{
insert_unique_pos = (__int64)m_right;
goto LABEL_38;
}
}
m_right = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_41;
}
LABEL_47:
operator delete(v46);
LABEL_9:
*(_DWORD *)(insert_unique_pos + 36) = a2;
v15 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v15);
Items = GJGarageLayer::getItems((__int64)a1, v11, a2, a3, active);
m_iconSelection = a1->m_iconSelection;
if ( m_iconSelection )
{
m_iconSelection->removeMeAndCleanup(m_iconSelection);
a1->m_iconSelection = nullptr;
}
cocos2d::CCPoint::CCPoint(v65, v60 * 0.5, (float)((float)(v61 * 0.5) + -5.0) - 60.0);
v68.x = 5.0;
v68.y = 5.0;
v20 = ListButtonBar::create(Items, v68, (unsigned int)&v56 + 208, 12, 25.0, 220.0, v18, v19, 3);
a1->m_iconSelection = v20;
BoomScrollLayer::togglePageIndicators(v20->m_scrollLayer, 0);
a1->addChild_0(a1, a1->m_iconSelection, 100);
m_currentIcon = a1->m_currentIcon;
if ( m_currentIcon )
{
m_cursor1 = a1->m_cursor1;
setPosition = m_cursor1->setPosition;
v24 = m_currentIcon->getParent(a1->m_currentIcon);
v25 = a1->m_currentIcon->getPosition(a1->m_currentIcon);
v66 = cocos2d::CCNode::convertToWorldSpace(v24, v25);
((void (__fastcall *)(cocos2d::CCSprite *, cocos2d::CCPoint *, float, float))setPosition)(
m_cursor1,
v65,
v66.x,
v66.y);
a1->m_cursor1->setVisible(a1->m_cursor1, 1);
}
else
{
a1->m_cursor1->setVisible(a1->m_cursor1, 0);
}
a1->m_leftArrow->setEnabled(a1->m_leftArrow, v11 > 36);
a1->m_leftArrow->setVisible(a1->m_leftArrow, v11 > 36);
a1->m_rightArrow->setEnabled(a1->m_rightArrow, v11 > 36);
a1->m_rightArrow->setVisible(a1->m_rightArrow, v11 > 36);
m_navDotMenu = a1->m_navDotMenu;
if ( v11 <= 36 )
{
m_navDotMenu->setEnabled(a1->m_navDotMenu, 0);
a1->m_navDotMenu->setVisible(a1->m_navDotMenu, 0);
if ( a3 != DeathEffect )
return;
goto LABEL_27;
}
m_navDotMenu->setEnabled(a1->m_navDotMenu, 1);
a1->m_navDotMenu->setVisible(a1->m_navDotMenu, 1);
a1->m_navDotMenu->removeAllChildren(a1->m_navDotMenu);
v27 = (int)(float)(floorf((float)(v11 / 36)) + 1.0);
while ( (unsigned int)cocos2d::CCArray::count(a1->m_pageButtons) < v27 )
{
v28 = cocos2d::CCSprite::createWithSpriteFrameName("gj_navDotBtn_on_001.png");
v28->setScale(v28, 0.9);
v67.adj = (size_t)GJGarageLayer::onNavigate;
v67.ptr = (void (__cdecl *)(cocos2d::CCObject *))a1;
v29 = CCMenuItemSpriteExtra::create(v28, nullptr, v67);
setTag = v29->setTag;
v31 = cocos2d::CCArray::count(a1->m_pageButtons);
setTag(v29, v31);
cocos2d::CCArray::addObject(a1->m_pageButtons, v29);
CCMenuItemSpriteExtra::setSizeMult(v29, 1.1);
}
v32 = 0;
if ( v27 > 0 )
{
v59 = "gj_navDotBtn_on_001.png";
do
{
v33 = (cocos2d::CCNode *)cocos2d::CCArray::objectAtIndex(a1->m_pageButtons, v32);
a1->m_navDotMenu->addChild(a1->m_navDotMenu, v33);
v34 = ((__int64 (__fastcall *)(cocos2d::CCNode *))v33->__vftable[1].setScale_0)(v33);
v35 = *(void (__fastcall **)(__int64, cocos2d::CCSpriteFrame *))(*(_QWORD *)v34 + 1144LL);
v36 = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache();
if ( v32 == a2 )
v37 = cocos2d::CCSpriteFrameCache::spriteFrameByName(v36, v59);
else
v37 = cocos2d::CCSpriteFrameCache::spriteFrameByName(v36, "gj_navDotBtn_off_001.png");
v35(v34, v37);
++v32;
}
while ( v32 != v27 );
}
cocos2d::CCMenu::alignItemsHorizontallyWithPadding(a1->m_navDotMenu, 6.0);
if ( a3 == DeathEffect )
{
LABEL_27:
v38 = cocos2d::CCMenu::create();
a1->m_iconSelection->addChild_0(a1->m_iconSelection, v38, 1);
cocos2d::CCPoint::CCPoint(&v62, 8.0, 0.0);
sub_D153B8((int)&v64, "Explode");
v39 = GameManager::sharedState();
v40 = !GameManager::getGameVariable(v39, "0153");
cocos2d::CCPoint::CCPoint(
&v63,
(float)(v60 * 0.5) + -165.0,
(float)((float)((float)(v61 * 0.5) + -5.0) - 60.0) - 30.0);
v41 = a1->m_iconSelection;
cocos2d::CCPoint::CCPoint(v65, &v62);
GameToolbox::createToggleButton(
0.6,
0.5,
80.0,
(__int64)&v64,
(void (__cdecl *)(cocos2d::CCObject *))GJGarageLayer::onSpecial,
0,
v40,
v38,
&v63,
v41,
v41,
(float *)v65,
(__int64)"goldFont.fnt",
0,
0,
nullptr);
v42 = (void *)(v64 - 24);
if ( (__int64 *)(v64 - 24) != &qword_124B6B0 )
{
v43 = (unsigned int *)(v64 - 8);
if ( &pthread_create )
{
do
v44 = __ldaxr(v43);
while ( __stlxr(v44 - 1, v43) );
}
else
{
v44 = *(_DWORD *)(v64 - 8);
*(_DWORD *)(v64 - 8) = v44 - 1;
}
if ( v44 <= 0 )
operator delete(v42);
}
}
}