//
// LevelInfoLayer::downloadLevel from 0x1402f9fa0 to 0x1402fa2c5 (805 bytes)
//
// 4 xrefs:
// > LevelInfoLayer::init @ 0x1402f80f9
// > LevelInfoLayer::onPlay @ 0x1402fc48b
// > LevelInfoLayer::onUpdate @ 0x1402fed0a
// > ??> @ 0x1406d4154
//
// 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=8
void LevelInfoLayer::downloadLevel(LevelInfoLayer *a1)
{
_BOOL8 v2; // rdx
__int64 v3; // r9
int v4; // eax
GameManager *v5; // rcx
bool GameVariable; // al
int v7; // edx
__int64 v8; // rax
__int64 v9; // rax
__int64 i; // r8
int v11; // ecx
int v12; // edx
__int64 v13; // rax
__int64 v14; // rax
__int64 j; // r8
int v16; // ecx
GJGameLevel *m_level; // rax
int v18; // edi
int v19; // esi
GameLevelManager *v20; // rcx
LevelDownloadDelegate *v21; // rbx
__int64 v22; // rax
void *v23; // [rsp+30h] [rbp+8h]
void *v24; // [rsp+30h] [rbp+8h]
void *v25; // [rsp+30h] [rbp+8h]
void *v26; // [rsp+30h] [rbp+8h]
void *v27; // [rsp+30h] [rbp+8h]
void *v28; // [rsp+30h] [rbp+8h]
void *v29; // [rsp+30h] [rbp+8h]
a1->m_playBtnMenu->setVisible(a1->m_playBtnMenu, 0);
LOBYTE(v2) = 1;
a1->m_circle->setVisible(a1->m_circle, v2);
v3 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v23 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v3 = qword_1406C2EC0;
}
v4 = *(_DWORD *)(v3 + 904);
if ( v4 != 99 && v4 != 100 )
{
v5 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v24 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v5 = (GameManager *)qword_1406C2ED8;
}
GameVariable = GameManager::getGameVariable(v5, "0084");
v3 = qword_1406C2EC0;
if ( GameVariable )
{
if ( !a1->m_level->m_levelIndex )
{
if ( !qword_1406C2EC0 )
{
v25 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v3 = qword_1406C2EC0;
}
v7 = 0;
v8 = *(_QWORD *)(v3 + 352);
if ( v8 )
{
v9 = *(_QWORD *)(v8 + 56);
if ( v9 )
{
for ( i = *(_QWORD *)(v9 + 288); ; i = *(_QWORD *)(i + 288) )
{
v11 = v7;
v7 = *(_DWORD *)(*(_QWORD *)(v9 + 264) + 696LL);
if ( v7 >= v11 )
v7 = v11;
v9 = i;
if ( !i )
break;
}
}
}
a1->m_level->m_levelIndex = v7;
}
}
else
{
if ( !qword_1406C2EC0 )
{
v26 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v26);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v3 = qword_1406C2EC0;
}
v12 = 0;
v13 = *(_QWORD *)(v3 + 352);
if ( v13 )
{
v14 = *(_QWORD *)(v13 + 56);
if ( v14 )
{
for ( j = *(_QWORD *)(v14 + 288); ; j = *(_QWORD *)(j + 288) )
{
v16 = v12;
v12 = *(_DWORD *)(*(_QWORD *)(v14 + 264) + 696LL);
if ( v12 <= v16 )
v12 = v16;
v14 = j;
if ( !j )
break;
}
}
}
a1->m_level->m_levelIndex = v12 + 1;
}
}
if ( !v3 )
{
v27 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v27);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v3 = qword_1406C2EC0;
}
GameLevelManager::saveLevel((GameLevelManager *)v3, a1->m_level);
m_level = a1->m_level;
v18 = m_level->m_dailyID.random - m_level->m_dailyID.seed;
v19 = m_level->m_levelID.random - m_level->m_levelID.seed;
v20 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v28 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v28);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v20 = (GameLevelManager *)qword_1406C2EC0;
}
GameLevelManager::downloadLevel(v20, v19, a1->m_level->m_gauntletLevel, v18);
v21 = &a1->LevelDownloadDelegate;
v22 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v29 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v22 = qword_1406C2EC0;
}
*(_QWORD *)(v22 + 728) = v21;
}