public void SendPreviewBeatmapPacket(PreviewBeatmapStub preview, string characteristic, BeatmapDifficulty difficulty) { PreviewBeatmapPacket beatmapPacket = new PreviewBeatmapPacket().FromPreview(preview, characteristic, difficulty); Plugin.Log?.Info($"Sending 'PreviewBeatmapPacket' with {preview.levelID}"); _sessionManager.Send(beatmapPacket); }
public new void SetLocalPlayerBeatmapLevel(string levelId, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO characteristic) { string?hash = Utilities.Utils.LevelIdToHash(levelId); if (hash != null) { Plugin.Log?.Debug($"Local user selected song '{hash}'."); PreviewBeatmapManager.GetPopulatedPreview(levelId).ContinueWith(r => { PreviewBeatmapStub preview = r.Result; localBeatmap = new PreviewBeatmapPacket().FromPreview(preview, characteristic.serializedName, beatmapDifficulty); if (base.localUserId == base.hostUserId) { _sessionManager.SetLocalPlayerState("bmlocal", preview.isDownloaded); _sessionManager.SetLocalPlayerState("bmcloud", preview.isDownloadable); } HMMainThreadDispatcher.instance.Enqueue(() => { _packetManager.Send(localBeatmap); _menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(levelId, characteristic.serializedName, beatmapDifficulty)); base.SetPlayerBeatmapLevel(base.localUserId, preview, beatmapDifficulty, characteristic); }); }); return; } base.SetLocalPlayerBeatmapLevel(levelId, beatmapDifficulty, characteristic); }
public async new void SetLocalPlayerBeatmapLevel(string levelId, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO characteristic) { string?hash = Utilities.Utils.LevelIdToHash(levelId); if (hash != null) { Plugin.Log?.Debug($"Local user selected song '{hash}'."); PreviewBeatmapStub?preview = null; if (_playersData.Values.Any(playerData => playerData.beatmapLevel?.levelID == levelId)) { IPreviewBeatmapLevel playerPreview = _playersData.Values.Where(playerData => playerData.beatmapLevel?.levelID == levelId).First().beatmapLevel; if (playerPreview is PreviewBeatmapStub playerPreviewStub) { preview = playerPreviewStub; } } IPreviewBeatmapLevel localPreview = SongCore.Loader.GetLevelById(levelId); if (localPreview != null) { preview = new PreviewBeatmapStub(hash, localPreview); } if (preview == null) { try { Beatmap bm = await Plugin.BeatSaver.Hash(hash); preview = new PreviewBeatmapStub(bm); } catch { return; } } if (base.localUserId == base.hostUserId) { _sessionManager.SetLocalPlayerState("beatmap_downloaded", preview.isDownloaded); } HMMainThreadDispatcher.instance.Enqueue(() => base.SetPlayerBeatmapLevel(base.localUserId, preview, beatmapDifficulty, characteristic)); _packetManager.Send(await PreviewBeatmapPacket.FromPreview(preview, characteristic.serializedName, beatmapDifficulty)); if (!_sessionManager.connectedPlayers.All(x => x.HasState("modded"))) { _menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(levelId, characteristic.serializedName, beatmapDifficulty)); } } else { base.SetLocalPlayerBeatmapLevel(levelId, beatmapDifficulty, characteristic); } }
public void HandlePreviewBeatmapPacket(PreviewBeatmapPacket packet, IConnectedPlayer player) { string?hash = Utilities.Utils.LevelIdToHash(packet.levelId); if (hash != null) { Plugin.Log?.Debug($"'{player.userId}' selected song '{hash}'."); BeatmapCharacteristicSO characteristic = _beatmapCharacteristicCollection.GetBeatmapCharacteristicBySerializedName(packet.characteristic); PreviewBeatmapStub preview = new PreviewBeatmapStub(packet); HMMainThreadDispatcher.instance.Enqueue(() => base.SetPlayerBeatmapLevel(player.userId, preview, packet.difficulty, characteristic)); } }
/// <summary> /// Triggered when a player joins and sends the request. /// If the newly joined player is not modded or the selected song isn't custom, sends back a vanilla packet. /// Otherwise, sends a <see cref="MultiplayerExtensions.Beatmaps.PreviewBeatmapPacket"/> /// </summary> public async override void HandleMenuRpcManagerGetSelectedBeatmap(string userId) { ILobbyPlayerDataModel lobbyPlayerDataModel = this.GetLobbyPlayerDataModel(this.localUserId); if (lobbyPlayerDataModel != null && MPState.CurrentGameType != MultiplayerGameType.QuickPlay && _multiplayerSessionManager.GetPlayerByUserId(userId).HasState("modded") && lobbyPlayerDataModel?.beatmapLevel is PreviewBeatmapStub preview) { _packetManager.Send(await PreviewBeatmapPacket.FromPreview(preview, lobbyPlayerDataModel.beatmapCharacteristic.serializedName, lobbyPlayerDataModel.beatmapDifficulty)); } else if (lobbyPlayerDataModel != null && lobbyPlayerDataModel.beatmapLevel != null) { this._menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(lobbyPlayerDataModel.beatmapLevel.levelID, lobbyPlayerDataModel.beatmapCharacteristic.serializedName, lobbyPlayerDataModel.beatmapDifficulty)); } }
public void HandlePreviewBeatmapPacket(PreviewBeatmapPacket packet, ExtendedPlayer player) { if (Utilities.Utils.LevelIdToHash(packet.levelId) != null) { PreviewBeatmapStub preview = PreviewBeatmapManager.GetPreview(packet); if (!preview.isDownloaded) { BeatmapCharacteristicSO?characteristic = _beatmapCharacteristicCollection.GetBeatmapCharacteristicBySerializedName(packet.characteristic); HMMainThreadDispatcher.instance.Enqueue(() => { base.SetPlayerBeatmapLevel(player.userId, preview, packet.difficulty, characteristic); }); } } }
/// <summary> /// Triggered when the local player selects a song. /// </summary> public async new void SetLocalPlayerBeatmapLevel(string levelId, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO characteristic) { string?hash = Utilities.Utils.LevelIdToHash(levelId); Plugin.Log?.Debug($"Local user selected song '{hash ?? levelId}'."); if (hash != null) { if (_playersData.Values.Any(playerData => playerData.beatmapLevel?.levelID == levelId)) { PreviewBeatmapStub?preview = GetExistingPreview(levelId); HMMainThreadDispatcher.instance.Enqueue(() => base.SetPlayerBeatmapLevel(base.localUserId, preview, beatmapDifficulty, characteristic)); _menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(levelId, characteristic.serializedName, beatmapDifficulty)); } else { PreviewBeatmapStub? preview = null; IPreviewBeatmapLevel localPreview = SongCore.Loader.GetLevelById(levelId); if (localPreview != null) { preview = new PreviewBeatmapStub(hash, localPreview); } if (preview == null) { preview = await FetchBeatSaverPreview(levelId, hash); } HMMainThreadDispatcher.instance.Enqueue(() => base.SetPlayerBeatmapLevel(base.localUserId, preview, beatmapDifficulty, characteristic)); _packetManager.Send(await PreviewBeatmapPacket.FromPreview(preview, characteristic.serializedName, beatmapDifficulty)); if (!_multiplayerSessionManager.connectedPlayers.All(x => x.HasState("modded"))) { _menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(levelId, characteristic.serializedName, beatmapDifficulty)); } } } else { base.SetLocalPlayerBeatmapLevel(levelId, beatmapDifficulty, characteristic); } }