Esempio n. 1
0
            internal virtual void Write(BinaryWriterEx bw, List <T> entries)
            {
                bw.WriteInt32(Version);
                bw.WriteInt32(entries.Count + 1);
                bw.ReserveInt64("ParamNameOffset");
                for (int i = 0; i < entries.Count; i++)
                {
                    bw.ReserveInt64($"EntryOffset{i}");
                }
                bw.ReserveInt64("NextParamOffset");

                bw.FillInt64("ParamNameOffset", bw.Position);
                bw.WriteUTF16(Name, true);
                bw.Pad(8);

                int  index = 0;
                Type type  = null;

                for (int i = 0; i < entries.Count; i++)
                {
                    if (type != entries[i].GetType())
                    {
                        type  = entries[i].GetType();
                        index = 0;
                    }

                    bw.FillInt64($"EntryOffset{i}", bw.Position);
                    entries[i].Write(bw, index);
                    bw.Pad(8);
                    index++;
                }
            }
Esempio n. 2
0
            internal override void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteUInt32((uint)Type);
                bw.WriteInt32(id);
                bw.ReserveInt64("SibOffset");
                bw.WriteInt32(InstanceCount);
                bw.WriteInt32(Unk1C);
                bw.ReserveInt64("TypeDataOffset");

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(ReambiguateName(Name), true);
                bw.FillInt64("SibOffset", bw.Position - start);
                bw.WriteUTF16(Placeholder, true);
                bw.Pad(8);

                if (HasTypeData)
                {
                    bw.FillInt64("TypeDataOffset", bw.Position - start);
                    WriteTypeData(bw);
                }
                else
                {
                    bw.FillInt64("TypeDataOffset", 0);
                }
            }
Esempio n. 3
0
 internal void WriteName(BinaryWriterEx bw, byte format2D, int i)
 {
     if (Name == null || Name == "")
     {
         if ((format2D & 0x7F) < 4)
         {
             bw.FillUInt32($"NameOffset{i}", 0);
         }
         else
         {
             bw.FillInt64($"NameOffset{i}", 0);
         }
     }
     else
     {
         if ((format2D & 0x7F) < 4)
         {
             bw.FillUInt32($"NameOffset{i}", (uint)bw.Position);
             bw.WriteShiftJIS(Name, true);
         }
         else
         {
             bw.FillInt64($"NameOffset{i}", bw.Position);
             bw.WriteUTF16(Name, true);
         }
     }
 }
Esempio n. 4
0
            internal override void Write(BinaryWriterEx bw, int index)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteUInt16((ushort)Type);
                bw.WriteInt16(Index);
                bw.WriteInt32(0);
                bw.ReserveInt64("TypeDataOffset");
                bw.WriteInt64(0);

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(MSB.ReambiguateName(Name), true);
                bw.Pad(8);

                if (Type == ModelType.Object)
                {
                    bw.FillInt64("TypeDataOffset", bw.Position - start);
                    bw.WriteInt64(0);
                }
                else
                {
                    bw.FillInt64("TypeDataOffset", 0);
                }
            }
Esempio n. 5
0
            internal void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteInt32(EventID);
                bw.WriteUInt32((uint)Type);
                bw.WriteInt32(id);
                bw.WriteInt32(0);
                bw.ReserveInt64("BaseDataOffset");
                bw.ReserveInt64("TypeDataOffset");

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(Name, true);
                bw.Pad(8);

                bw.FillInt64("BaseDataOffset", bw.Position - start);
                bw.WriteInt32(partIndex);
                bw.WriteInt32(pointIndex);
                bw.WriteInt32(EventEntityID);
                bw.WriteInt32(0);

                bw.FillInt64("TypeDataOffset", bw.Position - start);
                WriteSpecific(bw);
            }
Esempio n. 6
0
        internal override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = false;

            Entries entries;

            entries.Models     = Models.GetEntries();
            entries.Events     = Events.GetEntries();
            entries.Regions    = Regions.GetEntries();
            entries.Routes     = Routes.GetEntries();
            entries.Layers     = Layers.GetEntries();
            entries.Parts      = Parts.GetEntries();
            entries.PartsPoses = PartsPoses.GetEntries();
            entries.BoneNames  = BoneNames.GetEntries();

            Models.CountInstances(entries);
            Events.GetIndices(this, entries);
            Parts.GetIndices(this, entries);
            Regions.GetIndices(this, entries);

            bw.WriteASCII("MSB ");
            bw.WriteInt32(1);
            bw.WriteInt32(0x10);

            bw.WriteByte(0);
            bw.WriteByte(0);
            bw.WriteByte(1);
            bw.WriteByte(0xFF);

            Models.Write(bw, entries.Models);
            bw.Pad(8);
            bw.FillInt64("NextOffset", bw.Position);

            Events.Write(bw, entries.Events);
            bw.Pad(8);
            bw.FillInt64("NextOffset", bw.Position);

            Regions.Write(bw, entries.Regions);
            bw.Pad(8);
            bw.FillInt64("NextOffset", bw.Position);

            /*Routes.Write(bw, entries.Routes);
             * bw.Pad(8);
             * bw.FillInt64("NextOffset", bw.Position);
             *
             * Layers.Write(bw, entries.Layers);
             * bw.Pad(8);
             * bw.FillInt64("NextOffset", bw.Position);*/

            Parts.Write(bw, entries.Parts);
            //bw.Pad(8);
            bw.FillInt64("NextOffset", 0);

            /*PartsPoses.Write(bw, entries.PartsPoses);
             * bw.Pad(8);
             * bw.FillInt64("NextOffset", bw.Position);
             *
             * BoneNames.Write(bw, entries.BoneNames);
             * bw.FillInt64("NextOffset", 0);*/
        }
Esempio n. 7
0
            internal void WriteHashAndKey(BinaryWriterEx bw, Game game, int bucketIndex, int fileIndex)
            {
                if (game >= Game.DarkSouls2)
                {
                    if (SHAHash == null)
                    {
                        bw.FillInt64($"SHAHashOffset{bucketIndex}:{fileIndex}", 0);
                    }
                    else
                    {
                        bw.FillInt64($"SHAHashOffset{bucketIndex}:{fileIndex}", bw.Position);
                        SHAHash.Write(bw);
                    }

                    if (AESKey == null)
                    {
                        bw.FillInt64($"AESKeyOffset{bucketIndex}:{fileIndex}", 0);
                    }
                    else
                    {
                        bw.FillInt64($"AESKeyOffset{bucketIndex}:{fileIndex}", bw.Position);
                        AESKey.Write(bw);
                    }
                }
            }
            internal void Write(BinaryWriterEx bw, List <T> entries)
            {
                bw.WriteInt32(Version);
                bw.WriteInt32(entries.Count + 1);
                bw.ReserveInt64("ParamNameOffset");
                for (int i = 0; i < entries.Count; i++)
                {
                    bw.ReserveInt64($"EntryOffset{i}");
                }
                bw.ReserveInt64("NextParamOffset");

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

                int  id          = 0;
                Type currentType = null;

                for (int i = 0; i < entries.Count; i++)
                {
                    if (currentType != entries[i].GetType())
                    {
                        currentType = entries[i].GetType();
                        id          = 0;
                    }

                    bw.FillInt64($"EntryOffset{i}", bw.Position);
                    WriteEntry(bw, id, entries[i]);
                    id++;
                }
            }
Esempio n. 9
0
        /// <summary>
        /// Serializes file data to a stream.
        /// </summary>
        protected override void Write(BinaryWriterEx bw)
        {
            Entries entries;

            entries.Models  = Models.GetEntries();
            entries.Events  = Events.GetEntries();
            entries.Regions = Regions.GetEntries();
            entries.Parts   = Parts.GetEntries();

            foreach (Model model in entries.Models)
            {
                model.CountInstances(entries.Parts);
            }
            foreach (Event evt in entries.Events)
            {
                evt.GetIndices(this, entries);
            }
            foreach (Part part in entries.Parts)
            {
                part.GetIndices(this, entries);
            }

            bw.BigEndian = false;
            MSB.WriteHeader(bw);

            Models.Write(bw, entries.Models);
            bw.FillInt64("NextParamOffset", bw.Position);
            Events.Write(bw, entries.Events);
            bw.FillInt64("NextParamOffset", bw.Position);
            Regions.Write(bw, entries.Regions);
            bw.FillInt64("NextParamOffset", bw.Position);
            Parts.Write(bw, entries.Parts);
            bw.FillInt64("NextParamOffset", 0);
        }
 internal void WriteStrings(BinaryWriterEx bw, bool longFormat, int index)
 {
     if (longFormat)
     {
         bw.FillInt64($"NameOffset{index}", bw.Position);
         bw.WriteUTF16(Name, true);
         if (LogicInterruptName == null)
         {
             bw.FillInt64($"LogicInterruptNameOffset{index}", 0);
         }
         else
         {
             bw.FillInt64($"LogicInterruptNameOffset{index}", bw.Position);
             bw.WriteUTF16(LogicInterruptName, true);
         }
     }
     else
     {
         bw.FillUInt32($"NameOffset{index}", (uint)bw.Position);
         bw.WriteShiftJIS(Name, true);
         if (LogicInterruptName == null)
         {
             bw.FillUInt32($"LogicInterruptNameOffset{index}", 0);
         }
         else
         {
             bw.FillUInt32($"LogicInterruptNameOffset{index}", (uint)bw.Position);
             bw.WriteShiftJIS(LogicInterruptName, true);
         }
     }
 }
Esempio n. 11
0
            internal override void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteInt32(EventIndex);
                bw.WriteUInt32((uint)Type);
                bw.WriteInt32(id);
                bw.WriteInt32(0);
                bw.ReserveInt64("BaseDataOffset");
                bw.ReserveInt64("TypeDataOffset");

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(Name, true);
                bw.Pad(8);

                bw.FillInt64("BaseDataOffset", bw.Position - start);
                bw.WriteInt32(PartIndex);
                bw.WriteInt32(RegionIndex);
                bw.WriteInt32(EntityID);
                bw.WriteInt32(0);

                if (HasTypeData)
                {
                    bw.FillInt64("TypeDataOffset", bw.Position - start);
                    WriteTypeData(bw);
                }
                else
                {
                    bw.FillInt64("TypeDataOffset", 0);
                }
            }
Esempio n. 12
0
            internal Dictionary <float, long> WriteTimes(BinaryWriterEx bw, int animIndex)
            {
                var times = new SortedSet <float>();

                foreach (Event evt in Events)
                {
                    times.Add(evt.StartTime);
                    times.Add(evt.EndTime);
                }
                bw.FillInt32($"TimesCount{animIndex}", times.Count);

                if (times.Count == 0)
                {
                    bw.FillInt64($"TimesOffset{animIndex}", 0);
                }
                else
                {
                    bw.FillInt64($"TimesOffset{animIndex}", bw.Position);
                }

                var timeOffsets = new Dictionary <float, long>();

                foreach (float time in times)
                {
                    timeOffsets[time] = bw.Position;
                    bw.WriteSingle(time);
                }
                bw.Pad(0x10);

                return(timeOffsets);
            }
Esempio n. 13
0
            internal void WriteData(BinaryWriterEx bw, int i, int j, List<long> eventHeaderOffsets)
            {
                bw.FillInt64($"EventGroupTypeOffset{i}:{j}", bw.Position);
                bw.WriteUInt64((ulong)Type);
                bw.WriteInt64(0);

                bw.FillInt64($"EventGroupValuesOffset{i}:{j}", bw.Position);
                for (int k = 0; k < Indices.Count; k++)
                    bw.WriteInt32((int)eventHeaderOffsets[Indices[k]]);
                bw.Pad(0x10);
            }
Esempio n. 14
0
        internal static void WriteHeader(IBND4 bnd, BinaryWriterEx bw, List <BinderFileHeader> fileHeaders)
        {
            bw.BigEndian = bnd.BigEndian;

            bw.WriteASCII("BND4");

            bw.WriteBoolean(bnd.Unk04);
            bw.WriteBoolean(bnd.Unk05);
            bw.WriteByte(0);
            bw.WriteByte(0);

            bw.WriteByte(0);
            bw.WriteBoolean(bnd.BigEndian);
            bw.WriteBoolean(!bnd.BitBigEndian);
            bw.WriteByte(0);

            bw.WriteInt32(fileHeaders.Count);
            bw.WriteInt64(0x40);
            bw.WriteFixStr(bnd.Version, 8);
            bw.WriteInt64(Binder.GetBND4FileHeaderSize(bnd.Format));
            bw.ReserveInt64("HeadersEnd");

            bw.WriteBoolean(bnd.Unicode);
            Binder.WriteFormat(bw, bnd.BitBigEndian, bnd.Format);
            bw.WriteByte(bnd.Extended);
            bw.WriteByte(0);

            bw.WriteInt32(0);
            bw.ReserveInt64("HashTableOffset");

            for (int i = 0; i < fileHeaders.Count; i++)
            {
                fileHeaders[i].WriteBinder4FileHeader(bw, bnd.Format, bnd.BitBigEndian, i);
            }

            for (int i = 0; i < fileHeaders.Count; i++)
            {
                fileHeaders[i].WriteFileName(bw, bnd.Format, bnd.Unicode, i);
            }

            if (bnd.Extended == 4)
            {
                bw.Pad(0x8);
                bw.FillInt64("HashTableOffset", bw.Position);
                BinderHashTable.Write(bw, fileHeaders);
            }
            else
            {
                bw.FillInt64("HashTableOffset", 0);
            }

            bw.FillInt64("HeadersEnd", bw.Position);
        }
Esempio n. 15
0
 internal void WriteEventGroupHeaders(BinaryWriterEx bw, int i)
 {
     if (EventGroups.Count > 0)
     {
         bw.FillInt64($"EventGroupHeadersOffset{i}", bw.Position);
         for (int j = 0; j < EventGroups.Count; j++)
             EventGroups[j].WriteHeader(bw, i, j);
     }
     else
     {
         bw.FillInt64($"EventGroupHeadersOffset{i}", 0);
     }
 }
Esempio n. 16
0
            internal void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteUInt32((uint)Type);
                bw.WriteInt32(id);
                bw.WriteUInt32((uint)Shape.Type);
                bw.WriteVector3(Position);
                bw.WriteVector3(Rotation);
                bw.WriteInt32(Unk2);
                bw.ReserveInt64("BaseDataOffset1");
                bw.ReserveInt64("BaseDataOffset2");
                bw.WriteInt32(-1);
                bw.WriteUInt32(MapStudioLayer);

                bw.ReserveInt64("ShapeDataOffset");
                bw.ReserveInt64("BaseDataOffset3");
                bw.ReserveInt64("TypeDataOffset");

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(ReambiguateName(Name), true);
                bw.Pad(4);

                bw.FillInt64("BaseDataOffset1", bw.Position - start);
                bw.WriteInt16((short)UnkA.Count);
                bw.WriteInt16s(UnkA);
                bw.Pad(4);

                bw.FillInt64("BaseDataOffset2", bw.Position - start);
                bw.WriteInt16((short)UnkB.Count);
                bw.WriteInt16s(UnkB);
                bw.Pad(8);

                Shape.Write(bw, start);

                bw.FillInt64("BaseDataOffset3", bw.Position - start);
                bw.WriteInt32(ActivationPartIndex);
                bw.WriteInt32(EventEntityID);

                if (HasTypeData)
                {
                    WriteSpecific(bw, start);
                }
                else
                {
                    bw.FillInt64("TypeDataOffset", 0);
                }

                bw.Pad(8);
            }
Esempio n. 17
0
        internal override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = false;

            Entries entries;

            entries.Models  = Models.GetEntries();
            entries.Events  = Events.GetEntries();
            entries.Regions = Regions.GetEntries();
            entries.Parts   = Parts.GetEntries();

            foreach (Model model in entries.Models)
            {
                model.CountInstances(entries.Parts);
            }
            foreach (Event evt in entries.Events)
            {
                evt.GetIndices(this, entries);
            }
            foreach (Region region in entries.Regions)
            {
                region.GetIndices(this, entries);
            }
            foreach (Part part in entries.Parts)
            {
                part.GetIndices(this, entries);
            }

            bw.WriteASCII("MSB ");
            bw.WriteInt32(1);
            bw.WriteInt32(0x10);

            bw.WriteBoolean(false);
            bw.WriteBoolean(false);
            bw.WriteByte(1);
            bw.WriteByte(0xFF);

            Models.Write(bw, entries.Models);
            bw.FillInt64("NextParamOffset", bw.Position);

            Events.Write(bw, entries.Events);
            bw.FillInt64("NextParamOffset", bw.Position);

            Regions.Write(bw, entries.Regions);
            bw.FillInt64("NextParamOffset", bw.Position);

            Parts.Write(bw, entries.Parts);
            bw.FillInt64("NextParamOffset", 0);
        }
Esempio n. 18
0
 internal override void WriteSpecific(BinaryWriterEx bw, long start)
 {
     bw.FillInt64("TypeDataOffset", bw.Position - start);
     bw.WriteSingle(Length);
     bw.WriteSingle(Width);
     bw.WriteSingle(Height);
 }
Esempio n. 19
0
            internal void WriteDescription(BinaryWriterEx bw, PARAMDEF def, int index)
            {
                long descriptionOffset = 0;

                if (Description != null)
                {
                    descriptionOffset = bw.Position;
                    if (def.Unicode)
                    {
                        bw.WriteUTF16(Description, true);
                    }
                    else
                    {
                        bw.WriteShiftJIS(Description, true);
                    }
                }

                if (def.Version >= 201)
                {
                    bw.FillInt64($"DescriptionOffset{index}", descriptionOffset);
                }
                else
                {
                    bw.FillInt32($"DescriptionOffset{index}", (int)descriptionOffset);
                }
            }
Esempio n. 20
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);
            }
        }
Esempio n. 21
0
            internal void WriteName(BinaryWriterEx bw, PARAM parent, int i)
            {
                long nameOffset = 0;

                if (Name != null)
                {
                    nameOffset = bw.Position;
                    if (parent.Format2E.HasFlag(FormatFlags2.UnicodeRowNames))
                    {
                        bw.WriteUTF16(Name, true);
                    }
                    else
                    {
                        bw.WriteShiftJIS(Name, true);
                    }
                }

                if (parent.Format2D.HasFlag(FormatFlags1.LongDataOffset))
                {
                    bw.FillInt64($"NameOffset{i}", nameOffset);
                }
                else
                {
                    bw.FillUInt32($"NameOffset{i}", (uint)nameOffset);
                }
            }
Esempio n. 22
0
            internal void WriteName(BinaryWriterEx bw, byte format2D, byte format2E, int i)
            {
                long nameOffset = 0;

                if (Name != null)
                {
                    nameOffset = bw.Position;
                    if (format2E < 7)
                    {
                        bw.WriteShiftJIS(Name, true);
                    }
                    else
                    {
                        bw.WriteUTF16(Name, true);
                    }
                }

                if ((format2D & 0x7F) < 4)
                {
                    bw.FillUInt32($"NameOffset{i}", (uint)nameOffset);
                }
                else
                {
                    bw.FillInt64($"NameOffset{i}", nameOffset);
                }
            }
Esempio n. 23
0
 internal override void WriteSpecific(BinaryWriterEx bw, long start)
 {
     bw.FillInt64("TypeDataOffset", bw.Position - start);
     bw.WriteInt16(MessageID);
     bw.WriteInt16(UnkT02);
     bw.WriteInt32(Hidden ? 1 : 0);
 }
Esempio n. 24
0
 internal override void WriteSpecific(BinaryWriterEx bw, long start)
 {
     bw.FillInt64("TypeDataOffset", bw.Position - start);
     bw.WriteUInt32((uint)SoundType);
     bw.WriteInt32(SoundID);
     bw.WriteInt32s(ChildRegionIndices);
 }
Esempio n. 25
0
 internal override void WriteSpecific(BinaryWriterEx bw, long start)
 {
     bw.FillInt64("TypeDataOffset", bw.Position - start);
     bw.WriteInt32(UnkT00);
     bw.WriteInt32(0);
     bw.WriteInt32(0);
     bw.WriteInt32(0);
 }
Esempio n. 26
0
            internal override void Write(BinaryWriterEx bw, int index)
            {
                long start = bw.Position;

                bw.ReserveInt64("NameOffset");
                bw.WriteInt32(EventID);
                bw.WriteUInt16((ushort)Type);
                bw.WriteInt16((short)index);
                bw.ReserveInt64("TypeDataOffset");

                bw.FillInt64("NameOffset", bw.Position - start);
                bw.WriteUTF16(Name, true);
                bw.Pad(8);

                bw.FillInt64("TypeDataOffset", bw.Position - start);
                WriteTypeData(bw);
            }
Esempio n. 27
0
 internal override void WriteEntries(BinaryWriterEx bw, List <string> entries)
 {
     for (int i = 0; i < entries.Count; i++)
     {
         bw.FillInt64($"Offset{i}", bw.Position);
         bw.WriteUTF16(entries[i], true);
     }
 }
Esempio n. 28
0
 internal override void WriteEntries(BinaryWriterEx bw, List <Part> entries)
 {
     for (int i = 0; i < entries.Count; i++)
     {
         bw.FillInt64($"Offset{i}", bw.Position);
         entries[i].Write(bw);
     }
 }
Esempio n. 29
0
 internal void WriteTimes(BinaryWriterEx bw, int i)
 {
     bw.FillInt64($"TimesOffset{i}", bw.Position);
     for (int j = 0; j < Events.Count; j++)
     {
         Events[j].WriteTime(bw);
     }
 }
Esempio n. 30
0
            internal void WriteAnimFile(BinaryWriterEx bw, int i)
            {
                bw.FillInt64($"AnimFileOffset{i}", bw.Position);
                bw.WriteInt64(AnimFileReference ? 1 : 0);
                bw.WriteInt64(bw.Position + 8);
                bw.ReserveInt64("AnimFileNameOffset");
                bw.WriteInt32(AnimFileUnk18);
                bw.WriteInt32(AnimFileUnk20);
                bw.WriteInt64(0);
                bw.WriteInt64(0);

                bw.FillInt64("AnimFileNameOffset", bw.Position);
                if (AnimFileName != null)
                {
                    bw.WriteUTF16(AnimFileName, true);
                    bw.Pad(0x10);
                }
            }