//
// GJBaseGameLayer::processSFXState from 0x100206164 to 0x1002064cc (872 bytes)
//
// 4 xrefs:
// > GJBaseGameLayer::canProcessSFX @ 0x1002060cc
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100206b6c
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100206c00
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100206d24
//
// 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 __fastcall GJBaseGameLayer::processSFXState(
GJBaseGameLayer *a1,
SFXTriggerState *a2,
SFXTriggerState *a3,
int a4,
float m_unkDouble1)
{
SFXTriggerGameObject *m_sfxTriggerGameObject; // x8
double v6; // d1
double m_unkDouble3; // d16
float m_unkFloat1; // s2
float m_unkFloat2; // s4
double m_unkDouble2; // d3
double v11; // d17
char v12; // w13
float v13; // s7
char v14; // w12
__int64 v15; // x13
double *v16; // x13
float v17; // s16
char v18; // w13
float v19; // s18
char v20; // w12
__int64 v21; // x13
char *v22; // x13
float *v23; // x14
float v24; // s20
float v25; // s19
double v26; // d21
float v27; // s22
float v28; // s20
float v29; // s17
__int64 v30; // x8
double *v31; // x8
double v32; // d2
float v33; // s3
double v34; // d2
float v35; // s3
SFXTriggerGameObject *v36; // x8
_BOOL4 m_unkBool; // w8
float v38; // s2
float v39; // s3
float v40; // s1
double v42; // d0
double m_duration; // d1
float m_unkFloat3; // s2
double v45; // d1
double v46; // d2
float v47; // s2
if ( a2->m_processed )
return;
if ( a3 )
{
m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject;
if ( a3->m_sfxTriggerGameObject->m_stop )
goto LABEL_72;
m_unkDouble1 = a3->m_unkDouble1;
if ( !m_sfxTriggerGameObject->m_changeVolume && !m_sfxTriggerGameObject->m_stopLoop )
goto LABEL_43;
}
v6 = m_unkDouble1;
m_unkDouble3 = a2->m_unkDouble3;
if ( m_unkDouble3 >= m_unkDouble1 )
goto LABEL_34;
m_unkFloat1 = a2->m_unkFloat1;
m_unkFloat2 = a2->m_unkFloat2;
m_unkDouble2 = a2->m_unkDouble2;
do
{
v11 = m_unkDouble3;
v12 = 1;
v13 = m_unkDouble1;
do
{
v14 = v12;
if ( (v12 & 1) != 0 )
v15 = 72;
else
v15 = 104;
v16 = (double *)((char *)a2 + v15);
if ( *((_BYTE *)v16 + 24) == 1 )
{
v17 = *v16 + v16[1];
if ( v13 > v17 )
v13 = *v16 + v16[1];
}
v12 = 0;
}
while ( (v14 & 1) != 0 );
m_unkDouble3 = v13;
v18 = 1;
v19 = m_unkFloat1;
while ( 1 )
{
v20 = v18;
if ( (v18 & 1) != 0 )
v21 = 72;
else
v21 = 104;
v22 = (char *)a2 + v21;
if ( v22[24] != 1 )
goto LABEL_29;
v23 = (v20 & 1) != 0 ? &a2->m_unkFloat1 : &a2->m_unkFloat2;
v24 = *v23;
v25 = *((float *)v22 + 4);
v26 = *((double *)v22 + 1);
if ( *(double *)v22 + v26 <= m_unkDouble3 )
{
v22[24] = 0;
}
else
{
v27 = m_unkDouble3 - *(double *)v22;
v25 = v24 + (float)(v25 - v24) * (v27 / v26);
}
v28 = (float)(v24 + v25) * 0.5;
if ( (v20 & 1) == 0 )
break;
a2->m_unkFloat1 = v25;
m_unkFloat1 = v25;
v19 = v28;
LABEL_29:
v18 = 0;
if ( (v20 & 1) == 0 )
{
v28 = m_unkFloat2;
goto LABEL_32;
}
}
a2->m_unkFloat2 = v25;
m_unkFloat2 = v25;
LABEL_32:
v29 = m_unkDouble3 - v11;
m_unkDouble2 = m_unkDouble2 + (float)((float)(v28 * (float)(v19 * v29)) * 1000.0);
}
while ( v13 < m_unkDouble1 );
a2->m_unkDouble2 = m_unkDouble2;
a2->m_unkDouble3 = m_unkDouble3;
LABEL_34:
v30 = 104;
if ( !a4 )
v30 = 72;
v31 = (double *)((char *)a2 + v30);
if ( !a3 || !a3->m_sfxTriggerGameObject->m_changeVolume )
{
if ( *((_BYTE *)v31 + 24) == 1 )
{
v34 = v31[1];
if ( *v31 + v34 >= v6 )
{
v35 = v6 - *v31;
*v31 = v6;
v31[1] = v34 - v35;
if ( a4 )
goto LABEL_44;
goto LABEL_47;
}
*((_BYTE *)v31 + 24) = 0;
}
LABEL_43:
if ( a4 )
goto LABEL_44;
LABEL_47:
if ( a3 )
{
v36 = a3->m_sfxTriggerGameObject;
if ( !a3->m_sfxTriggerGameObject->m_changeSpeed )
{
LABEL_66:
if ( v36->m_stopLoop && a2->m_unkBool1 )
{
a2->m_unkBool1 = 0;
a2->m_unkDouble2 = a2->m_unkDouble2
- (float)(a2->m_unkFloat4 * (float)(int)vcvtmd_s64_f64(a2->m_unkDouble2 / a2->m_unkFloat4));
}
goto LABEL_69;
}
}
m_unkBool = a2->m_sfxStateContainers.__elems_[2].m_unkBool;
if ( m_unkBool )
{
v38 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble2;
v39 = m_unkDouble1 - a2->m_sfxStateContainers.__elems_[2].m_unkDouble1;
v40 = a2->m_sfxStateContainers.__elems_[2].m_unkFloat1;
if ( v38 > 0.0 && v38 > v39 )
v40 = a2->m_unkFloat3 + (float)((float)(v40 - a2->m_unkFloat3) * (float)(v39 / v38));
a2->m_unkFloat3 = v40;
}
if ( a3 && a3->m_sfxTriggerGameObject->m_changeSpeed )
{
v42 = m_unkDouble1;
m_duration = a3->m_sfxTriggerGameObject->m_duration;
m_unkFloat3 = a3->m_unkFloat3;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v42;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble2 = m_duration;
a2->m_sfxStateContainers.__elems_[2].m_unkFloat1 = m_unkFloat3;
a2->m_sfxStateContainers.__elems_[2].m_unkFloat2 = 0.0;
a2->m_sfxStateContainers.__elems_[2].m_unkBool = 1;
}
else if ( m_unkBool )
{
v46 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble1;
v45 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble2;
v42 = m_unkDouble1;
if ( v46 + v45 >= v42 )
{
v47 = v42 - v46;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v42;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble2 = v45 - v47;
}
else
{
a2->m_sfxStateContainers.__elems_[2].m_unkBool = 0;
}
}
else
{
v42 = m_unkDouble1;
}
a2->m_unkDouble4 = v42;
if ( !a3 )
goto LABEL_69;
LABEL_65:
v36 = a3->m_sfxTriggerGameObject;
goto LABEL_66;
}
v32 = a3->m_sfxTriggerGameObject->m_duration;
v33 = a3->m_unkFloat1;
*v31 = v6;
v31[1] = v32;
*((float *)v31 + 4) = v33;
*((_DWORD *)v31 + 5) = 0;
*((_BYTE *)v31 + 24) = 1;
if ( !a4 )
goto LABEL_47;
LABEL_44:
if ( a3 )
goto LABEL_65;
LABEL_69:
if ( a2->m_sfxTriggerGameObject->m_objectID == 3602 && !a2->m_unkBool1 && a2->m_unkDouble2 > a2->m_unkFloat4 )
LABEL_72:
a2->m_processed = 1;
}