public override void Start() { try { if (BS_Utils.Plugin.LevelData.IsSet) { LevelOptionsInfo levelInfo = owner.playerInfo.updateInfo.playerLevelOptions; IDifficultyBeatmap diffBeatmap = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.level.beatmapLevelData.difficultyBeatmapSets.First(x => x.beatmapCharacteristic.serializedName == owner.playerInfo.updateInfo.playerLevelOptions.characteristicName).difficultyBeatmaps.First(x => x.difficulty == owner.playerInfo.updateInfo.playerLevelOptions.difficulty); _beatsPerMinute = diffBeatmap.level.beatsPerMinute; _noteLinesCount = diffBeatmap.beatmapData.beatmapLinesData.Length; _noteJumpMovementSpeed = diffBeatmap.noteJumpMovementSpeed; _disappearingArrows = levelInfo.modifiers.disappearingArrows; _ghostNotes = levelInfo.modifiers.ghostNotes; float num = 60f / _beatsPerMinute; _moveDistance = _moveSpeed * num * _moveDurationInBeats; while (_noteJumpMovementSpeed * num * _halfJumpDurationInBeats > _maxHalfJumpDistance) { _halfJumpDurationInBeats /= 2f; } _halfJumpDurationInBeats += diffBeatmap.noteJumpStartBeatOffset; if (_halfJumpDurationInBeats < 1f) { _halfJumpDurationInBeats = 1f; } _jumpDistance = _noteJumpMovementSpeed * num * _halfJumpDurationInBeats * 2f; _spawnAheadTime = _moveDistance / _moveSpeed + _jumpDistance * 0.5f / _noteJumpMovementSpeed; } } catch (Exception e) { Plugin.log.Warn("Unable to update beatmap data! Exception: " + e); } if (_beatmapObjectCallbackController != null) { if (_beatmapObjectCallbackId != -1) { _beatmapObjectCallbackController.RemoveBeatmapObjectCallback(_beatmapObjectCallbackId); } _beatmapObjectCallbackId = _beatmapObjectCallbackController.AddBeatmapObjectCallback(new BeatmapObjectCallbackController.BeatmapObjectCallback(HandleBeatmapObjectCallback), _spawnAheadTime); if (_eventCallbackId != -1) { _beatmapObjectCallbackController.RemoveBeatmapEventCallback(_eventCallbackId); } _beatmapObjectCallbackController.callbacksForThisFrameWereProcessedEvent += HandleCallbacksForThisFrameWereProcessed; } NoteCutEffectSpawner cutEffectSpawner = FindObjectOfType <NoteCutEffectSpawner>(); (this as BeatmapObjectSpawnController).noteWasCutEvent += (sender, controller, cutInfo) => { if (cutInfo.allIsOK) { cutEffectSpawner.HandleNoteWasCutEvent(sender, controller, cutInfo); } }; }
public void Init(OnlinePlayerController newOwner, OnlineBeatmapCallbackController callbackController, OnlineAudioTimeController syncController) { BeatmapObjectSpawnController original = FindObjectsOfType <BeatmapObjectSpawnController>().First(x => !x.name.StartsWith("Online")); foreach (FieldInfo info in original.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Default).Where(x => !x.Name.ToLower().Contains("event"))) { info.SetValue(this, info.GetValue(original)); } owner = newOwner; try { if (BS_Utils.Plugin.LevelData.IsSet) { LevelOptionsInfo levelInfo = owner.PlayerInfo.playerLevelOptions; IDifficultyBeatmap diffBeatmap = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.level.beatmapLevelData.difficultyBeatmapSets.First(x => x.beatmapCharacteristic.serializedName == owner.PlayerInfo.playerLevelOptions.characteristicName).difficultyBeatmaps.First(x => x.difficulty == owner.PlayerInfo.playerLevelOptions.difficulty); Init(diffBeatmap.level.beatsPerMinute, diffBeatmap.beatmapData.beatmapLinesData.Length, diffBeatmap.noteJumpMovementSpeed, diffBeatmap.noteJumpStartBeatOffset, levelInfo.modifiers.disappearingArrows, levelInfo.modifiers.ghostNotes); } }catch (Exception e) { Plugin.log.Warn("Unable to update beatmap data! Exception: " + e); } onlineCallbackController = callbackController; _beatmapObjectCallbackController = onlineCallbackController; onlineSyncController = syncController; if (onlineCallbackController != null) { _beatmapObjectCallbackId = onlineCallbackController.AddBeatmapObjectCallback(new BeatmapObjectCallbackController.BeatmapObjectCallback(BeatmapObjectSpawnCallback), _spawnAheadTime); } _localPlayer = FindObjectsOfType <PlayerController>().First(x => !(x is OnlinePlayerController)); _localSyncController = FindObjectsOfType <AudioTimeSyncController>().First(x => !(x is OnlineAudioTimeController)); NoteCutEffectSpawner cutEffectSpawner = FindObjectOfType <NoteCutEffectSpawner>(); (this as BeatmapObjectSpawnController).noteWasCutEvent += (sender, controller, cutInfo) => { if (cutInfo.allIsOK) { cutEffectSpawner.HandleNoteWasCutEvent(sender, controller, cutInfo); } }; _activeNotes = new List <NoteController>(); _activeObstacles = new List <ObstacleController>(); }
public static void Postfix(GameNoteController __instance, Saber saber) { if (sabers == null) { sabers = Resources.FindObjectsOfTypeAll <Saber>(); } var otherSaber = sabers.Where((x) => x != saber).First(); if (Vector3.Distance(otherSaber.saberBladeTopPos, __instance.gameObject.transform.position) < threshold) { if (spawner == null) { spawner = Resources.FindObjectsOfTypeAll <NoteCutEffectSpawner>().FirstOrDefault(); } ReflectionUtil.GetField <NoteCutHapticEffect, NoteCutEffectSpawner>(spawner, "_noteCutHapticEffect").HitNote(otherSaber.saberType); } }
private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene) { try { this._playerController = FindObjectOfType <PlayerController>(); if (scene.buildIndex == 1) { IsLeftSaberOn = true; if (_beatmapObjectSpawnController != null) { _beatmapObjectSpawnController.noteWasCutEvent -= this.HandleNoteWasCutEvent; } if (_mainSettingsModel != null && stored) { StartCoroutine(RestoreNoEnergy()); } } if (scene.buildIndex == 5) { var _mainGameSceneSetup = FindObjectOfType <MainGameSceneSetup>(); this._gameSongController = FindObjectOfType <GameSongController>(); this._noteCutEffectSpawner = FindObjectOfType <NoteCutEffectSpawner>(); this._beatmapObjectSpawnController = FindObjectOfType <BeatmapObjectSpawnController>(); _noteCutHapticEffect = ReflectionUtil.GetPrivateField <NoteCutHapticEffect>(_noteCutEffectSpawner, "_noteCutHapticEffect"); _hapticFeedbackController = ReflectionUtil.GetPrivateField <HapticFeedbackController>(_noteCutHapticEffect, "_hapticFeedbackController"); _mainSettingsModel = ReflectionUtil.GetPrivateField <MainSettingsModel>(_hapticFeedbackController, "_mainSettingsModel"); _mainSettingsModel.controllersRumbleEnabled = true; this._mainGameSceneSetupData = ReflectionUtil.GetPrivateField <MainGameSceneSetupData>(_mainGameSceneSetup, "_mainGameSceneSetupData"); if (!stored) { storedNoEnergy = _mainGameSceneSetupData.gameplayOptions.noEnergy; } stored = true; if (_mainGameSceneSetupData.gameplayMode == GameplayMode.SoloNoArrows) { BeatmapDataModel _beatmapDataModel = ReflectionUtil.GetPrivateField <BeatmapDataModel>(_mainGameSceneSetup, "_beatmapDataModel"); BeatmapData beatmapData = CreateTransformedBeatmapData(_mainGameSceneSetupData.difficultyLevel.beatmapData, _mainGameSceneSetupData.gameplayOptions, _mainGameSceneSetupData.gameplayMode); if (beatmapData != null) { _beatmapDataModel.beatmapData = beatmapData; ReflectionUtil.SetPrivateField(_mainGameSceneSetup, "_beatmapDataModel", _beatmapDataModel); } if (Plugin.IsOneColorModeOn) { _mainGameSceneSetupData.gameplayOptions.noEnergy = true; _sabers = FindObjectsOfType <Saber>(); Saber targetSaber = (Plugin.IsColorRed) ? _playerController.leftSaber : _playerController.rightSaber; Saber otherSaber = (Plugin.IsColorRed) ? _playerController.rightSaber : _playerController.leftSaber; if (targetSaber == null || otherSaber == null) { return; } var targetCopy = Instantiate(targetSaber.gameObject); Saber newSaber = targetCopy.GetComponent <Saber>(); targetCopy.transform.parent = targetSaber.transform.parent; targetCopy.transform.localPosition = Vector3.zero; targetCopy.transform.localRotation = Quaternion.identity; targetSaber.transform.parent = otherSaber.transform.parent; targetSaber.transform.localPosition = Vector3.zero; targetSaber.transform.localRotation = Quaternion.identity; otherSaber.gameObject.SetActive(false); if (Plugin.IsColorRed) { ReflectionUtil.SetPrivateField(_playerController, "_rightSaber", targetSaber); ReflectionUtil.SetPrivateField(_playerController, "_leftSaber", newSaber); } else { ReflectionUtil.SetPrivateField(_playerController, "_leftSaber", targetSaber); ReflectionUtil.SetPrivateField(_playerController, "_rightSaber", newSaber); } _playerController.leftSaber.gameObject.SetActive(IsLeftSaberOn); if (_beatmapObjectSpawnController != null) { _beatmapObjectSpawnController.noteWasCutEvent += this.HandleNoteWasCutEvent; } } } } } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } }
private void SpawnController_ScaleRemoveCut(BeatmapObjectSpawnController arg1, INoteController controller, NoteCutInfo arg3) { NoteData note = controller.noteData; Transform noteTransform = controller.noteTransform; // Log("DESPAWN" + noteTransform.localScale.ToString()); if (noteTransform.localScale.x != 1) { noteTransform.localScale = new Vector3(1f, 1f, 1f); } // Log("DESPAWN" + noteTransform.localScale.ToString()); // if (modifiedNotes[note.id] != null) // note = modifiedNotes[note.id]; FloatBehavior behavior = noteTransform.gameObject.GetComponent <FloatBehavior>(); if (behavior != null) { noteTransform.localPosition = new Vector3(behavior.originalX, behavior.originalY, noteTransform.localPosition.z); GameObject.Destroy(behavior); } if (GMPUI.oneColor) { if (!defaultRumble) { return; } _noteCutEffectSpawner = UnityEngine.Object.FindObjectOfType <NoteCutEffectSpawner>(); if (_noteCutEffectSpawner != null) { _noteCutHapticEffect = ReflectionUtil.GetPrivateField <NoteCutHapticEffect>(_noteCutEffectSpawner, "_noteCutHapticEffect"); } if (_noteCutHapticEffect != null) { _hapticFeedbackController = ReflectionUtil.GetPrivateField <HapticFeedbackController>(_noteCutHapticEffect, "_hapticFeedbackController"); } if (_hapticFeedbackController != null) { _RumbleEnabledOneC = ReflectionUtil.GetPrivateField <BoolSO>(_hapticFeedbackController, "_controllersRumbleEnabled"); } if (_RumbleEnabledOneC == null) { return; } Vector3 notePos = controller.noteTransform.position; Vector3 leftPos = player.leftSaber.transform.position; leftPos += player.leftSaber.transform.forward * 0.5f; Vector3 rightPos = player.rightSaber.transform.position; rightPos += player.rightSaber.transform.forward * 0.5f; float leftDist = Vector3.Distance(leftPos, notePos); float rightDist = Vector3.Distance(rightPos, notePos); // Log(leftDist.ToString() + " " + rightDist.ToString()); _RumbleEnabledOneC.value = true; Saber.SaberType targetType = (leftDist > rightDist) ? Saber.SaberType.SaberB : Saber.SaberType.SaberA; if (!(Mathf.Abs(leftDist - rightDist) <= 0.2f)) { _noteCutHapticEffect.HitNote(targetType); } else { _noteCutHapticEffect.HitNote(Saber.SaberType.SaberA); _noteCutHapticEffect.HitNote(Saber.SaberType.SaberB); } _RumbleEnabledOneC.value = false; } }
private IEnumerator Start() { yield return(FindComponentInBeatSaber(SearchTimeout, (HapticFeedbackController Result) => HapticFeedbackController = Result)); yield return(FindComponentInBeatSaber(SearchTimeout, (NoteCutEffectSpawner Result) => NoteCutEffectSpawner = Result)); if (HapticFeedbackController == null) { Logger.log.Error("Haptic Feedback Controller not found!"); yield break; } if (NoteCutEffectSpawner == null) { Logger.log.Error("Note Cut Spawner not found!"); yield break; } FieldInfo field = NoteCutEffectSpawner.GetType().GetField("_beatmapObjectSpawnController", BindingFlags.Instance | BindingFlags.NonPublic); BeatmapObjectSpawnController = field.GetValue(NoteCutEffectSpawner) as BeatmapObjectSpawnController; if (BeatmapObjectSpawnController == null) { Logger.log.Error("Beatmap object spawner not found"); yield break; } BeatmapObjectSpawnController.noteWasCutEvent += BeatmapObjectSpawnController_noteWasCutEvent; }
public void Init(OnlinePlayerController newOwner, OnlineBeatmapCallbackController callbackController, OnlineAudioTimeController syncController) { BeatmapObjectSpawnController original = FindObjectsOfType <BeatmapObjectSpawnController>().First(x => !(x is OnlineBeatmapSpawnController)); foreach (FieldInfo info in original.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).Where(x => !x.Name.ToLower().Contains("event"))) { info.SetValue(this, info.GetValue(original)); } owner = newOwner; try { if (BS_Utils.Plugin.LevelData.IsSet) { LevelOptionsInfo levelInfo = owner.playerInfo.updateInfo.playerLevelOptions; IDifficultyBeatmap diffBeatmap = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.level.beatmapLevelData.difficultyBeatmapSets.First(x => x.beatmapCharacteristic.serializedName == owner.playerInfo.updateInfo.playerLevelOptions.characteristicName).difficultyBeatmaps.First(x => x.difficulty == owner.playerInfo.updateInfo.playerLevelOptions.difficulty); _beatsPerMinute = diffBeatmap.level.beatsPerMinute; _noteLinesCount = (float)diffBeatmap.beatmapData.beatmapLinesData.Length; _noteJumpMovementSpeed = diffBeatmap.noteJumpMovementSpeed; _disappearingArrows = levelInfo.modifiers.disappearingArrows; _ghostNotes = levelInfo.modifiers.ghostNotes; float num = 60f / _beatsPerMinute; _moveDistance = _moveSpeed * num * _moveDurationInBeats; while (_noteJumpMovementSpeed * num * _halfJumpDurationInBeats > _maxHalfJumpDistance) { _halfJumpDurationInBeats /= 2f; } _halfJumpDurationInBeats += diffBeatmap.noteJumpStartBeatOffset; if (_halfJumpDurationInBeats < 1f) { _halfJumpDurationInBeats = 1f; } _jumpDistance = _noteJumpMovementSpeed * num * _halfJumpDurationInBeats * 2f; _spawnAheadTime = _moveDistance / _moveSpeed + _jumpDistance * 0.5f / _noteJumpMovementSpeed; } }catch (Exception e) { Plugin.log.Warn("Unable to update beatmap data! Exception: " + e); } _beatmapObjectCallbackController = callbackController; onlineSyncController = syncController; if (_beatmapObjectCallbackId != -1) { _beatmapObjectCallbackController.RemoveBeatmapObjectCallback(_beatmapObjectCallbackId); } if (_beatmapObjectCallbackController != null) { _beatmapObjectCallbackId = _beatmapObjectCallbackController.AddBeatmapObjectCallback(new BeatmapObjectCallbackController.BeatmapObjectCallback(BeatmapObjectSpawnCallback), _spawnAheadTime); } _localPlayer = FindObjectsOfType <PlayerController>().First(x => !(x is OnlinePlayerController)); _localSyncController = FindObjectsOfType <AudioTimeSyncController>().First(x => !(x is OnlineAudioTimeController)); NoteCutEffectSpawner cutEffectSpawner = FindObjectOfType <NoteCutEffectSpawner>(); (this as BeatmapObjectSpawnController).noteWasCutEvent += (sender, controller, cutInfo) => { if (cutInfo.allIsOK) { cutEffectSpawner.HandleNoteWasCutEvent(sender, controller, cutInfo); } }; _activeNotes = new List <NoteController>(); _activeObstacles = new List <ObstacleController>(); }