//
// GameLevelManager::createNewLevel from 0x14021bff0 to 0x14021c2f8 (776 bytes)
//
// 4 xrefs:
// > EditLevelLayer::FLAlert_Clicked @ 0x14017c32c
// > LevelBrowserLayer::onNew @ 0x1403e809e
// > LevelInfoLayer::FLAlert_Clicked @ 0x1404261f5
// > ??> @ 0x14091ba4c
//
// 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=4
__int64 GameLevelManager::createNewLevel()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 v2; // rdx
void **v3; // rdx
void **v4; // rax
int v5; // r12d
__int64 v6; // rcx
__int64 v7; // rax
__int64 AllLevelsInDict; // r13
int v9; // r15d
size_t v10; // rsi
cocos2d::CCString *v11; // rax
const char *CString; // rax
const char *v13; // rbx
size_t v14; // r8
bool v15; // r14
void *v16; // rcx
void **v17; // rdx
__int64 v18; // rcx
__int64 v19; // rax
void *v21; // [rsp+30h] [rbp-39h]
void *v22; // [rsp+30h] [rbp-39h]
void *v23[2]; // [rsp+38h] [rbp-31h] BYREF
size_t v24; // [rsp+48h] [rbp-21h]
unsigned __int64 v25; // [rsp+50h] [rbp-19h]
void *Src[4]; // [rsp+58h] [rbp-11h] BYREF
__int128 v27; // [rsp+78h] [rbp+Fh] BYREF
__int64 v28; // [rsp+88h] [rbp+1Fh]
unsigned __int64 v29; // [rsp+90h] [rbp+27h]
v21 = operator new(0x840u);
v0 = GJGameLevel::GJGameLevel((__int64)v21);
v1 = v0;
if ( v0 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64))(*(_QWORD *)v0 + 72LL))(v0) )
{
cocos2d::CCObject::autorelease((cocos2d::CCObject *)v1);
}
else
{
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v1 + 8LL))(v1, 1);
v1 = 0;
}
}
*(_DWORD *)(v1 + 1220) = 2;
*(_BYTE *)(v1 + 720) = 1;
v2 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v22 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager(v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v2 = qword_14090BFD0;
}
sub_14003F4F0((__int64)Src, v2 + 656);
if ( (void **)(v1 + 440) != Src )
{
v3 = Src;
if ( Src[3] > (void *)0xF )
v3 = (void **)Src[0];
sub_1400405A0((void **)(v1 + 440), v3, (size_t)Src[2]);
}
sub_14003D310((__int64)Src);
if ( !*(_QWORD *)(v1 + 1608) )
{
v4 = GameToolbox::gen_random((void **)&v27, 0x10u);
sub_140059C40(v1 + 1592, (__int64)v4);
sub_14003D310((__int64)&v27);
}
sub_14003F4F0((__int64)&v27, v1 + 1592);
v5 = 6;
sub_14003D310((__int64)&v27);
v7 = LocalLevelManager::sharedState(v6);
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v7);
v9 = 0;
v10 = -1;
while ( 1 )
{
v11 = cocos2d::CCString::createWithFormat("Unnamed %i", v9);
CString = cocos2d::CCString::getCString(v11);
v13 = CString;
v27 = 0;
v28 = 0;
v29 = 0;
v14 = -1;
do
++v14;
while ( CString[v14] );
sub_14003D230(&v27, CString, v14);
v5 |= 1u;
v15 = !cocos2d::CCDictionary::objectForKey(AllLevelsInDict, &v27) || v9 >= 999;
if ( (v5 & 1) != 0 )
{
v5 &= ~1u;
if ( v29 > 0xF )
{
v16 = (void *)v27;
if ( v29 + 1 >= 0x1000 )
{
v16 = *(void **)(v27 - 8);
if ( (unsigned __int64)(v27 - (_QWORD)v16 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v16);
}
}
if ( v15 )
break;
++v9;
}
*(_OWORD *)v23 = 0;
v24 = 0;
v25 = 0;
do
++v10;
while ( v13[v10] );
sub_14003D230(v23, v13, v10);
if ( (void **)(v1 + 1232) != v23 )
{
v17 = v23;
if ( v25 > 0xF )
v17 = (void **)v23[0];
sub_1400405A0((void **)(v1 + 1232), v17, v24);
}
sub_14003D310((__int64)v23);
v19 = LocalLevelManager::sharedState(v18);
cocos2d::CCArray::insertObject(*(cocos2d::CCArray **)(v19 + 368), (struct cocos2d::CCObject *)v1, 0);
return v1;
}