//
// MusicDownloadManager::downloadSong from 0x140483ce0 to 0x140484021 (833 bytes)
//
// 4 xrefs:
// > CustomSongWidget::startDownload @ 0x14016bb64
// > CustomSongWidget::loadSongInfoFinished @ 0x14016df97
// > CustomSongWidget::processNextMultiAsset @ 0x14016e6b3
// > ??> @ 0x140928a84
//
// 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::downloadSong(cocos2d::CCObject *a1, unsigned int a2)
{
cocos2d::CCString *v4; // rax
const char *CString; // r14
__int64 v6; // rcx
__int64 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
cocos2d::extension::CCHttpClient *Instance; // rax
void *v21; // rcx
void *v22; // rcx
void *v23; // [rsp+30h] [rbp-50h]
void *v24[2]; // [rsp+38h] [rbp-48h] BYREF
__int128 v25; // [rsp+48h] [rbp-38h]
void *Block[2]; // [rsp+58h] [rbp-28h] BYREF
__int128 v27; // [rsp+68h] [rbp-18h]
if ( (int)a2 <= 10000000 )
{
v4 = cocos2d::CCString::createWithFormat("d_%i", a2);
CString = cocos2d::CCString::getCString(v4);
if ( !AchievementManager::getAchievementsWithID((__int64)a1, (__int64)CString) )
{
MusicDownloadManager::downloadSongStarted((__int64)a1, a2);
*(_OWORD *)v24 = 0;
*(_QWORD *)&v25 = 0;
*((_QWORD *)&v25 + 1) = 15;
LOBYTE(v24[0]) = 0;
v6 = qword_14090C070;
if ( !qword_14090C070 )
{
v23 = operator new(0x3D0u);
qword_14090C070 = MusicDownloadManager::MusicDownloadManager((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090C070 + 72LL))(qword_14090C070);
v6 = qword_14090C070;
}
SongInfoObject = MusicDownloadManager::getSongInfoObject(v6, a2);
if ( SongInfoObject )
{
sub_14003F4F0((__int64)Block, SongInfoObject + 392);
*(_OWORD *)v24 = *(_OWORD *)Block;
v25 = v27;
*(_QWORD *)&v27 = 0;
*((_QWORD *)&v27 + 1) = 15;
LOBYTE(Block[0]) = 0;
sub_14003D310((__int64)Block);
}
v8 = -1;
if ( !(_QWORD)v25 )
{
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_1400405A0(v24, v10, v11);
}
v12 = cocos2d::CCString::createWithFormat("%i.mp3", a2);
v13 = cocos2d::CCString::getCString(v12);
*(_OWORD *)Block = 0;
v27 = 0u;
do
++v8;
while ( v13[v8] );
sub_14003D230(Block, v13, v8);
v14 = (cocos2d::extension::CCHttpRequest *)operator new(0xE0u);
cocos2d::extension::CCHttpRequest::CCHttpRequest(v14);
*(_QWORD *)v14 = &cocos2d::extension::CCHttpRequest::`vftable';
*((_DWORD *)v14 + 53) = 120;
v15 = v24;
if ( *((_QWORD *)&v25 + 1) > 0xFu )
v15 = (void **)v24[0];
cocos2d::extension::CCHttpRequest::setUrl(v14, (const char *)v15);
*((_DWORD *)v14 + 14) = 0;
*((_QWORD *)v14 + 19) = a1;
*((_QWORD *)v14 + 20) = MusicDownloadManager::onDownloadSongCompleted;
if ( a1 )
cocos2d::CCObject::retain(a1);
v16 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, a2);
v17 = cocos2d::CCString::getCString(v16);
cocos2d::extension::CCHttpRequest::setTag(v14, v17);
Instance = (cocos2d::extension::CCHttpClient *)cocos2d::extension::CCHttpClient::getInstance(v19, v18);
cocos2d::extension::CCHttpClient::send(Instance, v14);
cocos2d::CCObject::release(v14);
MusicDownloadManager::addDLToActive(a1, CString, v14);
if ( *((_QWORD *)&v27 + 1) > 0xFu )
{
v21 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v27 + 1) + 1LL) >= 0x1000 )
{
v21 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v21 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v21);
}
if ( *((_QWORD *)&v25 + 1) > 0xFu )
{
v22 = v24[0];
if ( (unsigned __int64)(*((_QWORD *)&v25 + 1) + 1LL) >= 0x1000 )
{
v22 = *((void **)v24[0] - 1);
if ( (unsigned __int64)((char *)v24[0] - (char *)v22 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v22);
}
}
}
else
{
MusicDownloadManager::downloadCustomSong();
}
}