//
// LevelEditorLayer::getLevelString from 0x1000e3470 to 0x1000e37a5 (821 bytes)
//
// 1 xrefs:
// > EditorPauseLayer::saveLevel @ 0x100294879
//
// 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
//
std::string *__fastcall LevelEditorLayer::getLevelString(std::string *this, __int64 a2)
{
const std::string::value_type *v3; // rsi
std::string::size_type v4; // rdx
__int64 v5; // rax
unsigned int *v6; // rax
GameObject **v7; // r12
int v8; // r15d
GameObject *v9; // r13
bool hasSecondaryColor; // bl
int v11; // r14d
cocos2d::CCObject *v12; // r15
int v13; // eax
cocos2d::CCObject *v14; // r15
const std::string::value_type *v15; // rsi
std::string::size_type v16; // rdx
unsigned __int64 v18; // [rsp+8h] [rbp-68h]
__int64 v19; // [rsp+10h] [rbp-60h]
cocos2d::CCDictionary *v20; // [rsp+28h] [rbp-48h]
unsigned __int8 v21; // [rsp+30h] [rbp-40h] BYREF
std::string::value_type __s[7]; // [rsp+31h] [rbp-3Fh] BYREF
std::string::size_type v23; // [rsp+38h] [rbp-38h]
void *__p; // [rsp+40h] [rbp-30h]
GJBaseGameLayer::generateSpawnRemap((GJBaseGameLayer *)a2);
GJBaseGameLayer::calculateColorGroups((GJBaseGameLayer *)a2);
v20 = cocos2d::CCDictionary::create();
*(_BYTE *)(a2 + 13705) = 0;
*(_WORD *)&this->__r_.__value_.__l.0 = 0;
LevelSettingsObject::getSaveString(&v21, *(_QWORD *)(a2 + 3248));
if ( (v21 & 1) != 0 )
{
v3 = (const std::string::value_type *)__p;
v4 = v23;
}
else
{
v4 = v21 >> 1;
v3 = __s;
}
std::string::append(this, v3, v4);
if ( (v21 & 1) != 0 )
operator delete(__p);
std::string::append(this, ";");
qsort(
*(void **)(*(_QWORD *)(*(_QWORD *)(a2 + 3256) + 56LL) + 16LL),
**(unsigned int **)(*(_QWORD *)(a2 + 3256) + 56LL),
8u,
(int (__cdecl *)(const void *, const void *))sub_1000DA520);
v5 = *(_QWORD *)(a2 + 3256);
if ( v5 )
{
v6 = *(unsigned int **)(v5 + 56);
if ( *v6 )
{
v7 = *((GameObject ***)v6 + 2);
v18 = (unsigned __int64)&v7[*v6 - 1];
v8 = 1;
v19 = a2;
while ( 1 )
{
v9 = *v7;
if ( !*v7 )
return this;
if ( !v9->m_unk507 )
break;
LABEL_9:
if ( (unsigned __int64)++v7 > v18 )
return this;
}
GameObject::updateHSVState(*v7);
hasSecondaryColor = GameObject::hasSecondaryColor(v9);
v11 = v8;
GameObject::getColorKey(&v21, v9, 1, 1);
if ( cocos2d::CCDictionary::objectForKey_1(v20, &v21) )
{
v9->m_mainColorKeyIndex = *(_DWORD *)(cocos2d::CCDictionary::objectForKey_1(v20, &v21) + 56);
if ( (v21 & 1) == 0 )
goto LABEL_15;
}
else
{
v12 = (cocos2d::CCObject *)operator new(0x40u);
cocos2d::CCObject::CCObject(v12);
v12->__vftable = (cocos2d::CCObject_vtbl *)off_1008B8348;
LODWORD(v12[1].__vftable) = v11;
cocos2d::CCObject::autorelease(v12);
cocos2d::CCDictionary::setObject_1(v20, v12, &v21);
v13 = v11++;
v9->m_mainColorKeyIndex = v13;
if ( (v21 & 1) == 0 )
{
LABEL_15:
if ( hasSecondaryColor )
{
GameObject::getColorKey(&v21, v9, 0, 1);
if ( cocos2d::CCDictionary::objectForKey_1(v20, &v21) )
{
v8 = v11;
v9->m_detailColorKeyIndex = *(_DWORD *)(cocos2d::CCDictionary::objectForKey_1(v20, &v21) + 56);
if ( (v21 & 1) == 0 )
goto LABEL_24;
goto LABEL_23;
}
v14 = (cocos2d::CCObject *)operator new(0x40u);
cocos2d::CCObject::CCObject(v14);
v14->__vftable = (cocos2d::CCObject_vtbl *)off_1008B8348;
LODWORD(v14[1].__vftable) = v11;
cocos2d::CCObject::autorelease(v14);
cocos2d::CCDictionary::setObject_1(v20, v14, &v21);
v8 = v11 + 1;
v9->m_detailColorKeyIndex = v11;
if ( (v21 & 1) != 0 )
LABEL_23:
operator delete(__p);
}
else
{
v8 = v11;
}
LABEL_24:
((void (__fastcall *)(unsigned __int8 *, GameObject *, __int64))v9->getSaveString)(&v21, v9, v19);
if ( (v21 & 1) != 0 )
{
v15 = (const std::string::value_type *)__p;
v16 = v23;
}
else
{
v16 = v21 >> 1;
v15 = __s;
}
std::string::append(this, v15, v16);
std::string::append(this, ";");
if ( !*(_BYTE *)(v19 + 13705) )
*(_BYTE *)(v19 + 13705) = v9->m_isHighDetail;
if ( (v21 & 1) != 0 )
operator delete(__p);
goto LABEL_9;
}
}
operator delete(__p);
goto LABEL_15;
}
}
return this;
}