Example #1
0
        public static IDifficultyBeatmap GetDifficultyBeatmap(this BeatmapLevelSO level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, bool strictDifficulty = false)
        {
            IDifficultyBeatmapSet difficultySet = null;

            if (characteristic == null)
            {
                difficultySet = level.difficultyBeatmapSets.FirstOrDefault();
            }
            else
            {
                difficultySet = level.difficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic == characteristic);
            }

            if (difficultySet == null)
            {
                return(null);
            }

            IDifficultyBeatmap beatmap = difficultySet.difficultyBeatmaps.FirstOrDefault(x => x.difficulty == difficulty);

            if (beatmap == null && !strictDifficulty)
            {
                return(difficultySet.difficultyBeatmaps[GetClosestDifficultyIndex(difficultySet.difficultyBeatmaps, difficulty)]);
            }
            else
            {
                return(beatmap);
            }
        }
        static void Prefix(StandardLevelDetailView __instance, IBeatmapLevel level, BeatmapDifficulty defaultDifficulty, BeatmapCharacteristicSO defaultBeatmapCharacteristic, PlayerData playerData)
        {
            List <BeatmapCharacteristicSO> toGenerate = new List <BeatmapCharacteristicSO>();

            if (Config.Instance.ShowGenerated360)
            {
                toGenerate.Add(GameModeHelper.GetGenerated360GameMode());
            }
            if (Config.Instance.ShowGenerated90)
            {
                toGenerate.Add(GameModeHelper.GetGenerated90GameMode());
            }

            List <IDifficultyBeatmapSet> sets = new List <IDifficultyBeatmapSet>(level.beatmapLevelData.difficultyBeatmapSets);

            // Generate each custom gamemode
            foreach (BeatmapCharacteristicSO customGameMode in toGenerate)
            {
                if (level.beatmapLevelData.difficultyBeatmapSets.Any((e) => e.beatmapCharacteristic.serializedName == GameModeHelper.GENERATED_360DEGREE_MODE))
                {
                    // Already added the generated gamemode
                    continue;
                }

                IDifficultyBeatmapSet basedOnGameMode = level.beatmapLevelData.difficultyBeatmapSets.FirstOrDefault((e) => e.beatmapCharacteristic.serializedName == Config.Instance.BasedOn);
                if (basedOnGameMode == null)
                {
                    // Level does not have a standard mode to base its 360 mode on
                    continue;
                }

                CustomDifficultyBeatmapSet customSet    = new CustomDifficultyBeatmapSet(customGameMode);
                CustomDifficultyBeatmap[]  difficulties = basedOnGameMode.difficultyBeatmaps.Select((e) => new CustomDifficultyBeatmap(e.level, customSet, e.difficulty, e.difficultyRank, e.noteJumpMovementSpeed, e.noteJumpStartBeatOffset, e.beatmapData.GetCopy())).ToArray();
                customSet.SetCustomDifficultyBeatmaps(difficulties);
                sets.Add(customSet);
            }

            // Update difficultyBeatmapSets
            if (level.beatmapLevelData is BeatmapLevelData data)
            {
                if (!FieldHelper.Set(data, "_difficultyBeatmapSets", sets.ToArray()))
                {
                    Plugin.Log.Warn("Could not set new difficulty sets");
                    return;
                }
            }
            else
            {
                Plugin.Log.Info("Unsupported beatmapLevelData: " + (level.beatmapLevelData?.GetType().FullName ?? "null"));
            }
        }
Example #3
0
        // Taken from BeatSaberMultiplayer
        public static IDifficultyBeatmap GetDifficultyBeatmap(this IBeatmapLevel level,
                                                              BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, bool strictDifficulty = false)
        {
            IDifficultyBeatmapSet difficultySet = null;

            if (characteristic == null)
            {
                difficultySet = level.beatmapLevelData.difficultyBeatmapSets.FirstOrDefault();
            }
            else
            {
                difficultySet =
                    level.beatmapLevelData.difficultyBeatmapSets.FirstOrDefault(x =>
                                                                                x.beatmapCharacteristic == characteristic);
                if (difficultySet == null)
                {
                    difficultySet = level.beatmapLevelData.difficultyBeatmapSets.FirstOrDefault();
                }
            }

            if (difficultySet == null)
            {
                Plugin.log.Error("Unable to find any difficulty set!");
                return(null);
            }

            var beatmap = difficultySet.difficultyBeatmaps.FirstOrDefault(x => x.difficulty == difficulty);

            if (beatmap == null && !strictDifficulty)
            {
                var index = GetClosestDifficultyIndex(difficultySet.difficultyBeatmaps, difficulty);
                if (index >= 0)
                {
                    return(difficultySet.difficultyBeatmaps[index]);
                }
                else
                {
                    Plugin.log.Error("Unable to find difficulty!");
                    return(null);
                }
            }
            else
            {
                return(beatmap);
            }
        }