//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x4d1ed4 to 0x4d20b6 (482 bytes)
//
// 1 xrefs:
// > GameLevelManager::handleIt @ 0x4da82a
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 11:50:48 +0000
//
int __fastcall GameLevelManager::onGetLeaderboardScoresCompleted(GameLevelManager *a1, unsigned __int8 *a2, _DWORD *a3)
{
char *v6; // r6
cocos2d::CCArray *v7; // r4
cocos2d::CCString *v8; // r0
int v9; // r9
cocos2d::CCString *v10; // r0
int v11; // r10
int result; // r0
size_t **Scores; // r5
size_t *v14; // r2
size_t v15; // r3
int *v16; // r2
int *v17; // r3
int v18; // r1
int v19; // t1
int (**v20)(const void *, const void *); // r2
size_t *v21; // r2
int v22; // r3
int *v23; // r2
int v24; // r1
int *v25; // r3
int v26; // r0
int v27; // t1
_BOOL4 v28; // [sp+4h] [bp-18h]
int v29; // [sp+8h] [bp-14h] BYREF
int v30; // [sp+Ch] [bp-10h]
int v31; // [sp+10h] [bp-Ch]
if ( (*(_BYTE *)a3 & 1) != 0 )
v6 = (char *)a3[2];
else
v6 = (char *)a3 + 1;
GameLevelManager::removeDLFromActive(a1, v6);
v7 = sub_4C1A88(a3, "_");
if ( cocos2d::CCArray::count(v7) == 3 )
{
v8 = (cocos2d::CCString *)cocos2d::CCArray::stringAtIndex(v7, 1u);
v9 = cocos2d::CCString::intValue(v8);
}
else
{
v9 = 0;
}
if ( cocos2d::CCArray::count(v7) == 3 )
{
v10 = (cocos2d::CCString *)cocos2d::CCArray::stringAtIndex(v7, 2u);
v11 = cocos2d::CCString::intValue(v10);
}
else
{
v11 = 0;
}
if ( v9 == 3 )
v11 = 0;
v29 = 0;
v30 = 0;
v31 = 0;
std::string::__init(&v29, "-1", 2u);
v28 = sub_4A9CC4(a2, (unsigned __int8 *)&v29);
std::string::~string((int)&v29);
if ( v28 )
{
result = *((_DWORD *)a1 + 214);
if ( result )
return (*(int (__fastcall **)(int, char *))(*(_DWORD *)result + 12))(result, v6);
}
else
{
std::string::basic_string(&v29, (int)a2);
Scores = (size_t **)GameLevelManager::createAndGetScores(a1, (int)&v29, v9 == 3);
std::string::~string((int)&v29);
if ( cocos2d::CCArray::count((cocos2d::CCArray *)Scores) )
{
if ( v11 )
{
if ( Scores )
{
v14 = Scores[13];
v15 = *v14;
if ( *v14 )
{
v16 = (int *)v14[3];
v17 = &v16[v15 - 1];
while ( v16 <= v17 )
{
v19 = *v16++;
v18 = v19;
if ( !v19 )
break;
*(_DWORD *)(v18 + 628) = v11;
}
}
}
}
}
if ( cocos2d::CCArray::count((cocos2d::CCArray *)Scores) && v9 == 4 )
{
if ( v11 == 2 )
{
v20 = (int (**)(const void *, const void *))&scoreCompareDemons;
}
else if ( v11 == 3 )
{
v20 = (int (**)(const void *, const void *))&scoreCompareUserCoins;
}
else
{
v20 = (int (**)(const void *, const void *))(v11 == 1 ? &scoreCompareMoons : &scoreCompare);
}
qsort((void *)Scores[13][3], *Scores[13], 4u, *v20);
v21 = Scores[13];
if ( *v21 )
{
v22 = *v21 + 0x40000000;
v23 = (int *)v21[3];
v24 = 1;
v25 = &v23[v22 - 1];
while ( v23 <= v25 )
{
v27 = *v23++;
v26 = v27;
if ( !v27 )
break;
*(_DWORD *)(v26 + 316) = v24++;
}
}
}
v29 = 0;
v30 = 0;
v31 = 0;
std::string::__init(&v29, " ", 1u);
GameLevelManager::storeSearchResult(a1, (cocos2d::CCObject *)Scores, COERCE_FLOAT(&v29), v6);
std::string::~string((int)&v29);
result = *((_DWORD *)a1 + 214);
if ( result )
return (*(int (__fastcall **)(int, size_t **, char *))(*(_DWORD *)result + 8))(result, Scores, v6);
}
return result;
}