private static void ReadyUp(IBeatmapLevel song) { if (queuedSong != null || (queuedSong == null && song == null)) { return; } if (queuedSong == null && song != null) { queuedSong = song; if (autoReady) { PracticeSettings pSettings = null; if (SteamAPI.GetSongOffset() > 0f) { pSettings = new PracticeSettings(); float offsetTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds() - timeRequestedToLaunch; // add 5 seconds to it because that's about how long it takes to launch a song pSettings.startSongTime = SteamAPI.GetSongOffset() + offsetTime + 5f; timeRequestedToLaunch = 0; } SongListUtils.StartSong(song, SteamAPI.GetSongDifficulty(), SteamAPI.GetGameplayModifiers(), pSettings); } else { SteamAPI.SetReady(); PreviewPlayer.CrossfadeTo(song.previewAudioClip, song.previewStartTime, song.previewDuration); } } }
public static PracticeSettings ConvertPractice(PartyPanelShared.Models.PracticeSettings practiceSettings) { Logger.Debug(practiceSettings.songSpeed.ToString()); PracticeSettings newSettings = new PracticeSettings(0f, practiceSettings.songSpeed / 10000); return(newSettings); }
private IEnumerator SongStartWait(bool update, bool songStart = true) { if (this.audioTimeSyncController != null) { float songTime = this.audioTimeSyncController.songTime; yield return(new WaitWhile(() => this.audioTimeSyncController.songTime > songTime)); PracticeSettings practiceSettings = this.CurrentData.practiceSettings; float songSpeedMul = this.CurrentData.gameplayModifiers.songSpeedMul; if (practiceSettings != null) { songSpeedMul = practiceSettings.songSpeedMul; } this.statusManager.GameStatus.start = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - (long)(this.audioTimeSyncController.songTime * 1000f / songSpeedMul); //resumeの時はstartSongTime分がsongTimeに含まれているので処理不要 if (songStart && practiceSettings != null) { this.statusManager.GameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul); } update = true; } if (update == false) { yield break; } if (songStart) { this.statusManager.EmitStatusUpdate(ChangedProperty.AllButNoteCut, BeatSaberEvent.SongStart); } else { this.statusManager.EmitStatusUpdate(ChangedProperty.Beatmap, BeatSaberEvent.Resume); } }
public StateID Run(PracticeSettings pr) { Console.Clear(); m_ActionBeforePrint?.Invoke(pr); Console.Write(m_TextToPrint); m_ActionAfterPrint?.Invoke(pr); int op = -1; while (!int.TryParse(Console.ReadLine(), out op)) { } m_ActionAfterUserInput?.Invoke(pr, op); // return next state if (m_Transitions != null && m_Transitions.ContainsKey(op)) { return(m_Transitions[op]); } if (m_FuncNextState != null) { return(m_FuncNextState.Invoke(pr, op)); } return(StateID.None); }
static void Postfix(StandardLevelScenesTransitionSetupDataSO __instance, IDifficultyBeatmap difficultyBeatmap, IPreviewBeatmapLevel previewBeatmapLevel, OverrideEnvironmentSettings overrideEnvironmentSettings, GameplayModifiers gameplayModifiers, ColorScheme overrideColorScheme, PlayerSpecificSettings playerSpecificSettings, ref PracticeSettings practiceSettings, bool useTestNoteCutSoundEffects, MainSettingsModelSO ____mainSettingsModel) { EnvironmentInfoSO environmentInfoSO = difficultyBeatmap.GetEnvironmentInfo(); if (overrideEnvironmentSettings is { overrideEnvironments : true })
public void StartLevel(BeatmapLevelSO level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers, float startTime = 0f) { Client.Instance.playerInfo.playerComboBlocks = 0; Client.Instance.playerInfo.playerCutBlocks = 0; Client.Instance.playerInfo.playerTotalBlocks = 0; Client.Instance.playerInfo.playerEnergy = 0f; Client.Instance.playerInfo.playerScore = 0; MenuTransitionsHelperSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelperSO>().FirstOrDefault(); if (_playerManagementViewController != null) { _playerManagementViewController.SetGameplayModifiers(modifiers); } if (menuSceneSetupData != null) { if (Config.Instance.SpectatorMode) { Client.Instance.playerInfo.playerState = PlayerState.Spectating; modifiers.noFail = true; } else { Client.Instance.playerInfo.playerState = PlayerState.Game; } PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings; roomInfo.roomState = RoomState.InGame; IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(characteristic, difficulty, true); #if DEBUG Logger.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}"); #endif Client.Instance.MessageReceived -= PacketReceived; try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("Beat Saber Multiplayer"); } catch { } PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); practiceSettings.startSongTime = startTime + 1.5f; practiceSettings.songSpeedMul = modifiers.songSpeedMul; menuSceneSetupData.StartStandardLevel(difficultyBeatmap, modifiers, playerSettings, (startTime > 1f ? practiceSettings : null), false, () => {}, (StandardLevelScenesTransitionSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, modifiers, false); }); return; } else { Logger.Error("SceneSetupData is null!"); } }
private static void StartLevel(IBeatmapLevel level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers, float startTime = 0f) { var menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelper>().FirstOrDefault(); if (menuSceneSetupData != null) { 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 = level.GetDifficultyBeatmap(characteristic, difficulty, false); try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("TestMod"); } catch { } PracticeSettings practiceSettings = null; if (startTime > 1f) { practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); if (startTime > 1f) { practiceSettings.startSongTime = startTime + 1.5f; practiceSettings.startInAdvanceAndClearNotes = true; } practiceSettings.songSpeedMul = modifiers.songSpeedMul; } menuSceneSetupData.StartStandardLevel( difficultyBeatmap, environmentOverrideSettings, colorSchemesSettings, modifiers, playerSettings, practiceSettings, "Menu", false, () => { }, (manager, result) => { }); } else { Plugin.log.Error("SceneSetupData is null!"); } }
public void StartLevel(IBeatmapLevel level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers, float startTime = 0f) { Client.Instance.playerInfo.updateInfo.playerComboBlocks = 0; Client.Instance.playerInfo.updateInfo.playerCutBlocks = 0; Client.Instance.playerInfo.updateInfo.playerTotalBlocks = 0; Client.Instance.playerInfo.updateInfo.playerEnergy = 0f; Client.Instance.playerInfo.updateInfo.playerScore = 0; Client.Instance.playerInfo.updateInfo.playerLevelOptions = new LevelOptionsInfo(difficulty, modifiers, characteristic.serializedName); MenuTransitionsHelperSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelperSO>().FirstOrDefault(); if (_playerManagementViewController != null) { _playerManagementViewController.SetGameplayModifiers(modifiers); } if (menuSceneSetupData != null) { Client.Instance.playerInfo.updateInfo.playerState = Config.Instance.SpectatorMode ? PlayerState.Spectating : PlayerState.Game; PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().playerData.playerSpecificSettings; roomInfo.roomState = RoomState.InGame; IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(characteristic, difficulty, false); Plugin.log.Debug($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}"); Client.Instance.MessageReceived -= PacketReceived; try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("Beat Saber Multiplayer"); } catch { } PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); practiceSettings.startSongTime = startTime + 1.5f; practiceSettings.songSpeedMul = modifiers.songSpeedMul; practiceSettings.startInAdvanceAndClearNotes = true; menuSceneSetupData.StartStandardLevel(difficultyBeatmap, new OverrideEnvironmentSettings() { overrideEnvironments = false }, null, modifiers, playerSettings, (startTime > 1f ? practiceSettings : null), "Lobby", false, () => { }, (StandardLevelScenesTransitionSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(levelCompletionResults, difficultyBeatmap, modifiers, startTime > 1f); }); } else { Plugin.log.Error("SceneSetupData is null!"); } }
static void Postfix(ref LevelCompletionResults __result, LevelCompletionResults.LevelEndStateType levelEndStateType) { if ((ScoreSubmission.WasDisabled || ScoreSubmission.disabled || ScoreSubmission.prolongedDisable) && levelEndStateType == LevelCompletionResults.LevelEndStateType.Cleared && Plugin.scenesTransitionSetupData != null) { var gameplayCoreSceneSetupData = GameplayCoreSceneSetupDataAccessor(ref Plugin.scenesTransitionSetupData).OfType <GameplayCoreSceneSetupData>().FirstOrDefault(); if (gameplayCoreSceneSetupData != null) { PracticeSettingsAccessor(ref gameplayCoreSceneSetupData) = new PracticeSettings(); } Plugin.scenesTransitionSetupData = null; __result.SetField("multipliedScore", -__result.multipliedScore); } }
static void Prefix(MultiplayerLevelScenesTransitionSetupDataSO __instance, ref EnvironmentInfoSO ____multiplayerEnvironmentInfo, string gameMode, IPreviewBeatmapLevel previewBeatmapLevel, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO beatmapCharacteristic, IDifficultyBeatmap difficultyBeatmap, ColorScheme overrideColorScheme, GameplayModifiers gameplayModifiers, PlayerSpecificSettings playerSpecificSettings, PracticeSettings practiceSettings, bool useTestNoteCutSoundEffects = false) { ScoreSubmission._wasDisabled = false; ScoreSubmission.LastDisablers = Array.Empty <string>(); Plugin.LevelData.GameplayCoreSceneSetupData = new GameplayCoreSceneSetupData(difficultyBeatmap, gameplayModifiers, playerSpecificSettings, practiceSettings, useTestNoteCutSoundEffects, ____multiplayerEnvironmentInfo); Plugin.LevelData.IsSet = true; Plugin.LevelData.Mode = Mode.Multiplayer; Utilities.Logger.log.Debug("Level Data set"); __instance.didFinishEvent -= __instance_didFinishEvent; __instance.didFinishEvent += __instance_didFinishEvent; }
public void StartLevel(BeatmapLevelSO level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers, float startTime = 0f) { Client.Instance.playerInfo.playerComboBlocks = 0; Client.Instance.playerInfo.playerCutBlocks = 0; Client.Instance.playerInfo.playerEnergy = 0f; Client.Instance.playerInfo.playerScore = 0; MenuTransitionsHelperSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelperSO>().FirstOrDefault(); if (menuSceneSetupData != null) { PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings; channelInfo.state = ChannelState.InGame; Client.Instance.playerInfo.playerState = PlayerState.Game; IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(characteristic, difficulty, false); #if DEBUG Misc.Logger.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}"); #endif PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); if (startTime > 1.5f) { practiceSettings.startSongTime = startTime + 1.5f; } Client.Instance.MessageReceived -= MessageReceived; try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("Beat Saber Multiplayer"); } catch { } menuSceneSetupData.StartStandardLevel(difficultyBeatmap, modifiers, playerSettings, (startTime > 1.5f ? practiceSettings : null), null, (StandardLevelScenesTransitionSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, modifiers, (practiceSettings != null)); }); return; } else { Misc.Logger.Error("SceneSetupData is null!"); } }
public void StartLevel(IBeatmapLevel level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers, float startTime = 0f) { Client.Instance.playerInfo.updateInfo.playerComboBlocks = 0; Client.Instance.playerInfo.updateInfo.playerCutBlocks = 0; Client.Instance.playerInfo.updateInfo.playerEnergy = 0f; Client.Instance.playerInfo.updateInfo.playerScore = 0; MenuTransitionsHelperSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelperSO>().FirstOrDefault(); if (menuSceneSetupData != null) { PlayerData playerData = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().playerData; PlayerSpecificSettings playerSettings = playerData.playerSpecificSettings; channelInfo.state = ChannelState.InGame; Client.Instance.playerInfo.updateInfo.playerState = PlayerState.Game; IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(characteristic, difficulty, false); #if DEBUG Plugin.log.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}"); #endif PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); practiceSettings.startSongTime = startTime + 1.5f; practiceSettings.songSpeedMul = modifiers.songSpeedMul; practiceSettings.startInAdvanceAndClearNotes = true; Client.Instance.MessageReceived -= MessageReceived; try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("Beat Saber Multiplayer"); } catch { } OverrideEnvironmentSettings overrideEnvironmentSettings = new OverrideEnvironmentSettings(); menuSceneSetupData.StartStandardLevel(difficultyBeatmap, overrideEnvironmentSettings, playerData.colorSchemesSettings.GetSelectedColorScheme(), modifiers, playerSettings, (startTime > 1f ? practiceSettings : null), "Lobby", false, () => {}, (StandardLevelScenesTransitionSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, modifiers, (startTime > 1f)); }); } else { Plugin.log.Error("SceneSetupData is null!"); } }
static void Postfix(bool firstActivation, PercentSlider ____speedSlider, PracticeSettings ____practiceSettings) { if (!firstActivation) { return; } int minSpeed = PluginConfig.instance.minSpeed; int maxSpeed = PluginConfig.instance.maxSpeed; int stepSize = Math.Max(1, PluginConfig.instance.stepSize); maxSpeed -= (maxSpeed - minSpeed) % stepSize; ____speedSlider.minValue = minSpeed / 100f; ____speedSlider.maxValue = maxSpeed / 100f; ____speedSlider.numberOfSteps = (maxSpeed - minSpeed) / stepSize + 1; ____speedSlider.value = Mathf.Clamp(____practiceSettings.songSpeedMul, ____speedSlider.minValue, ____speedSlider.maxValue); ____practiceSettings.songSpeedMul = ____speedSlider.value; }
public void StartLevel(LevelSO level, BeatmapDifficulty difficulty, float startTime = 0f) { Client.Instance.playerInfo.playerComboBlocks = 0; Client.Instance.playerInfo.playerCutBlocks = 0; Client.Instance.playerInfo.playerEnergy = 0f; Client.Instance.playerInfo.playerScore = 0; MenuSceneSetupDataSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().FirstOrDefault(); if (menuSceneSetupData != null) { GameplayModifiers gameplayModifiers = new GameplayModifiers(); gameplayModifiers.noFail = true; PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings; channelInfo.state = ChannelState.InGame; Client.Instance.playerInfo.playerState = PlayerState.Game; IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(difficulty); if (difficultyBeatmap == null) { difficultyBeatmap = level.GetDifficultyBeatmap(GetClosestDifficulty(level, difficulty)); } Misc.Logger.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}"); PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); practiceSettings.startSongTime = startTime + 1.5f; Client.Instance.MessageReceived -= MessageReceived; menuSceneSetupData.StartStandardLevel(difficultyBeatmap, gameplayModifiers, playerSettings, (startTime > 1f ? practiceSettings : null), null, (StandardLevelSceneSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, gameplayModifiers, (practiceSettings != null)); }); return; } else { Misc.Logger.Error("SceneSetupData is null!"); } }
public async void HandleSongStart() { // Check if level data is actually available in BS_Utils before proceeding further. It isn't available in the tutorial if (!BS_Utils.Plugin.LevelData.IsSet) { Plugin.log.Debug("BS_Utils level data is not present. Probably due to the tutorial being active."); return; } GameStatus gameStatus = statusManager.gameStatus; // Check for multiplayer early to abort if needed: gameplay controllers don't exist in multiplayer until later multiplayerSessionManager = FindFirstOrDefaultOptional <MultiplayerSessionManager>(); multiplayerController = FindFirstOrDefaultOptional <MultiplayerController>(); if (multiplayerSessionManager && multiplayerController) { Plugin.log.Debug("Multiplayer Level loaded"); // public event Action<DisconnectedReason> MultiplayerSessionManager#disconnectedEvent; multiplayerSessionManager.disconnectedEvent += OnMultiplayerDisconnected; // public event Action<State> MultiplayerController#stateChangedEvent; multiplayerController.stateChangedEvent += OnMultiplayerStateChanged; // Do nothing until the next state change to Gameplay. if (multiplayerController.state != MultiplayerController.State.Gameplay) { return; } multiplayerLocalActivePlayerFacade = FindFirstOrDefaultOptional <MultiplayerLocalActivePlayerFacade>(); if (multiplayerLocalActivePlayerFacade != null) { multiplayerLocalActivePlayerFacade.playerDidFinishEvent += OnMultiplayerLevelFinished; } } else if (!doDelayedSongStart) { doDelayedSongStart = true; return; } // `wants_to_play_next_level` is set for players who don't want to play the song aka want to spectate aka are not "active". `isSpectating` is apparently not spectating. gameStatus.scene = multiplayerSessionManager.isSpectating || !multiplayerSessionManager.LocalPlayerHasState(NetworkConstants.wantsToPlayNextLevel) ? "Spectator" : "Song"; gameStatus.multiplayer = multiplayerSessionManager.isConnectingOrConnected; pauseController = FindFirstOrDefaultOptional <PauseController>(); scoreController = FindWithMultiplayerFix <ScoreController>(); beatmapObjectManager = (BeatmapObjectManager)scoreControllerBeatmapObjectManagerField.GetValue(scoreController); gameplayManager = FindFirstOrDefaultOptional <StandardLevelGameplayManager>() as MonoBehaviour ?? FindFirstOrDefaultOptional <MissionLevelGameplayManager>(); beatmapObjectCallbackController = FindWithMultiplayerFix <BeatmapObjectCallbackController>(); gameplayModifiersSO = FindFirstOrDefault <GameplayModifiersModelSO>(); audioTimeSyncController = FindWithMultiplayerFix <AudioTimeSyncController>(); playerHeadAndObstacleInteraction = (PlayerHeadAndObstacleInteraction)scoreControllerHeadAndObstacleInteractionField.GetValue(scoreController); gameSongController = FindWithMultiplayerFix <GameSongController>(); gameEnergyCounter = FindWithMultiplayerFix <GameEnergyCounter>(); if (multiplayerController) { // NOOP } else if (gameplayManager is StandardLevelGameplayManager) { Plugin.log.Debug("Standard Level loaded"); } else if (gameplayManager is MissionLevelGameplayManager) { Plugin.log.Debug("Mission Level loaded"); } gameplayCoreSceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData; // Register event listeners // PauseController doesn't exist in multiplayer if (pauseController != null) { // public event Action PauseController#didPauseEvent; pauseController.didPauseEvent += OnGamePause; // public event Action PauseController#didResumeEvent; pauseController.didResumeEvent += OnGameResume; } // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after CutScoreBuffer is created scoreController.noteWasCutEvent += OnNoteWasCut; // public ScoreController#noteWasMissedEvent<NoteData, int multiplier> scoreController.noteWasMissedEvent += OnNoteWasMissed; // public ScoreController#scoreDidChangeEvent<int, int> // score scoreController.scoreDidChangeEvent += OnScoreDidChange; // public ScoreController#comboDidChangeEvent<int> // combo scoreController.comboDidChangeEvent += OnComboDidChange; // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1] scoreController.multiplierDidChangeEvent += OnMultiplierDidChange; beatmapObjectManager.noteWasSpawnedEvent += OnNoteWasSpawned; // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger; // public event Action GameSongController#songDidFinishEvent; gameSongController.songDidFinishEvent += OnLevelFinished; // public event Action GameEnergyCounter#gameEnergyDidReach0Event; gameEnergyCounter.gameEnergyDidReach0Event += OnEnergyDidReach0Event; if (gameplayManager is ILevelEndActions levelEndActions) { // event Action levelFailedEvent; levelEndActions.levelFailedEvent += OnLevelFailed; } IDifficultyBeatmap diff = gameplayCoreSceneSetupData.difficultyBeatmap; IBeatmapLevel level = diff.level; gameStatus.partyMode = Gamemode.IsPartyActive; gameplayModifiers = gameplayCoreSceneSetupData.gameplayModifiers; gameplayModiferParamsList = gameplayModifiersSO.CreateModifierParamsList(gameplayModifiers); PlayerSpecificSettings playerSettings = gameplayCoreSceneSetupData.playerSpecificSettings; PracticeSettings practiceSettings = gameplayCoreSceneSetupData.practiceSettings; float songSpeedMul = gameplayModifiers.songSpeedMul; if (practiceSettings != null) { songSpeedMul = practiceSettings.songSpeedMul; } int beatmapObjectId = 0; var beatmapObjectsData = diff.beatmapData.beatmapObjectsData; // Generate NoteData to id mappings for backwards compatiblity with <1.12.1 noteToIdMapping = new NoteData[beatmapObjectsData.Count(obj => obj is NoteData)]; lastNoteId = 0; foreach (BeatmapObjectData beatmapObjectData in beatmapObjectsData) { if (beatmapObjectData is NoteData noteData) { noteToIdMapping[beatmapObjectId++] = noteData; } } gameStatus.songName = level.songName; gameStatus.songSubName = level.songSubName; gameStatus.songAuthorName = level.songAuthorName; gameStatus.levelAuthorName = level.levelAuthorName; gameStatus.songBPM = level.beatsPerMinute; gameStatus.noteJumpSpeed = diff.noteJumpMovementSpeed; gameStatus.noteJumpStartBeatOffset = diff.noteJumpStartBeatOffset; // 13 is "custom_level_" and 40 is the magic number for the length of the SHA-1 hash gameStatus.songHash = Regex.IsMatch(level.levelID, "^custom_level_[0-9A-F]{40}", RegexOptions.IgnoreCase) && !level.levelID.EndsWith(" WIP") ? level.levelID.Substring(13, 40) : null; gameStatus.levelId = level.levelID; gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f / songSpeedMul); gameStatus.length = (long)(level.beatmapLevelData.audioClip.length * 1000f / songSpeedMul); gameStatus.start = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul); if (practiceSettings != null) { gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul); } gameStatus.paused = 0; gameStatus.difficulty = diff.difficulty.Name(); gameStatus.difficultyEnum = Enum.GetName(typeof(BeatmapDifficulty), diff.difficulty); gameStatus.characteristic = diff.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName; gameStatus.notesCount = diff.beatmapData.cuttableNotesCount; gameStatus.bombsCount = diff.beatmapData.bombsCount; gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount; gameStatus.environmentName = level.environmentInfo.sceneInfo.sceneName; ColorScheme colorScheme = gameplayCoreSceneSetupData.colorScheme ?? new ColorScheme(gameplayCoreSceneSetupData.environmentInfo.colorScheme); gameStatus.colorSaberA = colorScheme.saberAColor; gameStatus.colorSaberB = colorScheme.saberBColor; gameStatus.colorEnvironment0 = colorScheme.environmentColor0; gameStatus.colorEnvironment1 = colorScheme.environmentColor1; if (colorScheme.supportsEnvironmentColorBoost) { gameStatus.colorEnvironmentBoost0 = colorScheme.environmentColor0Boost; gameStatus.colorEnvironmentBoost1 = colorScheme.environmentColor1Boost; } gameStatus.colorObstacle = colorScheme.obstaclesColor; try { // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures- // Modified to correctly handle texture atlases. Fixes #82. var active = RenderTexture.active; var sprite = await level.GetCoverImageAsync(CancellationToken.None); var texture = sprite.texture; var temporary = RenderTexture.GetTemporary(texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); Graphics.Blit(texture, temporary); RenderTexture.active = temporary; var spriteRect = sprite.rect; var uv = sprite.uv[0]; var cover = new Texture2D((int)spriteRect.width, (int)spriteRect.height); // Unity sucks. The coordinates of the sprite on its texture atlas are only accessible through the Sprite.uv property since rect always returns `x=0,y=0`, so we need to convert them back into texture space. cover.ReadPixels(new Rect( uv.x * texture.width, texture.height - uv.y * texture.height, spriteRect.width, spriteRect.height ), 0, 0); cover.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); gameStatus.songCover = System.Convert.ToBase64String(ImageConversion.EncodeToPNG(cover)); } catch { gameStatus.songCover = null; } gameStatus.ResetPerformance(); UpdateModMultiplier(); gameStatus.songSpeedMultiplier = songSpeedMul; gameStatus.batteryLives = gameEnergyCounter.batteryLives; gameStatus.modObstacles = gameplayModifiers.enabledObstacleType.ToString(); gameStatus.modInstaFail = gameplayModifiers.instaFail; gameStatus.modNoFail = gameplayModifiers.noFailOn0Energy; gameStatus.modBatteryEnergy = gameplayModifiers.energyType == GameplayModifiers.EnergyType.Battery; gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows; gameStatus.modNoBombs = gameplayModifiers.noBombs; gameStatus.modSongSpeed = gameplayModifiers.songSpeed.ToString(); gameStatus.modNoArrows = gameplayModifiers.noArrows; gameStatus.modGhostNotes = gameplayModifiers.ghostNotes; gameStatus.modFailOnSaberClash = gameplayModifiers.failOnSaberClash; gameStatus.modStrictAngles = gameplayModifiers.strictAngles; gameStatus.modFastNotes = gameplayModifiers.fastNotes; gameStatus.modSmallNotes = gameplayModifiers.smallCubes; gameStatus.modProMode = gameplayModifiers.proMode; gameStatus.modZenMode = gameplayModifiers.zenMode; var environmentEffectsFilterPreset = diff.difficulty == BeatmapDifficulty.ExpertPlus ? playerSettings.environmentEffectsFilterExpertPlusPreset : playerSettings.environmentEffectsFilterDefaultPreset; // Backwards compatibility for <1.13.4 gameStatus.staticLights = environmentEffectsFilterPreset != EnvironmentEffectsFilterPreset.AllEffects; gameStatus.leftHanded = playerSettings.leftHanded; gameStatus.playerHeight = playerSettings.playerHeight; gameStatus.sfxVolume = playerSettings.sfxVolume; gameStatus.reduceDebris = playerSettings.reduceDebris; gameStatus.noHUD = playerSettings.noTextsAndHuds; gameStatus.advancedHUD = playerSettings.advancedHud; gameStatus.autoRestart = playerSettings.autoRestart; gameStatus.saberTrailIntensity = playerSettings.saberTrailIntensity; gameStatus.environmentEffects = environmentEffectsFilterPreset.ToString(); gameStatus.hideNoteSpawningEffect = playerSettings.hideNoteSpawnEffect; statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart"); }
//private BeatmapObjectCallbackController beatmapObjectCallbackController; public void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene) { if (newScene.name == "GameCore") { gameStatus = new GameStatus(); levelSceneSetupData = FindFirstOrDefault <StandardLevelSceneSetupDataSO>(); //gamePauseManager = FindFirstOrDefault<GamePauseManager>(); scoreController = FindFirstOrDefault <ScoreController>(); gameplayModifiersSO = FindFirstOrDefault <GameplayModifiersModelSO>(); audioTimeSyncController = FindFirstOrDefault <AudioTimeSyncController>(); //playerHeadAndObstacleInteraction = FindFirstOrDefault<PlayerHeadAndObstacleInteraction>(); gameEnergyCounter = FindFirstOrDefault <GameEnergyCounter>(); gameplayManager = FindFirstOrDefault <StandardLevelGameplayManager>(); //beatmapObjectCallbackController = FindFirstOrDefault<BeatmapObjectCallbackController>(); // Register event listeners // private GameEvent GamePauseManager#_gameDidPauseSignal //AddSubscriber(gamePauseManager, "_gameDidPauseSignal", OnGamePause); // private GameEvent GamePauseManager#_gameDidResumeSignal //AddSubscriber(gamePauseManager, "_gameDidResumeSignal", OnGameResume); // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created scoreController.noteWasCutEvent += OnNoteWasCut; // public ScoreController#noteWasMissedEvent<NoteData, int multiplier> scoreController.noteWasMissedEvent += OnNoteWasMissed; // public ScoreController#scoreDidChangeEvent<int> // score scoreController.scoreDidChangeEvent += OnScoreDidChange; // public ScoreController#comboDidChangeEvent<int> // combo scoreController.comboDidChangeEvent += OnComboDidChange; // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1] scoreController.multiplierDidChangeEvent += OnMultiplierDidChange; // private GameEvent GameplayManager#_levelFinishedSignal AddSubscriber(gameplayManager, "_levelFinishedSignal", OnLevelFinished); // private GameEvent GameplayManager#_levelFailedSignal AddSubscriber(gameplayManager, "_levelFailedSignal", OnLevelFailed); // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent //beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger; IDifficultyBeatmap diff = levelSceneSetupData.difficultyBeatmap; IBeatmapLevel level = diff.level; GameplayModifiers gameplayModifiers = levelSceneSetupData.gameplayCoreSetupData.gameplayModifiers; PlayerSpecificSettings playerSettings = levelSceneSetupData.gameplayCoreSetupData.playerSpecificSettings; PracticeSettings practiceSettings = levelSceneSetupData.gameplayCoreSetupData.practiceSettings; float songSpeedMul = gameplayModifiers.songSpeedMul; if (practiceSettings != null) { songSpeedMul = practiceSettings.songSpeedMul; } float modifierMultiplier = gameplayModifiersSO.GetTotalMultiplier(gameplayModifiers); var songInfo = FindLevelInfancyWay(levelSceneSetupData.difficultyBeatmap.level.levelID); gameStatus.songHash = level.levelID.Substring(0, Math.Max(0, level.levelID.IndexOf('∎'))); gameStatus.songBeatSaverID = songInfo == null ? null : ParseIdFromSongPath(songInfo); gameStatus.songFilePath = songInfo?.path; gameStatus.songName = level.songName; gameStatus.songSubName = level.songSubName; gameStatus.songAuthorName = level.songAuthorName; gameStatus.songBPM = level.beatsPerMinute; gameStatus.noteJumpSpeed = diff.noteJumpMovementSpeed; gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f / songSpeedMul); gameStatus.length = (long)(level.audioClip.length * 1000f / songSpeedMul); gameStatus.start = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul); if (practiceSettings != null) { gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul); } gameStatus.paused = 0; gameStatus.difficulty = diff.difficulty.Name(); gameStatus.notesCount = diff.beatmapData.notesCount; gameStatus.bombsCount = diff.beatmapData.bombsCount; gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount; gameStatus.maxScore = ScoreController.GetScoreForGameplayModifiersScoreMultiplier(ScoreController.MaxScoreForNumberOfNotes(diff.beatmapData.notesCount), modifierMultiplier); gameStatus.maxPossibleScore = ScoreController.MaxScoreForNumberOfNotes(diff.beatmapData.notesCount); gameStatus.maxRank = RankModel.MaxRankForGameplayModifiers(gameplayModifiers, gameplayModifiersSO).ToString(); gameStatus.ResetPerformance(); gameStatus.modifierMultiplier = modifierMultiplier; gameStatus.songSpeedMultiplier = songSpeedMul; gameStatus.batteryLives = gameEnergyCounter.batteryLives; gameStatus.modObstacles = gameplayModifiers.enabledObstacleType.ToString(); gameStatus.modInstaFail = gameplayModifiers.instaFail; gameStatus.modNoFail = gameplayModifiers.noFail; gameStatus.modBatteryEnergy = gameplayModifiers.batteryEnergy; gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows; gameStatus.modNoBombs = gameplayModifiers.noBombs; gameStatus.modSongSpeed = gameplayModifiers.songSpeed.ToString(); gameStatus.modFailOnSaberClash = gameplayModifiers.failOnSaberClash; gameStatus.modStrictAngles = gameplayModifiers.strictAngles; } }
public async void HandleSongStart() { GameStatus gameStatus = statusManager.gameStatus; // Check for multiplayer early to abort if needed: gameplay controllers don't exist in multiplayer until later multiplayerSessionManager = FindFirstOrDefaultOptional <MultiplayerSessionManager>(); multiplayerController = FindFirstOrDefaultOptional <MultiplayerController>(); if (multiplayerSessionManager && multiplayerController) { Plugin.log.Debug("Multiplayer Level loaded"); // public event Action<DisconnectedReason> MultiplayerSessionManager#disconnectedEvent; multiplayerSessionManager.disconnectedEvent += OnMultiplayerDisconnected; // public event Action<State> MultiplayerController#stateChangedEvent; multiplayerController.stateChangedEvent += OnMultiplayerStateChanged; // Do nothing until the next state change to Gameplay. if (multiplayerController.state != MultiplayerController.State.Gameplay) { return; } multiplayerLocalActivePlayerFacade = FindFirstOrDefaultOptional <MultiplayerLocalActivePlayerFacade>(); if (multiplayerLocalActivePlayerFacade != null) { multiplayerLocalActivePlayerFacade.playerDidFinishEvent += OnMultiplayerLevelFinished; } } else if (!doDelayedSongStart) { doDelayedSongStart = true; return; } // `wants_to_play_next_level` is set for players who don't want to play the song aka want to spectate aka are not "active". `isSpectating` is apparently not spectating. gameStatus.scene = multiplayerSessionManager.isSpectating || !multiplayerSessionManager.LocalPlayerHasState(NetworkConstants.wantsToPlayNextLevel) ? "Spectator" : "Song"; gameStatus.multiplayer = multiplayerSessionManager.isConnectingOrConnected; pauseController = FindFirstOrDefaultOptional <PauseController>(); scoreController = FindFirstOrDefault <ScoreController>(); gameplayManager = FindFirstOrDefaultOptional <StandardLevelGameplayManager>() as MonoBehaviour ?? FindFirstOrDefaultOptional <MissionLevelGameplayManager>(); beatmapObjectCallbackController = FindFirstOrDefault <BeatmapObjectCallbackController>(); gameplayModifiersSO = FindFirstOrDefault <GameplayModifiersModelSO>(); audioTimeSyncController = FindFirstOrDefault <AudioTimeSyncController>(); playerHeadAndObstacleInteraction = (PlayerHeadAndObstacleInteraction)scoreControllerHeadAndObstacleInteractionField.GetValue(scoreController); gameSongController = FindFirstOrDefault <GameSongController>(); gameEnergyCounter = FindFirstOrDefault <GameEnergyCounter>(); if (multiplayerController) { // NOOP } else if (gameplayManager is StandardLevelGameplayManager) { Plugin.log.Debug("Standard Level loaded"); } else if (gameplayManager is MissionLevelGameplayManager) { Plugin.log.Debug("Mission Level loaded"); } gameplayCoreSceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData; // Register event listeners // PauseController doesn't exist in multiplayer if (pauseController != null) { // public event Action PauseController#didPauseEvent; pauseController.didPauseEvent += OnGamePause; // public event Action PauseController#didResumeEvent; pauseController.didResumeEvent += OnGameResume; } // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created scoreController.noteWasCutEvent += OnNoteWasCut; // public ScoreController#noteWasMissedEvent<NoteData, int multiplier> scoreController.noteWasMissedEvent += OnNoteWasMissed; // public ScoreController#scoreDidChangeEvent<int, int> // score scoreController.scoreDidChangeEvent += OnScoreDidChange; // public ScoreController#comboDidChangeEvent<int> // combo scoreController.comboDidChangeEvent += OnComboDidChange; // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1] scoreController.multiplierDidChangeEvent += OnMultiplierDidChange; // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger; // public event Action GameSongController#songDidFinishEvent; gameSongController.songDidFinishEvent += OnLevelFinished; // public event Action GameEnergyCounter#gameEnergyDidReach0Event; gameEnergyCounter.gameEnergyDidReach0Event += OnEnergyDidReach0Event; if (gameplayManager is ILevelEndActions levelEndActions) { // event Action levelFailedEvent; levelEndActions.levelFailedEvent += OnLevelFailed; } IDifficultyBeatmap diff = gameplayCoreSceneSetupData.difficultyBeatmap; IBeatmapLevel level = diff.level; gameStatus.partyMode = Gamemode.IsPartyActive; gameStatus.mode = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName; gameplayModifiers = gameplayCoreSceneSetupData.gameplayModifiers; PlayerSpecificSettings playerSettings = gameplayCoreSceneSetupData.playerSpecificSettings; PracticeSettings practiceSettings = gameplayCoreSceneSetupData.practiceSettings; float songSpeedMul = gameplayModifiers.songSpeedMul; if (practiceSettings != null) { songSpeedMul = practiceSettings.songSpeedMul; } // Generate NoteData to id mappings for backwards compatiblity with <1.12.1 noteToIdMapping = new NoteData[diff.beatmapData.cuttableNotesType + diff.beatmapData.bombsCount]; lastNoteId = 0; int beatmapObjectId = 0; var beatmapObjectsData = diff.beatmapData.beatmapObjectsData; foreach (BeatmapObjectData beatmapObjectData in beatmapObjectsData) { if (beatmapObjectData is NoteData noteData) { noteToIdMapping[beatmapObjectId++] = noteData; } } gameStatus.songName = level.songName; gameStatus.songSubName = level.songSubName; gameStatus.songAuthorName = level.songAuthorName; gameStatus.levelAuthorName = level.levelAuthorName; gameStatus.songBPM = level.beatsPerMinute; gameStatus.noteJumpSpeed = diff.noteJumpMovementSpeed; // 13 is "custom_level_" and 40 is the magic number for the length of the SHA-1 hash gameStatus.songHash = level.levelID.StartsWith("custom_level_") && !level.levelID.EndsWith(" WIP") ? level.levelID.Substring(13, 40) : null; gameStatus.levelId = level.levelID; gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f / songSpeedMul); gameStatus.length = (long)(level.beatmapLevelData.audioClip.length * 1000f / songSpeedMul); gameStatus.start = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul); if (practiceSettings != null) { gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul); } gameStatus.paused = 0; gameStatus.difficulty = diff.difficulty.Name(); gameStatus.notesCount = diff.beatmapData.cuttableNotesType; gameStatus.bombsCount = diff.beatmapData.bombsCount; gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount; gameStatus.environmentName = level.environmentInfo.sceneInfo.sceneName; try { // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures- var texture = (await level.GetCoverImageAsync(CancellationToken.None)).texture; var active = RenderTexture.active; var temporary = RenderTexture.GetTemporary( texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear ); Graphics.Blit(texture, temporary); RenderTexture.active = temporary; var cover = new Texture2D(texture.width, texture.height); cover.ReadPixels(new Rect(0, 0, temporary.width, temporary.height), 0, 0); cover.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); gameStatus.songCover = System.Convert.ToBase64String( ImageConversion.EncodeToPNG(cover) ); } catch { gameStatus.songCover = null; } gameStatus.ResetPerformance(); UpdateModMultiplier(); gameStatus.songSpeedMultiplier = songSpeedMul; gameStatus.batteryLives = gameEnergyCounter.batteryLives; gameStatus.modObstacles = gameplayModifiers.enabledObstacleType.ToString(); gameStatus.modInstaFail = gameplayModifiers.instaFail; gameStatus.modNoFail = gameplayModifiers.noFailOn0Energy; gameStatus.modBatteryEnergy = gameplayModifiers.energyType == GameplayModifiers.EnergyType.Battery; gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows; gameStatus.modNoBombs = gameplayModifiers.noBombs; gameStatus.modSongSpeed = gameplayModifiers.songSpeed.ToString(); gameStatus.modNoArrows = gameplayModifiers.noArrows; gameStatus.modGhostNotes = gameplayModifiers.ghostNotes; gameStatus.modFailOnSaberClash = gameplayModifiers.failOnSaberClash; gameStatus.modStrictAngles = gameplayModifiers.strictAngles; gameStatus.modFastNotes = gameplayModifiers.fastNotes; gameStatus.staticLights = playerSettings.staticLights; gameStatus.leftHanded = playerSettings.leftHanded; gameStatus.playerHeight = playerSettings.playerHeight; gameStatus.sfxVolume = playerSettings.sfxVolume; gameStatus.reduceDebris = playerSettings.reduceDebris; gameStatus.noHUD = playerSettings.noTextsAndHuds; gameStatus.advancedHUD = playerSettings.advancedHud; gameStatus.autoRestart = playerSettings.autoRestart; statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart"); }
static void Prefix(StandardLevelScenesTransitionSetupDataSO __instance, string gameMode, IDifficultyBeatmap difficultyBeatmap, OverrideEnvironmentSettings overrideEnvironmentSettings, GameplayModifiers gameplayModifiers, PlayerSpecificSettings playerSpecificSettings, PracticeSettings practiceSettings, string backButtonText, bool useTestNoteCutSoundEffects) { EnvironmentInfoSO environmentInfoSO = difficultyBeatmap.GetEnvironmentInfo(); if (overrideEnvironmentSettings != null && overrideEnvironmentSettings.overrideEnvironments) { environmentInfoSO = overrideEnvironmentSettings.GetOverrideEnvironmentInfoForType(environmentInfoSO.environmentType); } ScoreSubmission._wasDisabled = false; ScoreSubmission.LastDisablers = Array.Empty <string>(); Plugin.LevelData.GameplayCoreSceneSetupData = new GameplayCoreSceneSetupData(difficultyBeatmap, gameplayModifiers, playerSpecificSettings, practiceSettings, useTestNoteCutSoundEffects, environmentInfoSO); Plugin.LevelData.IsSet = true; Plugin.LevelData.Mode = Mode.Standard; Utilities.Logger.log.Debug("Level Data set"); __instance.didFinishEvent -= __instance_didFinishEvent; __instance.didFinishEvent += __instance_didFinishEvent; }
internal static void Postfix(ref StandardLevelScenesTransitionSetupDataSO standardLevelScenesTransitionSetupData, PracticeSettings __state) { standardLevelScenesTransitionSetupData.Get <GameplayCoreSceneSetupData>().SetField("practiceSettings", __state); }
static void Prefix(StandardLevelScenesTransitionSetupDataSO __instance, IDifficultyBeatmap difficultyBeatmap, GameplayModifiers gameplayModifiers, PlayerSpecificSettings playerSpecificSettings, PracticeSettings practiceSettings) { Plugin.LevelData.GameplayCoreSceneSetupData = new GameplayCoreSceneSetupData(difficultyBeatmap, gameplayModifiers, playerSpecificSettings, practiceSettings); Plugin.LevelData.IsSet = true; __instance.didFinishEvent += __instance_didFinishEvent; }
private void OnActiveSceneChanged(Scene oldScene, Scene newScene) { GameStatus gameStatus = statusManager.gameStatus; gameStatus.scene = newScene.name; if (newScene.name == "MenuCore") { // Menu gameStatus.scene = "Menu"; Gamemode.Init(); // TODO: get the current song, mode and mods while in menu gameStatus.ResetMapInfo(); gameStatus.ResetPerformance(); // Release references for AfterCutScoreBuffers that don't resolve due to player leaving the map before finishing. noteCutMapping.Clear(); statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "menu"); } else if (newScene.name == "GameCore") { // In game gameStatus.scene = "Song"; gamePauseManager = FindFirstOrDefault <GamePauseManager>(); scoreController = FindFirstOrDefault <ScoreController>(); gameplayManager = Resources.FindObjectsOfTypeAll <StandardLevelGameplayManager>().FirstOrDefault() as MonoBehaviour ?? Resources.FindObjectsOfTypeAll <MissionLevelGameplayManager>().FirstOrDefault(); beatmapObjectCallbackController = FindFirstOrDefault <BeatmapObjectCallbackController>(); gameplayModifiersSO = FindFirstOrDefault <GameplayModifiersModelSO>(); audioTimeSyncController = FindFirstOrDefault <AudioTimeSyncController>(); playerHeadAndObstacleInteraction = FindFirstOrDefault <PlayerHeadAndObstacleInteraction>(); gameEnergyCounter = FindFirstOrDefault <GameEnergyCounter>(); gameplayCoreSceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData; // Register event listeners // private GameEvent GamePauseManager#_gameDidPauseSignal AddSubscriber(gamePauseManager, "_gameDidPauseSignal", OnGamePause); // private GameEvent GamePauseManager#_gameDidResumeSignal AddSubscriber(gamePauseManager, "_gameDidResumeSignal", OnGameResume); // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created scoreController.noteWasCutEvent += OnNoteWasCut; // public ScoreController#noteWasMissedEvent<NoteData, int multiplier> scoreController.noteWasMissedEvent += OnNoteWasMissed; // public ScoreController#scoreDidChangeEvent<int, int> // score scoreController.scoreDidChangeEvent += OnScoreDidChange; // public ScoreController#comboDidChangeEvent<int> // combo scoreController.comboDidChangeEvent += OnComboDidChange; // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1] scoreController.multiplierDidChangeEvent += OnMultiplierDidChange; // private GameEvent GameplayManager#_levelFinishedSignal AddSubscriber(gameplayManager, "_levelFinishedSignal", OnLevelFinished); // private GameEvent GameplayManager#_levelFailedSignal AddSubscriber(gameplayManager, "_levelFailedSignal", OnLevelFailed); // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger; IDifficultyBeatmap diff = gameplayCoreSceneSetupData.difficultyBeatmap; IBeatmapLevel level = diff.level; gameStatus.partyMode = Gamemode.IsPartyActive; gameStatus.mode = Gamemode.GameMode; gameplayModifiers = gameplayCoreSceneSetupData.gameplayModifiers; PlayerSpecificSettings playerSettings = gameplayCoreSceneSetupData.playerSpecificSettings; PracticeSettings practiceSettings = gameplayCoreSceneSetupData.practiceSettings; float songSpeedMul = gameplayModifiers.songSpeedMul; if (practiceSettings != null) { songSpeedMul = practiceSettings.songSpeedMul; } float modifierMultiplier = gameplayModifiersSO.GetTotalMultiplier(gameplayModifiers); gameStatus.songName = level.songName; gameStatus.songSubName = level.songSubName; gameStatus.songAuthorName = level.songAuthorName; gameStatus.levelAuthorName = level.levelAuthorName; gameStatus.songBPM = level.beatsPerMinute; gameStatus.noteJumpSpeed = diff.noteJumpMovementSpeed; gameStatus.songHash = level.levelID.Substring(0, Math.Min(32, level.levelID.Length)); gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f / songSpeedMul); gameStatus.length = (long)(level.beatmapLevelData.audioClip.length * 1000f / songSpeedMul); gameStatus.start = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul); if (practiceSettings != null) { gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul); } gameStatus.paused = 0; gameStatus.difficulty = diff.difficulty.Name(); gameStatus.notesCount = diff.beatmapData.notesCount; gameStatus.bombsCount = diff.beatmapData.bombsCount; gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount; gameStatus.environmentName = level.environmentSceneInfo.sceneName; gameStatus.maxScore = ScoreController.MaxModifiedScoreForMaxRawScore(ScoreController.MaxRawScoreForNumberOfNotes(diff.beatmapData.notesCount), gameplayModifiers, gameplayModifiersSO); gameStatus.maxRank = RankModel.MaxRankForGameplayModifiers(gameplayModifiers, gameplayModifiersSO).ToString(); try { // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures- var texture = level.GetCoverImageTexture2DAsync(CancellationToken.None).Result; var active = RenderTexture.active; var temporary = RenderTexture.GetTemporary( texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear ); Graphics.Blit(texture, temporary); RenderTexture.active = temporary; var cover = new Texture2D(texture.width, texture.height); cover.ReadPixels(new Rect(0, 0, temporary.width, temporary.height), 0, 0); cover.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); gameStatus.songCover = System.Convert.ToBase64String( ImageConversion.EncodeToPNG(cover) ); } catch { gameStatus.songCover = null; } gameStatus.ResetPerformance(); gameStatus.modifierMultiplier = modifierMultiplier; gameStatus.songSpeedMultiplier = songSpeedMul; gameStatus.batteryLives = gameEnergyCounter.batteryLives; gameStatus.modObstacles = gameplayModifiers.enabledObstacleType.ToString(); gameStatus.modInstaFail = gameplayModifiers.instaFail; gameStatus.modNoFail = gameplayModifiers.noFail; gameStatus.modBatteryEnergy = gameplayModifiers.batteryEnergy; gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows; gameStatus.modNoBombs = gameplayModifiers.noBombs; gameStatus.modSongSpeed = gameplayModifiers.songSpeed.ToString(); gameStatus.modNoArrows = gameplayModifiers.noArrows; gameStatus.modGhostNotes = gameplayModifiers.ghostNotes; gameStatus.modFailOnSaberClash = gameplayModifiers.failOnSaberClash; gameStatus.modStrictAngles = gameplayModifiers.strictAngles; gameStatus.modFastNotes = gameplayModifiers.fastNotes; gameStatus.staticLights = playerSettings.staticLights; gameStatus.leftHanded = playerSettings.leftHanded; gameStatus.swapColors = playerSettings.swapColors; gameStatus.playerHeight = playerSettings.playerHeight; gameStatus.disableSFX = playerSettings.disableSFX; gameStatus.noHUD = playerSettings.noTextsAndHuds; gameStatus.advancedHUD = playerSettings.advancedHud; statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart"); } }
public void GotoPracticeSettings() { UserMenu.Click(); PracticeSettings.Click(); }
public static async void PlaySong(IPreviewBeatmapLevel level, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, PlaySong packet) { flow = (SoloFreePlayFlowCoordinator)Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().First().GetField("_soloFreePlayFlowCoordinator"); Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { Logger.Debug("G"); MenuTransitionsHelper _menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelper>().First(); IDifficultyBeatmap diffbeatmap = loadedLevel.beatmapLevelData.GetDifficultyBeatmap(characteristic, difficulty); Logger.Debug("L"); GameplaySetupViewController gameplaySetupViewController = (GameplaySetupViewController)typeof(SinglePlayerLevelSelectionFlowCoordinator).GetField("_gameplaySetupViewController", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(flow); Logger.Debug("D"); OverrideEnvironmentSettings environmentSettings = gameplaySetupViewController.environmentOverrideSettings; ColorScheme scheme = gameplaySetupViewController.colorSchemesSettings.GetSelectedColorScheme(); //GameplayModifiers modifiers = gameplaySetupViewController.gameplayModifiers; PlayerSpecificSettings settings = gameplaySetupViewController.playerSettings; //TODO: re add modifier customizability PracticeSettings practiceSettings = ConvertPractice(packet.practiceSettings); GameplayModifiers modifiers = ConvertModifiers(packet.gameplayModifiers, gameplaySetupViewController.gameplayModifiers); Logger.Debug(diffbeatmap.level.levelID + " " + scheme.colorSchemeId); _menuSceneSetupData.StartStandardLevel( "Solo", diffbeatmap, diffbeatmap.level, environmentSettings, scheme, modifiers, settings, practiceSettings, "Menu", false, null, new Action <StandardLevelScenesTransitionSetupDataSO, LevelCompletionResults>((StandardLevelScenesTransitionSetupDataSO q, LevelCompletionResults r) => { }) ); }; if (flow == null || flow.gameObject == null || !flow.gameObject.activeInHierarchy) { Button button = Resources.FindObjectsOfTypeAll <Button>().Where(x => x != null && x.name == "SoloButton").First(); button.onClick.Invoke(); } if ((level is PreviewBeatmapLevelSO && await HasDLCLevel(level.levelID)) || level is CustomPreviewBeatmapLevel) { Logger.Debug("Loading DLC/Custom level..."); var result = await GetLevelFromPreview(level); if (!(result?.isError == true)) { SongLoaded(result?.beatmapLevel); return; } Logger.Debug("You Suck Idiot"); } else if (level is BeatmapLevelSO) { Logger.Debug("Reading OST data without songloader..."); SongLoaded(level as IBeatmapLevel); } else { Logger.Debug($"Skipping unowned DLC ({level.songName})"); } }
public static void StartSong(IBeatmapLevel level, byte difficulty, GameplayModifiers gameplayModifiers, PracticeSettings practiceSettings = null) { if (InSong || level == null || gameplayModifiers == null) { return; } try { MenuTransitionsHelperSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelperSO>().FirstOrDefault(); if (menuSceneSetupData != null) { PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings; _gameplayModifiers = gameplayModifiers; _difficultyBeatmap = null; foreach (IDifficultyBeatmap difficultyBeatmap in level.beatmapLevelData.difficultyBeatmapSets[0].difficultyBeatmaps) { if (difficultyBeatmap.difficultyRank == difficulty) { _difficultyBeatmap = difficultyBeatmap; break; } } if (_difficultyBeatmap == null) { throw new Exception("IDifficultyBeatmap not found"); } Data.Logger.Debug($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={_difficultyBeatmap.difficulty}"); InSong = true; Controllers.PlayerController.Instance._playerInfo.SongFailed = false; Controllers.PlayerController.Instance._playerInfo.InSong = true; menuSceneSetupData.StartStandardLevel(_difficultyBeatmap, gameplayModifiers, playerSettings, practiceSettings, null, new Action <StandardLevelScenesTransitionSetupDataSO, LevelCompletionResults>(FinishSong)); } } catch (Exception e) { Data.Logger.Error(e); } }
public PracticeSetting(PracticeSettings _name, object _value) { Name = _name; Value = _value; }
public static void SwitchLevel(PreloadedLevel level, float startTime = 0f) { var _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault(); if (_scoreController == null) { Plugin.log.Info("ScoreController was null!"); } var oldCombo = _scoreController.GetPrivateField <int>("_combo"); var oldMaxCombo = _scoreController.maxCombo; var oldScore = _scoreController.GetPrivateField <int>("_baseRawScore"); var oldTotalNotes = _scoreController.GetPrivateField <int>("_cutOrMissedNotes"); var menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuTransitionsHelper>().FirstOrDefault(); if (menuSceneSetupData != null) { Plugin.log.Debug( $"Starting song: name={level.levelResult.beatmapLevel.songName}, levelId={level.levelResult.beatmapLevel.levelID}"); try { BS_Utils.Gameplay.Gamemode.NextLevelIsIsolated("TestMod"); } catch { } PracticeSettings practiceSettings = null; if (startTime > 1f || level.speed != 1f) { practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); if (startTime > 1f) { practiceSettings.startSongTime = startTime + 1.5f; practiceSettings.startInAdvanceAndClearNotes = true; } practiceSettings.songSpeedMul = level.speed != 1f ? level.speed : level.modifiers.songSpeedMul; } var transition = Resources.FindObjectsOfTypeAll <StandardLevelScenesTransitionSetupDataSO>().First(); transition.Init( level.difficulty, level.environmentSettings, level.colorScheme, level.modifiers, level.playerSpecificSettings, practiceSettings, "Menu", false); var _gameScenesManager = Object.FindObjectOfType <GameScenesManager>(); _gameScenesManager.ReplaceScenes(transition, 0f, null, () => { Plugin.log.Debug("Game scene has been replaced!"); var newScoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault(); if (newScoreController == null) { Plugin.log.Info("new ScoreController was null!"); } newScoreController.SetPrivateField("_combo", oldCombo); newScoreController.SetPrivateField("_maxCombo", oldMaxCombo); newScoreController.SetPrivateField("_baseRawScore", oldScore); newScoreController.SetPrivateField("_prevFrameRawScore", oldScore); newScoreController.SetPrivateField("_cutOrMissedNotes", oldTotalNotes); Executor.instance.StartCoroutine(FinishMovingScores(oldCombo, oldScore)); Plugin.log.Info("Level switch is complete!"); }); } else { Plugin.log.Error("SceneSetupData is null!"); } }
void SelectAndLoadSong(string name, string difficulty) { //try //{ // mainMenuViewController.HandleMenuButton(MainMenuViewController.MenuButton.SoloFreePlay); //} //catch (Exception e) //{ //} //try //{ // soloModeSelectionViewController.HandleMenuButton(SoloModeSelectionViewController.MenuType.FreePlayMode); //} //catch (Exception e) //{ //} LevelCollectionSO _levelCollection = SongLoader.CustomLevelCollectionSO; LevelSO level = _levelCollection.GetLevelsWithBeatmapCharacteristic(Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>().First(x => x.characteristicName == "Standard")).First(x => x.songName == name); //level = listViewController.GetPrivateField<IBeatmapLevel[]>("_levels").Where(x => x.songName == name)// && x.songAuthorName == author && x.songSubName == subname) // .ToList().ElementAt(0); Console.WriteLine("Song found:" + level.songName); difficultyLevel = level.GetDifficultyBeatmap(_difficulties[difficulty]); ////////////////////////////////////////////////////////////////// // THING TO GET SONG BY JUST STARTING IT // ////////////////////////////////////////////////////////////////// GameplayModifiers gameplayModifiers = new GameplayModifiers(); gameplayModifiers.ResetToDefault(); gameplayModifiers.noFail = true; PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings; var practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings); practiceSettings.startSongTime = time; practiceSettings.songSpeedMul = playbackSpeed; MenuSceneSetupDataSO menu = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().First(); SongLoader loader = Resources.FindObjectsOfTypeAll <SongLoader>().First(); loader.LoadAudioClipForLevel((CustomLevel)level, delegate(CustomLevel customLevel) { menu.StartStandardLevel(difficultyLevel, gameplayModifiers, playerSettings, practiceSettings, null, null); }); /////////////////////////////////////////////////////////////////// // THING TO GET SONG BY NAVIGATING THROUGH MENUS // /////////////////////////////////////////////////////////////////// //MenuSceneSetupDataSO menu = Resources.FindObjectsOfTypeAll<MenuSceneSetupDataSO>().First(); //soloFreePlayFlowCoordinator.HandleLevelListViewControllerDidSelectLevel(listViewController, level); //levelListView.SelectAndScrollToLevel(level.levelID); //int row = levelListView.RowNumberForLevelID(level.levelID); //levelListView.HandleDidSelectRowEvent(levelListView.GetPrivateField<TableView>("_tableView"), row); //try //{ // DifficultyTableView difficultyTableView = beatmapDifficultyViewController.GetPrivateField<DifficultyTableView>("_difficultyTableView"); // TableView tableView = difficultyTableView.GetPrivateField<TableView>("_tableView"); // difficultyTableView.HandleDidSelectRowEvent(tableView, 0); // tableView.SelectRow(0); // difficultyTableView.SelectRow(difficultyLevel, false); // soloFreePlayFlowCoordinator.HandleDifficultyViewControllerDidSelectDifficulty(beatmapDifficultyViewController, difficultyLevel); // practiceController.Init(level, new PracticeSettings()); // GameplayModifiers gameplayModifiers = new GameplayModifiers(); // gameplayModifiers.ResetToDefault(); // gameplayModifiers.noFail = true; // gameplaySetupViewController.SetData(gameplaySetupViewController.playerSettings, gameplayModifiers); // soloFreePlayFlowCoordinator.HandleLevelDetailViewControllerDidPressPracticeButton(detailViewController); // Console.WriteLine("loading " + difficultyLevel.level.songName); // detailViewController.PracticeButtonPressed(); // if (!autoPlayBuffer && time > 2) // { // pause on start // practiceController.HandleSongStartScrollbarOnValueChanged(time - 2); // } // else // { // autoplay or negative time will f**k it up // practiceController.HandleSongStartScrollbarOnValueChanged(time); // } // Console.WriteLine("Starting song at: " + practiceController.GetPrivateField<PracticeSettings>("_practiceSettings").startSongTime); // practiceController.PlayButtonPressed(); // soloFreePlayFlowCoordinator.HandlePracticeViewControllerDidPressPlayButton(); //} //catch (Exception e) //{ // Console.WriteLine(e); // //Console.WriteLine(e.StackTrace); //} //finally //{ // Console.WriteLine("[Mediocre Loader] Finally"); //} //mainGameSceneSetupData.TransitionToScene(0.7f); }
internal SiraPracticeSettings(PracticeSettings normalPracticeSettings) { this.normalPracticeSettings = normalPracticeSettings; }
static void Prefix(StandardLevelScenesTransitionSetupDataSO __instance, IDifficultyBeatmap difficultyBeatmap, OverrideEnvironmentSettings overrideEnvironmentSettings, ColorScheme overrideColorScheme, GameplayModifiers gameplayModifiers, PlayerSpecificSettings playerSpecificSettings, PracticeSettings practiceSettings, string backButtonText, bool useTestNoteCutSoundEffects) { Plugin.LevelData.GameplayCoreSceneSetupData = new GameplayCoreSceneSetupData(difficultyBeatmap, gameplayModifiers, playerSpecificSettings, practiceSettings, useTestNoteCutSoundEffects); Plugin.LevelData.IsSet = true; __instance.didFinishEvent -= __instance_didFinishEvent; __instance.didFinishEvent += __instance_didFinishEvent; }
internal static void Prefix(ref StandardLevelScenesTransitionSetupDataSO standardLevelScenesTransitionSetupData, out PracticeSettings __state) { var setupData = standardLevelScenesTransitionSetupData.Get <GameplayCoreSceneSetupData>(); if (setupData.practiceSettings is Submission.SiraPracticeSettings siraPracticeSettings) { __state = siraPracticeSettings.normalPracticeSettings; return; } __state = setupData.practiceSettings; }