Files
OpenRA/OpenRa.FileFormats/Terrain.cs
2009-12-05 14:23:59 +13:00

48 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.IO;
namespace OpenRa.FileFormats
{
public class Terrain
{
public readonly List<byte[]> TileBitmapBytes = new List<byte[]>();
public Terrain( Stream stream )
{
int Width, Height, XDim, YDim, NumTiles;
BinaryReader reader = new BinaryReader( stream );
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
if( Width != 24 || Height != 24 )
throw new InvalidDataException( string.Format( "{0}x{1}", Width, Height ) );
NumTiles = reader.ReadUInt16();
reader.ReadUInt16();
XDim = reader.ReadUInt16();
YDim = reader.ReadUInt16();
uint FileSize = reader.ReadUInt32();
uint ImgStart = reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt32();
int IndexEnd = reader.ReadInt32();
reader.ReadUInt32();
int IndexStart = reader.ReadInt32();
stream.Position = IndexStart;
foreach( byte b in new BinaryReader(stream).ReadBytes(IndexEnd - IndexStart) )
{
if (b != 255)
{
stream.Position = ImgStart + b * 24 * 24;
TileBitmapBytes.Add(new BinaryReader(stream).ReadBytes(24 * 24));
}
else
TileBitmapBytes.Add(null);
}
}
}
}