//
// GJBaseGameLayer::triggerAdvancedFollowCommand from 0x47021c to 0x4703a2 (390 bytes)
//
// 1 xrefs:
// > EffectGameObject::triggerObject @ 0x3edd8c
//
// 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::triggerAdvancedFollowCommand(GJBaseGameLayer *a1, AdvancedFollowTriggerObject *a2)
{
int m_centerGroupID; // r7
AdvancedFollowInstance *m_start; // lr
int v6; // r1
AdvancedFollowInstance *m_finish; // r2
AdvancedFollowInstance *i; // r3
AdvancedFollowInstance *m_reserveEnd; // r0
int v10; // r4
int m_controlID; // r11
int m_targetGroupID; // r3
int v13; // r4
int v14; // r3
int v15; // r2
bool v16; // cf
unsigned int v17; // r3
AdvancedFollowInstance *v18; // r8
AdvancedFollowInstance *v19; // r10
AdvancedFollowInstance *v20; // r9
int v21; // r2
unsigned int v22; // lr
int v23; // r1
char *v24; // r3
int j; // r12
AdvancedFollowInstance *v26; // r6
AdvancedFollowInstance *v28; // r7
AdvancedFollowTriggerObject *m_gameObject; // r0
int m_group; // r1
int m_objectKey; // r2
int v32; // r3
int *p_m_otherObjectKey; // r6
int *v34; // r7
int v35; // r1
int v36; // r2
AdvancedFollowInstance *v37; // r6
int m_unkUint8; // r1
m_centerGroupID = a2->m_centerGroupID;
if ( a2->m_targetPlayer1 )
{
m_centerGroupID = -1;
}
else if ( a2->m_targetPlayer2 )
{
m_centerGroupID = -2;
}
else if ( a2->m_followCPP )
{
m_centerGroupID = -3;
}
m_start = a1->m_gameState.m_advanceFollowInstances.m_start;
v6 = 0;
m_finish = a1->m_gameState.m_advanceFollowInstances.m_finish;
for ( i = m_start; i != m_finish; ++i )
{
if ( i->m_gameObject == a2
&& i->m_group == a2->m_targetGroupID
&& i->m_objectKey == m_centerGroupID
&& i->m_controlId == a2->m_controlID )
{
m_unkUint8 = a1->m_gameState.m_unkUint8;
i->m_finished = 0;
++m_unkUint8;
i->m_doStart = 0;
a1->m_gameState.m_unkUint8 = m_unkUint8;
i->m_relatedToGJGameStateUnkUint7 = m_unkUint8;
v6 = 1;
}
}
if ( !v6 )
{
m_reserveEnd = a1->m_gameState.m_advanceFollowInstances.m_reserveEnd;
v10 = a1->m_gameState.m_unkUint8 + 1;
a1->m_gameState.m_unkUint8 = v10;
m_controlID = a2->m_controlID;
if ( m_finish != m_reserveEnd )
{
m_targetGroupID = a2->m_targetGroupID;
if ( m_finish )
{
m_finish->m_gameObject = a2;
m_finish->m_group = m_targetGroupID;
m_finish->m_objectKey = m_centerGroupID;
m_finish->m_controlId = m_controlID;
m_finish->m_otherObjectKey = 0;
m_finish->m_relatedToGJGameStateUnkUint7 = v10;
m_finish->m_finished = 0;
m_finish->m_doStart = 0;
m_finish->m_started = 0;
m_finish->m_processed = 0;
}
a1->m_gameState.m_advanceFollowInstances.m_finish = m_finish + 1;
goto LABEL_39;
}
v13 = 153391689;
v14 = -1227133513 * (((char *)i - (char *)m_start) >> 2);
if ( v14 )
v15 = v14;
else
v15 = 1;
v16 = __CFADD__(v15, v14);
v17 = v15 + v14;
if ( !v16 && v17 <= 0x9249249 )
{
if ( !v17 )
{
v13 = 0;
v18 = nullptr;
goto LABEL_29;
}
v13 = v17;
}
v18 = (AdvancedFollowInstance *)operator new(28 * v13);
LABEL_29:
v19 = a1->m_gameState.m_advanceFollowInstances.m_finish;
v20 = a1->m_gameState.m_advanceFollowInstances.m_start;
v21 = a2->m_targetGroupID;
v22 = (char *)v19 - (char *)v20;
v23 = a1->m_gameState.m_unkUint8;
v24 = (char *)v18 + (char *)v19 - (char *)v20;
if ( v24 )
{
*(AdvancedFollowTriggerObject **)((char *)&v18->m_gameObject + v22) = a2;
*((_DWORD *)v24 + 1) = v21;
*((_DWORD *)v24 + 2) = m_centerGroupID;
*((_DWORD *)v24 + 3) = m_controlID;
*((_DWORD *)v24 + 4) = 0;
*((_DWORD *)v24 + 5) = v23;
v24[24] = 0;
v24[25] = 0;
v24[26] = 0;
v24[27] = 0;
}
for ( j = 0; ; ++j )
{
v26 = &v20[j];
if ( v19 == &v20[j] )
break;
v28 = &v18[j];
if ( &v18[j] != nullptr )
{
m_gameObject = v26->m_gameObject;
m_group = v26->m_group;
m_objectKey = v26->m_objectKey;
v32 = v26->m_controlId;
p_m_otherObjectKey = &v26->m_otherObjectKey;
v28->m_gameObject = m_gameObject;
v28->m_group = m_group;
v28->m_objectKey = m_objectKey;
v28->m_controlId = v32;
v34 = &v28->m_otherObjectKey;
v35 = p_m_otherObjectKey[1];
v36 = p_m_otherObjectKey[2];
*v34 = *p_m_otherObjectKey;
v34[1] = v35;
v34[2] = v36;
}
}
v37 = &v18[((920350135 * (v22 >> 2)) & 0x3FFFFFFF) + 1];
if ( v20 )
operator delete(v20);
a1->m_gameState.m_advanceFollowInstances.m_start = v18;
a1->m_gameState.m_advanceFollowInstances.m_finish = v37;
a1->m_gameState.m_advanceFollowInstances.m_reserveEnd = &v18[v13];
}
LABEL_39:
a1->m_gameState.m_unkBool27 = 1;
}