Exemple #1
0
        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
        {
            if (scene.buildIndex == 1)
            {
                if (SettingsObject == null)
                {
                    var volumeSettings = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();
                    volumeSettings.gameObject.SetActive(false);
                    SettingsObject = Object.Instantiate(volumeSettings.gameObject);
                    SettingsObject.SetActive(false);
                    volumeSettings.gameObject.SetActive(true);
                    var volume = SettingsObject.GetComponent <VolumeSettingsController>();
                    ReflectionUtil.CopyComponent(volume, typeof(SimpleSettingsController), typeof(SpeedSettingsController), SettingsObject);
                    Object.DestroyImmediate(volume);
                    SettingsObject.GetComponentInChildren <TMP_Text>().text = "SPEED";
                    Object.DontDestroyOnLoad(SettingsObject);
                }
            }
            else
            {
                if (_mainGameSceneSetupData == null)
                {
                    _mainGameSceneSetupData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                }

                if (_mainGameSceneSetupData == null || scene.buildIndex != 4)
                {
                    return;
                }

                if (_lastLevelId != _mainGameSceneSetupData.levelId && !string.IsNullOrEmpty(_lastLevelId))
                {
                    TimeScale    = 1;
                    _lastLevelId = _mainGameSceneSetupData.levelId;
                }

                _lastLevelId = _mainGameSceneSetupData.levelId;

                _audioTimeSync = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault();
                _audioTimeSync.forcedAudioSync = true;
                _songAudio = ReflectionUtil.GetPrivateField <AudioSource>(_audioTimeSync, "_audioSource");
                Enabled    = _mainGameSceneSetupData.gameplayOptions.noEnergy;
                var noteCutSoundEffectManager = Resources.FindObjectsOfTypeAll <NoteCutSoundEffectManager>().FirstOrDefault();
                var noteCutSoundEffect        =
                    ReflectionUtil.GetPrivateField <NoteCutSoundEffect>(noteCutSoundEffectManager, "_noteCutSoundEffectPrefab");
                _noteCutAudioSource =
                    ReflectionUtil.GetPrivateField <AudioSource>(noteCutSoundEffect, "_audioSource");

                var canvas = Resources.FindObjectsOfTypeAll <HorizontalLayoutGroup>().FirstOrDefault(x => x.name == "Buttons")
                             .transform.parent;
                canvas.gameObject.AddComponent <SpeedSettingsCreator>();
                TimeScale = TimeScale;

                gameSongController        = Resources.FindObjectsOfTypeAll <GameSongController>().FirstOrDefault();
                songObjectSpawnController = Resources.FindObjectsOfTypeAll <SongObjectSpawnController>().FirstOrDefault();
                scoreController           = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault <ScoreController>();

                scoresDict = new Dictionary <int, ScoreListItem>();
            }
        }
        public static CustomNoteCutSoundEffect CopyOriginal(NoteCutSoundEffect original)
        {
            var gameObj = Instantiate(original.gameObject);

            gameObj.name = "This is a copy!";
            //gameObj.SetActive(false);
            original = gameObj.GetComponent <NoteCutSoundEffect>();
            var noteCutSoundEffect = (CustomNoteCutSoundEffect)ReflectionUtil.CopyComponent(original, typeof(NoteCutSoundEffect),
                                                                                            typeof(CustomNoteCutSoundEffect), gameObj);

            DestroyImmediate(original);
            noteCutSoundEffect.Awake();
            return(noteCutSoundEffect);
        }
Exemple #3
0
        private void OneSceneChanged(Scene oldScene, Scene newScene)
        {
            Object.Destroy(Resources.FindObjectsOfTypeAll <UIElementsCreator>().FirstOrDefault()?.gameObject);
            if (newScene.name == MenuSceneName)
            {
                if (_resetNoFail)
                {
                    var resultsViewController =
                        Resources.FindObjectsOfTypeAll <ResultsViewController>().FirstOrDefault();
                    if (resultsViewController != null)
                    {
                        resultsViewController.continueButtonPressedEvent +=
                            ResultsViewControllerOnContinueButtonPressedEvent;
                    }
                }

                if (SpeedSettingsObject != null)
                {
                    return;
                }

                var volumeSettings = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();

                if (volumeSettings == null)
                {
                    return;
                }

                volumeSettings.gameObject.SetActive(false);
                SpeedSettingsObject = Object.Instantiate(volumeSettings.gameObject);
                SpeedSettingsObject.SetActive(false);
                volumeSettings.gameObject.SetActive(true);

                if (SpeedSettingsObject == null)
                {
                    return;
                }

                var volume = SpeedSettingsObject.GetComponent <VolumeSettingsController>();
                ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController),
                                             typeof(SpeedSettingsController), SpeedSettingsObject);
                Object.DestroyImmediate(volume);

                SpeedSettingsObject.GetComponentInChildren <TMP_Text>().text = "SPEED";
                Object.DontDestroyOnLoad(SpeedSettingsObject);


                //NJS Object
                if (NjsSettingsObject != null)
                {
                    return;
                }

                var volumeSettings2 = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();

                if (volumeSettings2 == null)
                {
                    return;
                }

                volumeSettings2.gameObject.SetActive(false);
                NjsSettingsObject = Object.Instantiate(volumeSettings2.gameObject);
                NjsSettingsObject.SetActive(false);
                volumeSettings2.gameObject.SetActive(true);

                if (NjsSettingsObject == null)
                {
                    return;
                }

                var volume2 = NjsSettingsObject.GetComponent <VolumeSettingsController>();
                ReflectionUtil.CopyComponent(volume2, typeof(IncDecSettingsController),
                                             typeof(NjsSettingsController), NjsSettingsObject);
                Object.DestroyImmediate(volume2);

                NjsSettingsObject.GetComponentInChildren <TMP_Text>().text = "NJS";
                Object.DontDestroyOnLoad(NjsSettingsObject);


                //Spawn Offset Object
                if (SpawnOffsetSettingsObject != null)
                {
                    return;
                }

                var volumeSettings3 = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();

                if (volumeSettings3 == null)
                {
                    return;
                }

                volumeSettings3.gameObject.SetActive(false);
                SpawnOffsetSettingsObject = Object.Instantiate(volumeSettings3.gameObject);
                SpawnOffsetSettingsObject.SetActive(false);
                volumeSettings3.gameObject.SetActive(true);

                if (SpawnOffsetSettingsObject == null)
                {
                    return;
                }

                var volume3 = SpawnOffsetSettingsObject.GetComponent <VolumeSettingsController>();
                ReflectionUtil.CopyComponent(volume3, typeof(IncDecSettingsController),
                                             typeof(SpawnOffsetController), SpawnOffsetSettingsObject);
                Object.DestroyImmediate(volume3);

                SpawnOffsetSettingsObject.GetComponentInChildren <TMP_Text>().text = "Spawn Offset";
                Object.DontDestroyOnLoad(SpawnOffsetSettingsObject);
            }
            else if (newScene.name == GameSceneName)
            {
                CustomEffectPoolsInstaller customEffectPoolsInstaller = null;
                var effectPoolsInstaller = Resources.FindObjectsOfTypeAll <EffectPoolsInstaller>().FirstOrDefault();
                if (effectPoolsInstaller != null)
                {
                    customEffectPoolsInstaller = (CustomEffectPoolsInstaller)ReflectionUtil.CopyComponent(effectPoolsInstaller,
                                                                                                          typeof(EffectPoolsInstaller), typeof(CustomEffectPoolsInstaller), effectPoolsInstaller.gameObject);
                }

                SceneContext          sceneContext          = null;
                SceneDecoratorContext sceneDecoratorContext = null;
                try
                {
                    Console.WriteLine("Custom effect Pool Installer Made");
                    foreach (var gameObject in newScene.GetRootGameObjects())
                    {
                        if (sceneContext == null)
                        {
                            sceneContext = gameObject.GetComponentInChildren <SceneContext>(true);
                        }
                    }

                    foreach (var gameObject in SceneManager.GetSceneByName(ContextSceneName).GetRootGameObjects())
                    {
                        if (sceneDecoratorContext == null)
                        {
                            sceneDecoratorContext = gameObject.GetComponentInChildren <SceneDecoratorContext>(true);
                        }
                    }


                    if (sceneContext != null && sceneDecoratorContext != null)
                    {
                        var prop           = typeof(Context).GetField("_installers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                        var installersList = (List <MonoInstaller>)prop.GetValue(sceneDecoratorContext);
                        installersList.Remove(effectPoolsInstaller);
                        Object.DestroyImmediate(effectPoolsInstaller);
                        installersList.Add(customEffectPoolsInstaller);
                        Console.WriteLine("Custom effect Pool Installer Added");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }


                if (_levelData == null)
                {
                    _levelData = Resources.FindObjectsOfTypeAll <StandardLevelSceneSetupDataSO>().FirstOrDefault();
                    if (_levelData == null)
                    {
                        return;
                    }
                    _levelData.didFinishEvent += MainGameSceneSetupDataOnDidFinishEvent;
                }

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


                if (_lastLevelId != _levelData.difficultyBeatmap.level.levelID &&
                    !string.IsNullOrEmpty(_lastLevelId))
                {
                    PlayingNewSong      = true;
                    HasTimeScaleChanged = false;
                    TimeScale           = 1;
                    _lastLevelId        = _levelData.difficultyBeatmap.level.levelID;
                }
                else
                {
                    PlayingNewSong = false;
                }

                if (IsEqualToOne(TimeScale))
                {
                    HasTimeScaleChanged = false;
                }

                _lastLevelId        = _levelData.difficultyBeatmap.level.levelID;
                _gameCoreSceneSetup = Resources.FindObjectsOfTypeAll <GameplayCoreSceneSetup>().FirstOrDefault();
                AudioTimeSync       = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault();
                _songAudio          = AudioTimeSync.GetPrivateField <AudioSource>("_audioSource");
                _mixer       = _gameCoreSceneSetup.GetPrivateField <AudioMixerSO>("_audioMixer");
                PracticeMode = (_levelData.gameplayCoreSetupData.practiceSettings != null && !BS_Utils.Gameplay.Gamemode.IsIsolatedLevel);
                //Check if Multiplayer is active, disable accordingly
                if (PluginManager.Plugins.Any(x => x.Name == "Beat Saber Multiplayer"))
                {
                    GameObject client = GameObject.Find("MultiplayerClient");
                    if (client != null)
                    {
                        Console.WriteLine("[PracticePlugin] Found MultiplayerClient game object!");
                        multiActive = true;
                    }
                    else
                    {
                        Console.WriteLine("[PracticePlugin] MultiplayerClient game object not found!");
                    }
                }
                if (multiActive == true)
                {
                    PracticeMode = false;
                }


                if (!PracticeMode)
                {
                    TimeScale = Mathf.Clamp(TimeScale, 1, SpeedMaxSize);
                }
                if (PracticeMode)
                {
                    if (_levelData.gameplayCoreSetupData.practiceSettings.songSpeedMul != 1f)
                    {
                        _timeScale = _levelData.gameplayCoreSetupData.practiceSettings.songSpeedMul;
                    }
                    else
                    {
                        _timeScale = _levelData.gameplayCoreSetupData.gameplayModifiers.songSpeedMul;
                    }
                    SharedCoroutineStarter.instance.StartCoroutine(DelayedUI());
                }
            }
        }
        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
        {
            if (scene.buildIndex == 1)
            {
                if (_resetNoFail)
                {
                    var resultsViewController =
                        Resources.FindObjectsOfTypeAll <ResultsViewController>().FirstOrDefault();
                    resultsViewController.continueButtonPressedEvent += ResultsViewControllerOnContinueButtonPressedEvent;
                }

                if (SettingsObject == null)
                {
                    var volumeSettings = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();
                    volumeSettings.gameObject.SetActive(false);
                    SettingsObject = Object.Instantiate(volumeSettings.gameObject);
                    SettingsObject.SetActive(false);
                    volumeSettings.gameObject.SetActive(true);
                    var volume = SettingsObject.GetComponent <VolumeSettingsController>();
                    ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController),
                                                 typeof(SpeedSettingsController), SettingsObject);
                    Object.DestroyImmediate(volume);
                    SettingsObject.GetComponentInChildren <TMP_Text>().text = "SPEED";
                    Object.DontDestroyOnLoad(SettingsObject);
                }
            }
            else
            {
                if (_mainGameSceneSetupData == null)
                {
                    _mainGameSceneSetupData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                    if (_mainGameSceneSetupData == null)
                    {
                        return;
                    }
                    _mainGameSceneSetupData.didFinishEvent += MainGameSceneSetupDataOnDidFinishEvent;
                }

                if (scene.buildIndex != 5)
                {
                    return;
                }

                if (_lastLevelId != _mainGameSceneSetupData.difficultyLevel.level.levelID &&
                    !string.IsNullOrEmpty(_lastLevelId))
                {
                    HasTimeScaleChanged = false;
                    TimeScale           = 1;
                    _lastLevelId        = _mainGameSceneSetupData.difficultyLevel.level.levelID;
                }

                if (IsEqualToOne(TimeScale))
                {
                    HasTimeScaleChanged = false;
                }

                _lastLevelId = _mainGameSceneSetupData.difficultyLevel.level.levelID;

                _audioTimeSync = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault();
                _songAudio     = _audioTimeSync.GetPrivateField <AudioSource>("_audioSource");
                NoFail         = !_mainGameSceneSetupData.gameplayOptions.validForScoreUse;

                if (!NoFail)
                {
                    TimeScale = Mathf.Clamp(TimeScale, 1, MaxSize);
                }

                NoteHitPitchChanger.ReplacePrefab();

                var canvas = Resources.FindObjectsOfTypeAll <HorizontalLayoutGroup>()
                             .FirstOrDefault(x => x.name == "Buttons")
                             .transform.parent;
                _speedSettingsCreator = canvas.gameObject.AddComponent <SpeedSettingsCreator>();
                _speedSettingsCreator.ValueChangedEvent += SpeedSettingsCreatorOnValueChangedEvent;
                TimeScale = TimeScale;
            }
        }
Exemple #5
0
        private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            if (scene.name == MenuSceneName)
            {
                if (_resetNoFail)
                {
                    var resultsViewController =
                        Resources.FindObjectsOfTypeAll <ResultsViewController>().FirstOrDefault();
                    if (resultsViewController != null)
                    {
                        resultsViewController.continueButtonPressedEvent +=
                            ResultsViewControllerOnContinueButtonPressedEvent;
                    }
                }

                if (SettingsObject != null)
                {
                    return;
                }

                var volumeSettings = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();

                if (volumeSettings == null)
                {
                    return;
                }

                volumeSettings.gameObject.SetActive(false);
                SettingsObject = Object.Instantiate(volumeSettings.gameObject);
                SettingsObject.SetActive(false);
                volumeSettings.gameObject.SetActive(true);

                if (SettingsObject == null)
                {
                    return;
                }

                var volume = SettingsObject.GetComponent <VolumeSettingsController>();
                ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController),
                                             typeof(SpeedSettingsController), SettingsObject);
                Object.DestroyImmediate(volume);

                SettingsObject.GetComponentInChildren <TMP_Text>().text = "SPEED";
                Object.DontDestroyOnLoad(SettingsObject);
            }
            else if (scene.name == GameSceneName)
            {
                CustomEffectPoolsInstaller customEffectPoolsInstaller = null;
                var effectPoolsInstaller = Resources.FindObjectsOfTypeAll <EffectPoolsInstaller>().FirstOrDefault();
                if (effectPoolsInstaller != null)
                {
                    customEffectPoolsInstaller = (CustomEffectPoolsInstaller)ReflectionUtil.CopyComponent(effectPoolsInstaller,
                                                                                                          typeof(EffectPoolsInstaller), typeof(CustomEffectPoolsInstaller), effectPoolsInstaller.gameObject);
                }

                SceneContext          sceneContext          = null;
                SceneDecoratorContext sceneDecoratorContext = null;

                foreach (var gameObject in scene.GetRootGameObjects())
                {
                    if (sceneContext == null)
                    {
                        sceneContext = gameObject.GetComponentInChildren <SceneContext>(true);
                    }
                }

                foreach (var gameObject in SceneManager.GetSceneByName(ContextSceneName).GetRootGameObjects())
                {
                    if (sceneDecoratorContext == null)
                    {
                        sceneDecoratorContext = gameObject.GetComponentInChildren <SceneDecoratorContext>(true);
                    }
                }


                if (sceneContext != null && sceneDecoratorContext != null)
                {
                    var prop           = typeof(Context).GetField("_installers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    var installersList = (List <MonoInstaller>)prop.GetValue(sceneDecoratorContext);
                    installersList.Remove(effectPoolsInstaller);
                    Object.DestroyImmediate(effectPoolsInstaller);
                    installersList.Add(customEffectPoolsInstaller);
                }

                if (_mainGameSceneSetupData == null)
                {
                    _mainGameSceneSetupData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                    if (_mainGameSceneSetupData == null)
                    {
                        return;
                    }
                    _mainGameSceneSetupData.didFinishEvent += MainGameSceneSetupDataOnDidFinishEvent;
                }

                if (_lastLevelId != _mainGameSceneSetupData.difficultyLevel.level.levelID &&
                    !string.IsNullOrEmpty(_lastLevelId))
                {
                    PlayingNewSong      = true;
                    HasTimeScaleChanged = false;
                    TimeScale           = 1;
                    _lastLevelId        = _mainGameSceneSetupData.difficultyLevel.level.levelID;
                }
                else
                {
                    PlayingNewSong = false;
                }

                if (IsEqualToOne(TimeScale))
                {
                    HasTimeScaleChanged = false;
                }

                _lastLevelId = _mainGameSceneSetupData.difficultyLevel.level.levelID;

                AudioTimeSync = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault();
                _songAudio    = AudioTimeSync.GetPrivateField <AudioSource>("_audioSource");
                NoFail        = !_mainGameSceneSetupData.gameplayOptions.validForScoreUse;

                if (!NoFail)
                {
                    TimeScale = Mathf.Clamp(TimeScale, 1, MaxSize);
                }

                var canvas = Resources.FindObjectsOfTypeAll <HorizontalLayoutGroup>()
                             .FirstOrDefault(x => x.name == "Buttons")
                             ?.transform.parent;

                if (canvas == null)
                {
                    return;
                }

                _uiElementsCreator = canvas.gameObject.AddComponent <UIElementsCreator>();
                _uiElementsCreator.ValueChangedEvent += UIElementsCreatorOnValueChangedEvent;
                _uiElementsCreator.Init();
                TimeScale = TimeScale;
            }
        }