Exemple #1
0
        /// <summary>
        /// Read a single entry from BAS.
        /// </summary>
        /// <param name="br">Binary Reader to use.</param>
        public BasEntry(DhBinaryReader br)
        {
            // Read Id.
            Id = br.ReadU32();

            // Read Gain.
            Gain = br.ReadF32();

            // Read Delay / Length.
            Delay = br.ReadF32();

            // Read Pitch.
            Pitch = br.ReadF32();

            // Read Unknown 1.
            Unknown1 = br.ReadS32();

            // Read Balance.
            Balance = br.Read();

            // Read Unknown 2.
            Unknown2 = br.Read();

            // Read Unknown 3.
            Unknown3 = br.Read();

            // Read Unknown 4.
            Unknown4 = br.Read();

            // Read Padding.
            Padding = br.ReadU32s(2);
        }
Exemple #2
0
        /// <summary>
        /// Read a single graph object from BIN.
        /// </summary>
        /// <param name="br">Binary Reader to use.</param>
        /// <param name="graphObjectOffset">Offset to the graph objects.</param>
        public GraphObject(DhBinaryReader br, uint graphObjectOffset) // 112 bytes long
        {
            // Read Parent Index.
            ParentIndex = br.ReadS16();

            // Read Child Index.
            ChildIndex = br.ReadS16();

            // Read Next Index.
            NextIndex = br.ReadS16();

            // Read Previous Index.
            PreviousIndex = br.ReadS16();

            // Read Render Flags.
            RenderFlags = (GraphObjectRenderFlags)br.ReadU16();

            // Unknown 1. (Padding?)
            Unknown1 = br.ReadU16();

            // Read Scale.
            Scale = br.ReadVec3();

            // Read Rotation.
            Rotation = br.ReadVec3();

            // Read Position
            Position = br.ReadVec3();

            // Read Bounding Box Minimum.
            BoundingBoxMinimum = br.ReadVec3();

            // Read Bounding Box Maximum.
            BoundingBoxMaximum = br.ReadVec3();

            // Read Bounding Sphere Radius.
            BoundingSphereRadius = br.ReadF32();

            // Read Parent Index.
            PartCount = br.ReadS16();

            // Unknown 3. (Padding?)
            Unknown3 = br.ReadU16();

            // Read Parent Index.
            PartOffset = br.ReadS32();

            // Unknown 4. (Padding?)
            Unknown4 = br.ReadU32s(7);

            // Initialize a new list to hold parts.
            Parts = new List <BinGraphObjectPart>();

            // Offset to continue reading from.
            long currentPosition = br.Position();

            // Goto graphobject's parts.
            br.Goto(graphObjectOffset + PartOffset);

            // Loop through parts.
            for (int i = 0; i < PartCount; i++)
            {
                // Read part and add it to the list of parts.
                Parts.Add(new BinGraphObjectPart(br));
            }

            // Go back to return offset we saved earlier.
            br.Goto(currentPosition);
        }
Exemple #3
0
        /// <summary>
        /// Reads BIN from a byte array.
        /// </summary>
        /// <param name="data">The byte array containing the BIN data.</param>
        public BIN(byte[] data)
        {
            // Define a binary reader to read with.
            DhBinaryReader br = new DhBinaryReader(data, DhEndian.Big);

            // Read bin version.
            Version = br.Read();

            // Make sure the bin version is either 0x01 or 0x02.
            if (Version == 0x00 || Version > 0x02)
            {
                throw new Exception($"[BIN] {Version} is not a valid version!");
            }

            // Read bin model name.
            ModelName = br.ReadFixedStr(11);

            // Define a new list to hold the bin's offsets.
            Offsets = br.ReadU32s(21);

            // Go to the bin graph object offset.
            br.Goto(Offsets[12]);

            // Get first graph object, then all of it's attached graph objects.
            GraphObjects = GetGraphObjects(br, 0);


            // Make sure bin batches has a offset.
            if (Offsets[11] != 0)
            {
                // Go to the bin batches offset.
                br.Goto(Offsets[11]);

                // Define a new list to hold the bin's batches.
                Batches = new List <Batch>();

                // Loop through batches.
                for (int i = 0; i < GetBatchCount(); i++)
                {
                    // Read a batch and add it to the batch list.
                    Batches.Add(new Batch(br, Offsets[11]));
                }
            }


            // Make sure bin shaders has a offset.
            if (Offsets[10] != 0)
            {
                // Go to the bin shaders offset.
                br.Goto(Offsets[10]);

                // Define a new list to hold the bin's shaders.
                Shaders = new List <Shader>();

                // Loop through shaders.
                for (int i = 0; i < GetShaderCount(); i++)
                {
                    // Read a shader and add it to the shader list.
                    Shaders.Add(new Shader(br));
                }
            }


            // Make sure bin texture coordinates 1 has a offset.
            if (Offsets[7] != 0)
            {
                // Go to the bin texture coordinates 1 offset.
                br.Goto(Offsets[7]);

                // Define a new list to hold the bin's texture coordinates 1.
                TextureCoordinates1 = new List <Vec2>();

                // Loop through texture coordinates 1.
                for (int i = 0; i < GetTexCoordinate1Count(); i++)
                {
                    // Read a bin texture coordinates and add it to the texture coordinates 1 list.
                    TextureCoordinates1.Add(br.ReadVec2());
                }
            }


            // Make sure bin texture coordinates 0 has a offset.
            if (Offsets[6] != 0)
            {
                // Go to the bin texture coordinates 0 offset.
                br.Goto(Offsets[6]);

                // Define a new list to hold the bin's texture coordinates 0.
                TextureCoordinates0 = new List <Vec2>();

                // Loop through texture coordinates 0.
                for (int i = 0; i < GetTexCoordinate0Count(); i++)
                {
                    // Read a bin texture coordinates 0 and add it to the texture coordinates 0 list.
                    TextureCoordinates0.Add(br.ReadVec2());
                }
            }


            // WE'RE SKIPPING COLOR0 AND COLOR1! (Offset5 and Offset4)


            // Make sure bin normals has a offset.
            if (Offsets[3] != 0)
            {
                // Go to the bin normals offset.
                br.Goto(Offsets[3]);

                // Define a new list to hold the bin's normals.
                Normals = new List <Vec3>();

                // Loop through normals.
                for (int i = 0; i < GetNormalCount(); i++)
                {
                    // Read a bin normal and add it to the normals list.
                    Normals.Add(br.ReadVec3());
                }
            }


            // Make sure bin positions has a offset.
            if (Offsets[2] != 0)
            {
                // Go to the bin positions offset.
                br.Goto(Offsets[2]);

                // Define a new list to hold the bin's positions.
                Positions = new List <Vec3>();

                // Loop through positions.
                for (int i = 0; i < GetPositionCount(); i++)
                {
                    // Read a bin position and add it to the positions list.
                    Positions.Add(new Vec3(br.ReadF16() / 256.0f, br.ReadF16() / 256.0f, br.ReadF16() / 256.0f));
                }
            }


            // Make sure bin materials has a offset.
            if (Offsets[1] != 0)
            {
                // Go to the bin materials offset.
                br.Goto(Offsets[1]);

                // Define a new list to hold the bin's materials.
                Materials = new List <Material>();

                // Loop through materials.
                for (int i = 0; i < GetMaterialCount(); i++)
                {
                    // Read a bin material and add it to the materials list.
                    Materials.Add(new Material(br));
                }
            }


            // Make sure bin textures has a offset.
            if (Offsets[0] != 0)
            {
                // Go to the bin textures offset.
                br.Goto(Offsets[0]);

                // Define a new list to hold the bin's textures.
                Textures = new List <BTI>();

                // Loop through textures.
                for (int i = 0; i < GetTextureCount(); i++)
                {
                    // Read a bin textures and add it to the textures list.
                    Textures.Add(new BTI(br, Offsets[0]));
                }
            }
        }