Пример #1
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var data = GetData();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            output.Write(input.ReadBytes(4));

                            var numColumns = input.ReadInt32();
                            var numRows    = input.ReadInt32();

                            output.Write(numColumns);
                            output.Write(numRows);
                            output.Write(input.ReadBytes(4));

                            foreach (var column in data.Columns)
                            {
                                column.WriteInfo(output);
                            }

                            foreach (var column in data.Columns)
                            {
                                column.WriteData(output);
                            }
                        }
        }
Пример #2
0
        public override void Rebuild(string outputFolder)
        {
            string outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            IList <Subtitle> subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            output.Write(input.ReadBytes(0x180));

                            string str = input.ReadStringSerialized(0x04);

                            Subtitle sub = subtitles.First(x => x.Offset == 0x180);

                            output.WriteStringSerialized(sub.Translation, 0x04);

                            int    remainderLength = (int)(input.Length - input.Position);
                            byte[] remainder       = input.ReadBytes(remainderLength);
                            output.Write(remainder);
                        }
        }
Пример #3
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            output.Write(input.ReadBytes(0x1A0));

                            var length = input.ReadInt32();
                            input.ReadBytes(length);
                            input.SkipPadding(0x04);

                            var sub  = subtitles.First(x => x.Offset == 0x1A0);
                            var data = FileEncoding.GetBytes(sub.Translation);
                            output.Write(data.Length);
                            output.Write(data);
                            output.WritePadding(0x04);

                            var remainderLength = (int)(input.Length - input.Position);
                            var remainder       = input.ReadBytes(remainderLength);
                            output.Write(remainder);
                        }
        }
Пример #4
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            output.Write(input.ReadBytes(32));

                            var  firstString  = input.PeekInt32();
                            long outputOffset = firstString;

                            var subtitle = ReadSubtitle(input);
                            outputOffset = WriteSubtitle(output, subtitles, subtitle.Offset, outputOffset);

                            subtitle     = ReadSubtitle(input);
                            outputOffset = WriteSubtitle(output, subtitles, subtitle.Offset, outputOffset);

                            output.Write(input.ReadBytes(24));

                            var dds = ReadSubtitle(input);
                            WriteString(output, dds, outputOffset);

                            output.Write(input.ReadBytes(firstString - (int)input.Position));

                            output.WritePadding(16);
                        }
        }
Пример #5
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles  = GetSubtitles();
            var subs       = subtitles.Select(subtitle => subtitle as SubtitleWithId).ToList();
            var dictionary = new Dictionary <string, SubtitleWithId>(subs.Count);

            foreach (SubtitleWithId subtitle in subs)
            {
                dictionary.Add(subtitle.Id, subtitle);
            }

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            output.Write(input.ReadBytes(0x04));
                            output.Write(input.ReadBytes(0x08));
                            output.Write(input.ReadBytes(0x04));
                            output.Write(input.ReadBytes(0x04));
                            output.Write(input.ReadBytes(0x08));
                            output.WriteStringSerialized(input.ReadStringSerialized(0x04), 0x04);

                            Rebuild(input, output, dictionary);
                        }
        }
Пример #6
0
        public override void Rebuild(string outputFolder)
        {
            string outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            IList <Subtitle> subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, customEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, customEncoding))
                        {
                            while (input.Position < input.Length)
                            {
                                output.Write(input.ReadBytes(4));

                                int    fileSize    = input.ReadInt32();
                                int    offsetBase  = (int)input.Position;
                                byte[] bytes       = input.ReadBytes(fileSize);
                                byte[] outputBytes = Rebuild(bytes, offsetBase, subtitles);

                                output.Write(outputBytes.Length);
                                output.Write(outputBytes);
                            }
                        }
        }
Пример #7
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            output.Write(input.ReadBytes(6));
                            var groupCount = input.ReadInt16();
                            output.Write(groupCount);
                            output.Write(input.ReadBytes(4));
                            var groupsOffset = input.ReadInt32();
                            output.Write(groupsOffset);

                            long outputOffset      = input.PeekInt32();
                            var  firstStringOffset = outputOffset;

                            while (input.Position < groupsOffset)
                            {
                                var offset = input.ReadInt32();
                                if (offset > 0 && offset < input.Length)
                                {
                                    outputOffset = WriteSubtitle(output, subtitles, offset, outputOffset);
                                }
                                else
                                {
                                    output.Write(offset);
                                }
                            }

                            output.Write(input.ReadBytes((int)(groupsOffset - (int)input.Position)));

                            for (var i = 0; i < groupCount; i++)
                            {
                                var offsets = new int[_groupSize];
                                for (var j = 0; j < _groupSize; j++)
                                {
                                    offsets[j] = input.ReadInt32();
                                }

                                for (var j = 0; j < 6; j++)
                                {
                                    output.Write(offsets[j]);
                                }

                                outputOffset = WriteSubtitle(output, subtitles, offsets[6], outputOffset);

                                output.Write(offsets[7]);
                            }

                            output.Write(input.ReadBytes((int)(firstStringOffset - input.Position)));
                        }
        }
Пример #8
0
        private byte[] Rebuild(byte[] inputBytes, int offsetBase, IList <Subtitle> subtitles)
        {
            using (var fsInput = new MemoryStream(inputBytes))
                using (var input = new ExtendedBinaryReader(fsInput, customEncoding))
                    using (var fsOutput = new MemoryStream())
                        using (var output = new ExtendedBinaryWriter(fsOutput, customEncoding))
                        {
                            int magic = input.ReadInt32();

                            int count         = 0x08;
                            var searchPattern = new byte[] { 0x00, 0x00, 0x00, 0x08 };
                            if (magic == 0x00100187)
                            {
                                count         = 0x0E;
                                searchPattern = new byte[] { 0x00, 0x00, 0x00, 0x0E };
                            }

                            var patternPos = new List <int>();
                            int pos        = input.FindPattern(searchPattern);
                            while (pos != -1)
                            {
                                patternPos.Add(pos);
                                pos = input.FindPattern(searchPattern);
                            }

                            if (patternPos.Count > 0)
                            {
                                input.Seek(0, SeekOrigin.Begin);
                                output.Write(input.ReadBytes(patternPos[patternPos.Count - 1] + 4));

                                for (int i = 0; i < count; i++)
                                {
                                    output.Write(input.ReadBytes(0x1C));
                                    Subtitle txt = ReadSubtitle(input);

                                    Subtitle sub = subtitles.FirstOrDefault(x => x.Offset == txt.Offset + offsetBase);
                                    output.WriteString(sub != null ? sub.Translation : txt.Text);

                                    txt = ReadSubtitle(input);
                                    sub = subtitles.FirstOrDefault(x => x.Offset == txt.Offset + offsetBase);
                                    output.WriteString(sub != null ? sub.Translation : txt.Text);
                                }

                                output.Write(input.ReadBytes(4));
                                Subtitle subtitle = ReadSubtitle(input);
                                Subtitle sub2     = subtitles.FirstOrDefault(x => x.Offset == subtitle.Offset + offsetBase);
                                output.WriteString(sub2 != null ? sub2.Translation : subtitle.Text);

                                subtitle = ReadSubtitle(input);
                                sub2     = subtitles.FirstOrDefault(x => x.Offset == subtitle.Offset + offsetBase);
                                output.WriteString(sub2 != null ? sub2.Translation : subtitle.Text);
                            }

                            return(fsOutput.ToArray());
                        }
        }
Пример #9
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            var patternPos = new List <int>();
                            var pos        = input.FindPattern(SearchPattern);
                            while (pos != -1)
                            {
                                patternPos.Add(pos);
                                pos = input.FindPattern(SearchPattern);
                            }

                            if (patternPos.Count > 0)
                            {
                                input.Seek(0, SeekOrigin.Begin);
                                output.Write(input.ReadBytes(patternPos[patternPos.Count - 1] + 3));

                                var count = input.ReadByte();
                                output.Write(count);

                                for (var i = 0; i < count; i++)
                                {
                                    output.Write(input.ReadBytes(0x1C));
                                    var txt = ReadSubtitle(input);

                                    var sub = subtitles.FirstOrDefault(x => x.Offset == txt.Offset);
                                    output.WriteString(sub != null ? sub.Translation : txt.Text);

                                    txt = ReadSubtitle(input);
                                    sub = subtitles.FirstOrDefault(x => x.Offset == txt.Offset);
                                    output.WriteString(sub != null ? sub.Translation : txt.Text);
                                }

                                output.Write(input.ReadBytes(4));
                                var subtitle = ReadSubtitle(input);
                                var sub2     = subtitles.FirstOrDefault(x => x.Offset == subtitle.Offset);
                                output.WriteString(sub2 != null ? sub2.Translation : subtitle.Text);

                                subtitle = ReadSubtitle(input);
                                sub2     = subtitles.FirstOrDefault(x => x.Offset == subtitle.Offset);
                                output.WriteString(sub2 != null ? sub2.Translation : subtitle.Text);
                            }
                        }
        }
Пример #10
0
        public static void Extract(string inputPath, string outputFolder)
        {
            Directory.CreateDirectory(outputFolder);
            var logFile = System.IO.Path.Combine(outputFolder, "Extract_Data.tf");

            using (var fs = new FileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var input = new ExtendedBinaryReader(fs, Encoding.UTF8, Endianness.BigEndian))
                    using (var log = new ExtendedBinaryWriter(new FileStream(logFile, FileMode.Create), Encoding.UTF8, Endianness.BigEndian))
                    {
                        var numFiles = input.ReadInt16();
                        log.Write((int)numFiles);

                        log.Write(input.ReadBytes(6));

                        for (var i = 0; i < numFiles; i++)
                        {
                            input.Seek(8 + i * 16, SeekOrigin.Begin);

                            var unknown = input.ReadInt32();
                            log.Write(unknown);

                            var offsetMsg       = input.ReadInt32();
                            var offsetRemainder = input.ReadInt32();

                            log.Write(offsetMsg == 0 ? 0 : 1);
                            log.Write(offsetRemainder == 0 ? 0 : 1);

                            var sizeMsg       = input.ReadInt16();
                            var sizeRemainder = input.ReadInt16();

                            if (offsetMsg > 0)
                            {
                                input.Seek(offsetMsg, SeekOrigin.Begin);
                                var msg = input.ReadBytes(sizeMsg);

                                var msgFile = Path.Combine(outputFolder, $"{i:0000}.msg");
                                File.WriteAllBytes(msgFile, msg);
                            }

                            if (offsetRemainder > 0)
                            {
                                log.Write((int)sizeRemainder);

                                input.Seek(offsetRemainder, SeekOrigin.Begin);
                                var remainder = input.ReadBytes(sizeRemainder);

                                log.Write(remainder);
                            }
                        }
                    }
        }
Пример #11
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            output.Write(input.ReadInt32());
                            var tableEnd = input.ReadInt32();
                            output.Write(tableEnd);
                            output.Write(input.ReadInt32());

                            long outputOffset      = input.PeekInt32();
                            var  firstStringOffset = outputOffset;

                            while (input.Position < tableEnd)
                            {
                                var offset = input.ReadInt32();
                                outputOffset = WriteSubtitle(output, subtitles, offset, outputOffset);
                            }

                            output.Write(input.ReadBytes((int)(firstStringOffset - tableEnd)));
                        }
        }
Пример #12
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new ExtendedBinaryReader(fileStream);

            // Apparently SEGA doesn't even do signature checking (try loading an AR in-game
            // with the first 0xC bytes set to 0, it works just fine), so why should we?
            reader.JumpAhead(0xC);
            Padding = reader.ReadUInt32();

            // Data
            while (fileStream.Position < fileStream.Length)
            {
                reader.Offset = (uint)fileStream.Position;

                uint   dataEndOffset   = reader.ReadUInt32();
                uint   dataLength      = reader.ReadUInt32();
                uint   dataStartOffset = reader.ReadUInt32();
                uint   unknown1        = reader.ReadUInt32();
                uint   unknown2        = reader.ReadUInt32();
                string name            = reader.ReadNullTerminatedString();

                reader.JumpTo(dataStartOffset, false);
                var data = reader.ReadBytes((int)dataLength);
                reader.JumpTo(dataEndOffset, false);

                var file = new ArchiveFile()
                {
                    Name = name,
                    Data = data
                };
                Data.Add(file);
            }
        }
Пример #13
0
        public static Prediction Read(ExtendedBinaryReader reader, Entry[] lut)
        {
            int numBytes = reader.ReadInt32();
            var data     = reader.ReadBytes(numBytes);

            return(new Prediction(data, lut));
        }
Пример #14
0
        protected override IList <Subtitle> GetSubtitles()
        {
            var result   = new List <Subtitle>();
            var module   = ModuleDefMD.Load(Path);
            var usStream = module.USStream;

            using (var ms = new MemoryStream(usStream.CreateReader().ToArray()))
                using (var input = new ExtendedBinaryReader(ms, System.Text.Encoding.Unicode))
                {
                    input.Skip(1);
                    while (input.Position < input.Length)
                    {
                        var offset = input.Position;
                        var length = input.ReadCompressedUInt32();
                        if (length > 0)
                        {
                            var str = System.Text.Encoding.Unicode.GetString(input.ReadBytes((int)length - 1));
                            input.Skip(1);

                            var subtitle = new Subtitle {
                                Text = str, Loaded = str, Translation = str, Offset = offset
                            };
                            subtitle.PropertyChanged += SubtitlePropertyChanged;
                            result.Add(subtitle);
                        }
                    }
                }

            result.Sort();
            LoadChanges(result);

            return(result);
        }
Пример #15
0
        private string ReadInfo(ExtendedBinaryReader br)
        {
            var len   = br.ReadInt32();
            var bytes = br.ReadBytes(len);

            return(Encoding.UTF8.GetString(bytes));
        }
Пример #16
0
        private static object ReadValueArray(Type elementType, ExtendedBinaryReader br)
        {
            int size = br.ReadInt32();

            if (elementType == typeof(byte) || elementType == typeof(Byte))
            {
                return(br.ReadBytes(size));
            }

            var ret = Array.CreateInstance(elementType, size);

            Type valueType = elementType;

            if (elementType.IsEnum)
            {
                valueType = Enum.GetUnderlyingType(elementType);
            }

            for (int i = 0; i < size; i++)
            {
                var element = ReadValueType(valueType, br, noAlign: true);
                if (elementType.IsEnum)
                {
                    element = Enum.ToObject(elementType, element);
                }
                ret.SetValue(element, i);
            }

            return(ret);
        }
Пример #17
0
        private void PreLoad(IChromosome chrom)
        {
            _annotations.Clear();
            _chromosome = chrom;

            (long startLocation, int numBytes, int refMinorCount) = _index.GetFileRange(chrom.Index);
            if (startLocation == -1)
            {
                return;
            }
            _reader.BaseStream.Position = startLocation;
            var buffer = _reader.ReadBytes(numBytes);

            using (var memStream = new MemoryStream(buffer))
                using (var reader = new ExtendedBinaryReader(memStream))
                {
                    for (var i = 0; i < refMinorCount; i++)
                    {
                        var position    = reader.ReadOptInt32();
                        var globalMajor = reader.ReadAsciiString();

                        _annotations[position] = globalMajor;
                    }
                }
        }
Пример #18
0
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding))
                {
                    input.Skip(0x1A0);
                    var length = input.ReadInt32();
                    var sub    = input.ReadBytes(length);
                    var str    = FileEncoding.GetString(sub);

                    var subtitle = new Subtitle
                    {
                        Offset      = 0x1A0,
                        Text        = str,
                        Loaded      = str,
                        Translation = str
                    };

                    subtitle.PropertyChanged += SubtitlePropertyChanged;
                    result.Add(subtitle);
                }

            LoadChanges(result);

            return(result);
        }
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            if (StartOffset > 0)
                            {
                                output.Write(input.ReadBytes(StartOffset));
                            }

                            long outputOffset = StartOffset;

                            while (input.Position < input.Length)
                            {
                                var inputSubtitle = ReadSubtitle(input);
                                outputOffset = WriteSubtitle(output, subtitles, inputSubtitle.Offset, outputOffset);
                            }
                        }
        }
Пример #20
0
        public override object Read(ExtendedBinaryReader reader)
        {
            var ipv4bytes = reader.ReadBytes(4);

            Array.Reverse(ipv4bytes);
            return(new IPAddress(ipv4bytes));
        }
        /// <summary>
        /// checks if the header is good
        /// </summary>
        private static SupplementaryAnnotationHeader GetHeader(ExtendedBinaryReader reader, out long intervalsPosition, string saPath = null)
        {
            // check the header and data version
            var header         = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(SupplementaryAnnotationCommon.DataHeader.Length));
            var dataVersion    = reader.ReadUInt16();
            var schemaVersion  = reader.ReadUInt16();
            var genomeAssembly = (GenomeAssembly)reader.ReadByte();

            if (header != SupplementaryAnnotationCommon.DataHeader || schemaVersion != SupplementaryAnnotationCommon.SchemaVersion)
            {
                throw new UserErrorException($"The header check failed for the supplementary annotation file ({saPath ?? "(resource)"}): ID: exp: {SupplementaryAnnotationCommon.DataHeader} obs: {header}, schema version: exp:{SupplementaryAnnotationCommon.SchemaVersion} obs: {schemaVersion}");
            }

            var creationTimeTicks     = reader.ReadInt64();
            var referenceSequenceName = reader.ReadString();

            // skip over the offsets since they're not currently used
            reader.ReadInt64(); // _dataSourceVersionsOffset
            reader.ReadInt64(); // _dataOffset
            intervalsPosition = reader.ReadInt64();
            reader.ReadInt64(); // _eofOffset

            // load the data source versions
            var numDataSourceVersions = reader.ReadOptInt32();
            var dataSourceVersions    = new List <DataSourceVersion>();

            for (var i = 0; i < numDataSourceVersions; i++)
            {
                dataSourceVersions.Add(DataSourceVersion.Read(reader));
            }

            return(new SupplementaryAnnotationHeader(referenceSequenceName, creationTimeTicks, dataVersion,
                                                     dataSourceVersions, genomeAssembly));
        }
Пример #22
0
        private void ReadIntervalScores(PhylopInterval interval)
        {
            if (interval == null)
            {
                return;
            }

            var filePosition = interval.FilePosition;

            //going to the file location that contains this interval.
            if (filePosition != -1)
            {
                _reader.BaseStream.Position = filePosition;
            }
            else
            {
                return;
            }

            var length           = _reader.ReadInt32();
            var compressedScores = _reader.ReadBytes(length);

            int requiredBufferSize = _qlz.GetDecompressedLength(compressedScores, length);

            if (requiredBufferSize > _scoreBytes.Length)
            {
                _scoreBytes = new byte[requiredBufferSize];
            }

            var uncompressedLength = _qlz.Decompress(compressedScores, length, _scoreBytes, _scoreBytes.Length);

            BytesToScores(uncompressedLength, _scoreBytes, _scores);

            _scoreCount = uncompressedLength / 2;
        }
Пример #23
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.BigEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.BigEndian))
                        {
                            output.Write(input.ReadBytes(16));
                            var count = input.ReadInt32();
                            output.Write(count);

                            for (var i = 0; i < count; i++)
                            {
                                output.Write(input.ReadInt32());

                                var offset = (int)input.Position;
                                WriteSubtitle(output, subtitles, offset);

                                input.Seek(offset + 64, SeekOrigin.Begin);
                            }
                        }
        }
        public static TranscriptConservationScores Read(ExtendedBinaryReader reader)
        {
            var id     = reader.ReadAsciiString();
            var count  = reader.ReadOptInt32();
            var scores = reader.ReadBytes(count);
            var item   = new TranscriptConservationScores(id, scores);

            return(item.IsEmpty() ? null : item);
        }
Пример #25
0
        public static AssetReference Read(ExtendedBinaryReader br)
        {
            string assetPath = br.ReadNullTerminatedString();

            byte[] GUID     = br.ReadBytes(16);
            int    type     = br.ReadInt32();
            string filePath = br.ReadNullTerminatedString();

            return(new AssetReference(assetPath: assetPath, GUID: GUID, type: type, filePath: filePath));
        }
Пример #26
0
        private ShopElement ReadItem(ExtendedBinaryReader input, int offset, int itemLength)
        {
            var returnPos = input.Position;

            input.Seek(offset, SeekOrigin.Begin);
            var id             = input.ReadUInt16();
            var unknown        = input.ReadBytes(0x0C);
            var unknown2Offset = input.ReadUInt16();
            var title          = ReadSubtitle(input);

            var unknown2 = input.ReadBytes(itemLength - (unknown2Offset - offset));

            var item = new ShopElement {
                Id = id, Unknown1 = unknown, Title = title, Unknown2 = unknown2
            };

            input.Seek(returnPos, SeekOrigin.Begin);
            return(item);
        }
Пример #27
0
        // TODO
        protected void LoadShadowArchive(ExtendedBinaryReader reader)
        {
            reader.JumpAhead(0x4);                                 // Unknown, Seems to always be 0
            uint   fileSize   = reader.ReadUInt32();               // File Size - 0xC
            uint   magic      = reader.ReadUInt32();               // Magic
            string ONEVersion = reader.ReadNullTerminatedString(); // Gets the version String

            reader.FixPadding();                                   // Aligns the reader

            uint fileCount = reader.ReadUInt32();                  // File Count

            reader.JumpAhead(0x38 * 2 + 0x20);                     // Jump to the third/first entry
            bool isVersion6     = ONEVersion == "ONE Ver 0.60";    // Checks if its version is 0.60
            int  fileNameLength = isVersion6 ? 0x2C : 0x20;        // The max file name size

            // Read File List
            var files = new FileEntry[FileEntryCount];

            for (int i = 0; i < fileCount; i++)
            {
                var entry = new FileEntry();
                entry.FileName = reader.ReadSignature(
                    fileNameLength).Replace("\0", string.Empty);

                entry.UncompressedSize = reader.ReadUInt32();
                entry.DataOffset       = reader.ReadUInt32();
                reader.JumpAhead(4); // Unknown, Seems to always be 1

                if (!isVersion6)
                {
                    reader.JumpAhead(0xC); // Unknown, Seems to always be 0
                }
                files[i] = entry;
            }

            // Read File Data
            if (files.Length > 0)
            {
                reader.JumpTo(files[0].DataOffset + 0xC);
                for (int i = 0; i < fileCount; ++i)
                {
                    // Compute the file's data length
                    files[i].DataLength = ((i == fileCount - 1) ?
                                           fileSize + 0xC : files[i + 1].DataOffset) - files[i].DataOffset;

                    var file = new ArchiveFile()
                    {
                        Name = files[i].FileName,
                        Data = reader.ReadBytes(
                            (int)files[i].DataLength) // TODO: Decompress file
                    };
                    Data.Add(file);
                }
            }
        }
Пример #28
0
        protected override IList <TF.Core.TranslationEntities.Subtitle> GetSubtitles()
        {
            var temp = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding, Endianness.BigEndian))
                {
                    var currentIndex = input.FindPattern(SearchPattern);

                    while (currentIndex != -1)
                    {
                        input.ReadBytes(12); //0x0C

                        var type = input.ReadUInt64();

                        var subtitles = type == 0 ? ReadLongSubtitles(input) : ReadShortSubtitles(input);

                        if (subtitles != null)
                        {
                            temp.AddRange(subtitles);
                        }

                        currentIndex = input.FindPattern(SearchPattern);
                    }
                }

            var englishSubtitles  = new List <Subtitle>();
            var japaneseSubtitles = new List <Subtitle>();

            foreach (var subtitle in temp)
            {
                switch (subtitle.Language)
                {
                case SubtitleLanguage.English:
                    englishSubtitles.Add(subtitle);
                    break;

                case SubtitleLanguage.Japanese:
                    japaneseSubtitles.Add(subtitle);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var result = new List <TF.Core.TranslationEntities.Subtitle>();

            result.AddRange(englishSubtitles);
            result.AddRange(japaneseSubtitles);

            LoadChanges(result);

            return(result);
        }
Пример #29
0
        private void CreateExeFile(string outputFile)
        {
            var peInfo = WindowsAssembly.FromFile(Path);

            using (var inputFs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(inputFs, FileEncoding, Endianness.LittleEndian))
                    using (var outputFs = new FileStream(outputFile, FileMode.Create))
                    {
                        var output         = new BinaryStreamWriter(outputFs);
                        var writingContext = new WritingContext(peInfo, new BinaryStreamWriter(outputFs));

                        var dosHeader = input.ReadBytes((int)peInfo.NtHeaders.StartOffset);
                        output.WriteBytes(dosHeader);

                        var ntHeader = peInfo.NtHeaders;
                        ntHeader.FileHeader.NumberOfSections++;
                        ntHeader.OptionalHeader.SizeOfImage += 0x00010000;

                        ntHeader.Write(writingContext);

                        var newSection = CreateTFSection(peInfo.SectionHeaders[peInfo.SectionHeaders.Count - 1], ntHeader.OptionalHeader.FileAlignment,
                                                         ntHeader.OptionalHeader.SectionAlignment);
                        peInfo.SectionHeaders.Add(newSection);

                        foreach (var section in peInfo.SectionHeaders)
                        {
                            section.Write(writingContext);
                        }

                        foreach (var section in peInfo.SectionHeaders)
                        {
                            input.Seek(section.PointerToRawData, SeekOrigin.Begin);
                            outputFs.Seek(section.PointerToRawData, SeekOrigin.Begin);

                            var data = input.ReadBytes((int)section.SizeOfRawData);
                            output.WriteBytes(data);
                        }

                        var bytes = new byte[0x00010000];
                        output.WriteBytes(bytes);
                    }
        }
Пример #30
0
        private MsgProperties ReadProperties(ExtendedBinaryReader input, int offset, int count)
        {
            var pos = input.Position;

            input.Seek(offset, SeekOrigin.Begin);
            var data = input.ReadBytes(16 * count);

            input.Seek(pos, SeekOrigin.Begin);

            var result = new MsgProperties(data);

            return(result);
        }
Пример #31
0
 public static FLVTag Parse(ExtendedBinaryReader br)
 {
     var b = br.ReadByte();
     var tag = new FLVTag
     {
         Reserved = (byte)(b & 0xc0),
         Filter = (b & 0x20) == 0,
         TagType = (TagType)(b & 0x1f),
         DataSize = br.ReadUInt24(),
         TimeStamp = br.ReadUInt24(),
         TimestampExtended = br.ReadByte(),
         StreamID = br.ReadUInt24()
     };
     tag.HeaderAndBody = br.ReadBytes((tag.TimestampExtended << 24) + (int)tag.TimeStamp);
     return tag;
 }