public static PathingMap Parse(Stream stream, bool leaveOpen = false) { var pathingMap = new PathingMap(); using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen)) { if (reader.ReadUInt32() != HeaderSignature) { throw new Exception(); } pathingMap._version = reader.ReadUInt32(); if (pathingMap._version != LatestVersion) { throw new Exception(); } // Width and height should be four times the size in .w3e file (since MapTile is 128x128, and cells in PathingMap are 32x32). pathingMap._width = reader.ReadUInt32(); pathingMap._height = reader.ReadUInt32(); for (var y = 0; y < pathingMap._width; y++) { for (var x = 0; x < pathingMap._height; x++) { pathingMap._cells.Add((PathingType)reader.ReadByte()); } } } return(pathingMap); }
public static PathingMap Parse(Stream stream, bool leaveOpen = false) { try { var pathingMap = new PathingMap(); using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen)) { if (reader.ReadUInt32() != HeaderSignature) { throw new InvalidDataException($"Expected file header signature at the start of a '{FileName}' file."); } pathingMap._version = reader.ReadUInt32(); if (pathingMap._version != LatestVersion) { throw new NotSupportedException($"Unknown version of '{FileName}': {pathingMap._version}"); } // Width and height should be four times the size in .w3e file (since MapTile is 128x128, and cells in PathingMap are 32x32). pathingMap._width = reader.ReadUInt32(); pathingMap._height = reader.ReadUInt32(); for (var y = 0; y < pathingMap._width; y++) { for (var x = 0; x < pathingMap._height; x++) { pathingMap._cells.Add((PathingType)reader.ReadByte()); } } } return(pathingMap); } catch (DecoderFallbackException e) { throw new InvalidDataException($"The '{FileName}' file contains invalid characters.", e); } catch (EndOfStreamException e) { throw new InvalidDataException($"The '{FileName}' file is missing data, or its data is invalid.", e); } catch { throw; } }