Ejemplo n.º 1
0
        public void Parse()
        {
            while (Reader.BaseStream.Position < Reader.BaseStream.Length)
            {
                string sectionName   = Encoding.UTF8.GetString(Reader.ReadBytes(4));
                int    sectionLength = Reader.ReadInt32();
                byte[] sectionBytes  = Reader.ReadBytes(sectionLength);

                BinaryReader sectionReader = new BinaryReader(new MemoryStream(sectionBytes));

                switch (sectionName)
                {
                case "VERS":
                    // TODO: Implement parsing of VERS section
                    break;

                case "TEXT":
                    // TODO: Implement parsing of TEXT section
                    break;

                case "SMTL":
                    // TODO: Implement parsing of SMTL section
                    break;

                case "BONE":
                    Bones = BoneReader.ReadAllBones(sectionReader);
                    break;

                case "ANIM":
                    // TODO: Implement parsing of ANIM section
                    break;

                case "MESH":
                    Vertices = VertexReader.ReadAllVertices(sectionReader);
                    Polygons = PolygonReader.ReadAllPolygons(sectionReader);
                    break;

                case "FANM":
                    // TODO: Implement parsing of FANM section
                    break;

                case "FRAM":
                    // TODO: Implement parsing of FRAM section
                    break;

                case "MOTI":
                    Motions = MotionReader.ReadAllMotions(sectionReader);
                    break;

                case "COLL":
                    CollisionBoxes = CollisionBoxReader.ReadAllCollisionBoxes(sectionReader);
                    break;
                }

                sectionReader.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the passed Stream into Puppet structures
        /// </summary>
        /// <param name="data">Stream containing the Puppet file data</param>
        /// <param name="catchExceptions">Flag allowing conditional exception catching</param>
        private void Parse(Stream data, bool catchExceptions = false)
        {
            using (BinaryReader reader = new BinaryReader(data))
            {
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    string sectionName   = Encoding.UTF8.GetString(reader.ReadBytes(4));
                    int    sectionLength = reader.ReadInt32();
                    byte[] sectionBytes  = reader.ReadBytes(sectionLength);

                    using (BinaryReader sectionReader = new BinaryReader(new MemoryStream(sectionBytes)))
                    {
                        try
                        {
                            switch (sectionName)
                            {
                            case "VERS":
                                Version = VersionReader.ReadVersion(sectionReader);
                                break;

                            case "TEXT":
                                Textures = TextureReader.ReadAllTextures(sectionReader);
                                break;

                            case "SMTL":
                                SpecularMaterial = true;
                                break;

                            case "BONE":
                                Bones = BoneReader.ReadAllBones(sectionReader, Version);
                                break;

                            case "EXTR":
                                Extra = ExtraReader.ReadExtra(sectionReader);
                                break;

                            case "ANIM":
                                Animations = AnimationReader.ReadAllAnimations(sectionReader, Version);
                                break;

                            case "MESH":
                                Mesh = MeshReader.ReadMesh(sectionReader, Version);
                                break;

                            case "FANM":
                                // TODO: Implement parsing of FANM section
                                break;

                            case "FRAM":
                                Frames = FrameReader.ReadAllFrames(sectionReader);
                                break;

                            case "MOTI":
                                Motions = MotionReader.ReadAllMotions(sectionReader);
                                break;

                            case "COLL":
                                CollisionBoxes = CollisionBoxReader.ReadAllCollisionBoxes(sectionReader, Version);
                                break;

                            default:
                                Debug.WriteLine($"Unknown section '${sectionName}' with size of ${sectionLength.ToString()} bytes");
                                break;
                            }
                        }
                        catch (Exception e) when(catchExceptions)
                        {
                            Debug.WriteLine($"{e.Message}\n{e.StackTrace}");
                        }
                    }
                }
            }
        }