//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x1005207a0 to 0x100520a69 (713 bytes)
//
// 1 xrefs:
// > GameLevelManager::handleIt @ 0x10051cd4a
//
// 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,
unsigned __int8 *a2,
__int64 a3,
double a4)
{
const char *v5; // r14
cocos2d::CCArray *v6; // rbx
int v7; // eax
int v8; // ecx
cocos2d::CCString *v9; // rax
bool v10; // zf
int v11; // eax
cocos2d::CCString *v12; // rax
int v13; // r12d
int v14; // r13d
char v15; // bl
const void *v16; // rdi
unsigned __int64 v17; // rax
unsigned __int64 v18; // rcx
const void *v19; // r14
size_t v20; // rdx
__int64 result; // rax
LeaderboardManagerDelegate *v22; // rdi
__int64 Scores; // r13
unsigned int *v24; // rax
__int64 v25; // rcx
unsigned __int64 v26; // rax
unsigned __int64 v27; // rcx
int v28; // eax
const char *v29; // rbx
int (__cdecl *v30)(const void *, const void *); // rcx
unsigned int *v31; // rax
__int64 v32; // rcx
unsigned __int64 v33; // rax
unsigned __int64 v34; // rcx
int v35; // edx
GameLevelManager *v36; // r14
LeaderboardManagerDelegate *m_leaderboardManagerDelegate; // rdi
_WORD __s2[11]; // [rsp+1h] [rbp-9Fh] BYREF
__int16 v39; // [rsp+18h] [rbp-88h] BYREF
char v40; // [rsp+1Ah] [rbp-86h]
unsigned __int8 *v41; // [rsp+30h] [rbp-70h]
unsigned __int64 v42; // [rsp+38h] [rbp-68h]
__int128 v43; // [rsp+40h] [rbp-60h] BYREF
void *__p; // [rsp+50h] [rbp-50h]
const char *v45; // [rsp+58h] [rbp-48h]
int v46; // [rsp+64h] [rbp-3Ch]
GameLevelManager *v47; // [rsp+68h] [rbp-38h]
int v48; // [rsp+74h] [rbp-2Ch]
if ( (*(_BYTE *)a3 & 1) != 0 )
v5 = *(const char **)(a3 + 16);
else
v5 = (const char *)(a3 + 1);
v47 = a1;
GameLevelManager::removeDLFromActive(a1, v5);
v6 = (cocos2d::CCArray *)sub_10052DD30(a3, "_");
v7 = sub_100720070(v6);
v8 = 0;
if ( v7 == 3 )
{
v9 = cocos2d::CCArray::stringAtIndex(v6, 1u);
v8 = cocos2d::CCString::intValue(v9);
}
v48 = v8;
v45 = v5;
v10 = (unsigned int)sub_100720070(v6) == 3;
v11 = 0;
if ( v10 )
{
v12 = cocos2d::CCArray::stringAtIndex(v6, 2u);
v11 = cocos2d::CCString::intValue(v12);
}
v13 = 0;
v14 = v48;
v46 = v11;
if ( v48 != 3 )
v13 = v11;
strcpy((char *)__s2, "-1");
v15 = *a2;
v16 = a2 + 1;
v17 = *a2 >> 1;
v18 = *((_QWORD *)a2 + 1);
v41 = a2;
v19 = *((const void **)a2 + 2);
if ( (v15 & 1) != 0 )
v16 = *((const void **)a2 + 2);
v42 = v18;
if ( (v15 & 1) != 0 )
v17 = v18;
v20 = 2;
if ( v17 < 2 )
v20 = v17;
if ( (v17 != 2) | (memcmp(v16, __s2, v20) != 0) )
{
if ( (v15 & 1) != 0 )
{
sub_100006B70(&v43, v19, v42, a4);
}
else
{
__p = *((void **)v41 + 2);
v43 = *(_OWORD *)v41;
}
Scores = GameLevelManager::createAndGetScores(v47, &v43, v14 == 3);
if ( (v43 & 1) != 0 )
operator delete(__p);
if ( (unsigned int)sub_100720070(Scores) != 0 && v13 != 0 && Scores != 0 )
{
v24 = *(unsigned int **)(Scores + 56);
v25 = *v24;
if ( *v24 )
{
v26 = *((_QWORD *)v24 + 2);
v27 = v26 + 8 * v25 - 8;
do
{
if ( !*(_QWORD *)v26 )
break;
*(_DWORD *)(*(_QWORD *)v26 + 808LL) = v13;
v26 += 8LL;
}
while ( v26 <= v27 );
}
}
v28 = sub_100720070(Scores);
v29 = v45;
if ( v28 != 0 && v48 == 4 )
{
v30 = (unsigned int)(v46 - 1) > 2
? (int (__cdecl *)(const void *, const void *))sub_10051A730
: (int (__cdecl *)(const void *, const void *))off_100962CE8[v46 - 1];
qsort(*(void **)(*(_QWORD *)(Scores + 56) + 16LL), **(unsigned int **)(Scores + 56), 8u, v30);
v31 = *(unsigned int **)(Scores + 56);
v32 = *v31;
if ( *v31 )
{
v33 = *((_QWORD *)v31 + 2);
v34 = v33 + 8 * v32 - 8;
v35 = 1;
do
{
if ( !*(_QWORD *)v33 )
break;
*(_DWORD *)(*(_QWORD *)v33 + 396LL) = v35++;
v33 += 8LL;
}
while ( v33 <= v34 );
}
}
v39 = 8194;
v40 = 0;
v36 = v47;
result = GameLevelManager::storeSearchResult(v47, Scores, &v39, v29);
m_leaderboardManagerDelegate = v36->m_leaderboardManagerDelegate;
if ( m_leaderboardManagerDelegate )
return ((__int64 (__fastcall *)(LeaderboardManagerDelegate *, __int64, const char *))m_leaderboardManagerDelegate->loadLeaderboardFinished)(
m_leaderboardManagerDelegate,
Scores,
v29);
}
else
{
result = (__int64)v47;
v22 = v47->m_leaderboardManagerDelegate;
if ( v22 )
return ((__int64 (__fastcall *)(LeaderboardManagerDelegate *, const char *))v22->loadLeaderboardFailed)(v22, v45);
}
return result;
}