Beispiel #1
0
        /// <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));
        }
Beispiel #2
0
    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);
            }
        }
    }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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));
 }
Beispiel #6
0
 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 = "";
    }
Beispiel #8
0
 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);
 }
Beispiel #9
0
        /// <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;
        }
Beispiel #10
0
    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"));
    }
Beispiel #11
0
    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"));
    }
Beispiel #12
0
    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);
    }
Beispiel #13
0
 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]);
     }
 }
Beispiel #14
0
    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);
    }
Beispiel #15
0
    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));
    }
Beispiel #16
0
    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));
    }
Beispiel #17
0
    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));
    }
Beispiel #18
0
    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));
    }
Beispiel #19
0
    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));
    }
Beispiel #20
0
    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));
    }
Beispiel #21
0
    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));
    }
Beispiel #22
0
    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'));
    }
Beispiel #23
0
    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));
    }
Beispiel #24
0
    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));
    }
Beispiel #25
0
    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));
    }
Beispiel #26
0
    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);
    }
Beispiel #27
0
    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));
    }
Beispiel #28
0
    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));
    }
Beispiel #29
0
    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));
    }
Beispiel #30
0
    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));
    }