Exemple #1
0
        public override ScriptData Read(string name, Stream stream)
        {
            using (var file = new BinaryReader(stream, Encodings.cp932, true))
            {
                uint signature = file.ReadUInt32();
                if (signature != file.BaseStream.Length)
                {
                    return(null);
                }
                uint header_size = file.ReadUInt32();
                if (header_size > 0x24 || header_size < 0x14)
                {
                    return(null);
                }
                uint   code_size       = file.ReadUInt32();
                uint   text_index_size = file.ReadUInt32();
                uint   text_size       = file.ReadUInt32();
                byte[] header_data     = file.ReadBytes((int)header_size - 0x14);
                byte[] code            = file.ReadBytes((int)code_size);
                uint[] index           = new uint[text_index_size / 4];
                for (int i = 0; i < index.Length; ++i)
                {
                    index[i] = file.ReadUInt32();
                    if (index[i] >= text_size)
                    {
                        return(null);
                    }
                }
                long text_offset = header_size + code_size + text_index_size;

                var script = new GscScriptData();
                script.Header = header_data;
                script.Code   = code;
                for (int i = 0; i < index.Length; ++i)
                {
                    file.BaseStream.Position = text_offset + index[i];
                    string text = StreamExtension.ReadCString(file.BaseStream);
                    script.TextLines.Add(new ScriptLine {
                        Id = (uint)i, Text = text
                    });
                }
                long footer_pos = text_offset + text_size;
                file.BaseStream.Position = footer_pos;
                script.Footer            = new byte[file.BaseStream.Length - footer_pos];
                file.BaseStream.Read(script.Footer, 0, script.Footer.Length);
                return(script);
            }
        }
Exemple #2
0
        public override ScriptData Read(string name, Stream stream)
        {
            using (var file = new BinaryReader (stream, Encodings.cp932, true))
            {
                uint signature = file.ReadUInt32();
                if (signature != file.BaseStream.Length)
                    return null;
                uint header_size = file.ReadUInt32();
                if (header_size > 0x24 || header_size < 0x14)
                    return null;
                uint code_size = file.ReadUInt32();
                uint text_index_size = file.ReadUInt32();
                uint text_size = file.ReadUInt32();
                byte[] header_data = file.ReadBytes ((int)header_size-0x14);
                byte[] code = file.ReadBytes ((int)code_size);
                uint[] index = new uint[text_index_size/4];
                for (int i = 0; i < index.Length; ++i)
                {
                    index[i] = file.ReadUInt32();
                    if (index[i] >= text_size)
                        return null;
                }
                long text_offset = header_size + code_size + text_index_size;

                var script = new GscScriptData();
                script.Header = header_data;
                script.Code = code;
                for (int i = 0; i < index.Length; ++i)
                {
                    file.BaseStream.Position = text_offset + index[i];
                    string text = StreamExtension.ReadCString (file.BaseStream);
                    script.TextLines.Add (new ScriptLine { Id = (uint)i, Text = text });
                }
                long footer_pos = text_offset + text_size;
                file.BaseStream.Position = footer_pos;
                script.Footer = new byte[file.BaseStream.Length - footer_pos];
                file.BaseStream.Read (script.Footer, 0, script.Footer.Length);
                return script;
            }
        }