Esempio n. 1
0
        static void ParseRegionData(MutagenFrame frame, IRegionInternal item)
        {
            var rdatFrame = frame.GetSubrecordFrame();

            RegionData.RegionDataType dataType = (RegionData.RegionDataType)BinaryPrimitives.ReadUInt32LittleEndian(rdatFrame.Content);
            var subMeta = frame.GetSubrecord(offset: rdatFrame.TotalLength);
            int len     = rdatFrame.TotalLength;

            if (IsExpected(dataType, subMeta.RecordType))
            {
                len += subMeta.TotalLength;
            }
            switch (dataType)
            {
            case RegionData.RegionDataType.Object:
                item.Objects = RegionObjects.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                break;

            case RegionData.RegionDataType.Map:
                item.MapName = RegionMap.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                break;

            case RegionData.RegionDataType.Grass:
                item.Grasses = RegionGrasses.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                break;

            case RegionData.RegionDataType.Sound:
                if (frame.Reader.TryGetSubrecord(out var nextRec, offset: len) &&
                    (nextRec.RecordType.Equals(RDSD) || nextRec.RecordType.Equals(RDMD)))
                {
                    len += nextRec.TotalLength;
                }
                item.Sounds = RegionSounds.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                break;

            case RegionData.RegionDataType.Weather:
                item.Weather = RegionWeather.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                break;

            case RegionData.RegionDataType.Icon:
                frame.Position += frame.MetaData.Constants.SubConstants.HeaderLength + rdatFrame.TotalLength;
                len             = len - frame.MetaData.Constants.SubConstants.HeaderLength - rdatFrame.TotalLength;
                if (StringBinaryTranslation.Instance.Parse(
                        frame.SpawnWithLength(len, checkFraming: false),
                        out var iconVal))
                {
                    item.Icon = iconVal;
                }
                else
                {
                    item.Icon = null;
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 2
0
            static void ParseRegionData(MutagenFrame frame, IRegionInternal item)
            {
                var rdatFrame = frame.Reader.GetSubrecordFrame();
                int len       = rdatFrame.TotalLength;

                RegionData.RegionDataType dataType = (RegionData.RegionDataType)BinaryPrimitives.ReadUInt32LittleEndian(rdatFrame.Content);

                if (frame.Reader.TryGetSubrecord(out var subMeta, offset: len))
                {
                    var recType = subMeta.RecordType;
                    if (recType == RecordTypes.ICON)
                    {
                        len += subMeta.TotalLength;
                        // Skip icon subrecord for now
                        subMeta = frame.Reader.GetSubrecord(offset: rdatFrame.TotalLength + subMeta.TotalLength);
                    }
                    if (IsExpected(dataType, recType))
                    {
                        len += subMeta.TotalLength;
                    }
                }

                switch (dataType)
                {
                case RegionData.RegionDataType.Object:
                    item.Objects = RegionObjects.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                case RegionData.RegionDataType.Map:
                    item.Map = RegionMap.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                case RegionData.RegionDataType.Grass:
                    item.Grasses = RegionGrasses.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                case RegionData.RegionDataType.Sound:
                    if (frame.Reader.TryGetSubrecord(out var nextRec, offset: len) &&
                        (nextRec.RecordType.Equals(RDSA) || nextRec.RecordType.Equals(RDMO)))
                    {
                        len += nextRec.TotalLength;
                    }
                    item.Sounds = RegionSounds.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                case RegionData.RegionDataType.Weather:
                    item.Weather = RegionWeather.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                case RegionData.RegionDataType.Land:
                    item.Land = RegionLand.CreateFromBinary(frame.SpawnWithLength(len, checkFraming: false));
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
Esempio n. 3
0
        public static bool IsExpected(RegionData.RegionDataType dataType, RecordType recordType)
        {
            switch (dataType)
            {
            case RegionData.RegionDataType.Object:
                if (!recordType.Equals(RDOT))
                {
                    return(false);
                }
                break;

            case RegionData.RegionDataType.Weather:
                if (!recordType.Equals(RDWT))
                {
                    return(false);
                }
                break;

            case RegionData.RegionDataType.Map:
                if (!recordType.Equals(RDMP))
                {
                    return(false);
                }
                break;

            case RegionData.RegionDataType.Icon:
                if (!recordType.Equals(ICON))
                {
                    return(false);
                }
                break;

            case RegionData.RegionDataType.Grass:
                if (!recordType.Equals(RDGS))
                {
                    return(false);
                }
                break;

            case RegionData.RegionDataType.Sound:
                if (!recordType.Equals(RDSD) && !recordType.Equals(RDMD))
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
            private void ParseRegionData(OverlayStream stream, int offset)
            {
                int loc       = stream.Position - offset;
                var rdatFrame = stream.ReadSubrecordFrame();

                RegionData.RegionDataType dataType = (RegionData.RegionDataType)BinaryPrimitives.ReadUInt32LittleEndian(rdatFrame.Content);
                var len = rdatFrame.TotalLength;

                if (!stream.Complete)
                {
                    var contentMeta = stream.GetSubrecord();
                    var recType     = contentMeta.RecordType;
                    if (recType == RecordTypes.ICON)
                    {
                        var totalLen = contentMeta.TotalLength;
                        len += totalLen;
                        // Skip icon subrecord for now
                        contentMeta = stream.GetSubrecord(offset: rdatFrame.TotalLength + totalLen);
                    }
                    if (RegionBinaryCreateTranslation.IsExpected(dataType, contentMeta.RecordType))
                    {
                        len             += contentMeta.TotalLength;
                        stream.Position += contentMeta.TotalLength;
                    }
                }
                switch (dataType)
                {
                case RegionData.RegionDataType.Object:
                    _ObjectsSpan = this._data.Slice(loc, len);
                    break;

                case RegionData.RegionDataType.Map:
                    _MapSpan = this._data.Slice(loc, len);
                    break;

                case RegionData.RegionDataType.Grass:
                    _GrassesSpan = this._data.Slice(loc, len);
                    break;

                case RegionData.RegionDataType.Land:
                    _LandSpan = this._data.Slice(loc, len);
                    break;

                case RegionData.RegionDataType.Sound:
                    if (stream.TryGetSubrecord(out var nextRec) &&
                        (nextRec.RecordType.Equals(RegionBinaryCreateTranslation.RDSA) ||
                         nextRec.RecordType.Equals(RegionBinaryCreateTranslation.RDMO)))
                    {
                        len += nextRec.TotalLength;
                    }
                    _SoundsSpan = this._data.Slice(loc, len);
                    break;

                case RegionData.RegionDataType.Weather:
                    _WeatherSpan = this._data.Slice(loc, len);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }