Esempio n. 1
0
        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
        {
            if (AreSongsLoading)
            {
                //Scene changing while songs are loading. Since we are using a separate thread while loading, this is bad and could cause a crash.
                //So we have to stop loading.
                if (_loadingTask != null)
                {
                    _loadingTask.Cancel();
                    _loadingCancelled = true;
                    AreSongsLoading   = false;
                    LoadingProgress   = 0;
                    StopAllCoroutines();
                    _progressBar.ShowMessage("Loading cancelled\n<size=80%>Press Ctrl+R to refresh</size>");
                    Log("Loading was cancelled by player since they loaded another scene.");
                }
            }

            StartCoroutine(WaitRemoveScores());

            if (scene.buildIndex == 1)
            {
                _mainFlowCoordinator = Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().FirstOrDefault();
                _mainFlowCoordinator.SetPrivateField("_levelCollectionsForGameplayModes", _customLevelCollectionsForGameplayModes);

                _standardLevelDetailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().FirstOrDefault();
                if (_standardLevelDetailViewController == null)
                {
                    return;
                }
                _standardLevelDetailViewController.didPressPlayButtonEvent += StandardLevelDetailControllerOnDidPressPlayButtonEvent;

                var standardLevelListViewController = Resources.FindObjectsOfTypeAll <StandardLevelListViewController>().FirstOrDefault();
                if (standardLevelListViewController == null)
                {
                    return;
                }

                standardLevelListViewController.didSelectLevelEvent += StandardLevelListViewControllerOnDidSelectLevelEvent;
            }
            else if (scene.buildIndex == 5)
            {
                if (NoteHitVolumeChanger.PrefabFound)
                {
                    return;
                }
                var mainGameData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                if (mainGameData == null)
                {
                    return;
                }
                var level = mainGameData.difficultyLevel.level;
                var song  = CustomLevels.FirstOrDefault(x => x.levelID == level.levelID);
                if (song == null)
                {
                    return;
                }
                NoteHitVolumeChanger.SetVolume(song.customSongInfo.noteHitVolume, song.customSongInfo.noteMissVolume);
            }
        }
Esempio n. 2
0
        public void OnApplicationQuit()
        {
            if (overlayEnabled && overlay != null)
            {
                overlay.ShutDown();
                OverlayTask.Cancel();
            }

            SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
            SceneManager.sceneLoaded        -= SceneManager_sceneLoaded;
        }
Esempio n. 3
0
 private void OnSceneChanged(Scene arg0, Scene arg1)
 {
     if (env.Contains(arg1.name))
     {
         StartData();
     }
     else if (arg1.name == "Menu")
     {
         File.WriteAllText(dir, "");
         getData.Cancel();
         setupData = null;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Only used to stop the caching thread during OnApplicationQuit().
        /// </summary>
        public void CancelPopulatingCache()
        {
            if (!IsCaching || _cachingTokenSource == null || _cachingTask == null)
            {
                return;
            }

            _cachingTokenSource.Cancel();
            _cachingTask.Cancel();

            _cachingTokenSource = null;
            _cachingTask        = null;
            IsCaching           = false;
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the beatmap details of a list of IPreviewBeatmapLevels.
        /// </summary>
        /// <param name="levels">A list of IPreviewBeatmaps.</param>
        /// <param name="update">A function that will run every 0.1s that gets the number of beatmaps currently loaded.</param>
        /// <param name="onFinish">The function that is called when the details of all beatmaps are retrieved.</param>
        public void LoadBeatmaps(IPreviewBeatmapLevel[] levels, Action <int> update = null, Action <BeatmapDetails[]> onFinish = null)
        {
            if (IsLoading)
            {
                _loadingTask?.Cancel();
            }

            IsLoading = true;

            if (IsCaching)
            {
                PausePopulatingCache();
            }

            _levels = levels;

            _update = update;
            StartCoroutine(UpdateCoroutine());

            if (_loadingTokenSource != null)
            {
                _loadingTokenSource.Dispose();
            }
            _loadingTokenSource = new CancellationTokenSource();

            _loadingTask = new HMTask(
                delegate()
            {
                Logger.log.Debug("Starting to load beatmap details");

                GetBeatmapLevelsAsync().GetAwaiter().GetResult();
            },
                delegate()
            {
                _loadingTask = null;
                _loadingTokenSource.Dispose();
                _loadingTokenSource = null;
                IsLoading           = false;

                if (IsCaching || !SongsAreCached)
                {
                    StartPopulatingCache();
                }

                onFinish?.Invoke(_loadedLevels.ToArray());
            });

            _loadingTask.Run();
        }
Esempio n. 6
0
        public void CancelLoading()
        {
            if (!IsLoading || _loadingTokenSource == null || _loadingTask == null)
            {
                return;
            }

            IsLoading = false;

            _loadingTokenSource.Cancel();
            _loadingTask.Cancel();
            _loadingTokenSource = null;
            _loadingTask        = null;

            if (IsCaching || !SongsAreCached)
            {
                StartPopulatingCache();
            }
        }
Esempio n. 7
0
        internal void MenuLoaded()
        {
            if (AreSongsLoading)
            {
                //Scene changing while songs are loading. Since we are using a separate thread while loading, this is bad and could cause a crash.
                //So we have to stop loading.
                if (_loadingTask != null)
                {
                    _loadingTask.Cancel();
                    _loadingCancelled = true;
                    AreSongsLoading   = false;
                    LoadingProgress   = 0;
                    StopAllCoroutines();
                    _progressBar.ShowMessage("Loading cancelled\n<size=80%>Press Ctrl+R to refresh</size>");
                    Logging.Log("Loading was cancelled by player since they loaded another scene.");
                }
            }
            BS_Utils.Gameplay.Gamemode.Init();
            if (_customLevelLoader == null)
            {
                _customLevelLoader = Resources.FindObjectsOfTypeAll <CustomLevelLoader>().FirstOrDefault();
                if (_customLevelLoader)
                {
                    Texture2D defaultCoverTex = _customLevelLoader.GetField <Texture2D>("_defaultPackCoverTexture2D");
                    defaultCoverImage = Sprite.Create(defaultCoverTex, new Rect(0f, 0f,
                                                                                defaultCoverTex.width, defaultCoverTex.height), new Vector2(0.5f, 0.5f));

                    cachedMediaAsyncLoaderSO        = _customLevelLoader.GetField <CachedMediaAsyncLoader>("_cachedMediaAsyncLoaderSO");
                    beatmapCharacteristicCollection = _customLevelLoader.GetField <BeatmapCharacteristicCollectionSO>("_beatmapCharacteristicCollection");
                }
                else
                {
                    Texture2D defaultCoverTex = Texture2D.blackTexture;
                    defaultCoverImage = Sprite.Create(defaultCoverTex, new Rect(0f, 0f,
                                                                                defaultCoverTex.width, defaultCoverTex.height), new Vector2(0.5f, 0.5f));
                }
            }
        }
Esempio n. 8
0
        internal void OnSceneChanged(Scene oldScene, Scene newScene)
        {
            if (AreSongsLoading)
            {
                //Scene changing while songs are loading. Since we are using a separate thread while loading, this is bad and could cause a crash.
                //So we have to stop loading.
                if (_loadingTask != null)
                {
                    _loadingTask.Cancel();
                    _loadingCancelled = true;
                    AreSongsLoading   = false;
                    LoadingProgress   = 0;
                    StopAllCoroutines();
                    _progressBar.ShowMessage("Loading cancelled\n<size=80%>Press Ctrl+R to refresh</size>");
                    Logging.Log("Loading was cancelled by player since they loaded another scene.");
                }
            }
            if (newScene.name == "MenuCore")
            {
                BS_Utils.Gameplay.Gamemode.Init();
                if (_customLevelLoader == null)
                {
                    _customLevelLoader = Resources.FindObjectsOfTypeAll <CustomLevelLoaderSO>().FirstOrDefault();
                    if (_customLevelLoader)
                    {
                        Texture2D defaultCoverTex = _customLevelLoader.GetField <Texture2D>("_defaultPackCoverTexture2D");
                        defaultCoverImage = Sprite.Create(defaultCoverTex, new Rect(0f, 0f,
                                                                                    (float)defaultCoverTex.width, (float)defaultCoverTex.height), new Vector2(0.5f, 0.5f));

                        cachedMediaAsyncLoaderSO        = _customLevelLoader.GetField <CachedMediaAsyncLoaderSO>("_cachedMediaAsyncLoaderSO");
                        beatmapCharacteristicCollection = _customLevelLoader.GetField <BeatmapCharacteristicCollectionSO>("_beatmapCharacteristicCollection");
                    }
                    else
                    {
                        Texture2D defaultCoverTex = Texture2D.blackTexture;
                        defaultCoverImage = Sprite.Create(defaultCoverTex, new Rect(0f, 0f,
                                                                                    (float)defaultCoverTex.width, (float)defaultCoverTex.height), new Vector2(0.5f, 0.5f));
                    }
                }

                if (BeatmapLevelsModelSO == null)
                {
                    BeatmapLevelsModelSO = Resources.FindObjectsOfTypeAll <BeatmapLevelsModelSO>().FirstOrDefault();
                }

                //Handle LevelPacks
                if (CustomBeatmapLevelPackCollectionSO == null)
                {
                    var beatmapLevelPackCollectionSO = Resources.FindObjectsOfTypeAll <BeatmapLevelPackCollectionSO>().FirstOrDefault();
                    CustomBeatmapLevelPackCollectionSO = SongCoreBeatmapLevelPackCollectionSO.ReplaceOriginal(beatmapLevelPackCollectionSO);
                    CustomLevelsCollection             = new SongCoreCustomLevelCollection(CustomLevels.Values.ToArray());
                    WIPLevelsCollection = new SongCoreCustomLevelCollection(CustomWIPLevels.Values.ToArray());
                    CustomLevelsPack    = new SongCoreCustomBeatmapLevelPack(CustomLevelLoaderSO.kCustomLevelPackPrefixId + "CustomLevels", "Custom Maps", defaultCoverImage, CustomLevelsCollection);
                    WIPLevelsPack       = new SongCoreCustomBeatmapLevelPack(CustomLevelLoaderSO.kCustomLevelPackPrefixId + "CustomWIPLevels", "WIP Maps", UI.BasicUI.WIPIcon, WIPLevelsCollection);
                    CustomBeatmapLevelPackCollectionSO.AddLevelPack(CustomLevelsPack);
                    CustomBeatmapLevelPackCollectionSO.AddLevelPack(WIPLevelsPack);

                    //    CustomBeatmapLevelPackSO = CustomBeatmapLevelPackSO.GetPack(CustomLevelCollectionSO);
                    //    CustomBeatmapLevelPackCollectionSO.AddLevelPack(CustomBeatmapLevelPackSO);
                    //    WIPCustomBeatmapLevelPackSO = CustomBeatmapLevelPackSO.GetPack(WIPCustomLevelCollectionSO, true);
                    //    CustomBeatmapLevelPackCollectionSO.AddLevelPack(WIPCustomBeatmapLevelPackSO);
                    CustomBeatmapLevelPackCollectionSO.ReplaceReferences();
                }
                else
                {
                    CustomBeatmapLevelPackCollectionSO.ReplaceReferences();
                }
                //RefreshLevelPacks();
                var soloFreePlay = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().FirstOrDefault();
                LevelPacksViewController levelPacksViewController = soloFreePlay?.GetField <LevelPacksViewController>("_levelPacksViewController");
                levelPacksViewController?.SetData(CustomBeatmapLevelPackCollectionSO, 0);
            }
        }
Esempio n. 9
0
        private void OnSceneTransitioned(Scene activeScene)
        {
            GameObject.Destroy(GameObject.Find("SongLoader Color Setter"));
            customSongColors    = IllusionPlugin.ModPrefs.GetBool("Songloader", "customSongColors", true, true);
            customSongPlatforms = IllusionPlugin.ModPrefs.GetBool("Songloader", "customSongPlatforms", true, true);
            if (AreSongsLoading)
            {
                //Scene changing while songs are loading. Since we are using a separate thread while loading, this is bad and could cause a crash.
                //So we have to stop loading.
                if (_loadingTask != null)
                {
                    _loadingTask.Cancel();
                    _loadingCancelled = true;
                    AreSongsLoading   = false;
                    LoadingProgress   = 0;
                    StopAllCoroutines();
                    _progressBar.ShowMessage("Loading cancelled\n<size=80%>Press Ctrl+R to refresh</size>");
                    Log("Loading was cancelled by player since they loaded another scene.");
                }
            }

            StartCoroutine(WaitRemoveScores());

            if (activeScene.name == MenuSceneName)
            {
                CurrentLevelPlaying = null;

                if (CustomLevelCollectionSO == null)
                {
                    var levelCollectionSO = Resources.FindObjectsOfTypeAll <LevelCollectionSO>().FirstOrDefault();
                    CustomLevelCollectionSO = CustomLevelCollectionSO.ReplaceOriginal(levelCollectionSO);
                }
                else
                {
                    CustomLevelCollectionSO.ReplaceReferences();
                }
                if (_standardLevelDetailViewController == null)
                {
                    _standardLevelDetailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().FirstOrDefault();
                    if (_standardLevelDetailViewController == null)
                    {
                        return;
                    }
                    _standardLevelDetailViewController.didPressPlayButtonEvent += StandardLevelDetailControllerOnDidPressPlayButtonEvent;
                }

                if (_LevelListViewController == null)
                {
                    _LevelListViewController = Resources.FindObjectsOfTypeAll <LevelListViewController>().FirstOrDefault();
                    if (_LevelListViewController == null)
                    {
                        return;
                    }

                    _LevelListViewController.didSelectLevelEvent += StandardLevelListViewControllerOnDidSelectLevelEvent;
                }



                if (_characteristicViewController == null)
                {
                    _characteristicViewController = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSelectionViewController>().FirstOrDefault();
                    if (_characteristicViewController == null)
                    {
                        return;
                    }

                    _characteristicViewController.didSelectBeatmapCharacteristicEvent += OnDidSelectBeatmapCharacteristicEvent;
                }

                if (CustomPlatformsPresent)
                {
                    CheckForPreviousPlatform();
                }
            }
            else if (activeScene.name == GameSceneName)
            {
                _standardLevelSceneSetupData = Resources.FindObjectsOfTypeAll <StandardLevelSceneSetupDataSO>().FirstOrDefault();
                if (_standardLevelSceneSetupData == null)
                {
                    return;
                }
                var level   = _standardLevelSceneSetupData.difficultyBeatmap;
                var beatmap = level as CustomLevel.CustomDifficultyBeatmap;
                if (beatmap != null)
                {
                    CurrentLevelPlaying = beatmap;

                    //The note jump movement speed now gets set in the Start method, so we're too early here. We have to wait a bit before overriding.
                    Invoke(nameof(DelayedNoteJumpMovementSpeedFix), 0.1f);
                }

                if (NoteHitVolumeChanger.PrefabFound)
                {
                    return;
                }
                var song = CustomLevels.FirstOrDefault(x => x.levelID == level.level.levelID);
                if (song == null)
                {
                    return;
                }
                NoteHitVolumeChanger.SetVolume(song.customSongInfo.noteHitVolume, song.customSongInfo.noteMissVolume);

                //Set environment if the song has customEnvironment
                if (CustomPlatformsPresent)
                {
                    CheckCustomSongEnvironment(song);
                }
                //Set enviroment colors for the song if it has song specific colors
                if (customSongColors)
                {
                    song.SetSongColors(CurrentLevelPlaying.colorLeft, CurrentLevelPlaying.colorRight, CurrentLevelPlaying.hasCustomColors);
                }
            }
        }
Esempio n. 10
0
        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
        {
            if (overlayEnabled)
            {
                if (arg1.name == "Menu" && InSong)
                {
                    Console.WriteLine("[StreamInfo] Exited song scene.");

                    InSong = false;
                    StartTask.Cancel();
                    ats = null;

                    Console.WriteLine("[StreamInfo] Ready for next song.");
                }
                else if (env.Contains(arg1.name))
                {
                    StartJob = delegate
                    {
                        Console.WriteLine("[StreamInfo] Entered song scene. Initializing...");
                        InSong         = true;
                        EnergyReached0 = false;
                        int runID = 1 + songCount++;

                        Console.WriteLine("[StreamInfo] Finding controllers and data...");

                        GameEnergyCounter      energy    = null;
                        ScoreController        score     = null;
                        MainGameSceneSetupData setupData = null;

                        while (ats == null || energy == null || score == null || setupData == null)
                        {
                            Thread.Sleep(150);
                            ats       = UnityEngine.Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault();
                            energy    = UnityEngine.Resources.FindObjectsOfTypeAll <GameEnergyCounter>().FirstOrDefault();
                            score     = UnityEngine.Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();
                            setupData = UnityEngine.Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                        }
                        Console.WriteLine("[StreamInfo] Found controllers and data.");

                        bool noFail = false;

                        if (setupData != null)
                        {
                            Console.WriteLine("[StreamInfo] Getting song name data...");
                            var level = setupData.difficultyLevel.level;

                            _songName   = level.songName;
                            _songSub    = level.songSubName;
                            _songAuthor = level.songAuthorName;

                            string songname = "\"" + _songName + "\" by " + _songSub + " - " + _songAuthor;
                            File.WriteAllText(Path.Combine(dir, "SongName.txt"), songname + "               ");

                            noFail = setupData.gameplayOptions.noEnergy;
                        }
                        Console.WriteLine("[StreamInfo] Hooking Events...");
                        if (score != null)
                        {
                            score.comboDidChangeEvent      += OnComboChange;
                            score.multiplierDidChangeEvent += OnMultiplierChange;
                            score.noteWasMissedEvent       += OnNoteMiss;
                            score.noteWasCutEvent          += OnNoteCut;
                            score.scoreDidChangeEvent      += OnScoreChange;
                        }
                        if (energy != null)
                        {
                            energy.gameEnergyDidChangeEvent += OnEnergyChange;
                            if (!BailOutInstalled)
                            {
                                energy.gameEnergyDidReach0Event += OnEnergyFail;
                            }
                        }
                        info.SetDefault();
                        if (noFail)
                        {
                            EnergyReached0 = true;
                            info.energy    = -3;
                        }
                        Console.WriteLine("[StreamInfo] Starting update loop...");
                        while (InSong && overlayEnabled && runID == songCount)
                        {
                            if (ats != null)
                            {
                                string time      = Math.Floor(ats.songTime / 60).ToString("N0") + ":" + Math.Floor(ats.songTime % 60).ToString("00");
                                string totaltime = Math.Floor(ats.songLength / 60).ToString("N0") + ":" + Math.Floor(ats.songLength % 60).ToString("00");
                                string percent   = ((ats.songTime / ats.songLength) * 100).ToString("N0");

                                overlay.UpdateText(info.GetVal("multiplier"),
                                                   info.GetVal("score"),
                                                   ScoreController.MaxScoreForNumberOfNotes(info.notes_total),
                                                   time + " / " + totaltime + " (" + percent + "%)",
                                                   info.GetVal("combo"),
                                                   info.GetVal("notes_hit") + "/" + info.GetVal("notes_total"),
                                                   info.GetVal("energy"));
                            }
                            Thread.Sleep(overlayRefreshRate);
                        }
                        Console.WriteLine("[SongInfo] Thread completed: " + runID);
                    };
                    StartTask = new HMTask(StartJob);
                    StartTask.Run();
                }
            }
        }