//
// FMODAudioEngine::channelForChannelID from 0x1003dfdd0 to 0x1003dff9e (462 bytes)
//
// 24 xrefs:
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100161895
// > FMODAudioEngine::stopAllMusic @ 0x1003de6de
// > FMODAudioEngine::updateQueuedMusic @ 0x1003df3d3
// > FMODAudioEngine::saveAudioState @ 0x1003dfbf7
// > FMODAudioEngine::loadAudioState @ 0x1003e037b
// > FMODAudioEngine::loadMusic @ 0x1003e1371
// > FMODAudioEngine::getActiveMusicChannel @ 0x1003e19ef
// > FMODAudioEngine::playEffectAdvanced @ 0x1003e1a99
// > FMODAudioEngine::setMusicTimeMS @ 0x1003e27bc
// > FMODAudioEngine::setChannelVolume @ 0x1003e3373
// > FMODAudioEngine::setChannelVolume @ 0x1003e33c3
// > FMODAudioEngine::setChannelPitch @ 0x1003e34e1
// > FMODAudioEngine::setChannelPitch @ 0x1003e3538
// > FMODAudioEngine::channelForUniqueID @ 0x1003e5769
// > FMODAudioEngine::setChannelVolumeMod @ 0x1003e6483
// > FMODAudioEngine::setChannelVolumeMod @ 0x1003e64d3
// > FMODAudioEngine::pauseAllMusic @ 0x1003e6a7f
// > FMODAudioEngine::pauseAllMusic @ 0x1003e6ab6
// > FMODAudioEngine::resumeAllMusic @ 0x1003e6b16
// > FMODAudioEngine::startMusic @ 0x1003e7870
// > FMODAudioEngine::getMusicTimeMS @ 0x1003e97ff
// > FMODAudioEngine::getMusicTime @ 0x1003e986f
// > FMODAudioEngine::getMusicLengthMS @ 0x1003e98ef
// > FMODAudioEngine::stopAndRemoveMusic @ 0x1003e9d1e
//
// 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::channelForChannelID(FMODAudioEngine *a1, int a2)
{
unsigned __int64 value; // r10
std::unordered_map *p_m_channelIDToChannel; // rdi
unsigned __int64 v4; // r9
unsigned __int64 v5; // r8
std::__hash_node_base, void *> *> *v6; // rax
std::__hash_node_base, void *> *>::__next_pointer next; // r11
unsigned __int64 v9; // r10
std::__hash_node_base, void *> *>::__next_pointer v10; // rax
unsigned __int64 v11; // rax
int *v12; // [rsp+0h] [rbp-10h] BYREF
int v13; // [rsp+8h] [rbp-8h] BYREF
char v14; // [rsp+Fh] [rbp-1h] BYREF
v13 = a2;
value = a1->m_channelIDToChannel.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !value )
return nullptr;
p_m_channelIDToChannel = &a1->m_channelIDToChannel;
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;
if ( value <= a2 )
{
if ( !((value | a2) >> 32) )
{
v5 = a2 % (unsigned int)value;
v6 = p_m_channelIDToChannel->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
goto LABEL_10;
}
v5 = a2 % value;
}
v6 = p_m_channelIDToChannel->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
goto LABEL_10;
}
v5 = a2 & (value - 1);
v6 = p_m_channelIDToChannel->__table_.__bucket_list_.__ptr_.__value_[v5];
if ( !v6 )
return nullptr;
LABEL_10:
next = v6->__next_;
if ( v6->__next_ )
{
if ( (unsigned int)v4 < 2 )
{
v9 = value - 1;
while ( 1 )
{
v10 = next[1].__next_;
if ( v10 == (std::__hash_node_base, void *> *>::__next_pointer)a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
goto LABEL_29;
}
else if ( (v9 & (unsigned __int64)v10) != v5 )
{
return nullptr;
}
next = next->__next_;
if ( !next )
return nullptr;
}
}
while ( 1 )
{
v11 = (unsigned __int64)next[1].__next_;
if ( v11 == a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
{
LABEL_29:
v12 = &v13;
return *(FMOD::Channel **)(((__int64 (__fastcall *)(std::unordered_map *, int *, void *, int **, char *, _QWORD))sub_1003EDB70)(
p_m_channelIDToChannel,
&v13,
&unk_10081B0A2,
&v12,
&v14,
0)
+ 24);
}
}
else
{
if ( v11 < value )
goto LABEL_25;
if ( (value | v11) >> 32 )
{
v11 %= value;
LABEL_25:
if ( v11 != v5 )
return nullptr;
goto LABEL_20;
}
if ( (unsigned int)v11 % (unsigned int)value != v5 )
return nullptr;
}
LABEL_20:
next = next->__next_;
if ( !next )
return nullptr;
}
}
return nullptr;
}