//
// LevelLeaderboard::loadScores from 0x140302310 to 0x1403025d1 (705 bytes)
//
// 3 xrefs:
// > LevelLeaderboard::init @ 0x140301c39
// > LevelLeaderboard::updateUserScoreFinished @ 0x1403025e7
// > ??> @ 0x1406d43ac
//
// 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=6
void LevelLeaderboard::loadScores(LevelLeaderboard *a1)
{
int v2; // ebx
cocos2d::CCString *v3; // rax
const char *CString; // rax
size_t v5; // r8
void **v6; // rsi
LeaderboardManagerDelegate_vtbl *v7; // rdi
cocos2d::CCArray *LocalScores; // rax
void **v9; // rbx
GameLevelManager *v10; // rcx
cocos2d::CCArray *StoredOnlineLevels; // rax
void **v12; // r8
GameLevelManager *v13; // rcx
_BOOL8 v14; // rdx
GameLevelManager *v15; // rcx
void *v16; // rcx
void *v17; // [rsp+20h] [rbp-38h]
void *v18; // [rsp+20h] [rbp-38h]
void *v19; // [rsp+20h] [rbp-38h]
void *v20; // [rsp+20h] [rbp-38h]
void *Block[2]; // [rsp+28h] [rbp-30h] BYREF
__int64 v22; // [rsp+38h] [rbp-20h]
unsigned __int64 v23; // [rsp+40h] [rbp-18h]
v2 = a1->m_level->m_levelID.random - a1->m_level->m_levelID.seed;
if ( !qword_1406C2EC0 )
{
v17 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v17);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
}
v3 = cocos2d::CCString::createWithFormat("ll_%i_%i_%i", v2, a1->m_type, a1->m_mode);
CString = cocos2d::CCString::getCString(v3);
*(_OWORD *)Block = 0;
v22 = 0;
v23 = 0;
v5 = -1;
do
++v5;
while ( CString[v5] );
sub_14003A930(Block, CString, v5);
if ( a1->m_type == Local )
{
v6 = Block;
if ( v23 > 0xF )
v6 = (void **)Block[0];
v7 = a1->LeaderboardManagerDelegate::__vftable;
LocalScores = LevelLeaderboard::getLocalScores(a1);
v7->loadLeaderboardFinished(&a1->LeaderboardManagerDelegate, LocalScores, (const char *)v6);
}
else
{
v9 = Block;
if ( v23 > 0xF )
v9 = (void **)Block[0];
v10 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v18 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v18);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v10 = (GameLevelManager *)qword_1406C2EC0;
}
StoredOnlineLevels = GameLevelManager::getStoredOnlineLevels(v10, (const char *)v9);
if ( StoredOnlineLevels )
{
v12 = Block;
if ( v23 > 0xF )
v12 = (void **)Block[0];
a1->loadLeaderboardFinished(&a1->LeaderboardManagerDelegate, StoredOnlineLevels, (const char *)v12);
}
else
{
v13 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v19 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v19);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v13 = (GameLevelManager *)qword_1406C2EC0;
}
GameLevelManager::makeTimeStamp(v13, "upd_ll");
LOBYTE(v14) = 1;
a1->m_circle->setVisible(a1->m_circle, v14);
a1->m_noInternet->setVisible(a1->m_noInternet, 0);
LevelLeaderboard::setupLeaderboard(a1, nullptr);
v15 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v20 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v15 = (GameLevelManager *)qword_1406C2EC0;
}
v15->m_leaderboardManagerDelegate = &a1->LeaderboardManagerDelegate;
GameLevelManager::getLevelLeaderboard(v15, a1->m_level, a1->m_type, a1->m_mode);
}
}
if ( v23 > 0xF )
{
v16 = Block[0];
if ( v23 + 1 >= 0x1000 )
{
v16 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v16 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v16);
}
}