Esempio n. 1
0
        private static void UpdatePlayerInfo()
        {
            Player player      = null;
            long   chapterTime = 0;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    chapterTime = level.Session.Time;
                    if (chapterTime != lastTimer || lastPos != player.ExactPosition)
                    {
                        string  statuses = ((int)(player.dashCooldownTimer * 60f) < 1 && player.Dashes > 0 ? "Dash " : string.Empty) + (player.LoseShards ? "Ground " : string.Empty) + (player.WallJumpCheck(1) ? "Wall-R " : string.Empty) + (player.WallJumpCheck(-1) ? "Wall-L " : string.Empty);
                        Vector2 diff     = (player.ExactPosition - lastPos) * 60;

                        if (player.Holding == null)
                        {
                            foreach (Component component in level.Tracker.GetComponents <Holdable>())
                            {
                                Holdable holdable = (Holdable)component;
                                if (holdable.Check(player))
                                {
                                    statuses += "Grab ";
                                    break;
                                }
                            }
                        }

                        StringBuilder sb = new StringBuilder();
                        sb.Append("Pos: ").Append(player.ExactPosition.X.ToString("0.0", enUS)).Append(',').AppendLine(player.ExactPosition.Y.ToString("0.0", enUS));
                        sb.Append("Speed: ").Append(player.Speed.X.ToString("0.00", enUS)).Append(',').Append(player.Speed.Y.ToString("0.00", enUS)).Append(',').AppendLine(player.Speed.Length().ToString("0.00", enUS));
                        sb.Append("Vel: ").Append(diff.X.ToString("0.00", enUS)).Append(',').Append(diff.Y.ToString("0.00", enUS)).Append(',').AppendLine(diff.Length().ToString("0.00", enUS));
                        sb.Append("Stamina: ").Append(player.Stamina.ToString("0")).Append(" Timer: ").AppendLine(((double)chapterTime / (double)10000000).ToString("0.000", enUS));
                        sb.Append(player.InControl && !level.Transitioning ? statuses : "NoControl ").Append(player.TimePaused ? "Paused " : string.Empty).Append(level.InCutscene ? "Cutscene " : string.Empty);
                        PlayerStatus = sb.ToString();
                        lastPos      = player.ExactPosition;
                        lastTimer    = chapterTime;
                    }
                }
                else
                {
                    PlayerStatus = level.InCutscene ? "Cutscene" : null;
                }
            }
            else if (Engine.Scene is SummitVignette summit)
            {
                PlayerStatus = string.Concat("SummitVignette ", summit.ready);
            }
            else if (Engine.Scene is Overworld overworld)
            {
                PlayerStatus = string.Concat("Overworld ", overworld.ShowInputUI);
            }
            else if (Engine.Scene != null)
            {
                PlayerStatus = Engine.Scene.GetType().Name;
            }
        }
        public static void ExportPlayerInfo()
        {
            Player player = null;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    string inputs = controller.Current.ActionsToString();
                    if (inputs.Length > 1)
                    {
                        inputs = inputs.Substring(1);
                    }
                    string time  = (level.Session.Time / 10000000D).ToString("0.000");
                    double x     = (double)player.X + player.PositionRemainder.X;
                    double y     = (double)player.Y + player.PositionRemainder.Y;
                    string pos   = x.ToString() + "," + y.ToString();
                    string speed = player.Speed.X.ToString() + "," + player.Speed.Y.ToString();

                    int    dashCooldown = (int)((float)player.GetPrivateField("dashCooldownTimer") * 60f);
                    string statuses     = (dashCooldown < 1 && player.Dashes > 0 ? "Dash " : string.Empty)
                                          + (player.LoseShards ? "Ground " : string.Empty)
                                          + ((bool)player.InvokePrivateMethod("WallJumpCheck", 1) ? "Wall-R " : string.Empty)
                                          + ((bool)player.InvokePrivateMethod("WallJumpCheck", -1) ? "Wall-L " : string.Empty)
                                          + (!player.LoseShards && (float)player.GetPrivateField("jumpGraceTimer") > 0 ? "Coyote " : string.Empty);
                    statuses = (player.InControl && !level.Transitioning ? statuses : "NoControl ")
                               + (player.TimePaused ? "Paused " : string.Empty)
                               + (level.InCutscene ? "Cutscene " : string.Empty);

                    if (player.Holding == null)
                    {
                        foreach (Component component in level.Tracker.GetComponents <Holdable>())
                        {
                            Holdable holdable = (Holdable)component;
                            if (holdable.Check(player))
                            {
                                statuses += "Grab ";
                                break;
                            }
                        }
                    }
                    string output = string.Join(" ", inputs, controller.CurrentFrame, time, pos, speed, player.StateMachine.State, statuses);

                    foreach (MethodInfo method in trackedEntities)
                    {
                        if (method == null)
                        {
                            continue;
                        }
                        List <Entity> entities = (List <Entity>)method.Invoke(level.Tracker, null);
                        foreach (Entity entity in entities)
                        {
                            Actor actor = entity as Actor;
                            if (actor != null)
                            {
                                x   = (double)actor.X + actor.PositionRemainder.X;
                                y   = (double)actor.Y + actor.PositionRemainder.Y;
                                pos = x.ToString() + "," + y.ToString();
                            }
                            else
                            {
                                pos = entity.X.ToString() + "," + entity.Y.ToString();
                            }
                            output += $" {method.GetGenericArguments()[0].Name}: {pos}";
                        }
                    }

                    sw.WriteLine(output);
                }
            }
        }
        private static void UpdatePlayerInfo()
        {
            Player player      = null;
            long   chapterTime = 0;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    chapterTime = level.Session.Time;
                    if (chapterTime != lastTimer || lastPos != player.ExactPosition)
                    {
                        string  pos       = GetAdjustedPos(player.Position, player.PositionRemainder);
                        string  speed     = $"Speed: {player.Speed.X.ToString("0.00")},{player.Speed.Y.ToString("0.00")}";
                        Vector2 diff      = (player.ExactPosition - lastPos) * 60;
                        string  vel       = $"Vel: {diff.X.ToString("0.00")},{diff.Y.ToString("0.00")}";
                        string  polarvel  = $"     {diff.Length().ToString("0.00")},{GetAngle(diff).ToString("0.00")}°";
                        string  miscstats = $"Stamina: {player.Stamina.ToString("0")} Timer: {(chapterTime / 10000000D).ToString("0.000")}";

                        int    dashCooldown = (int)((float)player.GetPrivateField("dashCooldownTimer") * 60f);
                        string statuses     = (dashCooldown < 1 && player.Dashes > 0 ? "Dash " : string.Empty)
                                              + (player.LoseShards ? "Ground " : string.Empty)
                                              + ((bool)player.InvokePrivateMethod("WallJumpCheck", 1) ? "Wall-R " : string.Empty)
                                              + ((bool)player.InvokePrivateMethod("WallJumpCheck", -1) ? "Wall-L " : string.Empty)
                                              + (!player.LoseShards && (float)player.GetPrivateField("jumpGraceTimer") > 0 ? "Coyote " : string.Empty);
                        statuses = (player.InControl && !level.Transitioning ? statuses : "NoControl ")
                                   + (player.TimePaused ? "Paused " : string.Empty)
                                   + (level.InCutscene ? "Cutscene " : string.Empty);

                        if (player.Holding == null)
                        {
                            foreach (Component component in level.Tracker.GetComponents <Holdable>())
                            {
                                Holdable holdable = (Holdable)component;
                                if (holdable.Check(player))
                                {
                                    statuses += "Grab ";
                                    break;
                                }
                            }
                        }

                        int      berryTimer            = -10;
                        Follower firstRedBerryFollower = player.Leader.Followers.Find(follower => follower.Entity is Strawberry berry && !berry.Golden);
                        if (firstRedBerryFollower?.Entity is Strawberry firstRedBerry)
                        {
                            object collectTimer;
                            if (firstRedBerry.GetType() == typeof(Strawberry) ||
                                (collectTimer = firstRedBerry.GetPrivateField("collectTimer")) == null)
                            {
                                // if this is a vanilla berry or a mod berry having no collectTimer, use the cached FieldInfo for Strawberry.collectTimer.
                                collectTimer = strawberryCollectTimer.GetValue(firstRedBerry);
                            }

                            berryTimer = (int)Math.Round(60f * (float)collectTimer);
                        }
                        string timers = (berryTimer != -10 ? $"BerryTimer: {berryTimer.ToString()} " : string.Empty)
                                        + (dashCooldown != 0 ? $"DashTimer: {(dashCooldown).ToString()} " : string.Empty);
                        string map = $"[{level.Session.Level}]";

                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(pos);
                        sb.AppendLine(speed);
                        sb.AppendLine(vel);

                        if (player.StateMachine.State == Player.StStarFly ||
                            SaveData.Instance.Assists.ThreeSixtyDashing ||
                            SaveData.Instance.Assists.SuperDashing)
                        {
                            sb.AppendLine(polarvel);
                        }

                        sb.AppendLine(miscstats);
                        if (!string.IsNullOrEmpty(statuses))
                        {
                            sb.AppendLine(statuses);
                        }
                        sb.Append(timers);
                        sb.Append(map);
                        lastPos      = player.ExactPosition;
                        lastTimer    = chapterTime;
                        PlayerStatus = sb.ToString().TrimEnd();
                    }
                }
                else
                {
                    PlayerStatus = level.InCutscene ? "Cutscene" : string.Empty;
                }
            }

            else if (Engine.Scene is SummitVignette summit)
            {
                PlayerStatus = "SummitVignette " + summit.GetPrivateField("ready");
            }

            else if (Engine.Scene is Overworld overworld)
            {
                PlayerStatus = "Overworld " + overworld.ShowInputUI;
            }

            else if (Engine.Scene != null)
            {
                PlayerStatus = Engine.Scene.GetType().Name;
            }
        }
        public static void UpdatePlayerInfo()
        {
            if (Engine.Scene is Level level)
            {
                Player player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    long chapterTime = level.Session.Time;
                    if (chapterTime != lastTimer || LastPos != player.ExactPosition)
                    {
                        framesPerSecond = 60f / Engine.TimeRateB;
                        string  pos      = GetAdjustedPos(player.Position, player.PositionRemainder);
                        string  speed    = $"Speed: {player.Speed.X:F2}, {player.Speed.Y:F2}";
                        Vector2 diff     = (player.ExactPosition - LastPos) * 60f;
                        string  vel      = $"Vel:   {diff.X:F2}, {diff.Y:F2}";
                        string  polarvel = $"Fly:   {diff.Length():F2}, {GetAngle(diff):F5}°";

                        string joystick;
                        if (Running && Controller.Previous is InputFrame inputFrame && inputFrame.HasActions(Actions.Feather))
                        {
                            joystick =
                                $"Analog: {AnalogHelper.LastDirection.X:F5}, {AnalogHelper.LastDirection.Y:F5}, {GetAngle(new Vector2(AnalogHelper.LastDirection.X, -AnalogHelper.LastDirection.Y)):F5}°";
                        }
                        else
                        {
                            joystick = string.Empty;
                        }

                        string miscstats = $"Stamina: {player.Stamina:0}  "
                                           + (WallJumpCheck(player, 1) ? "Wall-R " : string.Empty)
                                           + (WallJumpCheck(player, -1) ? "Wall-L " : string.Empty);
                        int dashCooldown = (int)(DashCooldownTimer(player) * framesPerSecond);

                        PlayerSeeker playerSeeker = level.Entities.FindFirst <PlayerSeeker>();
                        if (playerSeeker != null)
                        {
                            pos   = GetAdjustedPos(playerSeeker.Position, playerSeeker.PositionRemainder);
                            speed =
                                $"Speed: {PlayerSeekerSpeed(playerSeeker).X:F2}, {PlayerSeekerSpeed(playerSeeker).Y:F2}";
                            diff         = (playerSeeker.ExactPosition - LastPlayerSeekerPos) * 60f;
                            vel          = $"Vel:   {diff.X:F2}, {diff.Y:F2}";
                            polarvel     = $"Chase: {diff.Length():F2}, {GetAngle(diff):F2}°";
                            dashCooldown = (int)(PlayerSeekerDashTimer(playerSeeker) * framesPerSecond);
                        }

                        string statuses = (dashCooldown < 1 && player.Dashes > 0 ? "Dash " : string.Empty)
                                          + (player.LoseShards ? "Ground " : string.Empty)
                                          + (!player.LoseShards && JumpGraceTimer(player) > 0
                                              ? $"Coyote({(int) (JumpGraceTimer(player) * framesPerSecond)})"
                                              : string.Empty);
                        string transitionFrames = PlayerInfo.TransitionFrames > 0 ? $"({PlayerInfo.TransitionFrames})" : string.Empty;
                        statuses = (player.InControl && !level.Transitioning ? statuses : $"NoControl{transitionFrames} ")
                                   + (player.TimePaused ? "Paused " : string.Empty)
                                   + (level.InCutscene ? "Cutscene " : string.Empty)
                                   + (AdditionalStatusInfo ?? string.Empty);


                        if (player.Holding == null)
                        {
                            foreach (Component component in level.Tracker.GetComponents <Holdable>())
                            {
                                Holdable holdable = (Holdable)component;
                                if (holdable.Check(player))
                                {
                                    statuses += "Grab ";
                                    break;
                                }
                            }
                        }

                        int      berryTimer            = -10;
                        Follower firstRedBerryFollower =
                            player.Leader.Followers.Find(follower => follower.Entity is Strawberry berry && !berry.Golden);
                        if (firstRedBerryFollower?.Entity is Strawberry firstRedBerry)
                        {
                            object collectTimer;
                            if (firstRedBerry.GetType() == typeof(Strawberry) ||
                                (collectTimer = StrawberryCollectTimer(firstRedBerry)) == null)
                            {
                                // if this is a vanilla berry or a mod berry having no collectTimer, use the cached FieldInfo for Strawberry.collectTimer.
                                collectTimer = StrawberryCollectTimerFieldInfo.GetValue(firstRedBerry);
                            }

                            berryTimer = 9 - (int)Math.Round((float)collectTimer * framesPerSecond);
                        }

                        string timers = (berryTimer != -10
                                            ? berryTimer <= 9 ? $"BerryTimer: {berryTimer} " : $"BerryTimer: 9+{berryTimer - 9} "
                                            : string.Empty)
                                        + (dashCooldown != 0 ? $"DashTimer: {(dashCooldown).ToString()} " : string.Empty);
                        string roomNameAndTime =
                            $"[{level.Session.Level}] Timer: {(chapterTime / 10000000D):F3}({chapterTime / TimeSpan.FromSeconds(Engine.RawDeltaTime).Ticks})";

                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(pos);
                        sb.AppendLine(speed);
                        sb.AppendLine(vel);

                        if (player.StateMachine.State == Player.StStarFly ||
                            playerSeeker != null ||
                            SaveData.Instance.Assists.ThreeSixtyDashing ||
                            SaveData.Instance.Assists.SuperDashing)
                        {
                            sb.AppendLine(polarvel);
                        }

                        if (!string.IsNullOrEmpty(joystick))
                        {
                            sb.AppendLine(joystick);
                        }

                        sb.AppendLine(miscstats);
                        if (!string.IsNullOrEmpty(statuses))
                        {
                            sb.AppendLine(statuses);
                        }

                        if (!string.IsNullOrEmpty(timers))
                        {
                            sb.AppendLine(timers);
                        }

                        sb.Append(roomNameAndTime);
                        LastPos             = player.ExactPosition;
                        LastPlayerSeekerPos = playerSeeker?.ExactPosition ?? default;
                        lastTimer           = chapterTime;
                        PlayerStatus        = sb.ToString().TrimEnd();
                    }
                }
                else
                {
                    PlayerStatus = level.InCutscene ? "Cutscene" : string.Empty;
                }
            }
        private static void UpdatePlayerInfo()
        {
            Player player      = null;
            long   chapterTime = 0;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    chapterTime = level.Session.Time;
                    if (chapterTime != lastTimer || lastPos != player.ExactPosition)
                    {
                        string  pos       = $"Pos: {player.ExactPosition.X.ToString("0.00", enUS)},{player.ExactPosition.Y.ToString("0.00", enUS)}";
                        string  speed     = $"Speed: {player.Speed.X.ToString("0.00", enUS)},{player.Speed.Y.ToString("0.00", enUS)}";
                        Vector2 diff      = (player.ExactPosition - lastPos) * 60;
                        string  vel       = $"Vel: {diff.X.ToString("0.00", enUS)},{diff.Y.ToString("0.00", enUS)}";
                        string  polarvel  = $"     {diff.Length().ToString("0.00", enUS)},{GetAngle(diff).ToString("0.00", enUS)}°";
                        string  miscstats = $"Stamina: {player.Stamina.ToString("0")} Timer: {(chapterTime / 10000000D).ToString("0.000", enUS)}";
                        string  statuses  = (player.CanDash ? "Dash " : string.Empty) + (player.LoseShards ? "Ground " : string.Empty) + (player.WallJumpCheck(1) ? "Wall-R " : string.Empty) + (player.WallJumpCheck(-1) ? "Wall-L " : string.Empty) + (!player.LoseShards && player.jumpGraceTimer > 0 ? "Coyote " : string.Empty);
                        statuses = ((player.InControl && !level.Transitioning ? statuses : "NoControl ") + (player.TimePaused ? "Paused " : string.Empty) + (level.InCutscene ? "Cutscene " : string.Empty));
                        if (player.Holding == null)
                        {
                            foreach (Component component in level.Tracker.GetComponents <Holdable>())
                            {
                                Holdable holdable = (Holdable)component;
                                if (holdable.Check(player))
                                {
                                    statuses += "Grab ";
                                    break;
                                }
                            }
                        }

                        int      berryTimer            = -10;
                        Follower firstRedBerryFollower = player.Leader.Followers.Find(follower => follower.Entity is Strawberry berry && !berry.Golden);
                        if (firstRedBerryFollower?.Entity is Strawberry firstRedBerry)
                        {
                            berryTimer = (int)Math.Round(60f * firstRedBerry.collectTimer);
                        }
                        string timers = (berryTimer != -10 ? $"BerryTimer: {berryTimer.ToString()} " : string.Empty) + ((int)(player.dashCooldownTimer * 60f) != 0 ? $"DashTimer: {((int)Math.Round(player.dashCooldownTimer * 60f) - 1).ToString()} " : string.Empty);

                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(pos);
                        sb.AppendLine(speed);
                        sb.AppendLine(vel);
                        if (player.StateMachine.State == 19 || SaveData.Instance.Assists.ThreeSixtyDashing || SaveData.Instance.Assists.SuperDashing)
                        {
                            sb.AppendLine(polarvel);
                        }
                        sb.AppendLine(miscstats);
                        if (!string.IsNullOrEmpty(statuses))
                        {
                            sb.AppendLine(statuses);
                        }
                        sb.Append(timers);
                        PlayerStatus = sb.ToString().TrimEnd();
                        lastPos      = player.ExactPosition;
                        lastTimer    = chapterTime;
                    }
                }
                else
                {
                    PlayerStatus = level.InCutscene ? "Cutscene" : null;
                }
            }
            else if (Engine.Scene is SummitVignette summit)
            {
                PlayerStatus = string.Concat("SummitVignette ", summit);
            }
            else if (Engine.Scene is Overworld overworld)
            {
                PlayerStatus = string.Concat("Overworld ", overworld.ShowInputUI);
            }
            else if (Engine.Scene != null)
            {
                PlayerStatus = Engine.Scene.GetType().Name;
            }
        }
Esempio n. 6
0
        public static void UpdateInputs()
        {
            Player player      = null;
            long   chapterTime = 0;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    string statuses = ((int)(player.dashCooldownTimer * 60f) < 1 && player.Dashes > 0 ? "Dash " : string.Empty) + (player.LoseShards ? "Ground " : string.Empty) + (player.WallJumpCheck(1) ? "Wall-R " : string.Empty) + (player.WallJumpCheck(-1) ? "Wall-L " : string.Empty);
                    chapterTime = ((Celeste.Celeste)Engine.Instance).AutoSplitterInfo.ChapterTime;
                    Vector2 diff = (player.ExactPosition - lastPos) * 60;

                    if (player.Holding == null)
                    {
                        foreach (Component component in level.Tracker.GetComponents <Holdable>())
                        {
                            Holdable holdable = (Holdable)component;
                            if (holdable.Check(player))
                            {
                                statuses += "Grab ";
                                break;
                            }
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.Append("Pos: ").Append(player.ExactPosition.X.ToString("0.0", enUS)).Append(',').AppendLine(player.ExactPosition.Y.ToString("0.0", enUS));
                    sb.Append("Speed: ").Append(player.Speed.X.ToString("0.00", enUS)).Append(',').Append(player.Speed.Y.ToString("0.00", enUS)).Append(',').AppendLine(player.Speed.Length().ToString("0.00", enUS));
                    sb.Append("Vel: ").Append(diff.X.ToString("0.00", enUS)).Append(',').Append(diff.Y.ToString("0.00", enUS)).Append(',').AppendLine(diff.Length().ToString("0.00", enUS));
                    sb.Append("Stamina: ").Append(player.Stamina.ToString("0")).Append(" Timer: ").AppendLine(((double)chapterTime / (double)10000000).ToString("0.000", enUS));
                    sb.Append(player.InControl && !level.Transitioning ? statuses : "NoControl ").Append(player.TimePaused ? "Paused " : string.Empty).Append(level.InCutscene ? "Cutscene " : string.Empty);
                    PlayerStatus = sb.ToString();
                }
                else
                {
                    PlayerStatus = level.InCutscene ? "Cutscene" : null;
                }
            }
            else if (Engine.Scene is SummitVignette summit)
            {
                PlayerStatus = string.Concat("SummitVignette ", summit.ready);
            }
            else if (Engine.Scene is Overworld overworld)
            {
                PlayerStatus = string.Concat("Overworld ", overworld.ShowInputUI);
            }
            else if (Engine.Scene != null)
            {
                PlayerStatus = Engine.Scene.GetType().Name;
            }

            kbState = Keyboard.GetState();
            GamePadState padState = GetGamePadState();

            HandleFrameRates(padState);
            CheckControls(padState);
            FrameStepping(padState);

            if (HasFlag(state, State.Enable))
            {
                Running = true;

                if (HasFlag(state, State.FrameStep))
                {
                    return;
                }

                if (HasFlag(state, State.Record))
                {
                    controller.RecordPlayer();
                }
                else
                {
                    bool fastForward = controller.HasFastForward;
                    controller.PlaybackPlayer();
                    if (fastForward && !controller.HasFastForward)
                    {
                        nextState |= State.FrameStep;
                        FrameLoops = 1;
                    }

                    if (!controller.CanPlayback)
                    {
                        DisableRun();
                    }
                }
                string status = controller.Current.Line + "[" + controller.ToString() + "]";
                CurrentStatus = status;
            }
            else
            {
                Running       = false;
                CurrentStatus = null;

                if (!Engine.Instance.IsActive)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (MInput.GamePads[i].Attached)
                        {
                            MInput.GamePads[i].CurrentState = padState;
                        }
                    }
                    MInput.UpdateVirtualInputs();
                }
            }

            if (player != null && chapterTime != lastTimer)
            {
                lastPos   = player.ExactPosition;
                lastTimer = chapterTime;
            }
        }
        public static String GetPlayerInfo()
        {
            if (!(Engine.Scene is Level level))
            {
                return("");
            }

            Player player = level.Tracker.GetEntity <Player>();

            if (player == null)
            {
                return("");
            }

            double x, y;

            x = player.PositionRemainder.X % 0.25 < 0.01
                ? Math.Floor(player.PositionRemainder.X * 100) / 100
                : player.PositionRemainder.X;
            y = player.PositionRemainder.Y % 0.25 < 0.01
                ? Math.Floor(player.PositionRemainder.Y * 100) / 100
                : player.PositionRemainder.Y;
            x += player.X;
            y += player.Y;
            string  pos       = $"Pos: {x:0.00}, {y:0.00}";
            string  speed     = $"Speed: {player.Speed.X:0.00}, {player.Speed.Y:0.00}";
            Vector2 diff      = (player.ExactPosition - lastPos) * 60;
            string  vel       = $"Vel: {diff.X:0.00}, {diff.Y:0.00}";
            string  miscstats = $"Stamina: {player.Stamina:0}";

            int    dashCooldown = (int)((float)DashCooldownTimer.GetValue(player) * 60f);
            string statuses     = (dashCooldown < 1 && player.Dashes > 0 ? "Dash " : string.Empty)
                                  + (player.LoseShards ? "Ground " : string.Empty)
                                  + ((bool)PlayerWallJumpCheck.Invoke(player, 1) ? "Wall-R " : string.Empty)
                                  + ((bool)PlayerWallJumpCheck.Invoke(player, -1) ? "Wall-L " : string.Empty)
                                  + (!player.LoseShards && (float)JumpGraceTimer.GetValue(player) > 0
                                  ? "Coyote "
                                  : string.Empty);

            statuses = (player.InControl && !level.Transitioning ? statuses : "NoControl ")
                       + (player.TimePaused ? "Paused " : string.Empty)
                       + (level.InCutscene ? "Cutscene " : string.Empty);

            if (player.Holding == null)
            {
                foreach (Component component in level.Tracker.GetComponents <Holdable>())
                {
                    Holdable holdable = (Holdable)component;
                    if (holdable.Check(player))
                    {
                        statuses += "Grab ";
                        break;
                    }
                }
            }

            int      berryTimer            = -10;
            Follower firstRedBerryFollower =
                player.Leader.Followers.Find(follower => follower.Entity is Strawberry berry && !berry.Golden);

            if (firstRedBerryFollower?.Entity is Strawberry firstRedBerry)
            {
                object collectTimer;
                if (firstRedBerry.GetType() == typeof(Strawberry) ||
                    (collectTimer = firstRedBerry.GetType().GetPrivateFieldInfo("collectTimer")) == null)
                {
                    // if this is a vanilla berry or a mod berry having no collectTimer, use the cached FieldInfo for Strawberry.collectTimer.
                    collectTimer = CollectTimer.GetValue(firstRedBerry);
                }

                berryTimer = (int)Math.Round(60f * (float)collectTimer);
            }

            string timers = (berryTimer != -10 ? $"BerryTimer: {berryTimer.ToString()} " : string.Empty)
                            + (dashCooldown != 0 ? $"DashTimer: {(dashCooldown).ToString()} " : string.Empty);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(pos);
            sb.AppendLine(speed);
            sb.AppendLine(vel);

            sb.AppendLine(miscstats);
            if (!string.IsNullOrEmpty(statuses))
            {
                sb.AppendLine(statuses);
            }
            sb.Append(timers);
            lastPos = player.ExactPosition;
            return(sb.ToString().TrimEnd());
        }
Esempio n. 8
0
        public static void ExportPlayerInfo(string[] tracked = null)
        {
            Player player = null;

            if (Engine.Scene is Level level)
            {
                player = level.Tracker.GetEntity <Player>();
                if (player != null)
                {
                    string inputs = controller.Current.ActionsToString();
                    string time   = (level.Session.Time / 10000000D).ToString("0.000");
                    double x      = (double)player.X + player.PositionRemainder.X;
                    double y      = (double)player.Y + player.PositionRemainder.Y;
                    string pos    = x.ToString() + "," + y.ToString();
                    string speed  = player.Speed.X.ToString() + "," + player.Speed.Y.ToString();

                    int    dashCooldown = (int)((float)player.GetPrivateField("dashCooldownTimer") * 60f);
                    string statuses     = (dashCooldown < 1 && player.Dashes > 0 ? "Dash " : string.Empty)
                                          + (player.LoseShards ? "Ground " : string.Empty)
                                          + ((bool)player.InvokePrivateMethod("WallJumpCheck", 1) ? "Wall-R " : string.Empty)
                                          + ((bool)player.InvokePrivateMethod("WallJumpCheck", -1) ? "Wall-L " : string.Empty)
                                          + (!player.LoseShards && (float)player.GetPrivateField("jumpGraceTimer") > 0 ? "Coyote " : string.Empty);
                    statuses = (player.InControl && !level.Transitioning ? statuses : "NoControl ")
                               + (player.TimePaused ? "Paused " : string.Empty)
                               + (level.InCutscene ? "Cutscene " : string.Empty);

                    if (player.Holding == null)
                    {
                        foreach (Component component in level.Tracker.GetComponents <Holdable>())
                        {
                            Holdable holdable = (Holdable)component;
                            if (holdable.Check(player))
                            {
                                statuses += "Grab ";
                                break;
                            }
                        }
                    }
                    string output = string.Join(" ", inputs, controller.CurrentFrame, time, pos, speed, player.StateMachine.State, statuses);

                    /*
                     * foreach (string s in tracked) {
                     *      Type t = Type.GetType("Celeste." + s);
                     *      MethodInfo method = typeof(Tracker).GetMethod("GetEntities");
                     *      method.MakeGenericMethod(t);
                     *      Entity[] entities = (Entity[])method.Invoke(level.Tracker, null);
                     *      foreach (Entity entity in entities) {
                     *              Actor actor = entity as Actor;
                     *              if (actor != null) {
                     *                      x = (double)actor.X + actor.PositionRemainder.X;
                     *                      y = (double)actor.Y + actor.PositionRemainder.Y;
                     *                      pos = x.ToString() + "," + y.ToString();
                     *              }
                     *              else {
                     *                      pos = entity.X.ToString() + "," + entity.Y.ToString();
                     *              }
                     *              output += $" {s}: {pos}";
                     *      }
                     *
                     * }
                     */
                    sw.WriteLine(output);
                }
            }
        }