Exemplo n.º 1
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);
                            }
                        }
        }
Exemplo n.º 2
0
        public override void Load(ExtendedBinaryReader reader, bool keepOpen = false)
        {
            // Height of the character in pixels
            CharacterHeight = reader.ReadInt32();
            // The amount of characters defined
            int characterCount = reader.ReadInt32();

            // Unknown
            WidthScale  = reader.ReadSingle();
            HeightScale = reader.ReadSingle();

            for (int i = 0; i < characterCount; ++i)
            {
                var fontEntry = new FontEntry
                {
                    Character = ReadReversedUTF8Char(reader),   // The read UTF8 character
                    XScale    = reader.ReadSingle(),            // X position on the texture (Multiply by the textures width to get pixels)
                    YScale    = reader.ReadSingle(),            // Y position on the texture (Multiply by the textures height to get pixels)
                };
                if (!MonospaceOnly)
                {
                    fontEntry.Kerning = reader.ReadInt32();     // -X offset for positioning when rendering
                    fontEntry.Width   = reader.ReadInt32();     // The width of the character in pixels
                }
                else
                {
                    fontEntry.Width = CharacterHeight; // Force square character
                }

                Characters.Add(fontEntry);
            }
        }
Exemplo n.º 3
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, Endianness.BigEndian))
                {
                    input.Skip(16);
                    var count = input.ReadInt32();

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

                        var subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);

                        input.Seek(subtitle.Offset + 64, SeekOrigin.Begin);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 4
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);
                            }
                        }
        }
        protected virtual void LoadChanges(IList <Subtitle> subtitles)
        {
            if (HasChanges)
            {
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //File.Delete(ChangesFile);
                            return;
                        }

                        var subtitleCount = input.ReadInt32();

                        for (var i = 0; i < subtitleCount; i++)
                        {
                            var offset = input.ReadInt64();
                            var text   = input.ReadString();

                            var subtitle = subtitles.FirstOrDefault(x => x.Offset == offset);
                            if (subtitle != null)
                            {
                                subtitle.PropertyChanged -= SubtitlePropertyChanged;
                                subtitle.Translation      = text;
                                subtitle.Loaded           = subtitle.Translation;
                                subtitle.PropertyChanged += SubtitlePropertyChanged;
                            }
                        }
                    }
            }
        }
Exemplo n.º 6
0
        public override void Load(ExtendedBinaryReader reader, bool keepOpen = false)
        {
            string header = reader.ReadNullTerminatedString();

            reader.FixPadding(16);
            uint   textureOffset = reader.ReadUInt32();
            uint   textureCount  = reader.ReadUInt32();
            int    layerOffset   = reader.ReadInt32();
            int    layerCount    = reader.ReadInt32();
            int    unknownOffset = reader.ReadInt32();
            int    unknownCount  = reader.ReadInt32();
            uint   unknown28     = reader.ReadUInt32();
            uint   unknown2C     = reader.ReadUInt32();
            string projectDir    = reader.ReadStringElsewhere();
            uint   unknown34     = reader.ReadUInt32();
            uint   unknown38     = reader.ReadUInt32();
            uint   unknown3C     = reader.ReadUInt32();

            reader.JumpTo(textureOffset);
            for (int i = 0; i < textureCount; ++i)
            {
                Textures.Add(new MATexture(reader));
            }

            reader.JumpTo(layerOffset);
            for (int i = 0; i < layerCount; ++i)
            {
                Layers.Add(new MALayer(reader));
            }
        }
Exemplo n.º 7
0
            public override Instruction Read(ExtendedBinaryReader reader)
            {
                var    instruction = new InstructionSwitch(Name, ArgTypes);
                uint   unknown     = reader.ReadUInt32();
                ushort amount      = reader.ReadUInt16();
                bool   endFlag     = amount >> 15 == 1;

                if (endFlag)
                {
                    amount &= 0x7FF;
                }

                instruction.ArgTypes    = new ArgumentType[amount * 2 + 3];
                instruction.ArgTypes[0] = AT_DataReference;
                instruction.Arguments.Add(unknown);
                instruction.ArgTypes[1] = AT_Int16;
                instruction.Arguments.Add(amount);
                instruction.ArgTypes[2] = AT_Bool;
                instruction.Arguments.Add(endFlag);
                for (int i = 0; i < amount; ++i)
                {
                    // case
                    instruction.ArgTypes[i * 2 + 3 + 0] = AT_Int32;
                    instruction.Arguments.Add(reader.ReadInt32());
                    // location
                    instruction.ArgTypes[i * 2 + 3 + 1] = AT_CodePointer;
                    instruction.Arguments.Add(reader.ReadInt32());
                }
                return(instruction);
            }
Exemplo n.º 8
0
        private void LoadPatchesChanges(IList <ExePatch> data)
        {
            if (HasChanges)
            {
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //System.IO.File.Delete(ChangesFile);
                            return;
                        }

                        input.Skip(256 * 6 * 4);

                        foreach (var patch in data)
                        {
                            var value = input.ReadInt32();
                            patch.Enabled = value == 1;
                        }
                    }
            }
        }
Exemplo n.º 9
0
        private static IDictionary <int, SizeF[]> ReadBoxSizes(string path)
        {
            var result = new Dictionary <int, SizeF[]>();
            var file   = System.IO.Path.Combine(path, "resources_00001.-13");

            using (var fs = new FileStream(file, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs))
                {
                    input.BaseStream.Seek(0x150, SeekOrigin.Begin);

                    var heightCount = input.ReadInt32();
                    for (var i = 0; i < heightCount; i++)
                    {
                        var nameLength = input.ReadInt32();
                        var name       = input.ReadString();
                        var msgEnum    = input.ReadInt32();
                        var langCount  = input.ReadInt32();

                        var sizes = new SizeF[langCount];
                        for (var j = 0; j < langCount; j++)
                        {
                            var sz = new SizeF(input.ReadSingle(), input.ReadSingle());
                            sizes[j] = sz;
                        }

                        result.Add(msgEnum, sizes);
                    }
                }

            return(result);
        }
Exemplo n.º 10
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)));
                        }
        }
Exemplo n.º 11
0
        protected override void LoadChanges(IList <Subtitle> subtitles)
        {
            if (HasChanges)
            {
                var subs = subtitles.Select(subtitle => subtitle as UnderRailSubtitle).ToList();
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, System.Text.Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //File.Delete(ChangesFile);
                            return;
                        }

                        var subtitleCount = input.ReadInt32();

                        for (var i = 0; i < subtitleCount; i++)
                        {
                            var id   = input.ReadString();
                            var text = input.ReadString();

                            var subtitle = subs.FirstOrDefault(x => x.Id == id);
                            if (subtitle != null)
                            {
                                subtitle.PropertyChanged -= SubtitlePropertyChanged;
                                subtitle.Translation      = text;
                                subtitle.Loaded           = subtitle.Translation;
                                subtitle.PropertyChanged += SubtitlePropertyChanged;
                            }
                        }
                    }
            }
        }
Exemplo n.º 12
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, Endianness.BigEndian))
                {
                    var count1 = input.ReadInt32();
                    input.Skip(4);

                    for (var i = 0; i < count1; i++)
                    {
                        var count2    = input.ReadInt32();
                        var offset1   = input.ReadInt32();
                        var returnPos = input.Position;
                        input.Seek(offset1, SeekOrigin.Begin);
                        for (var j = 0; j < count2; j++)
                        {
                            var subtitle = ReadSubtitle(input);
                            subtitle.PropertyChanged += SubtitlePropertyChanged;
                            if (subtitle.Offset > 0)
                            {
                                result.Add(subtitle);
                            }
                        }
                        input.Seek(returnPos, SeekOrigin.Begin);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 13
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)));
                        }
        }
Exemplo n.º 14
0
 public void Load(ExtendedBinaryReader reader)
 {
     TextureFullPath = reader.ReadSignature(0x200).Trim('\0');
     TextureFileName = reader.ReadSignature(0x080).Trim('\0');
     TextureWidth    = reader.ReadInt32();
     TextureHeight   = reader.ReadInt32();
     reader.JumpAhead(0x84); // Unknown
 }
Exemplo n.º 15
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(0x0C);

                    int termCount = input.ReadInt32();

                    for (int termIndex = 0; termIndex < termCount; termIndex++)
                    {
                        string term     = input.ReadStringSerialized(0x04);
                        int    termType = input.ReadInt32();

                        string description = input.ReadStringSerialized(0x04);

                        int languageCount = input.ReadInt32();

                        for (int i = 0; i < languageCount; i++)
                        {
                            string sub = input.ReadStringSerialized(0x04);

                            if (i == LanguageIndex && !string.IsNullOrEmpty(sub))
                            {
                                var subtitle = new SubtitleWithId
                                {
                                    Id          = term,
                                    Offset      = 0,
                                    Text        = sub,
                                    Loaded      = sub,
                                    Translation = sub
                                };

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

                        int flagCount = input.ReadInt32();
                        input.Skip(flagCount);
                        input.SkipPadding(0x04);

                        int languageTouchCount = input.ReadInt32();
                        for (int i = 0; i < languageTouchCount; i++)
                        {
                            input.ReadStringSerialized(0x04);
                        }
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 16
0
        private void CheckHeaderVersion()
        {
            string headerTag     = _reader.ReadString();
            int    headerVersion = _reader.ReadInt32();

            if (headerTag != ReferenceSequenceCommon.HeaderTag || headerVersion != ReferenceSequenceCommon.HeaderVersion)
            {
                throw new InvalidFileFormatException($"The header identifiers do not match the expected values: Obs: {headerTag} {headerVersion} vs Exp: {ReferenceSequenceCommon.HeaderTag} {ReferenceSequenceCommon.HeaderVersion}");
            }
        }
Exemplo n.º 17
0
        protected override IList <TF.Core.TranslationEntities.Subtitle> GetSubtitles()
        {
            var result = new List <TF.Core.TranslationEntities.Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding, Endianness.BigEndian))
                {
                    input.Skip(3);
                    var count = input.ReadByte();
                    input.Skip(4);
                    var pointer1      = input.ReadInt32();
                    var countPointer1 = input.ReadInt16();

                    var numTalkers       = input.ReadInt16();
                    var pointerTalkers   = input.ReadInt32();
                    var pointerRemainder = input.ReadInt32();

                    for (var i = 0; i < count; i++)
                    {
                        input.Skip(4);
                        var groupOffset = input.ReadInt32();
                        input.Skip(1);
                        var stringCount = input.ReadByte();
                        input.Skip(6);

                        var subs = ReadSubtitles(input, groupOffset, stringCount);

                        if (subs.Count > 0)
                        {
                            result.AddRange(subs);
                        }
                    }

                    if (pointerTalkers > 0 && result.Count > 0)
                    {
                        input.Seek(pointerTalkers, SeekOrigin.Begin);
                        for (var i = 0; i < numTalkers; i++)
                        {
                            var offset   = input.ReadInt32();
                            var subtitle = ReadSubtitle(input, offset, true);
                            if (subtitle != null)
                            {
                                subtitle.PropertyChanged += SubtitlePropertyChanged;
                                result.Add(subtitle);
                            }
                        }
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 18
0
        private IList <Subtitle> ReadShortSubtitles(ExtendedBinaryReader input)
        {
            var result = new List <Subtitle>();

            input.Skip(266); //0x010A

            var numSubs = input.ReadInt32();

            input.Skip(28);

            if (numSubs > 0x1000)
            {
                // Probablemente el fichero no sea un cmn.bin
                return(null);
            }

            for (var i = 0; i < numSubs; i++)
            {
                input.Skip(16); //0x10

                var subtitle = ReadSubtitle(input, 128);

                /*subtitle.Language = SubtitleLanguage.Japanese;
                 * if (subtitle.Text.Length > 0)
                 * {
                 *  result.Add(subtitle);
                 * }*/
            }

            if (numSubs > 0x1000)
            {
                // Probablemente el fichero no sea un cmn.bin
                return(null);
            }

            numSubs = input.ReadInt32();
            input.Skip(28); //0x0C

            for (var i = 0; i < numSubs; i++)
            {
                input.Skip(16); //0x10

                var subtitle = ReadSubtitle(input, 128);
                subtitle.Language = SubtitleLanguage.English;
                if (subtitle.Text.Length > 0)
                {
                    result.Add(subtitle);
                }
            }

            return(result);
        }
Exemplo n.º 19
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, Endianness.BigEndian))
                {
                    input.Skip(6);
                    var groupCount = input.ReadInt16();
                    input.Skip(4);
                    var groupsOffset = input.ReadInt32();

                    Subtitle subtitle;

                    while (input.Position < groupsOffset)
                    {
                        var subtitleOffset = input.ReadInt32();

                        if (subtitleOffset > 0 && subtitleOffset < input.Length)
                        {
                            input.Seek(-4, SeekOrigin.Current);
                            subtitle = ReadSubtitle(input);
                            subtitle.PropertyChanged += SubtitlePropertyChanged;
                            result.Add(subtitle);
                        }
                    }

                    input.Seek(groupsOffset, SeekOrigin.Begin);

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

                        var returnPos = input.Position;

                        subtitle = ReadSubtitle(input, offsets[6], false);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);

                        input.Seek(returnPos, SeekOrigin.Begin);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 20
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);
                            }
                        }
                    }
        }
            // Methods
            public void Read(ExtendedBinaryReader reader)
            {
                NameOffset         = reader.ReadInt64();
                DataOffset         = reader.ReadInt64();
                ChildIDTableOffset = reader.ReadInt64();

                ParentIndex = reader.ReadInt32();
                GlobalIndex = reader.ReadInt32();
                DataIndex   = reader.ReadInt32();

                ChildCount   = reader.ReadUInt16();
                HasData      = reader.ReadBoolean();
                FullPathSize = reader.ReadByte();  // Not counting this node in.
            }
Exemplo n.º 22
0
        private static object ReadValueType(Type valueType, ExtendedBinaryReader br, bool noAlign = false)
        {
            if (!noAlign)
            {
                br.AlignStream();
            }

            if (valueType == typeof(string))
            {
                return(br.ReadAlignedString());
            }
            else if (valueType == typeof(Int32))
            {
                return(br.ReadInt32());
            }
            else if (valueType == typeof(UInt32))
            {
                return(br.ReadUInt32());
            }
            else if (valueType == typeof(Int64))
            {
                return(br.ReadInt64());
            }
            else if (valueType == typeof(UInt64))
            {
                return(br.ReadUInt64());
            }
            else if (valueType == typeof(Int16))
            {
                return(br.ReadInt16());
            }
            else if (valueType == typeof(UInt16))
            {
                return(br.ReadUInt16());
            }
            else if (valueType == typeof(Byte))
            {
                return(br.ReadByte());
            }
            else if (valueType == typeof(SByte))
            {
                return(br.ReadSByte());
            }
            else if (valueType == typeof(Boolean))
            {
                return(br.ReadBoolean());
            }
            else if (valueType == typeof(Double))
            {
                return(br.ReadDouble());
            }
            else if (valueType == typeof(Single))
            {
                return(br.ReadSingle());
            }
            else
            {
                throw new ArgumentException($"{valueType} is not a value type");
            }
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        private Array ReadArray(Type elementType, ExtendedBinaryReader br)
        {
            int size = br.ReadInt32();

            if (size > 0x40000)
            {
                throw new IOException("Size exceeds limit : " + size);
            }

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

            if (elementType == typeof(string))
            {
                for (int i = 0; i < size; i++)
                {
                    valueArray.SetValue(br.ReadAlignedString(), i);
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    valueArray.SetValue(Deserialize(elementType, br), i);
                }
            }

            return(valueArray);
        }
Exemplo n.º 25
0
            public virtual Instruction Read(ExtendedBinaryReader reader)
            {
                var instruction = new Instruction(Name, ArgTypes);

                if (ArgTypes == null)
                {
                    return(instruction);
                }
                for (int i = 0; i < ArgTypes.Length; ++i)
                {
                    if (ArgTypes[i] == AT_PointerArray)
                    {
                        int[] pointers = new int[reader.ReadByte()];
                        for (int i2 = 0; i2 < pointers.Length; ++i2)
                        {
                            pointers[i] = reader.ReadInt32();
                        }
                        Arguments.Add(pointers);
                    }
                    else
                    {
                        instruction.Arguments.Add(ReadByType(reader, ArgTypes[i]));
                    }
                }

                return(instruction);
            }
Exemplo n.º 26
0
        private void LoadFontTableChanges(CharacterInfo[] data)
        {
            if (HasChanges)
            {
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //System.IO.File.Delete(ChangesFile);
                            return;
                        }

                        for (var i = 0; i < 256; i++)
                        {
                            data[i][0] = input.ReadSingle();
                            data[i][1] = input.ReadSingle();
                            data[i][2] = input.ReadSingle();
                            data[i][3] = input.ReadSingle();
                            data[i][4] = input.ReadSingle();
                            data[i][5] = input.ReadSingle();
                        }
                    }
            }
        }
Exemplo n.º 27
0
        private static (IDataSourceVersion, GenomeAssembly, string, ReportFor, int) ReadHeader(Stream stream)
        {
            using (var reader = new ExtendedBinaryReader(stream, Encoding.UTF8, true))
            {
                var identifier = reader.ReadAsciiString();
                if (identifier != SaCommon.NsiIdentifier)
                {
                    throw new InvalidDataException($"Failed to find identifier!!Expected: {SaCommon.NsiIdentifier}, observed:{identifier}");
                }

                var version       = DataSourceVersion.Read(reader);
                var assembly      = (GenomeAssembly)reader.ReadByte();
                var jsonKey       = reader.ReadAsciiString();
                var reportFor     = (ReportFor)reader.ReadByte();
                int schemaVersion = reader.ReadInt32();

                var guard = reader.ReadUInt32();
                if (guard != SaCommon.GuardInt)
                {
                    throw new InvalidDataException($"Failed to find guard int!!Expected: {SaCommon.GuardInt}, observed:{guard}");
                }

                return(version, assembly, jsonKey, reportFor, schemaVersion);
            }
        }
        public IEnumerable <ISupplementaryInterval> GetSupplementaryIntervals(IChromosomeRenamer renamer)
        {
            if (_intervalsPosition == -1)
            {
                return(null);
            }
            var returnPosition = _stream.Position;

            _stream.Position = _intervalsPosition;

            var count = _reader.ReadInt32(); // how many supplementary intervals to read

            if (count == 0)
            {
                return(null);
            }

            var intervalList = new List <SupplementaryInterval>(count);

            for (var i = 0; i < count; i++)
            {
                intervalList.Add(SupplementaryInterval.Read(_reader, renamer));
            }

            _stream.Position = returnPosition;

            return(intervalList);
        }
Exemplo n.º 29
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))
                        {
                            // Material
                            output.Write(input.ReadBytes(0x04));
                            output.Write(input.ReadBytes(0x08));

                            // ColorRGBA
                            output.Write(input.ReadBytes(4 * 0x04));

                            // RaycastTarget
                            output.Write(input.ReadBytes(0x04));

                            // CullStateChangedEvent
                            int persistentCallCount = input.ReadInt32();
                            output.Write(persistentCallCount);
                            for (int i = 0; i < persistentCallCount; i++)
                            {
                                // PersistentCall
                            }

                            // FontData
                            output.Write(input.ReadBytes(0x04));
                            output.Write(input.ReadBytes(0x08));
                            output.Write(input.ReadBytes(0x04)); // FOnt size
                            output.Write(input.ReadBytes(0x04)); // Font style
                            input.ReadBytes(0x04);
                            output.Write(0x00000001);            // Best Fit
                            output.Write(input.ReadBytes(0x04)); // Min size
                            output.Write(input.ReadBytes(0x04)); // Max size
                            output.Write(input.ReadBytes(0x04)); // Alignment
                            output.Write(input.ReadBytes(0x04)); // Align by geometry
                            output.Write(input.ReadBytes(0x04)); // Rich Text
                            output.Write(input.ReadBytes(0x04)); // Horizontal Overflow
                            output.Write(input.ReadBytes(0x04)); // Vertical Overflow
                            output.Write(input.ReadBytes(0x04)); // Line spacing

                            string sub = input.ReadStringSerialized(0x04);

                            output.WriteStringSerialized(
                                dictionary.TryGetValue(sub, out SubtitleWithId subtitle) ? subtitle.Translation : sub, 0x04);
                        }
        }
Exemplo n.º 30
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, Endianness.BigEndian))
                {
                    input.Skip(0x38);
                    var stringsOffset = input.ReadInt32();

                    input.Seek(stringsOffset, SeekOrigin.Begin);

                    Subtitle subtitle;

                    while (input.Position < input.Length)
                    {
                        subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);
                    }
                }

            LoadChanges(result);

            return(result);
        }