diff --git a/MultiplayerExtensions/Environments/LobbyAvatarPlaceLighting.cs b/MultiplayerExtensions/Environments/LobbyAvatarPlaceLighting.cs index b86add5..08b6364 100644 --- a/MultiplayerExtensions/Environments/LobbyAvatarPlaceLighting.cs +++ b/MultiplayerExtensions/Environments/LobbyAvatarPlaceLighting.cs @@ -44,7 +44,9 @@ public virtual void SetColor(Color color, bool immediate) public virtual Color GetColor() { - return lights[0].color; + if (lights.Count > 0) + return lights[0].color; + return Color.black; } public virtual bool IsColorVeryCloseToColor(Color color0, Color color1) diff --git a/MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs b/MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs index 35ee749..5d6a613 100644 --- a/MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs +++ b/MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs @@ -1,11 +1,11 @@ using HarmonyLib; using HMUI; using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using UnityEngine; +using UnityEngine.Timeline; using UnityEngine.Playables; namespace MultiplayerExtensions.HarmonyPatches @@ -56,21 +56,31 @@ static void Prefix(ref IReadOnlyList resultsData) [HarmonyPatch(typeof(MultiplayerIntroAnimationController), nameof(MultiplayerIntroAnimationController.PlayIntroAnimation), MethodType.Normal)] internal class IntroAnimationPatch { - private static PlayableDirector lastDirector; + private static PlayableDirector lastDirector = null!; internal static int targetIterations = 0; - static void Prefix(ref PlayableDirector ____introPlayableDirector, ref MultiplayerPlayersManager ____multiplayerPlayersManager) + static void Prefix(MultiplayerIntroAnimationController __instance, ref bool ____bindingFinished, ref PlayableDirector ____introPlayableDirector, ref MultiplayerPlayersManager ____multiplayerPlayersManager) { lastDirector = ____introPlayableDirector; + if (targetIterations == 0) { - targetIterations = (int)Math.Floor(____multiplayerPlayersManager.allActiveAtGameStartPlayers.Count / 4f) + 1; + targetIterations = (int)Math.Floor((____multiplayerPlayersManager.allActiveAtGameStartPlayers.Count - 1) / 4f) + 1; } - else + if (targetIterations != 1) { - ____introPlayableDirector = new PlayableDirector(); + GameObject newPlayableGameObject = new GameObject(); + ____introPlayableDirector = newPlayableGameObject.AddComponent(); ____introPlayableDirector.playableAsset = lastDirector.playableAsset; } + + TimelineAsset mutedTimeline = (TimelineAsset)____introPlayableDirector.playableAsset; + foreach (TrackAsset track in mutedTimeline.GetOutputTracks()) + { + track.muted = track is AudioTrack && targetIterations != 1; + } + + ____bindingFinished = false; } static void Postfix(MultiplayerIntroAnimationController __instance, float maxDesiredIntroAnimationDuration, Action onCompleted, ref PlayableDirector ____introPlayableDirector) @@ -91,7 +101,18 @@ static void Postfix(ref IReadOnlyList __result) string methodName = stackTrace.GetFrame(2).GetMethod().Name; if (methodName == "BindTimeline") { - __result = __result.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList(); + if (__result.Any(player => player.isMe)) + { + List nonLocalPlayers = __result.Where(player => !player.isMe).ToList(); + IConnectedPlayer localPlayer = __result.First(player => player.isMe); + __result = nonLocalPlayers.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList(); + if (IntroAnimationPatch.targetIterations == 1) + __result = __result.AddItem(localPlayer).ToList(); + } + else + { + __result = __result.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList(); + } } else if (methodName == "BindOutroTimeline") { diff --git a/MultiplayerExtensions/MultiplayerExtensions.csproj b/MultiplayerExtensions/MultiplayerExtensions.csproj index 6b258a1..3124ee3 100644 --- a/MultiplayerExtensions/MultiplayerExtensions.csproj +++ b/MultiplayerExtensions/MultiplayerExtensions.csproj @@ -4,7 +4,7 @@ Library Properties MultiplayerExtensions - 0.5.3 + 0.5.4 net472 true portable @@ -116,6 +116,10 @@ $(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll False + + $(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Timeline.dll + False + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll False diff --git a/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs b/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs index 9ed6598..ce2ee5e 100644 --- a/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs +++ b/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace MultiplayerExtensions.OverrideClasses { @@ -100,9 +101,13 @@ private void OnPlayerStateChanged(IConnectedPlayer player) IEnumerable validDataModels = _lobbyPlayersDataModel.playersData.Values.Where(data => data.beatmapLevel != null); ILobbyPlayerDataModel chosenPlayerDataModel = validDataModels.ElementAt(new Random().Next(0, validDataModels.Count())); localPlayerDataModel.beatmapLevel = chosenPlayerDataModel.beatmapLevel; - localPlayerDataModel.beatmapCharacteristic = chosenPlayerDataModel.beatmapCharacteristic; localPlayerDataModel.beatmapDifficulty = chosenPlayerDataModel.beatmapDifficulty; + localPlayerDataModel.beatmapCharacteristic = chosenPlayerDataModel.beatmapCharacteristic; localPlayerDataModel.gameplayModifiers = chosenPlayerDataModel.gameplayModifiers; + _menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(chosenPlayerDataModel.beatmapLevel.levelID, chosenPlayerDataModel.beatmapCharacteristic.serializedName, chosenPlayerDataModel.beatmapDifficulty)); + _menuRpcManager.SelectGameplayModifiers(chosenPlayerDataModel.gameplayModifiers); + if (_lobbyPlayersDataModel is LobbyPlayersDataModel playersDataModel) + playersDataModel.NotifyModelChange(_lobbyPlayersDataModel.localUserId); } base.StartGame(); diff --git a/MultiplayerExtensions/OverrideClasses/PlayerTableCellStub.cs b/MultiplayerExtensions/OverrideClasses/PlayerTableCellStub.cs index 0b5c10e..ba65832 100644 --- a/MultiplayerExtensions/OverrideClasses/PlayerTableCellStub.cs +++ b/MultiplayerExtensions/OverrideClasses/PlayerTableCellStub.cs @@ -102,7 +102,7 @@ private async void GetLevelEntitlement(IConnectedPlayer player) private void SetLevelEntitlement(IConnectedPlayer player, EntitlementsStatus status) { - Plugin.Log?.Debug($"{player.userId} has entitlement {status.ToString()}"); + //Plugin.Log?.Debug($"{player.userId} has entitlement {status.ToString()}"); Color backgroundColor = status switch { EntitlementsStatus.Ok => green, diff --git a/MultiplayerExtensions/manifest.json b/MultiplayerExtensions/manifest.json index aa71b73..1e53dfd 100644 --- a/MultiplayerExtensions/manifest.json +++ b/MultiplayerExtensions/manifest.json @@ -3,7 +3,7 @@ "id": "MultiplayerExtensions", "name": "MultiplayerExtensions", "author": "Zingabopp and Goobwabber", - "version": "0.5.3", + "version": "0.5.4", "description": "Expands the functionality of Beat Saber Multiplayer.", "gameVersion": "1.16.1", "dependsOn": {