-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoiceChat.cs
More file actions
62 lines (52 loc) · 1.4 KB
/
VoiceChat.cs
File metadata and controls
62 lines (52 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using Causality0.Core;
using LabApi.Events.Arguments.PlayerEvents;
using LabApi.Events.Handlers;
using UnityEngine;
using VoiceChat.Networking;
namespace Causality0.Event.PlayerEvent;
public sealed class VoiceChat
{
public void Enable()
{
PlayerEvents.SendingVoiceMessage += OnSendingVoice;
}
public void Disable()
{
PlayerEvents.SendingVoiceMessage -= OnSendingVoice;
}
private void OnSendingVoice(PlayerSendingVoiceMessageEventArgs ev)
{
if (!Timeline.IsRec || global::Causality0.Causality0.Instance?.Config?.RecordVoice != true)
{
return;
}
ref VoiceMessage m = ref ev.Message;
if (m.SpeakerNull || m.Speaker == null || m.Speaker.authManager?.DoNotTrack == true)
{
return;
}
if (!Timeline.Tracks.TryGetValue(m.Speaker.PlayerId, out ActorTrack t))
{
return;
}
byte[] src = m.Data;
int n = m.DataLength;
if (src == null || n <= 0)
{
return;
}
if (n > src.Length)
{
n = src.Length;
}
byte[] data = new byte[n];
Array.Copy(src, 0, data, 0, n);
float ts = Time.time - Timeline.RecordStartTime;
if (ts < 0f)
{
ts = 0f;
}
t.AudioFrames.Add(new AudioPacket(ts, (byte)m.Channel, data, n));
}
}