11using HarmonyLib ;
22using HMUI ;
33using System ;
4- using System . Collections ;
54using System . Collections . Generic ;
65using System . Diagnostics ;
76using System . Linq ;
87using UnityEngine ;
8+ using UnityEngine . Timeline ;
99using UnityEngine . Playables ;
1010
1111namespace 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 {
0 commit comments