//
// FMODAudioEngine::activateQueuedMusic from 0x1003e9320 to 0x1003e96fa (986 bytes)
//
// 1 xrefs:
// > GJBaseGameLayer::activateSongTrigger @ 0x10015a3da
//
// 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::activateQueuedMusic(FMODAudioEngine *a1, int a2)
{
double v2; // xmm0_8
unsigned __int64 value; // r15
std::unordered_map *p_m_queuedMusicForChannels2; // rbx
unsigned __int64 v5; // rdx
unsigned __int64 v6; // r13
unsigned __int64 v7; // r8
std::__hash_node_base, void *> *> *v8; // rax
std::__hash_node_base, void *> *>::__next_pointer v9; // r12
unsigned __int64 v10; // r15
std::__hash_node_base, void *> *>::__next_pointer v11; // rax
unsigned __int64 v12; // rax
std::string *v13; // rax
std::string *v14; // r15
unsigned __int64 v15; // rbx
std::unordered_map *p_m_queuedMusicForChannels1; // rdi
unsigned __int64 v17; // rdx
unsigned __int64 v18; // r11
unsigned __int64 v19; // r8
std::__hash_node_base, void *> *> *v20; // rax
std::__hash_node_base, void *> *>::__next_pointer next; // r9
unsigned __int64 v22; // rbx
unsigned __int64 v23; // rax
std::__hash_node_base, void *> *>::__next_pointer v24; // rax
__int128 v25; // xmm0
__int128 v26; // xmm1
__int128 v27; // xmm2
FMODQueuedMusic v28; // [rsp+0h] [rbp-A0h] BYREF
int *v29; // [rsp+68h] [rbp-38h] BYREF
int v30; // [rsp+70h] [rbp-30h] BYREF
_BYTE v31[41]; // [rsp+77h] [rbp-29h] BYREF
v30 = a2;
value = a1->m_audioState.m_queuedMusicForChannels2.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !value )
{
LABEL_30:
v15 = a1->m_audioState.m_queuedMusicForChannels1.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !v15 )
return;
p_m_queuedMusicForChannels1 = &a1->m_audioState.m_queuedMusicForChannels1;
v17 = ((v15 - ((v15 >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((v15 - ((v15 >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL);
v18 = (0x101010101010101LL * ((v17 + (v17 >> 4)) & 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v18 > 1 )
{
v19 = a2;
if ( v15 <= a2 )
{
if ( !((v15 | a2) >> 32) )
{
v19 = a2 % (unsigned int)v15;
v20 = p_m_queuedMusicForChannels1->__table_.__bucket_list_.__ptr_.__value_[v19];
if ( !v20 )
return;
goto LABEL_38;
}
v19 = a2 % v15;
}
v20 = p_m_queuedMusicForChannels1->__table_.__bucket_list_.__ptr_.__value_[v19];
if ( !v20 )
return;
}
else
{
v19 = a2 & (v15 - 1);
v20 = p_m_queuedMusicForChannels1->__table_.__bucket_list_.__ptr_.__value_[v19];
if ( !v20 )
return;
}
LABEL_38:
next = v20->__next_;
if ( !v20->__next_ )
return;
if ( (unsigned int)v18 < 2 )
{
v22 = v15 - 1;
while ( 1 )
{
v24 = next[1].__next_;
if ( v24 == (std::__hash_node_base, void *> *>::__next_pointer)a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
goto LABEL_56;
}
else if ( (v22 & (unsigned __int64)v24) != v19 )
{
return;
}
next = next->__next_;
if ( !next )
return;
}
}
while ( 1 )
{
v23 = (unsigned __int64)next[1].__next_;
if ( v23 == a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
{
LABEL_56:
v29 = &v30;
*(_BYTE *)(sub_1003EBD20(p_m_queuedMusicForChannels1, &v30, &unk_10081B0A2, &v29, v31) + 92) = 1;
return;
}
}
else
{
if ( v23 < v15 )
goto LABEL_47;
if ( (v15 | v23) >> 32 )
{
v23 %= v15;
LABEL_47:
if ( v23 != v19 )
return;
goto LABEL_42;
}
if ( (unsigned int)v23 % (unsigned int)v15 != v19 )
return;
}
LABEL_42:
next = next->__next_;
if ( !next )
return;
}
}
p_m_queuedMusicForChannels2 = &a1->m_audioState.m_queuedMusicForChannels2;
v5 = ((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL);
v6 = (0x101010101010101LL * ((v5 + (v5 >> 4)) & 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v6 <= 1 )
{
v7 = a2 & (value - 1);
v8 = p_m_queuedMusicForChannels2->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_30;
goto LABEL_9;
}
v7 = a2;
if ( value <= a2 )
{
if ( !((value | a2) >> 32) )
{
v7 = a2 % (unsigned int)value;
v8 = p_m_queuedMusicForChannels2->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_30;
goto LABEL_9;
}
v7 = a2 % value;
}
v8 = p_m_queuedMusicForChannels2->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_30;
LABEL_9:
v9 = v8->__next_;
if ( !v8->__next_ )
goto LABEL_30;
if ( (unsigned int)v6 < 2 )
{
v10 = value - 1;
while ( 1 )
{
v11 = v9[1].__next_;
if ( v11 == (std::__hash_node_base, void *> *>::__next_pointer)a2 )
{
if ( LODWORD(v9[2].__next_) == a2 )
goto LABEL_27;
}
else if ( (v10 & (unsigned __int64)v11) != v7 )
{
goto LABEL_30;
}
v9 = v9->__next_;
if ( !v9 )
goto LABEL_30;
}
}
while ( 1 )
{
v12 = (unsigned __int64)v9[1].__next_;
if ( v12 == a2 )
break;
if ( v12 < value )
goto LABEL_23;
if ( (value | v12) >> 32 )
{
v12 %= value;
LABEL_23:
if ( v12 != v7 )
goto LABEL_30;
goto LABEL_18;
}
if ( (unsigned int)v12 % (unsigned int)value != v7 )
goto LABEL_30;
LABEL_18:
v9 = v9->__next_;
if ( !v9 )
goto LABEL_30;
}
if ( LODWORD(v9[2].__next_) != a2 )
goto LABEL_18;
LABEL_27:
v29 = &v30;
v13 = (std::string *)sub_1003EBD20(&a1->m_audioState.m_queuedMusicForChannels2, &v30, &unk_10081B0A2, &v29, v31);
v14 = v13;
if ( (v13[1].m_data.m_short.sizex2 & 1) != 0 )
sub_100006B70(&v28, v13[1].m_data.m_long.longStorage, v13[1].m_data.m_long.size, v2);
else
v28.m_filePath = v13[1];
v28.m_dontReset = v14[4].m_data.m_short.shortStorage.__elems_[15];
v25 = *(_OWORD *)&v14[2].m_data.m_short.sizex2;
v26 = *(_OWORD *)&v14[2].m_data.m_long.longStorage;
v27 = *(_OWORD *)&v14[3].m_data.m_long.size;
*(_OWORD *)&v28.m_queuedStatus = *(_OWORD *)&v14[4].m_data.m_short.sizex2;
*(_OWORD *)&v28.m_musicID = v27;
*(_OWORD *)&v28.m_end = v26;
*(_OWORD *)&v28.m_pitch = v25;
FMODAudioEngine::triggerQueuedMusic(a1, v28);
if ( (v28.m_filePath.m_data.m_short.sizex2 & 1) != 0 )
operator delete(v28.m_filePath.m_data.m_long.longStorage);
sub_1003EE010(p_m_queuedMusicForChannels2, &v30);
}