//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x140157d70 to 0x140158037 (711 bytes)
//
// 2 xrefs:
// > GameLevelManager::handleIt @ 0x140143386
// > ??> @ 0x1406ca980
//
// 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
//
// Hidden C++ exception states: #wind=2
void __fastcall GameLevelManager::onGetLeaderboardScoresCompleted(GameLevelManager *a1, const void **a2, __int64 *a3)
{
const char *v6; // r15
cocos2d::CCArray *v7; // rbx
int v8; // edi
cocos2d::CCString *v9; // rax
int v10; // r12d
cocos2d::CCString *v11; // rax
int v12; // eax
int v13; // ebx
const void *v14; // rcx
size_t v15; // r8
LeaderboardManagerDelegate *m_leaderboardManagerDelegate; // rcx
const void **v17; // rax
cocos2d::CCArray *Scores; // rdi
cocos2d::ccArray *data; // rcx
__int64 num; // rax
cocos2d::CCObject **arr; // rcx
cocos2d::CCObject **i; // rdx
int v23; // ebx
int v24; // ebx
int (__cdecl *v25)(const void *, const void *); // r9
int v26; // edx
cocos2d::ccArray *v27; // rcx
__int64 v28; // rax
cocos2d::CCObject **v29; // rcx
cocos2d::CCObject **j; // r8
LeaderboardManagerDelegate *v31; // rcx
char v32[32]; // [rsp+28h] [rbp-90h] BYREF
const void **v33; // [rsp+48h] [rbp-70h]
__int64 *v34; // [rsp+50h] [rbp-68h]
__int128 Buf2; // [rsp+58h] [rbp-60h] BYREF
__int64 v36; // [rsp+68h] [rbp-50h]
__int64 v37; // [rsp+70h] [rbp-48h]
v33 = a2;
v34 = a3;
v6 = (const char *)a3;
if ( (unsigned __int64)a3[3] > 0xF )
v6 = (const char *)*a3;
GameLevelManager::removeDLFromActive(a1, v6);
v7 = sub_140140F70(a3, "_");
v8 = 0;
if ( cocos2d::CCArray::count(v7) == 3 )
{
v9 = cocos2d::CCArray::stringAtIndex(v7, 1u);
v10 = cocos2d::CCString::intValue(v9);
}
else
{
v10 = 0;
}
if ( cocos2d::CCArray::count(v7) == 3 )
{
v11 = cocos2d::CCArray::stringAtIndex(v7, 2u);
v12 = cocos2d::CCString::intValue(v11);
}
else
{
v12 = 0;
}
v13 = 0;
if ( v10 != 3 )
v13 = v12;
Buf2 = 0;
v36 = 2;
v37 = 15;
strcpy((char *)&Buf2, "-1");
v14 = a2;
if ( (unsigned __int64)a2[3] > 0xF )
v14 = *a2;
v15 = (size_t)a2[2];
if ( v15 > 2 )
v15 = 2;
if ( !memcmp(v14, &Buf2, v15) && a2[2] == (const void *)2 )
{
m_leaderboardManagerDelegate = a1->m_leaderboardManagerDelegate;
if ( m_leaderboardManagerDelegate )
m_leaderboardManagerDelegate->loadLeaderboardFailed(m_leaderboardManagerDelegate, v6);
}
else
{
v17 = (const void **)sub_14003BDB0((__int64)v32, (__int64)a2);
LOBYTE(v8) = v10 == 3;
Scores = (cocos2d::CCArray *)GameLevelManager::createAndGetScores((__int64)a1, v17, v8);
if ( cocos2d::CCArray::count(Scores) )
{
if ( v13 )
{
if ( Scores )
{
data = Scores->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( i = &arr[num - 1]; arr <= i; ++arr )
{
if ( !*arr )
break;
(*arr)[16].m_nTag = v13;
}
}
}
}
}
if ( cocos2d::CCArray::count(Scores) && v10 == 4 )
{
v23 = v13 - 1;
if ( v23 )
{
v24 = v23 - 1;
if ( v24 )
v25 = v24 == 1
? (int (__cdecl *)(const void *, const void *))sub_140142B00
: (int (__cdecl *)(const void *, const void *))sub_140142A00;
else
v25 = (int (__cdecl *)(const void *, const void *))sub_140142AD0;
}
else
{
v25 = (int (__cdecl *)(const void *, const void *))sub_140142AA0;
}
qsort(Scores->data->arr, Scores->data->num, 8u, v25);
v26 = 1;
if ( Scores )
{
v27 = Scores->data;
v28 = v27->num;
if ( (_DWORD)v28 )
{
v29 = v27->arr;
for ( j = &v29[v28 - 1]; v29 <= j; ++v29 )
{
if ( !*v29 )
break;
(*v29)[7].m_uReference = v26++;
}
}
}
}
Buf2 = 0;
v36 = 1;
v37 = 15;
LOWORD(Buf2) = 32;
GameLevelManager::storeSearchResult(a1, (__int64)Scores, &Buf2, v6);
v31 = a1->m_leaderboardManagerDelegate;
if ( v31 )
v31->loadLeaderboardFinished(v31, Scores, v6);
}
sub_14003A830((__int64)a2);
sub_14003A830((__int64)a3);
}