//
// GJBaseGameLayer::processSongState from 0x100207074 to 0x100207460 (1004 bytes)
//
// 2 xrefs:
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100206774
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x10020688c
//
// 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
//
bool __fastcall GJBaseGameLayer::processSongState(
GJBaseGameLayer *a1,
int a2,
float a3,
float a4,
int a5,
float a6,
float a7,
std::vector *a8,
SongTriggerGameObject *a9)
{
std::__vector_base::pointer begin; // x25
SongTriggerState *end; // x26
SongTriggerGameObject *v19; // x23
float *v20; // x24
SongTriggerGameObject *m_songTriggerGameObject; // x28
float m_unkDouble; // s0
float m_duration; // s14
float v24; // s13
float v25; // s0
float v26; // s1
float v27; // s0
float v28; // s2
float v29; // s1
float v31; // s15
float v32; // s14
float v33; // s12
float v34; // s0
float v35; // s13
float v36; // s1
FMODAudioEngine *v37; // x0
FMODAudioEngine *v39; // x0
FMODAudioEngine *v40; // x0
float v41; // s0
float v42; // s1
float v43; // s12
float v44; // s13
bool v45; // cc
float v46; // s14
FMODAudioEngine *v47; // x0
FMODAudioEngine *v48; // x0
FMODAudioEngine *v49; // x0
FMOD::Channel *ActiveMusicChannel; // x0
FMODAudioEngine *v51; // x0
unsigned int v52; // [xsp+8h] [xbp-98h] BYREF
unsigned int v53; // [xsp+Ch] [xbp-94h] BYREF
if ( !a8 )
goto LABEL_56;
begin = a8->__begin_;
end = a8->__end_;
if ( a8->__begin_ == end )
goto LABEL_56;
v19 = nullptr;
v20 = nullptr;
do
{
m_songTriggerGameObject = begin->m_songTriggerGameObject;
m_unkDouble = begin->m_unkDouble;
begin->m_songTriggerGameObject->m_spawnTriggerDelay = m_unkDouble;
if ( m_unkDouble >= a3 )
{
if ( m_songTriggerGameObject->m_stop )
{
v37 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::stopMusic(v37, a2);
return 0;
}
if ( m_songTriggerGameObject->m_changeVolume )
{
if ( v19 )
{
m_duration = v19->m_duration;
v24 = m_unkDouble - v19->m_spawnTriggerDelay;
FMODAudioEngine::sharedEngine();
v25 = FMODAudioEngine::pitchForIdx(v19->m_speed);
v26 = v24 - m_duration;
if ( m_duration > 0.0 )
{
if ( m_duration <= v24 )
{
v24 = m_duration;
}
else
{
v25 = a7 + (float)((float)(v25 - a7) * (float)(v24 / m_duration));
v26 = 0.0;
}
a5 = (int)(float)((float)a5 + (float)((float)(v24 * (float)((float)(a7 + v25) * 0.5)) * 1000.0));
}
if ( v26 > 0.0 )
a5 = (int)(float)((float)a5 + (float)((float)(v26 * v25) * 1000.0));
v19 = m_songTriggerGameObject;
a7 = v25;
}
else
{
a5 = (int)(float)((float)a5 + (float)((float)(a7 * (float)(m_unkDouble - a3)) * 1000.0));
v19 = m_songTriggerGameObject;
}
}
if ( m_songTriggerGameObject->m_changeSpeed )
{
if ( v20 )
{
v27 = v20[363];
v28 = m_songTriggerGameObject->m_spawnTriggerDelay - v20[452];
v29 = v20[470];
if ( v27 <= 0.0 || v27 <= v28 )
{
v20 = (float *)m_songTriggerGameObject;
a6 = v29;
goto LABEL_26;
}
a6 = a6 + (float)((float)(v29 - a6) * (float)(v28 / v27));
}
v20 = (float *)m_songTriggerGameObject;
}
}
LABEL_26:
++begin;
}
while ( begin != end );
if ( v19 )
{
v31 = v19->m_duration;
v32 = a4 - v19->m_spawnTriggerDelay;
FMODAudioEngine::sharedEngine();
v33 = FMODAudioEngine::pitchForIdx(v19->m_speed);
v34 = v32 - v31;
v35 = 0.0;
if ( v31 <= 0.0 )
{
a7 = v33;
}
else
{
if ( v31 <= v32 )
{
v32 = v31;
v36 = v33;
}
else
{
v35 = v31 - v32;
v36 = a7 + (float)((float)(v33 - a7) * (float)(v32 / v31));
v34 = 0.0;
}
a5 = (int)(float)((float)a5 + (float)((float)(v32 * (float)((float)(a7 + v36) * 0.5)) * 1000.0));
a7 = v36;
}
if ( v34 > 0.0 )
a5 = (int)(float)((float)a5 + (float)((float)(a7 * v34) * 1000.0));
v39 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::updateChannel(v39, a2, MusicChannel, Pitch, 0.0, a7);
if ( v35 > 0.0 )
{
v40 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::updateChannel(v40, a2, MusicChannel, Pitch, v35, v33);
}
}
if ( v20 )
{
v41 = v20[363];
v42 = a4 - v20[452];
v43 = v20[470];
v44 = 0.0;
v45 = v41 <= 0.0 || v41 <= v42;
v46 = v20[470];
if ( !v45 )
{
v44 = v41 - v42;
v46 = a6 + (float)((float)(v43 - a6) * (float)(v42 / v41));
}
v47 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::updateChannel(v47, a2, MusicChannel, Volume, 0.0, v46);
if ( v44 > 0.0 )
{
v48 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::updateChannel(v48, a2, MusicChannel, Volume, v44, v43);
}
}
if ( !v19 )
{
LABEL_56:
a5 = (int)(float)((float)a5 + (float)((float)((float)(a4 - a3) * a7) * 1000.0));
if ( a9 )
goto LABEL_49;
LABEL_57:
if ( !a1->m_levelSettings->m_dontReset )
goto LABEL_54;
return 1;
}
if ( !a9 )
goto LABEL_57;
LABEL_49:
if ( a9->m_loop && a9->m_end >= 1 )
{
v49 = FMODAudioEngine::sharedEngine();
ActiveMusicChannel = FMODAudioEngine::getActiveMusicChannel(v49, a2);
if ( ActiveMusicChannel )
{
FMOD::Channel::getLoopPoints(ActiveMusicChannel, &v53, 1u, &v52, 1u);
a5 = (a5 - v53) % (v52 - v53) + v53;
}
}
if ( !a9->m_dontReset )
{
LABEL_54:
v51 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::setMusicTimeMS(v51, a5, 0, a2);
}
return 1;
}