//
// GJBaseGameLayer::processSFXState from 0x10015fbd0 to 0x1001600e2 (1298 bytes)
//
// 4 xrefs:
// > GJBaseGameLayer::canProcessSFX @ 0x10015fb3e
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100161106
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x1001613a4
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x10016172c
//
// 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
//
// local variable allocation has failed, the output may be wrong!
void __fastcall GJBaseGameLayer::processSFXState(
GJBaseGameLayer *a1,
SFXTriggerState *a2,
SFXTriggerState *a3,
int a4,
float a5)
{
SFXTriggerGameObject *m_sfxTriggerGameObject; // rax
__int128 v6; // xmm0
double v7; // xmm1_8
double m_unkDouble3; // xmm7_8
float m_unkFloat1; // xmm3_4
float m_unkFloat2; // xmm5_4
double m_unkDouble2; // xmm2_8
bool m_unkBool; // al
bool v13; // di
float v14; // xmm12_4
float v15; // xmm7_4
float v16; // xmm8_4
double v17; // xmm9_8
float v18; // xmm11_4
double m_unkDouble1; // xmm12_8
double v20; // xmm10_8
float v21; // xmm12_4
float v22; // xmm8_4
float v23; // xmm9_4
float v24; // xmm10_4
float v25; // xmm11_4
double v26; // xmm13_8
double v27; // xmm12_8
float v28; // xmm13_4
__int64 v29; // rax
double m_duration; // xmm2_8
float v31; // xmm3_4
double v32; // xmm3_8
double v33; // xmm2_8
float v34; // xmm3_4
SFXTriggerGameObject *v35; // rax
bool v36; // al
float v37; // xmm2_4
float v38; // xmm1_4
float v39; // xmm3_4
float m_unkFloat3; // xmm1_4
__m128d v41; // xmm0
double v42; // xmm2_8
double v43; // xmm1_8
double v44; // xmm0_8
float v45; // xmm2_4
float m_unkFloat4; // xmm1_4
__m128d v47; // xmm3
if ( a2->m_processed )
return;
if ( a3 )
{
m_sfxTriggerGameObject = a3->m_sfxTriggerGameObject;
if ( a3->m_sfxTriggerGameObject->m_stop )
{
LABEL_61:
a2->m_processed = 1;
return;
}
v6 = *(unsigned __int64 *)&a3->m_unkDouble1;
a5 = *(double *)&v6;
if ( !m_sfxTriggerGameObject->m_changeVolume && !m_sfxTriggerGameObject->m_stopLoop )
goto LABEL_33;
}
v7 = a5;
m_unkDouble3 = a2->m_unkDouble3;
if ( a5 > m_unkDouble3 )
{
m_unkFloat1 = a2->m_unkFloat1;
m_unkFloat2 = a2->m_unkFloat2;
m_unkDouble2 = a2->m_unkDouble2;
m_unkBool = a2->m_sfxStateContainers.__elems_[0].m_unkBool;
v13 = a2->m_sfxStateContainers.__elems_[1].m_unkBool;
while ( 1 )
{
v16 = a5;
if ( m_unkBool )
{
v22 = a2->m_sfxStateContainers.__elems_[0].m_unkDouble1 + a2->m_sfxStateContainers.__elems_[0].m_unkDouble2;
v16 = fminf(v22, a5);
if ( !v13 )
{
LABEL_12:
v17 = v16;
if ( !m_unkBool )
goto LABEL_17;
goto LABEL_13;
}
}
else if ( !v13 )
{
goto LABEL_12;
}
v23 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble1 + a2->m_sfxStateContainers.__elems_[1].m_unkDouble2;
v16 = fminf(v23, v16);
v17 = v16;
if ( !m_unkBool )
{
LABEL_17:
v24 = m_unkFloat1;
if ( v13 )
goto LABEL_21;
goto LABEL_8;
}
LABEL_13:
v18 = a2->m_sfxStateContainers.__elems_[0].m_unkFloat1;
m_unkDouble1 = a2->m_sfxStateContainers.__elems_[0].m_unkDouble1;
v20 = a2->m_sfxStateContainers.__elems_[0].m_unkDouble2;
if ( m_unkDouble1 + v20 <= v17 )
{
a2->m_sfxStateContainers.__elems_[0].m_unkBool = 0;
m_unkBool = 0;
}
else
{
v21 = v17 - m_unkDouble1;
v18 = v21 / v20 * (float)(v18 - m_unkFloat1) + m_unkFloat1;
}
v24 = (float)(m_unkFloat1 + v18) * 0.5;
a2->m_unkFloat1 = v18;
m_unkFloat1 = v18;
if ( v13 )
{
LABEL_21:
v25 = a2->m_sfxStateContainers.__elems_[1].m_unkFloat1;
v26 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble1;
v27 = a2->m_sfxStateContainers.__elems_[1].m_unkDouble2;
if ( v26 + v27 <= v17 )
{
a2->m_sfxStateContainers.__elems_[1].m_unkBool = 0;
v13 = 0;
}
else
{
v28 = v17 - v26;
v25 = v28 / v27 * (float)(v25 - m_unkFloat2) + m_unkFloat2;
}
v14 = (float)(m_unkFloat2 + v25) * 0.5;
a2->m_unkFloat2 = v25;
m_unkFloat2 = v25;
goto LABEL_9;
}
LABEL_8:
v14 = m_unkFloat2;
LABEL_9:
v15 = v17 - m_unkDouble3;
m_unkDouble2 = m_unkDouble2 + (float)((float)((float)(v24 * v15) * v14) * 1000.0);
m_unkDouble3 = v17;
if ( a5 <= v16 )
{
a2->m_unkDouble2 = m_unkDouble2;
a2->m_unkDouble3 = v17;
break;
}
}
}
v29 = (32 * (unsigned int)(a4 != 0)) | 0x48LL;
if ( a3 && a3->m_sfxTriggerGameObject->m_changeVolume )
{
m_duration = a3->m_sfxTriggerGameObject->m_duration;
v31 = a3->m_unkFloat1;
*(double *)((char *)&a2->m_sfxTriggerGameObject + v29) = v7;
*(double *)((char *)&a2->m_unkInt1 + v29) = m_duration;
*(float *)((char *)&a2->m_unkDouble1 + v29) = v31;
*(_DWORD *)((char *)&a2->m_unkDouble1 + v29 + 4) = 0;
*((_BYTE *)&a2->m_unkDouble2 + v29) = 1;
if ( !a4 )
goto LABEL_37;
LABEL_34:
if ( !a3 )
goto LABEL_58;
LABEL_54:
v35 = a3->m_sfxTriggerGameObject;
goto LABEL_55;
}
if ( *((_BYTE *)&a2->m_unkDouble2 + v29) != 1 )
goto LABEL_33;
v32 = *(double *)((char *)&a2->m_sfxTriggerGameObject + v29);
v33 = *(double *)((char *)&a2->m_unkInt1 + v29);
if ( v7 > v32 + v33 )
{
*((_BYTE *)&a2->m_unkDouble2 + v29) = 0;
LABEL_33:
if ( a4 )
goto LABEL_34;
goto LABEL_37;
}
v34 = v7 - v32;
*(double *)((char *)&a2->m_sfxTriggerGameObject + v29) = v7;
*(double *)((char *)&a2->m_unkInt1 + v29) = v33 - v34;
if ( a4 )
goto LABEL_34;
LABEL_37:
if ( !a3 || (v35 = a3->m_sfxTriggerGameObject, a3->m_sfxTriggerGameObject->m_changeSpeed) )
{
v36 = a2->m_sfxStateContainers.__elems_[2].m_unkBool;
if ( v36 )
{
v37 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble2;
v38 = a2->m_sfxStateContainers.__elems_[2].m_unkFloat1;
if ( v37 > 0.0 )
{
v39 = a5 - a2->m_sfxStateContainers.__elems_[2].m_unkDouble1;
if ( v37 > v39 )
v38 = (float)((float)(v39 / v37) * (float)(v38 - a2->m_unkFloat3)) + a2->m_unkFloat3;
}
a2->m_unkFloat3 = v38;
}
if ( a3 && a3->m_sfxTriggerGameObject->m_changeSpeed )
{
m_unkFloat3 = a3->m_unkFloat3;
v41 = _mm_cvtps_pd(_mm_insert_ps(*(__m128 *)&a5, (__m128)LODWORD(a3->m_sfxTriggerGameObject->m_duration), 16));
*(__m128d *)&a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v41;
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;
a2->m_unkDouble4 = v41.f64[0];
}
else if ( v36 )
{
v42 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble1;
v43 = a2->m_sfxStateContainers.__elems_[2].m_unkDouble2;
v44 = a5;
if ( v44 <= v42 + v43 )
{
v45 = v44 - v42;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble1 = v44;
a2->m_sfxStateContainers.__elems_[2].m_unkDouble2 = v43 - v45;
a2->m_unkDouble4 = v44;
if ( !a3 )
goto LABEL_58;
}
else
{
a2->m_sfxStateContainers.__elems_[2].m_unkBool = 0;
a2->m_unkDouble4 = v44;
if ( !a3 )
goto LABEL_58;
}
}
else
{
a2->m_unkDouble4 = a5;
if ( !a3 )
goto LABEL_58;
}
goto LABEL_54;
}
LABEL_55:
if ( v35->m_stopLoop && a2->m_unkBool1 )
{
a2->m_unkBool1 = 0;
m_unkFloat4 = a2->m_unkFloat4;
v47 = (__m128d)*(unsigned __int64 *)&a2->m_unkDouble2;
v47.f64[0] = v47.f64[0] / m_unkFloat4;
a2->m_unkDouble2 = a2->m_unkDouble2
- (float)(_mm_cvtepi32_ps(_mm_cvttpd_epi32(_mm_round_sd((__m128d)0LL, v47, 9))).f32[0] * m_unkFloat4);
}
LABEL_58:
if ( a2->m_sfxTriggerGameObject->m_objectID == 3602 && !a2->m_unkBool1 && a2->m_unkDouble2 > a2->m_unkFloat4 )
goto LABEL_61;
}