public void OnSceneUnloaded(Scene scene) { if (scene.name == "GameCore") { if (SyncHandler.Instance != null) { SyncHandler.Destroy(); } if (ScoreMonitor.Instance != null) { ScoreMonitor.Destroy(); } if (FloatingScoreScreen.Instance != null) { FloatingScoreScreen.Destroy(); } if (DisablePause) { DisablePause = false; //We can't disable this up above since SyncHandler might need to know info about its status } if (client != null && client.Connected) { (client.Self as Player).PlayState = Player.PlayStates.Waiting; var playerUpdated = new Event(); playerUpdated.Type = Event.EventType.PlayerUpdated; playerUpdated.ChangedObject = client.Self; client.Send(new Packet(playerUpdated)); } } }
protected override void Client_PacketReceived(Packet packet) { base.Client_PacketReceived(packet); if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = SongUtils.masterLevelList.First(x => x.levelID == playSong.GameplayParameters.Beatmap.LevelId); var desiredCharacteristic = desiredLevel.previewDifficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic.serializedName == playSong.GameplayParameters.Beatmap.Characteristic.SerializedName).beatmapCharacteristic ?? desiredLevel.previewDifficultyBeatmapSets.First().beatmapCharacteristic; var desiredDifficulty = (BeatmapDifficulty)playSong.GameplayParameters.Beatmap.Difficulty; var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First().playerData; var playerSettings = playerData.playerSpecificSettings; //Override defaults if we have forced options enabled if (playSong.GameplayParameters.PlayerSettings.Options != PlayerOptions.None) { playerSettings = new PlayerSpecificSettings( playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.StaticLights), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.LeftHanded), playSong.GameplayParameters.PlayerSettings.PlayerHeight, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AutoPlayerHeight), playSong.GameplayParameters.PlayerSettings.SfxVolume, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.ReduceDebris), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.NoHud), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.NoFailEffects), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AdvancedHud), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AutoRestart), playSong.GameplayParameters.PlayerSettings.SaberTrailIntensity, playSong.GameplayParameters.PlayerSettings.NoteJumpStartBeatOffset, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.HideNoteSpawnEffect), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AdaptiveSfx) ); } var songSpeed = GameplayModifiers.SongSpeed.Normal; if (playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.SlowSong)) { songSpeed = GameplayModifiers.SongSpeed.Slower; } if (playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FastSong)) { songSpeed = GameplayModifiers.SongSpeed.Faster; } var gameplayModifiers = new GameplayModifiers( playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DemoNoFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DemoNoObstacles), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.BatteryEnergy) ? GameplayModifiers.EnergyType.Battery : GameplayModifiers.EnergyType.Bar, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.InstaFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FailOnClash), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoObstacles) ? GameplayModifiers.EnabledObstacleType.NoObstacles : GameplayModifiers.EnabledObstacleType.All, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoBombs), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FastNotes), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.StrictAngles), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DisappearingArrows), songSpeed, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoArrows), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.GhostNotes) ); var colorScheme = playerData.colorSchemesSettings.overrideDefaultColors ? playerData.colorSchemesSettings.GetSelectedColorScheme() : null; //Disable score submission if nofail is on. This is specifically for Hidden Sabers, though it may stay longer if (playSong.DisableScoresaberSubmission) { BS_Utils.Gameplay.ScoreSubmission.DisableSubmission(SharedConstructs.Name); } if (playSong.ShowNormalNotesOnStream) { var customNotes = IPA.Loader.PluginManager.GetPluginFromId("CustomNotes"); if (customNotes != null) { EnableHMDOnly(); } } PlaySong?.Invoke(desiredLevel, desiredCharacteristic, desiredDifficulty, gameplayModifiers, playerSettings, playerData.overrideEnvironmentSettings, colorScheme, playSong.FloatingScoreboard, playSong.StreamSync, playSong.DisablePause, playSong.DisableFail); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.CommandType == Command.CommandTypes.ReturnToMenu) { if (SyncHandler.Instance != null) { ScreenOverlay.Instance.Clear(); } if ((Self as Player).PlayState == Player.PlayStates.InGame) { PlayerUtils.ReturnToMenu(); } } else if (command.CommandType == Command.CommandTypes.ScreenOverlay_ShowPng) { ScreenOverlay.Instance.ShowPng(); } else if (command.CommandType == Command.CommandTypes.DelayTest_Finish) { UnityMainThreadDispatcher.Instance().Enqueue(() => { ScreenOverlay.Instance.Clear(); SyncHandler.Instance.Resume(); SyncHandler.Destroy(); }); } } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloaded; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); //Notify any listeners of the client that a song has been loaded LoadedSong?.Invoke(loadedLevel); }; if (OstHelper.IsOst(loadSong.LevelId)) { SongLoaded?.Invoke(SongUtils.masterLevelList.First(x => x.levelID == loadSong.LevelId) as BeatmapLevelSO); } else { if (SongUtils.masterLevelList.Any(x => x.levelID == loadSong.LevelId)) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { Action <string, bool> loadSongAction = (hash, succeeded) => { if (succeeded) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { (Self as Player).DownloadState = Player.DownloadStates.DownloadError; var playerUpdated = new Event(); playerUpdated.Type = Event.EventType.PlayerUpdated; playerUpdated.ChangedObject = Self; Send(new Packet(playerUpdated)); } }; (Self as Player).DownloadState = Player.DownloadStates.Downloading; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); SongDownloader.DownloadSong(loadSong.LevelId, songDownloaded: loadSongAction, downloadProgressChanged: (hash, progress) => Logger.Debug($"DOWNLOAD PROGRESS ({hash}): {progress}"), customHostUrl: loadSong.CustomHostUrl); } } } else if (packet.Type == PacketType.File) { File file = packet.SpecificPacket as File; if (file.Intent == File.Intentions.SetPngToShowWhenTriggered) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); } else if (file.Intent == File.Intentions.ShowPngImmediately) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); ScreenOverlay.Instance.ShowPng(); } Send(packet.From, new Packet(new Acknowledgement() { PacketId = packet.Id, Type = Acknowledgement.AcknowledgementType.FileDownloaded })); } }
protected override void Client_PacketRecieved(Packet packet) { base.Client_PacketRecieved(packet); if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = SongUtils.masterLevelList.First(x => x.levelID == playSong.Beatmap.LevelId); var desiredCharacteristic = desiredLevel.previewDifficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic.serializedName == playSong.Beatmap.Characteristic.SerializedName).beatmapCharacteristic ?? desiredLevel.previewDifficultyBeatmapSets.First().beatmapCharacteristic; var desiredDifficulty = (BeatmapDifficulty)playSong.Beatmap.Difficulty; var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First().playerData; var playerSettings = playerData.playerSpecificSettings; //Override defaults if we have forced options enabled if (playSong.PlayerSettings.Options != PlayerOptions.None) { playerSettings = new PlayerSpecificSettings(); playerSettings.leftHanded = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.LeftHanded); playerSettings.staticLights = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.StaticLights); playerSettings.noTextsAndHuds = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.NoHud); playerSettings.advancedHud = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.AdvancedHud); playerSettings.reduceDebris = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.ReduceDebris); } var gameplayModifiers = new GameplayModifiers(); gameplayModifiers.batteryEnergy = playSong.GameplayModifiers.Options.HasFlag(GameOptions.BatteryEnergy); gameplayModifiers.disappearingArrows = playSong.GameplayModifiers.Options.HasFlag(GameOptions.DisappearingArrows); gameplayModifiers.failOnSaberClash = playSong.GameplayModifiers.Options.HasFlag(GameOptions.FailOnClash); gameplayModifiers.fastNotes = playSong.GameplayModifiers.Options.HasFlag(GameOptions.FastNotes); gameplayModifiers.ghostNotes = playSong.GameplayModifiers.Options.HasFlag(GameOptions.GhostNotes); gameplayModifiers.instaFail = playSong.GameplayModifiers.Options.HasFlag(GameOptions.InstaFail); gameplayModifiers.noBombs = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoBombs); gameplayModifiers.noFail = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoFail); gameplayModifiers.noObstacles = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoObstacles); gameplayModifiers.noArrows = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoArrows); if (playSong.GameplayModifiers.Options.HasFlag(GameOptions.SlowSong)) { gameplayModifiers.songSpeed = GameplayModifiers.SongSpeed.Slower; } if (playSong.GameplayModifiers.Options.HasFlag(GameOptions.FastSong)) { gameplayModifiers.songSpeed = GameplayModifiers.SongSpeed.Faster; } var colorScheme = playerData.colorSchemesSettings.overrideDefaultColors ? playerData.colorSchemesSettings.GetSelectedColorScheme() : null; PlaySong?.Invoke(desiredLevel, desiredCharacteristic, desiredDifficulty, gameplayModifiers, playerSettings, playerData.overrideEnvironmentSettings, colorScheme, playSong.FloatingScoreboard, playSong.StreamSync, playSong.DisablePause, playSong.DisableFail); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.CommandType == Command.CommandTypes.ReturnToMenu) { if (SyncHandler.Instance != null) { ScreenOverlay.Instance.Clear(); } if ((Self as Player).PlayState == Player.PlayStates.InGame) { PlayerUtils.ReturnToMenu(); } } else if (command.CommandType == Command.CommandTypes.ScreenOverlay_ShowPng) { ScreenOverlay.Instance.ShowPng(); } else if (command.CommandType == Command.CommandTypes.DelayTest_Finish) { UnityMainThreadDispatcher.Instance().Enqueue(() => { ScreenOverlay.Instance.Clear(); SyncHandler.Instance.Resume(); SyncHandler.Destroy(); }); } } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloaded; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); //Notify any listeners of the client that a song has been loaded LoadedSong?.Invoke(loadedLevel); Logger.Debug($"SENT DOWNLOADED SIGNAL {(playerUpdate.ChangedObject as Player).DownloadState}"); }; if (OstHelper.IsOst(loadSong.LevelId)) { SongLoaded?.Invoke(SongUtils.masterLevelList.First(x => x.levelID == loadSong.LevelId) as BeatmapLevelSO); } else { if (SongUtils.masterLevelList.Any(x => x.levelID == loadSong.LevelId)) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { Action <bool> loadSongAction = (succeeded) => { if (succeeded) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { (Self as Player).DownloadState = Player.DownloadStates.DownloadError; var playerUpdated = new Event(); playerUpdated.Type = Event.EventType.PlayerUpdated; playerUpdated.ChangedObject = Self; Send(new Packet(playerUpdated)); Logger.Debug($"SENT DOWNLOADED SIGNAL {(playerUpdated.ChangedObject as Player).DownloadState}"); } }; (Self as Player).DownloadState = Player.DownloadStates.Downloading; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); Logger.Debug($"SENT DOWNLOAD SIGNAL {(playerUpdate.ChangedObject as Player).DownloadState}"); SongDownloader.DownloadSong(loadSong.LevelId, songDownloaded: loadSongAction, downloadProgressChanged: (progress) => Logger.Debug($"DOWNLOAD PROGRESS: {progress}")); } } } else if (packet.Type == PacketType.File) { File file = packet.SpecificPacket as File; if (file.Intention == File.Intentions.SetPngToShowWhenTriggered) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); } else if (file.Intention == File.Intentions.ShowPngImmediately) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); ScreenOverlay.Instance.ShowPng(); } Send(packet.From, new Packet(new Acknowledgement() { PacketId = packet.Id, Type = Acknowledgement.AcknowledgementType.FileDownloaded })); } }