private Leaf[] GetLeafs(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_LEAFS];

            Leaf[] leafData = new Leaf[lump.length / 56];
            stream.Position = lump.offset;

            for (int i = 0; i < leafData.Length; i++)
            {
                leafData[i] = new Leaf();

                leafData[i].contents = (ContentsFlag)UtilityReader.ReadInt(stream);
                leafData[i].cluster  = UtilityReader.ReadShort(stream);
                leafData[i].area     = UtilityReader.ReadShort(stream);
                leafData[i].flags    = UtilityReader.ReadShort(stream);

                leafData[i].mins    = new short[3];
                leafData[i].mins[0] = UtilityReader.ReadShort(stream);
                leafData[i].mins[1] = UtilityReader.ReadShort(stream);
                leafData[i].mins[2] = UtilityReader.ReadShort(stream);

                leafData[i].maxs    = new short[3];
                leafData[i].maxs[0] = UtilityReader.ReadShort(stream);
                leafData[i].maxs[1] = UtilityReader.ReadShort(stream);
                leafData[i].maxs[2] = UtilityReader.ReadShort(stream);

                leafData[i].firstleafface   = UtilityReader.ReadUShort(stream);
                leafData[i].numleaffaces    = UtilityReader.ReadUShort(stream);
                leafData[i].firstleafbrush  = UtilityReader.ReadUShort(stream);
                leafData[i].numleafbrushes  = UtilityReader.ReadUShort(stream);
                leafData[i].leafWaterDataID = UtilityReader.ReadShort(stream);
            }

            return(leafData);
        }
        private Header GetHeader(Stream stream)
        {
            Header header = new Header();

            header.ident = UtilityReader.ReadInt(stream);

            if (header.ident == (int)('V' + ('B' << 8) + ('S' << 16) + ('P' << 24)))
            {
                UtilityReader.BigEndian = false;
            }
            else
            {
                UtilityReader.BigEndian = true;
            }

            header.version = UtilityReader.ReadInt(stream);
            header.lumps   = new Lump[64];
            for (int i = 0; i < header.lumps.Length; i++)
            {
                header.lumps[i]         = new Lump();
                header.lumps[i].type    = (LumpType)i;
                header.lumps[i].offset  = UtilityReader.ReadInt(stream);
                header.lumps[i].length  = UtilityReader.ReadInt(stream);
                header.lumps[i].version = UtilityReader.ReadInt(stream);
                header.lumps[i].fourCC  = UtilityReader.ReadInt(stream);
            }
            header.mapRevision = UtilityReader.ReadInt(stream);
            return(header);
        }
        private Node[] GetNodes(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_NODES];

            Node[] nodesData = new Node[lump.length / 32];
            stream.Position = lump.offset;

            for (int i = 0; i < nodesData.Length; i++)
            {
                nodesData[i] = new Node();

                nodesData[i].planenum = UtilityReader.ReadInt(stream);

                nodesData[i].children    = new int[2];
                nodesData[i].children[0] = UtilityReader.ReadInt(stream);
                nodesData[i].children[1] = UtilityReader.ReadInt(stream);

                nodesData[i].mins    = new short[3];
                nodesData[i].mins[0] = UtilityReader.ReadShort(stream);
                nodesData[i].mins[1] = UtilityReader.ReadShort(stream);
                nodesData[i].mins[2] = UtilityReader.ReadShort(stream);

                nodesData[i].maxs    = new short[3];
                nodesData[i].maxs[0] = UtilityReader.ReadShort(stream);
                nodesData[i].maxs[1] = UtilityReader.ReadShort(stream);
                nodesData[i].maxs[2] = UtilityReader.ReadShort(stream);

                nodesData[i].firstface = UtilityReader.ReadUShort(stream);
                nodesData[i].numfaces  = UtilityReader.ReadUShort(stream);
                nodesData[i].area      = UtilityReader.ReadShort(stream);
                nodesData[i].paddding  = UtilityReader.ReadShort(stream);
            }

            return(nodesData);
        }
        private string GetEntities(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_ENTITIES];

            stream.Position = lump.offset;
            byte[] data = UtilityReader.ReadBytes(stream, lump.length);
            return(System.Text.Encoding.ASCII.GetString(data));
        }
        private int[] GetSurfedges(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_SURFEDGES];

            int[] surfedges = new int[lump.length / 4];
            stream.Position = lump.offset;

            for (int i = 0; i < lump.length / 4; i++)
            {
                surfedges[i] = UtilityReader.ReadInt(stream);
            }

            return(surfedges);
        }
        private SurfFlag[] GetTextureInfo(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_TEXINFO];

            SurfFlag[] textureData = new SurfFlag[lump.length / 72];
            stream.Position = lump.offset;

            for (int i = 0; i < textureData.Length; i++)
            {
                stream.Position += 64;
                textureData[i]   = (SurfFlag)UtilityReader.ReadInt(stream);
                stream.Position += 4;
            }

            return(textureData);
        }
        private Vector3[] GetVertices(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_VERTEXES];

            stream.Position = lump.offset;
            Vector3[] vertices = new Vector3[(lump.length / 3) / 4];

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i]   = new Vector3();
                vertices[i].x = UtilityReader.ReadFloat(stream);
                vertices[i].y = UtilityReader.ReadFloat(stream);
                vertices[i].z = UtilityReader.ReadFloat(stream);
            }

            return(vertices);
        }
        private List <ushort[]> GetEdges(Stream stream)
        {
            List <ushort[]> edges = new List <ushort[]>();
            Lump            lump  = header.lumps[(int)LumpType.LUMP_EDGES];

            stream.Position = lump.offset;

            for (int i = 0; i < (lump.length / 2) / 2; i++)
            {
                ushort[] edge = new ushort[2];
                edge[0] = UtilityReader.ReadUShort(stream);
                edge[1] = UtilityReader.ReadUShort(stream);
                edges.Add(edge);
            }

            return(edges);
        }
        private Brush[] GetBrushes(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_BRUSHES];

            Brush[] brushes = new Brush[lump.length / 12];
            stream.Position = lump.offset;

            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i] = new Brush();

                brushes[i].firstside = UtilityReader.ReadInt(stream);
                brushes[i].numsides  = UtilityReader.ReadInt(stream);
                brushes[i].contents  = (ContentsFlag)UtilityReader.ReadInt(stream);
            }

            return(brushes);
        }
        private Brushside[] GetBrushsides(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_BRUSHES];

            Brushside[] brushsides = new Brushside[lump.length / 8];
            stream.Position = lump.offset;

            for (int i = 0; i < brushsides.Length; i++)
            {
                brushsides[i] = new Brushside();

                brushsides[i].planenum = UtilityReader.ReadUShort(stream);
                brushsides[i].texinfo  = UtilityReader.ReadShort(stream);
                brushsides[i].dispinfo = UtilityReader.ReadShort(stream);
                brushsides[i].bevel    = UtilityReader.ReadShort(stream);
            }

            return(brushsides);
        }
        private Face[] GetFaces(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_FACES];

            stream.Position = lump.offset;
            Face[] faces = new Face[lump.length / 56];

            for (int i = 0; i < faces.Length; i++)
            {
                faces[i]                                = new Face();
                faces[i].planeNumber                    = UtilityReader.ReadUShort(stream);
                faces[i].side                           = UtilityReader.ReadByte(stream);
                faces[i].onNode                         = UtilityReader.ReadByte(stream);
                faces[i].firstEdge                      = UtilityReader.ReadInt(stream);
                faces[i].numEdges                       = UtilityReader.ReadShort(stream);
                faces[i].texinfo                        = UtilityReader.ReadShort(stream);
                faces[i].dispinfo                       = UtilityReader.ReadShort(stream);
                faces[i].surfaceFogVolumeID             = UtilityReader.ReadShort(stream);
                faces[i].styles                         = new byte[4];
                faces[i].styles[0]                      = UtilityReader.ReadByte(stream);
                faces[i].styles[1]                      = UtilityReader.ReadByte(stream);
                faces[i].styles[2]                      = UtilityReader.ReadByte(stream);
                faces[i].styles[3]                      = UtilityReader.ReadByte(stream);
                faces[i].lightOffset                    = UtilityReader.ReadInt(stream);
                faces[i].area                           = UtilityReader.ReadFloat(stream);
                faces[i].LightmapTextureMinsInLuxels    = new int[2];
                faces[i].LightmapTextureMinsInLuxels[0] = UtilityReader.ReadInt(stream);
                faces[i].LightmapTextureMinsInLuxels[1] = UtilityReader.ReadInt(stream);
                faces[i].LightmapTextureSizeInLuxels    = new int[2];
                faces[i].LightmapTextureSizeInLuxels[0] = UtilityReader.ReadInt(stream);
                faces[i].LightmapTextureSizeInLuxels[1] = UtilityReader.ReadInt(stream);
                faces[i].originalFace                   = UtilityReader.ReadInt(stream);
                faces[i].numPrims                       = UtilityReader.ReadUShort(stream);
                faces[i].firstPrimID                    = UtilityReader.ReadUShort(stream);
                faces[i].smoothingGroups                = UtilityReader.ReadUInt(stream);
            }

            return(faces);
        }
        private Plane[] GetPlanes(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_PLANES];

            Plane[] planes = new Plane[lump.length / 20];
            stream.Position = lump.offset;

            for (int i = 0; i < planes.Length; i++)
            {
                planes[i] = new Plane();

                Vector3 normal = new Vector3();
                normal.x = UtilityReader.ReadFloat(stream);
                normal.y = UtilityReader.ReadFloat(stream);
                normal.z = UtilityReader.ReadFloat(stream);

                planes[i].normal   = normal;
                planes[i].distance = UtilityReader.ReadFloat(stream);
                planes[i].type     = UtilityReader.ReadInt(stream);
            }

            return(planes);
        }