From 08c06389826cb4bd2dc842d8156be53fa194be2d Mon Sep 17 00:00:00 2001 From: bob Date: Tue, 26 Jun 2007 11:13:54 +0000 Subject: [PATCH] Reading the map correctly is always a good idea git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1079 993157c7-ee19-0410-b2c4-bb4e9862e678 --- MapViewer/Program.cs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/MapViewer/Program.cs b/MapViewer/Program.cs index b20d653012..ee57870fbf 100644 --- a/MapViewer/Program.cs +++ b/MapViewer/Program.cs @@ -18,6 +18,14 @@ namespace MapViewer return (DialogResult.OK == ofd.ShowDialog()) ? ofd.OpenFile() : null; } + static byte ReadByte( Stream s ) + { + int ret = s.ReadByte(); + if( ret == -1 ) + throw new NotImplementedException (); + return (byte)ret; + } + static void Main(string[] args) { Stream s = GetFile(); @@ -88,17 +96,22 @@ namespace MapViewer ms.Position = 0; - TileReference[,] tiles = new TileReference[width, height]; - for( int i = 0; i < width; i++ ) - for (int j = 0; j < height; j++) - tiles[i, j].tile = (ushort)((ms.ReadByte() << 8) | ms.ReadByte()); + TileReference[ , ] tiles = new TileReference[ 128, 128 ]; + for( int i = 0 ; i < 128 ; i++ ) + { + for( int j = 0 ; j < 128 ; j++ ) + { + tiles[ i, j ].tile = ReadByte( ms ); + tiles[ i, j ].tile |= (ushort)( ReadByte( ms ) << 8 ); + } + } - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - tiles[i, j].image = (byte)ms.ReadByte(); + for( int i = 0 ; i < 128 ; i++ ) + for( int j = 0 ; j < 128 ; j++ ) + tiles[ i, j ].image = ReadByte( ms ); foreach( TileReference r in tiles ) - Console.Write("{0:x4}.{1:x2} ", r.tile, r.image); + Console.Write( "{0:x4}.{1:x2} ", r.tile, r.image ); } }