//
// GJBaseGameLayer::addProximityVolumeEffect from 0x10015e6e0 to 0x10015e90d (557 bytes)
//
// 4 xrefs:
// > GJBaseGameLayer::activateSongEditTrigger @ 0x10015a64d
// > GJBaseGameLayer::activateSFXTrigger @ 0x10015aa99
// > GJBaseGameLayer::activateSFXEditTrigger @ 0x10015add5
// > GJBaseGameLayer::activateSFXEditTrigger @ 0x10015ae5f
//
// 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::addProximityVolumeEffect(
GJBaseGameLayer *a1,
int a2,
int a3,
SFXTriggerGameObject *a4)
{
__int64 v5; // r15
std::__compressed_pair *>> *p_pair1; // rdx
std::__tree_end_node *>::pointer left; // rdi
std::__compressed_pair *>> *v9; // r13
std::__tree_end_node *>::pointer v10; // rax
std::__tree_end_node *> *v11; // rcx
std::__tree_end_node *> *v12; // rax
std::__tree_end_node *> **v13; // rcx
bool v14; // zf
char *v15; // r13
char *v16; // r12
std::__tree_end_node *> *v17; // rax
FMODAudioEngine *v18; // rax
__m128 v19; // [rsp+0h] [rbp-60h]
int m_controlID; // [rsp+2Ch] [rbp-34h]
std::__compressed_pair *>> *v22; // [rsp+30h] [rbp-30h]
std::__compressed_pair *>> *v23; // [rsp+30h] [rbp-30h]
float v24; // [rsp+30h] [rbp-30h]
v5 = (unsigned int)a3;
p_pair1 = &a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair1_;
left = a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair1_.__value_.__left_;
if ( left )
{
v9 = p_pair1;
v10 = left;
do
{
if ( *((_DWORD *)v10 + 8) < a2 )
{
v10 = (std::__tree_end_node *>::pointer)((char *)v10 + 8);
}
else if ( *((_DWORD *)v10 + 8) <= a2 )
{
if ( *((_DWORD *)v10 + 9) >= (int)v5 )
v9 = (std::__compressed_pair *>> *)v10;
v10 = (std::__tree_end_node *>::pointer)((char *)v10
+ 8 * (*((_DWORD *)v10 + 9) < (int)v5));
}
else
{
v9 = (std::__compressed_pair *>> *)v10;
}
v10 = *(std::__tree_end_node *>::pointer *)v10;
}
while ( v10 );
if ( v9 != p_pair1
&& SLODWORD(v9[4].__value_.__left_) <= a2
&& (SLODWORD(v9[4].__value_.__left_) < a2 || SHIDWORD(v9[4].__value_.__left_) <= (int)v5) )
{
v11 = (std::__tree_end_node *> *)v9[1].__value_.__left_;
if ( v11 )
{
do
{
v12 = v11;
v11 = (std::__tree_end_node *> *)v11->__left_;
}
while ( v11 );
}
else
{
v13 = (std::__tree_end_node *> **)v9;
do
{
v12 = v13[2];
v14 = v12->__left_ == (std::__tree_end_node *>::pointer)v13;
v13 = (std::__tree_end_node *> **)v12;
}
while ( !v14 );
}
v22 = p_pair1;
if ( (std::__compressed_pair *>> *)a1->m_gameState.m_proximityVolumeRelated.__tree_.__begin_node_ == v9 )
a1->m_gameState.m_proximityVolumeRelated.__tree_.__begin_node_ = v12;
--a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair3_.__value_;
sub_100165F60(left, v9);
operator delete(v9);
left = a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair1_.__value_.__left_;
p_pair1 = v22;
}
v19 = (__m128)*(unsigned __int64 *)&a4->m_targetGroupID;
m_controlID = a4->m_controlID;
if ( !left )
goto LABEL_25;
while ( 1 )
{
v15 = (char *)left;
if ( *((_DWORD *)left + 8) > a2 )
goto LABEL_26;
if ( *((_DWORD *)left + 8) < a2 )
{
LABEL_31:
left = *((std::__tree_end_node *>::pointer *)left + 1);
if ( !left )
{
v23 = (std::__compressed_pair *>> *)(v15 + 8);
goto LABEL_34;
}
}
else
{
if ( *((_DWORD *)left + 9) <= (int)v5 )
{
if ( *((_DWORD *)left + 9) >= (int)v5 )
goto LABEL_37;
goto LABEL_31;
}
LABEL_26:
left = *(std::__tree_end_node *>::pointer *)left;
if ( !*(_QWORD *)v15 )
{
v23 = (std::__compressed_pair *>> *)v15;
goto LABEL_34;
}
}
}
}
v19 = (__m128)*(unsigned __int64 *)&a4->m_targetGroupID;
m_controlID = a4->m_controlID;
LABEL_25:
v15 = (char *)p_pair1;
v23 = p_pair1;
LABEL_34:
v16 = v15;
v15 = (char *)operator new(0x40u);
*((_QWORD *)v15 + 4) = (v5 << 32) | (unsigned int)a2;
_mm_storel_ps((double *)v15 + 5, v19);
*((_DWORD *)v15 + 12) = m_controlID;
*((_QWORD *)v15 + 7) = a4;
*(_OWORD *)v15 = 0;
*((_QWORD *)v15 + 2) = v16;
v23->__value_.__left_ = (std::__tree_end_node *>::pointer)v15;
v17 = (std::__tree_end_node *> *)a1->m_gameState.m_proximityVolumeRelated.__tree_.__begin_node_->__left_;
if ( v17 )
a1->m_gameState.m_proximityVolumeRelated.__tree_.__begin_node_ = v17;
sub_100054DD0((__int64 *)a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair1_.__value_.__left_, (__int64 *)v15);
++a1->m_gameState.m_proximityVolumeRelated.__tree_.__pair3_.__value_;
LABEL_37:
v24 = GJBaseGameLayer::volumeForProximityEffect(a1, (SFXTriggerInstance *)(v15 + 40));
v18 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::setChannelVolumeMod(v18, a2, (AudioTargetType)v5, v24);
}