//
// GameLevelManager::createNewLevel from 0x10053e200 to 0x10053e582 (898 bytes)
//
// 5 xrefs:
// > EditLevelLayer::onClone @ 0x1001e0fbb
// > MapSelectLayer::init @ 0x10025248a
// > LevelInfoLayer::onClone @ 0x1002b1494
// > LevelBrowserLayer::onNew @ 0x100482fbd
// > LevelBrowserLayer::createNewLevel @ 0x10048759b
//
// 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 12:31:56 +0000
//
std::string *__fastcall GameLevelManager::createNewLevel(__m128 a1)
{
char *v1; // r14
__int64 v2; // rax
__m128 *v3; // rax
unsigned __int8 v4; // al
char *v5; // rbx
__int64 v6; // rax
__int64 AllLevelsInDict; // r13
__int64 v8; // rax
const char *CString; // r15
size_t v10; // rax
size_t v11; // rbx
int v12; // r14d
char *data; // r12
__int64 v14; // r15
size_t v15; // r13
bool v16; // bl
__int64 v17; // rax
size_t v18; // rax
std::string::size_type v19; // rbx
std::string::pointer v20; // r14
size_t v21; // r14
std::string *v22; // rbx
__int64 v23; // rax
__int128 v25; // [rsp+0h] [rbp-B0h] BYREF
void *__p; // [rsp+10h] [rbp-A0h]
const char *v27; // [rsp+20h] [rbp-90h]
std::string *v28; // [rsp+28h] [rbp-88h]
std::string __str; // [rsp+30h] [rbp-80h] BYREF
std::string *v30; // [rsp+50h] [rbp-60h]
std::string v31; // [rsp+58h] [rbp-58h] BYREF
std::string __dst[2]; // [rsp+70h] [rbp-40h] BYREF
v1 = (char *)operator new(0x740u);
GJGameLevel::GJGameLevel(v1);
if ( (*(unsigned __int8 (__fastcall **)(char *))(*(_QWORD *)v1 + 80LL))(v1) )
{
cocos2d::CCObject::autorelease((__int64)v1);
}
else
{
(*(void (__fastcall **)(char *))(*(_QWORD *)v1 + 16LL))(v1);
v1 = nullptr;
}
*((_DWORD *)v1 + 285) = 2;
v1[648] = 1;
v2 = GameManager::sharedState();
if ( (*(_BYTE *)(v2 + 632) & 1) != 0 )
{
sub_10001AD30(&__str, *(const void **)(v2 + 648), *(_QWORD *)(v2 + 640));
}
else
{
v3 = (__m128 *)(v2 + 632);
__str.__r_.__value_.__r.__words[2] = v3[1].u64[0];
a1 = *v3;
*(__m128 *)&__str.__r_.__value_.__l.0 = *v3;
}
std::string::operator=((std::string *)(v1 + 416), &__str);
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
operator delete(__str.__r_.__value_.__l.__data_);
v4 = v1[1440];
if ( (v4 & 1) != 0 )
{
v5 = v1 + 1440;
if ( *((_QWORD *)v1 + 181) )
{
LABEL_11:
if ( (v4 & 1) == 0 )
goto LABEL_12;
goto LABEL_18;
}
}
else
{
v5 = v1 + 1440;
if ( v4 >> 1 )
goto LABEL_11;
}
sub_1004EF000(__dst, 16);
if ( (*v5 & 1) != 0 )
operator delete(*((void **)v1 + 182));
*((_QWORD *)v5 + 2) = __dst[0].__r_.__value_.__l.__data_;
a1.i64[0] = __dst[0].__r_.__value_.__r.__words[0];
*(_OWORD *)v5 = *(_OWORD *)&__dst[0].__r_.__value_.__l.0;
if ( (*v5 & 1) == 0 )
{
LABEL_12:
__p = *((void **)v5 + 2);
a1 = *(__m128 *)v5;
v25 = *(_OWORD *)v5;
v30 = (std::string *)v1;
if ( (v25 & 1) == 0 )
goto LABEL_20;
goto LABEL_19;
}
LABEL_18:
sub_10001AD30(&v25, *((const void **)v1 + 182), *((_QWORD *)v1 + 181));
v30 = (std::string *)v1;
if ( (v25 & 1) != 0 )
LABEL_19:
operator delete(__p);
LABEL_20:
v6 = LocalLevelManager::sharedState(*(double *)a1.i64);
AllLevelsInDict = LocalLevelManager::getAllLevelsInDict(v6);
v8 = sub_10088E820("Unnamed %i", v25);
CString = (const char *)cocos2d::CCString::getCString(v8);
v10 = strlen(CString);
if ( v10 > 0xFFFFFFFFFFFFFFF7LL )
goto LABEL_33;
v11 = v10;
v28 = v30 + 48;
v12 = 1;
while ( 1 )
{
if ( v11 >= 0x17 )
{
v27 = CString;
v14 = AllLevelsInDict;
v15 = (v11 | 7) + 1;
if ( (v11 | 7) == 0x17 )
v15 = 26;
data = (char *)operator new(v15);
__dst[0].__r_.__value_.__r.__words[2] = (std::string::size_type)data;
__dst[0].__r_.__value_.__r.__words[0] = v15 + 1;
AllLevelsInDict = v14;
CString = v27;
__dst[0].__r_.__value_.__l.__size_ = v11;
LABEL_28:
memmove(data, CString, v11);
goto LABEL_29;
}
__dst[0].__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v11);
data = __dst[0].__r_.__value_.__s.__data_;
if ( v11 )
goto LABEL_28;
LABEL_29:
data[v11] = 0;
v16 = cocos2d::CCDictionary::objectForKey(AllLevelsInDict, (char *)__dst) != 0;
if ( (*(_BYTE *)&__dst[0].__r_.__value_.__s.0 & 1) != 0 )
operator delete(__dst[0].__r_.__value_.__l.__data_);
if ( (unsigned int)(v12 - 1) >= 0x3E7 || !v16 )
break;
v17 = sub_10088E820("Unnamed %i", v25);
CString = (const char *)cocos2d::CCString::getCString(v17);
v11 = strlen(CString);
++v12;
if ( v11 >= 0xFFFFFFFFFFFFFFF8LL )
goto LABEL_33;
}
v18 = strlen(CString);
if ( v18 >= 0xFFFFFFFFFFFFFFF8LL )
LABEL_33:
sub_100003630();
v19 = v18;
v20 = v31.__r_.__value_.__s.__data_;
if ( v18 >= 0x17 )
{
v21 = 26;
if ( (v18 | 7) != 0x17 )
v21 = (v18 | 7) + 1;
v31.__r_.__value_.__r.__words[2] = (std::string::size_type)operator new(v21);
v31.__r_.__value_.__r.__words[0] = v21 + 1;
v20 = v31.__r_.__value_.__l.__data_;
v31.__r_.__value_.__l.__size_ = v19;
goto LABEL_41;
}
v31.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v18);
if ( v18 )
LABEL_41:
memmove(v20, CString, v19);
v20[v19] = 0;
std::string::operator=(v28, &v31);
v22 = v30;
if ( (*(_BYTE *)&v31.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v31.__r_.__value_.__l.__data_);
v23 = LocalLevelManager::sharedState(*(double *)a1.i64);
sub_1007FF110(*(_QWORD *)(v23 + 360), v22, 0);
return v22;
}