Beispiel #1
0
        /// <summary>
        /// Adds a gameplayModifier to our list, getting rid of any incompatible mods that are currently in there.
        /// </summary>
        public static void AddMod(ModIdentifier modIdentifier)
        {
            IGameplayModifier gameplayModifier;

            // Set the newMod based on the ModType that is coming in
            switch (modIdentifier)
            {
            case ModIdentifier.Autoplay:
                gameplayModifier = new ModAutoplay();
                break;

            default:
                return;
            }

            // Remove incompatible mods.
            var incompatibleMods = CurrentModifiersList.FindAll(x => x.IncompatibleMods.Contains(gameplayModifier.ModIdentifier));

            incompatibleMods.ForEach(x => RemoveMod(x.ModIdentifier));

            // Remove the mod if it's already on.
            var alreadyOnMod = CurrentModifiersList.Find(x => x.ModIdentifier == gameplayModifier.ModIdentifier);

            if (alreadyOnMod != null)
            {
                CurrentModifiersList.Remove(alreadyOnMod);
            }

            // Add The Mod
            CurrentModifiersList.Add(gameplayModifier);
            gameplayModifier.InitializeMod();

            ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
            Logger.Log($"Added mod: {gameplayModifier.ModIdentifier}.", LogLevel.Info);
        }
Beispiel #2
0
        /// <summary>
        ///     Removes all items from our list of mods
        /// </summary>
        public static void RemoveAllMods()
        {
            CurrentModifiersList.Clear();
            CheckModInconsistencies();

            ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
            Logger.Debug("Removed all modifiers", LogType.Runtime, false);
        }
Beispiel #3
0
        /// <summary>
        /// Removes all items from our list of mods
        /// </summary>
        public static void RemoveAllMods()
        {
            CurrentModifiersList.Clear();
            CheckModInconsistencies();

            ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
            Logger.Log("Removed all modifiers", LogLevel.Info);
        }
Beispiel #4
0
        /// <summary>
        /// Removes a gameplayModifier from our GameBase
        /// </summary>
        public static void RemoveMod(ModIdentifier modIdentifier)
        {
            try
            {
                // Try to find the removed gameplayModifier in the list
                var removedMod = CurrentModifiersList.Find(x => x.ModIdentifier == modIdentifier);

                // Remove the Mod
                CurrentModifiersList.Remove(removedMod);

                ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
                Logger.Log($"Removed mod: {removedMod.ModIdentifier}.", LogLevel.Info);
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Removes any speed mods from the game and resets the clock
        /// </summary>
        public static void RemoveSpeedMods()
        {
            try
            {
                CurrentModifiersList.RemoveAll(x => x.Type == ModType.Speed);

                if (AudioEngine.Track != null)
                {
                    AudioEngine.Track.Rate = ModHelper.GetRateFromMods(Mods);
                }

                CheckModInconsistencies();

                ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
                Logger.Debug("Removed all speed modifiers", LogType.Runtime, false);
            }
            catch (Exception e)
            {
                Logger.Error(e, LogType.Runtime);
            }
        }
Beispiel #6
0
        private void RemoveMod(Mod mod)
        {
            mod.Loaded             -= OnModLoaded;
            mod.Unloaded           -= OnModUnloaded;
            mod.LoadCancelled      -= OnModLoadCancelled;
            mod.SceneLoaded        -= OnSceneLoaded;
            mod.SceneUnloaded      -= OnSceneUnloaded;
            mod.SceneLoadCancelled -= OnSceneLoadCancelled;
            mod.SetInvalid();

            foreach (Mod other in _mods)
            {
                other.UpdateConflicts(mod);
            }

            LogUtility.LogInfo("Mod removed: " + mod.name);
            _mods.Remove(mod);

            ModRemoved?.Invoke(mod);
            ModsChanged?.Invoke();
        }
Beispiel #7
0
        private void AddMod(Mod mod)
        {
            mod.Loaded             += OnModLoaded;
            mod.Unloaded           += OnModUnloaded;
            mod.LoadCancelled      += OnModLoadCancelled;
            mod.SceneLoaded        += OnSceneLoaded;
            mod.SceneUnloaded      += OnSceneUnloaded;
            mod.SceneLoadCancelled += OnSceneLoadCancelled;

            mod.UpdateConflicts(_mods);
            foreach (Mod other in _mods)
            {
                other.UpdateConflicts(mod);
            }

            LogUtility.LogInfo("Mod found: " + mod.name + " - " + mod.contentType);
            _mods.Add(mod);

            ModFound?.Invoke(mod);
            ModsChanged?.Invoke();
        }
Beispiel #8
0
        /// <summary>
        /// Refresh the collection of mod paths. Remove all missing paths and add all new paths.
        /// </summary>
        public void Refresh()
        {
            LogUtility.LogDebug("Refreshing Mod search directory: " + path);

            bool changed = false;

            string[] modInfoPaths = GetModInfoPaths();

            foreach (string path in _modPaths.Keys.ToArray())
            {
                if (!modInfoPaths.Contains(path))
                {
                    changed = true;
                    RemoveModPath(path);
                    continue;
                }

                DirectoryInfo modDirectory = new DirectoryInfo(Path.GetDirectoryName(path));

                long currentTicks  = DateTime.Now.Ticks;
                long lastWriteTime = _modPaths[path];

                if (modDirectory.LastWriteTime.Ticks > lastWriteTime)
                {
                    changed         = true;
                    _modPaths[path] = currentTicks;
                    UpdateModPath(path);
                    continue;
                }

                foreach (DirectoryInfo directory in modDirectory.GetDirectories("*", SearchOption.AllDirectories))
                {
                    if (directory.LastWriteTime.Ticks > lastWriteTime)
                    {
                        changed         = true;
                        _modPaths[path] = currentTicks;
                        UpdateModPath(path);
                        break;
                    }
                }

                foreach (FileInfo file in modDirectory.GetFiles("*", SearchOption.AllDirectories))
                {
                    if (file.Extension == ".info")
                    {
                        continue;
                    }

                    if (file.LastWriteTime.Ticks > lastWriteTime)
                    {
                        changed         = true;
                        _modPaths[path] = currentTicks;
                        UpdateModPath(path);
                        break;
                    }
                }
            }

            foreach (string path in modInfoPaths)
            {
                if (!_modPaths.ContainsKey(path))
                {
                    changed = true;
                    AddModPath(path);
                }
            }

            if (changed)
            {
                ModsChanged?.Invoke();
            }
        }
Beispiel #9
0
        /// <summary>
        ///     Adds a gameplayModifier to our list, getting rid of any incompatible mods that are currently in there.
        ///     Also, specifying a speed, if need-be. That is only "required" if passing in ModIdentifier.ManiaModSpeed
        /// </summary>
        public static void AddMod(ModIdentifier modIdentifier)
        {
            IGameplayModifier gameplayModifier;

            // Set the newMod based on the ModType that is coming in
            switch (modIdentifier)
            {
            case ModIdentifier.Speed05X:
            case ModIdentifier.Speed06X:
            case ModIdentifier.Speed07X:
            case ModIdentifier.Speed08X:
            case ModIdentifier.Speed09X:
            case ModIdentifier.Speed11X:
            case ModIdentifier.Speed12X:
            case ModIdentifier.Speed13X:
            case ModIdentifier.Speed14X:
            case ModIdentifier.Speed15X:
            case ModIdentifier.Speed16X:
            case ModIdentifier.Speed17X:
            case ModIdentifier.Speed18X:
            case ModIdentifier.Speed19X:
            case ModIdentifier.Speed20X:
                gameplayModifier = new ModSpeed(modIdentifier);
                break;

            case ModIdentifier.NoSliderVelocity:
                gameplayModifier = new ModNoSliderVelocities();
                break;

            case ModIdentifier.Strict:
                gameplayModifier = new ModStrict();
                break;

            case ModIdentifier.Chill:
                gameplayModifier = new ModChill();
                break;

            case ModIdentifier.Autoplay:
                gameplayModifier = new ModAutoplay();
                break;

            case ModIdentifier.Paused:
                gameplayModifier = new ModPaused();
                break;

            case ModIdentifier.NoFail:
                gameplayModifier = new ModNoFail();
                break;

            case ModIdentifier.NoLongNotes:
                gameplayModifier = new ModNoLongNotes();
                break;

            default:
                return;
            }

            // Remove incompatible mods.
            var incompatibleMods = CurrentModifiersList.FindAll(x => x.IncompatibleMods.Contains(gameplayModifier.ModIdentifier));

            incompatibleMods.ForEach(x => RemoveMod(x.ModIdentifier));

            // Remove the mod if it's already on.
            var alreadyOnMod = CurrentModifiersList.Find(x => x.ModIdentifier == gameplayModifier.ModIdentifier);

            if (alreadyOnMod != null)
            {
                CurrentModifiersList.Remove(alreadyOnMod);
            }

            // Add The Mod
            CurrentModifiersList.Add(gameplayModifier);
            gameplayModifier.InitializeMod();

            ModsChanged?.Invoke(typeof(ModManager), new ModsChangedEventArgs(Mods));
            Logger.Debug($"Added mod: {gameplayModifier.ModIdentifier}.", LogType.Runtime, false);
        }