//
// MusicDownloadManager::parseMusicLibrary from 0x45cd48 to 0x45d486 (1854 bytes)
//
// 3 xrefs:
// > MusicDownloadManager::onDownloadMusicLibraryCompleted @ 0x45d540
// > MusicDownloadManager::tryLoadLibraries @ 0x45d5c6
// > sub_581CB4 @ 0x582524
//
// 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
//
void MusicDownloadManager::parseMusicLibrary(MusicDownloadManager *a1)
{
cocos2d::CCFileUtils *v2; // r0
unsigned __int8 *v3; // r1
cocos2d::CCDictionary *m_musicObjects; // r0
cocos2d::CCDictionary *m_musicArtists; // r0
cocos2d::CCDictionary *v6; // r0
cocos2d::CCDictionary *v7; // r0
const char **v8; // r5
const char *v9; // r0
int v10; // r0
unsigned int i; // r8
char **v12; // r5
unsigned int j; // r11
char **v14; // r5
int v15; // r6
const char **v16; // r5
float v17; // s16
const char **v18; // r5
int v19; // r8
char *v20; // r1
char *v21; // r1
const char **v22; // r7
int v23; // r0
char v24; // r5
int v25; // r4
char *v26; // r1
cocos2d::CCObject *v27; // r1
SongInfoObject *v28; // r4
unsigned int k; // r6
const char **v30; // r9
int v31; // r0
char *v32; // r1
int v33; // r2
int v34; // r0
std::map *p_m_musicTags; // [sp+28h] [bp-CCh]
int v36; // [sp+2Ch] [bp-C8h]
intptr_t v37; // [sp+2Ch] [bp-C8h]
int v38; // [sp+30h] [bp-C4h]
cocos2d::CCObject *v39; // [sp+3Ch] [bp-B8h]
cocos2d::CCObject *v40; // [sp+3Ch] [bp-B8h]
int v41; // [sp+40h] [bp-B4h]
int v42; // [sp+64h] [bp-90h] BYREF
int v43; // [sp+68h] [bp-8Ch] BYREF
_DWORD *v44; // [sp+6Ch] [bp-88h] BYREF
cocos2d::ZipUtils v45; // [sp+70h] [bp-84h] BYREF
cocos2d::ZipUtils v46; // [sp+74h] [bp-80h] BYREF
cocos2d::ZipUtils v47; // [sp+78h] [bp-7Ch] BYREF
char v48[4]; // [sp+7Ch] [bp-78h] BYREF
std::string v49; // [sp+80h] [bp-74h] BYREF
std::string v50; // [sp+84h] [bp-70h] BYREF
cocos2d::ZipUtils v51; // [sp+88h] [bp-6Ch] BYREF
cocos2d::ZipUtils v52; // [sp+8Ch] [bp-68h] BYREF
char v53[4]; // [sp+90h] [bp-64h] BYREF
char v54[4]; // [sp+94h] [bp-60h] BYREF
char v55[4]; // [sp+98h] [bp-5Ch] BYREF
char v56[4]; // [sp+9Ch] [bp-58h] BYREF
char v57[4]; // [sp+A0h] [bp-54h] BYREF
char v58[4]; // [sp+A4h] [bp-50h] BYREF
int v59; // [sp+A8h] [bp-4Ch] BYREF
int v60; // [sp+ACh] [bp-48h] BYREF
const char **v61; // [sp+B0h] [bp-44h] BYREF
int v62; // [sp+B4h] [bp-40h]
int v63; // [sp+B8h] [bp-3Ch]
const char **v64; // [sp+BCh] [bp-38h] BYREF
int v65; // [sp+C0h] [bp-34h]
int v66; // [sp+C4h] [bp-30h]
_DWORD *v67; // [sp+C8h] [bp-2Ch] BYREF
int v68; // [sp+CCh] [bp-28h]
int v69; // [sp+D0h] [bp-24h]
std::string v70; // [sp+D4h] [bp-20h] BYREF
int v71; // [sp+D8h] [bp-1Ch]
int v72; // [sp+DCh] [bp-18h]
std::string v73; // [sp+E0h] [bp-14h] BYREF
int v74; // [sp+E4h] [bp-10h]
int v75; // [sp+E8h] [bp-Ch]
MusicDownloadManager::pathForSongFolder((MusicDownloadManager *)&v42, a1, 0, _stack_chk_guard);
sub_774544((int)&v42, "musiclibrary.dat");
v43 = 0;
v2 = cocos2d::CCFileUtils::sharedFileUtils();
v3 = (unsigned __int8 *)((int (__fastcall *)(cocos2d::CCFileUtils *, int, __int16 *, int *))v2->addSearchResolutionsOrder)(
v2,
v42,
&aO1i2r3e45s7t89[4],
&v43);
v44 = &unk_ACDDA8;
if ( !v3 )
goto LABEL_57;
cocos2d::ZipUtils::decompressString2(&v45, v3, 0, v43, 11);
sub_774794(&v44, &v45);
sub_774008(&v45);
if ( !*(v44 - 3) )
goto LABEL_57;
v61 = nullptr;
v62 = 0;
v63 = 0;
sub_45A6C8(&v44, "|", (int)&v61);
if ( (unsigned int)(v62 - (_DWORD)v61) <= 0xF )
{
std::vector::~vector((void **)&v61);
LABEL_57:
sub_774008(&v44);
goto LABEL_58;
}
m_musicObjects = a1->m_musicObjects;
v64 = nullptr;
v65 = 0;
v66 = 0;
if ( m_musicObjects )
cocos2d::CCObject::release(m_musicObjects);
m_musicArtists = a1->m_musicArtists;
if ( m_musicArtists )
cocos2d::CCObject::release(m_musicArtists);
a1->m_musicObjects = nullptr;
a1->m_musicArtists = nullptr;
v6 = cocos2d::CCDictionary::create();
a1->m_musicObjects = v6;
cocos2d::CCObject::retain(v6);
v7 = cocos2d::CCDictionary::create();
a1->m_musicArtists = v7;
cocos2d::CCObject::retain(v7);
p_m_musicTags = &a1->m_musicTags;
std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_erase(
(int)&a1->m_musicTags,
&a1->m_musicTags.m_header.m_parent->m_isblack);
v8 = v61;
a1->m_musicTags.m_header.m_parent = nullptr;
a1->m_musicTags.m_header.m_left = &a1->m_musicTags.m_header;
a1->m_musicTags.m_header.m_right = &a1->m_musicTags.m_header;
a1->m_musicTags.m_nodecount = 0;
v9 = *v8;
a1->m_musicObjectCount = 0;
a1->m_ncsSongCount = 0;
v10 = atoi(v9);
v67 = nullptr;
v68 = 0;
v69 = 0;
a1->m_musicLibraryVersion = v10;
sub_45A6C8(&byte_4[(_DWORD)v8], ";", (int)&v67);
for ( i = 0; i < (v68 - (int)v67) >> 2; ++i )
{
std::vector::clear(&v64);
sub_45A6C8(&v67[i], ",", (int)&v64);
v12 = (char **)v64;
if ( (unsigned int)(v65 - (_DWORD)v64) > 0xF )
{
v36 = atoi(*v64);
sub_776584((int)&v60, v12[1]);
sub_776584((int)&v70, (char *)v64[2]);
sub_776584((int)&v73, (char *)v64[3]);
if ( *((_DWORD *)v70.m_data.m_data - 3) > 1u )
{
cocos2d::ZipUtils::urlDecode(&v46, &v70);
sub_774794(&v70, &v46);
sub_774008(&v46);
}
else
{
sub_7753D4((int)&v70, (char *)&unk_939830);
}
if ( *((_DWORD *)v73.m_data.m_data - 3) > 1u )
{
cocos2d::ZipUtils::urlDecode(&v47, &v73);
sub_774794(&v73, &v47);
sub_774008(&v47);
}
else
{
sub_7753D4((int)&v73, (char *)&unk_939830);
}
sub_775C20(v48);
sub_775C20(&v49);
sub_775C20(&v50);
v39 = MusicArtistObject::create(v36);
sub_774008(&v50);
sub_774008(&v49);
sub_774008(v48);
cocos2d::CCDictionary::setObject(a1->m_musicArtists, v39, v36);
sub_774008(&v73);
sub_774008(&v70);
sub_774008(&v60);
}
}
v70.m_data.m_data = nullptr;
v71 = 0;
v72 = 0;
sub_45A6C8(v61 + 2, ";", (int)&v70);
for ( j = 0; j < (signed int)(v71 - (unsigned int)v70.m_data.m_data) >> 2; ++j )
{
std::vector::clear(&v64);
sub_45A6C8((_DWORD *)v70.m_data.m_data + j, ",", (int)&v64);
v14 = (char **)v64;
v15 = (v65 - (int)v64) >> 2;
if ( v15 <= 5 )
continue;
v40 = (cocos2d::CCObject *)atoi(*v64);
sub_776584((int)&v46, v14[1]);
v16 = v64;
v37 = atoi(v64[2]);
v17 = vcvts_n_f32_s32(atoi(v16[3]), 0x14u);
v41 = atoi(v16[4]);
sub_776584((int)&v47, (char *)v16[5]);
if ( v15 == 6 )
{
v19 = 0;
v20 = (char *)&unk_939830;
}
else
{
v18 = v64;
v19 = atoi(v64[6]);
if ( v15 == 7 )
v20 = (char *)&unk_939830;
else
v20 = (char *)v18[7];
}
sub_776584((int)v48, v20);
if ( v15 <= 8 )
v21 = (char *)&unk_939830;
else
v21 = (char *)v64[8];
sub_776584((int)&v49, v21);
if ( v15 <= 9 )
{
v24 = 0;
v25 = 0;
goto LABEL_60;
}
v22 = v64;
v23 = atoi(v64[9]);
v24 = v23;
if ( v23 )
v24 = 1;
if ( v15 <= 10 )
{
v25 = 0;
LABEL_60:
v26 = (char *)&unk_939830;
v38 = 0;
goto LABEL_38;
}
v25 = atoi(v22[10]);
if ( v15 == 11 )
goto LABEL_60;
v38 = atoi(v22[11]);
if ( v15 == 12 )
v26 = (char *)&unk_939830;
else
v26 = (char *)v22[12];
LABEL_38:
sub_776584((int)&v50, v26);
if ( *((_DWORD *)v49.m_data.m_data - 3) > 1u )
{
cocos2d::ZipUtils::urlDecode(&v51, &v49);
sub_774794(&v49, &v51);
sub_774008(&v51);
}
else
{
sub_7753D4((int)&v49, (char *)&unk_939830);
}
if ( *((_DWORD *)v50.m_data.m_data - 3) > 1u )
{
cocos2d::ZipUtils::urlDecode(&v52, &v50);
sub_774794(&v50, &v52);
sub_774008(&v52);
}
else
{
sub_7753D4((int)&v50, (char *)&unk_939830);
}
sub_776584((int)&v73, "NA");
v27 = cocos2d::CCDictionary::objectForKey(a1->m_musicArtists, v37);
if ( v27 )
sub_775D40(&v73, &v27[1].m_uID);
sub_775C20(v53);
sub_775C20(v54);
sub_776584((int)v55, (char *)&unk_939830);
sub_776584((int)v56, (char *)&unk_939830);
sub_775C20(v57);
sub_775C20(v58);
sub_775C20(&v59);
v28 = (SongInfoObject *)SongInfoObject::create(
(int)v40,
(int)v53,
(int)v54,
v37,
SLODWORD(v17),
(int)v55,
(int)v56,
(int)v57,
(int)v58,
v19,
(int)&v59,
v24,
v25,
0);
sub_774008(&v59);
sub_774008(v58);
sub_774008(v57);
sub_774008(v56);
sub_774008(v55);
sub_774008(v54);
sub_774008(v53);
v28->m_duration = v41;
v28->m_songOrder = v38;
v28->m_verified = 1;
sub_775C20(&v60);
SongInfoObject::addTags((void **)&v28->__vftable, &v60);
sub_774008(&v60);
MusicDownloadManager::storeMusicObject(a1, v28);
++a1->m_musicObjectCount;
if ( v19 == 1 )
++a1->m_ncsSongCount;
sub_774008(&v73);
sub_774008(&v50);
sub_774008(&v49);
sub_774008(v48);
sub_774008(&v47);
sub_774008(&v46);
}
v73.m_data.m_data = nullptr;
v74 = 0;
v75 = 0;
sub_45A6C8(v61 + 3, ";", (int)&v73);
for ( k = 0; k < (signed int)(v74 - (unsigned int)v73.m_data.m_data) >> 2; ++k )
{
std::vector::clear(&v64);
sub_45A6C8((_DWORD *)v73.m_data.m_data + k, ",", (int)&v64);
v30 = v64;
if ( (unsigned int)(v65 - (_DWORD)v64) > 7 )
{
v31 = atoi(*v64);
v32 = (char *)v30[1];
v59 = v31;
sub_776584((int)&v60, v32);
v34 = std::map::operator[](p_m_musicTags, &v59, v33);
sub_775D40(v34, &v60);
sub_774008(&v60);
}
}
std::vector::~vector((void **)&v73.m_data.m_data);
std::vector::~vector((void **)&v70.m_data.m_data);
std::vector::~vector((void **)&v67);
std::vector::~vector((void **)&v64);
std::vector::~vector((void **)&v61);
sub_774008(&v44);
LABEL_58:
sub_774008(&v42);
}