//
// GameLevelManager::createNewLevel from 0x140144870 to 0x140144b21 (689 bytes)
//
// 4 xrefs:
// > EditLevelLayer::FLAlert_Clicked @ 0x1400d8da6
// > LevelBrowserLayer::onNew @ 0x1402cded0
// > LevelInfoLayer::FLAlert_Clicked @ 0x140300463
// > ??> @ 0x1406ca53c
//
// 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=4
GJGameLevel *GameLevelManager::createNewLevel(GameLevelManager *a1)
{
GJGameLevel *v1; // rax
GJGameLevel *v2; // r12
int v3; // esi
__int64 v4; // rdx
void **v5; // rdx
LocalLevelManager *v6; // rax
cocos2d::CCDictionary *AllLevelsInDict; // r13
int v8; // r15d
size_t v9; // rdi
cocos2d::CCString *v10; // rax
const char *CString; // rax
const char *v12; // rbx
size_t v13; // r8
bool v14; // r14
void *v15; // rcx
void **v16; // rdx
LocalLevelManager *v17; // rax
GJGameLevel *v19; // [rsp+20h] [rbp-39h]
void *v20; // [rsp+20h] [rbp-39h]
void *v21[2]; // [rsp+28h] [rbp-31h] BYREF
size_t v22; // [rsp+38h] [rbp-21h]
unsigned __int64 v23; // [rsp+40h] [rbp-19h]
void *Src[4]; // [rsp+48h] [rbp-11h] BYREF
__int128 v25; // [rsp+68h] [rbp+Fh] BYREF
__int64 v26; // [rsp+78h] [rbp+1Fh]
unsigned __int64 v27; // [rsp+80h] [rbp+27h]
v19 = (GJGameLevel *)operator new(0x5C8u);
v1 = GJGameLevel::GJGameLevel(v19);
v2 = v1;
if ( v1 )
{
if ( v1->init(v1) )
{
cocos2d::CCObject::autorelease(v2);
}
else
{
((void (__fastcall *)(GJGameLevel *, __int64))v2->~GJGameLevel)(v2, 1);
v2 = nullptr;
}
}
v3 = 2;
v2->m_levelType = Editor;
v2->m_isEditable = 1;
v4 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v20 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v4 = qword_1406C2ED8;
}
sub_14003BDB0((__int64)Src, v4 + 616);
if ( &v2->m_creatorName != (std::string *)Src )
{
v5 = Src;
if ( Src[3] > (void *)0xF )
v5 = (void **)Src[0];
sub_14003CCE0((void **)&v2->m_creatorName, v5, (size_t)Src[2]);
}
sub_14003A830((__int64)Src);
v6 = LocalLevelManager::sharedState();
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v6);
v8 = 0;
v9 = -1;
while ( 1 )
{
v10 = cocos2d::CCString::createWithFormat("Unnamed %i", v8);
CString = cocos2d::CCString::getCString(v10);
v12 = CString;
v25 = 0;
v26 = 0;
v27 = 0;
v13 = -1;
do
++v13;
while ( CString[v13] );
sub_14003A930(&v25, CString, v13);
v3 |= 1u;
v14 = !cocos2d::CCDictionary::objectForKey(AllLevelsInDict, &v25) || v8 >= 999;
if ( (v3 & 1) != 0 )
{
v3 &= ~1u;
if ( v27 > 0xF )
{
v15 = (void *)v25;
if ( v27 + 1 >= 0x1000 )
{
v15 = *(void **)(v25 - 8);
if ( (unsigned __int64)(v25 - (_QWORD)v15 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v15);
}
}
if ( v14 )
break;
++v8;
}
*(_OWORD *)v21 = 0;
v22 = 0;
v23 = 0;
do
++v9;
while ( v12[v9] );
sub_14003A930(v21, v12, v9);
if ( &v2->m_tempName != (std::string *)v21 )
{
v16 = v21;
if ( v23 > 0xF )
v16 = (void **)v21[0];
sub_14003CCE0((void **)&v2->m_tempName, v16, v22);
}
sub_14003A830((__int64)v21);
v17 = LocalLevelManager::sharedState();
cocos2d::CCArray::insertObject(v17->m_localLevels, v2, 0);
return v2;
}