//
// GJBaseGameLayer::volumeForProximityEffect from 0x47852c to 0x4787c6 (666 bytes)
//
// 3 xrefs:
// > GJBaseGameLayer::updateProximityVolumeEffects @ 0x478808
// > GJBaseGameLayer::addProximityVolumeEffect @ 0x484a48
// > GJBaseGameLayer::activateSFXTrigger @ 0x484b70
//
// 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
//
float GJBaseGameLayer::volumeForProximityEffect(GJBaseGameLayer *a1, SFXTriggerInstance *a2)
{
cocos2d::CCDirector *v4; // r0
float m_cameraZoom; // s13
SFXTriggerGameObject *m_sfxTriggerGameObject; // r4
cocos2d::CCArray *Group; // r8
int v8; // r2
bool m_cameraDistance; // r3
cocos2d::CCPoint *v10; // r1
_BOOL4 m_isDualMode; // r7
float v12; // r0
int v13; // r2
bool v14; // r3
PlayerObject *m_player2; // r0
GameObject *MainObject; // r0
int v17; // r6
float v20; // r10
float m_volumeNear; // s18
int m_minDistFar; // r6
float m_volumeFar; // s19
float v24; // s16
cocos2d::CCPoint v25; // r1
float MinDistance; // r0
float v27; // s17
const cocos2d::CCPoint *v28; // r0
cocos2d::CCPoint v29; // r1
const cocos2d::CCPoint *v30; // r0
cocos2d::CCPoint v31; // r1
float v32; // s14
float v33; // s15
float *p_m_volumeMedium; // r3
float v35; // s17
int v36; // [sp+4h] [bp-30h]
int v37; // [sp+4h] [bp-30h]
int v38; // [sp+4h] [bp-30h]
int m_minDistMedium; // [sp+8h] [bp-2Ch]
cocos2d::CCSize v40; // [sp+14h] [bp-20h] BYREF
_BYTE v41[8]; // [sp+1Ch] [bp-18h] BYREF
cocos2d::CCPoint v42; // [sp+24h] [bp-10h] BYREF
cocos2d::CCPoint v43; // [sp+2Ch] [bp-8h] BYREF
cocos2d::CCPoint v44; // [sp+34h] [bp+0h] BYREF
v4 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(&v40, v4);
m_cameraZoom = a1->m_gameState.m_cameraZoom;
v40.width = v40.width / m_cameraZoom;
v40.height = v40.height / m_cameraZoom;
cocos2d::CCPoint::CCPoint(&v44, v40.width * 0.5, v40.height * 0.5);
cocos2d::CCPoint::operator+(v41, &a1->m_gameState.m_cameraPosition, &v44);
m_sfxTriggerGameObject = a2->m_sfxTriggerGameObject;
Group = GJBaseGameLayer::getGroup(a1, a2->m_groupID1);
cocos2d::CCPoint::CCPoint(&v42);
m_cameraDistance = m_sfxTriggerGameObject->m_cameraDistance;
if ( m_cameraDistance )
{
v10 = (cocos2d::CCPoint *)v41;
}
else
{
if ( m_sfxTriggerGameObject->m_targetPlayer1 )
{
v12 = ((float (__fastcall *)(PlayerObject *))a1->m_player1->getPosition)(a1->m_player1);
cocos2d::CCPoint::operator=((PlayerObject *)&v42, v12, v13, v14);
if ( m_sfxTriggerGameObject->m_targetPlayer2 )
m_isDualMode = a1->m_gameState.m_isDualMode;
else
m_isDualMode = m_sfxTriggerGameObject->m_targetPlayer2;
goto LABEL_15;
}
if ( m_sfxTriggerGameObject->m_targetPlayer2 )
{
if ( a1->m_gameState.m_isDualMode )
m_player2 = a1->m_player2;
else
m_player2 = a1->m_player1;
v10 = (cocos2d::CCPoint *)m_player2->getPosition(m_player2);
}
else
{
MainObject = GJBaseGameLayer::tryGetMainObject(a1, a2->m_groupID2);
if ( !MainObject )
{
m_isDualMode = 0;
v17 = 0;
goto LABEL_17;
}
MainObject->getRealPosition(&v44, MainObject);
v10 = &v44;
}
}
cocos2d::CCPoint::operator=((PlayerObject *)&v42, *(float *)&v10, v8, m_cameraDistance);
m_isDualMode = 0;
LABEL_15:
v17 = 1;
LABEL_17:
if ( Group && cocos2d::CCArray::count(Group) && v17 )
{
v20 = *(float *)&m_sfxTriggerGameObject->m_proximityMode;
m_volumeNear = m_sfxTriggerGameObject->m_volumeNear;
m_minDistFar = m_sfxTriggerGameObject->m_minDistFar;
m_volumeFar = m_sfxTriggerGameObject->m_volumeFar;
v24 = (float)(3 * m_sfxTriggerGameObject->m_minDistNear);
m_minDistMedium = m_sfxTriggerGameObject->m_minDistMedium;
cocos2d::CCPoint::CCPoint(&v44, &v42);
LODWORD(v25.x) = &v44;
LODWORD(v25.y) = Group;
MinDistance = GJBaseGameLayer::getMinDistance(a1, v25, (cocos2d::CCArray *)LODWORD(v24), v20, v36);
v27 = MinDistance;
if ( m_isDualMode && MinDistance > v24 )
{
v28 = a1->m_player2->getPosition(a1->m_player2);
cocos2d::CCPoint::CCPoint(&v43, v28);
LODWORD(v29.x) = &v43;
LODWORD(v29.y) = Group;
if ( v27 > GJBaseGameLayer::getMinDistance(a1, v29, (cocos2d::CCArray *)LODWORD(v24), v20, v37) )
{
v30 = a1->m_player2->getPosition(a1->m_player2);
cocos2d::CCPoint::CCPoint(&v44, v30);
LODWORD(v31.x) = &v44;
LODWORD(v31.y) = Group;
v27 = GJBaseGameLayer::getMinDistance(a1, v31, (cocos2d::CCArray *)LODWORD(v24), v20, v38);
}
}
if ( v27 > v24 )
{
v32 = (float)(3 * m_minDistMedium) + v24;
v33 = (float)(3 * m_minDistFar) + v32;
if ( v27 >= v33 )
{
v35 = 1.0;
return m_volumeNear + (float)((float)(m_volumeFar - m_volumeNear) * v35);
}
if ( v32 > 0.0 )
{
p_m_volumeMedium = &m_sfxTriggerGameObject->m_volumeMedium;
if ( v27 >= v32 )
{
m_volumeNear = *p_m_volumeMedium;
m_volumeFar = m_sfxTriggerGameObject->m_volumeFar;
v24 = (float)(3 * m_minDistMedium) + v24;
}
else
{
m_sfxTriggerGameObject = (SFXTriggerGameObject *)((char *)m_sfxTriggerGameObject + 1688);
}
if ( v27 < v32 )
{
m_volumeNear = *(float *)&m_sfxTriggerGameObject->EffectGameObject::EnhancedGameObject::GameObject::CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
m_volumeFar = *p_m_volumeMedium;
v33 = v32;
}
}
if ( v24 != v33 )
{
v35 = (float)(v27 - v24) / (float)(v33 - v24);
return m_volumeNear + (float)((float)(m_volumeFar - m_volumeNear) * v35);
}
}
v35 = 0.0;
return m_volumeNear + (float)((float)(m_volumeFar - m_volumeNear) * v35);
}
return 1.0;
}