//
// FMODAudioEngine::unloadAllEffects from 0x1003e6720 to 0x1003e695f (575 bytes)
//
// 6 xrefs:
// > PlayLayer::onQuit @ 0x1000b2fa8
// > EditorPauseLayer::onSaveAndExit @ 0x1002938a5
// > EditorPauseLayer::onExitNoSave @ 0x100293aad
// > EditorPauseLayer::playStep2 @ 0x100294cf8
// > EditorPauseLayer::onExitEditor @ 0x100294e21
// > EditorPauseLayer::FLAlert_Clicked @ 0x100294e83
//
// 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 __fastcall FMODAudioEngine::unloadAllEffects(FMODAudioEngine *a1)
{
FMODAudioEngine *v1; // rbx
std::__hash_node_base, void *> *>::__next_pointer next; // r13
char *end; // r12
FMOD::Sound **value; // rax
__int64 v5; // rbx
std::__vector_base::pointer begin; // rsi
signed __int64 v7; // r12
__int64 v8; // rbx
unsigned __int64 v9; // rcx
__int64 v10; // rax
unsigned __int64 v11; // r14
std::__hash_node_base, void *> *> *v12; // r15
FMODAudioEngine *v13; // rax
FMODAudioEngine *v14; // rax
__int64 *v15; // rax
void **v16; // rdi
std::__hash_node_base, void *> *> *v17; // r15
void *v18; // r14
__int64 *p_m_fmodSounds; // [rsp+8h] [rbp-68h]
void *__p[2]; // [rsp+20h] [rbp-50h] BYREF
char v21; // [rsp+30h] [rbp-40h]
__int64 *p_m_temporarySoundPaths; // [rsp+38h] [rbp-38h]
FMODAudioEngine *v23; // [rsp+40h] [rbp-30h]
v1 = a1;
FMODAudioEngine::stopAllEffects(a1);
next = a1->m_fmodSounds.__table_.__p1_.__value_.__next_;
if ( next )
{
p_m_fmodSounds = (__int64 *)&a1->m_fmodSounds;
p_m_temporarySoundPaths = (__int64 *)&a1->m_temporarySoundPaths;
v23 = a1;
do
{
while ( BYTE4(next[10].__next_) )
{
next = next->__next_;
if ( !next )
goto LABEL_32;
}
end = (char *)v1->m_removedSounds.__end_;
value = v1->m_removedSounds.__end_cap_.__value_;
if ( end >= (char *)value )
{
begin = v1->m_removedSounds.__begin_;
v7 = end - (char *)begin;
v8 = v7 >> 3;
v9 = (v7 >> 3) + 1;
if ( v9 > 0x1FFFFFFFFFFFFFFFLL )
sub_1003EE1D0(a1, begin);
v10 = (char *)value - (char *)begin;
v11 = v10 >> 2;
if ( v10 >> 2 <= v9 )
v11 = (v7 >> 3) + 1;
if ( (unsigned __int64)v10 >= 0x7FFFFFFFFFFFFFF8LL )
v11 = 0x1FFFFFFFFFFFFFFFLL;
if ( v11 )
{
if ( v11 > 0x1FFFFFFFFFFFFFFFLL )
sub_100054850();
v12 = (std::__hash_node_base, void *> *> *)operator new(8 * v11);
}
else
{
v12 = nullptr;
}
v12[v8] = next[5];
v5 = (__int64)&v12[v8 + 1];
memcpy(v12, begin, v7);
v13 = v23;
v23->m_removedSounds.__begin_ = (std::__vector_base::pointer)v12;
v13->m_removedSounds.__end_ = (std::__vector_base::pointer)v5;
v13->m_removedSounds.__end_cap_.__value_ = (FMOD::Sound **)&v12[v11];
if ( begin )
operator delete(begin);
}
else
{
*(std::__hash_node_base, void *> *> *)end = next[5];
v5 = (__int64)(end + 8);
}
v14 = v23;
v23->m_removedSounds.__end_ = (std::__vector_base::pointer)v5;
v1 = v14;
v15 = (__int64 *)sub_1003EF2E0(p_m_temporarySoundPaths, &next[2]);
if ( v15 )
{
sub_100056B40((__int64)__p, p_m_temporarySoundPaths, v15);
v16 = (void **)__p[0];
__p[0] = nullptr;
if ( v16 )
{
if ( v21 == 1 && ((_BYTE)v16[2] & 1) != 0 )
{
operator delete(v16[4]);
v1 = v23;
}
operator delete(v16);
}
}
v17 = next->__next_;
a1 = (FMODAudioEngine *)__p;
sub_100056B40((__int64)__p, p_m_fmodSounds, (__int64 *)next);
v18 = __p[0];
__p[0] = nullptr;
if ( v18 )
{
if ( v21 == 1 )
{
if ( (*((_BYTE *)v18 + 48) & 1) != 0 )
operator delete(*((void **)v18 + 8));
if ( (*((_BYTE *)v18 + 16) & 1) != 0 )
operator delete(*((void **)v18 + 4));
}
a1 = (FMODAudioEngine *)v18;
operator delete(v18);
}
next = v17;
}
while ( v17 );
}
LABEL_32:
dword_1009A1488 = 0;
}