//
// GameLevelManager::getNextLevelName from 0x14021c300 to 0x14021c866 (1382 bytes)
//
// 2 xrefs:
// > GJGameLevel::copyLevelInfo @ 0x14026709e
// > ??> @ 0x14091ba58
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:28:23 +0000
//
// Hidden C++ exception states: #wind=6
__int64 __fastcall GameLevelManager::getNextLevelName(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v6; // esi
int v7; // ebx
unsigned __int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rax
unsigned __int64 v11; // rdx
const char *v12; // rax
__int64 v13; // rax
__int64 v14; // rdx
__int64 AllLevelsInDict; // rbx
__int64 v16; // r9
size_t v17; // r8
size_t v18; // r12
size_t v19; // rcx
const char *v20; // rax
const char *v21; // rcx
int v22; // eax
int v23; // esi
cocos2d::CCString *v24; // rax
const char *CString; // rax
size_t v26; // r8
size_t v27; // r15
int v28; // ebx
unsigned __int64 v29; // rsi
void **v30; // rdx
void **v31; // rdx
size_t v32; // rax
size_t v33; // r8
const char *v34; // rdx
void **v35; // rdx
void **v36; // rdx
size_t v37; // r8
__int64 v38; // rbx
void *v39; // rcx
void *v40; // rcx
void *v41; // rcx
void *v42; // rcx
const char *v43; // rcx
unsigned __int64 v44; // r8
size_t v45; // r14
unsigned __int64 v46; // rax
const char *v47; // rdx
cocos2d::CCString *v48; // rax
char *v49; // rax
int v51; // [rsp+30h] [rbp-89h]
int v52; // [rsp+34h] [rbp-85h]
__int64 v53; // [rsp+38h] [rbp-81h]
void *v54[2]; // [rsp+50h] [rbp-69h] BYREF
size_t v55; // [rsp+60h] [rbp-59h]
unsigned __int64 v56; // [rsp+68h] [rbp-51h]
void *Src[2]; // [rsp+70h] [rbp-49h] BYREF
size_t Size[2]; // [rsp+80h] [rbp-39h]
void *Block[2]; // [rsp+90h] [rbp-29h] BYREF
__int128 v60; // [rsp+A0h] [rbp-19h]
char *String[2]; // [rsp+B0h] [rbp-9h] BYREF
__int128 v62; // [rsp+C0h] [rbp+7h]
v6 = 0;
v7 = 0;
v8 = *(_QWORD *)(a3 + 16);
if ( !v8 )
goto LABEL_59;
v9 = 0;
do
{
v10 = ~v9;
v11 = v10 + v8;
if ( v8 <= v10 + v8 )
sub_14003F4D0(v8, v11, a3, a4);
v12 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v12 = *(const char **)a3;
if ( !isdigit(v12[v11]) )
break;
++v6;
v9 = ++v7;
v8 = *(_QWORD *)(a3 + 16);
}
while ( v7 < v8 );
if ( v6 > 0 )
{
v13 = LocalLevelManager::sharedState(v8);
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v13);
v53 = AllLevelsInDict;
v17 = *(_QWORD *)(a3 + 16);
v18 = v6;
v19 = v17 - v6;
*(_OWORD *)String = 0;
v62 = 0;
if ( v17 < v19 )
sub_14003F4D0(v19, v14, v17, v16);
if ( v6 < v17 )
v17 = v6;
v20 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v20 = *(const char **)a3;
sub_14003D230(String, &v20[v19], v17);
v21 = (const char *)String;
if ( *((_QWORD *)&v62 + 1) > 0xFu )
v21 = String[0];
v22 = atoi(v21);
v23 = 0;
v51 = 0;
while ( 1 )
{
v52 = v22 + 1;
v24 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)(v22 + 1));
CString = cocos2d::CCString::getCString(v24);
*(_OWORD *)v54 = 0;
v55 = 0;
v56 = 0;
v26 = -1;
do
++v26;
while ( CString[v26] );
sub_14003D230(v54, CString, v26);
v27 = v55;
if ( v55 < v18 )
{
*(_OWORD *)Src = 0;
Size[0] = 0;
Size[1] = 15;
LOBYTE(Src[0]) = 0;
v28 = 0;
v29 = v18 - v55;
if ( v18 != v55 )
{
do
{
sub_140044D80(Src, "0", 1u);
++v28;
}
while ( v28 < v29 );
}
v30 = v54;
if ( v56 > 0xF )
v30 = (void **)v54[0];
sub_140044D80(Src, v30, v27);
v31 = Src;
if ( Size[1] > 0xF )
v31 = (void **)Src[0];
sub_1400405A0(v54, v31, Size[0]);
sub_14003D310((__int64)Src);
v27 = v55;
v23 = v51;
AllLevelsInDict = v53;
}
v32 = *(_QWORD *)(a3 + 16);
v33 = v32 - v18;
*(_OWORD *)Block = 0;
v60 = 0;
if ( v32 < v32 - v18 )
v33 = v32;
v34 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v34 = *(const char **)a3;
sub_14003D230(Block, v34, v33);
v35 = v54;
if ( v56 > 0xF )
v35 = (void **)v54[0];
sub_140044D80(Block, v35, v27);
v36 = Block;
if ( *((_QWORD *)&v60 + 1) > 0xFu )
v36 = (void **)Block[0];
*(_OWORD *)Src = 0;
*(_OWORD *)Size = 0;
v37 = -1;
do
++v37;
while ( *((_BYTE *)v36 + v37) );
sub_14003D230(Src, v36, v37);
v38 = cocos2d::CCDictionary::objectForKey(AllLevelsInDict, Src);
sub_14003D310((__int64)Src);
if ( !v38 )
{
*(_QWORD *)(a2 + 16) = 0;
*(_QWORD *)(a2 + 24) = 0;
*(_OWORD *)a2 = *(_OWORD *)Block;
*(_OWORD *)(a2 + 16) = v60;
sub_14003D310((__int64)v54);
sub_14003D310((__int64)String);
goto LABEL_70;
}
if ( v23 >= 999 )
break;
v51 = ++v23;
if ( *((_QWORD *)&v60 + 1) > 0xFu )
{
v39 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v60 + 1) + 1LL) >= 0x1000 )
{
v39 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v39 - 8) > 0x1F )
goto LABEL_50;
}
j_j_free(v39);
}
v22 = v52;
AllLevelsInDict = v53;
if ( v56 > 0xF )
{
v40 = v54[0];
if ( v56 + 1 >= 0x1000 )
{
v40 = *((void **)v54[0] - 1);
if ( (unsigned __int64)((char *)v54[0] - (char *)v40 - 8) > 0x1F )
goto LABEL_55;
}
j_j_free(v40);
v22 = v52;
}
}
*(_OWORD *)a2 = 0;
*(_QWORD *)(a2 + 16) = 0;
*(_QWORD *)(a2 + 24) = 0;
*(_OWORD *)a2 = *(_OWORD *)a3;
*(_OWORD *)(a2 + 16) = *(_OWORD *)(a3 + 16);
*(_QWORD *)(a3 + 16) = 0;
*(_QWORD *)(a3 + 24) = 15;
*(_BYTE *)a3 = 0;
if ( *((_QWORD *)&v60 + 1) > 0xFu )
{
v41 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v60 + 1) + 1LL) >= 0x1000 )
{
v41 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v41 - 8) > 0x1F )
LABEL_50:
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v41);
}
if ( v56 > 0xF )
{
v42 = v54[0];
if ( v56 + 1 >= 0x1000 )
{
v42 = *((void **)v54[0] - 1);
if ( (unsigned __int64)((char *)v54[0] - (char *)v42 - 8) > 0x1F )
LABEL_55:
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v42);
}
sub_14003D310((__int64)String);
}
else
{
LABEL_59:
v43 = (const char *)a3;
v44 = *(_QWORD *)(a3 + 24);
if ( v44 > 0xF )
v43 = *(const char **)a3;
v45 = -1;
v46 = -1;
do
++v46;
while ( v43[v46] );
if ( v46 <= 0x12 )
{
v47 = (const char *)a3;
if ( v44 > 0xF )
v47 = *(const char **)a3;
v48 = cocos2d::CCString::createWithFormat("%s 2", v47);
v49 = (char *)cocos2d::CCString::getCString(v48);
do
++v45;
while ( v49[v45] );
sub_1400405A0((void **)a3, v49, v45);
}
*(_OWORD *)a2 = 0;
*(_QWORD *)(a2 + 16) = 0;
*(_QWORD *)(a2 + 24) = 0;
*(_OWORD *)a2 = *(_OWORD *)a3;
*(_OWORD *)(a2 + 16) = *(_OWORD *)(a3 + 16);
*(_QWORD *)(a3 + 16) = 0;
*(_QWORD *)(a3 + 24) = 15;
*(_BYTE *)a3 = 0;
}
LABEL_70:
sub_14003D310(a3);
return a2;
}