//
// GameLevelManager::onGetLeaderboardScoresCompleted from 0x1402384c0 to 0x14023878b (715 bytes)
//
// 2 xrefs:
// > GameLevelManager::handleIt @ 0x140219b8b
// > ??> @ 0x14091c010
//
// This function is hookable on this platform (idp: pc, 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 11:28:33 +0000
//
// Hidden C++ exception states: #wind=2
void __fastcall GameLevelManager::onGetLeaderboardScoresCompleted(_QWORD *a1, const void **a2, __int64 *a3)
{
_BYTE *v6; // r12
cocos2d::CCArray *v7; // rbx
int v8; // edi
cocos2d::CCString *v9; // rax
int v10; // r15d
cocos2d::CCString *v11; // rax
int v12; // eax
int v13; // ebx
const void *v14; // rcx
size_t v15; // r8
__int64 v16; // rcx
_QWORD *v17; // rax
cocos2d::CCArray *Scores; // rdi
unsigned int *v19; // rcx
__int64 v20; // rax
unsigned __int64 v21; // rcx
unsigned __int64 i; // rdx
int v23; // ebx
int v24; // ebx
int (__cdecl *v25)(const void *, const void *); // r9
int v26; // edx
unsigned int *v27; // rcx
__int64 v28; // rax
unsigned __int64 v29; // rcx
unsigned __int64 j; // r8
__int64 v31; // rcx
__int128 Buf2; // [rsp+20h] [rbp-98h] BYREF
__int64 v33; // [rsp+30h] [rbp-88h]
__int64 v34; // [rsp+38h] [rbp-80h]
_BYTE v35[32]; // [rsp+48h] [rbp-70h] BYREF
const void **v36; // [rsp+68h] [rbp-50h]
__int64 *v37; // [rsp+70h] [rbp-48h]
v36 = a2;
v37 = a3;
v6 = a3;
if ( (unsigned __int64)a3[3] > 0xF )
v6 = (_BYTE *)*a3;
GameLevelManager::removeDLFromActive((__int64)a1, v6);
v7 = sub_1400D2840(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;
v33 = 2;
v34 = 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 )
{
v16 = a1[178];
if ( v16 )
(*(void (__fastcall **)(__int64, _BYTE *))(*(_QWORD *)v16 + 24LL))(v16, v6);
}
else
{
v17 = (_QWORD *)sub_14003F4F0((__int64)v35, (__int64)a2);
LOBYTE(v8) = v10 == 3;
Scores = (cocos2d::CCArray *)GameLevelManager::createAndGetScores(a1, v17, v8);
if ( cocos2d::CCArray::count(Scores) )
{
if ( v13 )
{
if ( Scores )
{
v19 = *((unsigned int **)Scores + 7);
v20 = *v19;
if ( (_DWORD)v20 )
{
v21 = *((_QWORD *)v19 + 2);
for ( i = v21 + 8 * (v20 - 1); v21 <= i; v21 += 8LL )
{
if ( !*(_QWORD *)v21 )
break;
*(_DWORD *)(*(_QWORD *)v21 + 944LL) = 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 *))scoreCompareUserCoins
: (int (__cdecl *)(const void *, const void *))scoreCompare;
else
v25 = (int (__cdecl *)(const void *, const void *))scoreCompareDemons;
}
else
{
v25 = (int (__cdecl *)(const void *, const void *))scoreCompareMoons;
}
qsort(*(void **)(*((_QWORD *)Scores + 7) + 16LL), **((unsigned int **)Scores + 7), 8u, v25);
v26 = 1;
if ( Scores )
{
v27 = *((unsigned int **)Scores + 7);
v28 = *v27;
if ( (_DWORD)v28 )
{
v29 = *((_QWORD *)v27 + 2);
for ( j = v29 + 8 * (v28 - 1); v29 <= j; v29 += 8LL )
{
if ( !*(_QWORD *)v29 )
break;
*(_DWORD *)(*(_QWORD *)v29 + 412LL) = v26++;
}
}
}
}
Buf2 = 0;
v33 = 1;
v34 = 15;
LOWORD(Buf2) = 32;
GameLevelManager::storeSearchResult((__int64)a1, (__int64)Scores, &Buf2, v6);
v31 = a1[178];
if ( v31 )
(*(void (__fastcall **)(__int64, cocos2d::CCArray *, _BYTE *))(*(_QWORD *)v31 + 16LL))(v31, Scores, v6);
}
sub_14003D310((__int64)a2);
sub_14003D310((__int64)a3);
}