//
// LevelEditorLayer::getLevelString from 0x1000b3030 to 0x1000b33b5 (901 bytes)
//
// 3 xrefs:
// > LevelEditorLayer::saveLevel @ 0x1000c6277
// > sub_1000D5190 @ 0x1000d52b4
// > sub_1000D5780 @ 0x1000d58a5
//
// 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:20:20 +0000
//
std::string *__fastcall LevelEditorLayer::getLevelString(std::string *this, __int64 a2)
{
std::string *v2; // r15
__int64 v3; // rdi
int v4; // eax
const std::string::value_type *v5; // rsi
std::string::size_type v6; // rdx
__int64 v7; // rax
unsigned int *v8; // rax
_QWORD *v9; // rbx
int v10; // r14d
__int64 v11; // r13
char hasSecondaryColor; // r12
__int64 v13; // rax
int v14; // r15d
__int64 v15; // rax
const std::string::value_type *v16; // rsi
std::string::size_type v17; // rdx
void **v18; // r14
void *v19; // rdi
void **v21; // rbx
unsigned __int64 v22; // [rsp+8h] [rbp-98h]
void *v23[2]; // [rsp+10h] [rbp-90h] BYREF
void *v24[2]; // [rsp+20h] [rbp-80h]
int v25; // [rsp+30h] [rbp-70h]
unsigned __int8 *v26; // [rsp+40h] [rbp-60h] BYREF
std::string *v27; // [rsp+48h] [rbp-58h]
__int64 v28; // [rsp+50h] [rbp-50h]
unsigned __int8 v29; // [rsp+58h] [rbp-48h] BYREF
std::string::value_type __s[7]; // [rsp+59h] [rbp-47h] BYREF
std::string::size_type v31; // [rsp+60h] [rbp-40h]
void *__p; // [rsp+68h] [rbp-38h]
_BYTE v33[41]; // [rsp+77h] [rbp-29h] BYREF
v2 = this;
GJBaseGameLayer::generateSpawnRemap(a2);
GJBaseGameLayer::calculateColorGroups(a2);
*(_OWORD *)v24 = 0;
*(_OWORD *)v23 = 0;
v25 = 1065353216;
*(_BYTE *)(a2 + 14018) = 0;
*(_WORD *)&this->__r_.__value_.__l.0 = 0;
v28 = a2;
v3 = *(_QWORD *)(a2 + 3280);
v27 = v2;
v4 = sub_1007FEF90(v3);
std::string::reserve(v2, (unsigned int)(200 * v4));
LevelSettingsObject::getSaveString(&v29, *(_QWORD *)(a2 + 3272));
if ( (v29 & 1) != 0 )
{
v5 = (const std::string::value_type *)__p;
v6 = v31;
}
else
{
v6 = v29 >> 1;
v5 = __s;
}
std::string::append(v2, v5, v6);
if ( (v29 & 1) != 0 )
operator delete(__p);
std::string::append(v2, ";");
qsort(
*(void **)(*(_QWORD *)(*(_QWORD *)(v28 + 3280) + 56LL) + 16LL),
**(unsigned int **)(*(_QWORD *)(v28 + 3280) + 56LL),
8u,
(int (__cdecl *)(const void *, const void *))sub_1000A9190);
v7 = *(_QWORD *)(v28 + 3280);
if ( v7 )
{
v8 = *(unsigned int **)(v7 + 56);
if ( *v8 )
{
v9 = *((_QWORD **)v8 + 2);
v22 = (unsigned __int64)&v9[*v8 - 1];
v10 = 1;
while ( 1 )
{
v11 = *v9;
if ( !*v9 )
goto LABEL_31;
if ( !*(_BYTE *)(v11 + 1303) )
break;
LABEL_9:
if ( (unsigned __int64)++v9 > v22 )
goto LABEL_31;
}
GameObject::updateHSVState(*v9);
hasSecondaryColor = GameObject::hasSecondaryColor(v11);
GameObject::getColorKey(&v29, v11, 1, 1);
v13 = sub_1000E0440(v23, &v29);
if ( v13 )
{
v14 = v10;
*(_DWORD *)(v11 + 1320) = *(_DWORD *)(v13 + 40);
if ( (v29 & 1) == 0 )
goto LABEL_15;
}
else
{
v26 = &v29;
*(_DWORD *)(sub_1000E06D0(v23, &v29, &unk_100A04AD3, &v26, v33) + 40) = v10;
v14 = v10 + 1;
*(_DWORD *)(v11 + 1320) = v10;
if ( (v29 & 1) == 0 )
{
LABEL_15:
if ( hasSecondaryColor )
{
GameObject::getColorKey(&v29, v11, 0, 1);
v15 = sub_1000E0440(v23, &v29);
if ( v15 )
{
v10 = v14;
*(_DWORD *)(v11 + 1324) = *(_DWORD *)(v15 + 40);
if ( (v29 & 1) == 0 )
goto LABEL_24;
goto LABEL_23;
}
v26 = &v29;
v10 = v14 + 1;
*(_DWORD *)(sub_1000E06D0(v23, &v29, &unk_100A04AD3, &v26, v33) + 40) = v14;
*(_DWORD *)(v11 + 1324) = v14;
if ( (v29 & 1) != 0 )
LABEL_23:
operator delete(__p);
}
else
{
v10 = v14;
}
LABEL_24:
v2 = v27;
(*(void (__fastcall **)(unsigned __int8 *, __int64, __int64))(*(_QWORD *)v11 + 1392LL))(&v29, v11, v28);
if ( (v29 & 1) != 0 )
{
v16 = (const std::string::value_type *)__p;
v17 = v31;
}
else
{
v17 = v29 >> 1;
v16 = __s;
}
std::string::append(v2, v16, v17);
std::string::append(v2, ";");
if ( !*(_BYTE *)(v28 + 14018) )
*(_BYTE *)(v28 + 14018) = *(_BYTE *)(v11 + 1259);
if ( (v29 & 1) != 0 )
operator delete(__p);
goto LABEL_9;
}
}
operator delete(__p);
goto LABEL_15;
}
}
LABEL_31:
v18 = (void **)v24[0];
if ( v24[0] )
{
do
{
v21 = (void **)*v18;
if ( ((_BYTE)v18[2] & 1) != 0 )
operator delete(v18[4]);
operator delete(v18);
v18 = v21;
}
while ( v21 );
}
v19 = v23[0];
v23[0] = nullptr;
if ( v19 )
operator delete(v19);
return v2;
}