//
// FMODAudioEngine::preloadMusic from 0x1003e7350 to 0x1003e7628 (728 bytes)
//
// 2 xrefs:
// > FMODAudioEngine::loadMusic @ 0x1003e1313
// > FMODAudioEngine::queueStartMusic @ 0x1003e7e0c
//
// 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
//
FMOD::Sound *__fastcall FMODAudioEngine::preloadMusic(
FMODAudioEngine *a1,
const std::string *a2,
int a3,
int a4,
double a5)
{
int v5; // r12d
unsigned int v8; // eax
char v9; // r13
char *v10; // rdi
size_t v11; // rdx
std::string::pointer data; // rsi
size_t size; // rax
bool v14; // zf
FMODAudioEngine *v15; // rbx
FMOD::Sound *v16; // r14
int v17; // r13d
int v18; // ecx
unsigned int v19; // edx
std::string::pointer v20; // rsi
__int64 v21; // rdx
char *v22; // r15
std::string::pointer v23; // rax
char *v24; // rax
__int64 v25; // rbx
void *__p; // [rsp+0h] [rbp-A0h]
char *__s; // [rsp+8h] [rbp-98h]
__int128 v29; // [rsp+10h] [rbp-90h] BYREF
void *v30; // [rsp+20h] [rbp-80h]
int *v31; // [rsp+30h] [rbp-70h] BYREF
__int128 __s1; // [rsp+38h] [rbp-68h] BYREF
std::string __str; // [rsp+48h] [rbp-58h] BYREF
__int16 v34; // [rsp+60h] [rbp-40h]
int v35; // [rsp+6Ch] [rbp-34h]
char v36; // [rsp+73h] [rbp-2Dh] BYREF
int v37[11]; // [rsp+74h] [rbp-2Ch] BYREF
v35 = a3;
v37[0] = a4;
FMODAudioEngine::getActiveMusic(&__s1, (__int64)a1, a4, a5);
v8 = (unsigned int)a2->__r_.__value_.__l.0;
v9 = __s1;
v10 = (char *)__str.__r_.__value_.__r.__words[0];
__p = (void *)__str.__r_.__value_.__r.__words[0];
if ( (__s1 & 1) != 0 )
{
v11 = *((_QWORD *)&__s1 + 1);
data = a2->__r_.__value_.__s.__data_;
__s = a2->__r_.__value_.__s.__data_;
if ( (v8 & 1) == 0 )
{
LABEL_3:
size = v8 >> 1;
goto LABEL_6;
}
}
else
{
v11 = (unsigned __int8)__s1 >> 1;
v10 = (char *)&__s1 + 1;
data = a2->__r_.__value_.__s.__data_;
__s = a2->__r_.__value_.__s.__data_;
if ( (v8 & 1) == 0 )
goto LABEL_3;
}
size = a2->__r_.__value_.__l.__size_;
data = a2->__r_.__value_.__l.__data_;
LABEL_6:
v14 = size == v11;
if ( size < v11 )
v11 = size;
LOBYTE(v5) = v14 & (memcmp(v10, data, v11) == 0);
if ( (v9 & 1) != 0 )
operator delete(__p);
v15 = a1;
if ( (_BYTE)v5 )
{
*(_QWORD *)&__s1 = v37;
return *(FMOD::Sound **)(sub_1003EF570(&a1->m_fmodMusic, v37, &unk_10081B0A2, &__s1, &v31) + 32);
}
FMODAudioEngine::stopAndRemoveMusic(a1, v37[0]);
if ( (*(_BYTE *)&a2->__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v29, a2->__r_.__value_.__l.__data_, a2->__r_.__value_.__l.__size_, a5);
}
else
{
v30 = a2->__r_.__value_.__l.__data_;
v29 = *(_OWORD *)&a2->__r_.__value_.__l.0;
}
v16 = (FMOD::Sound *)FMODAudioEngine::createStream(a1, &v29);
if ( (v29 & 1) != 0 )
operator delete(v30);
if ( !v16 )
return nullptr;
if ( !(_BYTE)v35 )
{
v17 = 69;
do
{
do
{
v15->m_lastResult = FMOD::Sound::getOpenState(v16, (FMOD_OPENSTATE *)&__s1, nullptr, nullptr, nullptr);
if ( (unsigned int)__s1 <= 6 )
{
v18 = __s1;
if ( _bittest(&v17, __s1) )
break;
}
v18 = v5;
}
while ( (unsigned int)__s1 > 6 );
v5 = v18;
}
while ( !_bittest(&v17, __s1) );
if ( v18 == 2 )
{
FMOD::Sound::release(v16);
return nullptr;
}
}
*((_QWORD *)&__s1 + 1) = 0;
*(_WORD *)&__str.__r_.__value_.__l.0 = 0;
v34 = 0;
LODWORD(__s1) = 0;
std::string::operator=(&__str, a2);
*((_QWORD *)&__s1 + 1) = v16;
v19 = (unsigned int)a2->__r_.__value_.__l.0;
v20 = __s;
if ( (v19 & 1) != 0 )
{
v21 = a2->__r_.__value_.__l.__size_;
v20 = a2->__r_.__value_.__l.__data_;
v22 = &v20[v21];
if ( v21 >= 4 )
{
LABEL_31:
v23 = v20;
do
{
v24 = (char *)memchr(v23, 46, v21 - 3);
if ( !v24 )
break;
if ( *(_DWORD *)v24 == 1734831918 )
goto LABEL_39;
v23 = v24 + 1;
v21 = v22 - v23;
}
while ( v22 - v23 > 3 );
v24 = v22;
goto LABEL_39;
}
}
else
{
v21 = v19 >> 1;
v22 = &__s[v21];
if ( v21 >= 4 )
goto LABEL_31;
}
v24 = v22;
LABEL_39:
LOBYTE(v34) = v24 != v22 && v24 - v20 != -1;
v31 = v37;
v25 = sub_1003EF570(&v15->m_fmodMusic, v37, &unk_10081B0A2, &v31, &v36);
*(_OWORD *)(v25 + 24) = __s1;
std::string::operator=((std::string *)(v25 + 40), &__str);
*(_WORD *)(v25 + 64) = v34;
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
operator delete(__str.__r_.__value_.__l.__data_);
return v16;
}