//
// MusicDownloadManager::downloadCustomSong from 0x140340310 to 0x14034057f (623 bytes)
//
// 2 xrefs:
// > MusicDownloadManager::downloadSong @ 0x14033ea56
// > ??> @ 0x1406d5744
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
// Hidden C++ exception states: #wind=4
void MusicDownloadManager::downloadCustomSong(MusicDownloadManager *a1, int a2)
{
cocos2d::CCString *v4; // rax
const char *CString; // r12
void **v6; // rdx
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
void **v11; // r15
char *v12; // rsi
unsigned __int64 v13; // r13
__int64 v14; // rbx
unsigned __int64 v15; // rdi
const char *v16; // rbx
const char *v17; // rax
cocos2d::extension::CCHttpRequest *Request; // rax
char *v19; // rax
__int128 v20; // [rsp+30h] [rbp-D0h] BYREF
unsigned __int64 v21; // [rsp+40h] [rbp-C0h]
__int64 v22; // [rsp+48h] [rbp-B8h]
_BYTE *v23; // [rsp+50h] [rbp-B0h]
_BYTE v24[32]; // [rsp+60h] [rbp-A0h] BYREF
char v25[32]; // [rsp+80h] [rbp-80h] BYREF
void *Src[2]; // [rsp+A0h] [rbp-60h] BYREF
unsigned __int64 v27; // [rsp+B0h] [rbp-50h]
unsigned __int64 v28; // [rsp+B8h] [rbp-48h]
void *v29[4]; // [rsp+C0h] [rbp-40h] BYREF
_BYTE v30[32]; // [rsp+E0h] [rbp-20h] BYREF
if ( a1->m_customContentURL.m_data.m_size )
{
v4 = cocos2d::CCString::createWithFormat("d_%i", a2);
CString = cocos2d::CCString::getCString(v4);
if ( !AchievementManager::getAchievementsWithID((__int64)a1, (__int64)CString) )
{
MusicDownloadManager::downloadSongStarted(a1, a2);
GameToolbox::intToString(v29, a2);
Src[1] = nullptr;
v27 = 7;
v28 = 15;
Src[0] = (void *)0x2F636973756D2FLL;
v6 = v29;
if ( v29[3] > (void *)0xF )
v6 = (void **)v29[0];
sub_140041270(Src, v6, (size_t)v29[2]);
sub_140041270(Src, ".ogg", 4u);
v20 = 0;
v21 = 0;
v22 = 0;
v11 = Src;
v12 = (char *)Src[0];
v13 = v28;
if ( v28 > 0xF )
v11 = (void **)Src[0];
v14 = 0x7FFFFFFFFFFFFFFFLL;
v15 = v27;
if ( v27 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v8, v7, v9, v10);
v22 = 15;
if ( v27 > 0xF )
{
if ( (v27 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
v14 = v27 | 0xF;
if ( (v27 | 0xF) < 0x16 )
v14 = 22;
}
*(_QWORD *)&v20 = sub_14003AA10(v14 + 1);
v21 = v15;
v22 = v14;
memcpy((void *)v20, v11, v15 + 1);
}
else
{
v21 = v27;
v20 = *(_OWORD *)v11;
}
MusicDownloadManager::generateCustomContentURL(a1, v30, &v20);
v23 = v24;
v16 = (const char *)sub_14003BDB0((__int64)v24, (__int64)v29);
v17 = (const char *)sub_14003BDB0((__int64)v25, (__int64)v30);
Request = MusicDownloadManager::ProcessHttpGetRequest(
a1,
v17,
v16,
(void (__cdecl *)(cocos2d::extension::CCHttpClient *, cocos2d::extension::CCHttpResponse *))MusicDownloadManager::onDownloadSongCompleted,
0,
0);
MusicDownloadManager::addDLToActive(a1, CString, Request);
sub_14003A830((__int64)v30);
if ( v13 > 0xF )
{
v19 = v12;
if ( v13 + 1 >= 0x1000 )
{
v12 = *((char **)v12 - 1);
if ( (unsigned __int64)(v19 - v12 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v12);
}
sub_14003A830((__int64)v29);
}
}
}