public Map Load( System.IO.Stream MapStream ) { // Reset the seeker to the front of the stream // This should probably be done differently. MapStream.Seek( 0, SeekOrigin.Begin ); // Setup a GZipStream to decompress and read the map file GZipStream gs = new GZipStream( MapStream, CompressionMode.Decompress, true ); BinaryReader bs = new BinaryReader( gs ); Map map = new Map(); // Read in the magic number if ( bs.ReadUInt16() != 0x752 ) { throw new FormatException(); } // Read in the map dimesions map.widthX = bs.ReadInt16(); map.widthY = bs.ReadInt16(); map.height = bs.ReadInt16(); // Read in the spawn location map.spawn.x = (short)(bs.ReadInt16() * 32); map.spawn.y = (short)(bs.ReadInt16() * 32); map.spawn.h = (short)(bs.ReadInt16() * 32); // Read in the spawn orientation map.spawn.r = bs.ReadByte(); map.spawn.l = bs.ReadByte(); // Skip over the VisitPermission and BuildPermission bytes bs.ReadByte(); bs.ReadByte(); if( !map.ValidateHeader() ) { throw new Exception( "One or more of the map dimensions are invalid." ); } // Read in the map data map.blocks = bs.ReadBytes( map.GetBlockCount() ); for( int i = 0; i < map.blocks.Length; i++ ) { if( map.blocks[i] > 49 ) { map.blocks[i] = mapping[map.blocks[i]]; } } return map; }
public Map Load( Stream MapStream ) { MapStream.Seek( 0, SeekOrigin.Begin ); GZipStream gs = new GZipStream( MapStream, CompressionMode.Decompress, true ); NBTag tag = NBTag.ReadStream( gs ); Map map = new Map(); NBTag mapTag = tag["Map"]; map.widthX = mapTag["Width"].GetShort(); map.height = mapTag["Height"].GetShort(); map.widthY = mapTag["Length"].GetShort(); if( !map.ValidateHeader() ) { throw new Exception( "One or more of the map dimensions are invalid." ); } map.blocks = mapTag["Blocks"].GetBytes(); map.ValidateBlockTypes( false ); map.spawn.x = mapTag["Spawn"][0].GetShort(); map.spawn.h = mapTag["Spawn"][1].GetShort(); map.spawn.y = mapTag["Spawn"][2].GetShort(); map.spawn.r = 0; map.spawn.l = 0; return map; }
public Map Load( Stream MapStream ) { // Reset the seeker to the front of the stream // This should probably be done differently. MapStream.Seek( 0, SeekOrigin.Begin ); Map map = new Map(); BinaryReader reader = new BinaryReader( MapStream ); // Read in the magic number if ( reader.ReadUInt32() != Identifier ) { throw new FormatException(); } // Read in the map dimesions map.widthX = reader.ReadInt16(); map.widthY = reader.ReadInt16(); map.height = reader.ReadInt16(); // Read in the spawn location map.spawn.x = reader.ReadInt16(); map.spawn.y = reader.ReadInt16(); map.spawn.h = reader.ReadInt16(); // Read in the spawn orientation map.spawn.r = reader.ReadByte(); map.spawn.l = reader.ReadByte(); // Read the metadata map.ReadMetadata( reader ); if( !map.ValidateHeader() ) { throw new Exception( "One or more of the map dimensions are invalid." ); } // Read in the map data map.blocks = new Byte[map.GetBlockCount()]; using ( GZipStream decompressor = new GZipStream( MapStream, CompressionMode.Decompress, true ) ) { decompressor.Read( map.blocks, 0, map.blocks.Length ); } return map; }