public async Task BeatmapDownloadByHash(string hash, CancellationToken token, IProgress <double> progress = null, bool direct = false) { var options = new StandardRequestOptions { Token = token, Progress = progress }; bool songDownloaded = false; while (!songDownloaded) { try { var song = await beatSaverInstance.Hash(hash, options); await BeatSaverBeatmapDownload(song, options, direct); songDownloaded = true; } catch (Exception e) { if (e is BeatSaverSharp.Exceptions.RateLimitExceededException rateLimitException) { double timeRemaining = (rateLimitException.RateLimit.Reset - DateTime.Now).TotalMilliseconds; timeRemaining = timeRemaining > 0 ? timeRemaining : 0; await Task.Delay((int)timeRemaining); continue; } else if (!(e is TaskCanceledException)) { Plugin.Log.Critical(string.Format("Failed to download Song {0}. Exception: {1}", hash, e.ToString())); } songDownloaded = true; } } }
public async Task BeatmapDownloadByHash(string hash, CancellationToken token, IProgress <double> progress = null, bool direct = false) { var options = new StandardRequestOptions { Token = token, Progress = progress }; var song = await beatSaverInstance.Hash(hash, options); try { string customSongsPath = CustomLevelPathHelper.customLevelsDirectoryPath; if (!Directory.Exists(customSongsPath)) { Directory.CreateDirectory(customSongsPath); } var zip = await song.ZipBytes(direct, options).ConfigureAwait(false); await ExtractZipAsync(song, zip, customSongsPath).ConfigureAwait(false); } catch (Exception e) { if (e is TaskCanceledException) { Plugin.Log.Warn("Song Download Aborted."); } else { Plugin.Log.Critical("Failed to download Song!"); } } }
public async Task <IEnumerable <ILookupResult> > GetByExpression(string fileExpression, VersionMatch versionMatch) { if (string.IsNullOrWhiteSpace(fileExpression)) { throw new System.ArgumentNullException(nameof(fileExpression)); } var fileName = System.IO.Path.GetFileNameWithoutExtension(fileExpression); if (fileName.Length == 40) { var map = await _client.Hash(fileName); return(new List <ILookupResult> { new BeatSaverLookupResult(map) }); } throw new System.NotImplementedException(); }
public async Task BeatmapDownloadByHash(string hash, CancellationToken token, IProgress <double> progress = null, bool direct = false) { var options = new StandardRequestOptions { Token = token, Progress = progress }; var song = await beatSaverInstance.Hash(hash, options); try { await BeatSaverBeatmapDownload(song, options, direct); } catch (Exception e) { if (!(e is TaskCanceledException)) { Plugin.Log.Critical(string.Format("Failed to download Song {0}", hash)); } } }
private async Task DownloadPlayList(PlayList playList, string playListName, string bsFolderPath) { var songs = playList.Songs.Count; for (var i = 0; i < songs; i++) { if (!_playlistDownloading.Contains(playListName)) { BeginInvoke((MethodInvoker)(() => { WriteToLog($"Stopped downloading {playListName}"); cboActiveStop.Items.Remove(playListName); cboActiveStop.Text = ""; })); return; } try { var beatMap = await _beatSaver.Hash(playList.Songs[i].Hash); if (CheckIfSongAlreadyPresent(bsFolderPath, beatMap)) { WriteToLog($"{i + 1}/{songs} | {beatMap.Name} already exists!"); continue; } await DownloadAndExtractBeatMap(beatMap, bsFolderPath, i, songs); } catch (Exception ex) { WriteToLog($"{i}/{songs} | failed download{Environment.NewLine}" + $"Message: {ex.Message}"); } } WriteToLog("Finished downloading missing songs from playlist!"); }
private void BSEvents_gameSceneLoaded() { ResetData(); LiveData.InLevel = true; scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault(); scoreController.scoreDidChangeEvent += ScoreController_scoreDidChangeEvent; AudioTimeSyncController audioController = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault(); PlayerData playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().FirstOrDefault().playerData; GameplayCoreSceneSetupData currentMap = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData; IBeatmapLevel levelData = currentMap.difficultyBeatmap.level; StaticData.SongName = levelData.songName; StaticData.SongSubName = levelData.songSubName; StaticData.SongAuthor = levelData.songAuthorName; StaticData.Mapper = levelData.levelAuthorName; StaticData.BPM = Convert.ToInt32(Math.Round(levelData.beatsPerMinute)); StaticData.Length = Convert.ToInt32(Math.Round(audioController.songLength)); PlayerLevelStatsData playerLevelStats = playerData.GetPlayerLevelStatsData(levelData.levelID, currentMap.difficultyBeatmap.difficulty, currentMap.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic); StaticData.PreviousRecord = playerLevelStats.highScore; if (previousMap == null || previousBeatmap == null || (levelData.levelID != previousMap.difficultyBeatmap.level.levelID)) { Task.Run(async() => { if (previousBeatmap != null) { StaticData.PreviousBSR = previousBeatmap.Key; } Beatmap bm = await beatSaver.Hash(levelData.levelID.Replace("custom_level_", "")); if (bm != null) { StaticData.BSRKey = bm.Key; StaticData.coverImage = BeatSaver.BaseURL + bm.CoverURL; previousBeatmap = bm; } else { StaticData.BSRKey = null; StaticData.coverImage = null; previousBeatmap = null; } StaticData.Send(); }); } else { StaticData.BSRKey = previousBeatmap.Key; StaticData.coverImage = BeatSaver.BaseURL + previousBeatmap.CoverURL; } StaticData.Difficulty = currentMap.difficultyBeatmap.difficultyRank; StaticData.NJS = currentMap.difficultyBeatmap.noteJumpMovementSpeed; StaticData.Modifiers.Add("instaFail", currentMap.gameplayModifiers.instaFail); StaticData.Modifiers.Add("batteryEnergy", currentMap.gameplayModifiers.energyType == GameplayModifiers.EnergyType.Battery); StaticData.Modifiers.Add("disappearingArrows", currentMap.gameplayModifiers.disappearingArrows); StaticData.Modifiers.Add("ghostNotes", currentMap.gameplayModifiers.ghostNotes); StaticData.Modifiers.Add("fasterSong", currentMap.gameplayModifiers.songSpeedMul == 1.2f ? true : false); StaticData.Modifiers.Add("noFail", currentMap.gameplayModifiers.noFail); LiveData.PlayerHealth = StaticData.Modifiers["noFail"] ? 100 : 50; StaticData.Modifiers.Add("noObstacles", currentMap.gameplayModifiers.enabledObstacleType == GameplayModifiers.EnabledObstacleType.NoObstacles); StaticData.Modifiers.Add("noBombs", currentMap.gameplayModifiers.noBombs); StaticData.Modifiers.Add("slowerSong", currentMap.gameplayModifiers.songSpeedMul == 0.85f ? true : false); StaticData.Modifiers.Add("noArrows", currentMap.gameplayModifiers.noArrows); if (currentMap.practiceSettings != null) //In Practice mode { StaticData.PracticeMode = true; startSongTime = new TimeSpan(0, 0, (int)Math.Round(currentMap.practiceSettings.startSongTime) - 1); //1s time desync StaticData.PracticeModeModifiers.Add("songSpeedMul", currentMap.practiceSettings.songSpeedMul); } previousMap = currentMap; TimeElapsed.Start(); TimeElapsedLogger.Start(); StaticData.Send(); LiveData.Send(); }
public void SetupMapDataAndMisc() { PlayerData playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().FirstOrDefault().playerData; IBeatmapLevel levelData = gameplayCoreSceneSetupData.difficultyBeatmap.level; bool isCustomLevel = true; string mapHash = string.Empty; try { mapHash = levelData.levelID.Split('_')[2]; } catch { isCustomLevel = false; } isCustomLevel = isCustomLevel && mapHash.Length == 40 ? true : false; var difficultyData = SongCore.Collections.RetrieveDifficultyData(gameplayCoreSceneSetupData.difficultyBeatmap); MapData.Hash = isCustomLevel ? mapHash : null; MapData.SongName = levelData.songName; MapData.SongSubName = levelData.songSubName; MapData.SongAuthor = levelData.songAuthorName; MapData.Mapper = levelData.levelAuthorName; MapData.BPM = Convert.ToInt32(Math.Round(levelData.beatsPerMinute)); MapData.Length = Convert.ToInt32(Math.Round(audioTimeSyncController.songLength)); PlayerLevelStatsData playerLevelStats = playerData.GetPlayerLevelStatsData(levelData.levelID, gameplayCoreSceneSetupData.difficultyBeatmap.difficulty, gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic); MapData.PreviousRecord = playerLevelStats.highScore; MapData.MapType = gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName; MapData.Difficulty = gameplayCoreSceneSetupData.difficultyBeatmap.difficulty.ToString("g"); MapData.NJS = gameplayCoreSceneSetupData.difficultyBeatmap.noteJumpMovementSpeed; MapData.CustomDifficultyLabel = difficultyData?._difficultyLabel ?? null; SongDataCoreCurrent sdc = new SongDataCoreCurrent { available = isCustomLevel ? SongDataCore.Plugin.Songs.IsDataAvailable() : false }; if (sdc.available) { BeatStarSong map; SongDataCore.Plugin.Songs.Data.Songs.TryGetValue(mapHash, out map); sdc.map = map; if (sdc.map != null) { Dictionary <string, BeatStarSongDifficultyStats> diffs = sdc.map.characteristics[(BeatStarCharacteristics)Enum.Parse(typeof(BeatStarCharacteristics), gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)]; sdc.stats = diffs[MapData.Difficulty == "ExpertPlus" ? "Expert+" : MapData.Difficulty]; MapData.PP = sdc.stats.pp; MapData.Star = sdc.stats.star; } else { sdc.available = false; } } if (sdc.available) { MapData.BSRKey = sdc.map.key; if (levelData is CustomPreviewBeatmapLevel customLevel) { MapData.coverImage = GetBase64CoverImage(customLevel); } else { getBeatsaverMap(); } } else { getBeatsaverMap(); } void getBeatsaverMap() { Task.Run(async() => { Beatmap bm = await beatSaver.Hash(mapHash); if (bm != null) { MapData.BSRKey = bm.Key; MapData.coverImage = BeatSaver.BaseURL + bm.CoverURL; } else { MapData.BSRKey = null; } MapData.Send(); }); } if (MapData.Hash != previousStaticData.Hash) { MapData.PreviousBSR = previousStaticData.BSRKey; } MapData.Modifiers.Add("noFailOn0Energy", gameplayCoreSceneSetupData.gameplayModifiers.noFailOn0Energy); MapData.Modifiers.Add("oneLife", gameplayCoreSceneSetupData.gameplayModifiers.instaFail); MapData.Modifiers.Add("fourLives", gameplayCoreSceneSetupData.gameplayModifiers.energyType == GameplayModifiers.EnergyType.Battery); MapData.Modifiers.Add("noBombs", gameplayCoreSceneSetupData.gameplayModifiers.noBombs); MapData.Modifiers.Add("noWalls", gameplayCoreSceneSetupData.gameplayModifiers.enabledObstacleType == GameplayModifiers.EnabledObstacleType.NoObstacles); MapData.Modifiers.Add("noArrows", gameplayCoreSceneSetupData.gameplayModifiers.noArrows); MapData.Modifiers.Add("ghostNotes", gameplayCoreSceneSetupData.gameplayModifiers.ghostNotes); MapData.Modifiers.Add("disappearingArrows", gameplayCoreSceneSetupData.gameplayModifiers.disappearingArrows); MapData.Modifiers.Add("smallNotes", gameplayCoreSceneSetupData.gameplayModifiers.smallCubes); MapData.Modifiers.Add("proMode", gameplayCoreSceneSetupData.gameplayModifiers.proMode); MapData.Modifiers.Add("strictAngles", gameplayCoreSceneSetupData.gameplayModifiers.strictAngles); MapData.Modifiers.Add("zenMode", gameplayCoreSceneSetupData.gameplayModifiers.zenMode); MapData.Modifiers.Add("slowerSong", gameplayCoreSceneSetupData.gameplayModifiers.songSpeedMul == 0.85f ? true : false); MapData.Modifiers.Add("fasterSong", gameplayCoreSceneSetupData.gameplayModifiers.songSpeedMul == 1.2f ? true : false); MapData.Modifiers.Add("superFastSong", gameplayCoreSceneSetupData.gameplayModifiers.songSpeedMul == 1.5f ? true : false); foreach (KeyValuePair <string, bool> keyValue in MapData.Modifiers) { if (MapData.Modifiers[keyValue.Key] && Enum.IsDefined(typeof(Modifiers), keyValue.Key)) { MapData.ModifiersMultiplier += (int)(Modifiers)Enum.Parse(typeof(Modifiers), keyValue.Key) / 100f; } } MapData.PracticeMode = gameplayCoreSceneSetupData.practiceSettings != null ? true : false; MapData.PracticeModeModifiers.Add("songSpeedMul", MapData.PracticeMode ? gameplayCoreSceneSetupData.practiceSettings.songSpeedMul : 1); MapData.PracticeModeModifiers.Add("startInAdvanceAndClearNotes", MapData.PracticeMode ? gameplayCoreSceneSetupData.practiceSettings.startInAdvanceAndClearNotes ? 1 : 0 : 0); MapData.PracticeModeModifiers.Add("startSongTime", MapData.PracticeMode ? gameplayCoreSceneSetupData.practiceSettings.startSongTime : 0); MapData.InLevel = true; timer.Start(); MapData.Send(); LiveData.Send(); }