//
// GJBaseGameLayer::gameEventTriggered from 0x889614 to 0x889b64 (1360 bytes)
//
// 27 xrefs:
// > PlayLayer::processCheckpoints @ 0x5e4390
// > PlayLayer::resetLevel @ 0x5e561c
// > PlayerObject::gameEventTriggered @ 0x623f88
// > LevelEditorLayer::checkpointActivated @ 0x65b588
// > GJBaseGameLayer::gameEventTriggered @ 0x8898b4
// > GJBaseGameLayer::teleportPlayer @ 0x889ec4
// > GJBaseGameLayer::playerWillSwitchMode @ 0x88a1f0
// > GJBaseGameLayer::destroyObject @ 0x88b2f0
// > GJBaseGameLayer::bumpPlayer @ 0x88b4b8
// > GJBaseGameLayer::bumpPlayer @ 0x88b4cc
// > GJBaseGameLayer::gravBumpPlayer @ 0x88b614
// > GJBaseGameLayer::playerTouchedRing @ 0x88b72c
// > GJBaseGameLayer::collisionCheckObjects @ 0x88bcd4
// > GJBaseGameLayer::collisionCheckObjects @ 0x88be4c
// > GJBaseGameLayer::collisionCheckObjects @ 0x88be7c
// > GJBaseGameLayer::collisionCheckObjects @ 0x88bef8
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c07c
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c128
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c1ac
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c294
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c328
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c408
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c4a8
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c644
// > GJBaseGameLayer::collisionCheckObjects @ 0x88c720
// > GJBaseGameLayer::handleButton @ 0x88c8ec
// > ??> @ 0x93000
//
// 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 GJBaseGameLayer::gameEventTriggered(GJBaseGameLayer *a1, GJGameEvent a2, int a3, int a4)
{
std::_rb_tree_base *p_m_header; // x27
int EventKey; // w20
std::_rb_tree_base *m_parent; // x2
std::_rb_tree_base *v11; // x1
std::_rb_tree_base *v12; // x0
GJGameEvent v13; // w3
GJGameEvent v14; // w0
_DWORD *v15; // x26
__int64 insert_hint_unique_pos; // x0
__int64 v17; // x1
_DWORD *v18; // x3
__int64 v19; // x2
int v20; // w3
_BOOL8 v21; // x0
int v22; // w1
unsigned int m_commandIndex; // w4
std::_rb_tree_base *v24; // x26
GJGameEvent v25; // w0
GJGameEvent v26; // w0
std::_rb_tree_base *v27; // x0
std::_rb_tree_base *v28; // x19
std::_rb_tree_base *v29; // x26
GJGameEvent v30; // w1
GJGameEvent v31; // w0
std::_rb_tree_base *v32; // x19
unsigned int *i; // x27
std::_rb_tree_base *m_right; // x26
std::_rb_tree_base *v35; // x1
unsigned __int64 v36; // x28
unsigned __int64 v37; // x0
char *v38; // x3
std::_rb_tree_base *v39; // x1
signed __int64 v40; // x26
__int64 v41; // x1
__int64 v42; // x4
void (__fastcall *spawnGroup)(GJBaseGameLayer *__hidden, int, bool, double, const std::vector *, int, int); // x6
__int64 m_parent_low; // x5
__int64 v45; // x0
__int64 v46; // x0
__int64 v47; // x1
std::_rb_tree_base *v48; // x3
__int64 v49; // x2
int v50; // w3
_BOOL8 v51; // x0
int v52; // w1
__int64 v53; // x0
__int64 v54; // x1
std::_rb_tree_base *v55; // x20
__int64 v56; // x2
int v57; // w3
_BOOL8 v58; // x0
int v59; // w1
void *v60; // x0
std::_rb_tree_base *v61; // x0
std::_rb_tree_base *v62; // x19
std::_rb_tree_base *m_left; // x27
std::_rb_tree_base *v64; // x0
std::_rb_tree_base *v65; // x0
__int64 v66; // [xsp+68h] [xbp+68h]
__int64 v67; // [xsp+68h] [xbp+68h]
__int64 v68; // [xsp+68h] [xbp+68h]
void *p; // [xsp+70h] [xbp+70h] BYREF
char *v70; // [xsp+78h] [xbp+78h]
char *v71; // [xsp+80h] [xbp+80h]
p_m_header = &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header;
EventKey = getEventKey(a3, a4);
m_parent = a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header.m_parent;
v11 = &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header;
v12 = m_parent;
if ( m_parent )
{
do
{
while ( 1 )
{
v13 = *(_DWORD *)&v12[1].m_isblack;
if ( v13 < a2 || v13 <= a2 && EventKey > *((_DWORD *)&v12[1].m_isblack + 1) )
break;
v11 = v12;
v12 = v12->m_left;
if ( !v12 )
goto LABEL_6;
}
v12 = v12->m_right;
}
while ( v12 );
LABEL_6:
if ( p_m_header != v11 )
{
v14 = *(_DWORD *)&v11[1].m_isblack;
if ( v14 <= a2 && (v14 < a2 || EventKey >= *((_DWORD *)&v11[1].m_isblack + 1)) )
{
m_commandIndex = a1->m_gameState.m_commandIndex;
if ( LODWORD(v11[1].m_parent) == m_commandIndex )
goto LABEL_41;
goto LABEL_15;
}
}
}
v66 = (__int64)v11;
v15 = (_DWORD *)operator new(0x30u);
v15[8] = a2;
v15[9] = EventKey;
v15[10] = 0;
insert_hint_unique_pos = std::_Rb_tree,std::pair const,int>,std::_Select1st const,int>>,std::less>,std::allocator const,int>>>::_M_get_insert_hint_unique_pos(
&a1->m_gameState.m_unkMapPairGJGameEventIntInt.compare.pad,
v66,
v15 + 8);
v18 = (_DWORD *)insert_hint_unique_pos;
v19 = v17;
if ( v17 )
{
if ( insert_hint_unique_pos || p_m_header == (std::_rb_tree_base *)v17 )
{
v21 = 1;
}
else
{
v20 = v15[8];
v21 = 1;
v22 = *(_DWORD *)(v17 + 32);
if ( v20 >= v22 )
{
v21 = 0;
if ( v20 <= v22 )
v21 = v15[9] < *(_DWORD *)(v19 + 36);
}
}
sub_CFAD74(v21, v15, v19, &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header);
++a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_nodecount;
}
else
{
v60 = v15;
v15 = v18;
operator delete(v60);
}
m_commandIndex = a1->m_gameState.m_commandIndex;
if ( v15[10] == m_commandIndex )
goto LABEL_41;
m_parent = a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header.m_parent;
if ( m_parent )
{
LABEL_15:
v24 = &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header;
do
{
while ( 1 )
{
v25 = *(_DWORD *)&m_parent[1].m_isblack;
if ( v25 < a2 || v25 <= a2 && EventKey > *((_DWORD *)&m_parent[1].m_isblack + 1) )
break;
v24 = m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_20;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_20:
if ( p_m_header != v24 )
{
v26 = *(_DWORD *)&v24[1].m_isblack;
if ( v26 <= a2 && (v26 < a2 || EventKey >= *((_DWORD *)&v24[1].m_isblack + 1)) )
goto LABEL_23;
}
goto LABEL_57;
}
v24 = &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header;
LABEL_57:
v67 = (__int64)v24;
v24 = (std::_rb_tree_base *)operator new(0x30u);
*(_DWORD *)&v24[1].m_isblack = a2;
*((_DWORD *)&v24[1].m_isblack + 1) = EventKey;
LODWORD(v24[1].m_parent) = 0;
v46 = std::_Rb_tree,std::pair const,int>,std::_Select1st const,int>>,std::less>,std::allocator const,int>>>::_M_get_insert_hint_unique_pos(
&a1->m_gameState.m_unkMapPairGJGameEventIntInt.compare.pad,
v67,
&v24[1].m_isblack);
v48 = (std::_rb_tree_base *)v46;
v49 = v47;
if ( v47 )
{
if ( v46 || p_m_header == (std::_rb_tree_base *)v47 )
{
v51 = 1;
}
else
{
v50 = *(_DWORD *)&v24[1].m_isblack;
v51 = 1;
v52 = *(_DWORD *)(v47 + 32);
if ( v50 >= v52 )
{
v51 = 0;
if ( v50 <= v52 )
v51 = *((_DWORD *)&v24[1].m_isblack + 1) < *(_DWORD *)(v49 + 36);
}
}
sub_CFAD74(v51, v24, v49, &a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_header);
m_commandIndex = a1->m_gameState.m_commandIndex;
++a1->m_gameState.m_unkMapPairGJGameEventIntInt.m_nodecount;
}
else
{
v61 = v24;
v24 = v48;
operator delete(v61);
m_commandIndex = a1->m_gameState.m_commandIndex;
}
LABEL_23:
v27 = a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.m_header.m_parent;
v28 = &a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.m_header;
LODWORD(v24[1].m_parent) = m_commandIndex;
v29 = &a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.m_header;
if ( !v27 )
goto LABEL_65;
do
{
while ( 1 )
{
v30 = *(_DWORD *)&v27[1].m_isblack;
if ( a2 > v30 || a2 >= v30 && EventKey > *((_DWORD *)&v27[1].m_isblack + 1) )
break;
v29 = v27;
v27 = v27->m_left;
if ( !v27 )
goto LABEL_28;
}
v27 = v27->m_right;
}
while ( v27 );
LABEL_28:
if ( v28 == v29
|| (v31 = *(_DWORD *)&v29[1].m_isblack, a2 < v31)
|| a2 <= v31 && EventKey < *((_DWORD *)&v29[1].m_isblack + 1) )
{
LABEL_65:
v68 = (__int64)v29;
v29 = (std::_rb_tree_base *)operator new(0x40u);
*((_DWORD *)&v29[1].m_isblack + 1) = EventKey;
*(_DWORD *)&v29[1].m_isblack = a2;
v29[1].m_parent = nullptr;
v29[1].m_left = nullptr;
v29[1].m_right = nullptr;
v53 = std::_Rb_tree,std::pair const,std::vector>,std::_Select1st const,std::vector>>,std::less>,std::allocator const,std::vector>>>::_M_get_insert_hint_unique_pos(
&a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.compare.pad,
v68,
&v29[1].m_isblack);
v55 = (std::_rb_tree_base *)v53;
v56 = v54;
if ( v54 )
{
if ( v53 || v28 == (std::_rb_tree_base *)v54 )
{
v58 = 1;
}
else
{
v57 = *(_DWORD *)&v29[1].m_isblack;
v58 = 1;
v59 = *(_DWORD *)(v54 + 32);
if ( v57 >= v59 )
{
v58 = 0;
if ( v57 <= v59 )
v58 = *((_DWORD *)&v29[1].m_isblack + 1) < *(_DWORD *)(v56 + 36);
}
}
sub_CFAD74(v58, v29, v56, &a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.m_header);
++a1->m_gameState.m_unkMapPairGJGameEventIntVectorEventTriggerInstance.m_nodecount;
}
else
{
v62 = v29[1].m_parent;
m_left = v29[1].m_left;
if ( v62 != m_left )
{
do
{
v64 = v62->m_left;
if ( v64 )
operator delete(v64);
v62 = (std::_rb_tree_base *)((char *)v62 + 40);
}
while ( m_left != v62 );
m_left = v29[1].m_parent;
}
if ( m_left )
operator delete(m_left);
v65 = v29;
v29 = v55;
operator delete(v65);
}
}
v32 = v29[1].m_parent;
for ( i = (unsigned int *)v29[1].m_left; i != (unsigned int *)v32; v32 = (std::_rb_tree_base *)((char *)v32 + 40) )
{
while ( 1 )
{
if ( !BYTE4(v32->m_parent) )
{
m_right = v32->m_right;
v35 = v32->m_left;
p = nullptr;
v36 = (char *)m_right - (char *)v35;
v70 = nullptr;
v37 = ((char *)m_right - (char *)v35) >> 2;
v71 = nullptr;
if ( v37 )
{
if ( v37 > 0x3FFFFFFFFFFFFFFFLL )
sub_D1383C();
v45 = operator new(v36);
m_right = v32->m_right;
v38 = (char *)v45;
}
else
{
v38 = nullptr;
}
p = v38;
v70 = v38;
v71 = &v38[v36];
v39 = v32->m_left;
v40 = (char *)m_right - (char *)v39;
if ( v40 >> 2 )
v38 = (char *)memmove(v38, v39, v40);
v41 = *(unsigned int *)&v32->m_isblack;
v42 = *((unsigned int *)&v32->m_isblack + 1);
spawnGroup = a1->spawnGroup;
m_parent_low = LODWORD(v32->m_parent);
v70 = &v38[v40];
((void (__fastcall *)(GJBaseGameLayer *, __int64, _QWORD, void **, __int64, __int64, double))spawnGroup)(
a1,
v41,
0,
&p,
v42,
m_parent_low,
0.0);
if ( p )
break;
}
v32 = (std::_rb_tree_base *)((char *)v32 + 40);
if ( i == (unsigned int *)v32 )
goto LABEL_41;
}
operator delete(p);
}
LABEL_41:
if ( a4 )
GJBaseGameLayer::gameEventTriggered(a1, a2, a3, 0);
}