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

                bw.FillInt32("ParamNameOffset", (int)bw.Position);
                bw.WriteASCII(Name, true);
                bw.Pad(4);

                int  id   = 0;
                Type type = null;

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

                    bw.FillInt32($"EntryOffset{i}", (int)bw.Position);
                    entries[i].Write(bw, id);
                    id++;
                }
            }
Ejemplo n.º 2
0
            internal override void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

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

                bw.FillInt32("NameOffset", (int)(bw.Position - start));
                bw.WriteShiftJIS(Name, true);
                bw.Pad(4);

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

                bw.FillInt32("TypeDataOffset", (int)(bw.Position - start));
                WriteTypeData(bw);
            }
Ejemplo n.º 3
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();

            Models.DiscriminateModels();
            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;

            Models.Write(bw, entries.Models);
            bw.FillInt32("NextParamOffset", (int)bw.Position);
            Events.Write(bw, entries.Events);
            bw.FillInt32("NextParamOffset", (int)bw.Position);
            Regions.Write(bw, entries.Regions);
            bw.FillInt32("NextParamOffset", (int)bw.Position);
            Parts.Write(bw, entries.Parts);
            bw.FillInt32("NextParamOffset", 0);
        }
Ejemplo n.º 4
0
                internal void WriteMembers(BinaryWriterEx bw, int index, List <int> offsetIndex, SortedDictionary <int, List <int> > membersOffsetIndex)
                {
                    if (Members == null)
                    {
                        bw.FillInt32($"MembersOffset{index}", 0);
                    }
                    else
                    {
                        bw.FillInt32($"MembersOffset{index}", (int)bw.Position);
                        bw.WriteInt16(-1);
                        bw.WriteInt16((short)Members.Count);
                        membersOffsetIndex[index].Add((int)bw.Position);
                        bw.ReserveInt32($"MemberOffsetsOffset{index}");

                        // :^)
                        bw.FillInt32($"MemberOffsetsOffset{index}", (int)bw.Position);
                        for (int i = 0; i < Members.Count; i++)
                        {
                            membersOffsetIndex[index].Add((int)bw.Position);
                            bw.ReserveInt32($"MemberOffset{index}:{i}");
                        }

                        for (int i = 0; i < Members.Count; i++)
                        {
                            bw.FillInt32($"MemberOffset{index}:{i}", (int)bw.Position);
                            Members[i].Write(bw, index, i, offsetIndex);
                        }
                    }
                }
Ejemplo n.º 5
0
 internal void WriteSection11s(BinaryWriterEx bw, int index, ref int section11Count)
 {
     bw.FillInt32($"Section3Section11Offset1[{index}]", (int)bw.Position);
     bw.WriteInt32(Section11Data1);
     bw.FillInt32($"Section3Section11Offset2[{index}]", (int)bw.Position);
     bw.WriteInt32(Section11Data2);
     section11Count += 2;
 }
Ejemplo n.º 6
0
            internal void WritePaths(BinaryWriterEx bw, int index)
            {
                bw.FillInt32($"AbsolutePathOffset{index}", (int)bw.Position);
                bw.WriteUTF16(AbsolutePath, true);

                bw.FillInt32($"RelativePathOffset{index}", (int)bw.Position);
                bw.WriteUTF16(RelativePath, true);
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Serializes file data to a stream.
        /// </summary>
        protected override void Write(BinaryWriterEx bw)
        {
            var offsetIndex        = new List <int>();
            var memberOffsetsIndex = new SortedDictionary <int, List <int> >();

            bw.BigEndian = BigEndian;
            bw.WriteASCII("ACB\0");
            bw.WriteByte(2);
            bw.WriteByte(1);
            bw.WriteByte(0);
            bw.WriteByte(0);
            bw.WriteInt32(Assets.Count);
            bw.ReserveInt32("OffsetIndexOffset");

            for (int i = 0; i < Assets.Count; i++)
            {
                offsetIndex.Add((int)bw.Position);
                bw.ReserveInt32($"AssetOffset{i}");
            }

            for (int i = 0; i < Assets.Count; i++)
            {
                bw.FillInt32($"AssetOffset{i}", (int)bw.Position);
                Assets[i].Write(bw, i, offsetIndex, memberOffsetsIndex);
            }

            for (int i = 0; i < Assets.Count; i++)
            {
                if (Assets[i] is Asset.Model model)
                {
                    model.WriteMembers(bw, i, offsetIndex, memberOffsetsIndex);
                }
            }

            for (int i = 0; i < Assets.Count; i++)
            {
                Assets[i].WritePaths(bw, i);
            }

            for (int i = 0; i < Assets.Count; i++)
            {
                if (Assets[i] is Asset.Model model && model.Members != null)
                {
                    for (int j = 0; j < model.Members.Count; j++)
                    {
                        model.Members[j].WriteText(bw, i, j);
                    }
                }
            }

            bw.Pad(4);
            bw.FillInt32("OffsetIndexOffset", (int)bw.Position);
            bw.WriteInt32s(offsetIndex);
            foreach (List <int> offsets in memberOffsetsIndex.Values)
            {
                bw.WriteInt32s(offsets);
            }
        }
Ejemplo n.º 8
0
            internal override void Write(BinaryWriterEx bw, int id)
            {
                long start = bw.Position;

                bw.ReserveInt32("NameOffset");
                bw.WriteUInt32((uint)Type);
                bw.WriteInt32(id);
                bw.WriteInt32(ModelIndex);
                bw.ReserveInt32("SibOffset");
                bw.WriteVector3(Position);
                bw.WriteVector3(Rotation);
                bw.WriteVector3(Scale);
                bw.WriteUInt32s(DrawGroups);
                bw.WriteUInt32s(DispGroups);
                bw.ReserveInt32("EntityDataOffset");
                bw.ReserveInt32("TypeDataOffset");
                bw.WriteInt32(0);

                long stringsStart = bw.Position;

                bw.FillInt32("NameOffset", (int)(bw.Position - start));
                bw.WriteShiftJIS(MSB.ReambiguateName(Name), true);
                bw.FillInt32("SibOffset", (int)(bw.Position - start));
                bw.WriteShiftJIS(Placeholder, true);
                bw.Pad(4);
                if (bw.Position - stringsStart < 0x14)
                {
                    bw.WritePattern((int)(0x14 - (bw.Position - stringsStart)), 0x00);
                }

                bw.FillInt32("EntityDataOffset", (int)(bw.Position - start));
                bw.WriteInt32(EntityID);
                bw.WriteByte(LightID);
                bw.WriteByte(FogID);
                bw.WriteByte(ScatterID);
                bw.WriteByte(LensFlareID);
                bw.WriteByte(ShadowID);
                bw.WriteByte(DofID);
                bw.WriteByte(ToneMapID);
                bw.WriteByte(ToneCorrectID);
                bw.WriteByte(LanternID);
                bw.WriteByte(LodParamID);
                bw.WriteByte(0);
                bw.WriteByte(IsShadowSrc);
                bw.WriteByte(IsShadowDest);
                bw.WriteByte(IsShadowOnly);
                bw.WriteByte(DrawByReflectCam);
                bw.WriteByte(DrawOnlyReflectCam);
                bw.WriteByte(UseDepthBiasFloat);
                bw.WriteByte(DisablePointLightEffect);
                bw.WriteByte(0);
                bw.WriteByte(0);

                bw.FillInt32("TypeDataOffset", (int)(bw.Position - start));
            }
Ejemplo n.º 9
0
 internal void FillGXOffset(BinaryWriterEx bw, int index, List <int> gxOffsets)
 {
     if (GXIndex == -1)
     {
         bw.FillInt32($"GXOffset{index}", 0);
     }
     else
     {
         bw.FillInt32($"GXOffset{index}", gxOffsets[GXIndex]);
     }
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 internal void WriteBoundingBox(BinaryWriterEx bw, int index, FLVERHeader header)
 {
     if (BoundingBox == null)
     {
         bw.FillInt32($"MeshBoundingBox{index}", 0);
     }
     else
     {
         bw.FillInt32($"MeshBoundingBox{index}", (int)bw.Position);
         BoundingBox.Write(bw, header);
     }
 }
Ejemplo n.º 12
0
 internal void WriteValues(BinaryWriterEx bw, GPGame game, int index, int unk3ValueIDsOffset)
 {
     if (ValueIDs.Count == 0)
     {
         bw.FillInt32($"Unk3ValueIDsOffset{index}", 0);
     }
     else
     {
         bw.FillInt32($"Unk3ValueIDsOffset{index}", (int)bw.Position - unk3ValueIDsOffset);
         bw.WriteInt32s(ValueIDs);
     }
 }
Ejemplo n.º 13
0
 internal void WriteMembers(BinaryWriterEx bw, int index, List <int> offsetIndex, SortedDictionary <int, List <int> > membersOffsetIndex)
 {
     if (Members == null)
     {
         bw.FillInt32($"MembersOffset{index}", 0);
     }
     else
     {
         bw.FillInt32($"MembersOffset{index}", (int)bw.Position);
         Members.Write(bw, index, offsetIndex, membersOffsetIndex);
     }
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
 internal void WriteBoneIndices(BinaryWriterEx bw, int index, int boneIndicesStart)
 {
     if (BoneIndices.Count == 0)
     {
         // Just a weird case for byte-perfect writing
         bw.FillInt32($"MeshBoneIndices{index}", boneIndicesStart);
     }
     else
     {
         bw.FillInt32($"MeshBoneIndices{index}", (int)bw.Position);
         bw.WriteInt32s(BoneIndices);
     }
 }
Ejemplo n.º 16
0
 internal void WriteSection11s(BinaryWriterEx bw, int index, ref int section11Count)
 {
     if (Section11s.Count == 0)
     {
         bw.FillInt32($"Section7Section11sOffset[{index}]", 0);
     }
     else
     {
         bw.FillInt32($"Section7Section11sOffset[{index}]", (int)bw.Position);
         bw.WriteInt32s(Section11s);
         section11Count += Section11s.Count;
     }
 }
Ejemplo n.º 17
0
 internal void WriteSequences(BinaryWriterEx bw, int customDataIndex, long valueOffset)
 {
     if (Sequences.Count == 0)
     {
         bw.FillInt32($"SequencesOffset[{customDataIndex}]", 0);
     }
     else
     {
         bw.FillInt32($"SequencesOffset[{customDataIndex}]", (int)bw.Position);
         for (int i = 0; i < Sequences.Count; i++)
         {
             Sequences[i].Write(bw, customDataIndex, i, valueOffset);
         }
     }
 }
Ejemplo n.º 18
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);
                }
            }
Ejemplo n.º 19
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);
            }
Ejemplo n.º 20
0
        internal static void WriteHeader(IBND3 bnd, BinaryWriterEx bw, List <BinderFileHeader> fileHeaders)
        {
            bw.BigEndian = bnd.BigEndian || Binder.ForceBigEndian(bnd.Format);

            bw.WriteASCII("BND3");
            bw.WriteFixStr(bnd.Version, 8);

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

            bw.WriteInt32(fileHeaders.Count);
            bw.ReserveInt32("FileHeadersEnd");
            bw.WriteInt32(bnd.Unk18);
            bw.WriteInt32(0);

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

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

            bw.FillInt32($"FileHeadersEnd", (int)bw.Position);
        }
Ejemplo n.º 21
0
 internal void WriteSection5s(BinaryWriterEx bw, int index, ref int section5Count)
 {
     if (Section5s.Count == 0)
     {
         bw.FillInt32($"Section4Section5sOffset[{index}]", 0);
     }
     else
     {
         bw.FillInt32($"Section4Section5sOffset[{index}]", (int)bw.Position);
         for (int i = 0; i < Section5s.Count; i++)
         {
             Section5s[i].Write(bw, section5Count + i);
         }
         section5Count += Section5s.Count;
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Serializes file data to a stream.
        /// </summary>
        protected override void Write(BinaryWriterEx bw)
        {
            bw.BigEndian = BigEndian;
            bw.WriteInt32(1);
            bw.WriteInt32(Unk04);
            bw.WriteInt32(Nodes.Count);
            bw.ReserveInt32("NodesOffset");
            bw.WriteInt32(Edges.Count);
            bw.ReserveInt32("EdgesOffset");
            bw.WriteInt32(Unk18);
            bw.WriteInt32(Unk1C);

            var edgeIndicesAOffsets = new long[Edges.Count];
            var edgeIndicesBOffsets = new long[Edges.Count];

            for (int i = 0; i < Edges.Count; i++)
            {
                edgeIndicesAOffsets[i] = bw.Position;
                bw.WriteInt32s(Edges[i].UnkIndicesA);
                edgeIndicesBOffsets[i] = bw.Position;
                bw.WriteInt32s(Edges[i].UnkIndicesB);
            }

            var nodeNodeIndicesOffsets = new long[Nodes.Count];
            var nodeEdgeIndicesOffsets = new long[Nodes.Count];

            for (int i = 0; i < Nodes.Count; i++)
            {
                Node node = Nodes[i];
                nodeNodeIndicesOffsets[i] = node.ConnectedNodeIndices.Count == 0 ? 0 : bw.Position;
                bw.WriteInt32s(node.ConnectedNodeIndices);
                nodeEdgeIndicesOffsets[i] = node.ConnectedEdgeIndices.Count == 0 ? 0 : bw.Position;
                bw.WriteInt32s(node.ConnectedEdgeIndices);
            }

            bw.FillInt32("EdgesOffset", (int)bw.Position);
            for (int i = 0; i < Edges.Count; i++)
            {
                Edges[i].Write(bw, edgeIndicesAOffsets[i], edgeIndicesBOffsets[i]);
            }

            bw.FillInt32("NodesOffset", (int)bw.Position);
            for (int i = 0; i < Nodes.Count; i++)
            {
                Nodes[i].Write(bw, nodeNodeIndicesOffsets[i], nodeEdgeIndicesOffsets[i]);
            }
        }
Ejemplo n.º 23
0
 internal void WriteSection6s(BinaryWriterEx bw, int index, List <FFXDrawEntityHost> section6s)
 {
     bw.FillInt32($"Section5Section6sOffset[{index}]", (int)bw.Position);
     foreach (FFXDrawEntityHost section6 in Section6s)
     {
         section6.Write(bw, section6s);
     }
 }
Ejemplo n.º 24
0
 internal void WriteNameRefs(BinaryWriterEx bw, int version, int index)
 {
     if (version >= 4)
     {
         bw.FillInt32($"NameRefOffset{index}", (int)bw.Position);
         bw.WriteInt32s(NameReferenceIDs);
     }
 }
Ejemplo n.º 25
0
 internal void WriteTextures(BinaryWriterEx bw, int index, int textureIndex)
 {
     bw.FillInt32($"TextureIndex{index}", textureIndex);
     for (int i = 0; i < Textures.Count; i++)
     {
         Textures[i].Write(bw, textureIndex + i);
     }
 }
Ejemplo n.º 26
0
 internal void WriteSubIDs(BinaryWriterEx bw, int version, int index)
 {
     if (version >= 2)
     {
         bw.FillInt32($"SubIDsOffset{index}", (int)bw.Position);
         bw.WriteInt16s(SubIDs);
     }
 }
Ejemplo n.º 27
0
 internal void WriteFileHeaders(BinaryWriterEx bw, Game game, int index)
 {
     bw.FillInt32($"FileHeadersOffset{index}", (int)bw.Position);
     for (int i = 0; i < Count; i++)
     {
         this[i].Write(bw, game, index, i);
     }
 }
Ejemplo n.º 28
0
 internal void WriteSection2s(BinaryWriterEx bw)
 {
     bw.FillInt32("Section1Section2sOffset", (int)bw.Position);
     for (int i = 0; i < Section2s.Count; i++)
     {
         Section2s[i].Write(bw, i);
     }
 }
Ejemplo n.º 29
0
 internal void WriteSection8s(BinaryWriterEx bw, int index, List <Section8> section8s)
 {
     bw.FillInt32($"Section7Section8sOffset[{index}]", (int)bw.Position);
     foreach (Section8 section8 in Section8s)
     {
         section8.Write(bw, section8s);
     }
 }
Ejemplo n.º 30
0
 internal void WriteSection10s(BinaryWriterEx bw, int index, List <Section10> section10s)
 {
     bw.FillInt32($"Section6Section10sOffset[{index}]", (int)bw.Position);
     foreach (Section10 section10 in Section10s)
     {
         section10.Write(bw, section10s);
     }
 }