//
// MusicDownloadManager::downloadSong from 0x1001d4da4 to 0x1001d501c (632 bytes)
//
// 3 xrefs:
// > CustomSongWidget::startDownload @ 0x100121d08
// > CustomSongWidget::loadSongInfoFinished @ 0x100122964
// > CustomSongWidget::processNextMultiAsset @ 0x100123010
//
// This function is hookable on this platform (idp: arm, 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:00:24 +0000
//
void __fastcall MusicDownloadManager::downloadSong(__int64 a1, __int64 a2)
{
__int64 v4; // x0
char *CString; // x20
__int64 v6; // x0
__int64 SongInfoObject; // x0
std::string::size_type size; // x8
__int64 v9; // x0
const std::string::value_type *v10; // x0
__int64 v11; // x0
char *v12; // x0
char *v13; // x22
std::string *p_p; // x1
__int64 v15; // x0
const std::string::value_type *v16; // x0
std::string *v17; // x0
__int64 Instance; // x0
std::string __dst; // [xsp+10h] [xbp-70h] BYREF
std::string __p; // [xsp+30h] [xbp-50h] BYREF
if ( (int)a2 < 10000001 )
{
v4 = sub_1003065B0("d_%i", a2);
CString = (char *)cocos2d::CCString::getCString(v4);
if ( !sub_1001D2E78(a1, CString) )
{
MusicDownloadManager::downloadSongStarted(a1, a2);
sub_100009900(&__p, "");
v6 = MusicDownloadManager::sharedState();
SongInfoObject = MusicDownloadManager::getSongInfoObject(v6, a2);
if ( SongInfoObject )
{
if ( *(char *)(SongInfoObject + 391) < 0 )
sub_1000097D0(&__dst, *(void **)(SongInfoObject + 368), *(_QWORD *)(SongInfoObject + 376));
else
__dst = *(std::string *)(SongInfoObject + 368);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
__p = __dst;
}
size = HIBYTE(__p.__r_.__value_.__r.__words[2]);
if ( (__p.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) != 0LL )
size = __p.__r_.__value_.__l.__size_;
if ( !size )
{
v9 = sub_1003065B0("https://www.newgrounds.com/audio/download/%i", a2);
v10 = (const std::string::value_type *)cocos2d::CCString::getCString(v9);
std::string::assign(&__p, v10);
}
v11 = sub_1003065B0("%i.mp3", a2);
v12 = (char *)cocos2d::CCString::getCString(v11);
sub_100009900(&__dst, v12);
v13 = (char *)operator new(0xD8u);
cocos2d::CCObject::CCObject((__int64)v13);
*(_QWORD *)v13 = off_1008CEAF0;
*((_OWORD *)v13 + 7) = 0u;
*((_QWORD *)v13 + 21) = 0;
*((_OWORD *)v13 + 11) = 0u;
*((_QWORD *)v13 + 16) = 0;
*((_OWORD *)v13 + 5) = 0u;
*((_OWORD *)v13 + 6) = 0u;
*((_OWORD *)v13 + 4) = 0u;
*((_DWORD *)v13 + 14) = 5;
*((_DWORD *)v13 + 48) = 0;
v13[196] = 0;
*((_DWORD *)v13 + 52) = 0;
*(_OWORD *)(v13 + 151) = 0u;
v13[167] = 0;
*(_OWORD *)(v13 + 135) = 0u;
if ( (__p.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
p_p = &__p;
else
p_p = (std::string *)__p.__r_.__value_.__r.__words[0];
*((_QWORD *)v13 + 25) = 0x7800000000LL;
std::string::assign((std::string *)(v13 + 64), (const std::string::value_type *)p_p);
*((_DWORD *)v13 + 14) = 0;
*((_QWORD *)v13 + 17) = a1;
*((_QWORD *)v13 + 18) = MusicDownloadManager::onDownloadSongCompleted;
*((_QWORD *)v13 + 19) = 0;
if ( a1 )
cocos2d::CCObject::retain(a1);
v15 = sub_1003065B0("%i", a2);
v16 = (const std::string::value_type *)cocos2d::CCString::getCString(v15);
v17 = std::string::assign((std::string *)(v13 + 112), v16);
Instance = cocos2d::extension::CCHttpClient::getInstance(v17);
cocos2d::extension::CCHttpClient::send(Instance, v13);
cocos2d::CCObject::release(v13);
MusicDownloadManager::addDLToActive(a1, CString, v13);
if ( SHIBYTE(__dst.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
}
}
else
{
MusicDownloadManager::downloadCustomSong(a1, a2);
}
}