//
// MusicDownloadManager::limitDownloadedSongs from 0x10058e860 to 0x10058e9a0 (320 bytes)
//
// 1 xrefs:
// > MusicDownloadManager::onDownloadSongCompleted @ 0x10058f6a8
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
void __fastcall MusicDownloadManager::limitDownloadedSongs(MusicDownloadManager *a1)
{
__int64 v1; // rsi
int m_customMenuSongID; // r12d
__int64 v4; // r14
cocos2d::CCDictionary *m_songObjects; // rax
cocos2d::CCDictElement *m_pElements; // r13
cocos2d::CCObject *m_pObject; // r15
int v8; // r13d
int v9; // edx
const std::__fs::filesystem::path *data; // rdi
std::string v11; // [rsp+8h] [rbp-48h] BYREF
int m_customPracticeSongID; // [rsp+24h] [rbp-2Ch]
m_customMenuSongID = GameManager::sharedState()->m_customMenuSongID;
m_customPracticeSongID = GameManager::sharedState()->m_customPracticeSongID;
v4 = sub_10071F9E0(a1, v1);
m_songObjects = a1->m_songObjects;
if ( m_songObjects )
{
m_pElements = m_songObjects->m_pElements;
while ( m_pElements )
{
m_pObject = m_pElements->m_pObject;
m_pElements = (cocos2d::CCDictElement *)m_pElements->hh.next;
if ( MusicDownloadManager::isSongDownloaded(a1, m_pObject[5].m_uUnknown) )
sub_10071FCD0(v4, m_pObject);
}
}
if ( (unsigned int)sub_100720070(v4) >= 2 )
qsort(
*(void **)(*(_QWORD *)(v4 + 56) + 16LL),
**(unsigned int **)(v4 + 56),
8u,
(int (__cdecl *)(const void *, const void *))sub_1005895B0);
v8 = m_customPracticeSongID;
if ( (unsigned int)sub_100720070(v4) >= 0x33 )
{
do
{
v9 = *(_DWORD *)(sub_1007200E0(v4) + 316);
if ( v9 != m_customMenuSongID && 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, (std::error_code *)a1);
if ( (*(_BYTE *)&v11.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v11.__r_.__value_.__l.__data_);
}
sub_100720200(v4, 1);
}
while ( (unsigned int)sub_100720070(v4) > 0x32 );
}
}