//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x84960c to 0x8499c8 (956 bytes)
//
// 2 xrefs:
// > GameLevelManager::handleIt @ 0x85c3fc
// > ??> @ 0xa7f08
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:55:22 +0000
//
__int64 __fastcall GameLevelManager::onGetLeaderboardScoresCompleted(GameLevelManager *this, __int64 a2, char *a3)
{
char *v5; // x19
cocos2d::CCArray *v6; // x21
int v7; // w20
int v8; // w25
_BOOL4 v9; // w26
__int64 v10; // x0
cocos2d::CCString *v12; // x0
char v13; // w0
__int64 v14; // x0
__int64 v15; // x1
cocos2d::CCArray *Scores; // x24
int v17; // w0
unsigned int *v18; // x0
unsigned int v19; // w1
__int64 v20; // x0
unsigned int *v21; // x1
unsigned int v22; // w0
__int64 *v23; // x1
__int64 *v24; // x3
__int64 v25; // x2
int j; // w0
__int64 *v27; // x0
__int64 *i; // x2
__int64 v29; // x1
cocos2d::CCString *v30; // x0
__int64 v32; // [xsp+60h] [xbp+60h] BYREF
__int64 v33; // [xsp+68h] [xbp+68h]
void *v34; // [xsp+70h] [xbp+70h]
v5 = a3 + 1;
if ( (*a3 & 1) != 0 )
v5 = *((char **)a3 + 2);
GameLevelManager::removeDLFromActive(this, v5);
v6 = sub_80CFCC((unsigned __int8 *)a3, &byte_11528B0);
if ( (unsigned int)cocos2d::CCArray::count(v6) == 3 )
{
v7 = 0;
v12 = (cocos2d::CCString *)cocos2d::CCArray::stringAtIndex(v6, 1u);
v8 = cocos2d::CCString::intValue(v12);
if ( (unsigned int)cocos2d::CCArray::count(v6) != 3 )
goto LABEL_13;
}
else
{
if ( (unsigned int)cocos2d::CCArray::count(v6) != 3 )
{
v7 = 0;
v8 = 0;
goto LABEL_6;
}
v8 = 0;
}
v30 = (cocos2d::CCString *)cocos2d::CCArray::stringAtIndex(v6, 2u);
v7 = cocos2d::CCString::intValue(v30);
LABEL_13:
if ( v8 == 3 )
v7 = 0;
LABEL_6:
v32 = 0;
v33 = 0;
v34 = nullptr;
std::string::__init(&v32, &word_117CE08, 2u);
v9 = sub_7FEA60(a2, (__int64)&v32);
if ( (v32 & 1) != 0 )
operator delete(v34);
if ( v9 )
{
v10 = *((_QWORD *)this + 162);
if ( v10 )
(*(void (__fastcall **)(__int64, char *))(*(_QWORD *)v10 + 24LL))(v10, v5);
}
else
{
v13 = *(_BYTE *)a2;
v32 = 0;
v33 = 0;
v34 = nullptr;
if ( (v13 & 1) != 0 )
{
std::string::__init(&v32, *(void **)(a2 + 16), *(_QWORD *)(a2 + 8));
}
else
{
v14 = *(_QWORD *)a2;
v15 = *(_QWORD *)(a2 + 8);
v34 = *(void **)(a2 + 16);
v32 = v14;
v33 = v15;
}
Scores = GameLevelManager::createAndGetScores(this, (char *)&v32, v8 == 3);
if ( (v32 & 1) != 0 )
operator delete(v34);
v17 = cocos2d::CCArray::count(Scores);
if ( Scores != nullptr && v7 != 0 )
{
if ( v17 )
{
v18 = *((unsigned int **)Scores + 7);
v19 = *v18;
if ( *v18 )
{
v27 = *((__int64 **)v18 + 2);
for ( i = &v27[v19 - 1]; i >= v27; *(_DWORD *)(v29 + 840) = v7 )
{
v29 = *v27;
if ( !*v27 )
break;
++v27;
}
}
}
}
if ( (unsigned int)cocos2d::CCArray::count(Scores) && v8 == 4 )
{
switch ( v7 )
{
case 2:
qsort(
*(void **)(*((_QWORD *)Scores + 7) + 16LL),
**((unsigned int **)Scores + 7),
8u,
(int (*)(const void *, const void *))scoreCompareDemons);
break;
case 3:
qsort(
*(void **)(*((_QWORD *)Scores + 7) + 16LL),
**((unsigned int **)Scores + 7),
8u,
(int (*)(const void *, const void *))scoreCompareUserCoins);
break;
case 1:
qsort(
*(void **)(*((_QWORD *)Scores + 7) + 16LL),
**((unsigned int **)Scores + 7),
8u,
(int (*)(const void *, const void *))scoreCompareMoons);
break;
default:
qsort(
*(void **)(*((_QWORD *)Scores + 7) + 16LL),
**((unsigned int **)Scores + 7),
8u,
(int (*)(const void *, const void *))scoreCompare);
break;
}
v21 = *((unsigned int **)Scores + 7);
v22 = *v21;
if ( *v21 )
{
v23 = *((__int64 **)v21 + 2);
v24 = &v23[v22 - 1];
if ( v23 <= v24 )
{
v25 = *v23;
for ( j = 1; *v23; v25 = *v23 )
{
++v23;
*(_DWORD *)(v25 + 396) = j++;
if ( v24 < v23 )
break;
}
}
}
}
v32 = 0;
v33 = 0;
v34 = nullptr;
std::string::__init(&v32, &byte_11E1A70, 1u);
GameLevelManager::storeSearchResult(this, Scores, (__int64)&v32, v5);
if ( (v32 & 1) != 0 )
operator delete(v34);
v20 = *((_QWORD *)this + 162);
if ( v20 )
(*(void (__fastcall **)(__int64, cocos2d::CCArray *, char *))(*(_QWORD *)v20 + 16LL))(v20, Scores, v5);
}
return _stack_chk_guard;
}