public static void SetupSounds(HorseOverhaul mod)
        {
            var soundEffects = new List <Tuple <string, string> >
            {
                new Tuple <string, string>(HorseSnickerSound + "0", "horse-neigh-shortened.wav"),
                new Tuple <string, string>(HorseSnickerSound + "1", "horse-small-whinny.wav"),
                new Tuple <string, string>(HorseSnortSound, "horse-snort-3.wav")
            };

            foreach (var item in soundEffects)
            {
                // Creating cue and setting its name, which will be the name of the audio to play when using sound functions
                var myCueDefinition = new CueDefinition
                {
                    name = item.Item1
                };

                //// myCueDefinition.instanceLimit = 1;
                //// myCueDefinition.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest;

                // Get the audio file and add it to a SoundEffect
                SoundEffect audio;
                string      filePathCombined = Path.Combine(mod.Helper.DirectoryPath, "assets", "sounds", item.Item2);
                using (var stream = new FileStream(filePathCombined, FileMode.Open))
                {
                    audio = SoundEffect.FromStream(stream);
                }

                // Setting the sound effect to the new cue
                myCueDefinition.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound"), false);

                // Adding the cue to the sound bank
                Game1.soundBank.AddCue(myCueDefinition);
            }
        }
        /// <summary>
        /// Create a new instance of the <see cref="SAATSoundBankWrapper"/> class, an implementation of <see cref="ISoundBank"/>.
        /// </summary>
        /// <param name="defaultCue">The cue implementation to default to on failure to retrieve/load cues.</param>
        /// <param name="monitor">Implementation of SMAPI's monitor and logging system.</param>
        /// <param name="wrapper">The game code's implementation of <see cref="ISoundBank"/> currently in use.</param>
        internal SAATSoundBankWrapper(CueDefinition defaultCue, IMonitor monitor, ISoundBank wrapper)
        {
            this.defaultDefinition = defaultCue;
            wrapper.AddCue(defaultCue);
            this.defaultCue = wrapper.GetCue(this.defaultDefinition.name);

            this.sdvSoundBankWrapper = wrapper;
            this.monitor             = monitor;
        }
Пример #3
0
        /// <inheritdoc/>
        public ICue Load(string filePath, string owner, CreateAudioInfo createInfo)
        {
            if (this.cueTable.ContainsKey(createInfo.Name))
            {
                return(this.cueTable[createInfo.Name]);
            }

            SoundEffect sfx;
            uint        byteSize;

            try
            {
                sfx = AudioManager.LoadFile(filePath, out byteSize);
            }
            catch (Exception e)
            {
                this.monitor.Log($"Unable to load audio: {e.Message}\n{e.StackTrace}");
                return(null);
            }

            // Am I being funny yet?
            var cueBall = new CueDefinition(createInfo.Name, sfx, (int)createInfo.Category, createInfo.Loop);

            // Need to add the defition to the bank in order to generate a cue.
            this.SoundBank.AddCue(cueBall);
            var cue = this.SoundBank.GetCue(createInfo.Name);

            this.cueTable.Add(createInfo.Name, cue);

            var track = new Track {
                BufferSize = byteSize,
                Category   = createInfo.Category,
                Filepath   = filePath,
                Id         = createInfo.Name,
                Instance   = cue,
                Loop       = createInfo.Loop,
                Owner      = owner
            };

            this.trackTable.Add(createInfo.Name, track);

            return(cue);
        }
Пример #4
0
    public void MakeSFX(AudioType type, Transform targetTransform)
    {
        CueDefinition selectedDef = null;

        if (type == AudioType.ANY)
        {
            if (m_curDefs.Length > 0)
            {
                selectedDef = m_curDefs[Random.Range(0, m_curDefs.Length)];
            }
        }
        else
        {
            for (int i = 0; i < m_curDefs.Length; ++i)
            {
                if (m_curDefs[i].m_type == type)
                {
                    selectedDef = m_curDefs[i];
                    break;
                }
            }
        }

        if (selectedDef != null)
        {
            if (m_deadSoundCueList.Count > 0)
            {
                m_deadSoundCueList[0].InitSoundCue(targetTransform, selectedDef.m_clip);
                m_aliveSoundCueList.Add(m_deadSoundCueList[0]);
                m_deadSoundCueList.RemoveAt(0);
            }
            else
            {
                var go = GameObject.Instantiate(m_soundCuePrefab);
                var soundCueComponent = go.GetComponent <SoundCue>();
                soundCueComponent.InitSoundCue(targetTransform, selectedDef.m_clip);
                m_aliveSoundCueList.Add(soundCueComponent);
                soundCueComponent.m_OnSoundCueDead += OnSoundCueDead;
            }
        }
    }
Пример #5
0
        private static bool SoundBank_GetCuePrefix(SoundBank __instance, string name, Dictionary <string, CueDefinition> ____cues, AudioEngine ____audioengine, ref Cue __result)
        {
            if (!Config.EnableMod || !replacementDict.ContainsKey(name) || string.IsNullOrEmpty(name))
            {
                return(true);
            }
            CueDefinition cue_definition = __instance.GetCueDefinition(name);

            if (cue_definition.sounds.Count == 0)
            {
                return(true);
            }
            int           cat             = (int)cue_definition.sounds[0].categoryID;
            bool          reverb          = cue_definition.sounds[0].useReverb;
            CueDefinition cue_definition2 = cue_definition;

            string newName = GetReplacement(name);

            if (newName.Length == 0)
            {
                cue_definition2.sounds = new List <XactSoundBankSound>()
                {
                    new XactSoundBankSound(new SoundEffect[] { silentSound }, cat, false, reverb)
                };
            }
            else if (soundEffectDict.ContainsKey(newName))
            {
                cue_definition2.sounds = new List <XactSoundBankSound>()
                {
                    new XactSoundBankSound(new SoundEffect[] { soundEffectDict[newName] }, cat, false, reverb)
                };
            }
            else if (!____cues.TryGetValue(newName, out cue_definition2))
            {
                return(true);
            }
            __result = (Cue)AccessTools.Constructor(typeof(Cue), new Type[] { typeof(AudioEngine), typeof(CueDefinition) }).Invoke(new object[] { ____audioengine, cue_definition2 });
            return(false);
        }
        internal static void Initialize()
        {
            try
            {
                if (MainClass.ModHelper == null)
                {
                    return;
                }

                Dictionary <String, TYPE> soundEffects = new Dictionary <String, TYPE>();

                soundEffects.Add("drop_item", TYPE.Sound);
                soundEffects.Add("colliding", TYPE.Sound);

                soundEffects.Add("npc_top", TYPE.Footstep);
                soundEffects.Add("npc_right", TYPE.Footstep);
                soundEffects.Add("npc_left", TYPE.Footstep);
                soundEffects.Add("npc_bottom", TYPE.Footstep);

                soundEffects.Add("obj_top", TYPE.Footstep);
                soundEffects.Add("obj_right", TYPE.Footstep);
                soundEffects.Add("obj_left", TYPE.Footstep);
                soundEffects.Add("obj_bottom", TYPE.Footstep);

                soundEffects.Add("npc_mono_top", TYPE.Footstep);
                soundEffects.Add("npc_mono_right", TYPE.Footstep);
                soundEffects.Add("npc_mono_left", TYPE.Footstep);
                soundEffects.Add("npc_mono_bottom", TYPE.Footstep);

                soundEffects.Add("obj_mono_top", TYPE.Footstep);
                soundEffects.Add("obj_mono_right", TYPE.Footstep);
                soundEffects.Add("obj_mono_left", TYPE.Footstep);
                soundEffects.Add("obj_mono_bottom", TYPE.Footstep);

                for (int i = 0; i < soundEffects.Count; i++)
                {
                    KeyValuePair <String, TYPE> soundEffect = soundEffects.ElementAt(i);

                    CueDefinition cueDefinition = new CueDefinition();
                    cueDefinition.name = soundEffect.Key;

                    if (soundEffect.Value == TYPE.Sound)
                    {
                        cueDefinition.instanceLimit = 1;
                        cueDefinition.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest;
                    }

                    SoundEffect effect;
                    string      filePath = Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "sounds", $"{soundEffect.Key}.wav");
                    using (FileStream stream = new(filePath, FileMode.Open))
                    {
                        effect = SoundEffect.FromStream(stream);
                    }

                    if (soundEffect.Value == TYPE.Sound)
                    {
                        cueDefinition.SetSound(effect, Game1.audioEngine.GetCategoryIndex("Sound"), false);
                    }
                    else if (soundEffect.Value == TYPE.Footstep)
                    {
                        cueDefinition.SetSound(effect, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
                    }

                    Game1.soundBank.AddCue(cueDefinition);
                }
            }
            catch (Exception e)
            {
                MainClass.ErrorLog($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}");
            }
        }
 /// <summary>
 /// Add a <see cref="CueDefinition"/> to the sound bank, allowing for cue creation of the audio track.
 /// </summary>
 /// <param name="cueDefinition">The instance to add.</param>
 public void AddCue(CueDefinition cueDefinition)
 {
     this.sdvSoundBankWrapper.AddCue(cueDefinition);
 }