//
// MusicDownloadManager::createCustomSFXPlacement from 0x1006522d0 to 0x100652619 (841 bytes)
//
// 2 xrefs:
// > SFXBrowser::sfxFolderPicked @ 0x100432e0c
// > sub_100654A90 @ 0x100655128
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:34:49 +0000
//
__int64 __fastcall MusicDownloadManager::createCustomSFXPlacement(
__int64 a1,
unsigned int a2,
unsigned int a3,
unsigned __int8 *a4,
int a5)
{
__int64 v8; // rdi
__int64 v9; // rsi
__int64 v10; // rdi
__int64 v11; // rdi
__int64 v12; // r15
unsigned int v13; // eax
__int64 v14; // rax
const char *CString; // r12
size_t v16; // rax
_BYTE *v17; // rdx
char *v18; // rax
size_t v19; // r12
const char *v20; // rsi
_BYTE *v21; // r12
__int64 v22; // rdi
__int64 v23; // rdi
__int64 v24; // rax
int v25; // ecx
__int64 v26; // r13
__int64 v27; // rdx
__int64 v28; // rcx
__int64 v29; // r8
__int64 v30; // r15
char v32; // [rsp+0h] [rbp-90h]
const char *v33; // [rsp+8h] [rbp-88h]
__int128 v34; // [rsp+10h] [rbp-80h] BYREF
void *__p; // [rsp+20h] [rbp-70h]
__int128 v36; // [rsp+30h] [rbp-60h] BYREF
char *v37; // [rsp+40h] [rbp-50h]
void *__dst; // [rsp+50h] [rbp-40h]
__int64 CustomSFXRoot; // [rsp+58h] [rbp-38h]
unsigned int v40; // [rsp+64h] [rbp-2Ch]
v40 = a2;
v8 = *(_QWORD *)(a1 + 824);
if ( v8 == 0
|| (int)a3 <= 0
|| (CustomSFXRoot = cocos2d::CCDictionary::objectForKey_1(v8, a3)) == 0
|| !*(_BYTE *)(CustomSFXRoot + 72)
&& ((v9 = *(int *)(CustomSFXRoot + 60), v10 = *(_QWORD *)(a1 + 824), v9 <= 0 || v10 == 0)
|| (CustomSFXRoot = cocos2d::CCDictionary::objectForKey_1(v10, v9)) == 0
|| !*(_BYTE *)(CustomSFXRoot + 72)) )
{
CustomSFXRoot = MusicDownloadManager::getCustomSFXRoot(a1);
}
v11 = *(_QWORD *)(a1 + 400);
if ( v11 )
v12 = cocos2d::CCDictionary::objectForKey_1(v11, (int)v40);
else
v12 = 0;
sub_100652190(&v36, a4);
if ( (*a4 & 1) != 0 )
operator delete(*((void **)a4 + 2));
*((_QWORD *)a4 + 2) = v37;
*(_OWORD *)a4 = v36;
v13 = *a4;
if ( (v13 & 1) != 0 )
{
if ( *((_QWORD *)a4 + 1) )
{
LABEL_15:
if ( (unsigned int)(a5 - 2) > 0xFFFFFD )
goto LABEL_37;
LABEL_35:
v22 = *(_QWORD *)(a1 + 824);
if ( !v22 || !cocos2d::CCDictionary::objectForKey_1(v22, (unsigned int)a5) )
goto LABEL_44;
goto LABEL_37;
}
}
else if ( v13 >> 1 )
{
goto LABEL_15;
}
if ( !v12 )
{
v14 = sub_10088E820("SFX %i", v32);
CString = (const char *)cocos2d::CCString::getCString(v14);
v16 = strlen(CString);
if ( v16 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v17 = (_BYTE *)v16;
if ( v16 >= 0x17 )
{
v33 = CString;
v19 = 26;
if ( (v16 | 7) != 0x17 )
v19 = (v16 | 7) + 1;
__dst = (void *)v16;
v18 = (char *)operator new(v19);
v17 = __dst;
v37 = v18;
*(_QWORD *)&v36 = v19 + 1;
CString = v33;
*((_QWORD *)&v36 + 1) = __dst;
}
else
{
LOBYTE(v36) = 2 * v16;
v18 = (char *)&v36 + 1;
if ( !v17 )
{
LABEL_32:
v17[(_QWORD)v18] = 0;
if ( (*a4 & 1) == 0 )
goto LABEL_34;
goto LABEL_33;
}
}
__dst = v18;
v20 = CString;
v21 = v17;
memmove(v18, v20, (size_t)v17);
v18 = (char *)__dst;
v17 = v21;
goto LABEL_32;
}
if ( (*(_BYTE *)(v12 + 80) & 1) == 0 )
{
v37 = *(char **)(v12 + 96);
v36 = *(_OWORD *)(v12 + 80);
if ( (*a4 & 1) == 0 )
goto LABEL_34;
LABEL_33:
operator delete(*((void **)a4 + 2));
goto LABEL_34;
}
sub_10001AD30(&v36, *(const void **)(v12 + 96), *(_QWORD *)(v12 + 88));
if ( (*a4 & 1) != 0 )
goto LABEL_33;
LABEL_34:
*((_QWORD *)a4 + 2) = v37;
*(_OWORD *)a4 = v36;
if ( (unsigned int)(a5 - 2) <= 0xFFFFFD )
goto LABEL_35;
LABEL_37:
a5 = *(_DWORD *)(a1 + 832);
v23 = *(_QWORD *)(a1 + 824);
if ( v23 != 0 && a5 > 0 )
{
while ( 1 )
{
v24 = cocos2d::CCDictionary::objectForKey_1(v23, (unsigned int)a5);
v25 = *(_DWORD *)(a1 + 832);
if ( !v24 )
break;
a5 = v25 + 1;
*(_DWORD *)(a1 + 832) = v25 + 1;
if ( v25 >= 0 )
{
v23 = *(_QWORD *)(a1 + 824);
if ( v23 )
continue;
}
goto LABEL_43;
}
a5 = *(_DWORD *)(a1 + 832);
}
LABEL_43:
*(_DWORD *)(a1 + 832) = a5 + 1;
LABEL_44:
if ( (*a4 & 1) != 0 )
{
sub_10001AD30(&v34, *((const void **)a4 + 2), *((_QWORD *)a4 + 1));
v26 = CustomSFXRoot;
v27 = *(unsigned int *)(CustomSFXRoot + 76);
if ( v12 )
goto LABEL_46;
}
else
{
__p = *((void **)a4 + 2);
v34 = *(_OWORD *)a4;
v26 = CustomSFXRoot;
v27 = *(unsigned int *)(CustomSFXRoot + 76);
if ( v12 )
{
LABEL_46:
v28 = *(unsigned int *)(v12 + 64);
v29 = *(unsigned int *)(v12 + 68);
goto LABEL_49;
}
}
v28 = 0;
v29 = 0;
LABEL_49:
v30 = SFXInfoObject::create(v40, &v34, v27, v28, v29);
if ( (v34 & 1) != 0 )
operator delete(__p);
*(_DWORD *)(v30 + 76) = a5;
cocos2d::CCDictionary::setObject_1(*(_QWORD *)(a1 + 824), v30, a5);
sub_1007FEBF0(*(_QWORD *)(v26 + 152), v30);
return v30;
}