//
// MusicDownloadManager::downloadSong from 0x14033ea20 to 0x14033ed13 (755 bytes)
//
// 5 xrefs:
// > CustomSongWidget::onDownload @ 0x1400cad64
// > CustomSongWidget::loadSongInfoFinished @ 0x1400cccfc
// > CustomSongWidget::loadSongInfoFinished @ 0x1400ccdb9
// > CustomSongWidget::processNextMultiAsset @ 0x1400cd3af
// > ??> @ 0x1406d5690
//
// 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=3
void MusicDownloadManager::downloadSong(MusicDownloadManager *a1, int a2)
{
cocos2d::CCString *v4; // rax
const char *CString; // r14
MusicDownloadManager *v6; // rax
SongInfoObject *SongInfoObject; // rax
size_t v8; // rbx
cocos2d::CCString *v9; // rax
char *v10; // rax
size_t v11; // r8
cocos2d::CCString *v12; // rax
const char *v13; // rax
cocos2d::extension::CCHttpRequest *v14; // rbx
void **v15; // rdx
cocos2d::CCString *v16; // rax
const char *v17; // rax
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
__int64 v21; // r9
cocos2d::extension::CCHttpClient *Instance; // rax
void *v23; // rcx
void *v24; // rcx
void *v25[2]; // [rsp+28h] [rbp-31h] BYREF
__int128 v26; // [rsp+38h] [rbp-21h]
__int128 v27; // [rsp+48h] [rbp-11h] BYREF
__int128 v28; // [rsp+58h] [rbp-1h]
void *Block[2]; // [rsp+68h] [rbp+Fh] BYREF
__int64 v30; // [rsp+78h] [rbp+1Fh]
unsigned __int64 v31; // [rsp+80h] [rbp+27h]
if ( a2 <= 10000000 )
{
v4 = cocos2d::CCString::createWithFormat("d_%i", a2);
CString = cocos2d::CCString::getCString(v4);
if ( !AchievementManager::getAchievementsWithID((__int64)a1, (__int64)CString) )
{
MusicDownloadManager::downloadSongStarted(a1, a2);
*(_OWORD *)v25 = 0;
*(_QWORD *)&v26 = 0;
*((_QWORD *)&v26 + 1) = 15;
LOBYTE(v25[0]) = 0;
v6 = MusicDownloadManager::sharedState();
SongInfoObject = MusicDownloadManager::getSongInfoObject(v6, a2);
if ( SongInfoObject )
{
sub_14003BDB0((__int64)&v27, (__int64)&SongInfoObject->m_songUrl);
*(_OWORD *)v25 = v27;
v26 = v28;
*(_QWORD *)&v28 = 0;
*((_QWORD *)&v28 + 1) = 15;
LOBYTE(v27) = 0;
sub_14003A830((__int64)&v27);
}
v8 = -1;
if ( !(_QWORD)v26 )
{
v9 = cocos2d::CCString::createWithFormat("https://www.newgrounds.com/audio/download/%i", a2);
v10 = (char *)cocos2d::CCString::getCString(v9);
v11 = -1;
do
++v11;
while ( v10[v11] );
sub_14003CCE0(v25, v10, v11);
}
v12 = cocos2d::CCString::createWithFormat("%i.mp3", a2);
v13 = cocos2d::CCString::getCString(v12);
*(_OWORD *)Block = 0;
v30 = 0;
v31 = 0;
do
++v8;
while ( v13[v8] );
sub_14003A930(Block, v13, v8);
v14 = (cocos2d::extension::CCHttpRequest *)operator new(0xE0u);
cocos2d::extension::CCHttpRequest::CCHttpRequest(v14);
v14->__vftable = (cocos2d::extension::CCHttpRequest_vtbl *)&cocos2d::extension::CCHttpRequest::`vftable';
*(_DWORD *)&v14->_shouldCancel = 120;
v15 = v25;
if ( *((_QWORD *)&v26 + 1) > 0xFu )
v15 = (void **)v25[0];
cocos2d::extension::CCHttpRequest::setUrl(v14, (const char *)v15);
v14->_requestType = kHttpGet;
v14->_pTarget = a1;
v14->_pSelector.ptr = (void (__cdecl *)(cocos2d::extension::CCHttpClient *, cocos2d::extension::CCHttpResponse *))MusicDownloadManager::onDownloadSongCompleted;
if ( a1 )
cocos2d::CCObject::retain(a1);
v16 = cocos2d::CCString::createWithFormat("%i", a2);
v17 = cocos2d::CCString::getCString(v16);
cocos2d::extension::CCHttpRequest::setTag(v14, v17);
Instance = (cocos2d::extension::CCHttpClient *)cocos2d::extension::CCHttpClient::getInstance(v19, v18, v20, v21);
cocos2d::extension::CCHttpClient::send(Instance, v14);
cocos2d::CCObject::release(v14);
MusicDownloadManager::addDLToActive(a1, CString, v14);
if ( v31 > 0xF )
{
v23 = Block[0];
if ( v31 + 1 >= 0x1000 )
{
v23 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v23 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v23);
}
if ( *((_QWORD *)&v26 + 1) > 0xFu )
{
v24 = v25[0];
if ( (unsigned __int64)(*((_QWORD *)&v26 + 1) + 1LL) >= 0x1000 )
{
v24 = *((void **)v25[0] - 1);
if ( (unsigned __int64)((char *)v25[0] - (char *)v24 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v24);
}
}
}
else
{
MusicDownloadManager::downloadCustomSong(a1, a2);
}
}