//
// GJBaseGameLayer::activateSongTrigger from 0x1402415c0 to 0x140241940 (896 bytes)
//
// 6 xrefs:
// > GJBaseGameLayer::processQueuedAudioTriggers @ 0x14023bc0f
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x140243a48
// > LevelEditorLayer::activateTriggerEffect @ 0x1402dd46f
// > EffectGameObject::triggerObject @ 0x1404a7364
// > ??> @ 0x1406ce430
// > ??> @ 0x1406ce43c
//
// 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
//
// Hidden C++ exception states: #wind=4
void GJBaseGameLayer::activateSongTrigger(GJBaseGameLayer *a1, SongTriggerGameObject *a2)
{
std::_Vector_val>::pointer Mylast; // rdx
unsigned int m_songChannel; // r15d
unsigned int v6; // ebx
FMODAudioEngine *v7; // rdi
unsigned __int64 v8; // r9
std::_Vector_val>>>>>::pointer Myfirst; // r10
__int64 v10; // rcx
__int64 v11; // r8
_QWORD *v12; // rax
FMODQueuedMusic *v13; // rax
unsigned __int64 v14; // rdx
std::_Vector_val>>>>>::pointer v15; // r9
__int64 v16; // rcx
MusicDownloadManager *v17; // rax
void **v18; // rsi
float v19; // xmm0_4
char v20; // r8
__int64 v21; // r9
int v22; // [rsp+58h] [rbp-E0h]
_BYTE v23[32]; // [rsp+80h] [rbp-B8h] BYREF
_BYTE v24[152]; // [rsp+A0h] [rbp-98h] BYREF
SongTriggerGameObject *v25; // [rsp+140h] [rbp+8h] BYREF
FMODAudioEngine *v26; // [rsp+150h] [rbp+18h]
if ( !a1->m_practiceMusicSync && a1->m_isPracticeMode )
return;
((void (__fastcall *)(GJBaseGameLayer *))a1->activatedAudioTrigger)(a1);
if ( a1->m_loadingStartPosition )
return;
if ( a1->m_startingFromBeginning )
{
v25 = a2;
Mylast = a1->m_activeSfxTriggers._Mypair._Myval2._Mylast;
if ( Mylast == a1->m_activeSfxTriggers._Mypair._Myval2._Myend )
{
sub_14012D2A0((const void **)&a1->m_activeSfxTriggers._Mypair._Myval2._Myfirst, Mylast, &v25);
}
else
{
*Mylast = a2;
++a1->m_activeSfxTriggers._Mypair._Myval2._Mylast;
}
return;
}
m_songChannel = a2->m_songChannel;
v6 = ~m_songChannel;
if ( !a2->m_loadPrep )
{
if ( !qword_1406C2E88 )
{
v25 = (SongTriggerGameObject *)operator new(0x888u);
qword_1406C2E88 = (__int64)FMODAudioEngine::FMODAudioEngine((FMODAudioEngine *)v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2E88 + 72LL))(qword_1406C2E88);
}
v25 = (SongTriggerGameObject *)v23;
v17 = MusicDownloadManager::sharedState();
v18 = (void **)MusicDownloadManager::pathForSong(v17, v23, (unsigned int)a2->m_soundID);
if ( !qword_1406C2E88 )
{
v26 = (FMODAudioEngine *)operator new(0x888u);
qword_1406C2E88 = (__int64)FMODAudioEngine::FMODAudioEngine(v26);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2E88 + 72LL))(qword_1406C2E88);
}
v19 = FMODAudioEngine::pitchForIdx(a2->m_speed);
FMODAudioEngine::queueStartMusic(
v21,
v18,
v19,
0.0,
LODWORD(a2->m_volume),
a2->m_loop,
a2->m_start,
a2->m_end,
a2->m_fadeIn,
a2->m_fadeOut,
v6,
v22,
m_songChannel,
v20,
a2->m_dontReset);
return;
}
v7 = (FMODAudioEngine *)qword_1406C2E88;
if ( !qword_1406C2E88 )
{
v25 = (SongTriggerGameObject *)operator new(0x888u);
qword_1406C2E88 = (__int64)FMODAudioEngine::FMODAudioEngine((FMODAudioEngine *)v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2E88 + 72LL))(qword_1406C2E88);
v7 = (FMODAudioEngine *)qword_1406C2E88;
}
LODWORD(v25) = ~m_songChannel;
v8 = 0x100000001B3LL
* ((~m_songChannel >> 24)
^ (0x100000001B3LL
* ((unsigned __int8)(~m_songChannel >> 16)
^ (0x100000001B3LL
* ((unsigned __int8)((unsigned __int16)~(_WORD)m_songChannel >> 8)
^ (0x100000001B3LL * ((unsigned __int8)v6 ^ 0xCBF29CE484222325uLL)))))));
Myfirst = v7->m_audioState.m_queuedMusicForChannels2._Vec._Mypair._Myval2._Myfirst;
v10 = *((_QWORD *)Myfirst + 2 * (v8 & v7->m_audioState.m_queuedMusicForChannels2._Mask) + 1);
v11 = 0;
if ( (std::_List_val>>::_Nodeptr)v10 != v7->m_audioState.m_queuedMusicForChannels2._List._Mypair._Myval2._Myhead )
{
if ( v6 == *(_DWORD *)(v10 + 16) )
goto LABEL_17;
while ( v10 != *((_QWORD *)Myfirst + 2 * (v8 & v7->m_audioState.m_queuedMusicForChannels2._Mask)) )
{
v10 = *(_QWORD *)(v10 + 8);
if ( v6 == *(_DWORD *)(v10 + 16) )
goto LABEL_17;
}
}
v10 = 0;
LABEL_17:
if ( v10 )
{
v12 = (_QWORD *)sub_140061B10(
&v7->m_audioState.m_queuedMusicForChannels2._Traitsobj._Mypair._Myval2._Myval2,
(__int64)v23,
(unsigned __int8 *)&v25);
v13 = (FMODQueuedMusic *)sub_1400565F0((__int64)v24, *v12 + 24LL);
FMODAudioEngine::triggerQueuedMusic(v7, v13);
sub_14005DF60(
&v7->m_audioState.m_queuedMusicForChannels2._Traitsobj._Mypair._Myval2._Myval2,
(unsigned __int8 *)&v25);
}
else
{
v14 = v8 & v7->m_audioState.m_queuedMusicForChannels1._Mask;
v15 = v7->m_audioState.m_queuedMusicForChannels1._Vec._Mypair._Myval2._Myfirst;
v16 = *((_QWORD *)v15 + 2 * v14 + 1);
if ( (std::_List_val>>::_Nodeptr)v16 != v7->m_audioState.m_queuedMusicForChannels1._List._Mypair._Myval2._Myhead )
{
if ( v6 == *(_DWORD *)(v16 + 16) )
{
LABEL_23:
v11 = v16;
}
else
{
while ( v16 != *((_QWORD *)v15 + 2 * v14) )
{
v16 = *(_QWORD *)(v16 + 8);
if ( v6 == *(_DWORD *)(v16 + 16) )
goto LABEL_23;
}
}
}
if ( v11 )
*(_BYTE *)(*(_QWORD *)sub_140061B10(
&v7->m_audioState.m_queuedMusicForChannels1._Traitsobj._Mypair._Myval2._Myval2,
(__int64)v23,
(unsigned __int8 *)&v25)
+ 100LL) = 1;
}
}