{"type": "func", "start": 5373444144, "end": 5373444829, "name": "MusicDownloadManager::onDownloadSongCompleted", "pseudocode": "// \n// MusicDownloadManager::onDownloadSongCompleted from 0x140484030 to 0x1404842dd (685 bytes)\n// \n// 3 xrefs:\n// > MusicDownloadManager::downloadSong @ 0x140483ef9\n// > MusicDownloadManager::downloadCustomSong @ 0x14048c600\n// > <???> @ 0x140928a90\n// \n// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!\n// \n// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA\n// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings\n// Generated at Fri, 27 Nov 2026 11:32:46 +0000\n// \n\n// Hidden C++ exception states: #wind=4\nvoid __fastcall MusicDownloadManager::onDownloadSongCompleted(__int64 a1, __int64 a2, __int64 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  __int64 SongInfoObject; // rax\n  __int64 v13; // rcx\n  __int64 v14; // rax\n  int v15; // r14d\n  int v16; // ebp\n  cocos2d::CCArray *i; // rdi\n  __int64 v18; // 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(*(cocos2d::extension::CCHttpRequest **)(a3 + 56));\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 ( *(_BYTE *)(a3 + 64) )\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(*(const void **)(a3 + 72), 1u, *(_QWORD *)(a3 + 80) - *(_QWORD *)(a3 + 72), v10);\n      fclose(v11);\n      SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v6);\n      if ( SongInfoObject )\n        *(_DWORD *)(SongInfoObject + 476) = ++*(_DWORD *)(a1 + 360);\n      v13 = qword_14090BFD0;\n      if ( !qword_14090BFD0 )\n      {\n        v22 = operator new(0x6E8u);\n        qword_14090BFD0 = GameManager::GameManager((__int64)v22);\n        (*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);\n        v13 = qword_14090BFD0;\n      }\n      if ( !GameManager::getGameVariable(v13, \"0018\") )\n      {\n        v14 = qword_14090BFD0;\n        if ( !qword_14090BFD0 )\n        {\n          v23 = operator new(0x6E8u);\n          qword_14090BFD0 = GameManager::GameManager((__int64)v23);\n          (*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);\n          v14 = qword_14090BFD0;\n        }\n        v15 = *(_DWORD *)(v14 + 1164);\n        v16 = *(_DWORD *)(v14 + 1168);\n        for ( i = MusicDownloadManager::getDownloadedSongs(a1);\n              cocos2d::CCArray::count(i) > 0x32;\n              cocos2d::CCArray::removeLastObject(i, 1) )\n        {\n          v18 = *((unsigned int *)cocos2d::CCArray::lastObject(i) + 80);\n          if ( (_DWORD)v18 != v15 && (_DWORD)v18 != v16 )\n          {\n            MusicDownloadManager::pathForSong(a1, v24, v18);\n            v19 = (const char *)v24;\n            if ( v24[3] > (char *)0xF )\n              v19 = v24[0];\n            remove(v19);\n            sub_14003D310((__int64)v24);\n          }\n        }\n      }\n      for ( j = 0; j < cocos2d::CCArray::count(*(cocos2d::CCArray **)(a1 + 336)); ++j )\n      {\n        v21 = cocos2d::CCArray::objectAtIndex(*(cocos2d::CCArray **)(a1 + 336), j);\n        (*(void (__fastcall **)(_QWORD, _QWORD))(**((_QWORD **)v21 + 40) + 24LL))(*((_QWORD *)v21 + 40), v6);\n      }\n    }\n    else\n    {\n      MusicDownloadManager::downloadSongFailed(a1, v6, 0);\n    }\n    sub_14003D310((__int64)FileName);\n  }\n  else\n  {\n    MusicDownloadManager::downloadSongFailed(a1, v6, *(_BYTE *)(*(_QWORD *)(a3 + 56) + 204LL) != 0 ? 3 : 0);\n  }\n}", "assembly": "; \n; MusicDownloadManager::onDownloadSongCompleted from 0x140484030 to 0x1404842dd (685 bytes)\n; \n; 3 xrefs:\n; > MusicDownloadManager::downloadSong @ 0x140483ef9\n; > MusicDownloadManager::downloadCustomSong @ 0x14048c600\n; > <???> @ 0x140928a90\n; \n; This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!\n; \n; Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA\n; Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings\n; Generated at Fri, 27 Nov 2026 11:32:46 +0000\n; \nmov     [rsp+arg_8], rbx                                               ; +0x0, 0x140484030\nmov     [rsp+arg_18], rbp                                              ; +0x5, 0x140484035\npush    rsi                                                            ; +0xa, 0x14048403a\npush    rdi                                                            ; +0xb, 0x14048403b\npush    r14                                                            ; +0xc, 0x14048403c\nsub     rsp, 70h                                                       ; +0xe, 0x14048403e\nmov     rax, cs:__security_cookie                                      ; +0x12, 0x140484042\nxor     rax, rsp                                                       ; +0x19, 0x140484049\nmov     [rsp+88h+var_20], rax                                          ; +0x1c, 0x14048404c\nmov     rdi, r8                                                        ; +0x21, 0x140484051\nmov     rbx, rcx                                                       ; +0x24, 0x140484054\nmov     rcx, [r8+38h]                                                  ; +0x27, 0x140484057\ncall    cs:?getTag@CCHttpRequest@extension@cocos2d@@QEAAPEBDXZ; cocos2d::extension::CCHttpRequest::getTag(void) ; +0x2b, 0x14048405b\nmov     rcx, rax; String                                               ; +0x31, 0x140484061\ncall    cs:atoi                                                        ; +0x34, 0x140484064\nmov     esi, eax                                                       ; +0x3a, 0x14048406a\nmov     edx, eax                                                       ; +0x3c, 0x14048406c\nlea     rcx, aDI; \"d_%i\"                                               ; +0x3e, 0x14048406e\ncall    cs:?createWithFormat@CCString@cocos2d@@SAPEAV12@PEBDZZ; cocos2d::CCString::createWithFormat(char const *,...) ; +0x45, 0x140484075\nmov     rcx, rax                                                       ; +0x4b, 0x14048407b\ncall    cs:?getCString@CCString@cocos2d@@QEBAPEBDXZ; cocos2d::CCString::getCString(void) ; +0x4e, 0x14048407e\nmov     rdx, rax                                                       ; +0x54, 0x140484084\nmov     rcx, rbx                                                       ; +0x57, 0x140484087\ncall    MusicDownloadManager__removeDLFromActive                       ; +0x5a, 0x14048408a\nmov     rcx, rbx                                                       ; +0x5f, 0x14048408f\ncmp     byte ptr [rdi+40h], 0                                          ; +0x62, 0x140484092\njnz     short loc_1404840BA                                            ; +0x66, 0x140484096\nmov     rdx, [rdi+38h]                                                 ; +0x68, 0x140484098\nmovzx   r8d, byte ptr [rdx+0CCh]                                       ; +0x6c, 0x14048409c\nneg     r8b                                                            ; +0x74, 0x1404840a4\nsbb     r8d, r8d                                                       ; +0x77, 0x1404840a7\nand     r8d, 3                                                         ; +0x7a, 0x1404840aa\nmov     edx, esi                                                       ; +0x7e, 0x1404840ae\ncall    MusicDownloadManager__downloadSongFailed                       ; +0x80, 0x1404840b0\njmp     loc_1404842BB                                                  ; +0x85, 0x1404840b5\nmov     r8d, esi                                                       ; +0x8a, 0x1404840ba\nlea     rdx, [rsp+88h+FileName]                                        ; +0x8d, 0x1404840bd\ncall    MusicDownloadManager__pathForSong                              ; +0x92, 0x1404840c2\nnop                                                                    ; +0x97, 0x1404840c7\nlea     rcx, [rsp+88h+FileName]                                        ; +0x98, 0x1404840c8\ncmp     [rsp+88h+var_28], 0Fh                                          ; +0x9d, 0x1404840cd\ncmova   rcx, [rsp+88h+FileName]; FileName                              ; +0xa3, 0x1404840d3\nlea     rdx, aWb; \"wb\"                                                 ; +0xa9, 0x1404840d9\ncall    cs:fopen                                                       ; +0xb0, 0x1404840e0\nmov     rbp, rax                                                       ; +0xb6, 0x1404840e6\ntest    rax, rax                                                       ; +0xb9, 0x1404840e9\njnz     short loc_140484100                                            ; +0xbc, 0x1404840ec\nxor     r8d, r8d                                                       ; +0xbe, 0x1404840ee\nmov     edx, esi                                                       ; +0xc1, 0x1404840f1\nmov     rcx, rbx                                                       ; +0xc3, 0x1404840f3\ncall    MusicDownloadManager__downloadSongFailed                       ; +0xc6, 0x1404840f6\njmp     loc_1404842B1                                                  ; +0xcb, 0x1404840fb\nmov     rcx, [rdi+48h]; Buffer                                         ; +0xd0, 0x140484100\nmov     r8, [rdi+50h]                                                  ; +0xd4, 0x140484104\nsub     r8, rcx; ElementCount                                          ; +0xd8, 0x140484108\nmov     r9, rbp; Stream                                                ; +0xdb, 0x14048410b\nmov     edx, 1; ElementSize                                            ; +0xde, 0x14048410e\ncall    cs:fwrite                                                      ; +0xe3, 0x140484113\nmov     rcx, rbp; Stream                                               ; +0xe9, 0x140484119\ncall    cs:fclose                                                      ; +0xec, 0x14048411c\nmov     edx, esi                                                       ; +0xf2, 0x140484122\nmov     rcx, rbx                                                       ; +0xf4, 0x140484124\ncall    MusicDownloadManager__getSongInfoObject                        ; +0xf7, 0x140484127\ntest    rax, rax                                                       ; +0xfc, 0x14048412c\njz      short loc_140484143                                            ; +0xff, 0x14048412f\ninc     dword ptr [rbx+168h]                                           ; +0x101, 0x140484131\nmov     ecx, [rbx+168h]                                                ; +0x107, 0x140484137\nmov     [rax+1DCh], ecx                                                ; +0x10d, 0x14048413d\nmov     rcx, cs:qword_14090BFD0                                        ; +0x113, 0x140484143\ntest    rcx, rcx                                                       ; +0x11a, 0x14048414a\njnz     short loc_140484181                                            ; +0x11d, 0x14048414d\nmov     ecx, 6E8h; Size                                                ; +0x11f, 0x14048414f\ncall    ??2@YAPEAX_K@Z; operator new(unsigned __int64)                 ; +0x124, 0x140484154\nmov     [rsp+88h+var_68], rax                                          ; +0x129, 0x140484159\nmov     rcx, rax                                                       ; +0x12e, 0x14048415e\ncall    GameManager__GameManager                                       ; +0x131, 0x140484161\nnop                                                                    ; +0x136, 0x140484166\nmov     cs:qword_14090BFD0, rax                                        ; +0x137, 0x140484167\nmov     rcx, [rax]                                                     ; +0x13e, 0x14048416e\nmov     rdx, [rcx+48h]                                                 ; +0x141, 0x140484171\nmov     rcx, rax                                                       ; +0x145, 0x140484175\ncall    rdx                                                            ; +0x148, 0x140484178\nmov     rcx, cs:qword_14090BFD0                                        ; +0x14a, 0x14048417a\nlea     rdx, a0018; \"0018\"                                             ; +0x151, 0x140484181\ncall    GameManager__getGameVariable                                   ; +0x158, 0x140484188\ntest    al, al                                                         ; +0x15d, 0x14048418d\njnz     loc_140484261                                                  ; +0x15f, 0x14048418f\nmov     rax, cs:qword_14090BFD0                                        ; +0x165, 0x140484195\ntest    rax, rax                                                       ; +0x16c, 0x14048419c\njnz     short loc_1404841D3                                            ; +0x16f, 0x14048419f\nmov     ecx, 6E8h; Size                                                ; +0x171, 0x1404841a1\ncall    ??2@YAPEAX_K@Z; operator new(unsigned __int64)                 ; +0x176, 0x1404841a6\nmov     [rsp+88h+var_68], rax                                          ; +0x17b, 0x1404841ab\nmov     rcx, rax                                                       ; +0x180, 0x1404841b0\ncall    GameManager__GameManager                                       ; +0x183, 0x1404841b3\nnop                                                                    ; +0x188, 0x1404841b8\nmov     cs:qword_14090BFD0, rax                                        ; +0x189, 0x1404841b9\nmov     rcx, [rax]                                                     ; +0x190, 0x1404841c0\nmov     rdx, [rcx+48h]                                                 ; +0x193, 0x1404841c3\nmov     rcx, rax                                                       ; +0x197, 0x1404841c7\ncall    rdx                                                            ; +0x19a, 0x1404841ca\nmov     rax, cs:qword_14090BFD0                                        ; +0x19c, 0x1404841cc\nmov     r14d, [rax+48Ch]                                               ; +0x1a3, 0x1404841d3\nmov     ebp, [rax+490h]                                                ; +0x1aa, 0x1404841da\nmov     rcx, rbx                                                       ; +0x1b0, 0x1404841e0\ncall    MusicDownloadManager__getDownloadedSongs                       ; +0x1b3, 0x1404841e3\nmov     rdi, rax                                                       ; +0x1b8, 0x1404841e8\nmov     rcx, rax                                                       ; +0x1bb, 0x1404841eb\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x1be, 0x1404841ee\ncmp     eax, 32h ; '2'                                                 ; +0x1c4, 0x1404841f4\njbe     short loc_140484261                                            ; +0x1c7, 0x1404841f7\nnop     dword ptr [rax+00000000h]                                      ; +0x1c9, 0x1404841f9\nmov     rcx, rdi                                                       ; +0x1d0, 0x140484200\ncall    cs:?lastObject@CCArray@cocos2d@@QEAAPEAVCCObject@2@XZ; cocos2d::CCArray::lastObject(void) ; +0x1d3, 0x140484203\nmov     r8d, [rax+140h]                                                ; +0x1d9, 0x140484209\ncmp     r8d, r14d                                                      ; +0x1e0, 0x140484210\njz      short loc_140484248                                            ; +0x1e3, 0x140484213\ncmp     r8d, ebp                                                       ; +0x1e5, 0x140484215\njz      short loc_140484248                                            ; +0x1e8, 0x140484218\nlea     rdx, [rsp+88h+var_60]                                          ; +0x1ea, 0x14048421a\nmov     rcx, rbx                                                       ; +0x1ef, 0x14048421f\ncall    MusicDownloadManager__pathForSong                              ; +0x1f2, 0x140484222\nlea     rcx, [rsp+88h+var_60]                                          ; +0x1f7, 0x140484227\ncmp     [rsp+88h+var_48], 0Fh                                          ; +0x1fc, 0x14048422c\ncmova   rcx, [rsp+88h+var_60]; FileName                                ; +0x202, 0x140484232\ncall    cs:remove                                                      ; +0x208, 0x140484238\nlea     rcx, [rsp+88h+var_60]                                          ; +0x20e, 0x14048423e\ncall    sub_14003D310                                                  ; +0x213, 0x140484243\nmov     dl, 1                                                          ; +0x218, 0x140484248\nmov     rcx, rdi                                                       ; +0x21a, 0x14048424a\ncall    cs:?removeLastObject@CCArray@cocos2d@@QEAAX_N@Z; cocos2d::CCArray::removeLastObject(bool) ; +0x21d, 0x14048424d\nmov     rcx, rdi                                                       ; +0x223, 0x140484253\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x226, 0x140484256\ncmp     eax, 32h ; '2'                                                 ; +0x22c, 0x14048425c\nja      short loc_140484200                                            ; +0x22f, 0x14048425f\nxor     edi, edi                                                       ; +0x231, 0x140484261\nmov     rcx, [rbx+150h]                                                ; +0x233, 0x140484263\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x23a, 0x14048426a\ntest    eax, eax                                                       ; +0x240, 0x140484270\njz      short loc_1404842B1                                            ; +0x242, 0x140484272\nnop     dword ptr [rax+00h]                                            ; +0x244, 0x140484274\nnop     dword ptr [rax+rax+00000000h]                                  ; +0x248, 0x140484278\nmov     edx, edi                                                       ; +0x250, 0x140484280\nmov     rcx, [rbx+150h]                                                ; +0x252, 0x140484282\ncall    cs:?objectAtIndex@CCArray@cocos2d@@QEAAPEAVCCObject@2@I@Z; cocos2d::CCArray::objectAtIndex(uint) ; +0x259, 0x140484289\nmov     rcx, [rax+140h]                                                ; +0x25f, 0x14048428f\nmov     rax, [rcx]                                                     ; +0x266, 0x140484296\nmov     edx, esi                                                       ; +0x269, 0x140484299\ncall    qword ptr [rax+18h]                                            ; +0x26b, 0x14048429b\ninc     edi                                                            ; +0x26e, 0x14048429e\nmov     rcx, [rbx+150h]                                                ; +0x270, 0x1404842a0\ncall    cs:?count@CCArray@cocos2d@@QEBAIXZ; cocos2d::CCArray::count(void) ; +0x277, 0x1404842a7\ncmp     edi, eax                                                       ; +0x27d, 0x1404842ad\njb      short loc_140484280                                            ; +0x27f, 0x1404842af\nlea     rcx, [rsp+88h+FileName]                                        ; +0x281, 0x1404842b1\ncall    sub_14003D310                                                  ; +0x286, 0x1404842b6\nmov     rcx, [rsp+88h+var_20]                                          ; +0x28b, 0x1404842bb\nxor     rcx, rsp; StackCookie                                          ; +0x290, 0x1404842c0\ncall    __security_check_cookie                                        ; +0x293, 0x1404842c3\nlea     r11, [rsp+88h+var_18]                                          ; +0x298, 0x1404842c8\nmov     rbx, [r11+28h]                                                 ; +0x29d, 0x1404842cd\nmov     rbp, [r11+38h]                                                 ; +0x2a1, 0x1404842d1\nmov     rsp, r11                                                       ; +0x2a5, 0x1404842d5\npop     r14                                                            ; +0x2a8, 0x1404842d8\npop     rdi                                                            ; +0x2aa, 0x1404842da\npop     rsi                                                            ; +0x2ab, 0x1404842db\nretn                                                                   ; +0x2ac, 0x1404842dc", "xrefs": ["MusicDownloadManager::downloadSong @ 0x140483ef9", "MusicDownloadManager::downloadCustomSong @ 0x14048c600", "<???> @ 0x140928a90"], "is_objc": false, "is_32_bit": false, "is_64_bit": true, "idp_name": "pc", "bida_info": "8.3.0 @ https://github.com/Stazzical/BromaIDA", "bindings_info": "commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings"}