//
// GameLevelManager::getNextLevelName from 0x140144b30 to 0x140145046 (1302 bytes)
//
// 2 xrefs:
// > GJGameLevel::copyLevelInfo @ 0x14016d88d
// > ??> @ 0x1406ca548
//
// 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=6
__int64 __fastcall GameLevelManager::getNextLevelName(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // r14d
int v6; // esi
unsigned __int64 v7; // rcx
__int64 v8; // rbx
unsigned __int64 v9; // rax
const char *v10; // rcx
LocalLevelManager *v11; // rax
cocos2d::CCDictionary *AllLevelsInDict; // rbx
size_t v13; // r8
size_t v14; // rcx
const char *v15; // rax
const char *v16; // rcx
int v17; // eax
int v18; // esi
cocos2d::CCString *v19; // rax
const char *CString; // rax
size_t v21; // r8
size_t v22; // r15
int v23; // ebx
size_t v24; // rsi
void **v25; // rdx
void **v26; // rdx
size_t v27; // rax
size_t v28; // r8
const char *v29; // rdx
void **v30; // rdx
void **v31; // rdx
size_t v32; // r8
__int64 v33; // rbx
void *v34; // rcx
void *v35; // rcx
void *v36; // rcx
void *v37; // rcx
const char *v38; // rcx
unsigned __int64 v39; // rdx
size_t v40; // r14
unsigned __int64 v41; // rax
const char *v42; // rax
cocos2d::CCString *v43; // rax
char *v44; // rax
int v46; // [rsp+20h] [rbp-89h]
int v47; // [rsp+24h] [rbp-85h]
cocos2d::CCDictionary *v48; // [rsp+28h] [rbp-81h]
void *v49[2]; // [rsp+40h] [rbp-69h] BYREF
size_t v50; // [rsp+50h] [rbp-59h]
unsigned __int64 v51; // [rsp+58h] [rbp-51h]
void *Src[2]; // [rsp+60h] [rbp-49h] BYREF
size_t Size; // [rsp+70h] [rbp-39h]
unsigned __int64 v54; // [rsp+78h] [rbp-31h]
void *Block[2]; // [rsp+80h] [rbp-29h] BYREF
__int128 v56; // [rsp+90h] [rbp-19h]
char *String[2]; // [rsp+A0h] [rbp-9h] BYREF
__int128 v58; // [rsp+B0h] [rbp+7h]
v5 = 0;
v6 = 0;
v7 = *(_QWORD *)(a3 + 16);
if ( !v7 )
goto LABEL_59;
v8 = 0;
do
{
v9 = v7 - v8 - 1;
if ( v7 <= v9 )
sub_14003BCC0(v7);
v10 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v10 = *(const char **)a3;
if ( !isdigit(v10[v9]) )
break;
++v5;
++v6;
++v8;
v7 = *(_QWORD *)(a3 + 16);
}
while ( v6 < v7 );
if ( v5 > 0 )
{
v11 = LocalLevelManager::sharedState();
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v11);
v48 = AllLevelsInDict;
v13 = *(_QWORD *)(a3 + 16);
v14 = v13 - v5;
*(_OWORD *)String = 0;
v58 = 0;
if ( v13 < v14 )
sub_14003BCC0(v14);
if ( v5 < v13 )
v13 = v5;
v15 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v15 = *(const char **)a3;
sub_14003A930(String, &v15[v14], v13);
v16 = (const char *)String;
if ( *((_QWORD *)&v58 + 1) > 0xFu )
v16 = String[0];
v17 = atoi(v16);
v18 = 0;
v46 = 0;
while ( 1 )
{
v47 = v17 + 1;
v19 = cocos2d::CCString::createWithFormat("%i", v17 + 1);
CString = cocos2d::CCString::getCString(v19);
*(_OWORD *)v49 = 0;
v50 = 0;
v51 = 0;
v21 = -1;
do
++v21;
while ( CString[v21] );
sub_14003A930(v49, CString, v21);
v22 = v50;
if ( v50 < v5 )
{
*(_OWORD *)Src = 0;
Size = 0;
v54 = 15;
LOBYTE(Src[0]) = 0;
v23 = 0;
v24 = v5 - v50;
if ( v5 != v50 )
{
do
{
sub_140041270(Src, "0", 1u);
++v23;
}
while ( v23 < v24 );
}
v25 = v49;
if ( v51 > 0xF )
v25 = (void **)v49[0];
sub_140041270(Src, v25, v22);
v26 = Src;
if ( v54 > 0xF )
v26 = (void **)Src[0];
sub_14003CCE0(v49, v26, Size);
sub_14003A830((__int64)Src);
v22 = v50;
v18 = v46;
AllLevelsInDict = v48;
}
v27 = *(_QWORD *)(a3 + 16);
v28 = v27 - v5;
*(_OWORD *)Block = 0;
v56 = 0u;
if ( v27 < v28 )
v28 = v27;
v29 = (const char *)a3;
if ( *(_QWORD *)(a3 + 24) > 0xFu )
v29 = *(const char **)a3;
sub_14003A930(Block, v29, v28);
v30 = v49;
if ( v51 > 0xF )
v30 = (void **)v49[0];
sub_140041270(Block, v30, v22);
v31 = Block;
if ( *((_QWORD *)&v56 + 1) > 0xFu )
v31 = (void **)Block[0];
*(_OWORD *)Src = 0;
Size = 0;
v54 = 0;
v32 = -1;
do
++v32;
while ( *((_BYTE *)v31 + v32) );
sub_14003A930(Src, v31, v32);
v33 = cocos2d::CCDictionary::objectForKey(AllLevelsInDict, Src);
sub_14003A830((__int64)Src);
if ( !v33 )
{
*(_OWORD *)a2 = *(_OWORD *)Block;
*(_OWORD *)(a2 + 16) = v56;
sub_14003A830((__int64)v49);
sub_14003A830((__int64)String);
goto LABEL_70;
}
if ( v18 >= 999 )
break;
v46 = ++v18;
if ( *((_QWORD *)&v56 + 1) > 0xFu )
{
v34 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v56 + 1) + 1LL) >= 0x1000 )
{
v34 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v34 - 8) > 0x1F )
goto LABEL_50;
}
j_j_free(v34);
}
v17 = v47;
AllLevelsInDict = v48;
if ( v51 > 0xF )
{
v35 = v49[0];
if ( v51 + 1 >= 0x1000 )
{
v35 = *((void **)v49[0] - 1);
if ( (unsigned __int64)((char *)v49[0] - (char *)v35 - 8) > 0x1F )
goto LABEL_55;
}
j_j_free(v35);
v17 = v47;
}
}
*(_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 *)&v56 + 1) > 0xFu )
{
v36 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v56 + 1) + 1LL) >= 0x1000 )
{
v36 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v36 - 8) > 0x1F )
LABEL_50:
invalid_parameter_noinfo_noreturn();
}
j_j_free(v36);
}
if ( v51 > 0xF )
{
v37 = v49[0];
if ( v51 + 1 >= 0x1000 )
{
v37 = *((void **)v49[0] - 1);
if ( (unsigned __int64)((char *)v49[0] - (char *)v37 - 8) > 0x1F )
LABEL_55:
invalid_parameter_noinfo_noreturn();
}
j_j_free(v37);
}
sub_14003A830((__int64)String);
}
else
{
LABEL_59:
v38 = (const char *)a3;
v39 = *(_QWORD *)(a3 + 24);
if ( v39 > 0xF )
v38 = *(const char **)a3;
v40 = -1;
v41 = -1;
do
++v41;
while ( v38[v41] );
if ( v41 <= 0x12 )
{
v42 = (const char *)a3;
if ( v39 > 0xF )
v42 = *(const char **)a3;
v43 = cocos2d::CCString::createWithFormat("%s 2", v42);
v44 = (char *)cocos2d::CCString::getCString(v43);
do
++v40;
while ( v44[v40] );
sub_14003CCE0((void **)a3, v44, v40);
}
*(_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_14003A830(a3);
return a2;
}