//
// MusicSearchResult::updateObjects from 0x140347330 to 0x140347872 (1346 bytes)
//
// 5 xrefs:
// > ??> @ 0x1405ad4a0
// > ??> @ 0x140695e94
// > ??> @ 0x140695edc
// > ??> @ 0x140695eec
// > ??> @ 0x1406d5954
//
// 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 MusicSearchResult::updateObjects(MusicSearchResult *a1, AudioSortType a2)
{
__int64 m_songType; // rdi
AudioSortType v4; // r12d
MusicDownloadManager *v5; // rbx
unsigned int v6; // eax
struct cocos2d::CCArray *v7; // rax
cocos2d::CCDictionary *m_musicObjects; // rdx
cocos2d::CCArray *v9; // r13
cocos2d::CCDictElement *m_pElements; // rdx
cocos2d::CCDictElement *i; // rbx
cocos2d::CCObject **p_m_tagFilterObjects; // rdi
OptionsObjectDelegate *v13; // r14
MusicDownloadManager *v14; // rbp
struct cocos2d::CCArray *v15; // rax
_QWORD *Myhead; // rcx
cocos2d::CCArray *v17; // rsi
_QWORD *k; // rbx
__int64 v19; // rax
__int64 v20; // rdx
char *v21; // rax
__int64 **v22; // rax
__int64 j; // rax
__int64 *v24; // rcx
cocos2d::CCArray **v25; // rbx
cocos2d::CCObject **p_m_artistFilterObjects; // rdi
OptionsObjectDelegate *v27; // rbp
MusicDownloadManager *v28; // rbx
unsigned int v29; // eax
struct cocos2d::CCArray *v30; // rax
cocos2d::CCDictionary *m_musicArtists; // rbx
cocos2d::CCArray *v32; // rsi
cocos2d::CCDictElement *v33; // rbx
cocos2d::CCDictElement *m; // rdi
cocos2d::CCObject *m_pObject; // rbx
__int64 v36; // rax
__int64 v37; // rdx
char *v38; // rax
cocos2d::CCArray **v39; // rbx
cocos2d::CCArray *FilesMatchingSearch; // r14
__int64 v41; // rax
__int64 v42; // rcx
cocos2d::CCArray *v43; // rbp
cocos2d::CCObject_vtbl *v44; // rsi
__int64 copyWithZone_low; // rax
bool (__fastcall *isEqual)(cocos2d::CCObject *__hidden, const cocos2d::CCObject *); // rsi
bool (__fastcall *n)(cocos2d::CCObject *__hidden, const cocos2d::CCObject *); // r12
__int64 v48; // rbx
MusicDownloadManager *v49; // rcx
cocos2d::CCArray *v50; // rax
cocos2d::ccArray *data; // rbx
__int64 num; // rax
struct cocos2d::CCObject **arr; // rbx
struct cocos2d::CCObject **ii; // rdi
cocos2d::CCArray *v55; // rsi
unsigned int v56; // eax
cocos2d::CCArray *m_tagFilterObjects; // rdi
unsigned int v58; // r14d
cocos2d::ccArray *v59; // rdi
__int64 v60; // rax
cocos2d::CCObject **v61; // rdi
cocos2d::CCObject **jj; // rbp
cocos2d::CCObject *v63; // rbx
unsigned int v64; // eax
MusicDownloadManager *v65; // rcx
cocos2d::CCArray *v66; // rax
cocos2d::CCArray *v67; // rax
cocos2d::CCArray *m_artistFilterObjects; // rbx
cocos2d::CCArray *v69; // r14
cocos2d::ccArray *v70; // rbx
__int64 v71; // rax
cocos2d::CCObject **v72; // rbx
cocos2d::CCObject **kk; // rbp
cocos2d::CCObject *v74; // rdi
MusicDownloadManager *v75; // rcx
cocos2d::CCArray *v76; // rax
int (__cdecl *v77)(const void *, const void *); // r9
cocos2d::CCArray *m_filterObjects; // rcx
_BYTE v79[32]; // [rsp+20h] [rbp-58h] BYREF
m_songType = a1->m_songType;
v4 = a2;
a1->m_sortType = a2;
v5 = MusicDownloadManager::sharedState();
v6 = cocos2d::CCDictionary::count(v5->m_musicObjects);
v7 = cocos2d::CCArray::createWithCapacity(v6);
m_musicObjects = v5->m_musicObjects;
v9 = v7;
if ( m_musicObjects )
{
m_pElements = m_musicObjects->m_pElements;
if ( m_pElements )
{
for ( i = (cocos2d::CCDictElement *)m_pElements->hh.next; ; i = (cocos2d::CCDictElement *)i->hh.next )
{
if ( m_songType == -1 || m_pElements->m_pObject[9].m_uAutoReleaseCount == (_DWORD)m_songType )
cocos2d::CCArray::addObject(v9, m_pElements->m_pObject);
m_pElements = i;
if ( !i )
break;
}
}
}
p_m_tagFilterObjects = &a1->m_tagFilterObjects;
if ( !a1->m_tagFilterObjects )
{
v13 = &a1->OptionsObjectDelegate;
if ( !a1 )
v13 = nullptr;
v14 = MusicDownloadManager::sharedState();
v15 = cocos2d::CCArray::createWithCapacity(v14->m_musicTags._Mypair._Myval2._Myval2._Mysize);
Myhead = v14->m_musicTags._Mypair._Myval2._Myval2._Myhead;
v17 = v15;
k = (_QWORD *)*Myhead;
if ( (_QWORD *)*Myhead != Myhead )
{
do
{
v19 = sub_14003BDB0((__int64)v79, (__int64)(k + 5));
v21 = OptionsObject::create(*((_DWORD *)k + 8), v20, v19, (__int64)v13);
cocos2d::CCArray::addObject(v17, (struct cocos2d::CCObject *)v21);
v22 = (__int64 **)k[2];
if ( *((_BYTE *)v22 + 25) )
{
for ( j = k[1]; !*(_BYTE *)(j + 25); j = *(_QWORD *)(j + 8) )
{
if ( k != *(_QWORD **)(j + 16) )
break;
k = (_QWORD *)j;
}
k = (_QWORD *)j;
}
else
{
v24 = *v22;
for ( k = (_QWORD *)k[2]; !*((_BYTE *)v24 + 25); v24 = (__int64 *)*v24 )
k = v24;
}
}
while ( k != (_QWORD *)v14->m_musicTags._Mypair._Myval2._Myval2._Myhead );
p_m_tagFilterObjects = &a1->m_tagFilterObjects;
}
if ( cocos2d::CCArray::count(v17) > 1 )
qsort(v17->data->arr, v17->data->num, 8u, (_CoreCrtNonSecureSearchSortCompareFunction)sub_14033CA90);
if ( *p_m_tagFilterObjects != v17 )
{
v25 = (cocos2d::CCArray **)p_m_tagFilterObjects;
if ( v17 )
{
cocos2d::CCObject::retain(v17);
v25 = &a1->m_tagFilterObjects;
}
if ( *p_m_tagFilterObjects )
{
cocos2d::CCObject::release(*p_m_tagFilterObjects);
p_m_tagFilterObjects = v25;
}
*p_m_tagFilterObjects = v17;
}
}
p_m_artistFilterObjects = &a1->m_artistFilterObjects;
if ( !a1->m_artistFilterObjects )
{
v27 = &a1->OptionsObjectDelegate;
if ( !a1 )
v27 = nullptr;
v28 = MusicDownloadManager::sharedState();
v29 = cocos2d::CCDictionary::count(v28->m_musicArtists);
v30 = cocos2d::CCArray::createWithCapacity(v29);
m_musicArtists = v28->m_musicArtists;
v32 = v30;
if ( m_musicArtists )
{
v33 = m_musicArtists->m_pElements;
if ( v33 )
{
for ( m = (cocos2d::CCDictElement *)v33->hh.next; ; m = (cocos2d::CCDictElement *)m->hh.next )
{
m_pObject = v33->m_pObject;
v36 = sub_14003BDB0((__int64)v79, (__int64)&m_pObject[1].m_uID);
v38 = OptionsObject::create((int)m_pObject[1].__vftable, v37, v36, (__int64)v27);
cocos2d::CCArray::addObject(v32, (struct cocos2d::CCObject *)v38);
v33 = m;
if ( !m )
break;
}
p_m_artistFilterObjects = &a1->m_artistFilterObjects;
}
}
if ( cocos2d::CCArray::count(v32) > 1 )
qsort(v32->data->arr, v32->data->num, 8u, (_CoreCrtNonSecureSearchSortCompareFunction)sub_14033CA90);
if ( *p_m_artistFilterObjects != v32 )
{
v39 = (cocos2d::CCArray **)p_m_artistFilterObjects;
if ( v32 )
{
cocos2d::CCObject::retain(v32);
v39 = &a1->m_artistFilterObjects;
}
if ( *p_m_artistFilterObjects )
{
cocos2d::CCObject::release(*p_m_artistFilterObjects);
p_m_artistFilterObjects = v39;
}
*p_m_artistFilterObjects = v32;
}
}
FilesMatchingSearch = v9;
if ( a1->m_searchQuery.m_data.m_size )
{
v41 = sub_14003BDB0((__int64)v79, (__int64)&a1->m_searchQuery);
FilesMatchingSearch = (cocos2d::CCArray *)MusicSearchResult::getFilesMatchingSearch(a1, v9, v41);
}
if ( cocos2d::CCArray::count(FilesMatchingSearch) )
{
v43 = (cocos2d::CCArray *)cocos2d::CCArray::create(v42);
a1->m_artistFilter = 0;
if ( *p_m_artistFilterObjects )
{
v44 = (*p_m_artistFilterObjects)[1].__vftable;
copyWithZone_low = LODWORD(v44->copyWithZone);
if ( (_DWORD)copyWithZone_low )
{
isEqual = v44->isEqual;
for ( n = (bool (__fastcall *)(cocos2d::CCObject *__hidden, const cocos2d::CCObject *))((char *)isEqual
+ 8 * copyWithZone_low
- 8);
(unsigned __int64)isEqual <= (unsigned __int64)n;
isEqual = (bool (__fastcall *)(cocos2d::CCObject *__hidden, const cocos2d::CCObject *))((char *)isEqual + 8) )
{
v48 = *(_QWORD *)isEqual;
if ( !*(_QWORD *)isEqual )
break;
if ( *(_BYTE *)(v48 + 60) )
{
a1->m_artistFilter = 1;
MusicDownloadManager::sharedState();
v50 = MusicDownloadManager::filterMusicByArtistID(v49, *(_DWORD *)(v48 + 56), FilesMatchingSearch);
if ( v50 )
{
data = v50->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( ii = &arr[num - 1]; arr <= ii; ++arr )
{
if ( !*arr )
break;
cocos2d::CCArray::addObject(v43, *arr);
}
}
}
}
}
v4 = a2;
}
}
if ( a1->m_artistFilter )
FilesMatchingSearch = v43;
}
v55 = MusicSearchResult::applyTagFilters(a1, FilesMatchingSearch);
v56 = cocos2d::CCArray::count(v55);
m_tagFilterObjects = a1->m_tagFilterObjects;
v58 = v56;
if ( m_tagFilterObjects )
{
v59 = m_tagFilterObjects->data;
v60 = v59->num;
if ( (_DWORD)v60 )
{
v61 = v59->arr;
for ( jj = &v61[v60 - 1]; v61 <= jj; v63[1].m_uOrderOfArrival = v64 )
{
v63 = *v61;
if ( !*v61 )
break;
if ( BYTE4(v63[1].__vftable) )
{
v64 = v58;
}
else
{
MusicDownloadManager::sharedState();
v66 = MusicDownloadManager::filterMusicByTag(v65, (int)v63[1].__vftable, v55);
v64 = cocos2d::CCArray::count(v66);
}
++v61;
}
}
}
v67 = MusicSearchResult::applyTagFilters(a1, v9);
m_artistFilterObjects = a1->m_artistFilterObjects;
v69 = v67;
if ( m_artistFilterObjects )
{
v70 = m_artistFilterObjects->data;
v71 = v70->num;
if ( (_DWORD)v71 )
{
v72 = v70->arr;
for ( kk = &v72[v71 - 1]; v72 <= kk; v74[1].m_uOrderOfArrival = cocos2d::CCArray::count(v76) )
{
v74 = *v72;
if ( !*v72 )
break;
MusicDownloadManager::sharedState();
v76 = MusicDownloadManager::filterMusicByArtistID(v75, (int)v74[1].__vftable, v69);
++v72;
}
}
}
if ( cocos2d::CCArray::count(v55) > 1 )
{
if ( v4 )
{
v77 = (int (__cdecl *)(const void *, const void *))sub_14033C560;
if ( v4 != SongOrder )
v77 = (int (__cdecl *)(const void *, const void *))sub_14033C530;
}
else
{
v77 = (int (__cdecl *)(const void *, const void *))sub_14033C590;
}
qsort(v55->data->arr, v55->data->num, 8u, v77);
}
if ( a1->m_filterObjects != v55 )
{
if ( v55 )
cocos2d::CCObject::retain(v55);
m_filterObjects = a1->m_filterObjects;
if ( m_filterObjects )
cocos2d::CCObject::release(m_filterObjects);
a1->m_filterObjects = v55;
}
}