//
// LocalLevelManager::exportLevelsToFile from 0x543cf0 to 0x5441e4 (1268 bytes)
//
// 4 xrefs:
// > EditLevelLayer::onExportLevel @ 0x49fbf4
// > LevelBrowserLayer::onExportSelected @ 0x4a58d8
// > EditorPauseLayer::FLAlert_Clicked @ 0x509590
// > EditorUI::handleEditorAction @ 0x6f2658
//
// 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::exportLevelsToFile(LocalLevelManager *this, cocos2d::CCArray *a2)
{
int v4; // r5
cocos2d::CCFileUtils *v6; // r0
int v7; // r0
int *v8; // r3
int v9; // r1
char *v10; // r2
int v11; // r0
size_t v12; // r1
char *v13; // r2
char *v14; // r0
char *v15; // r0
DIR *v16; // r10
struct dirent *v17; // r0
size_t v18; // r0
_BOOL4 v19; // r5
const char *v20; // r0
int v21; // r0
char *v22; // r2
size_t v23; // r3
int *v24; // r3
int v25; // r1
char *v26; // r2
int v27; // r0
int v28; // r1
char *v29; // r2
const char *v30; // r4
int v31; // r8
int v32; // r3
char *v33; // r0
FILE *v34; // r8
char *v35; // r0
size_t v36; // r2
int v37; // r3
cocos2d::CCString *v38; // r0
char *CString; // r0
char *v40; // r2
size_t v41; // r3
int *v42; // r3
int v43; // r1
char *v44; // r2
int v45; // r0
int v46; // r1
char *v47; // r2
int v48; // r3
int i; // r10
const char *v50; // r0
FILE *v51; // r0
cocos2d::CCString *v52; // r0
char *v53; // r0
_BOOL4 v54; // [sp+Ch] [bp-A0h]
cocos2d::CCString *v55; // [sp+18h] [bp-94h]
int v56; // [sp+2Ch] [bp-80h] BYREF
size_t v57; // [sp+30h] [bp-7Ch]
char *path; // [sp+34h] [bp-78h]
int v59; // [sp+38h] [bp-74h] BYREF
int v60; // [sp+3Ch] [bp-70h]
char *v61; // [sp+40h] [bp-6Ch]
_DWORD v62[3]; // [sp+44h] [bp-68h] BYREF
int v63; // [sp+50h] [bp-5Ch] BYREF
int *v64; // [sp+54h] [bp-58h]
int *v65; // [sp+58h] [bp-54h]
int v66[3]; // [sp+5Ch] [bp-50h] BYREF
unsigned int v67[3]; // [sp+68h] [bp-44h] BYREF
unsigned int v68[3]; // [sp+74h] [bp-38h] BYREF
int v69; // [sp+80h] [bp-2Ch] BYREF
int v70; // [sp+84h] [bp-28h]
char *v71; // [sp+88h] [bp-24h]
int v72[3]; // [sp+8Ch] [bp-20h] BYREF
int v73; // [sp+98h] [bp-14h] BYREF
int v74; // [sp+9Ch] [bp-10h]
char *v75; // [sp+A0h] [bp-Ch]
if ( !a2 || !cocos2d::CCArray::count(a2) )
return 0;
if ( *((int *)this + 96) > 0 )
return -2;
v56 = 0;
v57 = 0;
path = nullptr;
v54 = cocos2d::CCArray::count(a2) == 1;
std::string::__init(&v56, &unk_B6B226, 0);
v59 = 0;
v60 = 0;
v61 = nullptr;
v6 = (cocos2d::CCFileUtils *)std::string::__init(&v59, &unk_B6B226, 0);
v7 = cocos2d::CCFileUtils::sharedFileUtils(v6);
(*(void (__fastcall **)(_DWORD *, int))(*(_DWORD *)v7 + 72))(v62, v7);
v8 = std::string::append(v62, "exports/", 8u);
v9 = v8[1];
v10 = (char *)v8[2];
v73 = *v8;
v74 = v9;
v75 = v10;
*v8 = 0;
v8[1] = 0;
v8[2] = 0;
if ( (v56 & 1) != 0 )
{
*path = 0;
v57 = 0;
}
else
{
LOWORD(v56) = 0;
}
std::string::reserve(&v56, 0);
v11 = v73;
v12 = v74;
v13 = v75;
v73 = 0;
v74 = 0;
v75 = nullptr;
v56 = v11;
v57 = v12;
path = v13;
std::string::~string((int)&v73);
std::string::~string((int)v62);
if ( (v56 & 1) != 0 )
v14 = path;
else
v14 = (char *)&v56 + 1;
mkdir(v14, 0x1EDu);
if ( (v56 & 1) != 0 )
v15 = path;
else
v15 = (char *)&v56 + 1;
v16 = opendir(v15);
if ( v16 )
{
while ( 1 )
{
v17 = readdir(v16);
if ( !v17 )
break;
v55 = (cocos2d::CCString *)&v17->d_name[8];
v69 = 0;
v70 = 0;
v71 = nullptr;
v18 = strlen(&v17->d_name[8]);
std::string::__init(&v69, v55, v18);
v73 = 0;
v74 = 0;
v75 = nullptr;
std::string::__init(&v73, ".gdlvl", 6u);
v19 = GameToolbox::stringEndsWith((unsigned __int8 *)&v69, (unsigned __int8 *)&v73);
std::string::~string((int)&v73);
if ( v19 )
{
std::operator+(v72, (unsigned __int8 *)&v56, (unsigned __int8 *)&v69);
if ( (v72[0] & 1) != 0 )
v20 = (const char *)v72[2];
else
v20 = (char *)v72 + 1;
remove(v20);
std::string::~string((int)v72);
}
std::string::~string((int)&v69);
}
closedir(v16);
}
if ( v54 )
{
v21 = cocos2d::CCArray::objectAtIndex(a2, 0);
std::string::basic_string(v66, v21 + 280);
sub_54328C(v67, (int)v66);
if ( (v56 & 1) != 0 )
{
v22 = path;
v23 = v57;
}
else
{
v23 = (int)(unsigned __int8)v56 >> 1;
v22 = (char *)&v56 + 1;
}
v24 = std::string::insert(v67, 0, v22, v23);
v25 = v24[1];
v26 = (char *)v24[2];
v73 = *v24;
v74 = v25;
v75 = v26;
*v24 = 0;
v24[1] = 0;
v24[2] = 0;
if ( (v59 & 1) != 0 )
{
*v61 = 0;
v60 = 0;
}
else
{
LOWORD(v59) = 0;
}
std::string::reserve(&v59, 0);
v27 = v73;
v28 = v74;
v29 = v75;
v73 = 0;
v74 = 0;
v75 = nullptr;
v59 = v27;
v60 = v28;
v61 = v29;
std::string::~string((int)&v73);
std::string::~string((int)v67);
std::string::~string((int)v66);
}
v30 = nullptr;
v4 = 0;
v63 = 0;
v64 = nullptr;
v65 = nullptr;
while ( (unsigned int)v30 < cocos2d::CCArray::count(a2) )
{
v31 = cocos2d::CCArray::objectAtIndex(a2, (unsigned int)v30);
GJGameLevel::getExportSaveString((GJGameLevel *)v66, v31);
cocos2d::ZipUtils::compressString(v67, v66, 0, -1, 11);
v69 = 0;
v70 = 0;
v71 = nullptr;
if ( v54 && ((v59 & 1) != 0 ? (v32 = v60) : (v32 = (int)(unsigned __int8)v59 >> 1), v32) )
{
std::string::operator=((unsigned __int8 *)&v69, (unsigned __int8 *)&v59);
}
else
{
std::string::basic_string(v72, v31 + 280);
if ( (v72[0] & 1) != 0 )
v37 = v72[1];
else
v37 = (int)LOBYTE(v72[0]) >> 1;
if ( !v37 )
{
v38 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"level_%i", v30);
CString = (char *)cocos2d::CCString::getCString(v38);
std::string::assign(v72, CString);
}
sub_54328C(v68, (int)v72);
if ( (v56 & 1) != 0 )
{
v40 = path;
v41 = v57;
}
else
{
v41 = (int)(unsigned __int8)v56 >> 1;
v40 = (char *)&v56 + 1;
}
v42 = std::string::insert(v68, 0, v40, v41);
v43 = v42[1];
v44 = (char *)v42[2];
v73 = *v42;
v74 = v43;
v75 = v44;
*v42 = 0;
v42[1] = 0;
v42[2] = 0;
if ( (v69 & 1) != 0 )
{
*v71 = 0;
v70 = 0;
}
else
{
LOWORD(v69) = 0;
}
std::string::reserve(&v69, 0);
v45 = v73;
v46 = v74;
v47 = v75;
v73 = 0;
v74 = 0;
v75 = nullptr;
v69 = v45;
v70 = v46;
v71 = v47;
std::string::~string((int)&v73);
std::string::~string((int)v68);
if ( (v69 & 1) != 0 )
v48 = v70;
else
v48 = (int)(unsigned __int8)v69 >> 1;
std::string::basic_string(&v73, (unsigned __int8 *)&v69, 0, v48 - 6);
for ( i = 2; ; ++i )
{
v50 = (v69 & 1) != 0 ? v71 : (char *)&v69 + 1;
v51 = fopen(v50, (const char *)&a1i2r3e45s789g[3]);
if ( !v51 )
break;
fclose(v51);
if ( (v73 & 1) != 0 )
v52 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%s_%i.gdlvl", v75, i);
else
v52 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%s_%i.gdlvl",
(const char *)&v73 + 1,
i);
v53 = (char *)cocos2d::CCString::getCString(v52);
std::string::assign(&v69, v53);
}
std::string::~string((int)&v73);
std::string::~string((int)v72);
}
if ( (v69 & 1) != 0 )
v33 = v71;
else
v33 = (char *)&v69 + 1;
v34 = fopen(v33, "w");
if ( v34 )
{
if ( (v67[0] & 1) != 0 )
{
v35 = (char *)v67[2];
v36 = v67[1];
}
else
{
v36 = (int)LOBYTE(v67[0]) >> 1;
v35 = (char *)v67 + 1;
}
fwrite(v35, 1u, v36, v34);
fclose(v34);
++v4;
if ( v64 == v65 )
{
std::vector::__push_back_slow_path(&v63, (int)&v69);
}
else
{
if ( v64 )
std::string::basic_string(v64, (int)&v69);
v64 += 3;
}
}
++v30;
std::string::~string((int)&v69);
std::string::~string((int)v67);
std::string::~string((int)v66);
}
if ( v4 )
{
*((_DWORD *)this + 96) = v4;
PlatformToolbox::shareFiles(&v63);
v4 = -2;
}
std::__vector_base::~__vector_base((int)&v63);
std::string::~string((int)&v59);
std::string::~string((int)&v56);
return v4;
}