//
// GJOptionsLayer::goToPage from 0x8c8cb8 to 0x8c90d4 (1052 bytes)
//
// 4 xrefs:
// > GJOptionsLayer::init @ 0x8c9398
// > GJOptionsLayer::onNextPage @ 0x8c96ac
// > GJOptionsLayer::onPrevPage @ 0x8c96b8
// > ??> @ 0xbff40
//
// 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 GJOptionsLayer::goToPage(GJOptionsLayer *a1, int a2)
{
int v2; // w22
int m_maxPage; // w0
int m_page; // w1
cocos2d::CCDictionary *m_values; // x19
char *v7; // x0
cocos2d::CCArray *v8; // x20
char *v9; // x0
unsigned int v10; // w19
unsigned int v11; // w1
__int64 v12; // x0
cocos2d::CCDictionary *v13; // x19
char *v14; // x0
__int64 v15; // x19
char *v16; // x0
cocos2d::CCDictionary *v17; // x19
char *v18; // x0
cocos2d::CCArray *v19; // x20
char *v20; // x0
unsigned int v21; // w19
unsigned int v22; // w1
__int64 v23; // x0
cocos2d::CCDictionary *v24; // x19
char *v25; // x0
__int64 v26; // x19
char *v27; // x23
CCMenuItemSpriteExtra *m_prevButton; // x2
unsigned int *v29; // x1
int v30; // w2
unsigned int *v31; // x20
int v32; // w0
unsigned int *v33; // x1
int v34; // w2
unsigned int *v35; // x1
int v36; // w2
_QWORD v37[2]; // [xsp+0h] [xbp+0h] BYREF
std::string v38; // [xsp+60h] [xbp+60h] BYREF
v2 = a2;
m_maxPage = a1->m_maxPage;
if ( m_maxPage < a2 )
{
v2 = 0;
}
else if ( a2 < 0 )
{
v2 = m_maxPage;
}
m_page = a1->m_page;
if ( m_page != v2 )
{
m_values = a1->m_values;
v7 = (char *)GJOptionsLayer::objectKey(a1, m_page);
sub_D153B8((unsigned int)v37 + 96, v7);
v8 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(m_values, &v38);
v9 = (char *)v38.m_data.m_data - 24;
if ( (__int64 *)v38.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v35 = (unsigned int *)((char *)v38.m_data.m_data - 8);
do
v36 = __ldaxr(v35);
while ( __stlxr(v36 - 1, v35) );
}
else
{
v36 = *((_DWORD *)v38.m_data.m_data - 2);
*((_DWORD *)v38.m_data.m_data - 2) = v36 - 1;
}
if ( v36 <= 0 )
operator delete(v9);
}
v10 = 0;
if ( v8 )
{
while ( v10 < (unsigned int)cocos2d::CCArray::count(v8) )
{
v11 = v10++;
v12 = cocos2d::CCArray::objectAtIndex(v8, v11);
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v12 + 328LL))(v12, 0);
}
}
v13 = a1->m_values;
v14 = (char *)GJOptionsLayer::layerKey(a1, a1->m_page);
sub_D153B8((unsigned int)v37 + 96, v14);
v15 = cocos2d::CCDictionary::objectForKey(v13, &v38);
v16 = (char *)v38.m_data.m_data - 24;
if ( (__int64 *)v38.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_11;
if ( &pthread_create )
{
v29 = (unsigned int *)((char *)v38.m_data.m_data - 8);
do
v30 = __ldaxr(v29);
while ( __stlxr(v30 - 1, v29) );
}
else
{
v30 = *((_DWORD *)v38.m_data.m_data - 2);
*((_DWORD *)v38.m_data.m_data - 2) = v30 - 1;
}
if ( v30 > 0 )
{
LABEL_11:
if ( !v15 )
{
LABEL_13:
v17 = a1->m_values;
v18 = (char *)GJOptionsLayer::objectKey(a1, v2);
sub_D153B8((unsigned int)v37 + 96, v18);
v19 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(v17, &v38);
v20 = (char *)v38.m_data.m_data - 24;
if ( (__int64 *)v38.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v33 = (unsigned int *)((char *)v38.m_data.m_data - 8);
do
v34 = __ldaxr(v33);
while ( __stlxr(v34 - 1, v33) );
}
else
{
v34 = *((_DWORD *)v38.m_data.m_data - 2);
*((_DWORD *)v38.m_data.m_data - 2) = v34 - 1;
}
if ( v34 <= 0 )
operator delete(v20);
}
v21 = 0;
if ( v19 )
{
while ( v21 < (unsigned int)cocos2d::CCArray::count(v19) )
{
v22 = v21++;
v23 = cocos2d::CCArray::objectAtIndex(v19, v22);
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v23 + 328LL))(v23, 1);
}
}
v24 = a1->m_values;
v25 = (char *)GJOptionsLayer::layerKey(a1, v2);
sub_D153B8((unsigned int)v37 + 96, v25);
v26 = cocos2d::CCDictionary::objectForKey(v24, &v38);
v27 = (char *)v38.m_data.m_data - 24;
if ( (__int64 *)v38.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_19;
if ( &pthread_create )
{
v31 = (unsigned int *)((char *)v38.m_data.m_data - 8);
do
v32 = __ldaxr(v31);
while ( __stlxr(v32 - 1, v31) );
}
else
{
v32 = *((_DWORD *)v38.m_data.m_data - 2);
*((_DWORD *)v38.m_data.m_data - 2) = v32 - 1;
}
if ( v32 > 0 )
{
LABEL_19:
if ( !v26 )
{
LABEL_21:
m_prevButton = a1->m_prevButton;
a1->m_page = v2;
m_prevButton->setVisible(m_prevButton, v2 > 0);
a1->m_nextButton->setVisible(a1->m_nextButton, a1->m_page < a1->m_maxPage);
return;
}
}
else
{
operator delete(v27);
if ( !v26 )
goto LABEL_21;
}
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v26 + 328LL))(v26, 1);
goto LABEL_21;
}
}
else
{
operator delete(v16);
if ( !v15 )
goto LABEL_13;
}
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v15 + 328LL))(v15, 0);
goto LABEL_13;
}
}