//
// GJEffectManager::registerRotationCommand from 0x8b4b80 to 0x8b4f00 (896 bytes)
//
// 4 xrefs:
// > GJBaseGameLayer::processDynamicObjectActions @ 0x879cc8
// > GJEffectManager::prepareMoveActions @ 0x8b54cc
// > GJEffectManager::prepareMoveActions @ 0x8b5ac4
// > ??> @ 0x7aa48
//
// 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 GJEffectManager::registerRotationCommand(GJEffectManager *a1, GroupCommandObject2 *a2, bool a3)
{
int m_targetGroupID; // w19
int m_centerGroupID; // w23
std::_rb_tree_base *m_parent; // x0
std::map,std::vector> *p_m_unkMap770; // x22
std::_rb_tree_base *p_m_header; // x25
std::_rb_tree_base *v9; // x20
int v10; // w1
int v11; // w0
__int64 v12; // x20
__int64 p_m_parent; // x24
__int64 insert_hint_unique_pos; // x0
__int64 v15; // x1
__int64 v16; // x19
__int64 v17; // x2
int v18; // w3
_BOOL8 v19; // x0
int v20; // w1
GroupCommandObject2 **v21; // x0
std::vector *p_m_unkVector5b0; // x21
GroupCommandObject2 **m_finish; // x1
std::_rb_tree_base *v24; // x3
std::_rb_tree_base *v25; // x1
int v26; // w2
int v27; // w1
std::_rb_tree_base *v28; // x20
int v29; // w1
int v30; // w0
__int64 v31; // x0
__int64 v32; // x1
std::_rb_tree_base *v33; // x24
__int64 v34; // x2
int v35; // w3
_BOOL8 v36; // x0
int v37; // w1
void *v38; // x0
std::_rb_tree_base *v39; // x0
std::_rb_tree_base *v40; // x0
__int64 v41; // [xsp+50h] [xbp+50h]
__int64 v42; // [xsp+50h] [xbp+50h]
GroupCommandObject2 *v43; // [xsp+58h] [xbp+58h] BYREF
v43 = a2;
m_targetGroupID = a2->m_targetGroupID;
m_centerGroupID = a2->m_centerGroupID;
m_parent = a1->m_unkMap770.m_header.m_parent;
if ( !a3 )
{
p_m_unkMap770 = &a1->m_unkMap770;
p_m_header = &a1->m_unkMap770.m_header;
if ( m_parent )
goto LABEL_3;
LABEL_59:
v9 = p_m_header;
LABEL_10:
v41 = (__int64)v9;
v12 = operator new(0x40u);
p_m_parent = v12 + 40;
*(_DWORD *)(v12 + 32) = m_targetGroupID;
*(_DWORD *)(v12 + 36) = m_centerGroupID;
*(_QWORD *)(v12 + 40) = 0;
*(_QWORD *)(v12 + 48) = 0;
*(_QWORD *)(v12 + 56) = 0;
insert_hint_unique_pos = 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(
p_m_unkMap770,
v41,
(_DWORD *)(v12 + 32));
v16 = insert_hint_unique_pos;
v17 = v15;
if ( v15 )
{
if ( p_m_header == (std::_rb_tree_base *)v15 || insert_hint_unique_pos )
{
v19 = 1;
}
else
{
v18 = *(_DWORD *)(v12 + 32);
v19 = 1;
v20 = *(_DWORD *)(v15 + 32);
if ( v18 >= v20 )
{
v19 = 0;
if ( v18 <= v20 )
v19 = *(_DWORD *)(v12 + 36) < *(_DWORD *)(v17 + 36);
}
}
sub_CFAD74(v19, v12, v17, p_m_header);
++p_m_unkMap770->m_nodecount;
}
else
{
v38 = *(void **)(v12 + 40);
if ( v38 )
operator delete(v38);
p_m_parent = v16 + 40;
operator delete((void *)v12);
}
goto LABEL_17;
}
p_m_header = &a1->m_unkMap770.m_header;
p_m_unkMap770 = &a1->m_unkMap770;
v24 = &a1->m_unkMap770.m_header;
v25 = m_parent;
if ( !m_parent )
goto LABEL_59;
do
{
while ( 1 )
{
v26 = *(_DWORD *)&v25[1].m_isblack;
if ( m_targetGroupID > v26 || m_targetGroupID >= v26 && m_centerGroupID > *((_DWORD *)&v25[1].m_isblack + 1) )
break;
v24 = v25;
v25 = v25->m_left;
if ( !v25 )
goto LABEL_35;
}
v25 = v25->m_right;
}
while ( v25 );
LABEL_35:
if ( p_m_header != v24 )
{
v27 = *(_DWORD *)&v24[1].m_isblack;
if ( m_targetGroupID >= v27 && (m_targetGroupID > v27 || m_centerGroupID >= *((_DWORD *)&v24[1].m_isblack + 1)) )
{
v28 = &a1->m_unkMap770.m_header;
do
{
while ( 1 )
{
v29 = *(_DWORD *)&m_parent[1].m_isblack;
if ( m_targetGroupID > v29
|| m_targetGroupID >= v29 && m_centerGroupID > *((_DWORD *)&m_parent[1].m_isblack + 1) )
{
break;
}
v28 = m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_44;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_44:
if ( p_m_header == v28
|| (v30 = *(_DWORD *)&v28[1].m_isblack, m_targetGroupID < v30)
|| m_targetGroupID <= v30 && m_centerGroupID < *((_DWORD *)&v28[1].m_isblack + 1) )
{
v42 = (__int64)v28;
v28 = (std::_rb_tree_base *)operator new(0x40u);
*(_DWORD *)&v28[1].m_isblack = m_targetGroupID;
*((_DWORD *)&v28[1].m_isblack + 1) = m_centerGroupID;
v28[1].m_parent = nullptr;
v28[1].m_left = nullptr;
v28[1].m_right = nullptr;
v31 = 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_unkMap770.compare.pad,
v42,
&v28[1].m_isblack);
v33 = (std::_rb_tree_base *)v31;
v34 = v32;
if ( v32 )
{
if ( v31 || p_m_header == (std::_rb_tree_base *)v32 )
{
v36 = 1;
}
else
{
v35 = *(_DWORD *)&v28[1].m_isblack;
v36 = 1;
v37 = *(_DWORD *)(v32 + 32);
if ( v35 >= v37 )
{
v36 = 0;
if ( v35 <= v37 )
v36 = *((_DWORD *)&v28[1].m_isblack + 1) < *(_DWORD *)(v34 + 36);
}
}
sub_CFAD74(v36, v28, v34, &a1->m_unkMap770.m_header);
++a1->m_unkMap770.m_nodecount;
}
else
{
v39 = v28[1].m_parent;
if ( v39 )
operator delete(v39);
v40 = v28;
v28 = v33;
operator delete(v40);
}
}
v28[1].m_left = v28[1].m_parent;
m_parent = a1->m_unkMap770.m_header.m_parent;
if ( !m_parent )
goto LABEL_59;
}
}
LABEL_3:
v9 = p_m_header;
do
{
while ( 1 )
{
v10 = *(_DWORD *)&m_parent[1].m_isblack;
if ( m_targetGroupID > v10 || m_targetGroupID >= v10 && m_centerGroupID > *((_DWORD *)&m_parent[1].m_isblack + 1) )
break;
v9 = m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_8;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_8:
if ( p_m_header == v9 )
goto LABEL_10;
v11 = *(_DWORD *)&v9[1].m_isblack;
if ( m_targetGroupID < v11 )
goto LABEL_10;
p_m_parent = (__int64)&v9[1].m_parent;
if ( m_targetGroupID <= v11 && m_centerGroupID < *((_DWORD *)&v9[1].m_isblack + 1) )
goto LABEL_10;
LABEL_17:
v21 = *(GroupCommandObject2 ***)(p_m_parent + 8);
if ( v21 == *(GroupCommandObject2 ***)(p_m_parent + 16) )
{
std::vector::_M_emplace_back_aux(p_m_parent, &v43);
}
else
{
if ( v21 )
{
*v21 = v43;
v21 = *(GroupCommandObject2 ***)(p_m_parent + 8);
}
*(_QWORD *)(p_m_parent + 8) = v21 + 1;
}
p_m_unkVector5b0 = &a1->m_unkVector5b0;
m_finish = p_m_unkVector5b0->m_finish;
if ( m_finish == p_m_unkVector5b0->m_reserveEnd )
{
std::vector::_M_emplace_back_aux(
(__int64)p_m_unkVector5b0,
&v43);
}
else
{
if ( m_finish )
{
*m_finish = v43;
m_finish = p_m_unkVector5b0->m_finish;
}
p_m_unkVector5b0->m_finish = m_finish + 1;
}
}