//
// GJBaseGameLayer::activateSFXEditTrigger from 0x10015aac0 to 0x10015af01 (1089 bytes)
//
// 4 xrefs:
// > LevelEditorLayer::activateTriggerEffect @ 0x1000ef8d0
// > GJBaseGameLayer::processQueuedAudioTriggers @ 0x10015a28f
// > GJBaseGameLayer::processActivatedAudioTriggers @ 0x100161939
// > EffectGameObject::triggerObject @ 0x1001b9dfb
//
// 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::activateSFXEditTrigger(GJBaseGameLayer *a1, SFXTriggerGameObject *a2)
{
SFXTriggerGameObject *v2; // rbx
GJBaseGameLayer *v3; // r13
std::__vector_base::pointer end; // r15
SFXTriggerGameObject **value; // rax
int m_groupID; // eax
intptr_t v7; // r12
cocos2d::CCArray *v8; // r15
cocos2d::ccArray *data; // rax
__int64 num; // rcx
cocos2d::CCObject **arr; // rdx
cocos2d::CCObject *v12; // rax
__int64 v13; // rax
int *v14; // r15
int *v15; // r14
__int64 v16; // rax
int v17; // ebx
__int128 *v18; // r13
__int128 *v19; // r12
int v20; // eax
_DWORD *v21; // rax
std::__vector_base::pointer begin; // r12
signed __int64 v23; // r15
__int64 v24; // rbx
__int64 v25; // rax
unsigned __int64 v26; // r14
_QWORD *v27; // r13
__int128 *v28; // r14
int m_sfxGroup; // esi
FMODAudioEngine *v30; // rax
int v31; // eax
__int128 *v32; // rcx
__int128 *v33; // rax
bool v34; // zf
SFXTriggerGameObject **v35; // r14
__int64 v36; // rbx
GJBaseGameLayer *v37; // rax
GJBaseGameLayer *v38; // r13
int *p_m_uReference; // [rsp+0h] [rbp-80h] BYREF
cocos2d::CCObject **v40; // [rsp+8h] [rbp-78h]
unsigned __int64 v41; // [rsp+10h] [rbp-70h]
std::unordered_map> *p_m_unkUMap8; // [rsp+18h] [rbp-68h]
unsigned int m_uReference; // [rsp+24h] [rbp-5Ch] BYREF
SFXTriggerGameObject *v44; // [rsp+28h] [rbp-58h]
GJBaseGameLayer *v45; // [rsp+30h] [rbp-50h]
__int128 *v46; // [rsp+38h] [rbp-48h] BYREF
__int128 v47; // [rsp+40h] [rbp-40h] BYREF
char v48[41]; // [rsp+57h] [rbp-29h] BYREF
v2 = a2;
v3 = a1;
if ( a1->m_practiceMusicSync || !a1->m_isPracticeMode )
{
if ( a1->m_loadingStartPosition )
{
((void (__fastcall *)(GJBaseGameLayer *, SFXTriggerGameObject *))a1->activatedAudioTrigger)(a1, a2);
}
else if ( a1->m_startingFromBeginning )
{
end = a1->m_activeSfxTriggers.__end_;
value = a1->m_activeSfxTriggers.__end_cap_.__value_;
if ( end >= value )
{
v44 = a2;
begin = a1->m_activeSfxTriggers.__begin_;
v23 = (char *)end - (char *)begin;
v24 = v23 >> 3;
if ( (unsigned __int64)((v23 >> 3) + 1) >> 61 )
sub_1001733F0();
v25 = (char *)value - (char *)begin;
v26 = v25 >> 2;
if ( v25 >> 2 <= (unsigned __int64)((v23 >> 3) + 1) )
v26 = (v23 >> 3) + 1;
if ( (unsigned __int64)v25 >= 0x7FFFFFFFFFFFFFF8LL )
v26 = 0x1FFFFFFFFFFFFFFFLL;
v45 = a1;
if ( v26 )
{
if ( v26 > 0x1FFFFFFFFFFFFFFFLL )
sub_100054850();
v27 = operator new(8 * v26);
}
else
{
v27 = nullptr;
}
v35 = (SFXTriggerGameObject **)&v27[v26];
v27[v24] = v44;
v36 = (__int64)&v27[v24 + 1];
memcpy(v27, begin, v23);
v37 = v45;
v45->m_activeSfxTriggers.__begin_ = (std::__vector_base::pointer)v27;
v38 = v37;
v37->m_activeSfxTriggers.__end_ = (std::__vector_base::pointer)v36;
v37->m_activeSfxTriggers.__end_cap_.__value_ = v35;
if ( begin )
operator delete(begin);
v38->m_activeSfxTriggers.__end_ = (std::__vector_base::pointer)v36;
}
else
{
*end = a2;
a1->m_activeSfxTriggers.__end_ = end + 1;
}
}
else
{
m_groupID = a2->m_groupID;
if ( m_groupID > 0 )
{
v7 = 9999;
if ( (unsigned int)m_groupID < 0x270F )
v7 = (unsigned int)m_groupID;
v8 = a1->m_groups.__begin_[v7];
if ( v8
|| (v8 = (cocos2d::CCArray *)sub_10071F9E0(a1, a2),
cocos2d::CCDictionary::setObject(a1->m_groupDict, v8, v7),
(a1->m_groups.__begin_[v7] = v8) != nullptr) )
{
if ( (unsigned int)sub_100720070(v8) )
{
v47 = 0;
v46 = &v47;
data = v8->data;
num = data->num;
if ( data->num )
{
v44 = a2;
arr = data->arr;
v41 = (unsigned __int64)&arr[num - 1];
v45 = a1;
p_m_unkUMap8 = &a1->m_gameState.m_unkUMap8;
do
{
v12 = *arr;
if ( !*arr )
break;
v40 = arr;
if ( v12[18].m_uReference == 3602 )
{
m_uReference = v12[16].m_uReference;
p_m_uReference = (int *)&m_uReference;
v13 = sub_100173400(p_m_unkUMap8, &m_uReference, &unk_100816AE0, &p_m_uReference, v48);
v14 = *(int **)(v13 + 24);
v15 = *(int **)(v13 + 32);
while ( v14 != v15 )
{
v16 = v47;
v17 = *v14;
v18 = &v47;
LABEL_25:
v19 = v18;
if ( v16 )
{
do
{
v18 = (__int128 *)v16;
v20 = *(_DWORD *)(v16 + 28);
if ( v17 < v20 )
{
v16 = *(_QWORD *)v18;
goto LABEL_25;
}
if ( v17 <= v20 )
goto LABEL_21;
v16 = *((_QWORD *)v18 + 1);
}
while ( v16 );
v19 = (__int128 *)((char *)v18 + 8);
}
v21 = operator new(0x20u);
v21[7] = v17;
*(_OWORD *)v21 = 0;
*((_QWORD *)v21 + 2) = v18;
*(_QWORD *)v19 = v21;
if ( *(_QWORD *)v46 )
v46 = *(__int128 **)v46;
sub_100054DD0((__int64 *)v47, (__int64 *)v21);
++*((_QWORD *)&v47 + 1);
LABEL_21:
++v14;
}
}
arr = v40 + 1;
}
while ( (unsigned __int64)(v40 + 1) <= v41 );
v28 = v46;
v3 = v45;
v2 = v44;
if ( v46 != &v47 )
{
do
{
if ( !v2->m_applyDisabled )
GJBaseGameLayer::applySFXEditTrigger(v3, *((_DWORD *)v28 + 7), 0, v2);
if ( v2->m_targetGroupID > 0 )
GJBaseGameLayer::addProximityVolumeEffect(v3, *((_DWORD *)v28 + 7), 0, v2);
v32 = *((__int128 **)v28 + 1);
if ( v32 )
{
do
{
v33 = v32;
v32 = *(__int128 **)v32;
}
while ( v32 );
}
else
{
do
{
v33 = *((__int128 **)v28 + 2);
v34 = *(_QWORD *)v33 == (_QWORD)v28;
v28 = v33;
}
while ( !v34 );
}
v28 = v33;
}
while ( v33 != &v47 );
}
}
sub_100054D90((__int64)&v46, (_QWORD *)v47);
}
}
}
m_sfxGroup = v2->m_sfxGroup;
if ( m_sfxGroup > 0 )
{
if ( !v2->m_applyDisabled )
GJBaseGameLayer::applySFXEditTrigger(v3, m_sfxGroup, 1, v2);
if ( v2->m_targetGroupID > 0 )
GJBaseGameLayer::addProximityVolumeEffect(v3, v2->m_sfxGroup, 1, v2);
}
if ( v2->m_sfxUniqueID > 0 )
{
v30 = FMODAudioEngine::sharedEngine();
v31 = FMODAudioEngine::channelIDForUniqueID(v30, v2->m_sfxUniqueID);
if ( !v2->m_applyDisabled )
GJBaseGameLayer::applySFXEditTrigger(v3, v31, 0, v2);
}
}
}
}