//
// LevelEditorLayer::doAutoSave from 0x10040b414 to 0x10040b6b8 (676 bytes)
//
// 1 xrefs:
// > LevelEditorLayer::checkAutoSave @ 0x1003ffcb0
//
// This function is hookable on this platform (idp: arm, 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 11:04:45 +0000
//
void __fastcall LevelEditorLayer::doAutoSave(__int64 a1)
{
__int64 v2; // x20
__n128 v3; // q0
__int64 v4; // x0
__int64 v5; // x21
std::string *v6; // x8
void *v7; // x0
char *CString; // x0
__int64 v9; // x19
std::string *v10; // x0
__int64 v11; // x0
std::string *v12; // x1
std::string::size_type size; // x2
std::string *v14; // x0
std::string::size_type v15; // x21
char v16; // w23
std::__thread_struct *v17; // x20
char *v18; // x0
__int64 v19; // x8
int v20; // w0
pthread_t v21; // [xsp+10h] [xbp-D0h] BYREF
std::string v22; // [xsp+18h] [xbp-C8h] BYREF
std::string v23; // [xsp+30h] [xbp-B0h] BYREF
void *v24[2]; // [xsp+48h] [xbp-98h] BYREF
__int64 v25; // [xsp+58h] [xbp-88h]
std::string __p; // [xsp+60h] [xbp-80h] BYREF
std::string __str; // [xsp+78h] [xbp-68h] BYREF
char *v28; // [xsp+90h] [xbp-50h] BYREF
_QWORD v29[2]; // [xsp+98h] [xbp-48h]
if ( (unsigned int)LevelEditorLayer::canAutoSave(a1) )
{
v2 = *(_QWORD *)(a1 + 1936);
sub_1003FE824(a1);
LevelEditorLayer::getLevelString(a1, &__str);
if ( !sub_1000045BC((_QWORD *)(a1 + 15064), &__str) )
{
std::string::operator=((std::string *)(a1 + 15064), &__str);
v4 = EditorSFXManager::sharedState(v3);
EditorSFXManager::playAction_1(v4, 225);
v5 = *(_QWORD *)(a1 + 14248);
if ( v5 )
{
sub_100009900(&__p, "Auto-Save.");
EditorUI::showTextAlert(v5, &__p, 0, 1, 0);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
}
LevelEditorLayer::prepareSaveData(v24, a1, &__str);
sub_1000A65B0(v2, (__int64)&v22);
if ( (v22.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v6 = &v22;
else
v6 = (std::string *)v22.__r_.__value_.__r.__words[0];
v7 = sub_1003065B0("autosave_%s.gdlvl", (const char *)v6);
CString = (char *)cocos2d::CCString::getCString((__int64)v7);
sub_100009900(&v23, CString);
if ( SHIBYTE(v22.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v22.__r_.__value_.__l.__data_);
v9 = LocalLevelManager::sharedState();
std::mutex::lock((std::mutex *)(v9 + 464));
v10 = (std::string *)LocalLevelManager::sharedState();
std::string::operator=(v10 + 22, &v23);
v11 = LocalLevelManager::sharedState();
atomic_store(1u, (unsigned __int8 *)(v11 + 601));
sub_10004EB10(v11);
if ( (v23.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v12 = &v23;
else
v12 = (std::string *)v23.__r_.__value_.__r.__words[0];
if ( (v23.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
size = HIBYTE(v23.__r_.__value_.__r.__words[2]);
else
size = v23.__r_.__value_.__l.__size_;
v14 = std::string::append(&v22, (const std::string::value_type *)v12, size);
v15 = v14->__r_.__value_.__r.__words[0];
v29[0] = v14->__r_.__value_.__l.__size_;
*(_QWORD *)((char *)v29 + 7) = *(std::string::size_type *)((char *)&v14->__r_.__value_.__r.__words[1] + 7);
v16 = HIBYTE(v14->__r_.__value_.__r.__words[2]);
v14->__r_.__value_.__l.__size_ = 0;
v14->__r_.__value_.__r.__words[2] = 0;
v14->__r_.__value_.__r.__words[0] = 0;
v17 = (std::__thread_struct *)operator new(8u);
std::__thread_struct::__thread_struct(v17);
v18 = (char *)operator new(0x38u);
*(_QWORD *)v18 = v17;
*(_OWORD *)(v18 + 8) = *(_OWORD *)v24;
v19 = v25;
v24[0] = nullptr;
v24[1] = nullptr;
v25 = 0;
*((_QWORD *)v18 + 3) = v19;
*((_QWORD *)v18 + 4) = v15;
*((_QWORD *)v18 + 5) = v29[0];
*(_QWORD *)(v18 + 47) = *(_QWORD *)((char *)v29 + 7);
v18[55] = v16;
v28 = v18;
v20 = pthread_create(&v21, nullptr, (void *(__cdecl *)(void *))sub_1004149FC, v18);
if ( v20 )
{
std::__throw_system_error(v20, "thread constructor failed");
__break(1u);
return;
}
v28 = nullptr;
sub_100414B30(&v28);
std::thread::detach((std::thread *)&v21);
std::thread::~thread((std::thread *)&v21);
if ( SHIBYTE(v22.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v22.__r_.__value_.__l.__data_);
std::mutex::unlock((std::mutex *)(v9 + 464));
if ( SHIBYTE(v23.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v23.__r_.__value_.__l.__data_);
if ( SHIBYTE(v25) < 0 )
operator delete(v24[0]);
}
if ( SHIBYTE(__str.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__str.__r_.__value_.__l.__data_);
}
}