/// <summary> /// Gets recorded data and stores it in format Int16 /// </summary> /// <param name="buffer">buffer to fill with audio data recorded</param> /// <param name="bufferOffset">buffer start index</param> /// <param name="dataCount">amount of data to store</param> /// <param name="effectiveDataCount">effective amount of data stored</param> /// <returns>data info</returns> public override VoicePacketInfo GetMicData(byte[] buffer, int bufferOffset, int dataCount, out int effectiveDataCount) { effectiveDataCount = Mathf.Min(Mathf.Min(dataCount, buffer.Length - bufferOffset), MicDataAvailable * sizeof(short)); if ((effectiveDataCount & 1) == 1) { effectiveDataCount--; } if (effectiveDataCount <= 0) { return(VoicePacketInfo.InvalidPacket); } int l = effectiveDataCount + bufferOffset; for (int i = bufferOffset; i < l; i += sizeof(short)) { ByteManipulator.Write(buffer, i, (short)Mathf.LerpUnclamped(0, short.MaxValue, cyclicAudioBuffer[readIndex])); readIndex++; if (readIndex >= cyclicAudioBuffer.Length) { readIndex = 0; } } return(new VoicePacketInfo((ushort)clip.frequency, (byte)clip.channels, AudioDataTypeFlag.Int16)); }
private void EnemyDeath(Enemy enemy) { if (HostEnemySpawner.Instance.enemiesCount < HostEnemySpawner.MAX_NUM_ENEMIES) { if (enemy.Destroy) { byte[] d = ArrayPool <byte> .Get(sizeof(int)); ByteManipulator.Write(d, 0, enemy.NetworkId.NetworkId); Client.SendPacketToInGameUsers(d, 0, d.Length, PacketType.EnemyDeath, Steamworks.EP2PSend.k_EP2PSendReliable); ArrayPool <byte> .Recycle(d); enemy.Destroy = false; } enemy.randomSpawnTimer -= Time.deltaTime; if (enemy.randomSpawnTimer <= 0) { HostEnemySpawner.Instance.InstantiateEnemy(); enemy.randomSpawnTimer = UnityEngine.Random.Range(0f, 5.0f); enemy.Recycling = false; EnemyToRecycleToRemove.Add(enemy); } } }
/// <summary> /// Writes the value in the packet /// </summary> /// <param name="value">value to write</param> /// <param name="encoder">encoder to use</param> public void Write(string value, Encoding encoder) { int n = ByteManipulator.Write(Data, CurrentSeek, value, encoder); CurrentSeek += n; CurrentLength += n; }
public override VoicePacketInfo GetMicData(float[] buffer, int bufferOffset, int micDataCount, out int effectiveMicDataCount) { GetDataSingle = true; effectiveMicDataCount = Mathf.Min(buffer.Length - bufferOffset, DataRec.Length, micDataCount); ByteManipulator.Write <float>(DataRec, 0, buffer, bufferOffset, effectiveMicDataCount); return(Info); }
public void TestWriteArrayFloatRedLight4() { float[] first = new float[] { 0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f }; float[] second = new float[10]; ByteManipulator.Write(first, 0, second, 1, 9); Assert.That(second[9], Is.Not.EqualTo(0).Within(0.0001)); }
public void TestWriteArrayByteRedLight4() { byte[] first = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] second = new byte[10]; ByteManipulator.Write(first, 0, second, 1, 9); Assert.That(second[9], Is.Not.EqualTo(0)); }
public void SendChatMessage(string message) { int n = ByteManipulator.Write(inputData, 0, message, encoder); SteamMatchmaking.SendLobbyChatMsg(Client.Lobby.LobbyID, inputData, n); InputField.text = ""; }
public override VoicePacketInfo GetMicDataInt16(byte[] buffer, int bufferOffset, int micDataCount, out int effectiveMicDataCount) { GetDataInt16 = true; effectiveMicDataCount = Mathf.Min(buffer.Length - bufferOffset, DataRecInt16.Length, micDataCount); ByteManipulator.Write <byte>(DataRecInt16, 0, buffer, bufferOffset, effectiveMicDataCount); return(Info); }
/// <summary> /// Creates new instance by copying the given packet. MaxCapacity == gamePacketToCopy.Length /// </summary> /// <param name="toCopy">GamePacket to copy</param> public BytePacket(BytePacket toCopy) { int length = toCopy.Data.Length; Data = new byte[length]; ByteManipulator.Write <byte>(toCopy.Data, 0, Data, 0, length); CurrentLength = toCopy.CurrentLength; CurrentSeek = toCopy.CurrentSeek; }
public void TestStringReadRedLight() { string s = "dngsgnsiongDDDD@@#[ffa "; byte[] arr = new byte[Encoding.UTF8.GetByteCount(s) + sizeof(int)]; ByteManipulator.Write(arr, 0, s, encoder); int n; Assert.That(ByteManipulator.ReadString(arr, 0, encoder, out n), Is.Not.EqualTo("dngsgnsiongDDDD@@#[ffa")); }
public void TestCharsConversionsRedLight() { char[] s = "dngsgnsiongDDDD@@#[ffa ".ToCharArray(); char[] s2 = new char[s.Length]; byte[] arr = new byte[Encoding.UTF8.GetByteCount(s) + sizeof(int)]; ByteManipulator.Write(arr, 0, s, encoder); int n = ByteManipulator.ReadInt32(arr, 0); Assert.That(Encoding.UTF8.GetString(arr, sizeof(int), n), Is.Not.EqualTo("dngsgnsiongDDDD@@#[ffa")); }
public void SendShotCall() { byte[] d = ArrayPool <byte> .Get(sizeof(int)); ByteManipulator.Write(d, 0, gnOnject.NetworkId); Client.SendPacketToInGameUsers(d, 0, d.Length, PacketType.ShootCall, Client.MyID, Steamworks.EP2PSend.k_EP2PSendUnreliable, false); ArrayPool <byte> .Recycle(d); }
public override void SendToAll(BytePacket data, VoicePacketInfo info, List <ulong> receiversIds) { SentArray = new byte[data.Data.Length]; ByteManipulator.Write <byte>(data.Data, 0, SentArray, 0, SentArray.Length); DataSent = data.CurrentLength; for (int i = 0; i < receiversIds.Count; i++) { DataSentTo.Add(receiversIds[i]); } }
public void TestListBoolConversionRedLight() { List <byte> arr = new List <byte>(sizeof(bool)); for (int i = 0; i < sizeof(bool); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, false); Assert.That(BitConverter.ToBoolean(arr.ToArray(), 0), Is.Not.True); }
public void TestListSByteConversionRedLight() { List <byte> arr = new List <byte>(sizeof(sbyte)); for (int i = 0; i < sizeof(sbyte); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (sbyte)25); Assert.That((sbyte)arr[0], Is.Not.EqualTo(9)); }
public void TestListByteConversion() { List <byte> arr = new List <byte>(sizeof(byte)); for (int i = 0; i < sizeof(byte); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (byte)25); Assert.That(arr[0], Is.EqualTo(25)); }
public void TestListUlongConversionRedLight() { List <byte> arr = new List <byte>(sizeof(ulong)); for (int i = 0; i < sizeof(ulong); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (ulong)25000544); Assert.That(BitConverter.ToUInt64(arr.ToArray(), 0), Is.Not.EqualTo(9)); }
public void TestListSByteReadRedLight() { List <byte> arr = new List <byte>(sizeof(sbyte)); for (int i = 0; i < sizeof(sbyte); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (sbyte)-25); Assert.That(ByteManipulator.ReadSByte(arr, 0), Is.Not.EqualTo(9)); }
public void TestListUlongRead() { List <byte> arr = new List <byte>(sizeof(ulong)); for (int i = 0; i < sizeof(ulong); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (ulong)18446744073709551614); Assert.That(ByteManipulator.ReadUInt64(arr, 0), Is.EqualTo(18446744073709551614)); }
public void TestListUlongReadRedLight() { List <byte> arr = new List <byte>(sizeof(ulong)); for (int i = 0; i < sizeof(ulong); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (ulong)25000544); Assert.That(ByteManipulator.ReadUInt64(arr, 0), Is.Not.EqualTo(9)); }
public void TestListIntConversionRedLight() { List <byte> arr = new List <byte>(sizeof(int)); for (int i = 0; i < sizeof(int); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, -25); Assert.That(BitConverter.ToInt32(arr.ToArray(), 0), Is.Not.EqualTo(9)); }
public void TestListCharConversionRedLight() { List <byte> arr = new List <byte>(sizeof(char)); for (int i = 0; i < sizeof(char); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, 'u'); Assert.That(BitConverter.ToChar(arr.ToArray(), 0), Is.Not.EqualTo('z')); }
public void TestListDoubleConversionRedLight() { List <byte> arr = new List <byte>(sizeof(double)); for (int i = 0; i < sizeof(double); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, 10d); Assert.That(BitConverter.ToDouble(arr.ToArray(), 0), Is.Not.EqualTo(9d)); }
public void TestListFloatConversionRedLight() { List <byte> arr = new List <byte>(sizeof(float)); for (int i = 0; i < sizeof(float); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, 10f); Assert.That(BitConverter.ToSingle(arr.ToArray(), 0), Is.Not.EqualTo(9f).Within(0.0001)); }
public void TestListUlongConversion() { List <byte> arr = new List <byte>(sizeof(ulong)); for (int i = 0; i < sizeof(ulong); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (ulong)18446744073709551614); Assert.That(BitConverter.ToUInt64(arr.ToArray(), 0), Is.EqualTo(18446744073709551614)); }
public void TestListBoolReadRedLight() { List <byte> arr = new List <byte>(sizeof(bool)); for (int i = 0; i < sizeof(bool); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, false); Assert.That(ByteManipulator.ReadBoolean(arr, 0), Is.Not.True); }
public void TestListUintReadRedLight() { List <byte> arr = new List <byte>(sizeof(uint)); for (int i = 0; i < sizeof(uint); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (uint)25); Assert.That(ByteManipulator.ReadUInt32(arr, 0), Is.Not.EqualTo(9)); }
public void TestListLongRead() { List <byte> arr = new List <byte>(sizeof(long)); for (int i = 0; i < sizeof(long); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (long)-25); Assert.That(ByteManipulator.ReadInt64(arr, 0), Is.EqualTo(-25)); }
public void TestListUintConversion() { List <byte> arr = new List <byte>(sizeof(uint)); for (int i = 0; i < sizeof(uint); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (uint)25); Assert.That(BitConverter.ToUInt32(arr.ToArray(), 0), Is.EqualTo(25)); }
public void TestListLongConversion() { List <byte> arr = new List <byte>(sizeof(long)); for (int i = 0; i < sizeof(long); i++) { arr.Add(0); } ByteManipulator.Write(arr, 0, (long)-25); Assert.That(BitConverter.ToInt64(arr.ToArray(), 0), Is.EqualTo(-25)); }