Skip to content

Commit

Permalink
Fix Crashes and shit I hope
Browse files Browse the repository at this point in the history
  • Loading branch information
silentbaws committed Jun 17, 2020
1 parent 2081aa6 commit 35c355b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion XLMultiplayer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct CustomUI {
public Func<bool> isEnabled;
public Action OnGUI;
}


// TODO: Redo this UI in unity
public class OldUIBox : MonoBehaviour {
public static OldUIBox Instance { get; private set; } = null;

Expand Down
11 changes: 6 additions & 5 deletions XLMultiplayer/MultiplayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dictionary<string, AudioClip>>();
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<AudioSource>();
if (newSource != null) MultiplayerUtils.audioPlayerNames.Add(newSource.name);
Expand Down Expand Up @@ -524,6 +521,8 @@ public void Update() {
ProcessMessageQueue();

// Lerp frames using frame buffer
List<MultiplayerRemotePlayerController> controllerToRemove = new List<MultiplayerRemotePlayerController>();

foreach (MultiplayerRemotePlayerController controller in this.remoteControllers) {
if (controller != null) {
controller.ApplyTextures();
Expand All @@ -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() {
Expand Down
17 changes: 8 additions & 9 deletions XLMultiplayer/MultiplayerRemotePlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,14 @@ public void UnpackSounds(byte[] soundBytes) {
List<List<AudioCutoffEvent>> newCutoffEvents = new List<List<AudioCutoffEvent>>();

float earliestSoundTime = float.MaxValue;

for (int i = 0; i < MultiplayerUtils.audioPlayerNames.Count; i++) {
newOneShots.Add(new List<AudioOneShotEvent>());
newClipEvents.Add(new List<AudioClipEvent>());
newVolumeEvents.Add(new List<AudioVolumeEvent>());
newPitchEvents.Add(new List<AudioPitchEvent>());
newCutoffEvents.Add(new List<AudioCutoffEvent>());

int oneShots = BitConverter.ToInt32(soundBytes, readBytes);
readBytes += 4;
for (int j = 0; j < oneShots; j++) {
Expand All @@ -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++) {
Expand All @@ -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++) {
Expand All @@ -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++) {
Expand All @@ -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<AudioClipEvent>());
newSoundBufferObject.audioOneShots.Add(new List<AudioOneShotEvent>());
newSoundBufferObject.audioCutoffEvents.Add(new List<AudioCutoffEvent>());
newSoundBufferObject.audioPitchEvents.Add(new List<AudioPitchEvent>());
newSoundBufferObject.audioVolumeEvents.Add(new List<AudioVolumeEvent>());

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);
Expand Down

0 comments on commit 35c355b

Please sign in to comment.