//
// LocalLevelManager::tryRecoverAutoSaves from 0x543604 to 0x543cea (1766 bytes)
//
// 1 xrefs:
// > AppDelegate::applicationDidFinishLaunching @ 0x3f6fd0
//
// 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:52:21 +0000
//
int __fastcall LocalLevelManager::tryRecoverAutoSaves(LocalLevelManager *this)
{
int *i; // r6
unsigned __int8 *v3; // r5
_BOOL4 v4; // r7
int *v5; // r4
char *v6; // r0
_BOOL4 v7; // r7
_DWORD *v8; // r3
int v9; // r1
char *v10; // r2
int v11; // r2
unsigned int v12; // r1
_DWORD *v13; // r3
int v14; // r1
char *v15; // r2
unsigned __int8 *v16; // r11
unsigned __int8 *v17; // r4
int v18; // r5
bool v19; // nf
int *v20; // r5
int v21; // t1
int v22; // r2
int v23; // r3
const char *v24; // r1
int v25; // r3
cocos2d::CCString *v26; // r0
cocos2d::CCString *v27; // r0
cocos2d::CCString *v28; // r5
const char *CString; // r6
size_t v31; // r0
int v32; // r0
int v33; // r5
int v34; // r7
const char *v35; // r0
cocos2d::CCArray *v36; // r0
cocos2d::CCObject *v37; // r1
unsigned int v38; // r2
int v39; // r7
int v40; // s15
char *v41; // r1
int v42; // r3
bool v43; // cc
char *v44; // r3
int *j; // r0
char *v46; // r2
int *v47; // r7
int v48; // t1
int v49; // r8
int v50; // r3
int v51; // r3
unsigned int *v52; // r0
unsigned int v53; // r1
char *v54; // r2
int v55; // r0
int v56; // r1
char *v57; // r2
int *v58; // r0
int k; // r7
int v60; // r0
int v61; // r3
cocos2d::CCString *v62; // r0
char *v63; // r0
const char *v64; // r0
char *v65; // r1
int *v66; // r0
const char *v67; // r0
unsigned __int8 *v68; // [sp+0h] [bp-134h]
unsigned __int8 *v69; // [sp+Ch] [bp-128h]
int v70; // [sp+Ch] [bp-128h]
char *v71; // [sp+Ch] [bp-128h]
unsigned __int8 *v72; // [sp+10h] [bp-124h]
_BOOL4 v73; // [sp+14h] [bp-120h]
_BOOL4 v74; // [sp+14h] [bp-120h]
int *v75; // [sp+14h] [bp-120h]
unsigned __int8 v76[12]; // [sp+34h] [bp-100h] BYREF
unsigned __int8 *v77; // [sp+40h] [bp-F4h] BYREF
unsigned __int8 *v78; // [sp+44h] [bp-F0h]
int v79; // [sp+48h] [bp-ECh]
unsigned __int8 *v80; // [sp+4Ch] [bp-E8h] BYREF
_DWORD *v81; // [sp+50h] [bp-E4h]
unsigned int v82; // [sp+54h] [bp-E0h] BYREF
int v83; // [sp+58h] [bp-DCh] BYREF
int v84; // [sp+5Ch] [bp-D8h]
char *v85; // [sp+60h] [bp-D4h]
int v86[3]; // [sp+64h] [bp-D0h] BYREF
int v87[2]; // [sp+70h] [bp-C4h] BYREF
char *filename; // [sp+78h] [bp-BCh]
int v89[3]; // [sp+7Ch] [bp-B8h] BYREF
unsigned __int8 v90[12]; // [sp+88h] [bp-ACh] BYREF
int v91[3]; // [sp+94h] [bp-A0h] BYREF
int v92[3]; // [sp+A0h] [bp-94h] BYREF
int v93[3]; // [sp+ACh] [bp-88h] BYREF
unsigned int v94[3]; // [sp+B8h] [bp-7Ch] BYREF
int v95[3]; // [sp+C4h] [bp-70h] BYREF
int v96[3]; // [sp+D0h] [bp-64h] BYREF
int v97[3]; // [sp+DCh] [bp-58h] BYREF
int v98; // [sp+E8h] [bp-4Ch] BYREF
int v99; // [sp+ECh] [bp-48h]
char *v100; // [sp+F0h] [bp-44h]
unsigned int v101[2]; // [sp+F4h] [bp-40h] BYREF
char *v102; // [sp+FCh] [bp-38h]
int v103[3]; // [sp+100h] [bp-34h] BYREF
int v104; // [sp+10Ch] [bp-28h] BYREF
int v105; // [sp+110h] [bp-24h]
char *v106; // [sp+114h] [bp-20h]
_DWORD v107[2]; // [sp+118h] [bp-1Ch] BYREF
_DWORD *v108; // [sp+120h] [bp-14h]
i = (int *)v76;
GameToolbox::getSaveDirectory((GameToolbox *)v76);
v77 = nullptr;
v78 = nullptr;
v79 = 0;
v83 = 0;
v84 = 0;
v85 = nullptr;
std::string::__init(&v83, "autosave_", 9u);
GameToolbox::listFiles((int)v76, (int *)&v77, (unsigned __int8 *)&v83, nullptr);
std::string::~string((int)&v83);
v3 = v77;
v80 = nullptr;
v81 = nullptr;
v82 = 0;
v69 = v78;
while ( v3 != v69 )
{
memset(v86, 0, sizeof(v86));
std::string::__init(v86, ".gdlvl.tmp", 0xAu);
v4 = GameToolbox::stringEndsWith(v3, (unsigned __int8 *)v86);
std::string::~string((int)v86);
if ( v4 )
{
v5 = v87;
std::operator+(v87, v76, v3);
if ( (v87[0] & 1) != 0 )
v6 = filename;
else
v6 = (char *)v87 + 1;
remove(v6);
}
else
{
memset(v89, 0, sizeof(v89));
std::string::__init(v89, ".gdlvl", 6u);
v7 = GameToolbox::stringEndsWith(v3, (unsigned __int8 *)v89);
std::string::~string((int)v89);
if ( !v7 )
goto LABEL_24;
v5 = &v98;
std::operator+(&v98, v76, v3);
v8 = v81;
if ( (unsigned int)v81 >= v82 )
{
v11 = -1431655765 * (((char *)v81 - (char *)v80) >> 2);
if ( (unsigned int)(v11 + 1) > 0x15555555 )
sub_388638();
if ( (unsigned int)(-1431655765 * ((int)(v82 - (_DWORD)v80) >> 2)) > 0xAAAAAA9 )
{
v12 = 357913941;
}
else
{
v12 = 1431655766 * ((int)(v82 - (_DWORD)v80) >> 2);
if ( v12 < v11 + 1 )
v12 = v11 + 1;
}
std::__split_buffer::__split_buffer(v107, v12, v11, (int)&v82);
v13 = v108;
if ( v108 )
{
v14 = v99;
v15 = v100;
*v108 = v98;
v13[1] = v14;
v13[2] = v15;
v98 = 0;
v99 = 0;
v100 = nullptr;
}
v108 += 3;
std::vector::__swap_out_circular_buffer((int *)&v80, v107);
std::__split_buffer::~__split_buffer((int)v107);
}
else
{
if ( v81 )
{
v9 = v99;
v10 = v100;
*v81 = v98;
v8[1] = v9;
v8[2] = v10;
v98 = 0;
v99 = 0;
v100 = nullptr;
}
v81 += 3;
}
}
std::string::~string((int)v5);
LABEL_24:
v3 += 12;
}
v16 = v80;
v72 = (unsigned __int8 *)v81;
v70 = 0;
v17 = v80 + 1;
while ( v16 != v72 )
{
v18 = *(v17 - 1);
v19 = (v18 & 1) != 0;
if ( (v18 & 1) != 0 )
i = *(int **)(v17 + 7);
else
v18 >>= 1;
if ( v19 )
v18 = *(_DWORD *)(v17 + 3);
else
i = (int *)v17;
v20 = (int *)((char *)i + v18);
while ( v20 != i )
{
v21 = *((unsigned __int8 *)v20 - 1);
v20 = (int *)((char *)v20 - 1);
if ( memchr("/\\", v21, 2u) )
{
v22 = (char *)v20 - (char *)i;
goto LABEL_38;
}
}
v22 = -1;
LABEL_38:
std::string::basic_string(&v83, v16, v22 + 1, 0xFFFFFFFF);
if ( (v83 & 1) != 0 )
v23 = v84;
else
v23 = (int)(unsigned __int8)v83 >> 1;
std::string::basic_string(v86, (unsigned __int8 *)&v83, 9u, v23 - 15);
v25 = *(v17 - 1);
i = (int *)(v25 << 31);
if ( (v25 & 1) != 0 )
v26 = *(cocos2d::CCString **)(v17 + 7);
else
v26 = (cocos2d::CCString *)v17;
v27 = (cocos2d::CCString *)cocos2d::CCString::createWithContentsOfFile(v26, v24);
v28 = v27;
if ( !v27 || !*(_BYTE *)cocos2d::CCString::getCString(v27) )
{
if ( (*(v17 - 1) & 1) != 0 )
v67 = *(const char **)(v17 + 7);
else
v67 = (const char *)v17;
remove(v67);
goto LABEL_114;
}
CString = (const char *)cocos2d::CCString::getCString(v28);
v87[0] = 0;
v87[1] = 0;
filename = nullptr;
v31 = strlen(CString);
std::string::__init(v87, CString, v31);
i = v89;
cocos2d::ZipUtils::decompressString(v89, v87, 0, 11);
v32 = GJGameLevel::createFromFullSaveString((unsigned __int8 *)v89);
v33 = v32;
if ( !v32 )
{
LABEL_56:
if ( (*(v17 - 1) & 1) != 0 )
v35 = *(const char **)(v17 + 7);
else
v35 = (const char *)v17;
remove(v35);
std::string::~string((int)v89);
std::string::~string((int)v87);
LABEL_114:
std::string::~string((int)v86);
std::string::~string((int)&v83);
goto LABEL_115;
}
for ( i = nullptr; ; i = (int *)((char *)i + 1) )
{
if ( (unsigned int)i >= cocos2d::CCArray::count(*((cocos2d::CCArray **)this + 71)) )
goto LABEL_63;
v34 = cocos2d::CCArray::objectAtIndex(*((cocos2d::CCArray **)this + 71), (unsigned int)i);
GJGameLevel::generateAutoSaveUID((GJGameLevel *)v90, v34);
v73 = sub_542480(v90, (unsigned __int8 *)v86);
std::string::~string((int)v90);
if ( v73 )
break;
}
if ( !v34 )
{
LABEL_63:
std::string::basic_string(v95, v33 + 280);
if ( (v95[0] & 1) != 0 )
v39 = v95[1];
else
v39 = (int)LOBYTE(v95[0]) >> 1;
std::string::~string((int)v95);
if ( v39 )
{
i = v97;
std::string::basic_string(v97, v33 + 280);
sub_5430BC(v101, (unsigned __int8 *)v97);
std::string::operator=((unsigned __int8 *)(v33 + 280), (unsigned __int8 *)v101);
std::string::~string((int)v101);
}
else
{
i = v96;
memset(v96, 0, sizeof(v96));
std::string::__init(v96, "Recovered Autosave", 0x12u);
std::string::operator=((unsigned __int8 *)(v33 + 280), (unsigned __int8 *)v96);
}
std::string::~string((int)i);
v36 = *((cocos2d::CCArray **)this + 71);
v37 = (cocos2d::CCObject *)v33;
v38 = 0;
goto LABEL_61;
}
std::string::basic_string(v91, v34 + 304);
std::string::basic_string(v92, v33 + 304);
v74 = sub_542480((unsigned __int8 *)v91, (unsigned __int8 *)v92);
std::string::~string((int)v92);
std::string::~string((int)v91);
if ( v74 )
goto LABEL_56;
std::string::basic_string(v93, v34 + 280);
sub_5430BC(v94, (unsigned __int8 *)v93);
std::string::operator=((unsigned __int8 *)(v33 + 280), (unsigned __int8 *)v94);
std::string::~string((int)v94);
std::string::~string((int)v93);
v36 = *((cocos2d::CCArray **)this + 71);
v37 = (cocos2d::CCObject *)v33;
v38 = (unsigned int)i;
LABEL_61:
cocos2d::CCArray::insertObject(v36, v37, v38);
*(_DWORD *)(v33 + 952) = 2;
if ( (*(_BYTE *)(v33 + 1132) & 1) != 0 )
{
**(_BYTE **)(v33 + 1140) = 0;
*(_DWORD *)(v33 + 1136) = 0;
}
else
{
*(_BYTE *)(v33 + 1133) = 0;
*(_BYTE *)(v33 + 1132) = 0;
}
*(_BYTE *)(v33 + 608) = 0;
v40 = (int)(float)(vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0);
*(_DWORD *)(v33 + 604) = v40;
*(_DWORD *)(v33 + 600) = v40;
GJGameLevel::unverifyCoins((GJGameLevel *)v33);
*(_BYTE *)(v33 + 610) = 1;
std::string::basic_string(&v98, (int)v16);
if ( (v83 & 1) != 0 )
{
v41 = v85;
v42 = v84;
}
else
{
v42 = (int)(unsigned __int8)v83 >> 1;
v41 = (char *)&v83 + 1;
}
v43 = v42 <= 9;
if ( (unsigned int)v42 <= 9 )
goto LABEL_86;
v44 = &v41[v42];
if ( !v43 )
{
for ( j = (int *)v41; ; j = v47 )
{
v46 = (char *)j;
if ( j == (int *)(v44 - 9) )
break;
v47 = (int *)((char *)j + 1);
if ( *(_BYTE *)j == 95 )
{
v71 = "recovered";
v75 = (int *)((char *)j + 9);
do
{
i = v75;
if ( j == v75 )
goto LABEL_84;
v48 = *((unsigned __int8 *)j + 1);
j = (int *)((char *)j + 1);
i = (int *)(v71 + 1);
v49 = (unsigned __int8)*v71++;
}
while ( v48 == v49 );
}
}
}
v46 = v44;
LABEL_84:
if ( v46 == v44 || v46 - v41 == -1 )
{
LABEL_86:
v50 = *(v17 - 1);
if ( (v50 & 1) != 0 )
v51 = *(_DWORD *)(v17 + 3);
else
v51 = v50 >> 1;
v68 = v16;
std::string::basic_string(v103, v16, 0, v51 - 6);
v52 = std::string::append(v103, "_recovered", 0xAu);
i = (int *)v101;
v53 = v52[1];
v54 = (char *)v52[2];
v101[0] = *v52;
v101[1] = v53;
v102 = v54;
*v52 = 0;
v52[1] = 0;
v52[2] = 0;
std::string::~string((int)v103);
std::operator+((unsigned int *)&v104, (unsigned __int8 *)v101, ".gdlvl");
if ( (v98 & 1) != 0 )
{
*v100 = 0;
v99 = 0;
}
else
{
LOWORD(v98) = 0;
}
std::string::reserve(&v98, 0);
v55 = v104;
v56 = v105;
v57 = v106;
v104 = 0;
v105 = 0;
v106 = nullptr;
v98 = v55;
v99 = v56;
v100 = v57;
v58 = (int *)std::string::~string((int)&v104);
for ( k = 2; k != 100; ++k )
{
v60 = cocos2d::CCFileUtils::sharedFileUtils((cocos2d::CCFileUtils *)v58);
if ( !(*(int (__fastcall **)(int, int *))(*(_DWORD *)v60 + 80))(v60, &v98) )
break;
v61 = LOBYTE(v101[0]) << 31;
v62 = (cocos2d::CCString *)((v101[0] & 1) != 0
? cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%s%i.gdlvl",
v102,
k,
v61,
v68)
: cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%s%i.gdlvl",
(const char *)v101 + 1,
k,
v61,
v68));
v63 = (char *)cocos2d::CCString::getCString(v62);
v58 = std::string::assign(&v98, v63);
}
if ( (*(v17 - 1) & 1) != 0 )
v64 = *(const char **)(v17 + 7);
else
v64 = (const char *)v17;
if ( (v98 & 1) != 0 )
v65 = v100;
else
v65 = (char *)&v98 + 1;
if ( rename(v64, v65) )
std::string::operator=((unsigned __int8 *)&v98, v16);
std::string::~string((int)v101);
}
v66 = *((int **)this + 79);
if ( v66 == *((int **)this + 80) )
{
std::vector::__push_back_slow_path((int *)this + 78, (int)&v98);
}
else
{
if ( v66 )
std::string::basic_string(v66, (int)&v98);
*((_DWORD *)this + 79) += 12;
}
std::string::~string((int)&v98);
std::string::~string((int)v89);
std::string::~string((int)v87);
std::string::~string((int)v86);
std::string::~string((int)&v83);
v70 = 1;
LABEL_115:
v16 += 12;
v17 += 12;
}
std::__vector_base::~__vector_base((int)&v80);
std::__vector_base::~__vector_base((int)&v77);
std::string::~string((int)v76);
return v70;
}