Exemple #1
0
        public static MapDoodads Parse(Stream stream, bool leaveOpen = false)
        {
            var data = new MapDoodads();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                data._header = MapWidgetsHeader.Parse(stream, true);
                Func <Stream, bool, MapDoodadData> doodadParser = data._header.Version switch
                {
                    MapWidgetsVersion.RoC => MapDoodadData.Parse,
                    MapWidgetsVersion.TFT => MapDoodadData.ParseTft,
                    _ => throw new NotSupportedException(),
                };

                for (var i = 0; i < data._header.DataCount; i++)
                {
                    data._doodads.Add(doodadParser(stream, true));
                }

                var specialDoodadsVersion = reader.ReadInt32();
                if (specialDoodadsVersion != 0)
                {
                    throw new NotSupportedException($"Unknown special doodads version: {specialDoodadsVersion}.");
                }

                var specialDoodads = reader.ReadInt32();
                for (var i = 0; i < specialDoodads; i++)
                {
                    data._specialDoodads.Add(MapSpecialDoodadData.Parse(stream, true));
                }
            }

            return(data);
        }
Exemple #2
0
        public static MapUnits Parse(Stream stream, bool leaveOpen = false)
        {
            try
            {
                var data = new MapUnits();
                using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
                {
                    data._header = MapWidgetsHeader.Parse(stream, true);
                    var unitParser = data._header.UseTftParser
                        ? (Func <Stream, bool, MapUnitData>)MapUnitData.ParseTft
                        : MapUnitData.Parse;

                    for (var i = 0; i < data._header.DataCount; i++)
                    {
                        data._units.Add(unitParser(stream, true));
                    }
                }

                return(data);
            }
            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;
            }
        }
Exemple #3
0
        public static MapWidgetsHeader Parse(Stream stream, bool leaveOpen = false)
        {
            var header = new MapWidgetsHeader();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                if (reader.ReadUInt32() != HeaderSignature)
                {
                    throw new InvalidDataException();
                }

                header._version = (MapWidgetsVersion)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(MapWidgetsVersion), header._version))
                {
                    throw new NotSupportedException($"Version {header._version} for .doo files is not supported.");
                }

                header._subVersion = reader.ReadUInt32();

                /*if (header._subVersion != LatestSubVersion)
                 * {
                 *  throw new NotSupportedException($"Subversion {header._subVersion} is not supported.");
                 * }*/

                header._dataCount = reader.ReadUInt32();
            }

            return(header);
        }
Exemple #4
0
        public static MapDoodads Parse(Stream stream, bool leaveOpen = false)
        {
            try
            {
                var data = new MapDoodads();
                using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
                {
                    data._header = MapWidgetsHeader.Parse(stream, true);
                    Func <Stream, bool, MapDoodadData> doodadParser = data._header.Version switch
                    {
                        MapWidgetsVersion.RoC => MapDoodadData.Parse,
                        MapWidgetsVersion.TFT => MapDoodadData.ParseTft,
                        _ => throw new NotSupportedException(),
                    };

                    for (var i = 0; i < data._header.DataCount; i++)
                    {
                        data._doodads.Add(doodadParser(stream, true));
                    }

                    var specialDoodadsVersion = reader.ReadInt32();
                    if (specialDoodadsVersion != 0)
                    {
                        throw new NotSupportedException($"Unknown special doodads version: {specialDoodadsVersion}.");
                    }

                    var specialDoodads = reader.ReadInt32();
                    for (var i = 0; i < specialDoodads; i++)
                    {
                        data._specialDoodads.Add(MapSpecialDoodadData.Parse(stream, true));
                    }
                }

                return(data);
            }
            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;
            }
        }
Exemple #5
0
        public static MapUnits Parse(Stream stream, bool leaveOpen = false)
        {
            var data = new MapUnits();

            using (var reader = new BinaryReader(stream, new UTF8Encoding(false, true), leaveOpen))
            {
                data._header = MapWidgetsHeader.Parse(stream, true);
                Func <Stream, bool, MapUnitData> unitParser = data._header.Version switch
                {
                    MapWidgetsVersion.RoC => MapUnitData.Parse,
                    MapWidgetsVersion.TFT => MapUnitData.ParseTft,
                    _ => throw new NotSupportedException(),
                };

                for (var i = 0; i < data._header.DataCount; i++)
                {
                    data._units.Add(unitParser(stream, true));
                }
            }

            return(data);
        }
Exemple #6
0
 public MapDoodads(params MapDoodadData[] doodads)
 {
     _doodads        = new List <MapDoodadData>(doodads);
     _specialDoodads = new List <MapSpecialDoodadData>();
     _header         = MapWidgetsHeader.GetDefault((uint)_doodads.Count);
 }
Exemple #7
0
 public MapDoodads(IEnumerable <MapDoodadData> doodads, IEnumerable <MapSpecialDoodadData> specialDoodads)
 {
     _doodads        = new List <MapDoodadData>(doodads);
     _specialDoodads = new List <MapSpecialDoodadData>(specialDoodads);
     _header         = MapWidgetsHeader.GetDefault((uint)_doodads.Count);
 }
Exemple #8
0
 public MapUnits(params MapUnitData[] units)
 {
     _units  = new List <MapUnitData>(units);
     _header = MapWidgetsHeader.GetDefault((uint)_units.Count);
 }
Exemple #9
0
 public MapUnits(IEnumerable <MapUnitData> units)
 {
     _units  = new List <MapUnitData>(units);
     _header = MapWidgetsHeader.GetDefault((uint)_units.Count);
 }