//
// MusicDownloadManager::clearUnusedSongs from 0x14033e6a0 to 0x14033e995 (757 bytes)
//
// 4 xrefs:
// > GJAccountManager::backupAccount @ 0x140201b3d
// > GJSongBrowser::FLAlert_Clicked @ 0x1402b7bf1
// > LevelBrowserLayer::FLAlert_Clicked @ 0x1402cfc21
// > ??> @ 0x1406d5678
//
// 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
//
// Hidden C++ exception states: #wind=2
void MusicDownloadManager::clearUnusedSongs(MusicDownloadManager *a1)
{
__int64 v2; // rbx
cocos2d::CCDictionary *v3; // rsi
__int64 v4; // rbx
__int64 v5; // rbx
__int64 i; // rdi
__int64 v7; // rbx
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rbx
struct cocos2d::CCObject *v11; // rax
cocos2d::CCArray *m_localLevels; // rbp
unsigned int j; // edi
__int64 v14; // rcx
struct cocos2d::CCObject *v15; // rax
struct cocos2d::CCObject *v16; // rbx
__int64 v17; // rax
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // rbx
struct cocos2d::CCObject *v21; // rax
cocos2d::CCArray *v22; // rbp
cocos2d::CCDictionary *m_songObjects; // rdx
cocos2d::CCDictElement *m_pElements; // rdx
cocos2d::CCDictElement *k; // rbx
unsigned int m; // edi
struct cocos2d::CCObject *v27; // rbx
cocos2d::CCString *v28; // rax
const char *CString; // rax
size_t v30; // r8
void *v31; // rcx
void *v32; // [rsp+20h] [rbp-48h]
__int128 v33; // [rsp+28h] [rbp-40h] BYREF
__int64 v34; // [rsp+38h] [rbp-30h]
unsigned __int64 v35; // [rsp+40h] [rbp-28h]
v2 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v32 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v32);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v2 = qword_1406C2EC0;
}
v3 = (cocos2d::CCDictionary *)cocos2d::CCDictionary::create(a1);
v4 = *(_QWORD *)(v2 + 352);
if ( v4 )
{
v5 = *(_QWORD *)(v4 + 56);
if ( v5 )
{
for ( i = *(_QWORD *)(v5 + 288); ; i = *(_QWORD *)(i + 288) )
{
v7 = *(_QWORD *)(v5 + 264);
if ( !*(_BYTE *)(v7 + 1073)
&& *(int *)(v7 + 672) > 0
&& !cocos2d::CCDictionary::objectForKey(v3, *(int *)(v7 + 672)) )
{
v10 = *(int *)(v7 + 672);
v11 = (struct cocos2d::CCObject *)cocos2d::CCNode::create(v9, v8);
cocos2d::CCDictionary::setObject(v3, v11, v10);
}
v5 = i;
if ( !i )
break;
}
}
}
m_localLevels = LocalLevelManager::sharedState()->m_localLevels;
for ( j = 0; j < cocos2d::CCArray::count(m_localLevels); ++j )
{
v15 = cocos2d::CCArray::objectAtIndex(m_localLevels, j);
v16 = v15;
if ( !BYTE1(v15[19].m_uID) )
{
v17 = SLODWORD(v15[12].__vftable);
if ( (int)v17 > 0 && !cocos2d::CCDictionary::objectForKey(v3, v17) )
{
v20 = SLODWORD(v16[12].__vftable);
v21 = (struct cocos2d::CCObject *)cocos2d::CCNode::create(v19, v18);
cocos2d::CCDictionary::setObject(v3, v21, v20);
}
}
}
v22 = (cocos2d::CCArray *)cocos2d::CCArray::create(v14);
m_songObjects = a1->m_songObjects;
if ( m_songObjects )
{
m_pElements = m_songObjects->m_pElements;
if ( m_pElements )
{
for ( k = (cocos2d::CCDictElement *)m_pElements->hh.next; ; k = (cocos2d::CCDictElement *)k->hh.next )
{
cocos2d::CCArray::addObject(v22, m_pElements->m_pObject);
m_pElements = k;
if ( !k )
break;
}
}
}
for ( m = 0; m < cocos2d::CCArray::count(v22); ++m )
{
v27 = cocos2d::CCArray::objectAtIndex(v22, m);
if ( !MusicDownloadManager::isSongDownloaded(a1, v27[5].m_unknown2)
&& !cocos2d::CCDictionary::objectForKey(v3, v27[5].m_unknown2) )
{
v28 = cocos2d::CCString::createWithFormat("%i", v27[5].m_unknown2);
CString = cocos2d::CCString::getCString(v28);
v33 = 0;
v34 = 0;
v35 = 0;
v30 = -1;
do
++v30;
while ( CString[v30] );
sub_14003A930(&v33, CString, v30);
cocos2d::CCDictionary::removeObjectForKey(a1->m_songObjects, &v33);
if ( v35 > 0xF )
{
v31 = (void *)v33;
if ( v35 + 1 >= 0x1000 )
{
v31 = *(void **)(v33 - 8);
if ( (unsigned __int64)(v33 - (_QWORD)v31 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v31);
}
}
}
}