Inheritance: BinaryWriter
コード例 #1
0
ファイル: _50TRPage.cs プロジェクト: Razer2015/GT.RText
        public override void Write(EndianBinWriter writer, int baseOffset, int baseDataOffset)
        {
            writer.BaseStream.Position = baseDataOffset;
            int baseNameOffset = (int)writer.BaseStream.Position;

            writer.WriteNullTerminatedString(Name, 0x04);
            int pairUnitOffset = (int)writer.BaseStream.Position;

            // Proceed to write the string tree, skip the entry map for now
            writer.BaseStream.Position += EntrySize * PairUnits.Count;
            int lastStringPos = (int)writer.BaseStream.Position;


            // Setup for binary searching - strings are sorted by length, then their encrypted values
            // Override the sorting logic - couldn't find a better way to structure this to make it work across all versions
            // Not the most efficient
            var orderedPairs = PairUnits.Values.OrderBy(
                e => Encrypt(Encoding.UTF8.GetBytes(e.Label), Constants.KEY.AlignString(0x20)),
                ByteBufferComparer.Default);

            // Write our strings
            int j = 0;

            foreach (var pair in orderedPairs)
            {
                writer.BaseStream.Position = lastStringPos;

                int labelOffset = (int)writer.BaseStream.Position;
                var encLabel    = Encrypt(Encoding.UTF8.GetBytes(pair.Label), Constants.KEY.AlignString(0x20));
                writer.WriteAligned(encLabel, 4, nullTerminate: true);

                int valueOffset = (int)writer.BaseStream.Position;
                var encValue    = Encrypt(Encoding.UTF8.GetBytes(pair.Value), Constants.KEY.AlignString(0x20));
                writer.WriteAligned(encValue, 4, nullTerminate: true);

                lastStringPos = (int)writer.BaseStream.Position;

                // Write the offsets
                writer.BaseStream.Position = pairUnitOffset + (j * EntrySize);
                writer.Write(pair.ID);
                writer.Write((ushort)(pair.Label.Length + 1));
                writer.Write((ushort)(pair.Value.Length + 1));
                writer.Write(labelOffset);
                writer.Write(valueOffset);

                j++;
            }

            // Finish page toc entry
            writer.BaseStream.Position = baseOffset;
            writer.Write(baseNameOffset);
            writer.Write(PairUnits.Count);
            writer.Write(0); // Unk
            writer.Write(pairUnitOffset);

            // Seek to the end of it
            writer.BaseStream.Position = writer.BaseStream.Length;
        }
コード例 #2
0
ファイル: RT04Header.cs プロジェクト: Razer2015/GT.RText
        public void Save(EndianBinWriter writer)
        {
            var magicBytes = BitConverter.GetBytes(Magic);

            Array.Reverse(magicBytes);
            writer.Write(magicBytes);
            writer.Write(Padding);
            writer.Write(EntryCount);
        }
コード例 #3
0
ファイル: RT05Header.cs プロジェクト: Razer2015/GT.RText
 public void Save(EndianBinWriter writer)
 {
     writer.Write(Magic);
     writer.Write(EntryCount);
     writer.Write(Obfuscated);
     writer.Write(new byte[] { 0x00, 0x00, 0x00 });
     writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
     writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
     writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
     writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
     writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
 }
コード例 #4
0
ファイル: _50TRHeader.cs プロジェクト: Razer2015/GT.RText
        public void Save(EndianBinWriter writer)
        {
            var magicBytes = BitConverter.GetBytes(Magic);

            Array.Reverse(magicBytes);
            writer.Write(magicBytes);
            writer.Write(EntryCount);
            writer.Write(Obfuscated);
            writer.Write(new byte[] { 0x00, 0x00, 0x00 });
            writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
            writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
            writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
            writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
            writer.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 });
        }
コード例 #5
0
ファイル: Util.cs プロジェクト: Razer2015/PDIPFSWatcher
 public static void PackTwelveBits(EndianBinWriter writer, uint ptr_data, uint offset)
 {
     writer.BaseStream.Seek((int)((offset * 16 - offset * 4) / 8), SeekOrigin.Begin);
     if ((offset & 0x1) == 0)
     {
         ptr_data *= 16;
         writer.Write((ushort)(ptr_data));
     }
     else
     {
         int val = writer.BaseStream.ReadByte();
         writer.BaseStream.Position -= 1;
         val = val << 8;
         writer.Write((ushort)(ptr_data + val));
     }
 }
コード例 #6
0
ファイル: Util.cs プロジェクト: Razer2015/PDIPFSWatcher
        public static void PackValueAndAdvance(EndianBinWriter writer, uint in_value)
        {
            uint mask = 0x80;

            byte[] buffer = new byte[0];
            if (in_value <= 0x7F)
            {
                byte value = (byte)in_value;
                writer.Write(value);
                return;
            }
            else if (in_value <= 0x3FFF)
            {
                ushort value = (ushort)in_value;
                byte[] temp  = BitConverter.GetBytes(in_value).Reverse().ToArray();
                buffer = new byte[] { temp[2], temp[3] };
            }
            else if (in_value <= 0x1FFFFF)
            {
                uint   value = in_value;
                byte[] temp  = BitConverter.GetBytes(in_value).Reverse().ToArray();
                buffer = new byte[] { temp[1], temp[2], temp[3] };
            }
            else if (in_value <= 0xFFFFFFF)
            {
                uint value = in_value;
                buffer = BitConverter.GetBytes(in_value).Reverse().ToArray();
            }
            else if (in_value <= 0xFFFFFFFF)
            {
                uint   value = in_value;
                byte[] temp  = BitConverter.GetBytes(in_value).Reverse().ToArray();
                buffer = new byte[] { 0x00, temp[0], temp[1], temp[2], temp[3] };
            }
            else
            {
                throw new Exception("Somethings wrong with the pack_value_and_advance - function");
            }

            for (int i = 1; i < buffer.Length; i++)
            {
                buffer[0] += (byte)mask;
                mask       = mask >> 1;
            }

            writer.Write(buffer);
        }
コード例 #7
0
        public override void Write(EndianBinWriter writer, int baseOffset, int baseDataOffset)
        {
            writer.BaseStream.Position = baseDataOffset;
            int baseNameOffset = (int)writer.BaseStream.Position;

            writer.WriteNullTerminatedString(Name, 0x04);
            int pairUnitOffset = (int)writer.BaseStream.Position;

            // Proceed to write the string tree, skip the entry map for now
            writer.BaseStream.Position += EntrySize * PairUnits.Count;
            int lastStringPos = (int)writer.BaseStream.Position;

            // Write our strings
            int j = 0;

            foreach (var pair in PairUnits)
            {
                writer.BaseStream.Position = lastStringPos;

                int labelOffset = (int)writer.BaseStream.Position;
                writer.WriteNullTerminatedString(pair.Value.Label, 4);

                int valueOffset = (int)writer.BaseStream.Position;
                writer.WriteNullTerminatedString(pair.Value.Value, 4);

                lastStringPos = (int)writer.BaseStream.Position;

                // Write the offsets
                writer.BaseStream.Position = pairUnitOffset + (j * RT04Page.EntrySize);
                writer.Write(pair.Value.ID);
                writer.Write(labelOffset);
                writer.Write(valueOffset);

                j++;
            }

            // Finish page toc entry
            writer.BaseStream.Position = baseOffset;
            writer.Write(baseNameOffset);
            writer.Write(PairUnits.Count);
            writer.Write(pairUnitOffset);
            writer.Write(0x5E5E5E5E); // Padding

            // Seek to the end of it
            writer.BaseStream.Position = writer.BaseStream.Length;
        }
コード例 #8
0
ファイル: _50TR.cs プロジェクト: Razer2015/GT.RText
        public override void Save(string fileName)
        {
            using (var ms = new FileStream(fileName, FileMode.Create))
                using (var bs = new EndianBinWriter(ms, EndianType.LITTLE_ENDIAN))
                {
                    bs.Write(Encoding.ASCII.GetBytes(Magic));
                    bs.Write(_pages.Count);
                    bs.Write((byte)1); // "Obfuscated", we don't know, eboot doesn't read it
                    bs.BaseStream.Position = HeaderSize;

                    int i           = 0;
                    int baseDataPos = HeaderSize + (_pages.Count * 0x10);
                    foreach (var pagePair in _pages)
                    {
                        int baseEntryOffset = (int)HeaderSize + (i * 0x10);
                        pagePair.Value.Write(bs, baseEntryOffset, baseDataPos);
                        baseDataPos = (int)ms.Position;
                        i++;
                    }
                }
        }
コード例 #9
0
 public void Write(EndianBinWriter writer)
 {
     writer.Write(Text);
 }
コード例 #10
0
ファイル: RTextPageBase.cs プロジェクト: Razer2015/GT.RText
 public abstract void Write(EndianBinWriter writer, int baseOffset, int baseDataOffset);
コード例 #11
0
 public void Save(EndianBinWriter writer)
 {
     throw new NotImplementedException();
 }