static bool PrefixGetFormationFrame(ref bool __result, Agent ___Agent, ref FormationCohesionComponent ____cohesionComponent, ref WorldPosition formationPosition, ref Vec2 formationDirection, ref float speedLimit, ref bool isSettingDestinationSpeed, ref bool limitIsMultiplier)
        {
            var formation = ___Agent.Formation;

            if (!___Agent.IsMount && formation != null && formation.QuerySystem.IsInfantryFormation && !(bool)IsUnitDetached.Invoke(formation, new object[] { ___Agent }))
            {
                if (formation.MovementOrder.OrderType == OrderType.ChargeWithTarget)
                {
                    isSettingDestinationSpeed = false;
                    formationPosition         = formation.GetOrderPositionOfUnit(___Agent);
                    formationDirection        = formation.GetDirectionOfUnit(___Agent);
                    limitIsMultiplier         = true;
                    speedLimit = ____cohesionComponent != null && FormationCohesionComponent.FormationSpeedAdjustmentEnabled ? ____cohesionComponent.GetDesiredSpeedInFormation() : -1f;
                    __result   = true;
                    return(false);
                }
            }

            return(true);
        }
        public static bool GetFormationFrame_Prefix(ref bool __result, Agent ___Agent,
                                                    ref FormationCohesionComponent ____cohesionComponent,
                                                    ref WorldPosition formationPosition,
                                                    ref Vec2 formationDirection,
                                                    ref float speedLimit,
                                                    ref bool isSettingDestinationSpeed,
                                                    ref bool limitIsMultiplier)
        {
            var formation = ___Agent.Formation;

            if (!___Agent.IsMount && formation != null &&
                !(bool)IsUnitDetached.Invoke(formation, new object[] { ___Agent }))
            {
                if (Utility.ShouldChargeToFormation(___Agent))
                {
                    isSettingDestinationSpeed = false;
                    var component = ___Agent.GetComponent <CommandSystemAgentComponent>();
                    if (component == null)
                    {
                        return(true);
                    }
                    formationPosition  = component.CurrentTargetPosition.Value;
                    formationDirection = formation.GetDirectionOfUnit(___Agent);

                    limitIsMultiplier = true;
                    speedLimit        =
                        !___Agent.HasMount && ____cohesionComponent != null &&
                        FormationCohesionComponent.FormationSpeedAdjustmentEnabled
                            ? ____cohesionComponent.GetDesiredSpeedInFormation(true)
                            : -1f;
                    __result = true;
                    return(false);
                }
            }

            return(true);
        }