//
// MusicDownloadManager::onDownloadSongCompleted from 0x82fe84 to 0x830098 (532 bytes)
//
// 4 xrefs:
// > ??> @ 0x52080
// > MusicDownloadManager::downloadCustomSong @ 0x82bbfc
// > MusicDownloadManager::downloadSong @ 0x831da4
// > ??> @ 0x122aa58
//
// 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 MusicDownloadManager::onDownloadSongCompleted(
MusicDownloadManager *a1,
cocos2d::extension::CCHttpClient *a2,
cocos2d::extension::CCHttpResponse *a3)
{
int v5; // w22
const char *SongDownloadKey; // x0
GJSongError v7; // w2
FILE *v8; // x23
SongInfoObject *SongInfoObject; // x21
GameManager *v10; // x0
char *v11; // x2
char *v12; // x0
unsigned int *v13; // x2
int v14; // w1
unsigned int *v15; // x2
char *filename; // [xsp+50h] [xbp+50h] BYREF
v5 = atoi((const char *)a3->_pHttpRequest->_tag.m_data.m_data);
SongDownloadKey = MusicDownloadManager::getSongDownloadKey(a1, v5);
MusicDownloadManager::removeDLFromActive(a1, SongDownloadKey);
if ( !a3->_succeed )
{
if ( a3->_pHttpRequest->_shouldCancel )
v7 = DownloadCancelled;
else
v7 = 0;
MusicDownloadManager::downloadSongFailed(a1, v5, v7);
return;
}
MusicDownloadManager::pathForSong((__int64 *)&filename, a1, v5);
v8 = fopen(filename, "wb");
if ( !v8 )
{
MusicDownloadManager::downloadSongFailed(a1, v5, (GJSongError)0);
v11 = filename;
v12 = filename - 24;
if ( filename - 24 == (char *)&qword_124B6B0 )
return;
if ( &pthread_create )
{
v15 = (unsigned int *)(filename - 8);
do
v14 = __ldaxr(v15);
while ( __stlxr(v14 - 1, v15) );
LABEL_16:
if ( v14 <= 0 )
operator delete(v12);
return;
}
LABEL_23:
v14 = *((_DWORD *)v11 - 2);
*((_DWORD *)v11 - 2) = v14 - 1;
goto LABEL_16;
}
fwrite(a3->_responseData.m_start, 1u, a3->_responseData.m_finish - a3->_responseData.m_start, v8);
fclose(v8);
SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v5);
if ( SongInfoObject )
SongInfoObject->m_priority = MusicDownloadManager::getSongPriority(a1);
v10 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v10, "0018") )
MusicDownloadManager::limitDownloadedSongs(a1);
MusicDownloadManager::downloadSongFinished(a1, v5);
v11 = filename;
v12 = filename - 24;
if ( filename - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v13 = (unsigned int *)(filename - 8);
do
v14 = __ldaxr(v13);
while ( __stlxr(v14 - 1, v13) );
goto LABEL_16;
}
goto LABEL_23;
}
}