void ReplaceControllers() { if (!Config.Instance.SpectatorMode || Client.Instance.inRadioMode) { return; } audioTimeSync = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault(); _leftSaber = Resources.FindObjectsOfTypeAll <Saber>().First(x => x.saberType == SaberType.SaberB); _leftController = _leftSaber.GetField <VRController, Saber>("_vrController").gameObject.AddComponent <OnlineVRController>(); _leftSaber.SetField <Saber, VRController>("_vrController", _leftController); _rightSaber = Resources.FindObjectsOfTypeAll <Saber>().First(x => x.saberType == SaberType.SaberA); _rightController = _rightSaber.GetField <VRController, Saber>("_vrController").gameObject.AddComponent <OnlineVRController>(); _rightSaber.SetField <Saber, VRController>("_vrController", _rightController); Plugin.log.Info("Controllers replaced!"); _scoreController = FindObjectOfType <ScoreController>(); #if DEBUG _scoreController.noteWasMissedEvent += _scoreController_noteWasMissedEvent; _scoreController.noteWasCutEvent += _scoreController_noteWasCutEvent; #endif Plugin.log.Info("Score controller found!"); _energyCounter = FindObjectOfType <GameEnergyCounter>(); Plugin.log.Info("Energy counter found!"); }
private void TransformToOneColor() { const string OneSaberModeName = "OneSaber"; // Check for game mode and early exit on One Saber or NoArrows GameplayCoreSceneSetupData data = BS_Utils.Plugin.LevelData?.GameplayCoreSceneSetupData; var beatmap = data.difficultyBeatmap; string serializedName = beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName; if (serializedName == OneSaberModeName) { // Do not transform for One Saber or legitimate No Arrows mode Logging.Info($"No need to transform: {beatmap.level.songName} for spear as it is a One Saber map"); return; } // Get the in memory beat map var gameplayCoreSceneSetup = Resources.FindObjectsOfTypeAll <GameplayCoreSceneSetup>().First(); if (gameplayCoreSceneSetup == null) { return; } var dataModel = gameplayCoreSceneSetup.GetField <BeatmapDataModel>("_beatmapDataModel"); var beatmapData = dataModel.beatmapData; Logging.Info("Disabling submission on One Color No Arrows transformation"); BS_Utils.Gameplay.ScoreSubmission.DisableSubmission(Plugin.assemblyName); // Transform the map to One Color and No Arrows NoteType undesiredNoteType = ConfigOptions.instance.LeftHanded ? NoteType.NoteB : NoteType.NoteA; foreach (BeatmapLineData line in beatmapData.beatmapLinesData) { var objects = line.beatmapObjectsData; foreach (BeatmapObjectData beatmapObject in objects) { if (beatmapObject.beatmapObjectType == BeatmapObjectType.Note) { var note = beatmapObject as NoteData; note.SetNoteToAnyCutDirection(); if (note.noteType == undesiredNoteType) { note.SwitchNoteType(); } } } } // Change the other saber to desired type Saber.SaberType desiredSaberType = ConfigOptions.instance.LeftHanded ? Saber.SaberType.SaberA : Saber.SaberType.SaberB; var saberObject = new GameObject("SaberTypeObject").AddComponent <SaberTypeObject>(); saberObject.SetField("_saberType", desiredSaberType); var player = Resources.FindObjectsOfTypeAll <PlayerController>().FirstOrDefault(); Saber saberToSwap = ConfigOptions.instance.LeftHanded ? player.rightSaber : player.leftSaber; saberToSwap.SetField("_saberType", saberObject); }
private IEnumerator TransformMap() { yield return(new WaitForSecondsRealtime(0.1f)); // Set up for One Color if (ConfigOptions.instance.OneColor && !ConfigOptions.instance.NoArrowsRandom) { this.useLeft = (ConfigOptions.instance.PlayMode == PlayMode.BeatSaber && ConfigOptions.instance.UseLeftSaber) || (ConfigOptions.instance.PlayMode == PlayMode.DarthMaul && ConfigOptions.instance.UseLeftController) || (ConfigOptions.instance.PlayMode == PlayMode.BeatSpear && ConfigOptions.instance.UseLeftSpear); this.undesiredNoteType = this.useLeft ? NoteType.NoteB : NoteType.NoteA; // Change the other saber to desired type Saber.SaberType desiredSaberType = this.useLeft ? Saber.SaberType.SaberA : Saber.SaberType.SaberB; var saberObject = new GameObject("SaberTypeObject").AddComponent <SaberTypeObject>(); saberObject.SetField("_saberType", desiredSaberType); var player = Resources.FindObjectsOfTypeAll <PlayerController>().FirstOrDefault(); Saber saberToSwap = this.useLeft ? player.rightSaber : player.leftSaber; saberToSwap.SetField("_saberType", saberObject); if (ConfigOptions.instance.RemoveOtherSaber && ConfigOptions.instance.PlayMode == PlayMode.BeatSaber) { // Hide the off color saber Saber saberToHide = ConfigOptions.instance.UseLeftSaber ? this.playerController.rightSaber : this.playerController.leftSaber; saberToHide.gameObject.SetActive(false); } } // Get the in memory beat map BeatmapObjectCallbackController callbackController = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().First(); BeatmapData beatmapData = callbackController.GetField <BeatmapData>("_beatmapData"); if (ConfigOptions.instance.NoArrowsRandom) { // Transform the map to No Arrows Random using the ingame algorithm first Logging.Info($"Transforming NoArrowsRandom for song: {this.currentBeatmap.level.songName}"); var transformedBeatmap = BeatmapDataNoArrowsTransform.CreateTransformedData(beatmapData, true); callbackController.SetNewBeatmapData(transformedBeatmap); } // Transform every note var allNoteObjects = beatmapData.beatmapLinesData .SelectMany(line => line.beatmapObjectsData) .Where(objectData => objectData.beatmapObjectType == BeatmapObjectType.Note) .ToList(); allNoteObjects.ForEach(beatmapObject => { var note = beatmapObject as NoteData; // Transform for NoArrows or TouchNotes here but do not if NoArrowsRandom was already applied if ((ConfigOptions.instance.NoArrows || ConfigOptions.instance.TouchNotes) && !ConfigOptions.instance.NoArrowsRandom) { note.SetNoteToAnyCutDirection(); } // Transform for One Color if this is the other note type if (ConfigOptions.instance.OneColor && note.noteType == undesiredNoteType) { note.SwitchNoteType(); } }); // Touch Notes speed detection is not handled here but in the HarmonyPatches }
private IEnumerator TransformMap() { yield return(new WaitForSecondsRealtime(0.1f)); var config = Configuration.instance.ConfigurationData; // Set up for One Color if (config.OneColor && !config.NoArrowsRandom) { this.useLeft = (config.PlayMode == PlayMode.BeatSaber && config.UseLeftSaber) || (config.PlayMode == PlayMode.DarthMaul && config.UseLeftController) || (config.PlayMode == PlayMode.BeatSpear && config.UseLeftSpear); this.undesiredNoteType = this.useLeft ? ColorType.ColorB : ColorType.ColorA; // Change the other saber to desired type SaberType desiredSaberType = this.useLeft ? SaberType.SaberA : SaberType.SaberB; var saberObject = new GameObject("SaberTypeObject").AddComponent <SaberTypeObject>(); saberObject.SetField("_saberType", desiredSaberType); var player = Resources.FindObjectsOfTypeAll <SaberManager>().FirstOrDefault(); Saber saberToSwap = this.useLeft ? player.rightSaber : player.leftSaber; saberToSwap.SetField("_saberType", saberObject); } try { BeatmapObjectCallbackController callbackController = null; BeatmapData beatmapData = null; BeatmapObjectCallbackController[] callbackControllers = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>(); foreach (BeatmapObjectCallbackController cbc in callbackControllers) { if (cbc.GetField <BeatmapData>("_beatmapData") != null) { callbackController = cbc; beatmapData = callbackController.GetField <BeatmapData>("_beatmapData"); } } //BeatmapObjectCallbackController callbackController = Resources.FindObjectsOfTypeAll<BeatmapObjectCallbackController>().FirstOrDefault(); // BeatmapData beatmapData = callbackController.GetField<BeatmapData>("_beatmapData"); if (config.NoArrowsRandom) { // Transform the map to No Arrows Random using the ingame algorithm first AlternativePlay.Logger.Info($"Transforming NoArrowsRandom for song: {this.currentBeatmap.level.songName}"); var transformedBeatmap = BeatmapDataNoArrowsTransform.CreateTransformedData(beatmapData); callbackController.SetNewBeatmapData(transformedBeatmap); } // Transform every note var allNoteObjects = beatmapData.beatmapLinesData .SelectMany(line => line.beatmapObjectsData) .Where(objectData => objectData.beatmapObjectType == BeatmapObjectType.Note) .ToList(); allNoteObjects.ForEach(beatmapObject => { var note = beatmapObject as NoteData; // Transform for NoArrows or TouchNotes here but do not if NoArrowsRandom was already applied if ((config.NoArrows || config.TouchNotes) && !config.NoArrowsRandom) { note.SetNoteToAnyCutDirection(); } // Transform for One Color if this is the other note type if (config.OneColor && note.colorType == this.undesiredNoteType) { note.SwitchNoteColorType(); } }); // Touch Notes speed detection is not handled here but in the HarmonyPatches } catch { AlternativePlay.Logger.Info($"Transforming Error: {this.currentBeatmap.level.songName}"); } // Touch Notes speed detection is not handled here but in the HarmonyPatches }