public static async void LoadBeatmapLevelAsync( BeatmapCharacteristicSO characteristic, IPreviewBeatmapLevel selectedLevel, BeatmapDifficulty difficulty, Action <AdditionalContentModel.EntitlementStatus, bool, IBeatmapLevel> callback) { _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); _contentModelSO = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); var token = new CancellationTokenSource(); Plugin.log.Info("Checking entitlement"); var entitlementStatus = await _contentModelSO.GetLevelEntitlementStatusAsync(selectedLevel.levelID, token.Token); if (entitlementStatus == AdditionalContentModel.EntitlementStatus.Owned) { Plugin.log.Info("Level owned. Loading..."); var getBeatmapLevelResult = await _beatmapLevelsModel.GetBeatmapLevelAsync(selectedLevel.levelID, token.Token); callback?.Invoke(entitlementStatus, !getBeatmapLevelResult.isError, getBeatmapLevelResult.beatmapLevel); Plugin.log.Info("Starting..."); StartLevel(getBeatmapLevelResult.beatmapLevel, characteristic, difficulty, GameplayModifiers.defaultModifiers); } else { callback?.Invoke(entitlementStatus, false, null); } }
IEnumerator IEInstantiateAudioSource() { yield return(new WaitUntil(() => Resources.FindObjectsOfTypeAll <MainSettingsModelSO>().Any())); MainSettingsModelSO mainSettings = Resources.FindObjectsOfTypeAll <MainSettingsModelSO>().FirstOrDefault(); _maxPreviewVolume = mainSettings.volume * 0.5f; yield return(new WaitUntil(() => Resources.FindObjectsOfTypeAll <SongPreviewPlayer>().Any())); _songPreviewPlayer = Resources.FindObjectsOfTypeAll <SongPreviewPlayer>().FirstOrDefault(); _songPreviewPlayer.FadeOut(1); yield return(new WaitUntil(() => Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().Any())); BeatmapLevelsModel levelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); BeatmapLevelPackCollectionSO packCollectionSO = levelsModel.ostAndExtrasPackCollection; BeatmapLevelPackSO[] levelPack = packCollectionSO.GetField <BeatmapLevelPackSO[]>("_beatmapLevelPacks"); BeatmapLevelCollectionSO levelCollectionSO = levelPack[5].GetField <BeatmapLevelCollectionSO>("_beatmapLevelCollection"); BeatmapLevelSO[] levels = levelCollectionSO.GetField <BeatmapLevelSO[]>("_beatmapLevels"); AudioClip clip = levels[1].GetField <AudioClip>("_audioClip"); _audioSource = new GameObject("SSAudSource").AddComponent <AudioSource>(); _audioSource.clip = clip; _audioSource.spatialBlend = 0; _audioSource.loop = true; _audioSource.volume = 0; _audioSource.time = 20f; _audioSource.Play(); }
// Yoinked from TournamentAssistant public static async void PlaySong(IPreviewBeatmapLevel level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, OverrideEnvironmentSettings overrideEnvironmentSettings = null, ColorScheme colorScheme = null, GameplayModifiers gameplayModifiers = null, PlayerSpecificSettings playerSettings = null, Action <StandardLevelScenesTransitionSetupDataSO, LevelCompletionResults> songFinishedCallback = null) { Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { MenuTransitionsHelper _menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelper>().First(); _menuSceneSetupData.StartStandardLevel( loadedLevel.beatmapLevelData.GetDifficultyBeatmap(characteristic, difficulty), overrideEnvironmentSettings, colorScheme, gameplayModifiers ?? new GameplayModifiers(), playerSettings ?? new PlayerSpecificSettings(), null, "Menu", false, null, (standardLevelScenesTransitionSetupData, results) => songFinishedCallback?.Invoke(standardLevelScenesTransitionSetupData, results) ); }; BeatmapLevelsModel beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); var result = await GetLevelFromPreview(level); if (result != null && !(result?.isError == true)) { //HTTPstatus requires cover texture to be applied in here, and due to a fluke //of beat saber, it's not applied when the level is loaded, but it *is* //applied to the previewlevel it's loaded from var loadedLevel = result?.beatmapLevel; loadedLevel.SetField("_coverImageTexture2D", level.GetField <Texture2D>("_coverImageTexture2D")); SongLoaded(loadedLevel); } }
/// <summary> /// Constructor. Acquire all necessary BeatSaberUi elements. /// </summary> /// <param name="flowCoordinator"></param> public BeatSaberUIController(LevelSelectionFlowCoordinator flowCoordinator) { Logger.Debug("Collecting all BeatSaberUI Elements..."); LevelSelectionFlowCoordinator = flowCoordinator; // gather flow coordinator elements LevelSelectionNavigationController = LevelSelectionFlowCoordinator.GetField <LevelSelectionNavigationController, LevelSelectionFlowCoordinator>("levelSelectionNavigationController"); Logger.Debug("Acquired LevelSelectionNavigationController [{0}]", LevelSelectionNavigationController.GetInstanceID()); LevelFilteringNavigationController = LevelSelectionNavigationController.GetField <LevelFilteringNavigationController, LevelSelectionNavigationController>("_levelFilteringNavigationController"); Logger.Debug("Acquired LevelFilteringNavigationController [{0}]", LevelFilteringNavigationController.GetInstanceID()); LevelCollectionNavigationController = LevelSelectionNavigationController.GetField <LevelCollectionNavigationController, LevelSelectionNavigationController>("_levelCollectionNavigationController"); Logger.Debug("Acquired LevelCollectionNavigationController [{0}]", LevelCollectionNavigationController.GetInstanceID()); LevelCollectionViewController = LevelCollectionNavigationController.GetField <LevelCollectionViewController, LevelCollectionNavigationController>("_levelCollectionViewController"); Logger.Debug("Acquired LevelPackLevelsViewController [{0}]", LevelCollectionViewController.GetInstanceID()); LevelDetailViewController = LevelCollectionNavigationController.GetField <StandardLevelDetailViewController, LevelCollectionNavigationController>("_levelDetailViewController"); Logger.Debug("Acquired StandardLevelDetailViewController [{0}]", LevelDetailViewController.GetInstanceID()); LevelCollectionTableView = this.LevelCollectionViewController.GetField <LevelCollectionTableView, LevelCollectionViewController>("_levelCollectionTableView"); Logger.Debug("Acquired LevelPackLevelsTableView [{0}]", LevelCollectionTableView.GetInstanceID()); StandardLevelDetailView = LevelDetailViewController.GetField <StandardLevelDetailView, StandardLevelDetailViewController>("_standardLevelDetailView"); Logger.Debug("Acquired StandardLevelDetailView [{0}]", StandardLevelDetailView.GetInstanceID()); BeatmapCharacteristicSelectionViewController = StandardLevelDetailView.GetField <BeatmapCharacteristicSegmentedControlController, StandardLevelDetailView>("_beatmapCharacteristicSegmentedControlController"); Logger.Debug("Acquired BeatmapCharacteristicSegmentedControlController [{0}]", BeatmapCharacteristicSelectionViewController.GetInstanceID()); LevelDifficultyViewController = StandardLevelDetailView.GetField <BeatmapDifficultySegmentedControlController, StandardLevelDetailView>("_beatmapDifficultySegmentedControlController"); Logger.Debug("Acquired BeatmapDifficultySegmentedControlController [{0}]", LevelDifficultyViewController.GetInstanceID()); LevelCollectionTableViewTransform = LevelCollectionTableView.transform as RectTransform; Logger.Debug("Acquired TableViewRectTransform from LevelPackLevelsTableView [{0}]", LevelCollectionTableViewTransform.GetInstanceID()); AnnotatedBeatmapLevelCollectionsViewController = LevelFilteringNavigationController.GetField <AnnotatedBeatmapLevelCollectionsViewController, LevelFilteringNavigationController>("_annotatedBeatmapLevelCollectionsViewController"); Logger.Debug("Acquired AnnotatedBeatmapLevelCollectionsViewController from LevelFilteringNavigationController [{0}]", AnnotatedBeatmapLevelCollectionsViewController.GetInstanceID()); TableView tableView = LevelCollectionTableView.GetField <TableView, LevelCollectionTableView>("_tableView"); ScrollView scrollView = tableView.GetField <ScrollView, TableView>("_scrollView"); TableViewPageUpButton = scrollView.GetField <Button, ScrollView>("_pageUpButton"); TableViewPageDownButton = scrollView.GetField <Button, ScrollView>("_pageDownButton"); Logger.Debug("Acquired Page Up and Down buttons..."); ActionButtons = StandardLevelDetailView.GetComponentsInChildren <RectTransform>().First(x => x.name == "ActionButtons"); Logger.Debug("Acquired ActionButtons [{0}]", ActionButtons.GetInstanceID()); ScreenSystem = Resources.FindObjectsOfTypeAll <ScreenSystem>().Last(); Logger.Debug("Acquired ScreenSystem [{0}]", ScreenSystem.GetInstanceID()); SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll <SimpleDialogPromptViewController>().Last(); Logger.Debug("Acquired SimpleDialogPromptViewControllerPrefab [{0}]", SimpleDialogPromptViewControllerPrefab.GetInstanceID()); BeatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().Last(); Logger.Debug("Acquired BeatmapLevelsModel [{0}]", BeatmapLevelsModel); }
public static CustomPreviewBeatmapLevel GetLevel(string levelId) { if (_beatmapLevelsModel == null) { _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); } return(_beatmapLevelsModel.allLoadedBeatmapLevelPackCollection.beatmapLevelPacks.SelectMany(x => x.beatmapLevelCollection.beatmapLevels).FirstOrDefault(x => x.levelID == levelId) as CustomPreviewBeatmapLevel); }
public static void OnLoad() { if (Instance != null) { _beatmapLevelsModel = null; Instance.RefreshLevelPacks(); return; } new GameObject("SongCore Loader").AddComponent <Loader>(); }
/// <summary> /// Constructor. Acquire all necessary BeatSaberUi elements. /// </summary> /// <param name="flowCoordinator"></param> public BeatSaberUIController(FlowCoordinator flowCoordinator) { Logger.Debug("Collecting all BeatSaberUI Elements..."); LevelSelectionFlowCoordinator = flowCoordinator; // gather flow coordinator elements LevelSelectionNavigationController = LevelSelectionFlowCoordinator.GetPrivateField <LevelSelectionNavigationController>("_levelSelectionNavigationController"); Logger.Debug("Acquired LevelSelectionNavigationController [{0}]", LevelSelectionNavigationController.GetInstanceID()); // this is loaded late but available early, grab globally. LevelFilteringNavigationController = Resources.FindObjectsOfTypeAll <LevelFilteringNavigationController>().First(); //LevelSelectionFlowCoordinator.GetPrivateField<LevelFilteringNavigationController>("_levelFilteringNavigationController"); Logger.Debug("Acquired LevelFilteringNavigationController [{0}]", LevelFilteringNavigationController.GetInstanceID()); // grab nav controller elements LevelCollectionViewController = LevelSelectionNavigationController.GetPrivateField <LevelCollectionViewController>("_levelCollectionViewController"); Logger.Debug("Acquired LevelPackLevelsViewController [{0}]", LevelCollectionViewController.GetInstanceID()); LevelDetailViewController = LevelSelectionNavigationController.GetPrivateField <StandardLevelDetailViewController>("_levelDetailViewController"); Logger.Debug("Acquired StandardLevelDetailViewController [{0}]", LevelDetailViewController.GetInstanceID()); // grab level collection view controller elements LevelCollectionTableView = this.LevelCollectionViewController.GetPrivateField <LevelCollectionTableView>("_levelCollectionTableView"); Logger.Debug("Acquired LevelPackLevelsTableView [{0}]", LevelCollectionTableView.GetInstanceID()); // grab letel detail view StandardLevelDetailView = LevelDetailViewController.GetPrivateField <StandardLevelDetailView>("_standardLevelDetailView"); Logger.Debug("Acquired StandardLevelDetailView [{0}]", StandardLevelDetailView.GetInstanceID()); BeatmapCharacteristicSelectionViewController = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSegmentedControlController>().First(); Logger.Debug("Acquired BeatmapCharacteristicSegmentedControlController [{0}]", BeatmapCharacteristicSelectionViewController.GetInstanceID()); LevelDifficultyViewController = StandardLevelDetailView.GetPrivateField <BeatmapDifficultySegmentedControlController>("_beatmapDifficultySegmentedControlController"); Logger.Debug("Acquired BeatmapDifficultySegmentedControlController [{0}]", LevelDifficultyViewController.GetInstanceID()); LevelCollectionTableViewTransform = LevelCollectionTableView.transform as RectTransform; Logger.Debug("Acquired TableViewRectTransform from LevelPackLevelsTableView [{0}]", LevelCollectionTableViewTransform.GetInstanceID()); TableView tableView = LevelCollectionTableView.GetPrivateField <TableView>("_tableView"); TableViewPageUpButton = tableView.GetPrivateField <Button>("_pageUpButton"); TableViewPageDownButton = tableView.GetPrivateField <Button>("_pageDownButton"); Logger.Debug("Acquired Page Up and Down buttons..."); PlayContainer = StandardLevelDetailView.GetComponentsInChildren <RectTransform>().First(x => x.name == "PlayContainer"); PlayButtons = PlayContainer.GetComponentsInChildren <RectTransform>().First(x => x.name == "PlayButtons"); PlayButton = Resources.FindObjectsOfTypeAll <Button>().First(x => x.name == "PlayButton"); PracticeButton = PlayButtons.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton"); SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll <SimpleDialogPromptViewController>().First(); BeatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); }
public static void GetOriginalLevelHashes() { originalLevels.Clear(); BeatmapLevelsModel _levelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); foreach (var item in _levelsModel.ostAndExtrasPackCollection.beatmapLevelPacks.Concat(_levelsModel.dlcBeatmapLevelPackCollection.beatmapLevelPacks).SelectMany(x => x.beatmapLevelCollection.beatmapLevels)) { originalLevels.Add(item.levelID, BitConverter.ToString(HexConverter.GetStringHashBytes(item.levelID)).Replace("-", "")); } }
public static void Init() { if (_loaded) { return; } _loaded = true; Plugin.log.Debug("Loading level loader"); _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); _contentModelSO = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); }
protected override void DidActivate(bool firstActivation, ActivationType type) { base.DidActivate(firstActivation, type); if (firstActivation) { _songsTableView.tableView.didSelectCellWithIdxEvent += SongsTableView_DidSelectRow; _songsTableView.tableView.dataSource = this; _additionalContentModel = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().First(); _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); } _selectedSong = null; NotifyPropertyChanged(); }
public FoldersViewController(AnnotatedBeatmapLevelCollectionsViewController annotatedBeatmapLevelCollectionsViewController, MainFlowCoordinator mainFlowCoordinator, LevelSelectionNavigationController levelSelectionNavigationController, PopupModalsController popupModalsController, HoverHintController hoverHintController, BeatmapLevelsModel beatmapLevelsModel) { this.annotatedBeatmapLevelCollectionsViewController = annotatedBeatmapLevelCollectionsViewController; this.mainFlowCoordinator = mainFlowCoordinator; this.levelSelectionNavigationController = levelSelectionNavigationController; this.popupModalsController = popupModalsController; this.hoverHintController = hoverHintController; this.beatmapLevelsModel = beatmapLevelsModel; levelPacksIcon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("PlaylistManager.Icons.LevelPacks.png"); customPacksIcon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("PlaylistManager.Icons.CustomPacks.png"); playlistsIcon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("PlaylistManager.Icons.Playlists.png"); foldersIcon = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("PlaylistManager.Icons.Folders.png"); folderMode = FolderMode.None; }
public void Construct(PluginConfig config, Submission submission, AudioTimeSyncController audioTimeSyncController, BeatmapLevelsModel beatmapLevelsModel, GameplayCoreSceneSetupData gameplayCoreSceneSetupData, GameSongController gameSongController) { _config = config; _submission = submission; _audioTimeSyncController = audioTimeSyncController; _beatmapLevelsModel = beatmapLevelsModel; _gameplayCoreSceneSetupData = gameplayCoreSceneSetupData; _gameSongController = gameSongController; _random = new System.Random(); IBeatmapLevelPack beatmapLevelPack = _beatmapLevelsModel.GetLevelPackForLevelId(_gameplayCoreSceneSetupData.difficultyBeatmap.level.levelID); _previewBeatmapLevels = beatmapLevelPack.beatmapLevelCollection.beatmapLevels; }
public void Initialize() { if (_initialized) { return; } if (_beatmapLevelsModel == null) { _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); } _visiblePacks = _beatmapLevelsModel.allLoadedBeatmapLevelPackCollection.beatmapLevelPacks; SetPacks(_visiblePacks); if (_visiblePacks.Length > 0) { packSelected?.Invoke(_visiblePacks[0]); } _initialized = true; }
public void SetupViewController() { levelDetailsRect.gameObject.AddComponent <Mask>(); Image maskImage = levelDetailsRect.gameObject.AddComponent <Image>(); maskImage.material = Sprites.NoGlowMat; maskImage.sprite = Resources.FindObjectsOfTypeAll <Sprite>().First(x => x.name == "RoundRectPanel"); maskImage.type = Image.Type.Sliced; maskImage.color = new Color(0f, 0f, 0f, 0.25f); levelCoverImage.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); _defaultArtworkTexture = Resources.FindObjectsOfTypeAll <Texture2D>().First(x => x.name == "DefaultSongArtwork"); leaderboardTableView.GetComponent <TableView>().RemoveReusableCells("Cell"); if (selectedLevel != null) { SetContent(selectedLevel); } }
public void SetupFromPlaylist(Playlist playlist, IBeatmapLevelPackCollection coll, BeatmapLevelsModel model = null) { collectionName = playlist.Title; HashSet <string> vs = new HashSet <string>(); for (int i = 0; i < playlist.Maps.Count; i++) { var map = playlist.Maps[i]; if (map.Type == BeatmapType.LevelID && !vs.Contains(map.LevelID)) { vs.Add(map.LevelID); } else if (map.Type == BeatmapType.Hash && !vs.Contains("custom_level_" + IPA.Utilities.Utils.ByteArrayToString(map.Hash).ToUpper())) { vs.Add("custom_level_" + IPA.Utilities.Utils.ByteArrayToString(map.Hash).ToUpper()); } else if (map.Type == BeatmapType.Key && Loader.KeyToHashDB.TryGetValue(map.Key.ToString(), out string hash) && !vs.Contains("custom_level_" + hash.ToUpper())) { vs.Add("custom_level_" + hash.ToUpper()); } } BeatmapLevelFilterModel.LevelFilterParams levelFilterParams = BeatmapLevelFilterModel.LevelFilterParams.ByBeatmapLevelIds(vs); var filtered = BeatmapLevelFilterModel.FilerBeatmapLevelPackCollection(coll, levelFilterParams).beatmapLevels; BeatmapLevelCollection collection = new BeatmapLevelCollection(filtered.ToArray()); beatmapLevelCollection = collection; isDirty = false; }
public CustomSongPicker(BeatmapLevelsModel beatmapLevelsModel) { _beatmapLevelsModel = beatmapLevelsModel; _cancellationTokenSource = new CancellationTokenSource(); _containerCache = new Dictionary <IPreviewBeatmapLevel, AudioContainer>(); }
/// <summary> /// Adds a level pack selection to Quick Play's picker. Unfortunately, the server doesn't allow custom songs to be played in Quick Play. /// Left here for testing. /// </summary> static void Postfix(SongPackMasksModel __instance, ref BeatmapLevelsModel beatmapLevelsModel, ref List <Tuple <SongPackMask, string> > ____songPackMaskData) { SongPackMask customs = new SongPackMask("custom_levelpack_CustomLevels"); ____songPackMaskData.Add(customs, "Custom"); }
public AllPacksRefresher(AnnotatedBeatmapLevelCollectionsViewController annotatedBeatmapLevelCollectionsViewController, BeatmapLevelsModel beatmapLevelsModel) { this.annotatedBeatmapLevelCollectionsViewController = annotatedBeatmapLevelCollectionsViewController; this.beatmapLevelsModel = beatmapLevelsModel; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// Get a level from a level preview /// </summary> /// <param name="p_Level">Level instance</param> /// <param name="p_BeatmapLevelsModel">Model</param> /// <returns>Level instance</returns> private static async Task <BeatmapLevelsModel.GetBeatmapLevelResult?> GetLevelFromPreview(IPreviewBeatmapLevel p_Level, BeatmapLevelsModel p_BeatmapLevelsModel = null) { /* * Code from https://github.com/MatrikMoon/TournamentAssistant * * MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ p_BeatmapLevelsModel = p_BeatmapLevelsModel ?? Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); if (p_BeatmapLevelsModel != null) { m_GetLevelCancellationTokenSource?.Cancel(); m_GetLevelCancellationTokenSource = new CancellationTokenSource(); var l_Token = m_GetLevelCancellationTokenSource.Token; BeatmapLevelsModel.GetBeatmapLevelResult?l_Result = null; try { l_Result = await p_BeatmapLevelsModel.GetBeatmapLevelAsync(p_Level.levelID, l_Token); } catch (OperationCanceledException) { } if (l_Result?.isError == true || l_Result?.beatmapLevel == null) { return(null); /// Null out entirely in case of error } return(l_Result); } return(null); }
static bool Prefix(ref object ____playlistTabBarData, ref IAnnotatedBeatmapLevelCollection[] ____playlists, BeatmapLevelsModel ____beatmapLevelsModel) { if (PlaylistCore.instance.CanSetPlaylistsUp && ____playlistTabBarData != null) { List <IAnnotatedBeatmapLevelCollection> collections = new List <IAnnotatedBeatmapLevelCollection>(); foreach (var pl in PlaylistCore.instance.LoadedPlaylistSO) { if (pl.isDirty) { pl.SetupFromPlaylist(pl.playlist, ____beatmapLevelsModel.allLoadedBeatmapLevelPackCollection); } } collections.AddRange(____playlists); collections.AddRange(PlaylistCore.instance.LoadedPlaylistSO); ____playlistTabBarData.SetPrivateField("annotatedBeatmapLevelCollections", collections.ToArray()); } return(true); }
public static async void PreloadBeatmapLevelAsync( BeatmapCharacteristicSO characteristic, IPreviewBeatmapLevel selectedLevel, BeatmapDifficulty difficulty, GameplayModifiers modifiers, Action <PreloadedLevel> callback) { _beatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); _contentModelSO = Resources.FindObjectsOfTypeAll <AdditionalContentModel>().FirstOrDefault(); _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); var token = new CancellationTokenSource(); var previewCache = _beatmapLevelsModel .GetPrivateField <Dictionary <string, IPreviewBeatmapLevel> >("_loadedPreviewBeatmapLevels"); if (!previewCache.ContainsKey(selectedLevel.levelID)) { previewCache.Add(selectedLevel.levelID, selectedLevel); _beatmapLevelsModel.SetPrivateField("_loadedPreviewBeatmapLevels", previewCache); } var entitlementStatus = await _contentModelSO.GetLevelEntitlementStatusAsync(selectedLevel.levelID, token.Token); if (entitlementStatus == AdditionalContentModel.EntitlementStatus.Owned) { var getBeatmapLevelResult = await _beatmapLevelsModel.GetBeatmapLevelAsync(selectedLevel.levelID, token.Token); if (getBeatmapLevelResult.isError) { callback?.Invoke(null); return; } var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().FirstOrDefault().playerData; var playerSettings = playerData.playerSpecificSettings; var environmentOverrideSettings = playerData.overrideEnvironmentSettings; var colorSchemesSettings = playerData.colorSchemesSettings.overrideDefaultColors ? playerData.colorSchemesSettings.GetColorSchemeForId(playerData.colorSchemesSettings .selectedColorSchemeId) : null; var difficultyBeatmap = getBeatmapLevelResult.beatmapLevel.GetDifficultyBeatmap(characteristic, difficulty, false); callback?.Invoke(new PreloadedLevel() { characteristic = characteristic, levelResult = getBeatmapLevelResult, modifiers = modifiers, difficulty = difficultyBeatmap, playerData = playerData, playerSpecificSettings = playerSettings, environmentSettings = environmentOverrideSettings, colorScheme = colorSchemesSettings }); } else { callback?.Invoke(null); } }
public static async void TryDownloadSong(string levelId, TaskCompletionSource <BeatmapLevelsModel.GetBeatmapLevelResult> tcs, CancellationToken cancellationToken, BeatmapLevelsModel beatmapLevelsModel) { try { IPreviewBeatmapLevel beatmap = await Downloader.DownloadSong(levelId, cancellationToken); if (beatmap is CustomPreviewBeatmapLevel customLevel) { Plugin.Log?.Debug($"Download was successful."); IBeatmapLevel beatmapLevel = await CustomLevelLoader(ref beatmapLevelsModel).LoadCustomBeatmapLevelAsync(customLevel, cancellationToken); UIHelper.RefreshUI(); tcs.TrySetResult(new BeatmapLevelsModel.GetBeatmapLevelResult(false, beatmapLevel)); } else { Plugin.Log?.Error($"beatmap:{beatmap?.GetType().Name} is not an CustomPreviewBeatmapLevel"); } } catch (OperationCanceledException) { Plugin.Log?.Debug($"Download was canceled."); tcs.TrySetCanceled(cancellationToken); return; } catch (Exception ex) { Plugin.Log?.Error($"Error downloading beatmap '{levelId}': {ex.Message}"); Plugin.Log?.Debug(ex); } tcs.TrySetResult(new BeatmapLevelsModel.GetBeatmapLevelResult(true, null)); Plugin.Log?.Debug($"Download was unsuccessful."); }
public static async Task <BeatmapLevelsModel.GetBeatmapLevelResult?> GetLevelFromPreview(IPreviewBeatmapLevel level, BeatmapLevelsModel beatmapLevelsModel = null) { beatmapLevelsModel = beatmapLevelsModel ?? Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().FirstOrDefault(); if (beatmapLevelsModel != null) { getLevelCancellationTokenSource?.Cancel(); getLevelCancellationTokenSource = new CancellationTokenSource(); var token = getLevelCancellationTokenSource.Token; BeatmapLevelsModel.GetBeatmapLevelResult?result = null; try { result = await beatmapLevelsModel.GetBeatmapLevelAsync(level.levelID, token); } catch (OperationCanceledException) { } if (result?.isError == true || result?.beatmapLevel == null) { return(null); //Null out entirely in case of error } return(result); } return(null); }
static bool Prefix(ref string levelID, ref CancellationToken cancellationToken, ref Task <BeatmapLevelsModel.GetBeatmapLevelResult> __result, BeatmapLevelsModel __instance) { return(true); if (!levelID.StartsWith("custom_level_") || SongCore.Loader.GetLevelById(levelID) != null) { return(true); } Plugin.Log?.Info($"Attempting to download custom level..."); TaskCompletionSource <BeatmapLevelsModel.GetBeatmapLevelResult> tcs = new TaskCompletionSource <BeatmapLevelsModel.GetBeatmapLevelResult>(); __result = tcs.Task; tcs.Task.ContinueWith(r => { if (r.Result.beatmapLevel != null) { PreviewBeatmapLevel(ref MultiplayerLevelLoader_LoadLevel.MultiplayerLevelLoader) = r.Result.beatmapLevel; Plugin.Log?.Info($"PreviewBeatmap set to {r.Result.beatmapLevel.songName}"); } else { Plugin.Log?.Debug($"PreviewBeatmapLevel is null."); } }); TryDownloadSong(levelID, tcs, cancellationToken, __instance); return(false); }