//
// LeaderboardsLayer::selectLeaderboard from 0x1402c3260 to 0x1402c359b (827 bytes)
//
// 8 xrefs:
// > LeaderboardsLayer::init @ 0x1402c256b
// > LeaderboardsLayer::onStat @ 0x1402c31d3
// > LeaderboardsLayer::onTop @ 0x1402c31f5
// > LeaderboardsLayer::onWeek @ 0x1402c3215
// > LeaderboardsLayer::onGlobal @ 0x1402c3235
// > LeaderboardsLayer::onCreators @ 0x1402c3255
// > LeaderboardsLayer::updateUserScoreFinished @ 0x1402c384d
// > ??> @ 0x1406d2a2c
//
// 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=10
void LeaderboardsLayer::selectLeaderboard(LeaderboardsLayer *a1, LeaderboardType a2, LeaderboardStat a3)
{
__int64 v6; // rcx
_BOOL8 v7; // rdx
LeaderboardStat v8; // r14d
__int64 v9; // rax
cocos2d::CCString *v10; // rax
const char *CString; // rax
size_t v12; // r8
void **v13; // rdi
GameLevelManager *v14; // rcx
cocos2d::CCArray *StoredOnlineLevels; // rax
void **v16; // r8
LeaderboardManagerDelegate *v17; // rbx
GameLevelManager *v18; // rcx
void *v19; // rcx
LeaderboardManagerDelegate *v20; // rbx
GameLevelManager *v21; // rcx
void *v22; // [rsp+20h] [rbp-58h]
void *v23; // [rsp+20h] [rbp-58h]
void *v24; // [rsp+20h] [rbp-58h]
void *v25; // [rsp+20h] [rbp-58h]
void *v26; // [rsp+20h] [rbp-58h]
void *v27; // [rsp+20h] [rbp-58h]
void *Block[2]; // [rsp+28h] [rbp-50h] BYREF
__int64 v29; // [rsp+38h] [rbp-40h]
unsigned __int64 v30; // [rsp+40h] [rbp-38h]
if ( a1->m_type != a2 || a1->m_stat != a3 )
{
a1->m_type = a2;
a1->m_stat = a3;
v6 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v22 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v6 = qword_1406C2EC0;
}
*(_DWORD *)(v6 + 704) = a1->m_type;
*(_DWORD *)(v6 + 708) = a1->m_stat;
LeaderboardsLayer::toggleTabButtons(a1);
LOBYTE(v7) = 1;
a1->m_circle->setVisible(a1->m_circle, v7);
a1->m_noInternet->setVisible(a1->m_noInternet, 0);
v8 = Stars;
if ( a1->m_type != Creator )
v8 = a3;
v9 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v23 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v9 = qword_1406C2ED8;
}
if ( *(_BYTE *)(v9 + 648) )
{
if ( !qword_1406C2EC0 )
{
v24 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
}
v10 = cocos2d::CCString::createWithFormat("lb_%i_%i", a1->m_type, v8);
CString = cocos2d::CCString::getCString(v10);
*(_OWORD *)Block = 0;
v29 = 0;
v30 = 0;
v12 = -1;
do
++v12;
while ( CString[v12] );
sub_14003A930(Block, CString, v12);
v13 = Block;
if ( v30 > 0xF )
v13 = (void **)Block[0];
v14 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v25 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v14 = (GameLevelManager *)qword_1406C2EC0;
}
StoredOnlineLevels = GameLevelManager::getStoredOnlineLevels(v14, (const char *)v13);
if ( StoredOnlineLevels )
{
v16 = Block;
if ( v30 > 0xF )
v16 = (void **)Block[0];
a1->loadLeaderboardFinished(&a1->LeaderboardManagerDelegate, StoredOnlineLevels, (const char *)v16);
}
else
{
LeaderboardsLayer::setupLevelBrowser(a1, nullptr);
v17 = &a1->LeaderboardManagerDelegate;
v18 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v26 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v26);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v18 = (GameLevelManager *)qword_1406C2EC0;
}
v18->m_leaderboardManagerDelegate = v17;
GameLevelManager::getLeaderboardScores(v18, a2, v8);
}
if ( v30 > 0xF )
{
v19 = Block[0];
if ( v30 + 1 >= 0x1000 )
{
v19 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v19 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v19);
}
}
else
{
LeaderboardsLayer::setupLevelBrowser(a1, nullptr);
v20 = &a1->LeaderboardManagerDelegate;
v21 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v27 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v27);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v21 = (GameLevelManager *)qword_1406C2EC0;
}
v21->m_leaderboardManagerDelegate = v20;
GameLevelManager::updateUserScore(v21);
}
}
}