Exemple #1
0
        public static void Validate(this BspLump lump, int size)
        {
            if (lump.length % size != 0)
            {
                throw new BspCorruptedException();
            }

            int count = lump.length / size;

            if (count <= 0)
            {
                throw new BspCorruptedException();
            }
        }
Exemple #2
0
        public static BspTexture[] ReadBspTexturesLumpData(this BinaryReader br, BspLump lump)
        {
            br.BaseStream.Position = lump.offset;
            var count = br.ReadInt32();

            var result = new BspTexture[count];

            for (int i = 0, j = lump.offset + 4; i < count; i++, j += 4)
            {
                br.BaseStream.Position = j;
                result[i] = new HlBspMap.BspTexture(br, lump.offset, br.ReadInt32());
            }

            return(result);
        }
Exemple #3
0
        public static T[] ReadLumpData <T>(this BinaryReader br, BspLump lump, int size, Func <BinaryReader, T> readType)
        {
            lump.Validate(size);

            if (lump.length % size != 0)
            {
                throw new BspCorruptedException();
            }

            int count = lump.length / size;

            if (count <= 0)
            {
                throw new BspCorruptedException();
            }

            br.BaseStream.Position = lump.offset;

            return(Enumerable
                   .Range(0, count)
                   .Select(i => readType(br))
                   .ToArray());
        }
Exemple #4
0
        public static byte[] ReadLumpBytes(this BinaryReader br, BspLump lump)
        {
            br.BaseStream.Position = lump.offset;

            return(br.ReadBytes(lump.length));
        }