Exemple #1
0
        private Leaf[] GetLeafs(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpLeafs];

            Leaf[] leafData = new Leaf[lump.Length / 56];
            stream.Position = lump.Offset;

            for (int i = 0; i < leafData.Length; i++)
            {
                leafData[i] = new Leaf
                {
                    contents = (ContentsFlag)UtilityReader.ReadInt(stream),
                    cluster  = UtilityReader.ReadShort(stream),
                    area     = UtilityReader.ReadShort(stream),
                    flags    = UtilityReader.ReadShort(stream),
                    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);
        }
Exemple #2
0
        private Plane[] GetPlanes(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpPlanes];

            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
                {
                    X = UtilityReader.ReadFloat(stream),
                    Y = UtilityReader.ReadFloat(stream),
                    Z = UtilityReader.ReadFloat(stream)
                };

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

            return(planes);
        }
Exemple #3
0
        private Node[] GetNodes(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpNodes];

            Node[] nodesData = new Node[lump.Length / 32];
            stream.Position = lump.Offset;

            for (int i = 0; i < nodesData.Length; i++)
            {
                nodesData[i] = new Node
                {
                    planenum = UtilityReader.ReadInt(stream),
                    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);
        }
Exemple #4
0
        private string GetEntities(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpEntities];

            stream.Position = lump.Offset;
            byte[] data = UtilityReader.ReadBytes(stream, lump.Length);
            return(System.Text.Encoding.ASCII.GetString(data));
        }
Exemple #5
0
        private int[] GetSurfedges(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpSurfedges];

            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);
        }
Exemple #6
0
        private SurfFlag[] GetTextureInfo(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpTexinfo];

            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);
        }
Exemple #7
0
        private List <ushort[]> GetEdges(Stream stream)
        {
            List <ushort[]> edges = new List <ushort[]>();
            Lump            lump  = _header.lumps[(int)LumpType.LumpEdges];

            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);
        }
Exemple #8
0
        private Brush[] GetBrushes(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpBrushes];

            Brush[] brushes = new Brush[lump.Length / 12];
            stream.Position = lump.Offset;

            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i] = new Brush
                {
                    firstside = UtilityReader.ReadInt(stream),
                    numsides  = UtilityReader.ReadInt(stream),
                    contents  = (ContentsFlag)UtilityReader.ReadInt(stream)
                };
            }

            return(brushes);
        }
Exemple #9
0
        private Vector3[] GetVertices(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpVertexes];

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

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector3
                {
                    X = UtilityReader.ReadFloat(stream),
                    Y = UtilityReader.ReadFloat(stream),
                    Z = UtilityReader.ReadFloat(stream)
                };
            }

            return(vertices);
        }
Exemple #10
0
        private Brushside[] GetBrushsides(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpBrushes];

            Brushside[] brushsides = new Brushside[lump.Length / 8];
            stream.Position = lump.Offset;

            for (int i = 0; i < brushsides.Length; i++)
            {
                brushsides[i] = new Brushside
                {
                    planenum = UtilityReader.ReadUShort(stream),
                    texinfo  = UtilityReader.ReadShort(stream),
                    dispinfo = UtilityReader.ReadShort(stream),
                    bevel    = UtilityReader.ReadShort(stream)
                };
            }

            return(brushsides);
        }
Exemple #11
0
        private Face[] GetFaces(Stream stream)
        {
            Lump lump = _header.lumps[(int)LumpType.LumpFaces];

            stream.Position = lump.Offset;
            Face[] faces = new Face[lump.Length / 56];

            for (int i = 0; i < faces.Length; i++)
            {
                faces[i] = new Face
                {
                    planeNumber        = UtilityReader.ReadUShort(stream),
                    side               = UtilityReader.ReadByte(stream),
                    onNode             = UtilityReader.ReadByte(stream),
                    firstEdge          = UtilityReader.ReadInt(stream),
                    numEdges           = UtilityReader.ReadShort(stream),
                    texinfo            = UtilityReader.ReadShort(stream),
                    dispinfo           = UtilityReader.ReadShort(stream),
                    surfaceFogVolumeID = UtilityReader.ReadShort(stream),
                    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);
        }
Exemple #12
0
        private Header GetHeader(Stream stream)
        {
            Header header = new Header {
                ident = UtilityReader.ReadInt(stream)
            };

            UtilityReader.BigEndian = header.ident != 'V' + ('B' << 8) + ('S' << 16) + ('P' << 24);

            header.version = UtilityReader.ReadInt(stream);
            header.lumps   = new Lump[64];
            for (int i = 0; i < header.lumps.Length; i++)
            {
                header.lumps[i] = new Lump
                {
                    Type    = (LumpType)i,
                    Offset  = UtilityReader.ReadInt(stream),
                    Length  = UtilityReader.ReadInt(stream),
                    Version = UtilityReader.ReadInt(stream),
                    FourCc  = UtilityReader.ReadInt(stream)
                };
            }
            header.mapRevision = UtilityReader.ReadInt(stream);
            return(header);
        }