//
// MusicDownloadManager::downloadSong from 0x5701f0 to 0x570398 (424 bytes)
//
// 3 xrefs:
// > CustomSongWidget::startDownload @ 0x4e26da
// > CustomSongWidget::processNextMultiAsset @ 0x4e587c
// > CustomSongWidget::loadSongInfoFinished @ 0x4e5ec2
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:52:36 +0000
//
int __fastcall MusicDownloadManager::downloadSong(MusicDownloadManager *this, const char *a2)
{
int result; // r0
const char *SongDownloadKey; // r9
MusicDownloadManager *v6; // r0
MusicDownloadManager *v7; // r0
cocos2d::CCDictionary *SongInfoObject; // r0
int v9; // r0
int v10; // r1
char *v11; // r2
int v12; // r2
int v13; // r3
cocos2d::CCString *v14; // r0
cocos2d::CCString *v15; // r0
char *CString; // r0
const char *v17; // r4
size_t v18; // r0
int *v19; // r4
char *v20; // r1
cocos2d::CCString *v21; // r0
char *v22; // r0
int *v23; // r0
cocos2d::extension::CCHttpClient *Instance; // r0
int v25; // r3
int v26; // [sp+0h] [bp-28h] BYREF
int v27; // [sp+4h] [bp-24h]
char *v28; // [sp+8h] [bp-20h]
int v29; // [sp+Ch] [bp-1Ch] BYREF
int v30; // [sp+10h] [bp-18h]
char *v31; // [sp+14h] [bp-14h]
int v32[3]; // [sp+18h] [bp-10h] BYREF
if ( (int)a2 > 10000000 )
return MusicDownloadManager::downloadCustomSong((int)this, a2);
SongDownloadKey = (const char *)MusicDownloadManager::getSongDownloadKey(this, a2);
result = MusicDownloadManager::isDLActive(this, SongDownloadKey);
if ( !result )
{
MusicDownloadManager::downloadSongStarted((cocos2d::CCArray **)this, (int)a2);
v26 = 0;
v27 = 0;
v28 = nullptr;
v6 = (MusicDownloadManager *)std::string::__init(&v26, &unk_B6B226, 0);
v7 = (MusicDownloadManager *)MusicDownloadManager::sharedState(v6);
SongInfoObject = MusicDownloadManager::getSongInfoObject(v7, a2);
if ( SongInfoObject )
{
std::string::basic_string(&v29, (int)SongInfoObject + 292);
if ( (v26 & 1) != 0 )
{
*v28 = 0;
v27 = 0;
}
else
{
LOWORD(v26) = 0;
}
std::string::reserve(&v26, 0);
v9 = v29;
v10 = v30;
v11 = v31;
v29 = 0;
v30 = 0;
v31 = nullptr;
v26 = v9;
v27 = v10;
v28 = v11;
std::string::~string((int)&v29);
}
v12 = (unsigned __int8)v26 << 31;
if ( (v26 & 1) != 0 )
v13 = v27;
else
v13 = (int)(unsigned __int8)v26 >> 1;
if ( !v13 )
{
v15 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"https://www.newgrounds.com/audio/download/%i",
a2,
v12);
CString = (char *)cocos2d::CCString::getCString(v15);
std::string::assign(&v26, CString);
}
v14 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i.mp3", a2, v12);
v17 = (const char *)cocos2d::CCString::getCString(v14);
memset(v32, 0, sizeof(v32));
v18 = strlen(v17);
std::string::__init(v32, v17, v18);
v19 = (int *)operator new(0x8Cu);
cocos2d::extension::CCHttpRequest::CCHttpRequest((cocos2d::extension::CCHttpRequest *)v19);
v19[33] = 120;
if ( (v26 & 1) != 0 )
v20 = v28;
else
v20 = (char *)&v26 + 1;
std::string::assign(v19 + 14, v20);
v19[23] = (int)this;
v19[13] = 0;
v19[24] = (int)MusicDownloadManager::onDownloadSongCompleted;
v19[25] = 0;
if ( this )
cocos2d::CCObject::retain(this);
v21 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", a2);
v22 = (char *)cocos2d::CCString::getCString(v21);
v23 = std::string::assign(v19 + 20, v22);
Instance = (cocos2d::extension::CCHttpClient *)cocos2d::extension::CCHttpClient::getInstance((cocos2d::extension::CCHttpClient *)v23);
cocos2d::extension::CCHttpClient::send(Instance, (cocos2d::extension::CCHttpRequest *)v19);
cocos2d::CCObject::release((cocos2d::CCObject *)v19);
MusicDownloadManager::addDLToActive(this, SongDownloadKey, (cocos2d::CCObject *)v19, v25);
std::string::~string((int)v32);
return std::string::~string((int)&v26);
}
return result;
}