Beispiel #1
0
            private Model(BinaryReader br)
            {
                var bSpecial = false;
                var header   = Extended.UintLittleEndian(br.ReadUInt32());

                if (header != 0x01000100) //those may be some switches, but I don't know what they mean
                {
                    Memory.Log.WriteLine("WARNING- THIS STAGE IS DIFFERENT! It has weird object section. INTERESTING, TO REVERSE!");
                    bSpecial = true;
                }

                Vertices = Enumerable.Range(0, br.ReadUInt16()).Select(_ => Vertex.Read(br)).ToList().AsReadOnly();
                if (bSpecial && Memory.Encounters.Scenario == 20)
                {
                    Triangles = null;
                    Quads     = null;
                    return;
                }
                br.BaseStream.Seek((br.BaseStream.Position % 4) + 4, SeekOrigin.Current);
                var trianglesCount = br.ReadUInt16();
                var quadsCount     = br.ReadUInt16();

                br.BaseStream.Seek(4, SeekOrigin.Current);
                Triangles = Enumerable.Range(0, trianglesCount).Select(_ => Triangle.Read(br)).ToList().AsReadOnly();
                Quads     = Enumerable.Range(0, quadsCount).Select(_ => Quad.Read(br)).ToList().AsReadOnly();
            }
Beispiel #2
0
            /// <summary>
            /// This is the main class that reads given Stage geometry group. It stores the data into
            /// Model structure
            /// </summary>
            /// <param name="pointer">absolute pointer in buffer for given Stage geometry group</param>
            /// <returns></returns>
            public static Model Read(uint pointer, BinaryReader br)
            {
                bool bSpecial = false;

                br.BaseStream.Seek(pointer, System.IO.SeekOrigin.Begin);
                uint header = Extended.UintLittleEndian(br.ReadUInt32());

                if (header != 0x01000100) //those may be some switches, but I don't know what they mean
                {
                    Memory.Log.WriteLine("WARNING- THIS STAGE IS DIFFERENT! It has weird object section. INTERESTING, TO REVERSE!");
                    bSpecial = true;
                }
                ushort verticesCount = br.ReadUInt16();

                Vertex[] vertices = new Vertex[verticesCount];
                for (int i = 0; i < verticesCount; i++)
                {
                    vertices[i] = Vertex.Read(br);
                }
                if (bSpecial && Memory.Encounters.Scenario == 20)
                {
                    return(new Model());
                }
                br.BaseStream.Seek((br.BaseStream.Position % 4) + 4, SeekOrigin.Current);
                ushort trianglesCount = br.ReadUInt16();
                ushort quadsCount     = br.ReadUInt16();

                br.BaseStream.Seek(4, SeekOrigin.Current);
                Triangle[] triangles = new Triangle[trianglesCount];
                Quad[]     quads     = new Quad[quadsCount];
                if (trianglesCount > 0)
                {
                    for (int i = 0; i < trianglesCount; i++)
                    {
                        triangles[i] = Triangle.Read(br);
                    }
                }
                if (quadsCount > 0)
                {
                    for (int i = 0; i < quadsCount; i++)
                    {
                        quads[i] = Quad.Read(br);
                    }
                }
                return(new Model()
                {
                    vertices = vertices,
                    triangles = triangles,
                    quads = quads
                });
            }