//
// GameLevelManager::getLevelLeaderboard from 0x3d0d2c to 0x3d136c (1600 bytes)
//
// 6 xrefs:
// > PlayLayer::levelComplete @ 0x313874
// > PlayLayer::levelComplete @ 0x31388e
// > LevelInfoLayer::init @ 0x3b558e
// > LevelInfoLayer::init @ 0x3b55ac
// > LevelLeaderboard::onUpdate @ 0x4e51c2
// > LevelLeaderboard::loadScores @ 0x4e5306
//
// 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
//
void GameLevelManager::getLevelLeaderboard(
GameLevelManager *a1,
GJGameLevel *a2,
LevelLeaderboardType a3,
LevelLeaderboardMode a4)
{
char *LevelLeaderboardKey; // r0
GJAccountManager *v7; // r0
LeaderboardManagerDelegate *m_leaderboardManagerDelegate; // r0
int v9; // r9
int m_platformerSeed; // r2
const char *v11; // r5
float v12; // s16
unsigned int v13; // r0
int v14; // s16
int v15; // r10
int v16; // r6
GameStatsManager *v17; // r7
const char *v18; // r0
_BOOL4 hasPendingUserCoin; // r0
GameStatsManager *v20; // r7
const char *CoinKey; // r0
int v22; // r8
cocos2d::CCString *v23; // r0
const char *CString; // r0
int v25; // r6
cocos2d::CCString *v26; // r0
char *v27; // r0
GJAccountManager *v28; // r0
const char *v29; // r8
int v30; // r7
int v31; // r6
int v32; // r9
cocos2d::CCString *v33; // r0
char *v34; // r0
cocos2d::CCString *v35; // r0
char *v36; // r0
cocos2d::CCString *v37; // r0
char *v38; // r0
const void *v39; // r0
unsigned __int8 *v40; // r3
char *v41; // r2
char *v42; // r1
int v43; // [sp+68h] [bp-ECh]
int v44; // [sp+68h] [bp-ECh]
int v45; // [sp+6Ch] [bp-E8h]
int v46; // [sp+6Ch] [bp-E8h]
int v47; // [sp+70h] [bp-E4h]
int v48; // [sp+74h] [bp-E0h]
int m_bestTime; // [sp+78h] [bp-DCh]
int m_chk; // [sp+7Ch] [bp-D8h]
_BOOL4 isPlatformer; // [sp+80h] [bp-D4h]
int v52; // [sp+84h] [bp-D0h]
int m_bestPoints; // [sp+8Ch] [bp-C8h]
int v55; // [sp+90h] [bp-C4h]
int v57; // [sp+9Ch] [bp-B8h]
int v58; // [sp+A0h] [bp-B4h]
int v59; // [sp+A4h] [bp-B0h]
const char *v60; // [sp+A8h] [bp-ACh]
char *v61; // [sp+ACh] [bp-A8h]
int v62; // [sp+B0h] [bp-A4h]
int v63; // [sp+B4h] [bp-A0h]
int v64; // [sp+B8h] [bp-9Ch]
char *v65; // [sp+C4h] [bp-90h] BYREF
char v66; // [sp+C8h] [bp-8Ch] BYREF
int v67; // [sp+CCh] [bp-88h] BYREF
int v68; // [sp+D0h] [bp-84h] BYREF
int v69; // [sp+D4h] [bp-80h] BYREF
std::string v70; // [sp+D8h] [bp-7Ch] BYREF
_BYTE v71[4]; // [sp+DCh] [bp-78h] BYREF
int v72; // [sp+E0h] [bp-74h] BYREF
int v73; // [sp+E4h] [bp-70h] BYREF
char *v74; // [sp+E8h] [bp-6Ch] BYREF
int v75; // [sp+ECh] [bp-68h] BYREF
cocos2d::ZipUtils v76; // [sp+F0h] [bp-64h] BYREF
std::string v77; // [sp+F4h] [bp-60h] BYREF
_BYTE v78[4]; // [sp+F8h] [bp-5Ch] BYREF
_BYTE v79[4]; // [sp+FCh] [bp-58h] BYREF
char *v80; // [sp+100h] [bp-54h] BYREF
const char *v81; // [sp+104h] [bp-50h] BYREF
char *v82; // [sp+108h] [bp-4Ch] BYREF
unsigned __int8 v83[20]; // [sp+10Ch] [bp-48h] BYREF
unsigned __int8 v84[44]; // [sp+120h] [bp-34h] BYREF
if ( a2 )
{
LevelLeaderboardKey = (char *)GameLevelManager::getLevelLeaderboardKey(
a1,
a2->m_levelID.random - a2->m_levelID.seed,
a3,
a4);
sub_776584((int)&v65, LevelLeaderboardKey);
v7 = GJAccountManager::sharedState();
if ( v7->m_accountID - v7->m_unkInt1 > 0 )
{
if ( !GameLevelManager::isDLActive(a1, v65) )
{
GameLevelManager::addDLToActive(a1, v65);
if ( a3 == 4 )
cocos2d::CCDictionary::setObject((int)a1->m_localLeaderboardLevels, a2);
GameLevelManager::getBasePostString((GameLevelManager *)&v66);
sub_776584((int)&v67, (char *)&unk_939830);
sub_776584((int)&v68, (char *)&unk_939830);
m_chk = a2->m_chk;
isPlatformer = GJGameLevel::isPlatformer(a2);
m_bestTime = a2->m_bestTime;
if ( m_bestTime <= 0 )
{
v11 = nullptr;
v55 = 0;
v9 = 0;
v48 = 0;
m_bestPoints = 0;
v47 = 0;
v45 = 0;
v43 = 0;
m_bestTime = 0;
}
else
{
v43 = a2->m_ticksTime + 46533;
v45 = a2->m_clicksTime + 7684;
v47 = a2->m_coinsTime + 6433;
if ( a4 == Time )
sub_775D40(&v67, &a2->m_inputsTime);
m_bestPoints = a2->m_bestPoints;
v48 = a2->m_ticksPoints + 25645;
v55 = a2->m_clicksPoints + 3453;
v9 = a2->m_coinsPoints + 6323;
if ( a4 == Points )
sub_775D40(&v68, &a2->m_inputsPoints);
m_platformerSeed = m_chk;
if ( isPlatformer )
{
m_platformerSeed = a2->m_platformerSeed;
v11 = nullptr;
}
else
{
v11 = (const char *)a2->m_platformerSeed;
}
m_chk = m_platformerSeed;
}
v12 = 0.0;
v52 = a2->m_attempts.random - a2->m_attempts.seed + 8354;
v57 = a2->m_clicks.random - a2->m_clicks.seed + 3991;
v58 = a2->m_attemptTime.random - a2->m_attemptTime.seed + 4085;
v59 = a2->m_chk + 1482;
v13 = rand();
if ( a2->m_isChkValid )
v12 = 2000.0;
v14 = (int)(float)(v12 + (float)(vcvts_n_f32_s32(v13, 0x1Fu) * 1999.0));
sub_775C20(&v70);
sub_776584((int)v71, "41274");
cocos2d::ZipUtils::base64EncodeEnc((cocos2d::ZipUtils *)&v69, &v70, (std::string)v71);
sub_774008(v71);
sub_774008(&v70);
if ( a2->m_coins > 0 )
{
v16 = 1;
v15 = 0;
while ( v16 - 1 < a2->m_coins )
{
if ( a2->m_coinsVerified.random == a2->m_coinsVerified.seed )
{
v20 = GameStatsManager::sharedState();
CoinKey = GJGameLevel::getCoinKey(a2, v16);
hasPendingUserCoin = GameStatsManager::hasPendingUserCoin(v20, CoinKey);
}
else
{
v17 = GameStatsManager::sharedState();
v18 = GJGameLevel::getCoinKey(a2, v16);
hasPendingUserCoin = GameStatsManager::hasUserCoin(v17, v18);
}
if ( hasPendingUserCoin )
++v15;
++v16;
}
}
else
{
v15 = 0;
}
gen_random((int)&v72, 10);
v61 = (char *)(a2->m_levelID.random - a2->m_levelID.seed);
v22 = a2->m_newNormalPercent2.random - a2->m_newNormalPercent2.seed;
v23 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%c%s%s%c%c%s",
(const char *)&dword_54 + 3,
"mfd",
"2893",
103,
98,
&aO1i2r3e45s7t89[10]);
CString = cocos2d::CCString::getCString(v23);
v62 = v69;
v60 = CString;
v63 = v72;
v64 = a2->m_attempts.random - a2->m_attempts.seed;
v25 = a2->m_dailyID.random - a2->m_dailyID.seed;
gen_random((int)&v73, 5);
v26 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"&levelID=%i&percent=%i&time=%i&points=%i&plat=%i&secret=%s&typ"
"e=%i&mode=%i&s1=%i&s2=%i&s3=%i&s4=%i&s5=%i&s6=%s&s7=%s&s8=%i&s"
"9=%i&s10=%i&s11=%i&s12=%i&s13=%i&s14=%i&s15=%i&s16=%s&s17=%s&s"
"18=%i&s19=%i&s20=%i",
v61,
v22,
m_bestTime,
m_bestPoints,
isPlatformer,
v60,
a3,
a4,
v52,
v57,
v58,
v59,
v14,
v62,
v63,
v64,
v15 + 5819,
v25,
v43,
v48,
v73,
v45,
v55,
v67,
v68,
v47,
v9,
a2->m_levelVersion);
v27 = (char *)cocos2d::CCString::getCString(v26);
sub_774544((int)&v66, v27);
sub_774008(&v73);
v28 = GJAccountManager::sharedState();
v29 = (const char *)(v28->m_accountID - v28->m_unkInt1);
v30 = a2->m_levelID.random - a2->m_levelID.seed;
v31 = a2->m_newNormalPercent2.random - a2->m_newNormalPercent2.seed;
v44 = a2->m_attemptTime.random - a2->m_attemptTime.seed;
v46 = a2->m_clicks.random - a2->m_clicks.seed;
v32 = a2->m_attempts.random - a2->m_attempts.seed;
sub_775C20(&v75);
v33 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i%i%i%i%i%i%i%s%i%i%i",
v29,
v30,
v31,
v44,
v46,
v32,
m_chk,
v75,
a2->m_isChkValid,
v15,
a2->m_dailyID.random - a2->m_dailyID.seed);
v34 = (char *)cocos2d::CCString::getCString(v33);
sub_776584((int)&v74, v34);
sub_774008(&v75);
if ( (int)v11 > 0 )
{
v37 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", v11);
v38 = (char *)cocos2d::CCString::getCString(v37);
sub_774544((int)&v74, v38);
}
v35 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%c%s%s%c%c%s",
(const char *)&dword_78 + 1,
"Pg6",
"pUrt",
87,
110,
"0J");
v36 = (char *)cocos2d::CCString::getCString(v35);
sub_774544((int)&v74, v36);
sub_77441C(&v74, &v72);
v39 = (const void *)strlen(v74);
rtsha1::calc((rtsha1 *)v74, v39, (int)v83, v40);
rtsha1::toHexString((rtsha1 *)v83, v84, v41);
sub_776584((int)&v77, (char *)v84);
sub_776584((int)v78, "39673");
cocos2d::ZipUtils::base64EncodeEnc(&v76, &v77, (std::string)v78);
sub_774008(v78);
sub_774008(&v77);
sub_774544((int)&v66, "&chk=");
sub_77441C(&v66, &v76);
if ( isPlatformer )
v42 = "https://www.boomlings.com/database/getGJLevelScoresPlat.php";
else
v42 = "https://www.boomlings.com/database/getGJLevelScores211.php";
sub_776584((int)v79, v42);
sub_775C20(&v80);
sub_775C20(&v81);
sub_775C20(&v82);
GameLevelManager::ProcessHttpRequest(a1, &v80, &v81, &v82, 51);
sub_774008(&v82);
sub_774008(&v81);
sub_774008(&v80);
sub_774008(v79);
sub_774008(&v76);
sub_774008(&v74);
sub_774008(&v72);
sub_774008(&v69);
sub_774008(&v68);
sub_774008(&v67);
sub_774008(&v66);
}
}
else
{
m_leaderboardManagerDelegate = a1->m_leaderboardManagerDelegate;
if ( m_leaderboardManagerDelegate )
m_leaderboardManagerDelegate->loadLeaderboardFailed(m_leaderboardManagerDelegate, (const unsigned __int8 *)v65);
}
sub_774008(&v65);
}
}