//
// MusicDownloadManager::downloadSong from 0x10064ed20 to 0x10064f0ad (909 bytes)
//
// 5 xrefs:
// > CustomSongWidget::onDownload @ 0x1006f87e7
// > CustomSongWidget::startDownload @ 0x1006fb6f5
// > CustomSongWidget::loadSongInfoFinished @ 0x1006fcafa
// > CustomSongWidget::loadSongInfoFinished @ 0x1006fcc2c
// > CustomSongWidget::processNextMultiAsset @ 0x1006fda48
//
// 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 12:34:48 +0000
//
void __fastcall MusicDownloadManager::downloadSong(__int64 a1, int a2)
{
__int64 v3; // rax
const char *CString; // r14
unsigned int v5; // r12d
__int64 v6; // rdi
__int64 v7; // rax
__int64 SongInfoObject; // rax
__int64 v9; // rax
__int64 v10; // rax
const std::string::value_type *v11; // rax
__int64 v12; // rax
size_t v13; // rax
size_t v14; // r13
char *v15; // r14
const char *v16; // rsi
size_t v17; // r12
char *v18; // r12
const std::string::value_type *data; // rsi
__int64 v20; // rax
const std::string::value_type *v21; // rax
__int64 Instance; // rax
char v23; // [rsp+0h] [rbp-70h]
char v24; // [rsp+0h] [rbp-70h]
char v25; // [rsp+0h] [rbp-70h]
__int64 v26; // [rsp+0h] [rbp-70h]
const char *__src; // [rsp+8h] [rbp-68h]
__int128 __dst; // [rsp+10h] [rbp-60h] BYREF
void *__p; // [rsp+20h] [rbp-50h]
std::string v30; // [rsp+30h] [rbp-40h] BYREF
if ( a2 >= 10000001 )
{
MusicDownloadManager::downloadCustomSong(a1, (unsigned int)a2);
return;
}
v3 = sub_10088E820("d_%i", v23);
CString = (const char *)cocos2d::CCString::getCString(v3);
if ( !MusicDownloadManager::getDLObject(a1, CString) )
{
v24 = (char)CString;
if ( (unsigned int)sub_1007FEF90(*(_QWORD *)(a1 + 336)) )
{
v5 = 0;
do
{
v6 = *(_QWORD *)(sub_1007FEFE0(*(_QWORD *)(a1 + 336), v5) + 320);
if ( v6 )
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v6 + 16LL))(v6, (unsigned int)a2);
++v5;
}
while ( v5 < (unsigned int)sub_1007FEF90(*(_QWORD *)(a1 + 336)) );
}
*(_WORD *)&v30.__r_.__value_.__l.0 = 0;
v7 = MusicDownloadManager::sharedState();
SongInfoObject = MusicDownloadManager::getSongInfoObject(v7, a2);
if ( SongInfoObject )
{
if ( (*(_BYTE *)(SongInfoObject + 368) & 1) != 0 )
{
sub_10001AD30(&__dst, *(const void **)(SongInfoObject + 384), *(_QWORD *)(SongInfoObject + 376));
}
else
{
v9 = SongInfoObject + 368;
__p = *(void **)(v9 + 16);
__dst = *(_OWORD *)v9;
}
if ( (*(_BYTE *)&v30.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v30.__r_.__value_.__l.__data_);
v30.__r_.__value_.__r.__words[2] = (std::string::size_type)__p;
*(_OWORD *)&v30.__r_.__value_.__l.0 = __dst;
}
if ( (*(_BYTE *)&v30.__r_.__value_.__s.0 & 1) != 0 )
{
if ( v30.__r_.__value_.__l.__size_ )
goto LABEL_21;
}
else if ( *(_BYTE *)&v30.__r_.__value_.__l.0 >> 1 )
{
goto LABEL_21;
}
v10 = sub_10088E820("https://www.newgrounds.com/audio/download/%i", (char)CString);
v11 = (const std::string::value_type *)cocos2d::CCString::getCString(v10);
std::string::assign(&v30, v11);
LABEL_21:
v12 = sub_10088E820("%i.mp3", v24);
__src = (const char *)cocos2d::CCString::getCString(v12);
v13 = strlen(__src);
if ( v13 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v14 = v13;
if ( v13 >= 0x17 )
{
v17 = 26;
if ( (v13 | 7) != 0x17 )
v17 = (v13 | 7) + 1;
v16 = __src;
v15 = (char *)operator new(v17);
__p = v15;
*(_QWORD *)&__dst = v17 | 1;
}
else
{
LOBYTE(__dst) = 2 * v13;
v15 = (char *)&__dst + 1;
v16 = __src;
if ( !v13 )
goto LABEL_29;
}
memmove(v15, v16, v14);
LABEL_29:
v15[v14] = 0;
v18 = (char *)operator new(0xD8u);
cocos2d::CCObject::CCObject((__int64)v18);
*(_QWORD *)v18 = off_100B6FB70;
*(_OWORD *)(v18 + 168) = 0;
*((_QWORD *)v18 + 23) = 0;
*((_OWORD *)v18 + 4) = 0;
*((_OWORD *)v18 + 5) = 0;
*((_OWORD *)v18 + 6) = 0;
*((_OWORD *)v18 + 7) = 0;
*((_QWORD *)v18 + 16) = 0;
*((_DWORD *)v18 + 14) = 5;
*((_DWORD *)v18 + 48) = 0;
v18[196] = 0;
*((_QWORD *)v18 + 25) = 0x7800000000LL;
*((_DWORD *)v18 + 52) = 0;
*(_OWORD *)(v18 + 136) = 0;
*(_OWORD *)(v18 + 152) = 0;
if ( (*(_BYTE *)&v30.__r_.__value_.__s.0 & 1) != 0 )
data = v30.__r_.__value_.__l.__data_;
else
data = v30.__r_.__value_.__s.__data_;
std::string::assign((std::string *)(v18 + 64), data);
*((_DWORD *)v18 + 14) = 0;
*((_QWORD *)v18 + 17) = a1;
*((_QWORD *)v18 + 18) = MusicDownloadManager::onDownloadSongCompleted;
*((_QWORD *)v18 + 19) = 0;
cocos2d::CCObject::retain(a1);
v20 = sub_10088E820("%i", v25);
v21 = (const std::string::value_type *)cocos2d::CCString::getCString(v20);
std::string::assign((std::string *)(v18 + 112), v21);
Instance = cocos2d::extension::CCHttpClient::getInstance();
cocos2d::extension::CCHttpClient::send(Instance, (__int64)v18);
cocos2d::CCObject::release(v18);
MusicDownloadManager::addDLToActive(a1, v26, v18);
if ( (__dst & 1) != 0 )
operator delete(__p);
if ( (*(_BYTE *)&v30.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v30.__r_.__value_.__l.__data_);
}
}