//
// GJBaseGameLayer::processSFXState from 0x868f14 to 0x86930c (1016 bytes)
//
// 5 xrefs:
// > GJBaseGameLayer::canProcessSFX @ 0x88506c
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x88dc88
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x88dd64
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x88df28
// > ??> @ 0x515a0
//
// 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 GJBaseGameLayer::processSFXState(
GJBaseGameLayer *a1,
SFXTriggerState *a2,
SFXTriggerState *a3,
int a4,
float m_unkDouble1)
{
double v5; // d18
double m_unkDouble3; // d1
std::array *p_m_sfxStateContainers; // x5
double m_unkDouble2; // d17
SFXStateContainer *v9; // x0
float m_unkFloat1; // s3
float m_unkFloat2; // s4
double v12; // d7
double v13; // d16
double v14; // d6
float v15; // s5
_BOOL4 m_unkBool; // w6
float v17; // s2
double v18; // d2
float v19; // s5
float v20; // s7
double v21; // d5
double v22; // d16
float v23; // s6
float v24; // s5
float v25; // s1
float v26; // s1
std::array *v27; // x0
SFXTriggerGameObject *m_sfxTriggerGameObject; // x5
float m_duration; // s1
float v30; // w6
double v31; // d1
double v32; // d2
double v33; // d1
double v34; // d2
float v35; // s4
float v36; // s3
float v37; // s0
float v38; // s0
float m_unkFloat3; // w0
float m_unkFloat4; // s1
double v41; // d6
float v42; // s2
bool v43; // nf
float v44; // s1
float v45; // s0
if ( a2->m_processed )
return;
if ( !a3 )
goto LABEL_3;
m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject;
if ( a3->m_sfxTriggerGameObject->m_stop )
{
LABEL_61:
a2->m_processed = 1;
return;
}
m_unkDouble1 = a3->m_unkDouble1;
if ( m_sfxTriggerGameObject->m_changeVolume || m_sfxTriggerGameObject->m_stopLoop )
{
LABEL_3:
v5 = m_unkDouble1;
m_unkDouble3 = a2->m_unkDouble3;
if ( m_unkDouble3 < m_unkDouble1 )
{
p_m_sfxStateContainers = &a2->m_sfxStateContainers;
m_unkDouble2 = a2->m_unkDouble2;
v9 = &a2->m_sfxStateContainers.__elems_[1];
m_unkFloat1 = a2->m_unkFloat1;
m_unkFloat2 = a2->m_unkFloat2;
if ( a2->m_sfxStateContainers.__elems_[0].m_unkBool )
goto LABEL_5;
LABEL_19:
if ( a2->m_sfxStateContainers.__elems_[1].m_unkBool )
{
v21 = v9->m_unkDouble1;
v22 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble2;
v41 = v9->m_unkDouble1 + v22;
v42 = v41;
if ( v42 >= m_unkDouble1 )
v42 = m_unkDouble1;
v18 = v42;
v43 = v18 < v41;
v23 = a2->m_sfxStateContainers.__elems_[1].m_unkFloat1;
if ( v43 )
{
LABEL_15:
v24 = v18 - v21;
v23 = m_unkFloat2 + (float)(v23 - m_unkFloat2) * (v24 / v22);
}
else
{
LABEL_56:
a2->m_sfxStateContainers.__elems_[1].m_unkBool = 0;
}
a2->m_unkFloat2 = v23;
m_unkFloat2 = (float)(m_unkFloat2 + v23) * 0.5;
while ( 1 )
{
v25 = v18 - m_unkDouble3;
m_unkDouble2 = m_unkDouble2 + (float)((float)((float)(v25 * m_unkFloat1) * m_unkFloat2) * 1000.0);
if ( v5 <= v18 )
break;
m_unkDouble3 = v18;
m_unkFloat1 = a2->m_unkFloat1;
m_unkFloat2 = a2->m_unkFloat2;
if ( !a2->m_sfxStateContainers.__elems_[0].m_unkBool )
goto LABEL_19;
LABEL_5:
v12 = p_m_sfxStateContainers->__elems_[0].m_unkDouble1;
v13 = a2->m_sfxStateContainers.__elems_[0].m_unkDouble2;
v14 = p_m_sfxStateContainers->__elems_[0].m_unkDouble1 + v13;
v15 = v14;
if ( m_unkDouble1 <= v15 )
v15 = m_unkDouble1;
m_unkBool = a2->m_sfxStateContainers.__elems_[1].m_unkBool;
if ( a2->m_sfxStateContainers.__elems_[1].m_unkBool )
{
v17 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble1 + a2->m_sfxStateContainers.__elems_[1].m_unkDouble2;
if ( v17 >= v15 )
v17 = v15;
v12 = p_m_sfxStateContainers->__elems_[0].m_unkDouble1;
v13 = a2->m_sfxStateContainers.__elems_[0].m_unkDouble2;
v18 = v17;
v14 = p_m_sfxStateContainers->__elems_[0].m_unkDouble1 + v13;
}
else
{
v18 = v15;
}
v19 = a2->m_sfxStateContainers.__elems_[0].m_unkFloat1;
if ( v18 >= v14 )
{
a2->m_sfxStateContainers.__elems_[0].m_unkBool = 0;
}
else
{
v20 = v18 - v12;
v19 = m_unkFloat1 + (float)(v19 - m_unkFloat1) * (v20 / v13);
}
a2->m_unkFloat1 = v19;
m_unkFloat1 = (float)(m_unkFloat1 + v19) * 0.5;
if ( m_unkBool )
{
v21 = v9->m_unkDouble1;
v22 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble2;
v23 = a2->m_sfxStateContainers.__elems_[1].m_unkFloat1;
if ( v18 >= v9->m_unkDouble1 + v22 )
goto LABEL_56;
goto LABEL_15;
}
}
}
else
{
v18 = m_unkDouble1;
v26 = v5 - m_unkDouble3;
m_unkDouble2 = m_unkDouble2 + (float)((float)((float)(v26 * m_unkFloat1) * m_unkFloat2) * 1000.0);
}
a2->m_unkDouble2 = m_unkDouble2;
a2->m_unkDouble3 = v18;
}
v27 = &a2->m_sfxStateContainers;
if ( a4 )
v27 = (std::array *)&a2->m_sfxStateContainers.__elems_[1];
if ( a3 && (m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject, a3->m_sfxTriggerGameObject->m_changeVolume) )
{
m_duration = m_sfxTriggerGameObject->m_duration;
v30 = a3->m_unkFloat1;
v27->__elems_[0].m_unkBool = 1;
v27->__elems_[0].m_unkDouble1 = v5;
v27->__elems_[0].m_unkFloat1 = v30;
v27->__elems_[0].m_unkDouble2 = m_duration;
v27->__elems_[0].m_unkFloat2 = 0.0;
if ( a4 )
goto LABEL_27;
}
else
{
if ( v27->__elems_[0].m_unkBool )
{
v31 = v27->__elems_[0].m_unkDouble1;
v32 = v27->__elems_[0].m_unkDouble2;
if ( v27->__elems_[0].m_unkDouble1 + v32 >= v5 )
{
v27->__elems_[0].m_unkDouble1 = v5;
v44 = v5 - v31;
v27->__elems_[0].m_unkDouble2 = v32 - v44;
}
else
{
v27->__elems_[0].m_unkBool = 0;
}
}
if ( a4 )
{
LABEL_27:
if ( !a3 )
{
LABEL_28:
if ( a2->m_sfxTriggerGameObject->m_objectID != 3602 || a2->m_unkBool1 )
return;
goto LABEL_60;
}
goto LABEL_49;
}
if ( !a3 )
{
if ( !a2->m_sfxStateContainers.__elems_[2].m_unkBool )
{
LABEL_47:
a2->m_unkDouble4 = v5;
goto LABEL_48;
}
goto LABEL_41;
}
m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject;
}
}
else if ( a4 )
{
goto LABEL_27;
}
if ( m_sfxTriggerGameObject->m_changeSpeed )
{
v5 = m_unkDouble1;
if ( !a2->m_sfxStateContainers.__elems_[2].m_unkBool )
{
LABEL_46:
v38 = m_sfxTriggerGameObject->m_duration;
m_unkFloat3 = a3->m_unkFloat3;
a2->m_sfxStateContainers.__elems_[2].m_unkBool = 1;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v5;
a2->m_sfxStateContainers.__elems_[2].m_unkFloat1 = m_unkFloat3;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble2 = v38;
a2->m_sfxStateContainers.__elems_[2].m_unkFloat2 = 0.0;
goto LABEL_47;
}
LABEL_41:
v33 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble1;
v34 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble2;
v35 = v34;
v36 = a2->m_sfxStateContainers.__elems_[2].m_unkFloat1;
v37 = v5 - v33;
if ( v35 > v37 && v35 > 0.0 )
v36 = a2->m_unkFloat3 + (float)((float)(v36 - a2->m_unkFloat3) * (float)(v37 / v35));
a2->m_unkFloat3 = v36;
if ( !a3 || (m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject, !a3->m_sfxTriggerGameObject->m_changeSpeed) )
{
if ( v33 + v34 >= v5 )
{
a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v5;
a2->m_unkDouble4 = v5;
v45 = v5 - v33;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble2 = v34 - v45;
}
else
{
a2->m_sfxStateContainers.__elems_[2].m_unkBool = 0;
a2->m_unkDouble4 = v5;
}
LABEL_48:
if ( !a3 )
goto LABEL_28;
LABEL_49:
m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject;
goto LABEL_50;
}
goto LABEL_46;
}
LABEL_50:
if ( !m_sfxTriggerGameObject->m_stopLoop )
goto LABEL_28;
if ( a2->m_unkBool1 )
{
m_unkFloat4 = a2->m_unkFloat4;
a2->m_unkBool1 = 0;
a2->m_unkDouble2 = a2->m_unkDouble2
- (float)(m_unkFloat4 * (float)(int)vcvtmd_s64_f64(a2->m_unkDouble2 / m_unkFloat4));
goto LABEL_28;
}
if ( a2->m_sfxTriggerGameObject->m_objectID != 3602 )
return;
LABEL_60:
if ( a2->m_unkDouble2 > a2->m_unkFloat4 )
goto LABEL_61;
}