private void RemoveSoundPackMod(IPluginInfoInteractor mod)
        {
            string modName = mod.UserModInstance != null ? ((IUserMod)mod.UserModInstance as IUserMod).Name : mod.Name;

            if (!this.SoundPackMods.ContainsKey(mod.PublishedFileID.AsUInt64))
            {
                Mod.Instance.Log.Info("Can't remove sound pack mod {0} as it's not found, ignoring...", modName);
                return;
            }

            try
            {
                foreach (var soundPackFile in this.SoundPackMods[mod.PublishedFileID.AsUInt64].SoundPacks)
                {
                    foreach (var group in new Dictionary <string, SoundPacksFileV1.Audio[]>()
                    {
                        { "Ambient", soundPackFile.Ambients },
                        { "AmbientNight", soundPackFile.AmbientsNight },
                        { "Animal", soundPackFile.Animals },
                        { "Building", soundPackFile.Buildings },
                        { "Vehicle", soundPackFile.Vehicles },
                        { "Misc", soundPackFile.Miscs }
                    })
                    {
                        foreach (var audio in group.Value)
                        {
                            string uniqueName = group.Key + "." + audio.Type.ToString() + "." + audio.Name;
                            if (this.AudioFiles.Remove(uniqueName))
                            {
                                Mod.Instance.Log.Debug("Unloaded audio file {0} loaded from sound pack {1}", uniqueName, soundPackFile.Name);
                            }
                            else
                            {
                                Mod.Instance.Log.Debug("Audio file {0} from sound pack {1} was not added", uniqueName, soundPackFile.Name);
                            }
                        }
                    }
                }

                this.SoundPackMods.Remove(mod.PublishedFileID.AsUInt64);
                Mod.Instance.Log.Debug("Unloaded sound pack mod {0}", mod.UserModInstance != null ? ((IUserMod)mod.UserModInstance as IUserMod).Name : mod.Name);
            }
            catch (Exception ex)
            {
                Mod.Instance.Log.Warning("Could not remove the sound packs from mod {0}: {1}", modName, ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unsubscribes from the event when the plugin state changes.
        /// </summary>
        /// <param name="pluginInfo">The plugin info.</param>
        /// <param name="callback">The callback that will be used when the state changes, with a boolean parameter that is true when the plugin is enabled, and false otherwise.</param>
        public static void UnsubscribePluginStateChange(IPluginInfoInteractor pluginInfo, Action <bool> callback)
        {
            string pluginName = pluginInfo.Name;

            if (pluginStateChangeCallbacks.ContainsKey(pluginName))
            {
                pluginStateChangeCallbacks[pluginName].Remove(callback);
                if (pluginStateChangeCallbacks[pluginName].Count == 0)
                {
                    pluginStateChangeCallbacks.Remove(pluginName);
                }
            }

            if (pluginStateChangeCallbacks.Count == 0)
            {
                PluginManagerInteractor.OnPluginsStateChanged -= PluginManager_OnPluginsStateChanged;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Subscribes to the event when the plugin state changes.
        /// </summary>
        /// <param name="pluginInfo">The plugin info.</param>
        /// <param name="callback">The callback that will be used when the state changes, with a boolean parameter that is true when the plugin is enabled, and false otherwise.</param>
        public static void SubscribePluginStateChange(IPluginInfoInteractor pluginInfo, Action <bool> callback)
        {
            string pluginName = pluginInfo.Name;

            if (pluginStateChangeCallbacks.Count == 0)
            {
                PluginManagerInteractor.OnPluginsStateChanged += PluginManager_OnPluginsStateChanged;
                foreach (var pluginInfo_ in PluginManagerInteractor.GetPluginsInfo())
                {
                    pluginEnabledList[pluginInfo_.Name] = pluginInfo_.IsEnabled;
                }
            }

            if (!pluginStateChangeCallbacks.ContainsKey(pluginName))
            {
                pluginStateChangeCallbacks.Add(pluginName, new HashSet <Action <bool> >());
            }

            pluginStateChangeCallbacks[pluginName].Add(callback);
        }
        private void AddSoundPackMod(IPluginInfoInteractor mod)
        {
            string modName = mod.UserModInstance != null ? ((IUserMod)mod.UserModInstance as IUserMod).Name : mod.Name;

            if (this.SoundPackMods.ContainsKey(mod.PublishedFileID.AsUInt64))
            {
                Mod.Instance.Log.Info("Sound pack mod {0} has already been added, ignoring...", modName);
                return;
            }

            string path = Path.Combine(mod.ModPath, SOUNDPACKS_FILENAME_YAML);

            if (!File.Exists(path))
            {
                // Fallback to XML if YAML does not exist
                path = Path.Combine(mod.ModPath, SOUNDPACKS_FILENAME_XML);
            }

            try
            {
                SoundPacksFile soundPackFile = SoundPacksFile.LoadConfig(path, new SoundPacksFileMigrator());
                this.SoundPackMods.Add(mod.PublishedFileID.AsUInt64, soundPackFile);

                foreach (var soundPack in soundPackFile.SoundPacks)
                {
                    // Patch the paths
                    Action <SoundPacksFileV1.AudioInfo> patchAudioInfoClipPath = null;
                    patchAudioInfoClipPath = new Action <SoundPacksFileV1.AudioInfo>(a =>
                    {
                        a.Clip = Path.Combine(mod.ModPath, a.Clip);
                        if (a.Variations != null)
                        {
                            for (int i = 0; i < a.Variations.Length; i++)
                            {
                                patchAudioInfoClipPath(a.Variations[i].AudioInfo);
                            }
                        }
                    });
                    foreach (var group in new[] { soundPack.Ambients, soundPack.AmbientsNight, soundPack.Animals, soundPack.Buildings, soundPack.Vehicles, soundPack.Miscs })
                    {
                        for (int i = 0; i < group.Length; i++)
                        {
                            try
                            {
                                patchAudioInfoClipPath(group[i].AudioInfo);
                            }
                            catch (Exception ex)
                            {
                                Mod.Instance.Log.Warning("Failed to load audio file {0} from sound pack {1} in mod {2}. Please check if your XML or YAML syntax is correct. Keep in mind that XML and YAML tags are case-sensitive! Inner exception was: {3}", group[i].Name, soundPack.Name, modName, ex);
                            }
                        }
                    }

                    // Get every audio
                    var audioFiles = new Dictionary <string, SoundPacksFileV1.Audio>();
                    foreach (var group in new Dictionary <string, SoundPacksFileV1.Audio[]>()
                    {
                        { "Ambient", soundPack.Ambients },
                        { "AmbientNight", soundPack.AmbientsNight },
                        { "Animal", soundPack.Animals },
                        { "Building", soundPack.Buildings },
                        { "Vehicle", soundPack.Vehicles },
                        { "Misc", soundPack.Miscs }
                    })
                    {
                        foreach (var audio in group.Value)
                        {
                            string uniqueName = group.Key + "." + audio.Type.ToString() + "." + audio.Name;
                            if (this.AudioFiles.ContainsKey(uniqueName))
                            {
                                Mod.Instance.Log.Warning("Audio file {0} loaded from sound pack {1} in mod {2} already exists", uniqueName, soundPack.Name, modName);
                            }
                            else
                            {
                                this.AudioFiles[uniqueName] = audio;
                                Mod.Instance.Log.Debug("Loaded audio file {0} from sound pack {1}", uniqueName, soundPack.Name);
                            }
                        }
                    }

                    this.SoundPacks[soundPack.Name] = soundPack;

                    Mod.Instance.Log.Debug("Loaded sound pack {0} from mod {1}", soundPack.Name, modName);
                }
            }
            catch (Exception ex)
            {
                Mod.Instance.Log.Warning("Could not initialize the sound packs from mod {0}: {1}", modName, ex);
            }
        }