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