//
// GameToolbox::listFiles from 0x3d0528 to 0x3d072e (518 bytes)
//
// 2 xrefs:
// > LocalLevelManager::tryRecoverAutoSaves @ 0x54364e
// > AutoBackupPopup::listBackups @ 0x73d95c
//
// 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:46:40 +0000
//
DIR *__fastcall GameToolbox::listFiles(int a1, int *a2, unsigned __int8 *a3, int *a4)
{
int v6; // r5
int v9; // r0
int v10; // r0
const char *v11; // r0
int v12; // r2
int v13; // r3
DIR *result; // r0
DIR *v15; // r11
struct dirent *v16; // r0
char *v17; // r6
size_t v18; // r0
int v19; // r3
size_t v20; // r3
int v21; // r2
unsigned int v22; // r2
void *v23; // r3
int v24; // r3
char *v25; // r1
size_t v26; // r2
char *v27; // r2
char *v28; // r0
int v29; // r0
_BOOL4 v30; // r6
int *v31; // r0
_BOOL4 *v32; // r3
unsigned int v33; // r2
_BOOL4 v34; // [sp+1Ch] [bp-90h] BYREF
int v35; // [sp+20h] [bp-8Ch] BYREF
size_t v36; // [sp+24h] [bp-88h]
char *v37; // [sp+28h] [bp-84h]
int v38; // [sp+2Ch] [bp-80h] BYREF
int v39; // [sp+30h] [bp-7Ch]
char *file; // [sp+34h] [bp-78h]
_BYTE v41[16]; // [sp+38h] [bp-74h] BYREF
int v42; // [sp+48h] [bp-64h]
_BOOL4 v43; // [sp+68h] [bp-44h]
v6 = *a2;
while ( 1 )
{
v9 = a2[1];
if ( v6 == v9 )
break;
v10 = v9 - 12;
a2[1] = v10;
std::string::~string(v10);
}
if ( a4 )
{
v12 = *a4;
while ( 1 )
{
v13 = a4[1];
if ( v12 == v13 )
break;
a4[1] = v13 - 4;
}
}
if ( (*(_BYTE *)a1 & 1) != 0 )
v11 = *(const char **)(a1 + 8);
else
v11 = (const char *)(a1 + 1);
result = opendir(v11);
v15 = result;
if ( result )
{
while ( 1 )
{
v16 = readdir(v15);
if ( !v16 )
return (DIR *)closedir(v15);
v17 = &v16->d_name[8];
v35 = 0;
v36 = 0;
v37 = nullptr;
v18 = strlen(&v16->d_name[8]);
std::string::__init(&v35, v17, v18);
v19 = (unsigned __int8)v35;
if ( (v35 & 1) != 0 )
{
if ( v36 != 1 )
goto LABEL_15;
}
else if ( (int)(unsigned __int8)v35 >> 1 != 1 )
{
goto LABEL_19;
}
if ( !std::string::compare((unsigned __int8 *)&v35, 0, 0xFFFFFFFF, ".", 1u) )
goto LABEL_22;
v19 = (unsigned __int8)v35;
if ( (v35 & 1) == 0 )
{
LABEL_19:
v20 = v19 >> 1;
goto LABEL_20;
}
LABEL_15:
v20 = v36;
LABEL_20:
if ( v20 == 2 && !std::string::compare((unsigned __int8 *)&v35, 0, 0xFFFFFFFF, "..", 2u) )
goto LABEL_22;
v21 = *a3;
if ( (v21 & 1) != 0 )
{
v22 = *((_DWORD *)a3 + 1);
if ( !v22 )
goto LABEL_30;
v23 = *((void **)a3 + 2);
}
else
{
v22 = v21 >> 1;
if ( !v22 )
goto LABEL_30;
v23 = a3 + 1;
}
if ( std::string::compare((unsigned __int8 *)&v35, 0, v22, v23, v22) )
goto LABEL_22;
LABEL_30:
std::string::basic_string(&v38, a1);
if ( (v38 & 1) != 0 )
{
v24 = v39;
if ( v39 )
{
v27 = file;
LABEL_37:
if ( v27[v24 - 1] != 47 )
std::string::push_back(&v38, 47);
}
}
else
{
v24 = (int)(unsigned __int8)v38 >> 1;
if ( v24 )
{
v27 = (char *)&v38 + 1;
goto LABEL_37;
}
}
if ( (v35 & 1) != 0 )
{
v25 = v37;
v26 = v36;
}
else
{
v26 = (int)(unsigned __int8)v35 >> 1;
v25 = (char *)&v35 + 1;
}
std::string::append(&v38, v25, v26);
if ( (v38 & 1) != 0 )
v28 = file;
else
v28 = (char *)&v38 + 1;
v29 = stat(v28, (struct stat *)v41);
v30 = v29 == 0;
if ( v29 || (v42 & 0xF000) != 0x4000 )
{
v31 = (int *)a2[1];
if ( v31 == (int *)a2[2] )
{
std::vector::__push_back_slow_path(a2, (int)&v35);
}
else
{
if ( v31 )
std::string::basic_string(v31, (int)&v35);
a2[1] += 12;
}
if ( a4 )
{
if ( v30 )
v30 = v43;
v32 = (_BOOL4 *)a4[1];
v33 = a4[2];
v34 = v30;
if ( (unsigned int)v32 >= v33 )
{
std::vector::__push_back_slow_path((int)a4, &v34);
}
else
{
if ( v32 )
*v32 = v30;
a4[1] += 4;
}
}
}
std::string::~string((int)&v38);
LABEL_22:
std::string::~string((int)&v35);
}
}
return result;
}