//
// sub_1000D5190 from 0x1000d5190 to 0x1000d566a (1242 bytes)
//
// 1 xrefs:
// > sub_1000BD710 @ 0x1000bd857
//
// 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:55 +0000
//
__int64 __fastcall sub_1000D5190(__int64 a1, double a2)
{
__int64 v3; // r14
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rdi
__int64 v7; // rdi
unsigned int v8; // r12d
size_t v9; // r12
const void *v10; // rdi
std::string::size_type size; // r13
char v12; // r15
std::string::pointer data; // rsi
size_t v14; // rdx
__int64 v15; // rax
__int64 v16; // rdi
__int64 v17; // rax
const char *CString; // rbx
size_t v19; // rax
std::string::size_type v20; // r14
char *v21; // r15
size_t v22; // r12
std::mutex *v23; // rbx
std::string *v24; // rax
const std::string::value_type *v25; // rsi
std::string::size_type v26; // rdx
std::string *v27; // rax
std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0 v28; // r13
std::string::pointer v29; // r15
std::__thread_struct *v30; // r12
char *v31; // rax
__int64 v32; // rdx
int v33; // eax
char v35; // [rsp+0h] [rbp-E0h]
char v36; // [rsp+18h] [rbp-C8h] BYREF
_BYTE v37[23]; // [rsp+19h] [rbp-C7h] BYREF
__int128 v38; // [rsp+30h] [rbp-B0h] BYREF
void *v39; // [rsp+40h] [rbp-A0h]
std::string __str; // [rsp+50h] [rbp-90h] BYREF
pthread_t v41; // [rsp+68h] [rbp-78h] BYREF
std::string __dst; // [rsp+70h] [rbp-70h] BYREF
std::string v43; // [rsp+88h] [rbp-58h] BYREF
_QWORD v44[2]; // [rsp+A0h] [rbp-40h] BYREF
if ( (*(_BYTE *)(LocalLevelManager::sharedState(a2) + 601) & 1) != 0 )
return __stack_chk_guard;
v3 = *(_QWORD *)(a1 + 1936);
if ( *(_DWORD *)(v3 + 1140) != 2 || *(_DWORD *)(a1 + 1972) || *(_BYTE *)(a1 + 14808) )
return __stack_chk_guard;
v4 = *(_QWORD *)(a1 + 14248);
if ( v4 )
{
if ( *(_BYTE *)(v4 + 1513) || *(_BYTE *)(v4 + 1512) )
return __stack_chk_guard;
v5 = *(_QWORD *)(v4 + 760);
if ( v5 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64))(*(_QWORD *)v5 + 352LL))(v5) )
return __stack_chk_guard;
v4 = *(_QWORD *)(a1 + 14248);
}
v6 = *(_QWORD *)(v4 + 784);
if ( v6 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64))(*(_QWORD *)v6 + 352LL))(v6) )
return __stack_chk_guard;
v4 = *(_QWORD *)(a1 + 14248);
}
v7 = *(_QWORD *)(v4 + 792);
if ( v7 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64))(*(_QWORD *)v7 + 352LL))(v7) )
return __stack_chk_guard;
v4 = *(_QWORD *)(a1 + 14248);
}
if ( *(_DWORD *)(v4 + 704) != -1 )
return __stack_chk_guard;
v3 = *(_QWORD *)(a1 + 1936);
}
LevelEditorLayer::updateCustomSFXMappings((__int128 **)a1);
LevelEditorLayer::getLevelString(&__str, a1);
v8 = *(unsigned __int8 *)(a1 + 15064);
if ( (v8 & 1) != 0 )
{
v9 = *(_QWORD *)(a1 + 15072);
v10 = *(const void **)(a1 + 15080);
}
else
{
v9 = v8 >> 1;
v10 = (const void *)(a1 + 15065);
}
size = *(_BYTE *)&__str.__r_.__value_.__l.0 >> 1;
v12 = *(_BYTE *)&__str.__r_.__value_.__s.0 & 1;
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
size = __str.__r_.__value_.__l.__size_;
data = __str.__r_.__value_.__s.__data_;
if ( v12 )
data = __str.__r_.__value_.__l.__data_;
v14 = v9;
if ( size < v9 )
v14 = size;
if ( memcmp(v10, data, v14) || size != v9 )
{
std::string::operator=((std::string *)(a1 + 15064), &__str);
v15 = EditorSFXManager::sharedState(a1 + 15064);
EditorSFXManager::playAction_1(v15, 225);
v16 = *(_QWORD *)(a1 + 14248);
if ( v16 )
{
v36 = 20;
strcpy(v37, "Auto-Save.");
EditorUI::showTextAlert(v16, &v36, 0, 1, 0);
if ( (v36 & 1) != 0 )
operator delete(*(void **)&v37[15]);
}
sub_1000D62F0(&v38, a1, &__str);
sub_10053E630(&v43, v3);
v17 = sub_10088E820("autosave_%s.gdlvl", v35);
CString = (const char *)cocos2d::CCString::getCString(v17);
v19 = strlen(CString);
if ( v19 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v20 = v19;
if ( v19 >= 0x17 )
{
v22 = 26;
if ( (v19 | 7) != 0x17 )
v22 = (v19 | 7) + 1;
v21 = (char *)operator new(v22);
__dst.__r_.__value_.__r.__words[2] = (std::string::size_type)v21;
__dst.__r_.__value_.__r.__words[0] = v22 | 1;
__dst.__r_.__value_.__l.__size_ = v20;
}
else
{
__dst.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v19);
v21 = __dst.__r_.__value_.__s.__data_;
if ( !v19 )
{
LABEL_41:
v21[v20] = 0;
if ( (*(_BYTE *)&v43.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v43.__r_.__value_.__l.__data_);
v23 = (std::mutex *)(LocalLevelManager::sharedState(a2) + 464);
std::mutex::lock(v23);
v24 = (std::string *)LocalLevelManager::sharedState(a2);
std::string::operator=(v24 + 22, &__dst);
*(_BYTE *)(LocalLevelManager::sharedState(a2) + 601) = 1;
sub_1004F5360(&v43);
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
{
v25 = __dst.__r_.__value_.__l.__data_;
v26 = __dst.__r_.__value_.__l.__size_;
}
else
{
v25 = __dst.__r_.__value_.__s.__data_;
v26 = *(_BYTE *)&__dst.__r_.__value_.__l.0 >> 1;
}
v27 = std::string::append(&v43, v25, v26);
v28 = v27->__r_.__value_.__s.0;
*(_QWORD *)((char *)v44 + 7) = v27->__r_.__value_.__l.__size_;
v44[0] = *(std::string::size_type *)((char *)v27->__r_.__value_.__r.__words + 1);
v29 = v27->__r_.__value_.__l.__data_;
*(_OWORD *)&v27->__r_.__value_.__l.0 = 0;
v27->__r_.__value_.__r.__words[2] = 0;
v30 = (std::__thread_struct *)operator new(8u);
std::__thread_struct::__thread_struct(v30);
v31 = (char *)operator new(0x38u);
*(_QWORD *)v31 = v30;
*((_QWORD *)v31 + 3) = v39;
*(_OWORD *)(v31 + 8) = v38;
v38 = 0;
v39 = nullptr;
v31[32] = (char)v28;
v32 = *(_QWORD *)((char *)v44 + 7);
*(_QWORD *)(v31 + 33) = v44[0];
*((_QWORD *)v31 + 5) = v32;
*((_QWORD *)v31 + 6) = v29;
memset(v44, 0, 15);
v33 = pthread_create(&v41, nullptr, sub_1000E7B50, v31);
if ( v33 )
{
std::__throw_system_error(v33, "thread constructor failed");
BUG();
}
std::thread::detach((std::thread *)&v41);
std::thread::~thread((std::thread *)&v41);
if ( (*(_BYTE *)&v43.__r_.__value_.__s.0 & 1) != 0 )
{
operator delete(v43.__r_.__value_.__l.__data_);
std::mutex::unlock(v23);
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) == 0 )
{
LABEL_49:
if ( (v38 & 1) == 0 )
{
LABEL_51:
v12 = *(_BYTE *)&__str.__r_.__value_.__s.0 & 1;
goto LABEL_52;
}
LABEL_50:
operator delete(v39);
goto LABEL_51;
}
}
else
{
std::mutex::unlock(v23);
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_49;
}
operator delete(__dst.__r_.__value_.__l.__data_);
if ( (v38 & 1) == 0 )
goto LABEL_51;
goto LABEL_50;
}
}
memmove(v21, CString, v20);
goto LABEL_41;
}
LABEL_52:
if ( v12 )
operator delete(__str.__r_.__value_.__l.__data_);
return __stack_chk_guard;
}