//
// LocalLevelManager::exportLevelsToFile from 0x1002609dc to 0x100261024 (1608 bytes)
//
// 4 xrefs:
// > sub_100111434 @ 0x100111460
// > EditorUI::handleEditorAction @ 0x100163930
// > EditorPauseLayer::FLAlert_Clicked @ 0x100444c18
// > LevelBrowserLayer::onExportSelected @ 0x100497224
//
// 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:01:38 +0000
//
__int64 __fastcall LocalLevelManager::exportLevelsToFile(__int64 a1, __int64 a2)
{
__int64 v4; // x22
_QWORD *v6; // x0
__int64 v7; // x0
std::string *v8; // x0
void *v9; // x19
unsigned __int8 v10; // w22
void **p_p; // x0
const char *v12; // x0
DIR *v13; // x0
DIR *v14; // x22
dirent *i; // x8
_BOOL4 v16; // w0
_BOOL4 v17; // w24
std::error_code *v18; // x1
const std::__fs::filesystem::path *p_dst; // x0
__int64 v20; // x0
const std::string::value_type *v21; // x2
std::string::size_type v22; // x3
std::string *v23; // x0
std::string::size_type v24; // x19
char v25; // w22
__int64 v26; // x23
__int64 v27; // x28
std::string::size_type size; // x8
std::string::size_type v29; // x8
__int64 v30; // x0
const std::string::value_type *CString; // x0
const std::string::value_type *v32; // x2
std::string::size_type v33; // x3
std::string *v34; // x0
std::string::size_type v35; // x27
std::string::size_type v36; // x28
std::string::size_type v37; // x8
int j; // w28
std::string *v39; // x0
FILE *v40; // x0
std::string *v41; // x8
__int64 v42; // x0
const std::string::value_type *v43; // x0
std::string *v44; // x0
FILE *v45; // x28
__int128 *v46; // x0
size_t v47; // x2
__int64 v48; // [xsp+18h] [xbp-148h]
int v49; // [xsp+24h] [xbp-13Ch]
std::string v50; // [xsp+28h] [xbp-138h] BYREF
std::string v51; // [xsp+40h] [xbp-120h] BYREF
std::string v52; // [xsp+58h] [xbp-108h] BYREF
std::string __str; // [xsp+70h] [xbp-F0h] BYREF
void *__p; // [xsp+88h] [xbp-D8h] BYREF
_BYTE v55[15]; // [xsp+90h] [xbp-D0h]
unsigned __int8 v56; // [xsp+9Fh] [xbp-C1h]
std::string v57; // [xsp+A0h] [xbp-C0h] BYREF
_QWORD __a[2]; // [xsp+B8h] [xbp-A8h] BYREF
__int128 v59; // [xsp+C8h] [xbp-98h] BYREF
unsigned __int8 v60; // [xsp+DFh] [xbp-81h]
__int128 __dst; // [xsp+E0h] [xbp-80h] BYREF
__int64 v62; // [xsp+F0h] [xbp-70h]
if ( !a2 || !(unsigned int)sub_1002E757C(a2) )
return 0;
if ( *(int *)(a1 + 608) > 0 )
return 4294967294LL;
v49 = sub_1002E757C(a2);
sub_100009900(&__p, "");
v6 = sub_100009900(&__str, "");
v7 = cocos2d::CCFileUtils::sharedFileUtils(v6);
(*(void (__fastcall **)(std::string *__return_ptr))(*(_QWORD *)v7 + 144LL))(&v57);
v48 = a1;
v8 = std::string::append(&v57, "exports/");
v9 = (void *)v8->__r_.__value_.__r.__words[0];
*(_QWORD *)&__dst = v8->__r_.__value_.__l.__size_;
*(_QWORD *)((char *)&__dst + 7) = *(std::string::size_type *)((char *)&v8->__r_.__value_.__r.__words[1] + 7);
v10 = HIBYTE(v8->__r_.__value_.__r.__words[2]);
v8->__r_.__value_.__l.__size_ = 0;
v8->__r_.__value_.__r.__words[2] = 0;
v8->__r_.__value_.__r.__words[0] = 0;
if ( (char)v56 < 0 )
operator delete(__p);
__p = v9;
*(_QWORD *)v55 = __dst;
*(_QWORD *)&v55[7] = *(_QWORD *)((char *)&__dst + 7);
v56 = v10;
if ( SHIBYTE(v57.__r_.__value_.__r.__words[2]) < 0 )
{
operator delete(v57.__r_.__value_.__l.__data_);
v10 = v56;
v9 = __p;
}
if ( (v10 & 0x80u) == 0 )
p_p = &__p;
else
p_p = (void **)v9;
mkdir((const char *)p_p, 0x1EDu);
if ( (v56 & 0x80u) == 0 )
v12 = (const char *)&__p;
else
v12 = (const char *)__p;
v13 = opendir(v12);
v14 = v13;
if ( v13 )
{
for ( i = readdir(v13); i; i = readdir(v14) )
{
sub_100009900(&v57, i->d_name);
sub_100009900(&__dst, ".gdlvl");
v16 = sub_10004B4E0((__int64 **)&v57, &__dst);
v17 = v16;
if ( SHIBYTE(v62) < 0 )
{
operator delete((void *)__dst);
if ( v17 )
{
LABEL_23:
sub_10011E060((const void **)&__p, (const void **)&v57.__r_.__value_.__l.__data_, (__int64)&__dst);
if ( v62 >= 0 )
p_dst = (const std::__fs::filesystem::path *)&__dst;
else
p_dst = (const std::__fs::filesystem::path *)__dst;
remove(p_dst, v18);
if ( SHIBYTE(v62) < 0 )
operator delete((void *)__dst);
}
}
else if ( v16 )
{
goto LABEL_23;
}
if ( SHIBYTE(v57.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v57.__r_.__value_.__l.__data_);
}
closedir(v14);
}
sub_1001FA0FC((__int64 *)&__p);
if ( v49 == 1 )
{
v20 = sub_1002E75A0(a2, 0);
if ( *(char *)(v20 + 367) < 0 )
{
sub_1000097D0(&__dst, *(void **)(v20 + 344), *(_QWORD *)(v20 + 352));
}
else
{
__dst = *(_OWORD *)(v20 + 344);
v62 = *(_QWORD *)(v20 + 360);
}
sub_10026117C(&v57, &__dst);
if ( (v56 & 0x80u) == 0 )
v21 = (const std::string::value_type *)&__p;
else
v21 = (const std::string::value_type *)__p;
if ( (v56 & 0x80u) == 0 )
v22 = v56;
else
v22 = *(_QWORD *)v55;
v23 = std::string::insert(&v57, 0, v21, v22);
v24 = v23->__r_.__value_.__r.__words[0];
*(_QWORD *)&v59 = v23->__r_.__value_.__l.__size_;
*(_QWORD *)((char *)&v59 + 7) = *(std::string::size_type *)((char *)&v23->__r_.__value_.__r.__words[1] + 7);
v25 = HIBYTE(v23->__r_.__value_.__r.__words[2]);
v23->__r_.__value_.__l.__size_ = 0;
v23->__r_.__value_.__r.__words[2] = 0;
v23->__r_.__value_.__r.__words[0] = 0;
if ( SHIBYTE(__str.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__str.__r_.__value_.__l.__data_);
__str.__r_.__value_.__r.__words[0] = v24;
__str.__r_.__value_.__l.__size_ = v59;
*(std::string::size_type *)((char *)&__str.__r_.__value_.__r.__words[1] + 7) = *(_QWORD *)((char *)&v59 + 7);
*((_BYTE *)&__str.__r_.__value_.__s + 23) = v25;
if ( SHIBYTE(v57.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v57.__r_.__value_.__l.__data_);
if ( SHIBYTE(v62) < 0 )
operator delete((void *)__dst);
}
v4 = 0;
v26 = 0;
memset(&v57, 0, sizeof(v57));
while ( (unsigned int)v26 < (unsigned int)sub_1002E757C(a2) )
{
v27 = sub_1002E75A0(a2, v26);
sub_1000D470C(v27, &__dst);
cocos2d::ZipUtils::compressString(&v59, &__dst, 0, 0xFFFFFFFFLL, 11);
memset(&v52, 0, sizeof(v52));
if ( v49 != 1 )
goto LABEL_55;
size = HIBYTE(__str.__r_.__value_.__r.__words[2]);
if ( (__str.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) != 0LL )
size = __str.__r_.__value_.__l.__size_;
if ( size )
{
std::string::operator=(&v52, &__str);
}
else
{
LABEL_55:
if ( *(char *)(v27 + 367) < 0 )
sub_1000097D0(&v51, *(void **)(v27 + 344), *(_QWORD *)(v27 + 352));
else
v51 = *(std::string *)(v27 + 344);
v29 = HIBYTE(v51.__r_.__value_.__r.__words[2]);
if ( (v51.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) != 0LL )
v29 = v51.__r_.__value_.__l.__size_;
if ( !v29 )
{
v30 = sub_1003065B0("level_%i", v26);
CString = (const std::string::value_type *)cocos2d::CCString::getCString(v30);
std::string::assign(&v51, CString);
}
sub_10026117C(&v50, &v51);
if ( (v56 & 0x80u) == 0 )
v32 = (const std::string::value_type *)&__p;
else
v32 = (const std::string::value_type *)__p;
if ( (v56 & 0x80u) == 0 )
v33 = v56;
else
v33 = *(_QWORD *)v55;
v34 = std::string::insert(&v50, 0, v32, v33);
v35 = v34->__r_.__value_.__r.__words[0];
__a[0] = v34->__r_.__value_.__l.__size_;
*(_QWORD *)((char *)__a + 7) = *(std::string::size_type *)((char *)&v34->__r_.__value_.__r.__words[1] + 7);
v36 = HIBYTE(v34->__r_.__value_.__r.__words[2]);
v34->__r_.__value_.__r.__words[0] = 0;
v34->__r_.__value_.__l.__size_ = 0;
v34->__r_.__value_.__r.__words[2] = 0;
if ( SHIBYTE(v52.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v52.__r_.__value_.__l.__data_);
v52.__r_.__value_.__r.__words[0] = v35;
v52.__r_.__value_.__l.__size_ = __a[0];
*(std::string::size_type *)((char *)&v52.__r_.__value_.__r.__words[1] + 7) = *(_QWORD *)((char *)__a + 7);
*((_BYTE *)&v52.__r_.__value_.__s + 23) = v36;
if ( SHIBYTE(v50.__r_.__value_.__r.__words[2]) < 0 )
{
operator delete(v50.__r_.__value_.__l.__data_);
v36 = HIBYTE(v52.__r_.__value_.__r.__words[2]);
}
if ( (v36 & 0x80u) == 0LL )
v37 = v36;
else
v37 = v52.__r_.__value_.__l.__size_;
std::string::basic_string(&v50, &v52, 0, v37 - 6, (std::allocator *)__a);
for ( j = 2; ; ++j )
{
v39 = (v52.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL
? &v52
: (std::string *)v52.__r_.__value_.__r.__words[0];
v40 = fopen((const char *)v39, "r");
if ( !v40 )
break;
fclose(v40);
if ( (v50.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v41 = &v50;
else
v41 = (std::string *)v50.__r_.__value_.__r.__words[0];
v42 = sub_1003065B0("%s_%i.gdlvl", (const char *)v41, j);
v43 = (const std::string::value_type *)cocos2d::CCString::getCString(v42);
std::string::assign(&v52, v43);
}
if ( SHIBYTE(v50.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v50.__r_.__value_.__l.__data_);
if ( SHIBYTE(v51.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v51.__r_.__value_.__l.__data_);
}
if ( (v52.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v44 = &v52;
else
v44 = (std::string *)v52.__r_.__value_.__r.__words[0];
v45 = fopen((const char *)v44, "w");
if ( v45 )
{
if ( (v60 & 0x80u) == 0 )
v46 = &v59;
else
v46 = (__int128 *)v59;
if ( (v60 & 0x80u) == 0 )
v47 = v60;
else
v47 = *((_QWORD *)&v59 + 1);
fwrite(v46, 1u, v47, v45);
fclose(v45);
sub_100017C70((__int64)&v57);
v4 = (unsigned int)(v4 + 1);
}
if ( SHIBYTE(v52.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v52.__r_.__value_.__l.__data_);
if ( (char)v60 < 0 )
operator delete((void *)v59);
if ( SHIBYTE(v62) < 0 )
operator delete((void *)__dst);
v26 = (unsigned int)(v26 + 1);
}
if ( (int)v4 > 0 )
{
*(_DWORD *)(v48 + 608) = v4;
sub_1001F9DBC(&v57, v48 + 352);
v4 = 4294967294LL;
}
*(_QWORD *)&__dst = &v57;
sub_100018250((void ***)&__dst);
if ( SHIBYTE(__str.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__str.__r_.__value_.__l.__data_);
if ( (char)v56 < 0 )
operator delete(__p);
return v4;
}