Example #1
0
        private static AudioProperties ReadAudioProperties(this BinaryReader reader)
        {
            AudioProperties audioProperties = default;

            audioProperties.OverrideEffects = reader.ReadBoolean();
            audioProperties.EffectCount     = reader.ReadByte();
            if (audioProperties.EffectCount > 0)
            {
                audioProperties.BypassedEffects = (BypassedEffects)reader.ReadByte();
            }
            audioProperties.Effects = new Effect[audioProperties.EffectCount];
            for (var i = 0; i < audioProperties.EffectCount; i++)
            {
                Effect effect = default;
                effect.Index               = reader.ReadByte();
                effect.Id                  = reader.ReadUInt32();
                effect.UseShareSets        = reader.ReadBoolean();
                effect.Rendered            = reader.ReadBoolean();
                audioProperties.Effects[i] = effect;
            }
            audioProperties.Unknown_1      = reader.ReadByte();
            audioProperties.OutputBusId    = reader.ReadUInt32();
            audioProperties.ParentId       = reader.ReadUInt32();
            audioProperties.MidiOverride   = (Override)reader.ReadByte();
            audioProperties.ParameterCount = reader.ReadByte();
            audioProperties.ParameterTypes = new AudioParameterType[audioProperties.ParameterCount];
            for (var i = 0; i < audioProperties.ParameterCount; i++)
            {
                audioProperties.ParameterTypes[i] = (AudioParameterType)reader.ReadByte();
            }
            audioProperties.ParameterValues = new ValueType[audioProperties.ParameterCount];
            for (var i = 0; i < audioProperties.ParameterCount; i++)
            {
                var parameterType = audioProperties.ParameterTypes[i].ToString();
                if (parameterType.EndsWith("_UInt"))
                {
                    audioProperties.ParameterValues[i] = reader.ReadUInt32();
                }
                else if (parameterType.EndsWith("_Int"))
                {
                    audioProperties.ParameterValues[i] = reader.ReadInt32();
                }
                else
                {
                    audioProperties.ParameterValues[i] = reader.ReadSingle();
                }
            }
            audioProperties.Unknown_2   = reader.ReadByte();
            audioProperties.Positioning = (PositioningBehavior)reader.ReadByte();
            if (audioProperties.Positioning.HasFlag(PositioningBehavior.ThreeDimensional))
            {
                audioProperties.IsGameDefined = reader.ReadBoolean();
                audioProperties.AttenuationId = reader.ReadUInt32();
                if (!audioProperties.IsGameDefined)
                {
                    audioProperties.UserDefinedPlaySettings = (PositionEditorSettings)reader.ReadByte();
                    audioProperties.TransitionTime          = reader.ReadUInt32();
                    audioProperties.ControlPointKeyCount    = reader.ReadUInt32();
                    audioProperties.ControlPointKeys        = new ControlPointKey[audioProperties.ControlPointKeyCount];
                    for (var i = 0; i < audioProperties.ControlPointKeyCount; i++)
                    {
                        ControlPointKey controlPointKey = default;
                        controlPointKey.X                   = reader.ReadSingle();
                        controlPointKey.Z                   = reader.ReadSingle();
                        controlPointKey.Y                   = reader.ReadSingle();
                        controlPointKey.Timestamp           = reader.ReadUInt32();
                        audioProperties.ControlPointKeys[i] = controlPointKey;
                    }
                    audioProperties.RandomRangeCount    = reader.ReadUInt32();
                    audioProperties.RandomRangeUnknowns = new RandomRangeUnknown[audioProperties.RandomRangeCount];
                    for (var i = 0; i < audioProperties.RandomRangeCount; i++)
                    {
                        RandomRangeUnknown randomRangeUnknown = default;
                        randomRangeUnknown.Unknown_0           = reader.ReadUInt32();
                        randomRangeUnknown.Unknown_4           = reader.ReadUInt32();
                        audioProperties.RandomRangeUnknowns[i] = randomRangeUnknown;
                    }
                    audioProperties.RandomRanges = new RandomRange[audioProperties.RandomRangeCount];
                    for (var i = 0; i < audioProperties.RandomRangeCount; i++)
                    {
                        RandomRange randomRange = default;
                        randomRange.LeftRight           = reader.ReadSingle();
                        randomRange.FrontBack           = reader.ReadSingle();
                        randomRange.UpDown              = reader.ReadSingle();
                        audioProperties.RandomRanges[i] = randomRange;
                    }
                }
            }
            audioProperties.AuxSendsBehavior = (AuxSendsBehavior)reader.ReadByte();
            if (audioProperties.AuxSendsBehavior.HasFlag(AuxSendsBehavior.OverrideAuxSends))
            {
                audioProperties.AuxiliarySendBusIds    = new uint[4];
                audioProperties.AuxiliarySendBusIds[0] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[1] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[2] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[3] = reader.ReadUInt32();
            }
            audioProperties.LimitBehavior = (SoundLimitBehavior)reader.ReadByte();
            audioProperties.VirtualVoiceReturnBehavior = (VirtualVoiceReturnBehavior)reader.ReadByte();
            audioProperties.Unknown_3            = reader.ReadByte();
            audioProperties.Unknown_4            = reader.ReadByte();
            audioProperties.VirtualVoiceBehavior = (VirtualVoiceBehavior)reader.ReadByte();
            audioProperties.HdrBehavior          = (HdrBehavior)reader.ReadByte();
            audioProperties.StateGroupCount      = reader.ReadUInt32();
            audioProperties.StateGroups          = new StateGroup[audioProperties.StateGroupCount];
            for (var i = 0; i < audioProperties.StateGroupCount; i++)
            {
                StateGroup stateGroup = new StateGroup();
                stateGroup.Id             = reader.ReadUInt32();
                stateGroup.ChangeOccursAt = (InteractiveMusicKeyPoint)reader.ReadByte();
                stateGroup.StateWithCustomSettingsCount = reader.ReadUInt16();
                stateGroup.StateWithCustomSettings      = new StateWithCustomSettings[stateGroup.StateWithCustomSettingsCount];
                for (var j = 0; j < stateGroup.StateWithCustomSettingsCount; j++)
                {
                    StateWithCustomSettings stateWithCustomSettings = default;
                    stateWithCustomSettings.StateId       = reader.ReadUInt32();
                    stateWithCustomSettings.SettingsId    = reader.ReadUInt32();
                    stateGroup.StateWithCustomSettings[j] = stateWithCustomSettings;
                }
                audioProperties.StateGroups[i] = stateGroup;
            }
            audioProperties.RtpcCount = reader.ReadUInt16();
            audioProperties.Rtpcs     = new Rtpc[audioProperties.RtpcCount];
            for (var i = 0; i < audioProperties.RtpcCount; i++)
            {
                Rtpc rtpc = new Rtpc();
                rtpc.X                 = reader.ReadUInt32();
                rtpc.IsMidi            = reader.ReadBoolean();
                rtpc.IsGeneralSettings = reader.ReadBoolean();
                rtpc.Parameter         = (RtpcParameterType)reader.ReadByte();
                rtpc.UnknownId         = reader.ReadUInt32();
                rtpc.CurveScalingType  = (CurveScalingType)reader.ReadByte();
                rtpc.PointCount        = reader.ReadUInt16();
                rtpc.Points            = new RtpcPoint[rtpc.PointCount];
                for (var j = 0; j < rtpc.PointCount; j++)
                {
                    RtpcPoint rtpcPoint = default;
                    rtpcPoint.X = reader.ReadSingle();
                    rtpcPoint.Y = reader.ReadSingle();
                    rtpcPoint.FollowingCurveShape = (CurveShape)reader.ReadByte();
                    rtpcPoint.Unknown             = reader.ReadBytes(3);
                    rtpc.Points[j] = rtpcPoint;
                }
                audioProperties.Rtpcs[i] = rtpc;
            }
            return(audioProperties);
        }
Example #2
0
        public static AudioBus ParseAudioBus(byte[] blob)
        {
            using (var reader = new BinaryReader(new MemoryStream(blob)))
            {
                var audioBus = new AudioBus(blob.Length);
                audioBus.Id             = reader.ReadUInt32();
                audioBus.ParentId       = reader.ReadUInt32();
                audioBus.ParameterCount = reader.ReadByte();
                audioBus.ParameterTypes = new AudioBusParameterType[audioBus.ParameterCount];
                for (var i = 0; i < audioBus.ParameterCount; i++)
                {
                    audioBus.ParameterTypes[i] = (AudioBusParameterType)reader.ReadByte();
                }
                audioBus.ParameterValues = new float[audioBus.ParameterCount];
                for (var i = 0; i < audioBus.ParameterCount; i++)
                {
                    audioBus.ParameterValues[i] = reader.ReadSingle();
                }
                audioBus.Positioning            = (PositioningType)reader.ReadByte();
                audioBus.OnPlaybackLimitReached = (PlaybackLimitBehavior)reader.ReadByte();
                audioBus.SoundInstanceLimit     = reader.ReadUInt16();
                audioBus.Channel                 = (ChannelType)reader.ReadUInt32();
                audioBus.HdrReleaseMode          = (HdrReleaseMode)reader.ReadByte();
                audioBus.AutoDuckingRecoveryTime = reader.ReadUInt32();
                audioBus.AutoDuckingMaxVolume    = reader.ReadSingle();

                audioBus.DuckedBusCount = reader.ReadUInt32();
                audioBus.DuckedBuses    = new DuckedBus[audioBus.DuckedBusCount];
                for (var i = 0; i < audioBus.DuckedBusCount; i++)
                {
                    DuckedBus duckedBus = default;
                    duckedBus.Id            = reader.ReadUInt32();
                    duckedBus.Volume        = reader.ReadSingle();
                    duckedBus.FadeOut       = reader.ReadUInt32();
                    duckedBus.FadeIn        = reader.ReadUInt32();
                    duckedBus.CurveShape    = (CurveShape)reader.ReadByte();
                    duckedBus.Target        = (DuckTarget)reader.ReadByte();
                    audioBus.DuckedBuses[i] = duckedBus;
                }

                audioBus.EffectCount = reader.ReadByte();
                if (audioBus.EffectCount > 0)
                {
                    audioBus.BypassedEffects = (BypassedEffects)reader.ReadByte();
                }
                audioBus.Effects = new Effect[audioBus.EffectCount];
                for (var i = 0; i < audioBus.EffectCount; i++)
                {
                    Effect effect = default;
                    effect.Index        = reader.ReadByte();
                    effect.Id           = reader.ReadUInt32();
                    effect.UseShareSets = reader.ReadBoolean();
                    effect.Rendered     = reader.ReadBoolean();
                    audioBus.Effects[i] = effect;
                }

                audioBus.UnknownBytes = reader.ReadBytes(6);
                audioBus.RtpcCount    = reader.ReadUInt16();
                audioBus.Rtpcs        = new Rtpc[audioBus.RtpcCount];
                for (var i = 0; i < audioBus.RtpcCount; i++)
                {
                    Rtpc rtpc = new Rtpc();
                    rtpc.X                 = reader.ReadUInt32();
                    rtpc.IsMidi            = reader.ReadBoolean();
                    rtpc.IsGeneralSettings = reader.ReadBoolean();
                    rtpc.Parameter         = (RtpcParameterType)reader.ReadByte();
                    rtpc.UnknownId         = reader.ReadUInt32();
                    rtpc.CurveScalingType  = (CurveScalingType)reader.ReadByte();
                    rtpc.PointCount        = reader.ReadUInt16();
                    rtpc.Points            = new RtpcPoint[rtpc.PointCount];
                    for (var j = 0; j < rtpc.PointCount; j++)
                    {
                        RtpcPoint rtpcPoint = default;
                        rtpcPoint.X = reader.ReadSingle();
                        rtpcPoint.Y = reader.ReadSingle();
                        rtpcPoint.FollowingCurveShape = (CurveShape)reader.ReadByte();
                        rtpcPoint.Unknown             = reader.ReadBytes(3);
                        rtpc.Points[j] = rtpcPoint;
                    }
                    audioBus.Rtpcs[i] = rtpc;
                }

                audioBus.StateGroupCount = reader.ReadUInt32();
                audioBus.StateGroups     = new StateGroup[audioBus.StateGroupCount];
                for (var i = 0; i < audioBus.StateGroupCount; i++)
                {
                    StateGroup stateGroup = new StateGroup();
                    stateGroup.Id             = reader.ReadUInt32();
                    stateGroup.ChangeOccursAt = (InteractiveMusicKeyPoint)reader.ReadByte();
                    stateGroup.StateWithCustomSettingsCount = reader.ReadUInt16();
                    stateGroup.StateWithCustomSettings      = new StateWithCustomSettings[stateGroup.StateWithCustomSettingsCount];
                    for (var j = 0; j < stateGroup.StateWithCustomSettingsCount; j++)
                    {
                        StateWithCustomSettings stateWithCustomSettings = default;
                        stateWithCustomSettings.StateId       = reader.ReadUInt32();
                        stateWithCustomSettings.SettingsId    = reader.ReadUInt32();
                        stateGroup.StateWithCustomSettings[j] = stateWithCustomSettings;
                    }
                    audioBus.StateGroups[i] = stateGroup;
                }

                return(audioBus);
            }
        }