//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x7115e8 to 0x711a90 (1192 bytes)
//
// 2 xrefs:
// > GameLevelManager::handleIt @ 0x733294
// > ??> @ 0x77b68
//
// 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
//
__int64 __fastcall GameLevelManager::onGetLeaderboardScoresCompleted(
GameLevelManager *a1,
const void **a2,
const char **a3)
{
char *v3; // x24
cocos2d::CCArray *v6; // x19
int v7; // w20
int v8; // w23
unsigned __int64 v9; // x28
size_t v10; // x2
int v11; // w19
__int64 v12; // x28
__int64 *v13; // x0
LeaderboardManagerDelegate *v14; // x0
cocos2d::CCString *v16; // x0
cocos2d::CCArray *Scores; // x19
char *v18; // x0
int v19; // w0
cocos2d::ccArray *data; // x0
unsigned int num; // w1
cocos2d::CCObject **arr; // x0
cocos2d::CCObject **i; // x2
cocos2d::CCObject *v24; // x1
char *v25; // x21
LeaderboardManagerDelegate *m_leaderboardManagerDelegate; // x0
cocos2d::ccArray *v27; // x1
unsigned int v28; // w0
cocos2d::CCObject **v29; // x1
cocos2d::CCObject **v30; // x3
cocos2d::CCObject *v31; // x2
int j; // w0
unsigned int *v33; // x3
int v34; // w1
unsigned int *v35; // x20
int v36; // w0
unsigned int *v37; // x1
int v38; // w2
cocos2d::CCString *v39; // x0
unsigned __int64 v40; // [xsp+60h] [xbp+60h]
_DWORD *v42; // [xsp+68h] [xbp+68h]
void *v43; // [xsp+80h] [xbp+80h] BYREF
v3 = (char *)*a3;
GameLevelManager::removeDLFromActive(a1, *a3);
v6 = sub_6F004C(a3, "_");
if ( (unsigned int)cocos2d::CCArray::count(v6) == 3 )
{
v7 = 0;
v16 = cocos2d::CCArray::stringAtIndex(v6, 1u);
v8 = cocos2d::CCString::intValue(v16);
if ( (unsigned int)cocos2d::CCArray::count(v6) != 3 )
goto LABEL_15;
}
else
{
if ( (unsigned int)cocos2d::CCArray::count(v6) != 3 )
{
v7 = 0;
v8 = 0;
goto LABEL_4;
}
v8 = 0;
}
v39 = cocos2d::CCArray::stringAtIndex(v6, 2u);
v7 = cocos2d::CCString::intValue(v39);
LABEL_15:
if ( v8 == 3 )
v7 = 0;
LABEL_4:
sub_D153B8((int)&v43, "-1");
v42 = v43;
v9 = *((_QWORD *)*a2 - 3);
v40 = *((_QWORD *)v43 - 3);
if ( v40 > v9 )
v10 = *((_QWORD *)*a2 - 3);
else
v10 = *((_QWORD *)v43 - 3);
v11 = memcmp(*a2, v43, v10);
if ( v11 || (v11 = 0x7FFFFFFF, v12 = v9 - v40, v12 > 0x7FFFFFFF) )
{
v13 = (__int64 *)(v42 - 6);
if ( v42 - 6 == (_DWORD *)&qword_124B6B0 )
goto LABEL_10;
}
else
{
v13 = (__int64 *)(v42 - 6);
if ( v12 >= (__int64)0xFFFFFFFF80000000LL )
v11 = v12;
else
v11 = 0x80000000;
if ( v13 == &qword_124B6B0 )
goto LABEL_10;
}
if ( &pthread_create )
{
v33 = v42 - 2;
do
v34 = __ldaxr(v33);
while ( __stlxr(v34 - 1, v33) );
}
else
{
v34 = *(v42 - 2);
*(v42 - 2) = v34 - 1;
}
if ( v34 <= 0 )
operator delete(v13);
LABEL_10:
if ( v11 )
{
sub_D18D28(&v43, a2);
Scores = GameLevelManager::createAndGetScores(a1, (char **)&v43, v8 == 3);
v18 = (char *)v43 - 24;
if ( (char *)v43 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v37 = (unsigned int *)((char *)v43 - 8);
do
v38 = __ldaxr(v37);
while ( __stlxr(v38 - 1, v37) );
}
else
{
v38 = *((_DWORD *)v43 - 2);
*((_DWORD *)v43 - 2) = v38 - 1;
}
if ( v38 <= 0 )
operator delete(v18);
}
v19 = cocos2d::CCArray::count(Scores);
if ( Scores != nullptr && v7 != 0 )
{
if ( v19 )
{
data = Scores->data;
num = data->num;
if ( data->num )
{
arr = data->arr;
for ( i = &arr[num - 1]; i >= arr; v24[10].m_unknown2 = v7 )
{
v24 = *arr;
if ( !*arr )
break;
++arr;
}
}
}
}
if ( (unsigned int)cocos2d::CCArray::count(Scores) && v8 == 4 )
{
switch ( v7 )
{
case 2:
qsort(Scores->data->arr, Scores->data->num, 8u, (int (*)(const void *, const void *))scoreCompareDemons);
break;
case 3:
qsort(Scores->data->arr, Scores->data->num, 8u, (int (*)(const void *, const void *))scoreCompareUserCoins);
break;
case 1:
qsort(Scores->data->arr, Scores->data->num, 8u, (int (*)(const void *, const void *))scoreCompareMoons);
break;
default:
qsort(Scores->data->arr, Scores->data->num, 8u, (int (*)(const void *, const void *))scoreCompare);
break;
}
v27 = Scores->data;
v28 = v27->num;
if ( v27->num )
{
v29 = v27->arr;
v30 = &v29[v28 - 1];
if ( v29 <= v30 )
{
v31 = *v29;
for ( j = 1; *v29; v31 = *v29 )
{
++v29;
v31[6].m_eObjType = j++;
if ( v30 < v29 )
break;
}
}
}
}
sub_D153B8((int)&v43, " ");
GameLevelManager::storeSearchResult(a1, Scores, (char **)&v43, v3);
v25 = (char *)v43 - 24;
if ( (char *)v43 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v35 = (unsigned int *)((char *)v43 - 8);
do
v36 = __ldaxr(v35);
while ( __stlxr(v36 - 1, v35) );
}
else
{
v36 = *((_DWORD *)v43 - 2);
*((_DWORD *)v43 - 2) = v36 - 1;
}
if ( v36 <= 0 )
operator delete(v25);
}
m_leaderboardManagerDelegate = a1->m_leaderboardManagerDelegate;
if ( m_leaderboardManagerDelegate )
m_leaderboardManagerDelegate->loadLeaderboardFinished(
m_leaderboardManagerDelegate,
Scores,
(const unsigned __int8 *)v3);
}
else
{
v14 = a1->m_leaderboardManagerDelegate;
if ( v14 )
v14->loadLeaderboardFailed(v14, (const unsigned __int8 *)v3);
}
return _stack_chk_guard;
}