//
// MusicDownloadManager::limitDownloadedSongs from 0x10064e880 to 0x10064e9c0 (320 bytes)
//
// 1 xrefs:
// > MusicDownloadManager::onDownloadSongCompleted @ 0x10064f5c8
//
// This function is hookable on this platform (idp: pc, 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 12:34:48 +0000
//
__int64 __fastcall MusicDownloadManager::limitDownloadedSongs(std::error_code *__ec)
{
int v2; // r12d
__int64 v3; // r14
const std::error_category *cat; // rax
std::error_category_vtbl *v5; // r13
bool (__cdecl *equivalent_0)(const std::error_category *__hidden, const std::error_code *, int); // r15
__int64 result; // rax
int v8; // r13d
int v9; // edx
const std::__fs::filesystem::path *data; // rdi
std::string v11; // [rsp+8h] [rbp-48h] BYREF
int v12; // [rsp+24h] [rbp-2Ch]
v2 = *(_DWORD *)(GameManager::sharedState() + 1140);
v12 = *(_DWORD *)(GameManager::sharedState() + 1144);
v3 = sub_1007FE900(__ec);
cat = __ec[21].__cat_;
if ( cat )
{
v5 = cat[7].__vftable;
while ( v5 )
{
equivalent_0 = v5[4].equivalent_0;
v5 = (std::error_category_vtbl *)v5[5].~error_category_0;
if ( (unsigned __int8)MusicDownloadManager::isSongDownloaded((__int64)__ec, *((unsigned int *)equivalent_0 + 79)) )
sub_1007FEBF0(v3, equivalent_0);
}
}
if ( (unsigned int)sub_1007FEF90(v3) >= 2 )
qsort(
*(void **)(*(_QWORD *)(v3 + 56) + 16LL),
**(unsigned int **)(v3 + 56),
8u,
(int (__cdecl *)(const void *, const void *))sub_100649600);
result = sub_1007FEF90(v3);
v8 = v12;
if ( (unsigned int)result >= 0x33 )
{
do
{
v9 = *(_DWORD *)(sub_1007FF000(v3) + 316);
if ( v9 != v2 && v9 != v8 )
{
MusicDownloadManager::pathForSong(&v11);
data = (const std::__fs::filesystem::path *)((char *)&v11.__r_.__value_.__l.0 + 1);
if ( (*(_BYTE *)&v11.__r_.__value_.__s.0 & 1) != 0 )
data = (const std::__fs::filesystem::path *)v11.__r_.__value_.__l.__data_;
remove(data, __ec);
if ( (*(_BYTE *)&v11.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v11.__r_.__value_.__l.__data_);
}
sub_1007FF120(v3, 1);
result = sub_1007FEF90(v3);
}
while ( (unsigned int)result > 0x32 );
}
return result;
}