//
// MusicDownloadManager::onDownloadSongCompleted from 0x140484030 to 0x1404842dd (685 bytes)
//
// 3 xrefs:
// > MusicDownloadManager::downloadSong @ 0x140483ef9
// > MusicDownloadManager::downloadCustomSong @ 0x14048c600
// > ??> @ 0x140928a90
//
// 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=4
void __fastcall MusicDownloadManager::onDownloadSongCompleted(__int64 a1, __int64 a2, __int64 a3)
{
const char *Tag; // rax
unsigned int v6; // esi
cocos2d::CCString *v7; // rax
const char *CString; // rax
const char *v9; // rcx
FILE *v10; // rax
FILE *v11; // rbp
__int64 SongInfoObject; // rax
__int64 v13; // rcx
__int64 v14; // rax
int v15; // r14d
int v16; // ebp
cocos2d::CCArray *i; // rdi
__int64 v18; // r8
const char *v19; // rcx
unsigned int j; // edi
struct cocos2d::CCObject *v21; // rax
void *v22; // [rsp+20h] [rbp-68h]
void *v23; // [rsp+20h] [rbp-68h]
char *v24[4]; // [rsp+28h] [rbp-60h] BYREF
char *FileName[4]; // [rsp+48h] [rbp-40h] BYREF
Tag = cocos2d::extension::CCHttpRequest::getTag(*(cocos2d::extension::CCHttpRequest **)(a3 + 56));
v6 = atoi(Tag);
v7 = cocos2d::CCString::createWithFormat("d_%i", v6);
CString = cocos2d::CCString::getCString(v7);
MusicDownloadManager::removeDLFromActive(a1, CString);
if ( *(_BYTE *)(a3 + 64) )
{
MusicDownloadManager::pathForSong(a1, FileName, v6);
v9 = (const char *)FileName;
if ( FileName[3] > (char *)0xF )
v9 = FileName[0];
v10 = fopen(v9, "wb");
v11 = v10;
if ( v10 )
{
fwrite(*(const void **)(a3 + 72), 1u, *(_QWORD *)(a3 + 80) - *(_QWORD *)(a3 + 72), v10);
fclose(v11);
SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v6);
if ( SongInfoObject )
*(_DWORD *)(SongInfoObject + 476) = ++*(_DWORD *)(a1 + 360);
v13 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v22 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v13 = qword_14090BFD0;
}
if ( !GameManager::getGameVariable(v13, "0018") )
{
v14 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v23 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v14 = qword_14090BFD0;
}
v15 = *(_DWORD *)(v14 + 1164);
v16 = *(_DWORD *)(v14 + 1168);
for ( i = MusicDownloadManager::getDownloadedSongs(a1);
cocos2d::CCArray::count(i) > 0x32;
cocos2d::CCArray::removeLastObject(i, 1) )
{
v18 = *((unsigned int *)cocos2d::CCArray::lastObject(i) + 80);
if ( (_DWORD)v18 != v15 && (_DWORD)v18 != v16 )
{
MusicDownloadManager::pathForSong(a1, v24, v18);
v19 = (const char *)v24;
if ( v24[3] > (char *)0xF )
v19 = v24[0];
remove(v19);
sub_14003D310((__int64)v24);
}
}
}
for ( j = 0; j < cocos2d::CCArray::count(*(cocos2d::CCArray **)(a1 + 336)); ++j )
{
v21 = cocos2d::CCArray::objectAtIndex(*(cocos2d::CCArray **)(a1 + 336), j);
(*(void (__fastcall **)(_QWORD, _QWORD))(**((_QWORD **)v21 + 40) + 24LL))(*((_QWORD *)v21 + 40), v6);
}
}
else
{
MusicDownloadManager::downloadSongFailed(a1, v6, 0);
}
sub_14003D310((__int64)FileName);
}
else
{
MusicDownloadManager::downloadSongFailed(a1, v6, *(_BYTE *)(*(_QWORD *)(a3 + 56) + 204LL) != 0 ? 3 : 0);
}
}