//
// GameLevelManager::getMainLevel from 0x6f1654 to 0x6f1a84 (1072 bytes)
//
// 23 xrefs:
// > GameManager::verifyStarUnlocks @ 0x5e9f40
// > GameManager::verifySyncedCoins @ 0x5e9fb4
// > GameManager::verifySyncedCoins @ 0x5ea074
// > GameManager::verifyCoinUnlocks @ 0x5f511c
// > GameManager::verifyCoinUnlocks @ 0x5f51dc
// > GameManager::recountUserStats @ 0x5f9cd0
// > GameManager::dataLoaded @ 0x5fb1fc
// > GameManager::dataLoaded @ 0x5fb43c
// > GameManager::dataLoaded @ 0x5fb460
// > GameManager::dataLoaded @ 0x5fb484
// > LevelSelectLayer::init @ 0x79dfbc
// > GameStatsManager::getTotalCollectedCurrency @ 0x7a4828
// > GameStatsManager::getTotalCollectedCurrency @ 0x7a4904
// > GameStatsManager::getTotalCollectedCurrency @ 0x7a4978
// > GameStatsManager::awardOldSpecialStats @ 0x7baf50
// > SecretLayer2::onSecretLevel @ 0x93afd8
// > SecretLayer2::init @ 0x942c08
// > GJWorldNode::unlockActiveItem @ 0x95f030
// > GJWorldNode::init @ 0x960494
// > GJWorldNode::onLevel @ 0x962b04
// > LevelAreaInnerLayer::playStep1 @ 0xa2d784
// > LevelAreaInnerLayer::init @ 0xa3082c
// > ??> @ 0x607c8
//
// 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
//
GJGameLevel *GameLevelManager::getMainLevel(GameLevelManager *a1, int a2, bool a3)
{
cocos2d::CCDictionary *m_mainLevels; // x19
char *LevelKey; // x0
GJGameLevel *v8; // x19
char *v9; // x0
GJGameLevel *Level; // x20
char *v11; // x0
int v12; // w25
float v13; // s0
char *v14; // x0
int random; // w0
int seed; // w25
int v17; // w25
float v18; // s0
char *v19; // x23
float v20; // s0
cocos2d::CCDictionary *v22; // x20
char *v23; // x0
char *v24; // x20
unsigned int *v25; // x2
int v26; // w0
unsigned int *v27; // x1
int v28; // w2
unsigned int *v29; // x2
int v30; // w0
unsigned int *v31; // x1
int v32; // w2
unsigned int *v33; // x1
int v34; // w2
std::string v35; // [xsp+70h] [xbp+70h] BYREF
m_mainLevels = a1->m_mainLevels;
LevelKey = (char *)GameLevelManager::getLevelKey(a1, a2);
sub_D153B8((int)&v35, LevelKey);
v8 = (GJGameLevel *)cocos2d::CCDictionary::objectForKey(m_mainLevels, &v35);
v9 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v27 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v28 = __ldaxr(v27);
while ( __stlxr(v28 - 1, v27) );
}
else
{
v28 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v28 - 1;
}
if ( v28 <= 0 )
operator delete(v9);
}
Level = LevelTools::getLevel(a2, a3);
if ( v8 )
{
sub_D18D28(&v35, &Level->m_levelString);
sub_D18EA8(&v8->m_levelString, &v35);
v11 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v31 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v32 = __ldaxr(v31);
while ( __stlxr(v32 - 1, v31) );
}
else
{
v32 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v32 - 1;
}
if ( v32 <= 0 )
operator delete(v11);
}
v12 = Level->m_stars.random - Level->m_stars.seed;
v8->m_stars.value = v12;
v13 = (float)((float)rand() * 4.6566e-10) * 1000.0;
v8->m_stars.seed = (int)v13;
v8->m_stars.random = v12 + (int)v13;
v8->m_coins = Level->m_coins;
v8->m_requiredCoins = Level->m_requiredCoins;
sub_D18D28(&v35, &Level->m_levelName);
sub_D18EA8(&v8->m_levelName, &v35);
v14 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v33 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v34 = __ldaxr(v33);
while ( __stlxr(v34 - 1, v33) );
}
else
{
v34 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v34 - 1;
}
if ( v34 <= 0 )
operator delete(v14);
}
v8->m_audioTrack = Level->m_audioTrack;
random = Level->m_demon.random;
seed = Level->m_demon.seed;
v8->m_twoPlayerMode = Level->m_twoPlayerMode;
v17 = random - seed;
v8->m_demon.value = v17;
v18 = (float)((float)rand() * 4.6566e-10) * 1000.0;
v8->m_demon.seed = (int)v18;
v8->m_demon.random = v17 + (int)v18;
v8->m_difficulty = Level->m_difficulty;
sub_D18D28(&v35, &Level->m_capacityString);
sub_D18EA8(&v8->m_capacityString, &v35);
v19 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v29 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v30 = __ldaxr(v29);
while ( __stlxr(v30 - 1, v29) );
}
else
{
v30 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v30 - 1;
}
if ( v30 <= 0 )
operator delete(v19);
}
v8->m_levelID.value = a2;
v20 = (float)((float)rand() * 4.6566e-10) * 1000.0;
v8->m_levelID.seed = (int)v20;
v8->m_levelID.random = a2 + (int)v20;
v8->m_timestamp = Level->m_timestamp;
v8->m_levelLength = Level->m_levelLength;
}
else
{
v8 = LevelTools::getLevel(a2, 0);
v22 = a1->m_mainLevels;
v23 = (char *)GameLevelManager::getLevelKey(a1, a2);
sub_D153B8((int)&v35, v23);
cocos2d::CCDictionary::setObject((int)v22, v8);
v24 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v25 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v26 - 1;
}
if ( v26 <= 0 )
operator delete(v24);
}
}
return v8;
}