//
// FMODAudioEngine::getActiveMusicChannel from 0x1003e1860 to 0x1003e1a1f (447 bytes)
//
// 14 xrefs:
// > PlayLayer::showCompleteEffect @ 0x1000b45a3
// > GJBaseGameLayer::processSongState @ 0x1001622dd
// > FMODAudioEngine::resumeMusic @ 0x1003e1844
// > FMODAudioEngine::isMusicPlaying_1 @ 0x1003e6a1c
// > FMODAudioEngine::isMusicPlaying @ 0x1003e6bc9
// > FMODAudioEngine::loadAndPlayMusic @ 0x1003e6eb8
// > FMODAudioEngine::playMusic @ 0x1003e6f9f
// > FMODAudioEngine::playMusic @ 0x1003e7061
// > FMODAudioEngine::playMusic @ 0x1003e708e
// > FMODAudioEngine::fadeInMusic @ 0x1003e70d3
// > FMODAudioEngine::isPersistentMatchPlaying @ 0x1003e7253
// > FMODAudioEngine::pauseMusic @ 0x1003e9ed4
// > FMODAudioEngine::fadeOutMusic @ 0x1003e9f03
// > FMODAudioEngine::fadeMusic @ 0x1003e9fed
//
// 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::Channel *__fastcall FMODAudioEngine::getActiveMusicChannel(FMODAudioEngine *a1, int a2)
{
unsigned __int64 value; // rcx
std::unordered_map *p_m_fmodMusic; // r11
unsigned __int64 v4; // r10
unsigned __int64 v5; // r9
std::__hash_node_base, void *> *> *v6; // rax
std::__hash_node_base, void *> *>::__next_pointer next; // rbx
unsigned __int64 v8; // rcx
FMOD::Channel *v9; // r10
std::__hash_node_base, void *> *>::__next_pointer v10; // rax
unsigned __int64 v11; // rax
__int64 v12; // rax
int *v14; // [rsp+8h] [rbp-18h] BYREF
int v15; // [rsp+10h] [rbp-10h] BYREF
char v16[9]; // [rsp+17h] [rbp-9h] BYREF
v15 = a2;
value = a1->m_fmodMusic.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !value )
return nullptr;
p_m_fmodMusic = &a1->m_fmodMusic;
v4 = (0x101010101010101LL
* ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)
+ ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)) >> 4))
& 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v4 <= 1 )
{
v5 = a2 & (value - 1);
v6 = p_m_fmodMusic->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
goto LABEL_9;
}
v5 = a2;
if ( value <= a2 )
{
if ( !((value | a2) >> 32) )
{
v5 = a2 % (unsigned int)value;
v6 = p_m_fmodMusic->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
goto LABEL_9;
}
v5 = a2 % value;
}
v6 = p_m_fmodMusic->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
LABEL_9:
next = v6->__next_;
if ( !v6->__next_ )
return nullptr;
if ( (unsigned int)v4 < 2 )
{
v8 = value - 1;
v9 = nullptr;
while ( 1 )
{
v10 = next[1].__next_;
if ( v10 == (std::__hash_node_base, void *> *>::__next_pointer)a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
goto LABEL_28;
}
else if ( (v8 & (unsigned __int64)v10) != v5 )
{
return v9;
}
next = next->__next_;
if ( !next )
return v9;
}
}
v9 = nullptr;
while ( 1 )
{
v11 = (unsigned __int64)next[1].__next_;
if ( v11 == a2 )
break;
if ( v11 < value )
goto LABEL_24;
if ( (value | v11) >> 32 )
{
v11 %= value;
LABEL_24:
if ( v11 != v5 )
return v9;
goto LABEL_19;
}
if ( (unsigned int)v11 % (unsigned int)value != v5 )
return v9;
LABEL_19:
next = next->__next_;
if ( !next )
return v9;
}
if ( LODWORD(next[2].__next_) != a2 )
goto LABEL_19;
LABEL_28:
v14 = &v15;
v12 = sub_1003EF570(&a1->m_fmodMusic, &v15, &unk_10081B0A2, &v14, v16);
return FMODAudioEngine::channelForChannelID(a1, *(_DWORD *)(v12 + 24));
}