diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 1bae44f2ba..45a590f93b 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -229,44 +229,27 @@ namespace OpenRA Container.Write(entries); } - static byte ReadByte(Stream s) - { - int ret = s.ReadByte(); - if (ret == -1) - throw new NotImplementedException(); - return (byte)ret; - } - - static ushort ReadWord(Stream s) - { - ushort ret = ReadByte(s); - ret |= (ushort)(ReadByte(s) << 8); - - return ret; - } - public TileReference[,] LoadMapTiles() { var tiles = new TileReference[MapSize.X, MapSize.Y]; using (var dataStream = Container.GetContent("map.bin")) { - if (ReadByte(dataStream) != 1) + if (dataStream.ReadUInt8() != 1) throw new InvalidDataException("Unknown binary map format"); // Load header info - var width = ReadWord(dataStream); - var height = ReadWord(dataStream); + var width = dataStream.ReadUInt16(); + var height = dataStream.ReadUInt16(); if (width != MapSize.X || height != MapSize.Y) throw new InvalidDataException("Invalid tile data"); - // Load tile data for (int i = 0; i < MapSize.X; i++) for (int j = 0; j < MapSize.Y; j++) { - ushort tile = ReadWord(dataStream); - byte index = ReadByte(dataStream); + var tile = dataStream.ReadUInt16(); + var index = dataStream.ReadUInt8(); if (index == byte.MaxValue) index = (byte)(i % 4 + (j % 4) * 4); @@ -282,26 +265,25 @@ namespace OpenRA using (var dataStream = Container.GetContent("map.bin")) { - if (ReadByte(dataStream) != 1) + if (dataStream.ReadUInt8() != 1) throw new InvalidDataException("Unknown binary map format"); // Load header info - var width = ReadWord(dataStream); - var height = ReadWord(dataStream); + var width = dataStream.ReadUInt16(); + var height = dataStream.ReadUInt16(); if (width != MapSize.X || height != MapSize.Y) throw new InvalidDataException("Invalid tile data"); // Skip past tile data - for (var i = 0; i < 3*MapSize.X*MapSize.Y; i++) - ReadByte(dataStream); + dataStream.Seek(3*MapSize.X*MapSize.Y, SeekOrigin.Current); // Load resource data for (var i = 0; i < MapSize.X; i++) for (var j = 0; j < MapSize.Y; j++) { - byte type = ReadByte(dataStream); - byte index = ReadByte(dataStream); + var type = dataStream.ReadUInt8(); + var index = dataStream.ReadUInt8(); resources[i, j] = new TileReference(type, index); } }