//
// GameLevelManager::getMainLevel from 0x140144450 to 0x1401447fb (939 bytes)
//
// 17 xrefs:
// > GameManager::verifyCoinUnlocks @ 0x14017e60e
// > GameManager::verifyCoinUnlocks @ 0x14017e6f7
// > GameManager::recountUserStats @ 0x140184eb4
// > GameManager::dataLoaded @ 0x140187c54
// > GameManager::dataLoaded @ 0x140187d45
// > GameManager::dataLoaded @ 0x140188369
// > GameManager::dataLoaded @ 0x1401883f7
// > GameManager::dataLoaded @ 0x140188482
// > GameStatsManager::getTotalCollectedCurrency @ 0x1401e3900
// > GameStatsManager::getTotalCollectedCurrency @ 0x1401e3a33
// > GameStatsManager::getTotalCollectedCurrency @ 0x1401e3b93
// > LevelAreaInnerLayer::init @ 0x1402c6837
// > LevelAreaInnerLayer::playStep1 @ 0x1402c842d
// > LevelSelectLayer::init @ 0x140318960
// > SecretLayer2::init @ 0x1403e3705
// > SecretLayer2::onSecretLevel @ 0x1403e4708
// > ??> @ 0x1406ca524
//
// 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=2
GJGameLevel *GameLevelManager::getMainLevel(GameLevelManager *a1, int a2, bool a3)
{
cocos2d::CCString *v6; // rax
const char *CString; // rax
size_t v8; // rbx
size_t v9; // r8
GJGameLevel *v10; // rdi
void *v11; // rcx
GJGameLevel *Level; // rax
GJGameLevel *v13; // rsi
cocos2d::CCString *v14; // rax
const char *v15; // rax
void *v16; // rcx
void **v17; // rdx
int v18; // ebx
float v19; // xmm0_4
void **v20; // rdx
int v21; // ebx
float v22; // xmm0_4
void **v23; // rdx
float v24; // xmm0_4
void *Src[4]; // [rsp+28h] [rbp-51h] BYREF
void *v27[4]; // [rsp+48h] [rbp-31h] BYREF
void *v28[4]; // [rsp+68h] [rbp-11h] BYREF
void *Block[2]; // [rsp+88h] [rbp+Fh] BYREF
__m128i si128; // [rsp+98h] [rbp+1Fh]
v6 = cocos2d::CCString::createWithFormat("%i", a2);
CString = cocos2d::CCString::getCString(v6);
*(_OWORD *)Block = 0;
si128 = 0;
v8 = -1;
v9 = -1;
do
++v9;
while ( CString[v9] );
sub_14003A930(Block, CString, v9);
v10 = (GJGameLevel *)cocos2d::CCDictionary::objectForKey(a1->m_mainLevels, Block);
if ( si128.m128i_i64[1] > 0xFuLL )
{
v11 = Block[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v11 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v11 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v11);
}
si128 = _mm_load_si128((const __m128i *)&xmmword_140623F30);
LOBYTE(Block[0]) = 0;
Level = LevelTools::getLevel(a2, a3);
v13 = Level;
if ( v10 )
{
sub_14003BDB0((__int64)Src, (__int64)&Level->m_levelString);
if ( &v10->m_levelString != (std::string *)Src )
{
v17 = Src;
if ( Src[3] > (void *)0xF )
v17 = (void **)Src[0];
sub_14003CCE0((void **)&v10->m_levelString, v17, (size_t)Src[2]);
}
sub_14003A830((__int64)Src);
v18 = v13->m_stars.random - v13->m_stars.seed;
v10->m_stars.value = v18;
v19 = (float)((float)rand() / 32767.0) * 1000.0;
v10->m_stars.seed = (int)v19;
v10->m_stars.random = v18 + (int)v19;
v10->m_coins = v13->m_coins;
v10->m_requiredCoins = v13->m_requiredCoins;
sub_14003BDB0((__int64)v27, (__int64)&v13->m_levelName);
if ( &v10->m_levelName != (std::string *)v27 )
{
v20 = v27;
if ( v27[3] > (void *)0xF )
v20 = (void **)v27[0];
sub_14003CCE0((void **)&v10->m_levelName, v20, (size_t)v27[2]);
}
sub_14003A830((__int64)v27);
v10->m_audioTrack = v13->m_audioTrack;
v10->m_twoPlayerMode = v13->m_twoPlayerMode;
v21 = v13->m_demon.random - v13->m_demon.seed;
v10->m_demon.value = v21;
v22 = (float)((float)rand() / 32767.0) * 1000.0;
v10->m_demon.seed = (int)v22;
v10->m_demon.random = v21 + (int)v22;
v10->m_difficulty = v13->m_difficulty;
sub_14003BDB0((__int64)v28, (__int64)&v13->m_capacityString);
if ( &v10->m_capacityString != (std::string *)v28 )
{
v23 = v28;
if ( v28[3] > (void *)0xF )
v23 = (void **)v28[0];
sub_14003CCE0((void **)&v10->m_capacityString, v23, (size_t)v28[2]);
}
sub_14003A830((__int64)v28);
v10->m_levelID.value = a2;
v24 = (float)((float)rand() / 32767.0) * 1000.0;
v10->m_levelID.seed = (int)v24;
v10->m_levelID.random = a2 + (int)v24;
v10->m_timestamp = v13->m_timestamp;
v10->m_levelLength = v13->m_levelLength;
}
else
{
v10 = LevelTools::getLevel(a2, 0);
v14 = cocos2d::CCString::createWithFormat("%i", a2);
v15 = cocos2d::CCString::getCString(v14);
*(_OWORD *)Block = 0;
si128 = 0;
do
++v8;
while ( v15[v8] );
sub_14003A930(Block, v15, v8);
cocos2d::CCDictionary::setObject(a1->m_mainLevels, v10, Block);
if ( si128.m128i_i64[1] > 0xFuLL )
{
v16 = Block[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 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);
}
}
return v10;
}