Пример #1
0
        public override ScriptData Read(string name, Stream stream)
        {
            if (Signature != FormatCatalog.ReadSignature(stream))
            {
                return(null);
            }
            uint script_id  = Convert.ToUInt32(name, 16);
            uint max_offset = (uint)Math.Min(stream.Length, 0xffffffff);

            using (var file = new BinaryReader(stream, Encodings.cp932, true))
            {
                uint script_type = file.ReadUInt32();
                var  script      = new AmiScriptData {
                    Id   = script_id,
                    Type = script_type
                };
                uint count = file.ReadUInt32();
                for (uint i = 0; i < count; ++i)
                {
                    uint offset = file.ReadUInt32();
                    if (offset >= max_offset)
                    {
                        throw new InvalidFormatException("Invalid offset in script data file");
                    }
                    int  size       = file.ReadInt32();
                    uint id         = file.ReadUInt32();
                    var  header_pos = file.BaseStream.Position;
                    file.BaseStream.Position = offset;
                    byte[] line = file.ReadBytes(size);
                    if (line.Length != size)
                    {
                        throw new InvalidFormatException("Premature end of file");
                    }
                    string text = Encodings.cp932.GetString(line);

                    script.TextLines.Add(new ScriptLine {
                        Id = id, Text = text
                    });
                    file.BaseStream.Position = header_pos;
                }
                return(script);
            }
        }
Пример #2
0
        public override ScriptData Read(string name, Stream stream)
        {
            if (Signature != FormatCatalog.ReadSignature (stream))
                return null;
            uint script_id = Convert.ToUInt32 (name, 16);
            uint max_offset = (uint)Math.Min (stream.Length, 0xffffffff);

            using (var file = new BinaryReader (stream, Encodings.cp932, true))
            {
                uint script_type = file.ReadUInt32();
                var script = new AmiScriptData {
                    Id = script_id,
                    Type = script_type
                };
                uint count = file.ReadUInt32();
                for (uint i = 0; i < count; ++i)
                {
                    uint offset = file.ReadUInt32();
                    if (offset >= max_offset)
                        throw new InvalidFormatException ("Invalid offset in script data file");
                    int size = file.ReadInt32();
                    uint id = file.ReadUInt32();
                    var header_pos = file.BaseStream.Position;
                    file.BaseStream.Position = offset;
                    byte[] line = file.ReadBytes (size);
                    if (line.Length != size)
                        throw new InvalidFormatException ("Premature end of file");
                    string text = Encodings.cp932.GetString (line);

                    script.TextLines.Add (new ScriptLine { Id = id, Text = text });
                    file.BaseStream.Position = header_pos;
                }
                return script;
            }
        }