Skip to content

Commit

Permalink
fix hostpick and animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Goobwabber committed Jun 6, 2021
1 parent 9f6e712 commit b969709
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 28 additions & 7 deletions MultiplayerExtensions/HarmonyPatches/EnvironmentPatches.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -56,21 +56,31 @@ static void Prefix(ref IReadOnlyList<MultiplayerPlayerResultsData> 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<PlayableDirector>();
____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)
Expand All @@ -91,7 +101,18 @@ static void Postfix(ref IReadOnlyList<IConnectedPlayer> __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<IConnectedPlayer> 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")
{
Expand Down
6 changes: 5 additions & 1 deletion MultiplayerExtensions/MultiplayerExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>MultiplayerExtensions</AssemblyName>
<AssemblyVersion>0.5.3</AssemblyVersion>
<AssemblyVersion>0.5.4</AssemblyVersion>
<TargetFramework>net472</TargetFramework>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
Expand Down Expand Up @@ -116,6 +116,10 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Unity.Timeline">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Timeline.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MultiplayerExtensions.OverrideClasses
{
Expand Down Expand Up @@ -100,9 +101,13 @@ private void OnPlayerStateChanged(IConnectedPlayer player)
IEnumerable<ILobbyPlayerDataModel> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion MultiplayerExtensions/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit b969709

Please sign in to comment.