//
// MusicDownloadManager::downloadSong from 0x96857c to 0x9688cc (848 bytes)
//
// 4 xrefs:
// > CustomSongWidget::startDownload @ 0x8685f0
// > CustomSongWidget::processNextMultiAsset @ 0x86cfe4
// > CustomSongWidget::loadSongInfoFinished @ 0x86de74
// > ??> @ 0x820f0
//
// 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 12:57:36 +0000
//
__int64 __fastcall MusicDownloadManager::downloadSong(MusicDownloadManager *this, const char *a2)
{
unsigned int v2; // w21
const char *SongDownloadKey; // x23
MusicDownloadManager *v6; // x0
MusicDownloadManager *v7; // x0
__int64 SongInfoObject; // x0
char v9; // w1
__int64 *v10; // x2
__int64 v11; // x0
__int64 v12; // x1
__int64 v13; // x1
cocos2d::CCString *v14; // x0
char *CString; // x0
cocos2d::CCString *v16; // x0
size_t v17; // x0
__int64 v18; // x20
char v19; // w1
char v20; // w2
char *v21; // x1
cocos2d::CCString *v22; // x0
char *v23; // x0
__int64 *v24; // x0
cocos2d::extension::CCHttpClient *Instance; // x0
char *v26; // [xsp+58h] [xbp+58h]
__int64 v27; // [xsp+60h] [xbp+60h] BYREF
__int64 v28; // [xsp+68h] [xbp+68h]
char *v29; // [xsp+70h] [xbp+70h]
__int64 v30; // [xsp+78h] [xbp+78h] BYREF
__int64 v31; // [xsp+80h] [xbp+80h]
char *v32; // [xsp+88h] [xbp+88h]
__int64 v33[2]; // [xsp+90h] [xbp+90h] BYREF
void *v34; // [xsp+A0h] [xbp+A0h]
v2 = (unsigned int)a2;
if ( (int)a2 <= 10000000 )
{
SongDownloadKey = (const char *)MusicDownloadManager::getSongDownloadKey(this, a2);
if ( !MusicDownloadManager::isDLActive(this, SongDownloadKey) )
{
MusicDownloadManager::downloadSongStarted((cocos2d::CCArray **)this, v2);
v27 = 0;
v28 = 0;
v29 = nullptr;
v6 = (MusicDownloadManager *)std::string::__init(&v27, &byte_11B8890, 0);
v7 = (MusicDownloadManager *)MusicDownloadManager::sharedState(v6);
SongInfoObject = MusicDownloadManager::getSongInfoObject(v7, (const char *)v2);
if ( SongInfoObject )
{
v9 = *(_BYTE *)(SongInfoObject + 368);
v30 = 0;
v10 = (__int64 *)(SongInfoObject + 368);
v31 = 0;
v32 = nullptr;
if ( (v9 & 1) != 0 )
{
std::string::__init(&v30, *(void **)(SongInfoObject + 384), *(_QWORD *)(SongInfoObject + 376));
}
else
{
v11 = *v10;
v12 = v10[1];
v32 = (char *)v10[2];
v30 = v11;
v31 = v12;
}
if ( (v27 & 1) != 0 )
{
*v29 = 0;
v28 = 0;
}
else
{
LOWORD(v27) = 0;
}
std::string::reserve(&v27, 0);
v29 = v32;
v27 = v30;
v28 = v31;
}
v13 = (unsigned __int8)v27 >> 1;
if ( (v27 & 1) != 0 )
v13 = v28;
if ( !v13 )
{
v14 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"https://www.newgrounds.com/audio/download/%i",
(const char *)v2);
CString = (char *)cocos2d::CCString::getCString(v14);
std::string::assign(&v27, CString);
}
v16 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i.mp3", (const char *)v2);
v26 = (char *)cocos2d::CCString::getCString(v16);
v33[0] = 0;
v33[1] = 0;
v34 = nullptr;
v17 = strlen(v26);
std::string::__init(v33, v26, v17);
v18 = operator new(0xD8u);
cocos2d::CCObject::CCObject((cocos2d::CCObject *)v18);
*(_QWORD *)v18 = &off_143F160;
*(_QWORD *)(v18 + 64) = 0;
*(_QWORD *)(v18 + 72) = 0;
*(_QWORD *)(v18 + 80) = 0;
*(_QWORD *)(v18 + 112) = 0;
*(_QWORD *)(v18 + 88) = 0;
*(_QWORD *)(v18 + 96) = 0;
*(_QWORD *)(v18 + 104) = 0;
*(_QWORD *)(v18 + 120) = 0;
*(_QWORD *)(v18 + 128) = 0;
*(_QWORD *)(v18 + 168) = 0;
v19 = *(_BYTE *)(v18 + 112);
*(_QWORD *)(v18 + 176) = 0;
*(_QWORD *)(v18 + 184) = 0;
*(_DWORD *)(v18 + 56) = 5;
*(_BYTE *)(v18 + 65) = 0;
*(_BYTE *)(v18 + 64) = 0;
if ( (v19 & 1) != 0 )
{
LOBYTE(dword_0) = 0;
*(_QWORD *)(v18 + 120) = 0;
}
else
{
*(_BYTE *)(v18 + 113) = 0;
*(_BYTE *)(v18 + 112) = 0;
}
v20 = v27;
*(_QWORD *)(v18 + 136) = 0;
v21 = (char *)&v27 + 1;
*(_QWORD *)(v18 + 144) = 0;
*(_QWORD *)(v18 + 152) = 0;
*(_QWORD *)(v18 + 160) = 0;
*(_DWORD *)(v18 + 192) = 0;
*(_BYTE *)(v18 + 196) = 0;
*(_DWORD *)(v18 + 200) = 0;
*(_QWORD *)(v18 + 204) = 120;
if ( (v20 & 1) != 0 )
v21 = v29;
std::string::assign((__int64 *)(v18 + 64), v21);
*(_DWORD *)(v18 + 56) = 0;
*(_QWORD *)(v18 + 136) = this;
*(_QWORD *)(v18 + 144) = MusicDownloadManager::onDownloadSongCompleted;
*(_QWORD *)(v18 + 152) = 0;
if ( this )
cocos2d::CCObject::retain(this);
v22 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", (const char *)v2);
v23 = (char *)cocos2d::CCString::getCString(v22);
v24 = std::string::assign((__int64 *)(v18 + 112), v23);
Instance = (cocos2d::extension::CCHttpClient *)cocos2d::extension::CCHttpClient::getInstance((cocos2d::extension::CCHttpClient *)v24);
cocos2d::extension::CCHttpClient::send(Instance, (cocos2d::extension::CCHttpRequest *)v18);
cocos2d::CCObject::release((cocos2d::CCObject *)v18);
MusicDownloadManager::addDLToActive(this, SongDownloadKey, (cocos2d::CCObject *)v18);
if ( (v33[0] & 1) != 0 )
operator delete(v34);
if ( (v27 & 1) != 0 )
operator delete(v29);
}
}
else
{
MusicDownloadManager::downloadCustomSong(this, (unsigned int)a2);
}
return _stack_chk_guard;
}