Exemplo n.º 1
0
        /// <summary>
        /// Writes BND0 data to a BinaryWriterEx.
        /// </summary>
        internal override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = false;
            bw.WriteASCII("BND\0");

            if (Lite)
            {
                bw.ReserveInt32("FileSize");
                bw.WriteInt32(Files.Count);
                bw.WriteInt32(0);
            }
            else
            {
                bw.WriteInt32(0xF7FF);
                bw.WriteInt32(0xD3);
                bw.ReserveInt32("FileSize");
                bw.WriteInt32(Files.Count);
                bw.WriteInt32(0);

                bw.WriteByte(Flag1);
                bw.WriteByte(Flag2);
                bw.WriteByte(3);
                bw.WriteByte(0);

                bw.WriteInt32(0);
                bw.WriteInt32(0);
            }

            for (int i = 0; i < Files.Count; i++)
            {
                Files[i].Write(bw, Lite, i);
            }

            for (int i = 0; i < Files.Count; i++)
            {
                File file = Files[i];
                bw.Pad(0x20);

                bw.FillInt32($"FileOffset{i}", (int)bw.Position);
                if (Lite)
                {
                    bw.WriteInt32(file.Bytes.Length + 4);
                    bw.WriteBytes(file.Bytes);
                }
                else
                {
                    bw.WriteBytes(file.Bytes);
                }
            }

            bw.FillInt32("FileSize", (int)bw.Position);
        }
Exemplo n.º 2
0
                internal void WriteValue(BinaryWriterEx bw, object value)
                {
                    switch (Type)
                    {
                    case ParamType.aob: bw.WriteBytes((byte[])value); break;

                    case ParamType.b: bw.WriteBoolean((bool)value); break;

                    case ParamType.u8:
                    case ParamType.x8: bw.WriteByte((byte)value); break;

                    case ParamType.s8: bw.WriteSByte((sbyte)value); break;

                    case ParamType.u16:
                    case ParamType.x16: bw.WriteUInt16((ushort)value); break;

                    case ParamType.s16: bw.WriteInt16((short)value); break;

                    case ParamType.u32:
                    case ParamType.x32: bw.WriteUInt32((uint)value); break;

                    case ParamType.s32: bw.WriteInt32((int)value); break;

                    case ParamType.u64:
                    case ParamType.x64: bw.WriteUInt64((ulong)value); break;

                    case ParamType.s64: bw.WriteInt64((long)value); break;

                    case ParamType.f32: bw.WriteSingle((float)value); break;

                    case ParamType.f64: bw.WriteDouble((double)value); break;

                    default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}");
                    }
                }
Exemplo n.º 3
0
        private static void CompressDCXKRAK(byte[] data, BinaryWriterEx bw)
        {
            byte[] compressed = Oodle26.Compress(data, Oodle26.OodleLZ_Compressor.OodleLZ_Compressor_Kraken, Oodle26.OodleLZ_CompressionLevel.OodleLZ_CompressionLevel_Optimal2);

            bw.WriteASCII("DCX\0");
            bw.WriteInt32(0x11000);
            bw.WriteInt32(0x18);
            bw.WriteInt32(0x24);
            bw.WriteInt32(0x44);
            bw.WriteInt32(0x4C);
            bw.WriteASCII("DCS\0");
            bw.WriteUInt32((uint)data.Length);
            bw.WriteUInt32((uint)compressed.Length);
            bw.WriteASCII("DCP\0");
            bw.WriteASCII("KRAK");
            bw.WriteInt32(0x20);
            bw.WriteInt32(0x6000000);
            bw.WriteInt32(0);
            bw.WriteInt32(0);
            bw.WriteInt32(0);
            bw.WriteInt32(0x10100);
            bw.WriteASCII("DCA\0");
            bw.WriteInt32(8);
            bw.WriteBytes(compressed);
            bw.Pad(0x10);
        }
Exemplo n.º 4
0
 private protected override void WriteTypeData(BinaryWriterEx bw)
 {
     bw.WriteInt32(CollisionIndex);
     bw.WriteBytes(MapID);
     bw.WriteInt32(0);
     bw.WriteInt32(0);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Write a DDS file from this header object and given pixel data.
        /// </summary>
        public byte[] Write(byte[] pixelData)
        {
            var bw = new BinaryWriterEx(false);

            bw.WriteASCII("DDS ");
            bw.WriteInt32(0x7C);
            bw.WriteUInt32((uint)dwFlags);
            bw.WriteInt32(dwHeight);
            bw.WriteInt32(dwWidth);
            bw.WriteInt32(dwPitchOrLinearSize);
            bw.WriteInt32(dwDepth);
            bw.WriteInt32(dwMipMapCount);
            bw.WriteInt32s(dwReserved1);
            ddspf.Write(bw);
            bw.WriteUInt32((uint)dwCaps);
            bw.WriteUInt32((uint)dwCaps2);
            bw.WriteInt32(dwCaps3);
            bw.WriteInt32(dwCaps4);
            bw.WriteInt32(dwReserved2);

            if (ddspf.dwFourCC == "DX10")
            {
                header10.Write(bw);
            }

            bw.WriteBytes(pixelData);
            return(bw.FinishBytes());
        }
Exemplo n.º 6
0
 private static void WriteMarkedString(BinaryWriterEx bw, byte marker, string str)
 {
     byte[] bytes = SFEncoding.ShiftJIS.GetBytes(str);
     bw.WriteInt32(bytes.Length);
     bw.WriteBytes(bytes);
     WriteMarker(bw, marker);
 }
Exemplo n.º 7
0
        private void Write(BinaryWriterEx bhdWriter, BinaryWriterEx bdtWriter)
        {
            BHD.Write(bhdWriter, Files);

            for (int i = 0; i < Files.Count; i++)
            {
                File file = Files[i];
                bdtWriter.Pad(0x10);

                byte[] bytes = file.Bytes;
                if (file.Flags == 0x03 || file.Flags == 0xC0)
                {
                    bytes = DCX.Compress(bytes, DCX.Type.DarkSouls1);
                }

                if (BHD.Format == 0x3E)
                {
                    bhdWriter.FillUInt64($"FileOffset{i}", (ulong)bdtWriter.Position);
                }
                else
                {
                    bhdWriter.FillUInt32($"FileOffset{i}", (uint)bdtWriter.Position);
                }

                bhdWriter.FillInt64($"FileSize{i}", bytes.LongLength);
                bdtWriter.WriteBytes(bytes);
            }
        }
Exemplo n.º 8
0
 internal override void Write(BinaryWriterEx bw, int id)
 {
     base.Write(bw, id);
     bw.WriteInt32(CollisionIndex);
     bw.WriteBytes(MapID);
     bw.WriteInt32(0);
     bw.WriteInt32(0);
 }
Exemplo n.º 9
0
 internal void WriteBytecode(BinaryWriterEx bw, bool longFormat, int index, long dataStart)
 {
     for (int i = 0; i < Arguments.Count; i++)
     {
         FillVarint(bw, longFormat, $"Command{index}-{i}:BytecodeOffset", bw.Position - dataStart);
         bw.WriteBytes(Arguments[i]);
     }
 }
Exemplo n.º 10
0
            internal void WriteValues(BinaryWriterEx bw, int groupIndex, int paramIndex, int valuesOffset)
            {
                bw.FillInt32($"ValuesOffset{groupIndex}:{paramIndex}", (int)bw.Position - valuesOffset);
                for (int i = 0; i < Values.Count; i++)
                {
                    object value = Values[i];
                    switch (Type)
                    {
                    case ParamType.Byte:
                        bw.WriteInt32((byte)value);
                        break;

                    case ParamType.Short:
                        bw.WriteInt16((short)value);
                        break;

                    case ParamType.IntA:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.BoolA:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.IntB:
                        bw.WriteInt32((int)value);
                        break;

                    case ParamType.Float:
                        bw.WriteSingle((float)value);
                        break;

                    case ParamType.BoolB:
                        bw.WriteBoolean((bool)value);
                        break;

                    case ParamType.Float2:
                        bw.WriteVector2((Vector2)value);
                        bw.WriteInt32(0);
                        bw.WriteInt32(0);
                        break;

                    case ParamType.Float3:
                        bw.WriteVector3((Vector3)value);
                        bw.WriteInt32(0);
                        break;

                    case ParamType.Float4:
                        bw.WriteVector4((Vector4)value);
                        break;

                    case ParamType.Byte4:
                        bw.WriteBytes((byte[])value);
                        break;
                    }
                }
                bw.Pad(4);
            }
Exemplo n.º 11
0
        /// <summary>
        /// Writes TPF data to a BinaryWriterEx.
        /// </summary>
        internal override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = false;
            bw.WriteASCII("TPF\0");
            bw.ReserveInt32("DataSize");
            bw.WriteInt32(Textures.Count);
            bw.WriteByte((byte)Platform);
            bw.WriteByte(Flag2);
            bw.WriteByte(Encoding);
            bw.WriteByte(0);

            for (int i = 0; i < Textures.Count; i++)
            {
                Textures[i].Write(bw, i, Platform);
            }
            bw.Pad(0x10);

            for (int i = 0; i < Textures.Count; i++)
            {
                Texture texture = Textures[i];
                bw.FillInt32($"FileName{i}", (int)bw.Position);
                if (Encoding == 1)
                {
                    bw.WriteUTF16(texture.Name, true);
                }
                else if (Encoding == 0 || Encoding == 2)
                {
                    bw.WriteShiftJIS(texture.Name, true);
                }
            }

            int dataStart = (int)bw.Position;

            for (int i = 0; i < Textures.Count; i++)
            {
                Texture texture = Textures[i];
                if (texture.Bytes.Length > 0)
                {
                    bw.Pad(0x10);
                }

                bw.FillInt32($"FileData{i}", (int)bw.Position);

                byte[] bytes = texture.Bytes;
                if (texture.Flags1 == 2 || texture.Flags2 == 3)
                {
                    bytes = DCX.Compress(bytes, DCX.Type.ACEREDGE);
                }
                bw.FillInt32($"FileSize{i}", bytes.Length);
                bw.WriteBytes(bytes);
            }
            bw.FillInt32("DataSize", (int)bw.Position - dataStart);
        }
Exemplo n.º 12
0
        private void WriteFileData(BinaryWriterEx bw, byte[] bytes)
        {
            if (bytes.LongLength > 0)
            {
                bw.Pad(0x10);
            }

            DataOffset       = bw.Position;
            UncompressedSize = bytes.LongLength;
            if (IsCompressed(Flags))
            {
                byte[] compressed = DCX.Compress(bytes, CompressionType);
                CompressedSize = compressed.LongLength;
                bw.WriteBytes(compressed);
            }
            else
            {
                CompressedSize = bytes.LongLength;
                bw.WriteBytes(bytes);
            }
        }
Exemplo n.º 13
0
            internal void WriteData(BinaryWriterEx bw, int index)
            {
                bw.FillUInt32($"FileData{index}", (uint)bw.Position);

                byte[] bytes = Bytes;
                if (Flags1 == 2 || Flags1 == 3)
                {
                    bytes = DCX.Compress(bytes, DCX.Type.DCP_EDGE);
                }

                bw.FillInt32($"FileSize{index}", bytes.Length);
                bw.WriteBytes(bytes);
            }
Exemplo n.º 14
0
        private static void WriteBlobBytes(BinaryWriterEx bw, string name, byte[] bytes)
        {
            bw.WriteInt32(FourCCToInt(name));
            bw.ReserveInt32("BlobSize");
            bw.WriteInt32(1);
            bw.WriteInt32(0);

            long start = bw.Position;

            bw.WriteBytes(bytes);
            bw.Pad(0x10);
            bw.FillInt32("BlobSize", (int)(bw.Position - start));
        }
Exemplo n.º 15
0
            public static byte[] Write(List <Image> images)
            {
                var bw = new BinaryWriterEx(false);

                foreach (Image image in images)
                {
                    foreach (byte[] mip in image.MipLevels)
                    {
                        bw.WriteBytes(mip);
                    }
                }
                return(bw.FinishBytes());
            }
Exemplo n.º 16
0
            internal void Write(BinaryWriterEx bw)
            {
                if (Key.Length != 16)
                {
                    throw new InvalidDataException("AES key must be 16 bytes long.");
                }

                bw.WriteBytes(Key);
                bw.WriteInt32(Ranges.Count);
                foreach (Range range in Ranges)
                {
                    range.Write(bw);
                }
            }
Exemplo n.º 17
0
            internal void Write(BinaryWriterEx bw)
            {
                if (Hash.Length != 32)
                {
                    throw new InvalidDataException("SHA hash must be 32 bytes long.");
                }

                bw.WriteBytes(Hash);
                bw.WriteInt32(Ranges.Count);
                foreach (Range range in Ranges)
                {
                    range.Write(bw);
                }
            }
Exemplo n.º 18
0
        private void Write(BinaryWriterEx bhdWriter, BinaryWriterEx bdtWriter)
        {
            bhdWriter.WriteASCII("BHF3");
            bhdWriter.WriteFixStr(BHDTimestamp, 8);
            bhdWriter.WriteByte((byte)Format);
            bhdWriter.WriteByte(0);
            bhdWriter.WriteByte(0);
            bhdWriter.WriteByte(0);
            bhdWriter.BigEndian = Binder.ForceBigEndian(Format);

            bhdWriter.WriteInt32(Files.Count);
            bhdWriter.WriteInt32(0);
            bhdWriter.WriteInt32(0);
            bhdWriter.WriteInt32(0);

            bdtWriter.WriteASCII("BDF3");
            bdtWriter.WriteFixStr(BDTTimestamp, 8);
            bdtWriter.WriteInt32(0);

            for (int i = 0; i < Files.Count; i++)
            {
                BinderFile file = Files[i];
                bhdWriter.WriteByte(0x40);
                bhdWriter.WriteByte(0);
                bhdWriter.WriteByte(0);
                bhdWriter.WriteByte(0);

                bhdWriter.WriteInt32(file.Bytes.Length);
                bhdWriter.WriteUInt32((uint)bdtWriter.Position);
                bhdWriter.WriteInt32(i);
                bhdWriter.ReserveUInt32($"FileName{i}");

                if (Binder.HasUncompressedSize(Format))
                {
                    bhdWriter.WriteInt32(file.Bytes.Length);
                }

                bdtWriter.WriteBytes(file.Bytes);
                bdtWriter.Pad(0x10);
            }

            for (int i = 0; i < Files.Count; i++)
            {
                BinderFile file = Files[i];
                bhdWriter.FillUInt32($"FileName{i}", (uint)bhdWriter.Position);
                bhdWriter.WriteShiftJIS(file.Name, true);
            }
        }
Exemplo n.º 19
0
        private void Write(BinaryWriterEx bhdWriter, BinaryWriterEx bdtWriter)
        {
            bhdWriter.WriteASCII("BHF3");
            bhdWriter.WriteASCII(BHDTimestamp.PadRight(8, '\0'));
            bhdWriter.WriteByte(Format);
            bhdWriter.WriteByte(0);
            bhdWriter.WriteByte(0);
            bhdWriter.WriteByte(0);
            bhdWriter.BigEndian = Format == 0xE0;

            bhdWriter.WriteInt32(Files.Count);
            bhdWriter.WriteInt32(0);
            bhdWriter.WriteInt32(0);
            bhdWriter.WriteInt32(0);

            bdtWriter.WriteASCII("BDF3");
            bdtWriter.WriteASCII(BDTTimestamp.PadRight(8, '\0'));
            bdtWriter.WriteInt32(0);

            for (int i = 0; i < Files.Count; i++)
            {
                File file = Files[i];
                bhdWriter.WriteByte(0x40);
                bhdWriter.WriteByte(0);
                bhdWriter.WriteByte(0);
                bhdWriter.WriteByte(0);

                bhdWriter.WriteInt32(file.Bytes.Length);
                bhdWriter.WriteInt32((int)bdtWriter.Position);
                bhdWriter.WriteInt32(i);
                bhdWriter.ReserveInt32($"FileName{i}");

                if (Format == 0x54 || Format == 0x74)
                {
                    bhdWriter.WriteInt32(file.Bytes.Length);
                }

                bdtWriter.WriteBytes(file.Bytes);
                bdtWriter.Pad(0x10);
            }

            for (int i = 0; i < Files.Count; i++)
            {
                File file = Files[i];
                bhdWriter.FillInt32($"FileName{i}", (int)bhdWriter.Position);
                bhdWriter.WriteShiftJIS(file.Name, true);
            }
        }
Exemplo n.º 20
0
            internal void WriteArgs(BinaryWriterEx bw, Game format, Offsets offsets, int eventIndex, int instrIndex)
            {
                long argsOffset = ArgData.Length > 0 ? bw.Position - offsets.Arguments : -1;

                if (format < Game.Sekiro)
                {
                    bw.FillInt32($"Event{eventIndex}Instr{instrIndex}ArgsOffset", (int)argsOffset);
                }
                else
                {
                    bw.FillInt64($"Event{eventIndex}Instr{instrIndex}ArgsOffset", argsOffset);
                }

                bw.WriteBytes(ArgData);
                bw.Pad(4);
            }
Exemplo n.º 21
0
                internal void WriteValue(BinaryWriterEx bw, object value)
                {
                    switch (Type)
                    {
                    case ParamType.aob: bw.WriteBytes((byte[])value); break;

                    case ParamType.b: bw.WriteBoolean((bool)value); break;

                    case ParamType.u8:
                    case ParamType.x8:
                        bw.WriteByte(Convert.ToByte(value)); break;

                    case ParamType.s8:
                        bw.WriteSByte(Convert.ToSByte(value)); break;

                    case ParamType.u16:
                    case ParamType.x16:
                        bw.WriteUInt16(Convert.ToUInt16(value)); break;

                    case ParamType.s16:
                        bw.WriteInt16(Convert.ToInt16(value)); break;

                    case ParamType.u32:
                    case ParamType.x32:
                        bw.WriteUInt32(Convert.ToUInt32(value)); break;

                    case ParamType.s32:
                        bw.WriteInt32(Convert.ToInt32(value)); break;

                    case ParamType.u64:
                    case ParamType.x64:
                        bw.WriteUInt64(Convert.ToUInt64(value)); break;

                    case ParamType.s64:
                        bw.WriteInt64(Convert.ToInt64(value)); break;

                    case ParamType.f32:
                        bw.WriteSingle(Convert.ToSingle(value)); break;

                    case ParamType.f64:
                        bw.WriteDouble(Convert.ToDouble(value)); break;

                    default:
                        throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}");
                    }
                }
Exemplo n.º 22
0
 internal void Write(BinaryWriterEx bw, FLVERHeader header)
 {
     if (header.Version <= 0x20010)
     {
         if (int.TryParse(ID, out int id))
         {
             bw.WriteInt32(id);
         }
         else
         {
             throw new FormatException("For Dark Souls 2, GX IDs must be convertible to int.");
         }
     }
     else
     {
         bw.WriteFixStr(ID, 4);
     }
     bw.WriteInt32(Unk04);
     bw.WriteInt32(Data.Length + 0xC);
     bw.WriteBytes(Data);
 }
Exemplo n.º 23
0
        private static void WriteFileData(BinderFile file, BinaryWriterEx bw, int index)
        {
            if (file.Bytes.Length > 0)
            {
                bw.Pad(0x10);
            }

            bw.FillUInt32($"FileData{index}", (uint)bw.Position);

            int compressedSize = file.Bytes.Length;

            if (Binder.IsCompressed(file.Flags))
            {
                compressedSize = SFUtil.WriteZlib(bw, 0x9C, file.Bytes);
            }
            else
            {
                bw.WriteBytes(file.Bytes);
            }

            bw.FillInt32($"CompressedSize{index}", compressedSize);
        }
Exemplo n.º 24
0
            internal void Write(BinaryWriterEx bw)
            {
                bw.WriteInt32(Unk1);
                bw.WriteInt32(Entries.Count + 1);
                bw.ReserveInt64("TypeOffset");

                for (int i = 0; i < Entries.Count; i++)
                {
                    bw.ReserveInt64($"Offset{i}");
                }

                bw.ReserveInt64("NextOffset");

                bw.FillInt64("TypeOffset", bw.Position);
                bw.WriteUTF16(Type, true);
                bw.Pad(8);

                for (int i = 0; i < Entries.Count; i++)
                {
                    bw.FillInt64($"Offset{i}", bw.Position);
                    bw.WriteBytes(Entries[i]);
                }
            }
Exemplo n.º 25
0
            internal void WriteData(BinaryWriterEx bw, int index, byte format)
            {
                if (Bytes.Length > 0)
                {
                    bw.Pad(0x10);
                }

                bw.FillInt32($"FileData{index}", (int)bw.Position);

                byte[] bytes          = Bytes;
                int    compressedSize = bytes.Length;

                if (Flags == 0xC0)
                {
                    compressedSize = SFUtil.WriteZlib(bw, 0x9C, bytes);
                }
                else
                {
                    bw.WriteBytes(bytes);
                }

                bw.FillInt32($"CompressedSize{index}", bytes.Length);
            }
Exemplo n.º 26
0
        /// <summary>
        /// Write a DDS file from this header object and given pixel data.
        /// </summary>
        public byte[] Write(byte[] pixelData)
        {
            BinaryWriterEx bw = new BinaryWriterEx(false);

            bw.WriteASCII("DDS ");
            bw.WriteInt32(0x7C);

            bw.WriteUInt32((uint)dwFlags);
            bw.WriteInt32(dwHeight);
            bw.WriteInt32(dwWidth);
            bw.WriteInt32(dwPitchOrLinearSize);
            bw.WriteInt32(dwDepth);
            bw.WriteInt32(dwMipMapCount);

            for (int i = 0; i < 11; i++)
            {
                bw.WriteInt32(0);
            }

            ddspf.Write(bw);
            bw.WriteUInt32((uint)dwCaps);
            bw.WriteUInt32((uint)dwCaps2);

            for (int i = 0; i < 3; i++)
            {
                bw.WriteInt32(0);
            }

            if (ddspf.dwFourCC == PIXELFORMAT.FourCCDX10)
            {
                header10.Write(bw);
            }

            bw.WriteBytes(pixelData);
            return(bw.FinishBytes());
        }
Exemplo n.º 27
0
            internal void WriteCells(BinaryWriterEx bw, int i, Layout layout)
            {
                bw.FillInt64($"RowOffset{i}", bw.Position);
                for (int j = 0; j < layout.Count; j++)
                {
                    Cell         cell  = Cells[j];
                    Layout.Entry entry = layout[j];
                    CellType     type  = entry.Type;
                    object       value = cell.Value;

                    if (entry.Name != cell.Name || type != cell.Type)
                    {
                        throw new FormatException("Layout does not match cells.");
                    }

                    if (type == CellType.s8)
                    {
                        bw.WriteSByte((sbyte)value);
                    }
                    else if (type == CellType.u8 || type == CellType.x8)
                    {
                        bw.WriteByte((byte)value);
                    }
                    else if (type == CellType.s16)
                    {
                        bw.WriteInt16((short)value);
                    }
                    else if (type == CellType.u16 || type == CellType.x16)
                    {
                        bw.WriteUInt16((ushort)value);
                    }
                    else if (type == CellType.s32)
                    {
                        bw.WriteInt32((int)value);
                    }
                    else if (type == CellType.u32 || type == CellType.x32)
                    {
                        bw.WriteUInt32((uint)value);
                    }
                    else if (type == CellType.f32)
                    {
                        bw.WriteSingle((float)value);
                    }
                    else if (type == CellType.dummy8)
                    {
                        bw.WriteBytes((byte[])value);
                    }
                    else if (type == CellType.fixstr)
                    {
                        bw.WriteFixStr((string)value, entry.Size);
                    }
                    else if (type == CellType.fixstrW)
                    {
                        bw.WriteFixStrW((string)value, entry.Size);
                    }
                    else if (type == CellType.b8)
                    {
                        byte b = 0;
                        int  k;
                        for (k = 0; k < 8; k++)
                        {
                            if (j + k >= layout.Count || layout[j + k].Type != CellType.b8)
                            {
                                break;
                            }

                            if ((bool)Cells[j + k].Value)
                            {
                                b |= (byte)(1 << k);
                            }
                        }
                        j += k - 1;
                        bw.WriteByte(b);
                    }
                    else if (type == CellType.b32)
                    {
                        byte[] b = new byte[4];
                        int    k;
                        for (k = 0; k < 32; k++)
                        {
                            if (j + k >= layout.Count || layout[j + k].Type != CellType.b32)
                            {
                                break;
                            }

                            if ((bool)Cells[j + k].Value)
                            {
                                b[k / 8] |= (byte)(1 << (k % 8));
                            }
                        }
                        j += k - 1;
                        bw.WriteBytes(b);
                    }
                }
            }
Exemplo n.º 28
0
            internal void Write(BinaryWriterEx bw, long nameOffset, int version, bool longOffsets)
            {
                bw.WriteInt32(Unk00);
                bw.WriteInt32(Unk04);
                bw.WriteInt32(Unk08);
                bw.WriteInt32(Unk0C);

                if (longOffsets)
                {
                    bw.WriteInt64(nameOffset);
                }
                else
                {
                    bw.WriteInt32((int)nameOffset);
                }

                bw.WriteUInt32((uint)Type);
                bw.WriteBoolean(Unk1C);
                bw.WriteByte(DiffuseColor.R);
                bw.WriteByte(DiffuseColor.G);
                bw.WriteByte(DiffuseColor.B);
                bw.WriteSingle(DiffusePower);
                bw.WriteByte(SpecularColor.R);
                bw.WriteByte(SpecularColor.G);
                bw.WriteByte(SpecularColor.B);
                bw.WriteBoolean(CastShadows);
                bw.WriteSingle(SpecularPower);
                bw.WriteSingle(ConeAngle);
                bw.WriteSingle(Unk30);
                bw.WriteSingle(Unk34);
                bw.WriteVector3(Position);
                bw.WriteVector3(Rotation);
                bw.WriteInt32(Unk50);
                bw.WriteSingle(Unk54);
                bw.WriteSingle(Radius);
                bw.WriteInt32(Unk5C);
                bw.WriteInt32(0);
                bw.WriteBytes(Unk64);
                bw.WriteSingle(Unk68);
                bw.WriteByte(ShadowColor.R);
                bw.WriteByte(ShadowColor.G);
                bw.WriteByte(ShadowColor.B);
                bw.WriteByte(ShadowColor.A);
                bw.WriteSingle(Unk70);
                bw.WriteSingle(FlickerIntervalMin);
                bw.WriteSingle(FlickerIntervalMax);
                bw.WriteSingle(FlickerBrightnessMult);
                bw.WriteInt32(Unk80);
                bw.WriteBytes(Unk84);
                bw.WriteSingle(Unk88);
                bw.WriteInt32(0);
                bw.WriteSingle(Unk90);
                bw.WriteInt32(0);
                bw.WriteSingle(Unk98);
                bw.WriteSingle(Unk9C);
                bw.WriteBytes(UnkA0);
                bw.WriteSingle(Sharpness);
                bw.WriteInt32(0);
                bw.WriteSingle(UnkAC);

                if (longOffsets)
                {
                    bw.WriteInt64(0);
                }
                else
                {
                    bw.WriteInt32(0);
                }

                bw.WriteSingle(Width);
                bw.WriteSingle(UnkBC);
                bw.WriteBytes(UnkC0);
                bw.WriteSingle(UnkC4);

                if (version >= 16)
                {
                    bw.WriteSingle(UnkC8);
                    bw.WriteSingle(UnkCC);
                    bw.WriteSingle(UnkD0);
                    bw.WriteSingle(UnkD4);
                    bw.WriteSingle(UnkD8);
                    bw.WriteInt32(UnkDC);
                    bw.WriteSingle(UnkE0);
                    bw.WriteInt32(0);
                }
            }
Exemplo n.º 29
0
        private static void CompressDCXEDGE(byte[] data, BinaryWriterEx bw)
        {
            int chunkCount = data.Length / 0x10000;

            if (data.Length % 0x10000 > 0)
            {
                chunkCount++;
            }

            bw.WriteASCII("DCX\0");
            bw.WriteInt32(0x10000);
            bw.WriteInt32(0x18);
            bw.WriteInt32(0x24);
            bw.WriteInt32(0x24);
            bw.WriteInt32(0x50 + chunkCount * 0x10);

            bw.WriteASCII("DCS\0");
            bw.WriteInt32(data.Length);
            bw.ReserveInt32("CompressedSize");

            bw.WriteASCII("DCP\0");
            bw.WriteASCII("EDGE");
            bw.WriteInt32(0x20);
            bw.WriteInt32(0x9000000);
            bw.WriteInt32(0x10000);
            bw.WriteInt32(0);
            bw.WriteInt32(0);
            bw.WriteInt32(0x00100100);

            long dcaStart = bw.Position;

            bw.WriteASCII("DCA\0");
            bw.ReserveInt32("DCASize");
            long egdtStart = bw.Position;

            bw.WriteASCII("EgdT");
            bw.WriteInt32(0x00010100);
            bw.WriteInt32(0x24);
            bw.WriteInt32(0x10);
            bw.WriteInt32(0x10000);
            bw.WriteInt32(data.Length % 0x10000);
            bw.ReserveInt32("EGDTSize");
            bw.WriteInt32(chunkCount);
            bw.WriteInt32(0x100000);

            for (int i = 0; i < chunkCount; i++)
            {
                bw.WriteInt32(0);
                bw.ReserveInt32($"ChunkOffset{i}");
                bw.ReserveInt32($"ChunkSize{i}");
                bw.ReserveInt32($"ChunkCompressed{i}");
            }

            bw.FillInt32("DCASize", (int)(bw.Position - dcaStart));
            bw.FillInt32("EGDTSize", (int)(bw.Position - egdtStart));
            long dataStart = bw.Position;

            int compressedSize = 0;

            for (int i = 0; i < chunkCount; i++)
            {
                int chunkSize = 0x10000;
                if (i == chunkCount - 1)
                {
                    chunkSize = data.Length % 0x10000;
                }

                byte[] chunk;
                using (MemoryStream cmpStream = new MemoryStream())
                    using (MemoryStream dcmpStream = new MemoryStream(data, i * 0x10000, chunkSize))
                    {
                        DeflateStream dfltStream = new DeflateStream(cmpStream, CompressionMode.Compress);
                        dcmpStream.CopyTo(dfltStream);
                        dfltStream.Close();
                        chunk = cmpStream.ToArray();
                    }

                if (chunk.Length < chunkSize)
                {
                    bw.FillInt32($"ChunkCompressed{i}", 1);
                }
                else
                {
                    bw.FillInt32($"ChunkCompressed{i}", 0);
                    chunk = data;
                }

                compressedSize += chunk.Length;
                bw.FillInt32($"ChunkOffset{i}", (int)(bw.Position - dataStart));
                bw.FillInt32($"ChunkSize{i}", chunk.Length);
                bw.WriteBytes(chunk);
                bw.Pad(0x10);
            }

            bw.FillInt32("CompressedSize", compressedSize);
        }
Exemplo n.º 30
0
                internal void WriteDefaultValue(BinaryWriterEx bw)
                {
                    if (ValueToAssert != null)
                    {
                        WriteAssertValue(bw);
                    }
                    else if (DefaultValue == null)
                    {
                        switch (Type)
                        {
                        case ParamType.aob:
                            for (int i = 0; i < AobLength; i++)
                            {
                                bw.WriteByte(0);
                            }
                            break;

                        case ParamType.b:
                        case ParamType.u8:
                        case ParamType.x8: bw.WriteByte(0); break;

                        case ParamType.s8: bw.WriteSByte(0); break;

                        case ParamType.u16:
                        case ParamType.x16: bw.WriteUInt16(0); break;

                        case ParamType.s16: bw.WriteInt16(0); break;

                        case ParamType.u32:
                        case ParamType.x32: bw.WriteUInt32(0); break;

                        case ParamType.s32: bw.WriteInt32(0); break;

                        case ParamType.u64:
                        case ParamType.x64: bw.WriteUInt64(0); break;

                        case ParamType.s64: bw.WriteInt64(0); break;

                        case ParamType.f32: bw.WriteSingle(0); break;

                        case ParamType.f64: bw.WriteDouble(0); break;

                        default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}");
                        }
                    }
                    else
                    {
                        switch (Type)
                        {
                        case ParamType.aob:
                            var assertAob = (byte[])DefaultValue;
                            bw.WriteBytes(assertAob);
                            break;

                        case ParamType.b:
                        case ParamType.u8:
                        case ParamType.x8: bw.WriteByte((byte)DefaultValue); break;

                        case ParamType.s8: bw.WriteSByte((sbyte)DefaultValue); break;

                        case ParamType.u16:
                        case ParamType.x16: bw.WriteUInt16((ushort)DefaultValue); break;

                        case ParamType.s16: bw.WriteInt16((short)DefaultValue); break;

                        case ParamType.u32:
                        case ParamType.x32: bw.WriteUInt32((uint)DefaultValue); break;

                        case ParamType.s32: bw.WriteInt32((int)DefaultValue); break;

                        case ParamType.u64:
                        case ParamType.x64: bw.WriteUInt64((ulong)DefaultValue); break;

                        case ParamType.s64: bw.WriteInt64((long)DefaultValue); break;

                        case ParamType.f32: bw.WriteSingle((float)DefaultValue); break;

                        case ParamType.f64: bw.WriteDouble((double)DefaultValue); break;

                        default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}");
                        }
                    }
                }