//
// AchievementsLayer::loadPage from 0x607de8 to 0x60850c (1828 bytes)
//
// 4 xrefs:
// > AchievementsLayer::customSetup @ 0x608754
// > AchievementsLayer::onNextPage @ 0x6087cc
// > AchievementsLayer::onPrevPage @ 0x6087d8
// > ??> @ 0xa36f8
//
// 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 AchievementsLayer::loadPage(AchievementsLayer *a1, int a2)
{
stl::StringData::Internal *v3; // x0
cocos2d::CCArray *m_allAchievementsSorted; // x21
AchievementManager *v5; // x0
unsigned int v6; // w22
cocos2d::CCDictionary *v7; // x19
cocos2d::CCString *v8; // x0
char *CString; // x0
char *v10; // x0
stl::StringData::Internal *m_data; // x28
__int64 *v12; // x26
size_t v13; // x27
char *v14; // x3
size_t v15; // x2
int v16; // w25
char *v17; // x0
AchievementManager *v18; // x0
unsigned int v19; // w22
cocos2d::CCArray *isAchievementEarned; // x0
cocos2d::CCDictionary *v21; // x19
cocos2d::CCString *v22; // x0
char *v23; // x0
char *v24; // x0
stl::StringData::Internal *v25; // x26
__int64 *v26; // x25
unsigned __int64 v27; // x28
unsigned __int64 v28; // x27
size_t v29; // x2
unsigned int v30; // w0
__int64 v31; // x2
signed __int64 v32; // x3
char *v33; // x0
cocos2d::CCArray *v34; // x20
int v35; // w22
int v36; // w24
unsigned int v37; // w19
bool v38; // cf
CCMenuItemSpriteExtra *m_nextPageButton; // x2
AchievementsLayer *v40; // x19
unsigned int *v41; // x4
int v42; // w0
char *v43; // x0
unsigned int *v44; // x1
int v45; // w2
unsigned int *v46; // x1
int v47; // w2
unsigned int *v48; // x1
int v49; // w2
unsigned int *v50; // x4
int v51; // w0
unsigned int *v52; // x1
int v53; // w2
unsigned int *v54; // x1
int v55; // w2
unsigned int *v56; // x1
int v57; // w2
unsigned int v58; // w19
unsigned int v59; // w1
cocos2d::CCObject *v60; // x0
_QWORD v61[2]; // [xsp+0h] [xbp+0h] BYREF
int v62; // [xsp+6Ch] [xbp+6Ch]
AchievementsLayer *v63; // [xsp+70h] [xbp+70h]
char *v64; // [xsp+78h] [xbp+78h]
char *v65; // [xsp+80h] [xbp+80h]
char *v66; // [xsp+88h] [xbp+88h]
char v67; // [xsp+A0h] [xbp+A0h] BYREF
_QWORD *v68; // [xsp+A8h] [xbp+A8h] BYREF
std::string v69[2]; // [xsp+B0h] [xbp+B0h] BYREF
v63 = a1;
v62 = a2;
v3 = (stl::StringData::Internal *)_stack_chk_guard;
a1->m_currentPage = a2;
v69[1].m_data.m_data = v3;
if ( a2 <= 0 )
v63->m_prevPageButton->setVisible(v63->m_prevPageButton, 0);
else
a1->m_prevPageButton->setVisible(a1->m_prevPageButton, 1);
m_allAchievementsSorted = AchievementManager::sharedState()->m_allAchievementsSorted;
v5 = AchievementManager::sharedState();
v6 = 0;
if ( !AchievementManager::isAchievementEarned(v5, "geometry.ach.steam01") )
{
v64 = "identifier";
v65 = &v67;
if ( (unsigned int)cocos2d::CCArray::count(m_allAchievementsSorted) )
{
do
{
v7 = (cocos2d::CCDictionary *)cocos2d::CCArray::objectAtIndex(m_allAchievementsSorted, v6);
sub_D153B8((int)v69, v64);
v8 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v7, v69);
CString = (char *)cocos2d::CCString::getCString(v8);
sub_D153B8((int)&v68, CString);
v10 = (char *)v69[0].m_data.m_data - 24;
if ( (__int64 *)v69[0].m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v48 = (unsigned int *)((char *)v69[0].m_data.m_data - 8);
do
v49 = __ldaxr(v48);
while ( __stlxr(v49 - 1, v48) );
}
else
{
v49 = *((_DWORD *)v69[0].m_data.m_data - 2);
*((_DWORD *)v69[0].m_data.m_data - 2) = v49 - 1;
}
if ( v49 <= 0 )
operator delete(v10);
}
sub_D153B8((unsigned int)v61 + 176, "geometry.ach.steam01");
m_data = v69[0].m_data.m_data;
v12 = (__int64 *)((char *)v69[0].m_data.m_data - 24);
v13 = *((_QWORD *)v69[0].m_data.m_data - 3);
v14 = (char *)*(v68 - 3);
v66 = v14;
if ( v13 > (unsigned __int64)v14 )
v15 = (size_t)v14;
else
v15 = v13;
v16 = memcmp(v68, v69[0].m_data.m_data, v15);
if ( !v16 )
{
v16 = 0x7FFFFFFF;
if ( (__int64)&v66[-v13] <= 0x7FFFFFFF )
{
if ( (__int64)&v66[-v13] >= (__int64)0xFFFFFFFF80000000LL )
v16 = (_DWORD)v66 - v13;
else
v16 = 0x80000000;
}
}
if ( v12 == &qword_124B6B0 )
goto LABEL_15;
if ( &pthread_create )
{
v41 = (unsigned int *)((char *)m_data - 8);
do
v42 = __ldaxr(v41);
while ( __stlxr(v42 - 1, v41) );
}
else
{
v42 = *((_DWORD *)m_data - 2);
*((_DWORD *)m_data - 2) = v42 - 1;
}
if ( v42 > 0 )
{
LABEL_15:
if ( !v16 )
goto LABEL_46;
}
else
{
operator delete(v12);
if ( !v16 )
{
LABEL_46:
cocos2d::CCArray::removeObjectAtIndex(m_allAchievementsSorted, v6, 1);
v43 = (char *)(v68 - 3);
if ( v68 - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v44 = (unsigned int *)(v68 - 1);
do
v45 = __ldaxr(v44);
while ( __stlxr(v45 - 1, v44) );
}
else
{
v45 = *((_DWORD *)v68 - 2);
*((_DWORD *)v68 - 2) = v45 - 1;
}
if ( v45 <= 0 )
operator delete(v43);
}
break;
}
}
v17 = (char *)(v68 - 3);
if ( v68 - 3 == &qword_124B6B0 )
goto LABEL_17;
if ( &pthread_create )
{
v46 = (unsigned int *)(v68 - 1);
do
v47 = __ldaxr(v46);
while ( __stlxr(v47 - 1, v46) );
}
else
{
v47 = *((_DWORD *)v68 - 2);
*((_DWORD *)v68 - 2) = v47 - 1;
}
if ( v47 > 0 )
{
LABEL_17:
++v6;
}
else
{
++v6;
operator delete(v17);
}
}
while ( v6 < (unsigned int)cocos2d::CCArray::count(m_allAchievementsSorted) );
}
}
v18 = AchievementManager::sharedState();
v19 = 0;
isAchievementEarned = (cocos2d::CCArray *)AchievementManager::isAchievementEarned(v18, "geometry.ach.steam02");
if ( (_BYTE)isAchievementEarned )
goto LABEL_35;
v65 = "identifier";
v66 = &v67;
isAchievementEarned = (cocos2d::CCArray *)cocos2d::CCArray::count(m_allAchievementsSorted);
if ( !(_DWORD)isAchievementEarned )
goto LABEL_35;
while ( 1 )
{
v21 = (cocos2d::CCDictionary *)cocos2d::CCArray::objectAtIndex(m_allAchievementsSorted, v19);
sub_D153B8((int)v69, v65);
v22 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v21, v69);
v23 = (char *)cocos2d::CCString::getCString(v22);
sub_D153B8((int)&v68, v23);
v24 = (char *)v69[0].m_data.m_data - 24;
if ( (__int64 *)v69[0].m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v56 = (unsigned int *)((char *)v69[0].m_data.m_data - 8);
do
v57 = __ldaxr(v56);
while ( __stlxr(v57 - 1, v56) );
}
else
{
v57 = *((_DWORD *)v69[0].m_data.m_data - 2);
*((_DWORD *)v69[0].m_data.m_data - 2) = v57 - 1;
}
if ( v57 <= 0 )
operator delete(v24);
}
sub_D153B8((unsigned int)v61 + 176, "geometry.ach.steam02");
v25 = v69[0].m_data.m_data;
v26 = (__int64 *)((char *)v69[0].m_data.m_data - 24);
v27 = *((_QWORD *)v69[0].m_data.m_data - 3);
v28 = *(v68 - 3);
if ( v27 > v28 )
v29 = *(v68 - 3);
else
v29 = *((_QWORD *)v69[0].m_data.m_data - 3);
v30 = memcmp(v68, v69[0].m_data.m_data, v29);
v31 = v30;
if ( !v30 )
{
v31 = 0x7FFFFFFF;
v32 = v28 - v27;
if ( (__int64)(v28 - v27) <= 0x7FFFFFFF )
{
if ( v32 >= (__int64)0xFFFFFFFF80000000LL )
v31 = (unsigned int)v32;
else
v31 = 0x80000000LL;
}
}
if ( v26 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v50 = (unsigned int *)((char *)v25 - 8);
do
v51 = __ldaxr(v50);
while ( __stlxr(v51 - 1, v50) );
}
else
{
v51 = *((_DWORD *)v25 - 2);
*((_DWORD *)v25 - 2) = v51 - 1;
}
if ( v51 <= 0 )
break;
}
if ( !(_DWORD)v31 )
goto LABEL_67;
LABEL_32:
v33 = (char *)(v68 - 3);
if ( v68 - 3 == &qword_124B6B0 )
goto LABEL_33;
if ( &pthread_create )
{
v54 = (unsigned int *)(v68 - 1);
do
v55 = __ldaxr(v54);
while ( __stlxr(v55 - 1, v54) );
}
else
{
v55 = *((_DWORD *)v68 - 2);
*((_DWORD *)v68 - 2) = v55 - 1;
}
if ( v55 > 0 )
{
LABEL_33:
++v19;
}
else
{
++v19;
operator delete(v33);
}
isAchievementEarned = (cocos2d::CCArray *)cocos2d::CCArray::count(m_allAchievementsSorted);
if ( v19 >= (unsigned int)isAchievementEarned )
goto LABEL_35;
}
v64 = (char *)v31;
operator delete(v26);
if ( (_DWORD)v64 )
goto LABEL_32;
LABEL_67:
cocos2d::CCArray::removeObjectAtIndex(m_allAchievementsSorted, v19, 1);
isAchievementEarned = (cocos2d::CCArray *)(v68 - 3);
if ( v68 - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v52 = (unsigned int *)(v68 - 1);
do
v53 = __ldaxr(v52);
while ( __stlxr(v53 - 1, v52) );
}
else
{
v53 = *((_DWORD *)v68 - 2);
*((_DWORD *)v68 - 2) = v53 - 1;
}
if ( v53 <= 0 )
operator delete(isAchievementEarned);
}
LABEL_35:
v34 = (cocos2d::CCArray *)cocos2d::CCArray::create(isAchievementEarned);
v35 = 10 * v62;
v36 = cocos2d::CCArray::count(m_allAchievementsSorted);
if ( m_allAchievementsSorted && (unsigned int)cocos2d::CCArray::count(m_allAchievementsSorted) )
{
v58 = v35;
do
{
if ( v58 > (unsigned int)cocos2d::CCArray::count(m_allAchievementsSorted) - 1 )
break;
v59 = v58++;
v60 = (cocos2d::CCObject *)cocos2d::CCArray::objectAtIndex(m_allAchievementsSorted, v59);
cocos2d::CCArray::addObject(v34, v60);
}
while ( v58 != v35 + 10 );
}
v37 = cocos2d::CCArray::count(v34) + v35;
v38 = v37 >= (unsigned int)cocos2d::CCArray::count(m_allAchievementsSorted);
m_nextPageButton = v63->m_nextPageButton;
if ( v38 )
m_nextPageButton->setVisible(v63->m_nextPageButton, 0);
else
m_nextPageButton->setVisible(v63->m_nextPageButton, 1);
v40 = v63;
AchievementsLayer::setupPageInfo(v63, v36, v35, 10);
AchievementsLayer::setupLevelBrowser(v40, v34);
}