{"type": "func", "start": 5372112160, "end": 5372112829, "name": "MusicDownloadManager::onDownloadSongCompleted", "pseudocode": "// \n// MusicDownloadManager::onDownloadSongCompleted from 0x14033ed20 to 0x14033efbd (669 bytes)\n// \n// 3 xrefs:\n// > MusicDownloadManager::downloadSong @ 0x14033ec09\n// > MusicDownloadManager::downloadCustomSong @ 0x1403404e0\n// > <???> @ 0x1406d569c\n// \n// This function is hookable on this platform!\n// \n// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA\n// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings\n// \n\n// Hidden C++ exception states: #wind=4\nvoid MusicDownloadManager::onDownloadSongCompleted(\n        MusicDownloadManager *a1,\n        cocos2d::extension::CCHttpClient *a2,\n        cocos2d::extension::CCHttpResponse *a3)\n{\n  const char *Tag; // rax\n  unsigned int v6; // esi\n  cocos2d::CCString *v7; // rax\n  const char *CString; // rax\n  const char *v9; // rcx\n  FILE *v10; // rax\n  FILE *v11; // rbp\n  SongInfoObject *SongInfoObject; // rax\n  GameManager *v13; // rcx\n  __int64 v14; // rax\n  int v15; // r14d\n  int v16; // ebp\n  cocos2d::CCArray *i; // rdi\n  __int64 m_unknown2; // r8\n  const char *v19; // rcx\n  unsigned int j; // edi\n  struct cocos2d::CCObject *v21; // rax\n  void *v22; // [rsp+20h] [rbp-68h]\n  void *v23; // [rsp+20h] [rbp-68h]\n  char *v24[4]; // [rsp+28h] [rbp-60h] BYREF\n  char *FileName[4]; // [rsp+48h] [rbp-40h] BYREF\n\n  Tag = cocos2d::extension::CCHttpRequest::getTag(a3->_pHttpRequest);\n  v6 = atoi(Tag);\n  v7 = cocos2d::CCString::createWithFormat(\"d_%i\", v6);\n  CString = cocos2d::CCString::getCString(v7);\n  MusicDownloadManager::removeDLFromActive(a1, CString);\n  if ( a3->_succeed )\n  {\n    MusicDownloadManager::pathForSong(a1, FileName, v6);\n    v9 = (const char *)FileName;\n    if ( FileName[3] > (char *)0xF )\n      v9 = FileName[0];\n    v10 = fopen(v9, \"wb\");\n    v11 = v10;\n    if ( v10 )\n    {\n      fwrite(\n        a3->_responseData._Mypair._Myval2._Myfirst,\n        1u,\n        a3->_responseData._Mypair._Myval2._Mylast - a3->_responseData._Mypair._Myval2._Myfirst,\n        v10);\n      fclose(v11);\n      SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v6);\n      if ( SongInfoObject )\n        SongInfoObject->m_priority = ++a1->m_songPriority;\n      v13 = (GameManager *)qword_1406C2ED8;\n      if ( !qword_1406C2ED8 )\n      {\n        v22 = operator new(0x668u);\n        qword_1406C2ED8 = sub_14017AB00((__int64)v22);\n        (*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);\n        v13 = (GameManager *)qword_1406C2ED8;\n      }\n      if ( !GameManager::getGameVariable(v13, \"0018\") )\n      {\n        v14 = qword_1406C2ED8;\n        if ( !qword_1406C2ED8 )\n        {\n          v23 = operator new(0x668u);\n          qword_1406C2ED8 = sub_14017AB00((__int64)v23);\n          (*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);\n          v14 = qword_1406C2ED8;\n        }\n        v15 = *(_DWORD *)(v14 + 1080);\n        v16 = *(_DWORD *)(v14 + 1084);\n        for ( i = MusicDownloadManager::getDownloadedSongs(a1);\n              cocos2d::CCArray::count(i) > 0x32;\n              cocos2d::CCArray::removeLastObject(i, 1) )\n        {\n          m_unknown2 = (unsigned int)cocos2d::CCArray::lastObject(i)[5].m_unknown2;\n          if ( (_DWORD)m_unknown2 != v15 && (_DWORD)m_unknown2 != v16 )\n          {\n            MusicDownloadManager::pathForSong(a1, v24, m_unknown2);\n            v19 = (const char *)v24;\n            if ( v24[3] > (char *)0xF )\n              v19 = v24[0];\n            remove(v19);\n            sub_14003A830((__int64)v24);\n          }\n        }\n      }\n      for ( j = 0; j < cocos2d::CCArray::count(a1->m_musicDownloadDelegates); ++j )\n      {\n        v21 = cocos2d::CCArray::objectAtIndex(a1->m_musicDownloadDelegates, j);\n        (*(void (__fastcall **)(_QWORD, _QWORD))(**(_QWORD **)&v21[5].m_unknown2 + 24LL))(\n          *(_QWORD *)&v21[5].m_unknown2,\n          v6);\n      }\n    }\n    else\n    {\n      MusicDownloadManager::downloadSongFailed(a1, v6, (GJSongError)0);\n    }\n    sub_14003A830((__int64)FileName);\n  }\n  else\n  {\n    MusicDownloadManager::downloadSongFailed(\n      a1,\n      v6,\n      BYTE4(a3->_pHttpRequest->_headers._Mypair._Myval2._Myend) != 0 ? DownloadCancelled : (GJSongError)0);\n  }\n}", "assembly": "; \n; MusicDownloadManager::onDownloadSongCompleted from 0x14033ed20 to 0x14033efbd (669 bytes)\n; \n; 3 xrefs:\n; > MusicDownloadManager::downloadSong @ 0x14033ec09\n; > MusicDownloadManager::downloadCustomSong @ 0x1403404e0\n; > <???> @ 0x1406d569c\n; \n; This function is hookable on this platform!\n; \n; Using BromaIDA 8.0.0 @ https:;github.com/Stazzical/BromaIDA\n; Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https:;github.com/geode-sdk/bindings\n; \n\nmov     [rsp+arg_8], rbx                                               ; +0x0, 0x14033ed20\nmov     [rsp+arg_18], rbp                                              ; +0x5, 0x14033ed25\npush    rsi                                                            ; +0xa, 0x14033ed2a\npush    rdi                                                            ; +0xb, 0x14033ed2b\npush    r14                                                            ; +0xc, 0x14033ed2c\nsub     rsp, 70h                                                       ; +0xe, 0x14033ed2e\nmov     rax, cs:__security_cookie                                      ; +0x12, 0x14033ed32\nxor     rax, rsp                                                       ; +0x19, 0x14033ed39\nmov     [rsp+88h+var_20], rax                                          ; +0x1c, 0x14033ed3c\nmov     rdi, r8                                                        ; +0x21, 0x14033ed41\nmov     rbx, rcx                                                       ; +0x24, 0x14033ed44\nmov     rcx, [r8+38h]                                                  ; +0x27, 0x14033ed47\ncall    cs:?getTag@CCHttpRequest@extension@cocos2d@@QEAAPEBDXZ; cocos2d::extension::CCHttpRequest::getTag(void) ; +0x2b, 0x14033ed4b\nmov     rcx, rax; String                                               ; +0x31, 0x14033ed51\ncall    cs:atoi                                                        ; +0x34, 0x14033ed54\nmov     esi, eax                                                       ; +0x3a, 0x14033ed5a\nmov     edx, eax                                                       ; +0x3c, 0x14033ed5c\nlea     rcx, aDI; \"d_%i\"                                               ; +0x3e, 0x14033ed5e\ncall    cs:?createWithFormat@CCString@cocos2d@@SAPEAV12@PEBDZZ; cocos2d::CCString::createWithFormat(char const *,...) ; +0x45, 0x14033ed65\nmov     rcx, rax                                                       ; +0x4b, 0x14033ed6b\ncall    cs:?getCString@CCString@cocos2d@@QEBAPEBDXZ; cocos2d::CCString::getCString(void) ; +0x4e, 0x14033ed6e\nmov     rdx, rax                                                       ; +0x54, 0x14033ed74\nmov     rcx, rbx                                                       ; +0x57, 0x14033ed77\ncall    MusicDownloadManager__removeDLFromActive                       ; +0x5a, 0x14033ed7a\nmov     rcx, rbx                                                       ; +0x5f, 0x14033ed7f\ncmp     byte ptr [rdi+40h], 0                                          ; +0x62, 0x14033ed82\njnz     short loc_14033EDA8                                            ; +0x66, 0x14033ed86\nmov     rdx, [rdi+38h]                                                 ; +0x68, 0x14033ed88\nmovzx   eax, byte ptr [rdx+0CCh]                                       ; +0x6c, 0x14033ed8c\nneg     al                                                             ; +0x73, 0x14033ed93\nsbb     r8d, r8d                                                       ; +0x75, 0x14033ed95\nand     r8d, 3                                                         ; +0x78, 0x14033ed98\nmov     edx, esi                                                       ; +0x7c, 0x14033ed9c\ncall    MusicDownloadManager__downloadSongFailed                       ; +0x7e, 0x14033ed9e\njmp     loc_14033EF9B                                                  ; +0x83, 0x14033eda3\nmov     r8d, esi                                                       ; +0x88, 0x14033eda8\nlea     rdx, [rsp+88h+FileName]                                        ; +0x8b, 0x14033edab\ncall    MusicDownloadManager__pathForSong                              ; +0x90, 0x14033edb0\nnop                                                                    ; +0x95, 0x14033edb5\nlea     rcx, [rsp+88h+FileName]                                        ; +0x96, 0x14033edb6\ncmp     [rsp+88h+var_28], 0Fh                                          ; +0x9b, 0x14033edbb\ncmova   rcx, [rsp+88h+FileName]; FileName                              ; +0xa1, 0x14033edc1\nlea     rdx, Mode; \"wb\"                                                ; +0xa7, 0x14033edc7\ncall    cs:fopen                                                       ; +0xae, 0x14033edce\nmov     rbp, rax                                                       ; +0xb4, 0x14033edd4\ntest    rax, rax                                                       ; +0xb7, 0x14033edd7\njnz     short loc_14033EDEE                                            ; +0xba, 0x14033edda\nxor     r8d, r8d                                                       ; +0xbc, 0x14033eddc\nmov     edx, esi                                                       ; +0xbf, 0x14033eddf\nmov     rcx, rbx                                                       ; +0xc1, 0x14033ede1\ncall    MusicDownloadManager__downloadSongFailed                       ; +0xc4, 0x14033ede4\njmp     loc_14033EF91                                                  ; +0xc9, 0x14033ede9\nmov     rcx, [rdi+48h]; Buffer                                         ; +0xce, 0x14033edee\nmov     r8, [rdi+50h]                                                  ; +0xd2, 0x14033edf2\nsub     r8, rcx; ElementCount                                          ; +0xd6, 0x14033edf6\nmov     r9, rbp; Stream                                                ; +0xd9, 0x14033edf9\nmov     edx, 1; ElementSize                                            ; +0xdc, 0x14033edfc\ncall    cs:fwrite                                                      ; +0xe1, 0x14033ee01\nmov     rcx, rbp; Stream                                               ; +0xe7, 0x14033ee07\ncall    cs:fclose                                                      ; +0xea, 0x14033ee0a\nmov     edx, esi                                                       ; +0xf0, 0x14033ee10\nmov     rcx, rbx                                                       ; +0xf2, 0x14033ee12\ncall    MusicDownloadManager__getSongInfoObject                        ; +0xf5, 0x14033ee15\ntest    rax, rax                                                       ; +0xfa, 0x14033ee1a\njz      short loc_14033EE31                                            ; +0xfd, 0x14033ee1d\ninc     dword ptr [rbx+168h]                                           ; +0xff, 0x14033ee1f\nmov     ecx, [rbx+168h]                                                ; +0x105, 0x14033ee25\nmov     [rax+23Ch], ecx                                                ; +0x10b, 0x14033ee2b\nmov     rcx, cs:qword_1406C2ED8                                        ; +0x111, 0x14033ee31\ntest    rcx, rcx                                                       ; +0x118, 0x14033ee38\njnz     short loc_14033EE6C                                            ; +0x11b, 0x14033ee3b\nmov     ecx, 668h; Size                                                ; +0x11d, 0x14033ee3d\ncall    ??2@YAPEAX_K@Z; operator new(unsigned __int64)                 ; +0x122, 0x14033ee42\nmov     [rsp+88h+var_68], rax                                          ; +0x127, 0x14033ee47\nmov     rcx, rax                                                       ; +0x12c, 0x14033ee4c\ncall    sub_14017AB00                                                  ; +0x12f, 0x14033ee4f\nnop                                                                    ; +0x134, 0x14033ee54\nmov     cs:qword_1406C2ED8, rax                                        ; +0x135, 0x14033ee55\nmov     rdx, [rax]                                                     ; +0x13c, 0x14033ee5c\nmov     rcx, rax                                                       ; +0x13f, 0x14033ee5f\ncall    qword ptr [rdx+48h]                                            ; +0x142, 0x14033ee62\nmov     rcx, cs:qword_1406C2ED8                                        ; +0x145, 0x14033ee65\nlea     rdx, a0018; \"0018\"                                             ; +0x14c, 0x14033ee6c\ncall    GameManager__getGameVariable                                   ; +0x153, 0x14033ee73\ntest    al, al                                                         ; +0x158, 0x14033ee78\njnz     loc_14033EF42                                                  ; +0x15a, 0x14033ee7a\nmov     rax, cs:qword_1406C2ED8                                        ; +0x160, 0x14033ee80\ntest    rax, rax                                                       ; +0x167, 0x14033ee87\njnz     short loc_14033EEBB                                            ; +0x16a, 0x14033ee8a\nmov     ecx, 668h; Size                                                ; +0x16c, 0x14033ee8c\ncall    ??2@YAPEAX_K@Z; operator new(unsigned __int64)                 ; +0x171, 0x14033ee91\nmov     [rsp+88h+var_68], rax                                          ; +0x176, 0x14033ee96\nmov     rcx, rax                                                       ; +0x17b, 0x14033ee9b\ncall    sub_14017AB00                                                  ; +0x17e, 0x14033ee9e\nnop                                                                    ; +0x183, 0x14033eea3\nmov     cs:qword_1406C2ED8, rax                                        ; +0x184, 0x14033eea4\nmov     rdx, [rax]                                                     ; +0x18b, 0x14033eeab\nmov     rcx, rax                                                       ; +0x18e, 0x14033eeae\ncall    qword ptr [rdx+48h]                                            ; +0x191, 0x14033eeb1\nmov     rax, cs:qword_1406C2ED8                                        ; +0x194, 0x14033eeb4\nmov     r14d, [rax+438h]                                               ; +0x19b, 0x14033eebb\nmov     ebp, [rax+43Ch]                                                ; +0x1a2, 0x14033eec2\nmov     rcx, rbx                                                       ; +0x1a8, 0x14033eec8\ncall    MusicDownloadManager__getDownloadedSongs                       ; +0x1ab, 0x14033eecb\nmov     rdi, rax                                                       ; +0x1b0, 0x14033eed0\nmov     rcx, rax                                                       ; +0x1b3, 0x14033eed3\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x1b6, 0x14033eed6\ncmp     eax, 32h ; '2'                                                 ; +0x1bc, 0x14033eedc\njbe     short loc_14033EF42                                            ; +0x1bf, 0x14033eedf\nmov     rcx, rdi                                                       ; +0x1c1, 0x14033eee1\ncall    cs:?lastObject@CCArray@cocos2d@@QEAAPEAVCCObject@2@XZ; cocos2d::CCArray::lastObject(void) ; +0x1c4, 0x14033eee4\nmov     r8d, [rax+140h]                                                ; +0x1ca, 0x14033eeea\ncmp     r8d, r14d                                                      ; +0x1d1, 0x14033eef1\njz      short loc_14033EF29                                            ; +0x1d4, 0x14033eef4\ncmp     r8d, ebp                                                       ; +0x1d6, 0x14033eef6\njz      short loc_14033EF29                                            ; +0x1d9, 0x14033eef9\nlea     rdx, [rsp+88h+var_60]                                          ; +0x1db, 0x14033eefb\nmov     rcx, rbx                                                       ; +0x1e0, 0x14033ef00\ncall    MusicDownloadManager__pathForSong                              ; +0x1e3, 0x14033ef03\nlea     rcx, [rsp+88h+var_60]                                          ; +0x1e8, 0x14033ef08\ncmp     [rsp+88h+var_48], 0Fh                                          ; +0x1ed, 0x14033ef0d\ncmova   rcx, [rsp+88h+var_60]; FileName                                ; +0x1f3, 0x14033ef13\ncall    cs:remove                                                      ; +0x1f9, 0x14033ef19\nlea     rcx, [rsp+88h+var_60]                                          ; +0x1ff, 0x14033ef1f\ncall    sub_14003A830                                                  ; +0x204, 0x14033ef24\nmov     dl, 1                                                          ; +0x209, 0x14033ef29\nmov     rcx, rdi                                                       ; +0x20b, 0x14033ef2b\ncall    cs:?removeLastObject@CCArray@cocos2d@@QEAAX_N@Z; cocos2d::CCArray::removeLastObject(bool) ; +0x20e, 0x14033ef2e\nmov     rcx, rdi                                                       ; +0x214, 0x14033ef34\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x217, 0x14033ef37\ncmp     eax, 32h ; '2'                                                 ; +0x21d, 0x14033ef3d\nja      short loc_14033EEE1                                            ; +0x220, 0x14033ef40\nxor     edi, edi                                                       ; +0x222, 0x14033ef42\nmov     rcx, [rbx+150h]                                                ; +0x224, 0x14033ef44\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x22b, 0x14033ef4b\ntest    eax, eax                                                       ; +0x231, 0x14033ef51\njz      short loc_14033EF91                                            ; +0x233, 0x14033ef53\nnop     word ptr [rax+rax+00000000h]                                   ; +0x235, 0x14033ef55\nmov     edx, edi                                                       ; +0x240, 0x14033ef60\nmov     rcx, [rbx+150h]                                                ; +0x242, 0x14033ef62\ncall    cs:?objectAtIndex@CCArray@cocos2d@@QEAAPEAVCCObject@2@I@Z; cocos2d::CCArray::objectAtIndex(uint) ; +0x249, 0x14033ef69\nmov     rcx, [rax+140h]                                                ; +0x24f, 0x14033ef6f\nmov     rax, [rcx]                                                     ; +0x256, 0x14033ef76\nmov     edx, esi                                                       ; +0x259, 0x14033ef79\ncall    qword ptr [rax+18h]                                            ; +0x25b, 0x14033ef7b\ninc     edi                                                            ; +0x25e, 0x14033ef7e\nmov     rcx, [rbx+150h]                                                ; +0x260, 0x14033ef80\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x267, 0x14033ef87\ncmp     edi, eax                                                       ; +0x26d, 0x14033ef8d\njb      short loc_14033EF60                                            ; +0x26f, 0x14033ef8f\nlea     rcx, [rsp+88h+FileName]                                        ; +0x271, 0x14033ef91\ncall    sub_14003A830                                                  ; +0x276, 0x14033ef96\nmov     rcx, [rsp+88h+var_20]                                          ; +0x27b, 0x14033ef9b\nxor     rcx, rsp; StackCookie                                          ; +0x280, 0x14033efa0\ncall    __security_check_cookie                                        ; +0x283, 0x14033efa3\nlea     r11, [rsp+88h+var_18]                                          ; +0x288, 0x14033efa8\nmov     rbx, [r11+28h]                                                 ; +0x28d, 0x14033efad\nmov     rbp, [r11+38h]                                                 ; +0x291, 0x14033efb1\nmov     rsp, r11                                                       ; +0x295, 0x14033efb5\npop     r14                                                            ; +0x298, 0x14033efb8\npop     rdi                                                            ; +0x29a, 0x14033efba\npop     rsi                                                            ; +0x29b, 0x14033efbb\nretn                                                                   ; +0x29c, 0x14033efbc", "xrefs": ["MusicDownloadManager::downloadSong @ 0x14033ec09", "MusicDownloadManager::downloadCustomSong @ 0x1403404e0", "<???> @ 0x1406d569c"], "is_objc": false, "is_arm32": false, "is_arm64": false, "bida_info": "8.0.0 @ https://github.com/Stazzical/BromaIDA", "bindings_info": "commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings"}