Beispiel #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);
        }
Beispiel #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;
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
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);
        }