//
// GameLevelManager::createNewLevel from 0x701644 to 0x7018e8 (676 bytes)
//
// 5 xrefs:
// > LevelInfoLayer::onClone @ 0x6d9368
// > EditLevelLayer::onClone @ 0x6e2eac
// > LevelBrowserLayer::createNewLevel @ 0x6e93cc
// > MapSelectLayer::init @ 0x980a30
// > ??> @ 0x637c8
//
// 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
//
GJGameLevel *GameLevelManager::createNewLevel(GameLevelManager *a1)
{
__int64 v1; // x26
GameManager *v2; // x0
char *v3; // x0
LocalLevelManager *v4; // x0
int v5; // w20
cocos2d::CCDictionary *AllLevelsInDict; // x25
cocos2d::CCString *i; // x0
char *CString; // x21
_BOOL4 v9; // w2
char *v10; // x0
int v11; // w2
unsigned int *v12; // x3
int v13; // w1
char *v14; // x20
LocalLevelManager *v15; // x0
unsigned int *v17; // x19
int v18; // w0
unsigned int *v19; // x1
int v20; // w2
int v21; // [xsp+60h] [xbp+60h]
std::string v22; // [xsp+80h] [xbp+80h] BYREF
v1 = GJGameLevel::create(_stack_chk_guard);
*(_DWORD *)(v1 + 868) = 2;
*(_BYTE *)(v1 + 496) = (unsigned __int8)&dword_0 + 1;
v2 = GameManager::sharedState();
sub_D18D28(&v22, &v2->m_playerName);
sub_D18EA8(v1 + 368, &v22);
v3 = (char *)v22.m_data.m_data - 24;
if ( (__int64 *)v22.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v19 = (unsigned int *)((char *)v22.m_data.m_data - 8);
do
v20 = __ldaxr(v19);
while ( __stlxr(v20 - 1, v19) );
}
else
{
v20 = *((_DWORD *)v22.m_data.m_data - 2);
*((_DWORD *)v22.m_data.m_data - 2) = v20 - 1;
}
if ( v20 <= 0 )
operator delete(v3);
}
v4 = LocalLevelManager::sharedState();
v5 = 0;
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v4);
for ( i = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"Unnamed %i", nullptr);
;
i = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"Unnamed %i",
(const char *)(unsigned int)v5) )
{
CString = (char *)cocos2d::CCString::getCString(i);
sub_D153B8((int)&v22, CString);
v9 = cocos2d::CCDictionary::objectForKey(AllLevelsInDict, &v22) == 0;
v10 = (char *)v22.m_data.m_data - 24;
v11 = v9 || v5 > 998;
if ( (__int64 *)v22.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v12 = (unsigned int *)((char *)v22.m_data.m_data - 8);
do
v13 = __ldaxr(v12);
while ( __stlxr(v13 - 1, v12) );
}
else
{
v13 = *((_DWORD *)v22.m_data.m_data - 2);
*((_DWORD *)v22.m_data.m_data - 2) = v13 - 1;
}
if ( v13 <= 0 )
break;
}
if ( v11 )
goto LABEL_11;
LABEL_5:
++v5;
}
v21 = v11;
operator delete(v10);
if ( !v21 )
goto LABEL_5;
LABEL_11:
sub_D153B8((int)&v22, CString);
sub_D18EA8(v1 + 880, &v22);
v14 = (char *)v22.m_data.m_data - 24;
if ( (__int64 *)v22.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v17 = (unsigned int *)((char *)v22.m_data.m_data - 8);
do
v18 = __ldaxr(v17);
while ( __stlxr(v18 - 1, v17) );
}
else
{
v18 = *((_DWORD *)v22.m_data.m_data - 2);
*((_DWORD *)v22.m_data.m_data - 2) = v18 - 1;
}
if ( v18 <= 0 )
operator delete(v14);
}
v15 = LocalLevelManager::sharedState();
cocos2d::CCArray::insertObject(v15->m_localLevels, (cocos2d::CCObject *)v1, 0);
return (GJGameLevel *)v1;
}