//
// MusicDownloadManager::clearUnusedSongs from 0x140483950 to 0x140483c54 (772 bytes)
//
// 4 xrefs:
// > GJAccountManager::backupAccount @ 0x1403076f1
// > GJSongBrowser::FLAlert_Clicked @ 0x1403be204
// > LevelBrowserLayer::FLAlert_Clicked @ 0x1403ea9f9
// > ??> @ 0x140928a6c
//
// 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 11:32:46 +0000
//
// Hidden C++ exception states: #wind=2
unsigned int __fastcall MusicDownloadManager::clearUnusedSongs(__int64 a1)
{
__int64 v2; // rbx
cocos2d::CCDictionary *v3; // rbp
__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 *v12; // rsi
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; // rsi
__int64 v23; // rdx
__int64 v24; // rdx
__int64 k; // rbx
unsigned int v26; // edi
unsigned int result; // eax
struct cocos2d::CCObject *v28; // rbx
cocos2d::CCString *v29; // rax
const char *CString; // rax
size_t v31; // r8
void *v32; // rcx
void *v33; // [rsp+30h] [rbp-48h]
__int128 v34; // [rsp+38h] [rbp-40h] BYREF
__int64 v35; // [rsp+48h] [rbp-30h]
unsigned __int64 v36; // [rsp+50h] [rbp-28h]
v2 = *(_QWORD *)&qword_14090BFB0;
if ( !*(_QWORD *)&qword_14090BFB0 )
{
v33 = operator new(0x690u);
*(_QWORD *)&qword_14090BFB0 = GameLevelManager::GameLevelManager((__int64)v33);
(*(void (__fastcall **)(_QWORD))(**(_QWORD **)&qword_14090BFB0 + 72LL))(*(_QWORD *)&qword_14090BFB0);
v2 = *(_QWORD *)&qword_14090BFB0;
}
v3 = (cocos2d::CCDictionary *)cocos2d::CCDictionary::create(a1);
v4 = *(_QWORD *)(v2 + 856);
if ( v4 )
{
v5 = *(_QWORD *)(v4 + 56);
if ( v5 )
{
for ( i = *(_QWORD *)(v5 + 288); ; i = *(_QWORD *)(i + 288) )
{
v7 = *(_QWORD *)(v5 + 264);
if ( !*(_BYTE *)(v7 + 1185)
&& *(int *)(v7 + 680) > 0
&& !cocos2d::CCDictionary::objectForKey(v3, *(int *)(v7 + 680)) )
{
v10 = *(int *)(v7 + 680);
v11 = (struct cocos2d::CCObject *)cocos2d::CCNode::create(v9, v8);
cocos2d::CCDictionary::setObject(v3, v11, v10);
}
v5 = i;
if ( !i )
break;
}
}
}
v12 = *(cocos2d::CCArray **)(LocalLevelManager::sharedState() + 368);
for ( j = 0; j < cocos2d::CCArray::count(v12); ++j )
{
v15 = cocos2d::CCArray::objectAtIndex(v12, j);
v16 = v15;
if ( !*((_BYTE *)v15 + 1185) )
{
v17 = *((int *)v15 + 170);
if ( (int)v17 > 0 && !cocos2d::CCDictionary::objectForKey(v3, v17) )
{
v20 = *((int *)v16 + 170);
v21 = (struct cocos2d::CCObject *)cocos2d::CCNode::create(v19, v18);
cocos2d::CCDictionary::setObject(v3, v21, v20);
}
}
}
v22 = (cocos2d::CCArray *)cocos2d::CCArray::create(v14);
v23 = *(_QWORD *)(a1 + 344);
if ( v23 )
{
v24 = *(_QWORD *)(v23 + 56);
if ( v24 )
{
for ( k = *(_QWORD *)(v24 + 288); ; k = *(_QWORD *)(k + 288) )
{
cocos2d::CCArray::addObject(v22, *(struct cocos2d::CCObject **)(v24 + 264));
v24 = k;
if ( !k )
break;
}
}
}
v26 = 0;
result = cocos2d::CCArray::count(v22);
if ( result )
{
do
{
v28 = cocos2d::CCArray::objectAtIndex(v22, v26);
if ( !(unsigned __int8)MusicDownloadManager::isSongDownloaded(a1, *((unsigned int *)v28 + 80))
&& !cocos2d::CCDictionary::objectForKey(v3, *((int *)v28 + 80)) )
{
v29 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, *((unsigned int *)v28 + 80));
CString = cocos2d::CCString::getCString(v29);
v34 = 0;
v35 = 0;
v36 = 0;
v31 = -1;
do
++v31;
while ( CString[v31] );
sub_14003D230(&v34, CString, v31);
cocos2d::CCDictionary::removeObjectForKey(*(_QWORD *)(a1 + 344), &v34);
if ( v36 > 0xF )
{
v32 = (void *)v34;
if ( v36 + 1 >= 0x1000 )
{
v32 = *(void **)(v34 - 8);
if ( (unsigned __int64)(v34 - (_QWORD)v32 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v32);
}
}
++v26;
result = cocos2d::CCArray::count(v22);
}
while ( v26 < result );
}
return result;
}