static bool Prefix(string customLevelPath, string difficultyFileName, StandardLevelInfoSaveData standardLevelInfoSaveData, ref BeatmapData __result) { string path = Path.Combine(customLevelPath, difficultyFileName); if (File.Exists(path)) { string json = File.ReadAllText(path); CustomBeatmapSaveData bsd = CustomBeatmapSaveData.DeserializeFromJSONString(json); // NOTE: logic depends on the above call always returning non-null when the vanilla version would! if (bsd == null) { __result = BeatmapDataLoader.GetBeatmapDataFromJson(json, standardLevelInfoSaveData.beatsPerMinute, standardLevelInfoSaveData.shuffle, standardLevelInfoSaveData.shufflePeriod); } else if (standardLevelInfoSaveData is CustomLevelInfoSaveData lisd) { __result = CustomBeatmapDataLoader.GetBeatmapDataFromBeatmapSaveData(bsd.notes, bsd.obstacles, bsd.events, lisd.beatsPerMinute, lisd.shuffle, lisd.shufflePeriod, bsd.customEvents ?? new List <CustomBeatmapSaveData.CustomEventData>(), at(lisd.beatmapCustomDatasByFilename, difficultyFileName) ?? Tree(), lisd.customData ?? Tree()); } else { __result = CustomBeatmapDataLoader.GetBeatmapDataFromBeatmapSaveData(bsd.notes, bsd.obstacles, bsd.events, standardLevelInfoSaveData.beatsPerMinute, standardLevelInfoSaveData.shuffle, standardLevelInfoSaveData.shufflePeriod, bsd.customEvents ?? new List <CustomBeatmapSaveData.CustomEventData>(), Tree(), Tree()); } } return(false); }
private async Task PrepareNextSong() { try { bool validSong = false; while (!validSong) { await Task.Yield(); IPreviewBeatmapLevel previewLevel = null; IPreviewBeatmapLevel requestLevel = null; if (Config.EndlessPrioritizeSongRequests) { requestLevel = await GetSongRequestSong(); } if (requestLevel != null) { previewLevel = requestLevel; } else { if (Config.EndlessPlaySongsInOrder) { if (levelCollection.Count() <= 1) { break; } var currLevel = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.level; if (orderedIdx == -1) { if (currLevel is CustomPreviewBeatmapLevel) { orderedIdx = levelCollection.IndexOf(levelCollection.First(x => x.levelID == currLevel.levelID)); } else { orderedIdx = 0; } } orderedIdx++; if (orderedIdx > levelCollection.Count() - 1) { orderedIdx = 0; } // else // orderedIdx = orderedIdx++; previewLevel = levelCollection[orderedIdx]; } else { if (ToPlay.Count == 0) { if (!FoundValidSong) { break; } else { ResetToPlay(); } } int nextSongIndex = random.Next(0, ToPlay.Count); previewLevel = ToPlay[nextSongIndex]; ToPlay.RemoveAt(nextSongIndex); } } validSong = IsValid(previewLevel, out nextMapDiffInfo); if (validSong) { nextSongInfo = previewLevel as CustomPreviewBeatmapLevel; } // Plugin.Log("Removing song, new count: " + ToPlay.Count); } if (nextMapDiffInfo == null) { return; } FoundValidSong = true; await IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew( async() => nextSong = await nextSongInfo.GetPreviewAudioClipAsync(CancellationTokenSource.Token)); // bool loaded; // await Task.Run(() => loaded = nextSong.LoadAudioData()); string path = Path.Combine(nextSongInfo.customLevelPath, nextMapDiffInfo.beatmapFilename); string json = File.ReadAllText(path); nextBeatmap = dataLoader.GetBeatmapDataFromJson(json, nextSongInfo.beatsPerMinute, nextSongInfo.shuffle, nextSongInfo.shufflePeriod); Plugin.Log($"Next Song: {nextSongInfo.songName} - Mapped by {nextSongInfo.levelAuthorName}, is Ready"); } catch (Exception ex) { Plugin.Log(ex.ToString()); } }
static bool Prefix(BeatmapDataLoader ____beatmapDataLoader, string customLevelPath, string difficultyFileName, StandardLevelInfoSaveData standardLevelInfoSaveData, ref BeatmapData __result) { //Plugin.logger.Debug("In LoadBeatmapDataBeatmapData"); string path = Path.Combine(customLevelPath, difficultyFileName); //Plugin.logger.Debug("Loading " + standardLevelInfoSaveData.songName + " (" + path + ")"); if (File.Exists(path)) { string json = File.ReadAllText(path); CustomBeatmapSaveData bsd = CustomBeatmapSaveData.DeserializeFromJSONString(json); // NOTE: logic depends on the above call always returning non-null when the vanilla version would! if (bsd == null) { //Plugin.logger.Debug("CustomBeatmapSaveData was null; falling back to BeatmapDataLoader.GetBeatmapDataFromJson"); __result = ____beatmapDataLoader.GetBeatmapDataFromJson(json, standardLevelInfoSaveData.beatsPerMinute, standardLevelInfoSaveData.shuffle, standardLevelInfoSaveData.shufflePeriod); } else if (standardLevelInfoSaveData is CustomLevelInfoSaveData lisd) { //Plugin.logger.Debug("Loaded CustomBeatmapSaveData with CustomLevelInfoSaveData"); __result = CustomBeatmapDataLoader.GetBeatmapDataFromBeatmapSaveData(bsd.notes, bsd.obstacles, bsd.events, lisd.beatsPerMinute, lisd.shuffle, lisd.shufflePeriod, bsd.customEvents ?? new List <CustomBeatmapSaveData.CustomEventData>(), at(lisd.beatmapCustomDatasByFilename, difficultyFileName) ?? Tree(), lisd.customData ?? Tree(), ____beatmapDataLoader); } else { //Plugin.logger.Debug("Loaded CustomBeatmapSaveData with StandardLevelInfoSaveData"); __result = CustomBeatmapDataLoader.GetBeatmapDataFromBeatmapSaveData(bsd.notes, bsd.obstacles, bsd.events, standardLevelInfoSaveData.beatsPerMinute, standardLevelInfoSaveData.shuffle, standardLevelInfoSaveData.shufflePeriod, bsd.customEvents ?? new List <CustomBeatmapSaveData.CustomEventData>(), Tree(), Tree(), ____beatmapDataLoader); } /* * if (__result is CustomBeatmapData beatmapData) * { * foreach (var line in beatmapData.beatmapLinesData) * { * foreach (var obj in line.beatmapObjectsData) * { * if (obj is CustomObstacleData obs) * { * Plugin.logger.Debug("Custom obstacle at " + obs.time); * Plugin.logger.Debug("Data:"); * foreach (var pair in (IDictionary<string, object>)obs.customData) * { * Plugin.logger.Debug(" \"" + pair.Key + "\": " + pair.Value); * } * } * else if (obj is ObstacleData ob) * { * Plugin.logger.Debug("Non-custom obstacle at " + ob.time); * } * if (obj is CustomNoteData n) * { * Plugin.logger.Debug("Custom note at " + n.time); * Plugin.logger.Debug("Data:"); * foreach (var pair in (IDictionary<string, object>)n.customData) * { * Plugin.logger.Debug(" \"" + pair.Key + "\": " + pair.Value); * } * } * else if (obj is NoteData no) * { * Plugin.logger.Debug("Non-custom note at " + no.time); * } * } * } * foreach (var pair in beatmapData.customEventData) * { * Plugin.logger.Debug("Custom event \"" + pair.Key + "\":"); * foreach (var e in pair.Value) * { * Plugin.logger.Debug(" " + e.time + ":"); * foreach (var innerPair in (IDictionary<string, object>)e.data) * { * Plugin.logger.Debug(" \"" + innerPair.Key + "\": " + innerPair.Value); * } * } * } * } */ } return(false); }