diff --git a/XLMultiplayer/Main.cs b/XLMultiplayer/Main.cs index 7a3c457..adeeef3 100644 --- a/XLMultiplayer/Main.cs +++ b/XLMultiplayer/Main.cs @@ -37,7 +37,8 @@ struct CustomUI { public Func isEnabled; public Action OnGUI; } - + + // TODO: Redo this UI in unity public class OldUIBox : MonoBehaviour { public static OldUIBox Instance { get; private set; } = null; diff --git a/XLMultiplayer/MultiplayerController.cs b/XLMultiplayer/MultiplayerController.cs index 490dff7..35ca457 100644 --- a/XLMultiplayer/MultiplayerController.cs +++ b/XLMultiplayer/MultiplayerController.cs @@ -143,13 +143,10 @@ public void Start() { Main.oldBox.AddCustom(() => isConnected, PlayerListOnGUI); Main.oldBox.AddCustom(() => isConnected, NetworkStatsOnGUI); - var clipDict = Traverse.Create(SoundManager.Instance).Field("clipForName").GetValue>(); MultiplayerUtils.InitializeClipToArrayByteDict(clipDict); - foreach (var KVP in clipDict) { - UnityModManagerNet.UnityModManager.Logger.Log("Clip key " + MultiplayerUtils.GetArrayByteFromClipName(KVP.Key)); - } + MultiplayerUtils.audioPlayerNames.Clear(); foreach (ReplayAudioEventPlayer audioPlayer in ReplayEditorController.Instance.playbackController.AudioEventPlayers) { AudioSource newSource = Traverse.Create(audioPlayer).Property("audioSource").GetValue(); if (newSource != null) MultiplayerUtils.audioPlayerNames.Add(newSource.name); @@ -524,6 +521,8 @@ public void Update() { ProcessMessageQueue(); // Lerp frames using frame buffer + List controllerToRemove = new List(); + foreach (MultiplayerRemotePlayerController controller in this.remoteControllers) { if (controller != null) { controller.ApplyTextures(); @@ -542,12 +541,14 @@ public void Update() { } if (controller.playerID == 255 && controller.replayAnimationFrames.Last(obj => obj.realFrameTime != -1f).realFrameTime < ReplayRecorder.Instance.RecordedFrames.First().time) { - RemovePlayer(controller); + controllerToRemove.Add(controller); } controller.LerpNextFrame(GameManagement.GameStateMachine.Instance.CurrentState.GetType() == typeof(GameManagement.ReplayState)); } } + foreach(MultiplayerRemotePlayerController player in controllerToRemove) + RemovePlayer(player); } private void ProcessMessageQueue() { diff --git a/XLMultiplayer/MultiplayerRemotePlayerController.cs b/XLMultiplayer/MultiplayerRemotePlayerController.cs index 3560f7f..4e96504 100644 --- a/XLMultiplayer/MultiplayerRemotePlayerController.cs +++ b/XLMultiplayer/MultiplayerRemotePlayerController.cs @@ -391,14 +391,14 @@ public void UnpackSounds(byte[] soundBytes) { List> newCutoffEvents = new List>(); float earliestSoundTime = float.MaxValue; - + for (int i = 0; i < MultiplayerUtils.audioPlayerNames.Count; i++) { newOneShots.Add(new List()); newClipEvents.Add(new List()); newVolumeEvents.Add(new List()); newPitchEvents.Add(new List()); newCutoffEvents.Add(new List()); - + int oneShots = BitConverter.ToInt32(soundBytes, readBytes); readBytes += 4; for (int j = 0; j < oneShots; j++) { @@ -424,7 +424,7 @@ public void UnpackSounds(byte[] soundBytes) { readBytes += 6; } - + int volumeEvents = BitConverter.ToInt32(soundBytes, readBytes); readBytes += 4; for (int j = 0; j < volumeEvents; j++) { @@ -436,7 +436,7 @@ public void UnpackSounds(byte[] soundBytes) { readBytes += 8; } - + int pitchEvents = BitConverter.ToInt32(soundBytes, readBytes); readBytes += 4; for (int j = 0; j < pitchEvents; j++) { @@ -448,7 +448,7 @@ public void UnpackSounds(byte[] soundBytes) { readBytes += 8; } - + int cutoffEvents = BitConverter.ToInt32(soundBytes, readBytes); readBytes += 4; for ( int j = 0; j < cutoffEvents; j++) { @@ -464,21 +464,20 @@ public void UnpackSounds(byte[] soundBytes) { MultiplayerSoundBufferObject newSoundBufferObject = new MultiplayerSoundBufferObject(); soundQueue.Add(newSoundBufferObject); - + for (int i = 0; i < MultiplayerUtils.audioPlayerNames.Count; i++) { newSoundBufferObject.audioClipEvents.Add(new List()); newSoundBufferObject.audioOneShots.Add(new List()); newSoundBufferObject.audioCutoffEvents.Add(new List()); newSoundBufferObject.audioPitchEvents.Add(new List()); newSoundBufferObject.audioVolumeEvents.Add(new List()); - + newSoundBufferObject.audioClipEvents[i] = newClipEvents[i]; newSoundBufferObject.audioOneShots[i] = newOneShots[i]; newSoundBufferObject.audioCutoffEvents[i] = newCutoffEvents[i]; newSoundBufferObject.audioPitchEvents[i] = newPitchEvents[i]; newSoundBufferObject.audioVolumeEvents[i] = newVolumeEvents[i]; - - + foreach (ReplayAudioEventPlayer audioPlayer in replayController.AudioEventPlayers) { if (audioPlayer.name.Equals(MultiplayerUtils.audioPlayerNames[i])) { if (audioPlayer.clipEvents != null) audioPlayer.clipEvents.RemoveEventsOlderThanExcept(this.replayAnimationFrames.First(f => f.realFrameTime != -1f).realFrameTime, 0);