void IUtilityCommand.Run(Utility utility, string[] args)
        {
            var replay = ReplayMetadata.Read(args[1]);

            if (replay == null)
            {
                throw new InvalidDataException("Failed to read replay meta data");
            }

            var info = replay.GameInfo;

            var lines = FieldSaver.Save(info).ToLines(replay.FilePath);

            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }

            Console.WriteLine("\tPlayers:");
            var playerCount = 0;

            foreach (var p in info.Players)
            {
                var playerLines = FieldSaver.Save(p).ToLines("{0}".F(playerCount++));
                foreach (var line in playerLines)
                {
                    Console.WriteLine("\t\t" + line);
                }
            }
        }
Esempio n. 2
0
        public virtual void StartGame(Arguments args)
        {
            Launch = new LaunchArguments(args);
            Ui.ResetAll();
            Game.Settings.Save();

            if (!string.IsNullOrEmpty(Launch.Benchmark))
            {
                Console.WriteLine("Saving benchmark data into {0}".F(Path.Combine(Platform.SupportDir, "Logs")));

                Game.BenchmarkMode(Launch.Benchmark);
            }

            // Join a server directly
            var connect = Launch.GetConnectEndPoint();

            if (connect != null)
            {
                Game.LoadShellMap();
                Game.RemoteDirectConnect(connect);
                return;
            }

            // Start a map directly
            if (!string.IsNullOrEmpty(Launch.Map))
            {
                Game.LoadMap(Launch.Map);
                return;
            }

            // Load a replay directly
            if (!string.IsNullOrEmpty(Launch.Replay))
            {
                ReplayMetadata replayMeta = null;
                try
                {
                    replayMeta = ReplayMetadata.Read(Launch.Replay);
                }
                catch { }

                if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
                {
                    Game.JoinReplay(Launch.Replay);
                }

                if (replayMeta != null)
                {
                    var mod = replayMeta.GameInfo.Mod;
                    if (mod != null && mod != Game.ModData.Manifest.Id && Game.Mods.ContainsKey(mod))
                    {
                        Game.InitializeMod(mod, args);
                    }
                }

                return;
            }

            Game.LoadShellMap();
            Game.Settings.Save();
        }
Esempio n. 3
0
        public void StartGame(Arguments args)
        {
            Launch = new LaunchArguments(args);
            Ui.ResetAll();
            Game.Settings.Save();

            if (Launch.Benchmark)
            {
                Log.AddChannel("cpu", "cpu.csv");
                Log.Write("cpu", "tick;time [ms]");

                Log.AddChannel("render", "render.csv");
                Log.Write("render", "frame;time [ms]");

                Console.WriteLine("Saving benchmark data into {0}".F(Path.Combine(Platform.SupportDir, "Logs")));

                Game.BenchmarkMode = true;
            }

            // Join a server directly
            var connect = Launch.GetConnectAddress();

            if (!string.IsNullOrEmpty(connect))
            {
                var parts = connect.Split(':');

                if (parts.Length == 2)
                {
                    var host = parts[0];
                    var port = Exts.ParseIntegerInvariant(parts[1]);
                    Game.LoadShellMap();
                    Game.RemoteDirectConnect(host, port);
                    return;
                }
            }

            // Load a replay directly
            if (!string.IsNullOrEmpty(Launch.Replay))
            {
                var replayMeta = ReplayMetadata.Read(Launch.Replay);
                if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
                {
                    Game.JoinReplay(Launch.Replay);
                }

                if (replayMeta != null)
                {
                    var mod = replayMeta.GameInfo.Mod;
                    if (mod != null && mod != Game.ModData.Manifest.Mod.Id && ModMetadata.AllMods.ContainsKey(mod))
                    {
                        Game.InitializeMod(mod, args);
                    }
                }

                return;
            }

            Game.LoadShellMap();
            Game.Settings.Save();
        }
Esempio n. 4
0
        public void StartGame(Arguments args)
        {
            Launch = new LaunchArguments(args);
            Ui.ResetAll();
            Game.Settings.Save();

            // Join a server directly
            var connect = Launch.GetConnectAddress();

            if (!string.IsNullOrEmpty(connect))
            {
                var parts = connect.Split(':');

                if (parts.Length == 2)
                {
                    var host = parts[0];
                    var port = Exts.ParseIntegerInvariant(parts[1]);
                    Game.LoadShellMap();
                    Game.RemoteDirectConnect(host, port);
                    return;
                }
            }

            // Load a replay directly
            if (!string.IsNullOrEmpty(Launch.Replay))
            {
                var replayMeta = ReplayMetadata.Read(Launch.Replay);
                if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
                {
                    Game.JoinReplay(Launch.Replay);
                }

                if (replayMeta != null)
                {
                    var mod = replayMeta.GameInfo.Mod;
                    if (mod != null && mod != Game.ModData.Manifest.Mod.Id && ModMetadata.AllMods.ContainsKey(mod))
                    {
                        Game.InitializeMod(mod, args);
                    }
                }

                return;
            }

            Game.LoadShellMap();
            Game.Settings.Save();
        }
Esempio n. 5
0
        void LoadReplays(string dir, ScrollItemWidget template)
        {
            using (new Support.PerfTimer("Load replays"))
            {
                var loadedReplays = new ConcurrentBag <ReplayMetadata>();
                Parallel.ForEach(Directory.GetFiles(dir, "*.orarep", SearchOption.AllDirectories), (fileName, pls) =>
                {
                    if (cancelLoadingReplays)
                    {
                        pls.Stop();
                        return;
                    }

                    var replay = ReplayMetadata.Read(fileName);
                    if (replay != null)
                    {
                        loadedReplays.Add(replay);
                    }
                });

                if (cancelLoadingReplays)
                {
                    return;
                }

                var sortedReplays = loadedReplays.OrderByDescending(replay => replay.GameInfo.StartTimeUtc).ToList();
                Game.RunAfterTick(() =>
                {
                    replayList.RemoveChildren();
                    foreach (var replay in sortedReplays)
                    {
                        AddReplay(replay, template);
                    }

                    SetupReplayDependentFilters();
                    ApplyFilter();
                });
            }
        }
Esempio n. 6
0
        public void Run(ModData modData, string[] args)
        {
            var replay = ReplayMetadata.Read(args[1]);
            var info   = replay.GameInfo;

            var lines = FieldSaver.Save(info).ToLines(replay.FilePath);

            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }

            Console.WriteLine("\tPlayers:");
            var playerCount = 0;

            foreach (var p in info.Players)
            {
                var playerLines = FieldSaver.Save(p).ToLines("{0}".F(playerCount++));
                foreach (var line in playerLines)
                {
                    Console.WriteLine("\t\t" + line);
                }
            }
        }
Esempio n. 7
0
        public void StartGame(Arguments args)
        {
            Ui.ResetAll();
            Game.Settings.Save();

            // Check whether the mod content is installed
            // TODO: The installation code has finally been beaten into shape, so we can
            // finally move it all into the planned "Manage Content" panel in the modchooser mod.
            var installData       = Game.ModData.Manifest.Get <ContentInstaller>();
            var installModContent = !installData.TestFiles.All(f => GlobalFileSystem.Exists(f));
            var installModMusic   = args != null && args.Contains("Install.Music");

            if (installModContent || installModMusic)
            {
                var widgetArgs = new WidgetArgs()
                {
                    { "continueLoading", () => Game.InitializeMod(Game.Settings.Game.Mod, args) },
                };

                if (installData.BackgroundWidget != null)
                {
                    Ui.LoadWidget(installData.BackgroundWidget, Ui.Root, widgetArgs);
                }

                var menu = installModContent ? installData.MenuWidget : installData.MusicMenuWidget;
                Ui.OpenWindow(menu, widgetArgs);

                return;
            }

            // Join a server directly
            var connect = string.Empty;

            if (args != null)
            {
                if (args.Contains("Launch.Connect"))
                {
                    connect = args.GetValue("Launch.Connect", null);
                }

                if (args.Contains("Launch.URI"))
                {
                    connect = args.GetValue("Launch.URI", null);
                    if (connect != null)
                    {
                        connect = connect.Replace("openra://", "");
                        connect = connect.TrimEnd('/');
                    }
                }
            }

            if (!string.IsNullOrEmpty(connect))
            {
                var parts = connect.Split(':');

                if (parts.Length == 2)
                {
                    var host = parts[0];
                    var port = Exts.ParseIntegerInvariant(parts[1]);
                    Game.LoadShellMap();
                    Game.RemoteDirectConnect(host, port);
                    return;
                }
            }

            // Load a replay directly
            var replayFilename = args != null?args.GetValue("Launch.Replay", null) : null;

            if (!string.IsNullOrEmpty(replayFilename))
            {
                var replayMeta = ReplayMetadata.Read(replayFilename);
                if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
                {
                    Game.JoinReplay(replayFilename);
                }

                if (replayMeta != null)
                {
                    var mod = replayMeta.GameInfo.Mod;
                    if (mod != null && mod != Game.ModData.Manifest.Mod.Id && ModMetadata.AllMods.ContainsKey(mod))
                    {
                        Game.InitializeMod(mod, args);
                    }
                }

                return;
            }

            Game.LoadShellMap();
            Game.Settings.Save();
        }
Esempio n. 8
0
        public ReplayConnection(string replayFilename)
        {
            Filename      = replayFilename;
            FinalGameTick = ReplayMetadata.Read(replayFilename).GameInfo.FinalGameTick;

            // Parse replay data into a struct that can be fed to the game in chunks
            // to avoid issues with all immediate orders being resolved on the first tick.
            using (var rs = File.OpenRead(replayFilename))
            {
                var packets = new List <(int ClientId, byte[] Packet)>();
                var chunk   = new Chunk();
                while (rs.Position < rs.Length)
                {
                    var client = rs.ReadInt32();
                    if (client == ReplayMetadata.MetaStartMarker)
                    {
                        break;
                    }

                    var packetLen = rs.ReadInt32();
                    var packet    = rs.ReadBytes(packetLen);
                    var frame     = BitConverter.ToInt32(packet, 0);
                    packets.Add((client, packet));

                    if (frame != int.MaxValue && (!lastClientsFrame.ContainsKey(client) || frame > lastClientsFrame[client]))
                    {
                        lastClientsFrame[client] = frame;
                    }

                    if (packet.Length > 4 && (packet[4] == (byte)OrderType.Disconnect || packet[4] == (byte)OrderType.SyncHash))
                    {
                        continue;
                    }

                    if (frame == 0)
                    {
                        // Parse replay metadata from orders stream
                        var orders = packet.ToOrderList(null);
                        foreach (var o in orders)
                        {
                            if (o.OrderString == "StartGame")
                            {
                                IsValid = true;
                            }
                            else if (o.OrderString == "SyncInfo" && !IsValid)
                            {
                                LobbyInfo = Session.Deserialize(o.TargetString);
                            }
                        }
                    }
                    else
                    {
                        // Regular order - finalize the chunk
                        chunk.Frame   = frame;
                        chunk.Packets = packets.ToArray();
                        packets.Clear();
                        chunks.Enqueue(chunk);
                        chunk = new Chunk();

                        TickCount = Math.Max(TickCount, frame);
                    }
                }

                var lastClientToDisconnect = lastClientsFrame.MaxBy(kvp => kvp.Value).Key;

                // 2nd parse : replace all disconnect packets without frame with real
                // disconnect frame
                // NOTE: to modify/remove if a reconnect feature is set
                foreach (var tmpChunk in chunks)
                {
                    foreach (var tmpPacketPair in tmpChunk.Packets)
                    {
                        var client = tmpPacketPair.ClientId;

                        // Don't replace the final disconnection packet - we still want this to end the replay.
                        if (client == lastClientToDisconnect)
                        {
                            continue;
                        }

                        var packet = tmpPacketPair.Packet;
                        if (packet.Length == 5 && packet[4] == (byte)OrderType.Disconnect)
                        {
                            var lastClientFrame = lastClientsFrame[client];
                            var lastFramePacket = BitConverter.GetBytes(lastClientFrame);
                            Array.Copy(lastFramePacket, packet, lastFramePacket.Length);
                        }
                    }
                }
            }

            ordersFrame = LobbyInfo.GlobalSettings.OrderLatency;
        }
        public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart)
        {
            panel = widget;

            playerList     = panel.Get <ScrollPanelWidget>("PLAYER_LIST");
            playerHeader   = playerList.Get <ScrollItemWidget>("HEADER");
            playerTemplate = playerList.Get <ScrollItemWidget>("TEMPLATE");
            playerList.RemoveChildren();

            panel.Get <ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };

            replayList = panel.Get <ScrollPanelWidget>("REPLAY_LIST");
            var template = panel.Get <ScrollItemWidget>("REPLAY_TEMPLATE");

            var mod = Game.modData.Manifest.Mod;
            var dir = new[] { Platform.SupportDir, "Replays", mod.Id, mod.Version }.Aggregate(Path.Combine);

            replayList.RemoveChildren();
            if (Directory.Exists(dir))
            {
                using (new Support.PerfTimer("Load replays"))
                {
                    replays = Directory
                              .GetFiles(dir, "*.rep")
                              .Select((filename) => ReplayMetadata.Read(filename))
                              .Where((r) => r != null)
                              .OrderByDescending(r => r.GameInfo.StartTimeUtc)
                              .ToList();
                }

                foreach (var replay in replays)
                {
                    AddReplay(replay, template);
                }

                ApplyFilter();
            }
            else
            {
                replays = new List <ReplayMetadata>();
            }

            var watch = panel.Get <ButtonWidget>("WATCH_BUTTON");

            watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available;
            watch.OnClick    = () => { WatchReplay(); onStart(); };

            panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null;

            var preview = panel.Get <MapPreviewWidget>("MAP_PREVIEW");

            preview.SpawnOccupants = () => selectedSpawns;
            preview.Preview        = () => selectedReplay != null ? selectedReplay.GameInfo.MapPreview : null;

            var title = panel.GetOrNull <LabelWidget>("MAP_TITLE");

            if (title != null)
            {
                title.GetText = () => selectedReplay != null ? selectedReplay.GameInfo.MapPreview.Title : null;
            }

            var type = panel.GetOrNull <LabelWidget>("MAP_TYPE");

            if (type != null)
            {
                type.GetText = () => selectedReplay.GameInfo.MapPreview.Type;
            }

            panel.Get <LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds);

            SetupFilters();
            SetupManagement();
        }