Ejemplo n.º 1
0
        private static ICollection<Sc2ReplayAttribute> ParseAttributes(IMpqArchive replay)
        {
            var file = replay.ReadFile("replay.attributes.events");

            using (var stream = new MemoryStream(file))
            {
                stream.Skip(5); // there is a 5-byte header; should we validate this?

                var attributeCount = stream.ReadInt32();
                var attributes = new List<Sc2ReplayAttribute>();

                for (var i = 0; i < attributeCount; i++)
                {
                    var attr = new Sc2ReplayAttribute
                               {
                                   Header = stream.ReadInt32(),
                                   Type = (Sc2ReplayAttributeType) stream.ReadInt32(),
                                   PlayerIndex = stream.ReadByte(),
                                   Value = stream.ReadBytes(4).Reverse().ToArray(),
                               };

                    attributes.Add(attr);
                }

                return attributes;
            }
        }
Ejemplo n.º 2
0
        public static byte[]? ReadFile(this IMpqArchive archive, string path)
        {
            var size = archive.GetFileSize(path);

            if (!size.HasValue)
            {
                return(null);
            }

            var buf = new byte[size.Value];

            archive.ReadFile(buf, path);
            return(buf);
        }
Ejemplo n.º 3
0
        public static PooledArray <byte>?ReadFilePool(this IMpqArchive archive, string path)
        {
            var size = archive.GetFileSize(path);

            if (!size.HasValue)
            {
                return(null);
            }

            var buf = new PooledArray <byte>(size.Value);

            archive.ReadFile(buf.AsArray(), path);
            return(buf);
        }
Ejemplo n.º 4
0
        public static object ReadSerializedData(this IMpqArchive archive, string path, bool convertStringsToUtf8)
        {
            if (archive == null)
            {
                throw new ArgumentNullException("archive");
            }

            var file = archive.ReadFile(path);

            if (file == null)
            {
                return(null);
            }

            using (var memory = new MemoryStream(file))
                using (var reader = new BinaryReader(memory))
                {
                    return(Deserialize(reader, convertStringsToUtf8));
                }
        }