示例#1
0
文件: PWN343.cs 项目: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences(section, BoneWeights);
     WriteInfluences(section, BoneIndices);
     WriteVector2(section, TextureCoordinates0);
 }
示例#2
0
文件: PNGT3332.cs 项目: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
     WriteVector2(section, TextureCoordinates0);
 }
示例#3
0
文件: PWNG3433.cs 项目: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences(section, BoneWeights);
     WriteInfluences(section, BoneIndices);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
 }
示例#4
0
        public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
        {
            var items = obj as List <UInt16>;

            for (int i = 0; i < items.Count; i++)
            {
                section.Writer.Write(items[i]);
            }
        }
示例#5
0
        internal void WriteSectionRelocations(WritableSection section)
        {
            section.Header.numRelocations    = (UInt32)section.Fixups.Count;
            section.Header.relocationsOffset = (UInt32)MainStream.Position;

            foreach (var fixup in section.Fixups)
            {
                Writer.Write(fixup.Key);
                WriteSectionReference(GR2.ObjectOffsets[fixup.Value]);
            }
        }
示例#6
0
        internal void WriteSectionMixedMarshallingRelocations(WritableSection section)
        {
            section.Header.numMixedMarshallingData    = (UInt32)section.MixedMarshalling.Count;
            section.Header.mixedMarshallingDataOffset = (UInt32)MainStream.Position;

            foreach (var marshal in section.MixedMarshalling)
            {
                Writer.Write(marshal.Count);
                Writer.Write(GR2.ObjectOffsets[marshal.Obj].Offset);
                WriteSectionReference(GR2.ObjectOffsets[marshal.Type]);
            }
        }
示例#7
0
文件: Vertex.cs 项目: Norbyte/lslib
 protected void WriteHalfVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.W));
 }
示例#8
0
文件: Writer.cs 项目: Norbyte/lslib
        public byte[] Write(object root)
        {
            using (this.Writer = new BinaryWriter(Stream))
            {
                this.Magic = InitMagic();
                WriteMagic(Magic);

                this.Header = InitHeader();
                WriteHeader(Header);

                for (int i = 0; i < Header.numSections; i++)
                {
                    var section = new WritableSection((SectionType)i, this);
                    WriteSectionHeader(section.Header);
                    Sections.Add(section);
                }

                Magic.headersSize = (UInt32)Stream.Position;

                CurrentSection = Sections[(int)SectionType.Main];
                CurrentSection.WriteStruct(root);

                while (ArrayWrites.Count > 0 || StructWrites.Count > 0 || StringWrites.Count > 0)
                {
                    FlushPendingWrites();
                }

                foreach (var defn in Types.Values)
                {
                    Sections[(int)SectionType.Discardable].WriteStructDefinition(defn);
                }

                // We need to do this again to flush strings written by WriteMemberDefinition()
                FlushPendingWrites();

                FinalizeOffsets();

                foreach (var section in Sections)
                {
                    section.Header.first16bit = (UInt32)section.MainStream.Length;
                    section.Header.first8bit = (UInt32)section.MainStream.Length;
                    section.Finish();
                }

                var relocSection = Sections[(int)SectionType.Discardable];
                foreach (var section in Sections)
                {
                    relocSection.WriteSectionRelocations(section);
                    relocSection.WriteSectionMixedMarshallingRelocations(section);
                }

                foreach (var section in Sections)
                {
                    // Pad section size to a multiple of 4
                    while (section.MainStream.Position % 4 > 0)
                        section.Writer.Write((Byte)0);

                    section.MainStream.Flush();
                    section.Header.offsetInFile = (UInt32)Stream.Position;
                    section.Header.uncompressedSize = (UInt32)section.MainStream.Length;
                    section.Header.compressedSize = (UInt32)section.MainStream.Length;
                    Writer.Write(section.MainStream.ToArray());
                }

                foreach (var section in Sections)
                {
                    section.Header.relocationsOffset += relocSection.Header.offsetInFile;
                    section.Header.mixedMarshallingDataOffset += relocSection.Header.offsetInFile;
                }

                var rootStruct = LookupStructDefinition(root.GetType());
                Header.rootType = ObjectOffsets[rootStruct];
                Header.rootNode = new SectionReference(SectionType.Main, 0);
                Header.fileSize = (UInt32)Stream.Length;

                Stream.Seek(Magic.MagicSize + Header.HeaderSize, SeekOrigin.Begin);

                foreach (var section in Sections)
                {
                    WriteSectionHeader(section.Header);
                }

                Header.crc = Header.CalculateCRC(Stream);
                Stream.Seek(0, SeekOrigin.Begin);
                WriteMagic(Magic);
                WriteHeader(Header);

                return Stream.ToArray();
            }
        }
示例#9
0
文件: Writer.cs 项目: Norbyte/lslib
        internal void WriteSectionMixedMarshallingRelocations(WritableSection section)
        {
            section.Header.numMixedMarshallingData = (UInt32)section.MixedMarshalling.Count;
            section.Header.mixedMarshallingDataOffset = (UInt32)MainStream.Position;

            foreach (var marshal in section.MixedMarshalling)
            {
                Writer.Write(marshal.Count);
                Writer.Write(GR2.ObjectOffsets[marshal.Obj].Offset);
                WriteSectionReference(GR2.ObjectOffsets[marshal.Type]);
            }
        }
示例#10
0
文件: Writer.cs 项目: Norbyte/lslib
        internal void WriteSectionRelocations(WritableSection section)
        {
            section.Header.numRelocations = (UInt32)section.Fixups.Count;
            section.Header.relocationsOffset = (UInt32)MainStream.Position;

            foreach (var fixup in section.Fixups)
            {
                Writer.Write(fixup.Key);
                WriteSectionReference(GR2.ObjectOffsets[fixup.Value]);
            }
        }
示例#11
0
文件: P3.cs 项目: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
 }
示例#12
0
文件: Vertex.cs 项目: Norbyte/lslib
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     (obj as Vertex).Serialize(section);
 }
示例#13
0
文件: Vertex.cs 项目: Norbyte/lslib
 public abstract void Serialize(WritableSection section);
示例#14
0
文件: Helpers.cs 项目: Norbyte/lslib
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     var items = obj as List<UInt16>;
     for (int i = 0; i < items.Count; i++)
         section.Writer.Write(items[i]);
 }
示例#15
0
文件: Vertex.cs 项目: Norbyte/lslib
 protected void WriteVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
     section.Writer.Write(v.Z);
     section.Writer.Write(v.W);
 }
示例#16
0
文件: Vertex.cs 项目: Norbyte/lslib
 protected void WriteHalfVector3As4(WritableSection section, Vector3 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write((ushort)0);
 }
示例#17
0
文件: Vertex.cs 项目: Norbyte/lslib
 protected void WriteVector2(WritableSection section, Vector2 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
 }
示例#18
0
        public byte[] Write(object root)
        {
            using (this.Writer = new BinaryWriter(Stream))
            {
                this.Magic = InitMagic();
                WriteMagic(Magic);

                this.Header = InitHeader();
                WriteHeader(Header);

                for (int i = 0; i < Header.numSections; i++)
                {
                    var section = new WritableSection((SectionType)i, this);
                    WriteSectionHeader(section.Header);
                    Sections.Add(section);
                }

                Magic.headersSize = (UInt32)Stream.Position;

                CurrentSection = Sections[(int)SectionType.Main];
                CurrentSection.WriteStruct(root);

                while (ArrayWrites.Count > 0 || StructWrites.Count > 0 || StringWrites.Count > 0)
                {
                    FlushPendingWrites();
                }

                foreach (var defn in Types.Values)
                {
                    Sections[(int)SectionType.Discardable].WriteStructDefinition(defn);
                }

                // We need to do this again to flush strings written by WriteMemberDefinition()
                FlushPendingWrites();

                FinalizeOffsets();

                foreach (var section in Sections)
                {
                    section.Header.first16bit = (UInt32)section.MainStream.Length;
                    section.Header.first8bit  = (UInt32)section.MainStream.Length;
                    section.Finish();
                }

                var relocSection = Sections[(int)SectionType.Discardable];
                foreach (var section in Sections)
                {
                    relocSection.WriteSectionRelocations(section);
                }

                foreach (var section in Sections)
                {
                    relocSection.WriteSectionMixedMarshallingRelocations(section);
                }

                foreach (var section in Sections)
                {
                    // Pad section size to a multiple of the section alignment
                    while ((section.MainStream.Position % section.Header.alignment) > 0)
                    {
                        section.Writer.Write((Byte)0);
                    }

                    section.MainStream.Flush();
                    section.Header.offsetInFile     = (UInt32)Stream.Position;
                    section.Header.uncompressedSize = (UInt32)section.MainStream.Length;
                    section.Header.compressedSize   = (UInt32)section.MainStream.Length;
                    Writer.Write(section.MainStream.ToArray());
                }

                foreach (var section in Sections)
                {
                    section.Header.relocationsOffset          += relocSection.Header.offsetInFile;
                    section.Header.mixedMarshallingDataOffset += relocSection.Header.offsetInFile;
                }

                var rootStruct = LookupStructDefinition(root.GetType(), root);
                Header.rootType = ObjectOffsets[rootStruct];
                Header.rootNode = new SectionReference(SectionType.Main, 0);
                Header.fileSize = (UInt32)Stream.Length;

                Stream.Seek(Magic.MagicSize + Header.Size(), SeekOrigin.Begin);

                foreach (var section in Sections)
                {
                    WriteSectionHeader(section.Header);
                }

                Header.crc = Header.CalculateCRC(Stream);
                Stream.Seek(0, SeekOrigin.Begin);
                WriteMagic(Magic);
                WriteHeader(Header);

                return(Stream.ToArray());
            }
        }
示例#19
0
文件: Vertex.cs 项目: Norbyte/lslib
 protected void WriteInfluences(WritableSection section, BoneWeight v)
 {
     section.Writer.Write(v.A);
     section.Writer.Write(v.B);
     section.Writer.Write(v.C);
     section.Writer.Write(v.D);
 }
示例#20
0
文件: PNG333.cs 项目: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
 }