Пример #1
0
        public static Op FromStream(ReplayReader stream)
        {
            var t   = (CMDST)stream.ReadByte();
            var len = stream.ReadUInt16();

            byte[] data = null;

            if (len > 0)
            {
                data = stream.ReadBytes(len - 3);
            }

            Type type;

            CmdToType.TryGetValue(t, out type);
            var op = (Op)Activator.CreateInstance(type ?? opType);

            op.Set(t, data);

            return(op);
        }
Пример #2
0
        public static CommandStream FromStream(ReplayReader stream)
        {
            var cstream = new CommandStream {
                ops = new List <Op>((int)stream.Length / 9)
            };

            try
            {
                Op op;
                do
                {
                    op = Op.FromStream(stream);
                    cstream.Add(op);
                } while (op.Type != CMDST.EndGame);
            }
            catch (EndOfStreamException)
            {
            }

            return(cstream);
        }
Пример #3
0
        public static ReplayHeader FromStream(ReplayReader stream)
        {
            var header = new ReplayHeader
            {
                Version      = stream.ReadLuaString(),
                Unknown      = stream.ReadLuaString(),
                Map          = stream.ReadLuaString(),
                Unknown2     = stream.ReadLuaString(),
                NumMods      = stream.ReadUInt32(),
                Mods         = stream.ReadLua(),
                ScenarioSize = stream.ReadUInt32(),
                Scenario     = stream.ReadLua(),
                NumSources   = stream.ReadByte()
            };

            for (var i = 0; i < header.NumSources; i++)
            {
                var name = stream.ReadLuaString();
                header.Timeouts[name] = stream.ReadInt32();
            }
            header.Cheats    = stream.ReadByte() != 0;
            header.NumArmies = stream.ReadByte();

            for (var i = 0; i < header.NumArmies; i++)
            {
                var     n    = stream.ReadUInt32();
                dynamic data = stream.ReadLua();
                data["SourceId"] = stream.ReadByte();
                header.Armies.Add(data);
                header.CommandSources.Add(data["SourceId"]);
                if (stream.PeekByte() == 0xff) // some unknown weirdness in format
                {
                    stream.ReadByte();
                }
            }

            header.Random = stream.ReadUInt32();

            return(header);
        }
Пример #4
0
 public ReplayParser(Stream stream)
 {
     _stream = new ReplayReader(stream);
 }