//
// MusicDownloadManager::onDownloadSongCompleted from 0x10058f540 to 0x10058f7c1 (641 bytes)
//
// 2 xrefs:
// > MusicDownloadManager::downloadSong @ 0x10058f0ea
// > MusicDownloadManager::downloadCustomSong @ 0x10058f3ee
//
// 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::onDownloadSongCompleted(
MusicDownloadManager *a1,
cocos2d::extension::CCHttpClient *a2,
cocos2d::extension::CCHttpResponse *a3)
{
double v3; // xmm0_8
cocos2d::extension::CCHttpRequest *pHttpRequest; // rdi
const char *longStorage; // rdi
unsigned int v8; // r14d
cocos2d::CCString *v9; // rax
const char *CString; // rax
const char *data; // rdi
bool shouldCancel; // r15
int v13; // eax
unsigned int v14; // r15d
__int64 v15; // rax
FILE *v16; // rax
FILE *v17; // r12
SongInfoObject *SongInfoObject; // rax
int v19; // ecx
GameManager *v20; // rax
unsigned int v21; // r15d
__int64 v22; // rax
unsigned int v23; // r15d
__int64 v24; // rax
unsigned int v25; // r15d
__int64 v26; // rax
char v27; // [rsp+0h] [rbp-40h]
std::string v28; // [rsp+8h] [rbp-38h] BYREF
pHttpRequest = a3->_pHttpRequest;
if ( (pHttpRequest->_tag.m_data.m_short.sizex2 & 1) != 0 )
longStorage = pHttpRequest->_tag.m_data.m_long.longStorage;
else
longStorage = pHttpRequest->_tag.m_data.m_short.shortStorage.__elems_;
v8 = atoi(longStorage);
v9 = (cocos2d::CCString *)sub_1007AB580("d_%i", v27);
CString = cocos2d::CCString::getCString(v9);
MusicDownloadManager::removeDLFromActive(a1, CString);
if ( a3->_succeed )
{
MusicDownloadManager::pathForSong(&v28, v3, (__int64)a1, v8);
if ( (*(_BYTE *)&v28.__r_.__value_.__s.0 & 1) != 0 )
data = v28.__r_.__value_.__l.__data_;
else
data = v28.__r_.__value_.__s.__data_;
v16 = fopen(data, "wb");
v17 = v16;
if ( v16 )
{
fwrite(a3->_responseData.__begin_, 1u, a3->_responseData.__end_ - a3->_responseData.__begin_, v16);
fclose(v17);
SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v8);
if ( SongInfoObject )
{
v19 = a1->m_songPriority + 1;
a1->m_songPriority = v19;
SongInfoObject->m_priority = v19;
}
v20 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v20, "0018") )
MusicDownloadManager::limitDownloadedSongs(a1);
if ( (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) )
{
v21 = 0;
do
{
v22 = sub_1007200C0(a1->m_musicDownloadDelegates, v21);
(*(void (__fastcall **)(_QWORD, _QWORD))(**(_QWORD **)(v22 + 320) + 24LL))(*(_QWORD *)(v22 + 320), v8);
++v21;
}
while ( v21 < (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) );
}
}
else if ( (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) )
{
v25 = 0;
do
{
v26 = sub_1007200C0(a1->m_musicDownloadDelegates, v25);
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(**(_QWORD **)(v26 + 320) + 32LL))(
*(_QWORD *)(v26 + 320),
v8,
0);
++v25;
}
while ( v25 < (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) );
}
if ( (*(_BYTE *)&v28.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v28.__r_.__value_.__l.__data_);
}
else
{
shouldCancel = a3->_pHttpRequest->_shouldCancel;
v13 = sub_100720070(a1->m_musicDownloadDelegates);
if ( shouldCancel )
{
if ( v13 )
{
v14 = 0;
do
{
v15 = sub_1007200C0(a1->m_musicDownloadDelegates, v14);
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(**(_QWORD **)(v15 + 320) + 32LL))(
*(_QWORD *)(v15 + 320),
v8,
3);
++v14;
}
while ( v14 < (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) );
}
}
else if ( v13 )
{
v23 = 0;
do
{
v24 = sub_1007200C0(a1->m_musicDownloadDelegates, v23);
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(**(_QWORD **)(v24 + 320) + 32LL))(
*(_QWORD *)(v24 + 320),
v8,
0);
++v23;
}
while ( v23 < (unsigned int)sub_100720070(a1->m_musicDownloadDelegates) );
}
}
}