public static Bricklayer.Server.World.Map LoadMap(string name) { Bricklayer.Server.World.Map map; using (BinaryReader binaryReader = new BinaryReader( //Create a new binary writer to write to the file new BufferedStream( File.Open(Path.Combine(mapFolder, name + mapSuffix), FileMode.Open)))) { //Read general data map = new Bricklayer.Server.World.Map(binaryReader.ReadString(), binaryReader.ReadString(), binaryReader.ReadInt16(), binaryReader.ReadInt16(), Server.Maps.Count) { Rating = binaryReader.ReadDouble() }; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Tile fg; Tile bg; SaveFlags sf = (SaveFlags)binaryReader.ReadByte(); int RLE = 0; if (sf.HasFlag(SaveFlags.RLE)) { RLE = binaryReader.ReadInt16(); } if (sf.HasFlag(SaveFlags.Foreground)) { fg = new Tile(BlockType.FromID(binaryReader.ReadByte())); } else { fg = new Tile(BlockType.Empty); } if (sf.HasFlag(SaveFlags.Background)) { bg = new Tile(BlockType.FromID(binaryReader.ReadByte())); } else { bg = new Tile(BlockType.Empty); } map.Tiles[x, y, 1] = fg; map.Tiles[x, y, 0] = bg; if (RLE > 0) //RLE enabled { for (int i = 1; i <= RLE; i++) { map.Tiles[x + i, y, 1] = fg; map.Tiles[x + i, y, 0] = bg; } x += RLE; } } } } return(map); }