//
// SFXSearchResult::updateObjects from 0x140347d40 to 0x140348298 (1368 bytes)
//
// 2 xrefs:
// > ??> @ 0x1405adbe8
// > ??> @ 0x1406d59c0
//
// 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=3
void SFXSearchResult::updateObjects(SFXSearchResult *m_sfxObjects, AudioSortType a2)
{
AudioSortType v2; // r13d
SFXSearchResult *v3; // r12
std::string *p_m_searchQuery; // rdi
char *v5; // rbx
const char *Elems; // rcx
__int64 v7; // rbx
struct cocos2d::CCObject *v8; // rax
struct cocos2d::CCArray *v9; // rax
cocos2d::CCArray *v10; // rbx
cocos2d::CCObject *m_filterObjects; // rcx
cocos2d::CCArray *v12; // r15
SFXFolderObject *m_folderObject; // rax
struct cocos2d::CCArray *FilesMatchingSearch; // r14
cocos2d::CCArray *v15; // rdi
struct cocos2d::CCObject *Object; // rbx
cocos2d::CCObject_vtbl *v17; // rbx
int (__fastcall *getTag)(const cocos2d::CCObject *__hidden); // rbx
__int64 v19; // rax
__int64 *v20; // rbx
__int64 *i; // rsi
__int64 v22; // rdx
cocos2d::CCArray *v23; // rcx
MusicDownloadManager *v24; // rax
unsigned int v25; // eax
cocos2d::ccArray *data; // rbx
__int64 num; // rax
struct cocos2d::CCObject **arr; // rbx
struct cocos2d::CCObject **j; // rdi
cocos2d::ccArray *v30; // rcx
__int64 v31; // rax
cocos2d::CCObject **v32; // rcx
cocos2d::CCObject **k; // rdx
GameManager *v34; // rcx
__int64 v35; // rbx
__int64 v36; // rsi
_QWORD *v37; // rax
_BYTE *v38; // rdi
cocos2d::CCArray *v39; // r15
size_t v40; // r12
struct cocos2d::CCObject *v41; // r13
size_t v42; // rdx
__int64 v43; // rbx
__int64 v44; // rsi
_QWORD *v45; // rdi
char *v46; // rax
char *v47; // r9
_QWORD *v48; // rcx
char v49; // di
cocos2d::CCObject_vtbl *v50; // rax
int (__fastcall *v51)(const cocos2d::CCObject *__hidden); // rbx
__int64 v52; // rax
__int64 *v53; // rbx
__int64 *m; // rsi
__int64 v55; // rdx
__int64 v56; // rax
int (__cdecl *v57)(const void *, const void *); // r9
cocos2d::CCObject *v58; // rcx
SFXSearchResult *v60; // [rsp+38h] [rbp-21h]
void *v61; // [rsp+40h] [rbp-19h]
_QWORD v62[2]; // [rsp+48h] [rbp-11h] BYREF
size_t v63; // [rsp+58h] [rbp-1h]
unsigned __int64 v64; // [rsp+60h] [rbp+7h]
_QWORD v65[2]; // [rsp+68h] [rbp+Fh] BYREF
size_t v66; // [rsp+78h] [rbp+1Fh]
unsigned __int64 v67; // [rsp+80h] [rbp+27h]
v2 = a2;
v3 = m_sfxObjects;
v60 = m_sfxObjects;
if ( m_sfxObjects->m_searchQuery.m_data.m_size )
{
p_m_searchQuery = &m_sfxObjects->m_searchQuery;
if ( m_sfxObjects->m_searchQuery.m_data.m_capacity <= 0xF )
{
v5 = &p_m_searchQuery->m_data.m_smallStorage._Elems[m_sfxObjects->m_searchQuery.m_data.m_size];
}
else
{
v5 = &m_sfxObjects->m_searchQuery.m_data.m_bigStorage[m_sfxObjects->m_searchQuery.m_data.m_size];
p_m_searchQuery = (std::string *)p_m_searchQuery->m_data.m_bigStorage;
}
if ( p_m_searchQuery == (std::string *)v5 )
{
LABEL_8:
Elems = v3->m_searchQuery.m_data.m_smallStorage._Elems;
if ( v3->m_searchQuery.m_data.m_capacity > 0xF )
Elems = *(const char **)Elems;
v7 = atoi(Elems);
m_sfxObjects = (SFXSearchResult *)MusicDownloadManager::sharedState()->m_sfxObjects;
if ( m_sfxObjects )
{
v8 = cocos2d::CCDictionary::objectForKey((cocos2d::CCDictionary *)m_sfxObjects, v7);
if ( v8 )
{
v9 = cocos2d::CCArray::createWithObject(v8);
v10 = v9;
if ( v3->m_filterObjects != v9 )
{
if ( v9 )
cocos2d::CCObject::retain(v9);
m_filterObjects = v3->m_filterObjects;
if ( m_filterObjects )
cocos2d::CCObject::release(m_filterObjects);
v3->m_filterObjects = v10;
}
return;
}
}
}
else
{
while ( isdigit(p_m_searchQuery->m_data.m_smallStorage._Elems[0]) )
{
p_m_searchQuery = (std::string *)((char *)p_m_searchQuery + 1);
if ( p_m_searchQuery == (std::string *)v5 )
goto LABEL_8;
}
}
}
v3->m_sortType = v2;
v12 = nullptr;
m_folderObject = v3->m_folderObject;
if ( !m_folderObject )
{
LABEL_33:
v24 = MusicDownloadManager::sharedState();
v12 = (cocos2d::CCArray *)sub_140343A30((__int64)v24);
goto LABEL_34;
}
if ( v3->m_searchQuery.m_data.m_size )
{
if ( m_folderObject->m_sfxID != 1 )
{
FilesMatchingSearch = (struct cocos2d::CCArray *)cocos2d::CCArray::create(m_sfxObjects);
v15 = cocos2d::CCArray::createWithObject(v3->m_folderObject);
while ( cocos2d::CCArray::count(v15) )
{
Object = cocos2d::CCArray::lastObject(v15);
cocos2d::CCArray::removeLastObject(v15, 1);
v17 = Object[2].__vftable;
if ( v17 )
{
getTag = v17->getTag;
v19 = *(unsigned int *)getTag;
if ( (_DWORD)v19 )
{
v20 = *((__int64 **)getTag + 2);
for ( i = &v20[v19 - 1]; v20 <= i; ++v20 )
{
v22 = *v20;
if ( !*v20 )
break;
v23 = v15;
if ( !*(_BYTE *)(v22 + 72) )
v23 = FilesMatchingSearch;
cocos2d::CCArray::addObject(v23, (struct cocos2d::CCObject *)v22);
}
}
}
}
if ( FilesMatchingSearch )
goto LABEL_39;
goto LABEL_34;
}
goto LABEL_33;
}
v12 = m_folderObject->m_sfxObjects;
LABEL_34:
v25 = cocos2d::CCArray::count(v12);
FilesMatchingSearch = cocos2d::CCArray::createWithCapacity(v25);
if ( v12 )
{
data = v12->data;
num = data->num;
if ( (_DWORD)num )
{
arr = data->arr;
for ( j = &arr[num - 1]; arr <= j; ++arr )
{
if ( !*arr )
break;
cocos2d::CCArray::addObject(FilesMatchingSearch, *arr);
}
}
}
LABEL_39:
if ( v3->m_searchQuery.m_data.m_size )
{
if ( FilesMatchingSearch )
{
v30 = FilesMatchingSearch->data;
v31 = v30->num;
if ( (_DWORD)v31 )
{
v32 = v30->arr;
for ( k = &v32[v31 - 1]; v32 <= k; ++v32 )
{
if ( !*v32 )
break;
BYTE1((*v32)[1].m_nTag) = 0;
}
}
}
v34 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v61 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v61);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v34 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getGameVariable(v34, "0147") && v3->m_folderObject )
{
sub_14003BDB0((__int64)v62, (__int64)&v3->m_searchQuery);
if ( (_DWORD)v63 )
{
v35 = 0;
v36 = (unsigned int)v63;
do
{
if ( v64 <= 0xF )
{
v38 = (char *)v62 + v35;
v37 = v62;
}
else
{
v37 = (_QWORD *)v62[0];
v38 = (_BYTE *)(v35 + v62[0]);
}
*v38 = tolower(*((char *)v37 + v35++));
--v36;
}
while ( v36 );
}
v39 = cocos2d::CCArray::createWithObject(v3->m_folderObject);
if ( cocos2d::CCArray::count(v39) )
{
v40 = v63;
do
{
v41 = cocos2d::CCArray::lastObject(v39);
cocos2d::CCArray::removeLastObject(v39, 1);
sub_14003BDB0((__int64)v65, (__int64)&v41[1].m_uAutoReleaseCount);
v42 = v66;
if ( (_DWORD)v66 )
{
v43 = 0;
v44 = (unsigned int)v66;
do
{
if ( v67 <= 0xF )
{
v46 = (char *)v65 + v43;
v45 = v65;
}
else
{
v45 = (_QWORD *)v65[0];
v46 = (char *)(v43 + v65[0]);
}
*((_BYTE *)v45 + v43++) = tolower(*v46);
--v44;
}
while ( v44 );
v42 = v66;
}
if ( BYTE1(v41[1].m_nTag) )
goto LABEL_71;
v47 = (char *)v62;
if ( v64 > 0xF )
v47 = (char *)v62[0];
v48 = v65;
if ( v67 > 0xF )
v48 = (_QWORD *)v65[0];
if ( sub_14003BCE0((__int64)v48, v42, 0, v47, v40) != -1 )
LABEL_71:
v49 = 1;
else
v49 = 0;
v50 = v41[2].__vftable;
if ( v50 )
{
v51 = v50->getTag;
v52 = *(unsigned int *)v51;
if ( (_DWORD)v52 )
{
v53 = *((__int64 **)v51 + 2);
for ( m = &v53[v52 - 1]; v53 <= m; ++v53 )
{
v55 = *v53;
if ( !*v53 )
break;
*(_BYTE *)(v55 + 73) = v49;
if ( *(_BYTE *)(v55 + 72) )
cocos2d::CCArray::addObject(v39, (struct cocos2d::CCObject *)v55);
}
}
}
sub_14003A830((__int64)v65);
}
while ( cocos2d::CCArray::count(v39) );
v3 = v60;
v2 = a2;
}
sub_14003A830((__int64)v62);
}
v56 = sub_14003BDB0((__int64)v62, (__int64)&v3->m_searchQuery);
FilesMatchingSearch = (struct cocos2d::CCArray *)MusicSearchResult::getFilesMatchingSearch(
(__int64)v3,
(__int64)FilesMatchingSearch,
v56);
}
if ( cocos2d::CCArray::count(FilesMatchingSearch) > 1 )
{
switch ( v2 )
{
case NameDescending:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033C8D0;
break;
case LengthAscending:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033CA50;
break;
case LengthDescending:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033CA70;
break;
case IDAscending:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033C710;
break;
case IDDescending:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033C730;
break;
default:
v57 = (int (__cdecl *)(const void *, const void *))sub_14033C750;
break;
}
qsort(FilesMatchingSearch->data->arr, FilesMatchingSearch->data->num, 8u, v57);
}
if ( v3->m_filterObjects != FilesMatchingSearch )
{
if ( FilesMatchingSearch )
cocos2d::CCObject::retain(FilesMatchingSearch);
v58 = v3->m_filterObjects;
if ( v58 )
cocos2d::CCObject::release(v58);
v3->m_filterObjects = FilesMatchingSearch;
}
}