public deBSP() { this.Buffer = null; this.MapName = null; this.Header = null; this.Entities = null; this.Textures = null; }
public bool Load(String file) { if (!System.IO.File.Exists(file)) return false; this.MapName = System.IO.Path.GetFileNameWithoutExtension(file); this.Buffer = System.IO.File.ReadAllBytes(file); this.Header = new BSP_HEADER(); this.Header.Version = System.BitConverter.ToUInt32(this.Buffer, 0); if (this.Header.Version != 30) return false; for (int i = 0; i < this.Header.Lumps.Length; i++) { this.Header.Lumps[i] = new BSP_LUMP(); this.Header.Lumps[i].Offset = System.BitConverter.ToUInt32(this.Buffer, sizeof(UInt32) + (i * 2 * sizeof(UInt32))); this.Header.Lumps[i].Size = System.BitConverter.ToUInt32(this.Buffer, sizeof(UInt32) + (i * 2 * sizeof(UInt32)) + sizeof(UInt32)); } String ES = System.Text.ASCIIEncoding.ASCII.GetString(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.ENTITIES].Offset, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.ENTITIES].Size-1); this.Entities = new XNode(); ParseEntitiesString(ES, this.Entities); UInt32 NumberTextures = System.BitConverter.ToUInt32(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset); this.Textures = new BSP_TEXTURE_HEADER[NumberTextures]; for (int i = 0; i < this.Textures.Length; i++) { this.Textures[i] = new BSP_TEXTURE_HEADER(); Int32 Offset = (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset + System.BitConverter.ToInt32(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset + sizeof(Int32) + (i * sizeof(UInt32))); this.Textures[i].Name = System.Text.ASCIIEncoding.ASCII.GetString(this.Buffer, Offset, 16).Split('\0')[0]; this.Textures[i].Width = System.BitConverter.ToUInt32(this.Buffer, Offset + 16); this.Textures[i].Height = System.BitConverter.ToUInt32(this.Buffer, Offset + 16 + sizeof(UInt32)); for (int j = 0; j < this.Textures[i].Offsets.Length; j++) this.Textures[i].Offsets[j] = System.BitConverter.ToUInt32(this.Buffer, Offset + 16 + sizeof(UInt32) + sizeof(UInt32) + (j * sizeof(UInt32))); } return true; }