Skip to content

Commit b969709

Browse files
committed
fix hostpick and animations
1 parent 9f6e712 commit b969709

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

MultiplayerExtensions/Environments/LobbyAvatarPlaceLighting.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public virtual void SetColor(Color color, bool immediate)
4444

4545
public virtual Color GetColor()
4646
{
47-
return lights[0].color;
47+
if (lights.Count > 0)
48+
return lights[0].color;
49+
return Color.black;
4850
}
4951

5052
public virtual bool IsColorVeryCloseToColor(Color color0, Color color1)

MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using HarmonyLib;
22
using HMUI;
33
using System;
4-
using System.Collections;
54
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.Linq;
87
using UnityEngine;
8+
using UnityEngine.Timeline;
99
using UnityEngine.Playables;
1010

1111
namespace MultiplayerExtensions.HarmonyPatches
@@ -56,21 +56,31 @@ static void Prefix(ref IReadOnlyList<MultiplayerPlayerResultsData> resultsData)
5656
[HarmonyPatch(typeof(MultiplayerIntroAnimationController), nameof(MultiplayerIntroAnimationController.PlayIntroAnimation), MethodType.Normal)]
5757
internal class IntroAnimationPatch
5858
{
59-
private static PlayableDirector lastDirector;
59+
private static PlayableDirector lastDirector = null!;
6060
internal static int targetIterations = 0;
6161

62-
static void Prefix(ref PlayableDirector ____introPlayableDirector, ref MultiplayerPlayersManager ____multiplayerPlayersManager)
62+
static void Prefix(MultiplayerIntroAnimationController __instance, ref bool ____bindingFinished, ref PlayableDirector ____introPlayableDirector, ref MultiplayerPlayersManager ____multiplayerPlayersManager)
6363
{
6464
lastDirector = ____introPlayableDirector;
65+
6566
if (targetIterations == 0)
6667
{
67-
targetIterations = (int)Math.Floor(____multiplayerPlayersManager.allActiveAtGameStartPlayers.Count / 4f) + 1;
68+
targetIterations = (int)Math.Floor((____multiplayerPlayersManager.allActiveAtGameStartPlayers.Count - 1) / 4f) + 1;
6869
}
69-
else
70+
if (targetIterations != 1)
7071
{
71-
____introPlayableDirector = new PlayableDirector();
72+
GameObject newPlayableGameObject = new GameObject();
73+
____introPlayableDirector = newPlayableGameObject.AddComponent<PlayableDirector>();
7274
____introPlayableDirector.playableAsset = lastDirector.playableAsset;
7375
}
76+
77+
TimelineAsset mutedTimeline = (TimelineAsset)____introPlayableDirector.playableAsset;
78+
foreach (TrackAsset track in mutedTimeline.GetOutputTracks())
79+
{
80+
track.muted = track is AudioTrack && targetIterations != 1;
81+
}
82+
83+
____bindingFinished = false;
7484
}
7585

7686
static void Postfix(MultiplayerIntroAnimationController __instance, float maxDesiredIntroAnimationDuration, Action onCompleted, ref PlayableDirector ____introPlayableDirector)
@@ -91,7 +101,18 @@ static void Postfix(ref IReadOnlyList<IConnectedPlayer> __result)
91101
string methodName = stackTrace.GetFrame(2).GetMethod().Name;
92102
if (methodName == "BindTimeline")
93103
{
94-
__result = __result.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList();
104+
if (__result.Any(player => player.isMe))
105+
{
106+
List<IConnectedPlayer> nonLocalPlayers = __result.Where(player => !player.isMe).ToList();
107+
IConnectedPlayer localPlayer = __result.First(player => player.isMe);
108+
__result = nonLocalPlayers.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList();
109+
if (IntroAnimationPatch.targetIterations == 1)
110+
__result = __result.AddItem(localPlayer).ToList();
111+
}
112+
else
113+
{
114+
__result = __result.Skip((IntroAnimationPatch.targetIterations - 1) * 4).Take(4).ToList();
115+
}
95116
}
96117
else if (methodName == "BindOutroTimeline")
97118
{

MultiplayerExtensions/MultiplayerExtensions.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Library</OutputType>
55
<AppDesignerFolder>Properties</AppDesignerFolder>
66
<AssemblyName>MultiplayerExtensions</AssemblyName>
7-
<AssemblyVersion>0.5.3</AssemblyVersion>
7+
<AssemblyVersion>0.5.4</AssemblyVersion>
88
<TargetFramework>net472</TargetFramework>
99
<DebugSymbols>true</DebugSymbols>
1010
<DebugType>portable</DebugType>
@@ -116,6 +116,10 @@
116116
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
117117
<Private>False</Private>
118118
</Reference>
119+
<Reference Include="Unity.Timeline">
120+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Timeline.dll</HintPath>
121+
<Private>False</Private>
122+
</Reference>
119123
<Reference Include="UnityEngine">
120124
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
121125
<Private>False</Private>

MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using System.Threading.Tasks;
910

1011
namespace MultiplayerExtensions.OverrideClasses
1112
{
@@ -100,9 +101,13 @@ private void OnPlayerStateChanged(IConnectedPlayer player)
100101
IEnumerable<ILobbyPlayerDataModel> validDataModels = _lobbyPlayersDataModel.playersData.Values.Where(data => data.beatmapLevel != null);
101102
ILobbyPlayerDataModel chosenPlayerDataModel = validDataModels.ElementAt(new Random().Next(0, validDataModels.Count()));
102103
localPlayerDataModel.beatmapLevel = chosenPlayerDataModel.beatmapLevel;
103-
localPlayerDataModel.beatmapCharacteristic = chosenPlayerDataModel.beatmapCharacteristic;
104104
localPlayerDataModel.beatmapDifficulty = chosenPlayerDataModel.beatmapDifficulty;
105+
localPlayerDataModel.beatmapCharacteristic = chosenPlayerDataModel.beatmapCharacteristic;
105106
localPlayerDataModel.gameplayModifiers = chosenPlayerDataModel.gameplayModifiers;
107+
_menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(chosenPlayerDataModel.beatmapLevel.levelID, chosenPlayerDataModel.beatmapCharacteristic.serializedName, chosenPlayerDataModel.beatmapDifficulty));
108+
_menuRpcManager.SelectGameplayModifiers(chosenPlayerDataModel.gameplayModifiers);
109+
if (_lobbyPlayersDataModel is LobbyPlayersDataModel playersDataModel)
110+
playersDataModel.NotifyModelChange(_lobbyPlayersDataModel.localUserId);
106111
}
107112

108113
base.StartGame();

MultiplayerExtensions/OverrideClasses/PlayerTableCellStub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private async void GetLevelEntitlement(IConnectedPlayer player)
102102

103103
private void SetLevelEntitlement(IConnectedPlayer player, EntitlementsStatus status)
104104
{
105-
Plugin.Log?.Debug($"{player.userId} has entitlement {status.ToString()}");
105+
//Plugin.Log?.Debug($"{player.userId} has entitlement {status.ToString()}");
106106
Color backgroundColor = status switch
107107
{
108108
EntitlementsStatus.Ok => green,

MultiplayerExtensions/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "MultiplayerExtensions",
44
"name": "MultiplayerExtensions",
55
"author": "Zingabopp and Goobwabber",
6-
"version": "0.5.3",
6+
"version": "0.5.4",
77
"description": "Expands the functionality of Beat Saber Multiplayer.",
88
"gameVersion": "1.16.1",
99
"dependsOn": {

0 commit comments

Comments
 (0)