コード例 #1
0
        /// <summary>
        /// Write a GSprite with specified Binary Writer.
        /// </summary>
        public void Write(DhBinaryWriter bw)
        {
            // Write GSprite's Unknown 1.
            bw.WriteS16(Unknown1);

            // Write GSprite's Unknown 2.
            bw.WriteS16(Unknown2);

            // Write GSprite's RGBA.
            bw.WriteS32(RGBA);

            // Loop through GSprite's points.
            for (int i = 0; i < Points.Count; i++)
            {
                // Write the current point.
                Points[i].Write(bw);
            }

            // Loop through the GSprite's Unknown 3 values.
            for (int i = 0; i < Unknown3.Length; i++)
            {
                // Write the current GSprite's Unknown 3 value.
                bw.WriteS32(Unknown3[i]);
            }

            // Write GSprite's Unknown 4.
            bw.WriteF32(Unknown4);

            // Write GSprite's Unknown 5.
            bw.WriteF32(Unknown5);

            // Write GSprite's Unknown 6.
            bw.WriteS32(Unknown6);
        }
コード例 #2
0
ファイル: BinShader.cs プロジェクト: Astral-C/Dolhouse
        /// <summary>
        /// Write a single shader with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Unknown 1.
            bw.Write(Unknown1);

            // Write Unknown 2.
            bw.Write(Unknown2);

            // Write Unknown 3.
            bw.Write(Unknown3);

            // Write Tint.
            bw.WriteS32(Tint);

            // Write Unknown 4. (Padding)
            bw.Write(Unknown4);

            // Loop through Material Indices.
            for (int i = 0; i < 8; i++)
            {
                // Write a material index.
                bw.WriteS16(MaterialIndices[i]);
            }

            // Loop through Unknown 5. (Indices?)
            for (int i = 0; i < 8; i++)
            {
                // Write a Unknown 5 value.
                bw.WriteS16(Unknown5[i]);
            }
        }
コード例 #3
0
ファイル: GraphObject.cs プロジェクト: opeyx/Dolhouse
        public void Write(DhBinaryWriter bw)
        {
            // Write shader index.
            bw.WriteS16(ShaderIndex);


            // Write batch index.
            bw.WriteS16(BatchIndex);
        }
コード例 #4
0
ファイル: GraphObject.cs プロジェクト: opeyx/Dolhouse
        /// <summary>
        /// Write a single graph object with BinaryWriter.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        /// <param name="graphObjectsOffset">Offset to the graph objects.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write parent graphobject index.
            bw.WriteS16(ParentIndex);

            // Write child graphobject index.
            bw.WriteS16(ChildIndex);

            // Write next graphobject index.
            bw.WriteS16(NextIndex);

            // Write previous graphobject index.
            bw.WriteS16(PreviousIndex);

            // Write renderflags.
            bw.WriteU16((ushort)RenderFlags);

            // Write unknown 1.
            bw.WriteU16(Unknown1);

            // Write scale.
            bw.WriteVec3(Scale);

            // Write rotation.
            bw.WriteVec3(Rotation);

            // Write position.
            bw.WriteVec3(Position);

            // Write bounding box minimum.
            bw.WriteVec3(BoundingBoxMinimum);

            // Write bounding box maximum.
            bw.WriteVec3(BoundingBoxMaximum);

            // Write bounding sphere radius.
            bw.WriteF32(BoundingSphereRadius);

            // Write part count.
            bw.WriteS16((short)Parts.Count);

            // Write unknown 3.
            bw.WriteU16(Unknown3);

            // Write part offset. (CALCULATED)
            bw.WriteU32(0);

            // Write unknown 4.
            bw.WriteU32s(Unknown4);

            // Write unknown 4. TODO - Why does demolisher only read file if padding is written twice??
            bw.WriteU32s(Unknown4);
        }
コード例 #5
0
        /// <summary>
        /// Write a single primitive vertex with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw, Attributes attributes)
        {
            // Check if Matrix Index exists.
            if (attributes.HasFlag(Attributes.PosNormMatrix))
            {
                // Write BiNormal Index.
                bw.WriteS16((short)MatrixIndex);
            }

            // Check if Position Index exists.
            if (attributes.HasFlag(Attributes.Position))
            {
                // Write BiNormal Index.
                bw.WriteS16((short)PositionIndex);
            }

            // Check if Normal Index exists.
            if (attributes.HasFlag(Attributes.Normal))
            {
                // Write Normal Index.
                bw.WriteS16((short)NormalIndex);

                // Check if NBT Indices exists.
                if (attributes.HasFlag(Attributes.NormalBinormalTangent))
                {
                    // Write BiNormal Index.
                    bw.WriteS16((short)BiNormalIndex);

                    // Write Tangent Index.
                    bw.WriteS16((short)TangentIndex);
                }
            }

            // Check if Color0 Index exists.
            if (attributes.HasFlag(Attributes.Color0))
            {
                // Write Color1 Index.
                bw.WriteS16((short)ColorIndex[0]);
            }

            // Check if Color1 Index exists.
            if (attributes.HasFlag(Attributes.Color1))
            {
                // Write Color1 Index.
                bw.WriteS16((short)ColorIndex[1]);
            }

            // Loop through UV Indices.
            for (int i = 0; i < UVIndex.Length; i++)
            {
                // Check if current UV Index exists.
                if (attributes.HasFlag((Attributes)(1 << (13 + i))))
                {
                    // Write UV Index.
                    bw.WriteS16((short)UVIndex[i]);
                }
            }
        }
コード例 #6
0
ファイル: Batch.cs プロジェクト: opeyx/Dolhouse
        /// <summary>
        /// Write a single batch.
        /// </summary>
        /// <param name="bw">The binarywriter to write with.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write face count.
            bw.WriteU16(FaceCount);

            // Write list size. (CALCULATED)
            bw.WriteS16(0);

            // Write vertex attributes.
            bw.WriteU32((uint)VertexAttributes);

            // Write normals flag.
            bw.Write(UseNormals ? 1 : 0);

            // Write position winding flag.
            bw.Write(Positions);

            // Write uv count.
            bw.Write(UvCount);

            // Write NBT flag.
            bw.Write(UseNBT ? 1 : 0);

            // Write primitive offset. (CALCULATED)
            bw.WriteU32(0);

            // Write unknown 1.
            bw.WriteS32s(Unknown1); // 8 bytes
        }
コード例 #7
0
 public void Write(DhBinaryWriter bw, List <long> frameDataOffsets)
 {
     frameDataOffsets.Add(bw.GetStream().Position);
     for (int i = 0; i < TexObjIndicies.Length; i++)
     {
         bw.WriteS16(TexObjIndicies[i]);
     }
 }
コード例 #8
0
        /// <summary>
        /// Write a single primitive vertex with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Matrix Index.
            bw.WriteS16(MatrixIndex);

            // Write Position Index.
            bw.WriteS16(PositionIndex);

            // Write Normal Index.
            bw.WriteS16(NormalIndex);

            // Write BiNormal Index.
            bw.WriteS16(BiNormalIndex);

            // Write Tangent Index.
            bw.WriteS16(TangentIndex);

            // Loop through the ColorIndex array.
            for (int i = 0; i < 2; i++)
            {
                // Write ColorIndex value.
                bw.WriteS16(ColorIndex[i]);
            }

            // Loop through the UVIndex array.
            for (int i = 0; i < 8; i++)
            {
                // Write UVIndex value.
                bw.WriteS16(UVIndex[i]);
            }
        }
コード例 #9
0
        /// <summary>
        /// Write a PrmEntry with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Hash.
            bw.WriteU16(Hash);

            // Write NameLength.
            bw.WriteU16(NameLength);

            // Write Name.
            bw.WriteStr(Name);

            // Write ValueLength.
            bw.WriteU32(ValueLength);

            // Check Type.
            switch (Type)
            {
            case PrmType.BYTE:

                // Write Value as a byte.
                bw.Write((byte)Value);
                break;

            case PrmType.SHORT:

                // Write Value as a short.
                bw.WriteS16((short)Value);
                break;

            case PrmType.INT:

                // Write Value as a int.
                bw.WriteS32((int)Value);
                break;

            case PrmType.FLOAT:

                // Write Value as a float.
                bw.WriteF32((float)Value);
                break;

            case PrmType.RGBA:

                // Write Value as a Clr4.
                bw.WriteClr4((Clr4)Value);
                break;

            case PrmType.VECTOR3:

                // Write Value as a Vector3.
                bw.WriteVec3((Vec3)Value);
                break;

            default:
                throw new NotImplementedException("PRM parameter entry type is unknown!");
            }
        }
コード例 #10
0
ファイル: Material.cs プロジェクト: opeyx/Dolhouse
        /// <summary>
        /// Write a single material with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Index.
            bw.WriteS16(Index);

            // Write Unknown 1. (Unused index?)
            bw.WriteS16(Unknown1);

            // Write U-Wrapping.
            bw.Write(WrapU);

            // Write V-Wrapping.
            bw.Write(WrapV);

            // Write Unknown 2. (Flags?)
            bw.WriteS16(Unknown2);

            // Write Unknown 3.
            bw.WriteS32s(Unknown3);
        }
コード例 #11
0
        public Stream Write()
        {
            // Buffer for new TXP File
            Stream stream = new MemoryStream();

            // Define a binary writer to write with.
            DhBinaryWriter bw = new DhBinaryWriter(stream, DhEndian.Big);

            // Write the fixed Unknown values
            bw.WriteU16(1);
            bw.WriteU16(0);

            // Write Entry Count
            bw.WriteU16((ushort)TXPEntries.Count);

            // Write Frame Count
            bw.WriteU16(FrameCount);

            //Calculate and write frame data offset
            bw.WriteU32((uint)(0xC * TXPEntries.Count));

            bw.SaveOffset(0);

            //Write dummy entry headers
            for (int i = 0; i < TXPEntries.Count; i++)
            {
                bw.WriteU64(0);
                bw.WriteU32(0);
            }

            //Make a list to store the offsets for each entry's frame data
            List <long> frameDataOffsets = new List <long>();

            //Write the entries
            for (int entry = 0; entry < TXPEntries.Count; entry++)
            {
                TXPEntries[entry].Write(bw, frameDataOffsets);
            }

            bw.LoadOffset(0);
            //Write frame data offsets
            for (int i = 0; i < TXPEntries.Count; i++)
            {
                bw.WriteU16(1);
                bw.WriteS16(TXPEntries[i].MaterialIndex);
                bw.WriteU32(0);
                bw.WriteU32((uint)frameDataOffsets[i]);
            }

            // Returns the TXP as a stream
            return(stream);
        }
コード例 #12
0
 /// <summary>
 /// Write a single vertex.
 /// </summary>
 /// <param name="bw">The binarywriter to write with.</param>
 public void Write(DhBinaryWriter bw, Attributes attributes)
 {
     // Loop through indices.
     for (int i = 0; i < Indices.Length; i++)
     {
         // Make sure index is not null.
         if (Indices[i] != null)
         {
             // Write Index.
             bw.WriteS16((short)Indices[i]);
         }
     }
 }
コード例 #13
0
        /// <summary>
        /// Write a single triangle data entry with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Vertex Indices.
            bw.WriteS16s(VertexIndices);

            // Write Normal Index.
            bw.WriteS16(NormalIndex);

            // Write Edge Tangent Indices.
            bw.WriteS16s(EdgeTangentIndices);

            // Write Plane Point Index.
            bw.WriteS16(PlanePointIndex);

            // Write PlaneD Value.
            bw.WriteF32(PlaneDValue);

            // Write Unknown 1.
            bw.WriteS16(Unknown1);

            // Write Unknown 2.
            bw.WriteS16(Unknown2);
        }
コード例 #14
0
ファイル: TXP.cs プロジェクト: opeyx/Dolhouse
        /// <summary>
        /// Write a single entry header.
        /// </summary>
        /// <param name="bw">The binarywriter to write with.</param>
        public void WriteHeader(DhBinaryWriter bw)
        {
            // Write Unknown 1.
            bw.WriteS16(Unknown1);

            // Write Material Index.
            bw.WriteU16(MaterialIndex);

            // Write Unknown 2.
            bw.WriteS32(Unknown2);

            // Write Indices Offset.
            bw.WriteU32(IndicesOffset);
        }
コード例 #15
0
        /// <summary>
        /// Write a single material with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Index.
            bw.WriteS16(Index);

            // Write Unknown 1. (Unused index?)
            bw.WriteS16(Unknown1);

            // Write U-Wrapping.
            bw.Write(WrapU);

            // Write V-Wrapping.
            bw.Write(WrapV);

            // Write Unknown 2. (Flags?)
            bw.WriteS16(Unknown2);

            // Loop through the Unknown 3 values.
            for (int i = 0; i < Unknown3.Length; i++)
            {
                // Write the current Unknown 3 value.
                bw.WriteS32(Unknown3[i]);
            }
        }
コード例 #16
0
        /// <summary>
        /// Write a single primitive vertex with specified Binary Writer.
        /// </summary>
        /// <param name="bw">Binary Writer to use.</param>
        public void Write(DhBinaryWriter bw)
        {
            // Write Primitive type.
            bw.Write(Type);

            // Write number of primitive vertices.
            bw.WriteS16((short)Vertices.Count);

            // Loop through primitive vertices.
            for (int i = 0; i < Vertices.Count; i++)
            {
                // Write primitive vertex.
                Vertices[i].Write(bw);
            }
        }
コード例 #17
0
ファイル: BIN.cs プロジェクト: opeyx/Dolhouse
        /// <summary>
        /// Creates a byte array from this BIN.
        /// </summary>
        /// <returns>The BIN as a byte array.</returns>
        public byte[] Write()
        {
            // Define a stream to hold our BIN data.
            MemoryStream stream = new MemoryStream();

            // Define a binary writer to write with.
            DhBinaryWriter bw = new DhBinaryWriter(stream, DhEndian.Big);

            // Define a buffer to store our offsets.
            uint[] offsets = new uint[21];

            // Write version.
            bw.Write(Version);

            // Write model Name.
            bw.WriteFixedStr(ModelName, 11);

            // Write offsets.
            bw.WriteU32s(Offsets);

            // Make sure bin has textures.
            if (Textures.Count > 0)
            {
                // Set textures offset.
                offsets[0] = (uint)bw.Position();

                // Define a array to temporarily
                uint[] textureDataOffsets = new uint[Textures.Count];

                // Write texture headers. (CALCULATED)
                bw.Write(new byte[Textures.Count * 0x0C]);

                // Pad to nearest whole 32.
                bw.WritePadding32();

                // Loop through textures to write texture data.
                for (int i = 0; i < textureDataOffsets.Length; i++)
                {
                    // Get actual offset of texture data.
                    textureDataOffsets[i] = (uint)bw.Position() - offsets[0];

                    // Write texture data.
                    bw.Write(Textures[i].Data);
                }

                // Store this so we can resume after writing the texture headers.
                long currentOffset = (uint)bw.Position();

                // Pad to nearest whole 32.
                bw.WritePadding32();

                // Goto textures offset.
                bw.Goto(offsets[0]);

                // Loop through textures to write texture headers.
                for (int i = 0; i < Textures.Count; i++)
                {
                    // Write texture width.
                    bw.WriteU16(Textures[i].Width);

                    // Write texture height.
                    bw.WriteU16(Textures[i].Height);

                    // Write texture format.
                    bw.Write((byte)Textures[i].Format);

                    // Write texture alpha flag.
                    bw.Write(Textures[i].AlphaFlag);

                    // Write padding.
                    bw.WriteU16(0);

                    // Write texture dataoffset.
                    bw.WriteU32(textureDataOffsets[i]);
                }

                // Goto resume point.
                bw.Goto(currentOffset);

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // Make sure bin has materials.
            if (Materials.Count > 0)
            {
                // Set materials offset.
                offsets[1] = (uint)bw.Position();

                // Loop through materials.
                for (int i = 0; i < Materials.Count; i++)
                {
                    // Write material.
                    Materials[i].Write(bw);
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // Make sure bin has positions.
            if (Positions.Count > 0)
            {
                // Set positions offset.
                offsets[2] = (uint)bw.Position();

                // Loop through positions.
                for (int i = 0; i < Positions.Count; i++)
                {
                    // Write position.
                    bw.WriteS16s(new short[] { (short)(Positions[i].X * 256.0f), (short)(Positions[i].Y * 256.0f), (short)(Positions[i].Z * 256.0f) });
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // Make sure bin has normals.
            if (Normals.Count > 0)
            {
                // Set normals offset.
                offsets[3] = (uint)bw.Position();

                // Loop through normals.
                for (int i = 0; i < Normals.Count; i++)
                {
                    // Write normal.
                    bw.WriteVec3(Normals[i]);
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // SKIP COLOR0
            offsets[4] = (uint)0;

            // SKIP COLOR1
            offsets[5] = (uint)0;

            // Make sure bin has texture coordinates 0.
            if (TextureCoordinates0.Count > 0)
            {
                // Set texture coordinates 0 offset.
                offsets[6] = (uint)bw.Position();

                // Loop through texture coordinates 0.
                for (int i = 0; i < TextureCoordinates0.Count; i++)
                {
                    // Write texture coordinate 0.
                    bw.WriteVec2(TextureCoordinates0[i]);
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // SKIP TEXTURE COORDINATES 1
            offsets[7] = (uint)0;

            // SKIP TEXTURE COORDINATES 2 (?)
            offsets[8] = (uint)0;

            // SKIP TEXTURE COORDINATES 3 (?)
            offsets[9] = (uint)0;

            // Make sure bin has shaders.
            if (Shaders.Count > 0)
            {
                // Set shaders offset.
                offsets[10] = (uint)bw.Position();

                // Loop through shaders.
                for (int i = 0; i < Shaders.Count; i++)
                {
                    // Write shader.
                    Shaders[i].Write(bw);
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // Make sure bin has batches.
            if (Batches.Count > 0)
            {
                // Set batches offset.
                offsets[11] = (uint)bw.Position();

                // Loop through batches.
                for (int i = 0; i < Batches.Count; i++)
                {
                    // Write batch headers.
                    Batches[i].Write(bw);
                }

                // Pad to nearest whole 32.
                bw.WritePadding32();

                // We need to store this stuff somewhere
                long[] listStarts = new long[Batches.Count];
                long[] listEnds   = new long[Batches.Count];

                // Loop through batches. (Write primitives)
                for (int i = 0; i < Batches.Count; i++)
                {
                    // We'll store this offset for later.
                    listStarts[i] = bw.Position();

                    // Loop through primitives.
                    for (int y = 0; y < Batches[i].Primitives.Count; y++)
                    {
                        // Write primitive.
                        Batches[i].Primitives[y].Write(bw, Batches[i].VertexAttributes);
                    }

                    // We'll store this offset for later.
                    listEnds[i] = bw.Position();
                }

                // This offset is where we'll continue writing from.
                long currentOffset = bw.Position();

                // Loop through batches. (Write offsets)
                for (int i = 0; i < Batches.Count; i++)
                {
                    // Goto current batch's offset.
                    bw.Goto(offsets[11] + i * 24);

                    // Skip 2 bytes.
                    bw.Sail(2);

                    // Write list size represented as 32 byte blocks.
                    bw.WriteS16((short)(Math.Ceiling((float)(listEnds[i] - listStarts[i]) / 32)));

                    // Skip 8 bytes.
                    bw.Sail(8);

                    // Write primitive list offset.
                    bw.WriteU32((uint)(listStarts[i] - offsets[11]));
                }

                // Goto continue point we saved earlier.
                bw.Goto(currentOffset);

                // Pad to nearest whole 32.
                bw.WritePadding32();
            }

            // Make sure bin has graphobjects.
            if (GraphObjects.Count > 0)
            {
                // Set graphObjects offset.
                offsets[12] = (uint)bw.Position();

                // Loop through graphObjects.
                for (int i = 0; i < GraphObjects.Count; i++)
                {
                    // Write graphObject headers.
                    GraphObjects[i].Write(bw);
                }

                // Pad to nearest whole 16.
                bw.WritePadding16();

                // Array to hold graphobject's parts offset.
                long[] graphObjectsPartsOffsets = new long[GraphObjects.Count];

                // Loop through graphObjects. (Write parts)
                for (int i = 0; i < GraphObjects.Count; i++)
                {
                    // Store this graphobject's part offset.
                    graphObjectsPartsOffsets[i] = bw.Position();

                    // Loop through graphobject's parts.
                    for (int y = 0; y < GraphObjects[i].Parts.Count; y++)
                    {
                        // Write graphobject's parts.
                        GraphObjects[i].Parts[y].Write(bw);
                    }
                }

                // This offset is where we'll continue writing from.
                long currentOffset = bw.Position();

                // Loop through graphObjects. (Write offsets)
                for (int i = 0; i < GraphObjects.Count; i++)
                {
                    // Goto current graphobject's part offset.
                    bw.Goto(offsets[12] + (i * 140));

                    // Skip 80 bytes.
                    bw.Sail(80);

                    // Write graphobject's part offset.
                    bw.WriteU32((uint)(graphObjectsPartsOffsets[i] - offsets[12]));
                }

                // Goto continue point we saved earlier.
                bw.Goto(currentOffset);
            }

            // Goto offsets section.
            bw.Goto(12);

            // Write offsets.
            bw.WriteU32s(offsets);

            // Goto end of file.
            bw.Back(0);

            // Pad to nearest whole 16.
            bw.WritePadding16();

            // Return the BIN as a byte array.
            return(stream.ToArray());
        }