//
// LevelEditorLayer::doAutoSave from 0x472948 to 0x472bd8 (656 bytes)
//
// 1 xrefs:
// > LevelEditorLayer::checkAutoSave @ 0x4730d4
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:49:06 +0000
//
int __fastcall LevelEditorLayer::doAutoSave(LevelEditorLayer *this)
{
int result; // r0
unsigned __int8 *v3; // r0
EditorSFXManager *v4; // r0
int v5; // r10
char *v6; // r1
cocos2d::CCString *v7; // r0
const char *CString; // r10
size_t v9; // r0
LocalLevelManager *v10; // r0
std::mutex *v11; // r10
LocalLevelManager *v12; // r0
int v13; // r0
unsigned __int8 *v14; // r0
int v15; // r0
char *v16; // r1
size_t v17; // r2
std::__thread_struct **v18; // r0
std::__thread_struct *v19; // r1
char *v20; // r2
std::__thread_struct *v21; // r7
int v22; // r0
std::__thread_struct *v23; // r1
std::__thread_struct *v24; // r2
std::__thread_struct *v25; // r0
std::__thread_struct *v26; // r1
char *v27; // r2
std::__thread_struct **v28; // r5
std::__thread_struct *v29; // r1
std::__thread_struct *v30; // r2
std::__thread_struct *v31; // r1
char *v32; // r2
int v33; // r0
pthread_t v34; // [sp+Ch] [bp-60h] BYREF
unsigned __int8 v35[12]; // [sp+10h] [bp-5Ch] BYREF
int v36; // [sp+1Ch] [bp-50h] BYREF
std::__thread_struct *v37; // [sp+20h] [bp-4Ch]
std::__thread_struct *v38; // [sp+24h] [bp-48h]
int v39; // [sp+28h] [bp-44h] BYREF
size_t v40; // [sp+2Ch] [bp-40h]
char *v41; // [sp+30h] [bp-3Ch]
_DWORD v42[3]; // [sp+34h] [bp-38h] BYREF
std::__thread_struct *v43; // [sp+40h] [bp-2Ch] BYREF
std::__thread_struct *v44; // [sp+44h] [bp-28h]
char *v45; // [sp+48h] [bp-24h]
std::__thread_struct *v46; // [sp+4Ch] [bp-20h] BYREF
std::__thread_struct *v47; // [sp+50h] [bp-1Ch]
std::__thread_struct *v48; // [sp+54h] [bp-18h]
std::__thread_struct *v49; // [sp+58h] [bp-14h] BYREF
std::__thread_struct *v50; // [sp+5Ch] [bp-10h]
char *v51; // [sp+60h] [bp-Ch]
result = LevelEditorLayer::canAutoSave(this);
if ( result )
{
LevelEditorLayer::updateCustomSFXMappings((char **)this);
LevelEditorLayer::getLevelString((LevelEditorLayer *)v35, (int)this);
if ( !sub_45F9A6((unsigned __int8 *)this + 12348, v35) )
{
v3 = std::string::operator=((unsigned __int8 *)this + 12348, v35);
v4 = (EditorSFXManager *)EditorSFXManager::sharedState((EditorSFXManager *)v3);
EditorSFXManager::playAction(v4, 225);
v5 = *((_DWORD *)this + 2964);
if ( v5 )
{
v46 = nullptr;
v47 = nullptr;
v48 = nullptr;
std::string::__init((int *)&v46, "Auto-Save.", 0xAu);
EditorUI::showTextAlert(v5, (int)&v46, 0, 1, 0);
std::string::~string((int)&v46);
}
LevelEditorLayer::prepareSaveData((GJGameLevel *)&v36, (int)this, (char *)v35);
GJGameLevel::generateAutoSaveUID((GJGameLevel *)&v49);
if ( ((unsigned __int8)v49 & 1) != 0 )
v6 = v51;
else
v6 = (char *)&v49 + 1;
v7 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"autosave_%s.gdlvl",
v6,
(unsigned __int8)v49 << 31);
CString = (const char *)cocos2d::CCString::getCString(v7);
v39 = 0;
v40 = 0;
v41 = nullptr;
v9 = strlen(CString);
std::string::__init(&v39, CString, v9);
v10 = (LocalLevelManager *)std::string::~string((int)&v49);
v11 = (std::mutex *)(LocalLevelManager::sharedState(v10) + 336);
v12 = (LocalLevelManager *)std::mutex::lock(v11);
v13 = LocalLevelManager::sharedState(v12);
v14 = std::string::operator=((unsigned __int8 *)(v13 + 340), (unsigned __int8 *)&v39);
v15 = LocalLevelManager::sharedState((LocalLevelManager *)v14);
__dmb(0xFu);
*(_BYTE *)(v15 + 377) = 1;
__dmb(0xFu);
GameToolbox::getSaveDirectory((GameToolbox *)v42);
if ( (v39 & 1) != 0 )
{
v16 = v41;
v17 = v40;
}
else
{
v17 = (int)(unsigned __int8)v39 >> 1;
v16 = (char *)&v39 + 1;
}
v18 = (std::__thread_struct **)std::string::append(v42, v16, v17);
v19 = v18[1];
v20 = (char *)v18[2];
v43 = *v18;
v44 = v19;
v45 = v20;
*v18 = nullptr;
v18[1] = nullptr;
v18[2] = nullptr;
v21 = (std::__thread_struct *)operator new(4u);
std::__thread_struct::__thread_struct(v21);
v22 = v36;
v23 = v37;
v24 = v38;
v36 = 0;
v37 = nullptr;
v38 = nullptr;
v46 = (std::__thread_struct *)v22;
v47 = v23;
v48 = v24;
v25 = v43;
v26 = v44;
v27 = v45;
v43 = nullptr;
v44 = nullptr;
v45 = nullptr;
v49 = v25;
v50 = v26;
v51 = v27;
v28 = (std::__thread_struct **)operator new(0x1Cu);
*v28 = v21;
v29 = v47;
v30 = v48;
v28[1] = v46;
v28[2] = v29;
v28[3] = v30;
v46 = nullptr;
v31 = v50;
v32 = v51;
v47 = nullptr;
v48 = nullptr;
v28[4] = v49;
v28[5] = v31;
v28[6] = (std::__thread_struct *)v32;
v49 = nullptr;
v50 = nullptr;
v51 = nullptr;
std::string::~string((int)&v49);
std::string::~string((int)&v46);
v33 = pthread_create(&v34, nullptr, (void *(*)(void *))sub_46BA3C, v28);
if ( v33 )
std::__throw_system_error(v33, "thread constructor failed");
std::thread::detach((std::thread *)&v34);
std::thread::~thread((std::thread *)&v34);
std::string::~string((int)&v43);
std::string::~string((int)v42);
std::mutex::unlock(v11);
std::string::~string((int)&v39);
std::string::~string((int)&v36);
}
return std::string::~string((int)v35);
}
return result;
}