System.Array.Copy(System.Array, int, System.Array, int, int)

Here are the examples of the csharp api System.Array.Copy(System.Array, int, System.Array, int, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5682 Examples 7

19 View Source File : Data.cs
License : MIT License
Project Creator : 0x0ade

public virtual void Set<T>(DataContext ctx, T? value) where T : MetaType<T> {
            MetaType[] metas = Meta;

            if (value == null) {
                for (int i = 0; i < metas.Length; i++) {
                    MetaType meta = metas[i];
                    if (meta is T) {
                        if (i != metas.Length - 1)
                            Array.Copy(metas, i + 1, metas, i, metas.Length - i - 1);
                        Array.Resize(ref metas, metas.Length - 1);
                        Meta = metas;
                        return;
                    }
                }
                return;
            }

            for (int i = 0; i < metas.Length; i++) {
                MetaType meta = metas[i];
                if (meta == value || meta is T) {
                    metas[i] = value;
                    Meta = metas;
                    return;
                }
            }

            Array.Resize(ref metas, metas.Length + 1);
            metas[metas.Length - 1] = value;
            Meta = metas;
        }

19 View Source File : CelesteNetConnection.cs
License : MIT License
Project Creator : 0x0ade

public void Enqueue(DataType data) {
            lock (QueueLock) {
                int count;
                if (MaxCount > 0 && Interlocked.CompareExchange(ref QueueCount, 0, 0) == MaxCount) {
                    QueueSendNext = (QueueSendNext + 1) % Queue.Length;

                } else if ((count = Interlocked.Increment(ref QueueCount)) > Queue.Length) {
                    count--;
                    int next = QueueSendNext;
                    DataType?[] old = Queue;
                    DataType?[] resized = new DataType?[old.Length * 2];
                    if (next + count <= old.Length) {
                        Array.Copy(old, next, resized, 0, count);
                    } else {
                        Array.Copy(old, next, resized, 0, old.Length - next);
                        Array.Copy(old, 0, resized, old.Length - next, count - next);
                    }
                    Queue = resized;
                    QueueSendNext = 0;
                    QueueAddNext = count;
                }

                Queue[QueueAddNext] = data;
                QueueAddNext = (QueueAddNext + 1) % Queue.Length;

                try {
                    Event.Set();
                } catch (ObjectDisposedException) {
                }
            }
        }

19 View Source File : Helpers.cs
License : MIT License
Project Creator : 0x1000000

public static IReadOnlyList<T> Combine<T>(T arg, T[] rest)
        {
            if (rest.Length < 1)
            {
                return new[] {arg};
            }
            var result = new T[rest.Length + 1];
            result[0] = arg;
            Array.Copy(rest, 0, result, 1, rest.Length);
            return result;
        }

19 View Source File : Helpers.cs
License : MIT License
Project Creator : 0x1000000

public static T[] Combine<T>(T[] source, T newItem)
        {
            if (source.Length < 1)
            {
                return new[] {newItem};
            }
            var result = new T[source.Length + 1];
            result[result.Length - 1] = newItem;
            Array.Copy(source, 0, result, 0, source.Length);
            return result;
        }

19 View Source File : Helpers.cs
License : MIT License
Project Creator : 0x1000000

public static IReadOnlyList<T> Combine<T>(T arg1, T arg2, T[] rest)
        {
            if (rest.Length < 1)
            {
                return new[] {arg1, arg2};
            }
            var result = new T[rest.Length + 2];
            result[0] = arg1;
            result[1] = arg2;
            Array.Copy(rest, 0, result, 2, rest.Length);
            return result;
        }

19 View Source File : HeifImageHandle.cs
License : GNU Lesser General Public License v3.0
Project Creator : 0xC0000054

public byte[] GetExifMetadata()
        {
            VerifyNotDisposed();

            var exifBlockIds = GetMetadataBlockIds("Exif");

            if (exifBlockIds.Count == 0)
            {
                return null;
            }

            byte[] exifBlob = GetMetadata(exifBlockIds[0]);

            // The EXIF data block length should always be > 4 because the first 4 bytes
            // specify the offset to the start of the TIFF header as a big-endian Int32 value.
            // See ISO/IEC 23008-12:2017 section A.2.1.
            if (exifBlob is null || exifBlob.Length <= 4)
            {
                return null;
            }

            int tiffHeaderStartOffset = (exifBlob[0] << 24) | (exifBlob[1] << 16) | (exifBlob[2] << 8) | exifBlob[3];

            int startIndex = 4 + tiffHeaderStartOffset;

            // The start index must be within the buffer.
            if ((uint)startIndex >= (uint)exifBlob.Length)
            {
                return null;
            }

            int length = exifBlob.Length - startIndex;

            byte[] exif = new byte[length];
            Array.Copy(exifBlob, startIndex, exif, 0, length);

            return exif;
        }

19 View Source File : Chromium.cs
License : GNU General Public License v3.0
Project Creator : 0xfd3

public static byte[] GetMasterKey(string LocalStateFolder)
        {
            //Key saved in Local State file
            string filePath = LocalStateFolder + @"\Local State";
            byte[] masterKey = new byte[] { };

            if (File.Exists(filePath) == false)
                return null;

            //Get key with regex.
            var pattern = new System.Text.RegularExpressions.Regex("\"encrypted_key\":\"(.*?)\"", System.Text.RegularExpressions.RegexOptions.Compiled).Matches(File.ReadAllText(filePath));

            foreach (System.Text.RegularExpressions.Match prof in pattern)
            {
                if (prof.Success)
                    masterKey = Convert.FromBase64String((prof.Groups[1].Value)); //Decode base64
            }

            //Trim first 5 bytes. Its signature "DPAPI"
            byte[] temp = new byte[masterKey.Length - 5];
            Array.Copy(masterKey, 5, temp, 0, masterKey.Length - 5);

            try
            {
                return ProtectedData.Unprotect(temp, null, DataProtectionScope.CurrentUser);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }

19 View Source File : Chromium.cs
License : GNU General Public License v3.0
Project Creator : 0xfd3

public static string DecryptWithKey(byte[] encryptedData, byte[] MasterKey)
        {
            byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // IV 12 bytes

            //trim first 3 bytes(signature "v10") and take 12 bytes after signature.
            Array.Copy(encryptedData, 3, iv, 0, 12);

            try
            {
                //encryptedData without IV
                byte[] Buffer = new byte[encryptedData.Length - 15];
                Array.Copy(encryptedData, 15, Buffer, 0, encryptedData.Length - 15);

                byte[] tag = new byte[16]; //AuthTag
                byte[] data = new byte[Buffer.Length - tag.Length]; //Encrypted Data

                //Last 16 bytes for tag
                Array.Copy(Buffer, Buffer.Length - 16, tag, 0, 16);

                //encrypted preplacedword
                Array.Copy(Buffer, 0, data, 0, Buffer.Length - tag.Length);

                AesGcm aesDecryptor = new AesGcm();
                var result = Encoding.UTF8.GetString(aesDecryptor.Decrypt(MasterKey, iv, null, data, tag));

                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }

19 View Source File : BssMapObjMarshal.cs
License : MIT License
Project Creator : 1996v

private static void Optimization(Entry[] entries)
        {
            // 3 
            // 3 4   i-1
            // 3 5   i
            // ==>  3(hasValue)
            //        Chidlren[1] : 4   hasValue
            //        Chidlren[2] : 5   hasValue
            Array.Sort(entries, EntryCompare.Instance);

            for (int i = entries.Length - 1; i >= 1; i--)
            {
                if (entries[i].CurrentUInt64Value == entries[i - 1].CurrentUInt64Value)
                {
                    if (entries[i].IsKey == true && entries[i - 1].IsKey == true)
                    {
                        throw BssomSerializationArgumentException.BssMapKeyUnsupportedSameRawValue(entries[i].KeyType, entries[i].KeyIsNativeType, entries[i - 1].KeyType, entries[i - 1].KeyIsNativeType, entries[i].CurrentUInt64Value);
                    }

                    if (entries[i].Chidlerns != null)
                    {
                        if (entries[i - 1].Chidlerns == null)
                        {
                            entries[i - 1].Chidlerns = entries[i].Chidlerns;
                        }
                        else
                        {
                            int len = entries[i].Chidlerns.Length;
                            Array.Resize(ref entries[i].Chidlerns, entries[i].Chidlerns.Length + entries[i - 1].Chidlerns.Length);
                            Array.Copy(entries[i - 1].Chidlerns, 0, entries[i].Chidlerns, len, entries[i - 1].Chidlerns.Length);
                            entries[i - 1].Chidlerns = entries[i].Chidlerns;
                        }
                    }

                    if (entries[i].IsKey)
                    {
                        entries[i - 1].SetKey(entries[i].LastValueByteCount, entries[i].Value, entries[i].KeyType, entries[i].KeyIsNativeType);
                    }
                    entries[i] = null;
                }
            }
            /*
         + 0
         - 1
         + 2
         + 3
         - 4
         - 5
         + 6
         */

            for (int i = 0; i < entries.Length; i++)
            {
                if (entries[i] == null)
                {
                    for (int z = i + 1; z < entries.Length; z++)
                    {
                        if (entries[z] != null)
                        {
                            entries[i] = entries[z];
                            entries[z] = null;
                            i++;
                        }
                    }
                    break;
                }
            }

            for (int i = 0; i < entries.Length; i++)
            {
                if (entries[i] == null)
                {
                    break;
                }

                if (entries[i].Chidlerns != null)
                {
                    Optimization(entries[i].Chidlerns);
                }
            }

        }

19 View Source File : StreamDeserializeAux.cs
License : MIT License
Project Creator : 1996v

private void BufferResize(int len)
        {
            byte[] newBuf = ArrayPool<byte>.Shared.Rent(position + len);
            Array.Copy(buffer, 0, newBuf, 0, position);
            if (bufferHasExpanded)
            {
                ArrayPool<byte>.Shared.Return(buffer);
            }
            else
            {
                bufferHasExpanded = true;
            }
            buffer = newBuf;
        }

19 View Source File : ArrayExtensions.cs
License : MIT License
Project Creator : 3DBear

public static T[] SubArray<T>(this T[] data, int index, int length)
	{
		T[] result = new T[length];
		Array.Copy(data, index, result, 0, length);
		return result;
	}

19 View Source File : GuidMd5OrSha1.cs
License : MIT License
Project Creator : 3F

internal static Guid NewGuid(string input, AlgoVersion version)
        {
            const int _FMT = 16; // The UUID format is 16 octets

            if(input == null) return Guid.Empty;

            byte[] ret = new byte[_FMT];
            using(HashAlgorithm alg = (version == AlgoVersion.Md5) ? MD5.Create() : (HashAlgorithm)SHA1.Create())
            {
                byte[] ns = NamespaceTest.ToByteArray();

                alg.TransformBlock(ChangeByteOrder(ns), 0, _FMT, null, 0);

                byte[] strBytes = Encoding.UTF8.GetBytes(input);
                alg.TransformFinalBlock(strBytes, 0, strBytes.Length);

                Array.Copy(alg.Hash, 0, ret, 0, _FMT);
            }

            ret[6] &= 0x0F;
            ret[6] |= (byte)((byte)version << 4);

            ret[8] &= 0x3F;
            ret[8] |= 0x80;

            return new Guid(ChangeByteOrder(ret));
        }

19 View Source File : HMACT64.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

public int digest(byte[] buf, int offset, int len)
        {
            byte[] collection = MD5.ComputeHash(this.buffer.ToArray());
            this.buffer.Clear();
            this.buffer.AddRange(this.opad);
            this.buffer.AddRange(collection);
            byte[] sourceArray = MD5.ComputeHash(this.buffer.ToArray());

            if (len > sourceArray.Length)
            {
                len = sourceArray.Length;
            }

            Array.Copy(sourceArray, 0, buf, offset, len);
            this.reset();

            return sourceArray.Length;
        }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

private static byte[] computeResponse(byte[] responseKey, byte[] serverChallenge, byte[] clientData, int offset, int length, out byte[] keyExchangeKey)
        {
            HMACT64 hmact = new HMACT64(responseKey);
            hmact.update(serverChallenge);
            hmact.update(clientData, offset, length);
            byte[] sourceArray = hmact.digest();
            byte[] destinationArray = new byte[sourceArray.Length + clientData.Length];
            Array.Copy(sourceArray, 0, destinationArray, 0, sourceArray.Length);
            Array.Copy(clientData, 0, destinationArray, sourceArray.Length, clientData.Length);
            hmact = new HMACT64(responseKey);
            hmact.update(sourceArray);
            keyExchangeKey = hmact.digest();

            return destinationArray;
        }

19 View Source File : MD5.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

internal static byte[] GetHashFinalBlock(byte[] input, int ibStart, int cbSize, ABCDStruct ABCD, long len)
        {
            byte[] destinationArray = new byte[0x40];
            byte[] bytes = BitConverter.GetBytes(len);
            Array.Copy(input, ibStart, destinationArray, 0, cbSize);
            destinationArray[cbSize] = 0x80;
            if (cbSize <= 0x38)
            {
                Array.Copy(bytes, 0, destinationArray, 0x38, 8);
                GetHashBlock(destinationArray, ref ABCD, 0);
            }
            else
            {
                GetHashBlock(destinationArray, ref ABCD, 0);
                destinationArray = new byte[0x40];
                Array.Copy(bytes, 0, destinationArray, 0x38, 8);
                GetHashBlock(destinationArray, ref ABCD, 0);
            }
            byte[] buffer3 = new byte[0x10];
            Array.Copy(BitConverter.GetBytes(ABCD.A), 0, buffer3, 0, 4);
            Array.Copy(BitConverter.GetBytes(ABCD.B), 0, buffer3, 4, 4);
            Array.Copy(BitConverter.GetBytes(ABCD.C), 0, buffer3, 8, 4);
            Array.Copy(BitConverter.GetBytes(ABCD.D), 0, buffer3, 12, 4);
            return buffer3;
        }

19 View Source File : RC4.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

protected int engineUpdate(byte[] inData, int inOffset, int inLen, byte[] outData, int outOffset)
        {
            if (inLen < 0)
            {
                throw new RDFatalException("inLen < 0");

            }
            this.getState();
            int eNCRYPT = ENCRYPT;
            if ((inData == outData) && (((outOffset >= inOffset) && (outOffset < (inOffset + inLen))) || ((inOffset >= outOffset) && (inOffset < (outOffset + inLen)))))
            {
                byte[] destinationArray = new byte[inLen];
                Array.Copy(inData, inOffset, destinationArray, 0, inLen);
                inData = destinationArray;
                inOffset = 0;
            }
            this.rc4(inData, inOffset, inLen, outData, outOffset);
            return inLen;
        }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

public byte[] DecryptMessage(byte[] cryptmessage)
        {
            byte[] destinationArray = new byte[0x10];
            Array.Copy(cryptmessage, 0, destinationArray, 0, 0x10);
            byte[] message = this.m_ServerSealingRC4.crypt(cryptmessage, 0x10, cryptmessage.Length - 0x10);
            this.VerifySignature(message, destinationArray);

            return message;
        }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

private static byte[] getLMv2Response(byte[] responseKeyNT, byte[] serverChallenge, byte[] clientChallenge)
        {
            byte[] buf = new byte[0x18];
            HMACT64 hmact = new HMACT64(responseKeyNT);
            hmact.update(serverChallenge);
            hmact.update(clientChallenge);
            hmact.digest(buf, 0, 0x10);
            Array.Copy(clientChallenge, 0, buf, 0x10, 8);

            return buf;
        }

19 View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

public void InsertByte(byte value)
        {
            long position = this.Position;
            this.Seek(0L, SeekOrigin.End);
            this.WriteByte(0);
            byte[] sourceArray = this.GetBuffer();
            Array.Copy(sourceArray, (int) position, sourceArray, ((int) position) + 1, (int) ((sourceArray.Length - position) - 1L));
            this.Position = position;
            this.WriteByte(value);
        }

19 View Source File : BasicList.cs
License : MIT License
Project Creator : 404Lcc

internal void CopyTo(Array array, int offset)
            {
                if (length > 0)
                {
                    Array.Copy(data, 0, array, offset, length);
                }
            }

19 View Source File : Tlv.cs
License : MIT License
Project Creator : 499116344

private static void ParseTlv(byte[] rawTlv, ICollection<Tlv> result)
        {
            for (int i = 0, start = 0; i < rawTlv.Length; start = i)
            {
                // parse Tag
                var constructedTlv = (rawTlv[i] & 0x20) != 0;
                var moreBytes = (rawTlv[i] & 0x1F) == 0x1F;
                while (moreBytes && (rawTlv[++i] & 0x80) != 0)
                {
                    ;
                }

                //i++
                i += 2;

                var tag = GetInt(rawTlv, start, i - start);

                //// parse Length
                //bool multiByteLength = (rawTlv[i] & 0x80) != 0;
                //int length = multiByteLength ? GetInt(rawTlv, i + 1, rawTlv[i] & 0x1F) : rawTlv[i];
                //i = multiByteLength ? i + (rawTlv[i] & 0x1F) + 1 : i + 1;
                i += 2;
                start += 2;
                var length = GetInt(rawTlv, start, i - start);

                i += length;

                var rawData = new byte[i - start];
                Array.Copy(rawTlv, start, rawData, 0, i - start);
                var tlv = new Tlv(tag, length, rawData.Length - length, rawData);
                result.Add(tlv);

                if (constructedTlv)
                {
                    ParseTlv(tlv.Value, tlv.Children);
                }
            }
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

private static void Code(byte[] In, int inOffset, int inPos, byte[] Out, int outOffset, int outPos, byte[] key)
        {
            if (outPos > 0)
            {
                for (var i = 0; i < 8; i++)
                {
                    In[outOffset + outPos + i] =
                        BitConverter.GetBytes(In[inOffset + inPos + i] ^ Out[outOffset + outPos + i - 8])[0];
                }
            }

            var array = FormatKey(key);
            var num = ConvertByteArrayToUInt(In, outOffset + outPos);
            var num2 = ConvertByteArrayToUInt(In, outOffset + outPos + 4);
            var num3 = 0u;
            var num4 = 2654435769u;
            var num5 = 16u;
            while (num5-- > 0u)
            {
                num3 += num4;
                num += ((num2 << 4) + array[0]) ^ (num2 + num3) ^ ((num2 >> 5) + array[1]);
                num2 += ((num << 4) + array[2]) ^ (num + num3) ^ ((num >> 5) + array[3]);
            }

            Array.Copy(ConvertUIntToByteArray(num), 0, Out, outOffset + outPos, 4);
            Array.Copy(ConvertUIntToByteArray(num2), 0, Out, outOffset + outPos + 4, 4);
            if (inPos > 0)
            {
                for (var j = 0; j < 8; j++)
                {
                    Out[outOffset + outPos + j] =
                        BitConverter.GetBytes(Out[outOffset + outPos + j] ^ In[inOffset + inPos + j - 8])[0];
                }
            }
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

private static void Decode(byte[] In, int inOffset, int inPos, byte[] Out, int outOffset, int outPos,
            byte[] key)
        {
            if (outPos > 0)
            {
                for (var i = 0; i < 8; i++)
                {
                    Out[outOffset + outPos + i] =
                        BitConverter.GetBytes(In[inOffset + inPos + i] ^ Out[outOffset + outPos + i - 8])[0];
                }
            }
            else
            {
                Array.Copy(In, inOffset, Out, outOffset, 8);
            }

            var array = FormatKey(key);
            var num = ConvertByteArrayToUInt(Out, outOffset + outPos);
            var num2 = ConvertByteArrayToUInt(Out, outOffset + outPos + 4);
            var num3 = 3816266640u;
            var num4 = 2654435769u;
            var num5 = 16u;
            while (num5-- > 0u)
            {
                num2 -= ((num << 4) + array[2]) ^ (num + num3) ^ ((num >> 5) + array[3]);
                num -= ((num2 << 4) + array[0]) ^ (num2 + num3) ^ ((num2 >> 5) + array[1]);
                num3 -= num4;
            }

            Array.Copy(ConvertUIntToByteArray(num), 0, Out, outOffset + outPos, 4);
            Array.Copy(ConvertUIntToByteArray(num2), 0, Out, outOffset + outPos + 4, 4);
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

public static byte[] Decrypt(byte[] In, int offset, int len, byte[] key)
        {
            var temp = new byte[In.Length];
            Buffer.BlockCopy(In, 0, temp, 0, In.Length);
            if (len % 8 != 0 || len < 16)
            {
                return null;
            }

            var array = new byte[len];
            for (var i = 0; i < len; i += 8)
            {
                Decode(temp, offset, i, array, 0, i, key);
            }

            for (var j = 8; j < len; j++)
            {
                array[j] ^= temp[offset + j - 8];
            }

            var num = array[0] & 7;
            len = len - num - 10;
            var array2 = new byte[len];
            Array.Copy(array, num + 3, array2, 0, len);
            return array2;
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

public static byte[] Encrypt(byte[] In, int offset, int len, byte[] key)
        {
            var temp = new byte[In.Length];
            Buffer.BlockCopy(In, 0, temp, 0, In.Length);
            var random = new Random();
            var num = (len + 10) % 8;
            if (num != 0)
            {
                num = 8 - num;
            }

            var array = new byte[len + num + 10];
            array[0] = (byte) ((random.Next() & 248) | num);
            for (var i = 1; i < num + 3; i++)
            {
                array[i] = (byte) (random.Next() & 255);
            }

            Array.Copy(temp, 0, array, num + 3, len);
            for (var j = num + 3 + len; j < array.Length; j++)
            {
                array[j] = 0;
            }

            var array2 = new byte[len + num + 10];
            for (var k = 0; k < array2.Length; k += 8)
            {
                Code(array, 0, k, array2, 0, k, key);
            }

            return array2;
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

private static uint[] FormatKey(byte[] key)
        {
            if (key.Length == 0)
            {
                throw new ArgumentException("Key must be between 1 and 16 characters in length");
            }

            var array = new byte[16];
            if (key.Length < 16)
            {
                Array.Copy(key, 0, array, 0, key.Length);
                for (var i = key.Length; i < 16; i++)
                {
                    array[i] = 32;
                }
            }
            else
            {
                Array.Copy(key, 0, array, 0, 16);
            }

            var array2 = new uint[4];
            var num = 0;
            for (var j = 0; j < array.Length; j += 4)
            {
                array2[num++] = ConvertByteArrayToUInt(array, j);
            }

            return array2;
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static string GetString(byte[] b, int offset, int len, string encoding = QQGlobal.QQCharsetDefault)
        {
            var temp = new byte[len];
            Array.Copy(b, offset, temp, 0, len);
            return GetString(temp, encoding);
        }

19 View Source File : LightList.cs
License : MIT License
Project Creator : 71

private static void RemoveAt(ref T[] array, int index)
        {
            int newSize = array.Length - 1;

            T[] newArray = new T[newSize];
            Array.Copy(array, 0, newArray, 0, index);
            Array.Copy(array, index, newArray, index, newSize - index);
        }

19 View Source File : LightList.cs
License : MIT License
Project Creator : 71

public void Add(T item)
        {
            T[] array = underlyingArray;
            int newSize = array.Length + 1;

            T[] newArray = new T[newSize--];
            Array.Copy(array, 0, newArray, 0, newSize);
            newArray[newSize] = item;

            underlyingArray = newArray;
        }

19 View Source File : SessionServer.cs
License : Apache License 2.0
Project Creator : AantCoder

private void SetKey()
        {
            var rnd = new Random();
            var k = new byte[Rnd.Next(400, 600)];
            for (int i = 0; i < k.Length; i++)
            {
                k[i] = (byte)(Rnd.Next(0, 128) + rnd.Next(0, 128));
            }
            var k2 = KeyEncoding.GetBytes("089~`tgjРР·dfgорЫГ9♫7ПМпfghjp147&$#hf%#h^^gxчмиА▀ЫЮББЮю,><2en]√");

            int oldLen = k.Length;
            Array.Resize(ref k, k.Length + k2.Length);
            Array.Copy(k2, 0, k, oldLen, k2.Length);

            Key = cryptoHash.GetHash(k);
        }

19 View Source File : AppenderBase.cs
License : MIT License
Project Creator : Abc-Arbitrage

private int WriteLine(Stream stream, byte[] messageBytes, int messageLength)
        {
            var newlineBytes = _newlineBytes;

            if (messageLength + newlineBytes.Length < messageBytes.Length)
            {
                Array.Copy(newlineBytes, 0, messageBytes, messageLength, newlineBytes.Length);
                messageLength += newlineBytes.Length;

                stream.Write(messageBytes, 0, messageLength);
                return messageLength;
            }

            stream.Write(messageBytes, 0, messageLength);
            stream.Write(newlineBytes, 0, newlineBytes.Length);
            return messageLength + newlineBytes.Length;
        }

19 View Source File : RopeNode.cs
License : MIT License
Project Creator : Abdesol

internal RopeNode<T> Insert(int offset, T[] array, int arrayIndex, int count)
		{
			Debug.replacedert(count > 0);

			if (this.length + count < RopeNode<char>.NodeSize) {
				RopeNode<T> result = CloneIfShared();
				// result must be leaf node (Clone never returns function nodes, too short for concat node)
				int lengthAfterOffset = result.length - offset;
				T[] resultContents = result.contents;
				for (int i = lengthAfterOffset; i >= 0; i--) {
					resultContents[i + offset + count] = resultContents[i + offset];
				}
				Array.Copy(array, arrayIndex, resultContents, offset, count);
				result.length += count;
				return result;
			} else if (height == 0) {
				// TODO: implement this more efficiently?
				return Insert(offset, CreateFromArray(array, arrayIndex, count));
			} else {
				// this is a concat node (both leafs and function nodes are handled by the case above)
				RopeNode<T> result = CloneIfShared();
				if (offset < result.left.length) {
					result.left = result.left.Insert(offset, array, arrayIndex, count);
				} else {
					result.right = result.right.Insert(offset - result.left.length, array, arrayIndex, count);
				}
				result.length += count;
				result.Rebalance();
				return result;
			}
		}

19 View Source File : FdbMemoizedTuple.cs
License : MIT License
Project Creator : abdullin

public void CopyTo(object[] array, int offset)
		{
			Array.Copy(m_items, 0, array, offset, m_items.Length);
		}

19 View Source File : RopeNode.cs
License : MIT License
Project Creator : Abdesol

RopeNode<T> SplitAfter(int offset)
		{
			Debug.replacedert(!isShared && height == 0 && contents != null);
			RopeNode<T> newPart = new RopeNode<T>();
			newPart.contents = new T[NodeSize];
			newPart.length = this.length - offset;
			Array.Copy(this.contents, offset, newPart.contents, 0, newPart.length);
			this.length = offset;
			return newPart;
		}

19 View Source File : Deque.cs
License : MIT License
Project Creator : Abdesol

public void CopyTo(T[] array, int arrayIndex)
		{
			if (array == null)
				throw new ArgumentNullException("array");
			if (head < tail) {
				Array.Copy(arr, head, array, arrayIndex, tail - head);
			} else {
				int num1 = arr.Length - head;
				Array.Copy(arr, head, array, arrayIndex, num1);
				Array.Copy(arr, 0, array, arrayIndex + num1, tail);
			}
		}

19 View Source File : RopeNode.cs
License : MIT License
Project Creator : Abdesol

internal void CopyTo(int index, T[] array, int arrayIndex, int count)
		{
			if (height == 0) {
				if (this.contents == null) {
					// function node
					this.GetContentNode().CopyTo(index, array, arrayIndex, count);
				} else {
					// leaf node
					Array.Copy(this.contents, index, array, arrayIndex, count);
				}
			} else {
				// concat node
				if (index + count <= this.left.length) {
					this.left.CopyTo(index, array, arrayIndex, count);
				} else if (index >= this.left.length) {
					this.right.CopyTo(index - this.left.length, array, arrayIndex, count);
				} else {
					int amountInLeft = this.left.length - index;
					this.left.CopyTo(index, array, arrayIndex, amountInLeft);
					this.right.CopyTo(0, array, arrayIndex + amountInLeft, count - amountInLeft);
				}
			}
		}

19 View Source File : RopeNode.cs
License : MIT License
Project Creator : Abdesol

internal RopeNode<T> StoreElements(int index, T[] array, int arrayIndex, int count)
		{
			RopeNode<T> result = this.CloneIfShared();
			// result cannot be function node after a call to Clone()
			if (result.height == 0) {
				// leaf node:
				Array.Copy(array, arrayIndex, result.contents, index, count);
			} else {
				// concat node:
				if (index + count <= result.left.length) {
					result.left = result.left.StoreElements(index, array, arrayIndex, count);
				} else if (index >= this.left.length) {
					result.right = result.right.StoreElements(index - result.left.length, array, arrayIndex, count);
				} else {
					int amountInLeft = result.left.length - index;
					result.left = result.left.StoreElements(index, array, arrayIndex, amountInLeft);
					result.right = result.right.StoreElements(0, array, arrayIndex + amountInLeft, count - amountInLeft);
				}
				result.Rebalance(); // tree layout might have changed if function nodes were replaced with their content
			}
			return result;
		}

19 View Source File : EndianBitConverter.cs
License : Microsoft Public License
Project Creator : abfo

public static int ToInt32(byte[] value, int startIndex, ProvidedOrder order)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if ((startIndex + sizeof(int)) > value.Length)
            {
                throw new ArgumentException("startIndex invalid (not enough space in value to extract an integer", "startIndex");
            }

            if (BitConverter.IsLittleEndian && (order == ProvidedOrder.Big))
            {
                byte[] toConvert = new byte[sizeof(int)];
                Array.Copy(value, startIndex, toConvert, 0, sizeof(int));
                Array.Reverse(toConvert);
                return BitConverter.ToInt32(toConvert, 0);
            }
            else
            {
                return BitConverter.ToInt32(value, startIndex);
            }
        }

19 View Source File : EndianBitConverter.cs
License : Microsoft Public License
Project Creator : abfo

public static double ToDouble(byte[] value, int startIndex, ProvidedOrder order)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if ((startIndex + sizeof(double)) > value.Length)
            {
                throw new ArgumentException("startIndex invalid (not enough space in value to extract a double", "startIndex");
            }

            if (BitConverter.IsLittleEndian && (order == ProvidedOrder.Big))
            {
                byte[] toConvert = new byte[sizeof(double)];
                Array.Copy(value, startIndex, toConvert, 0, sizeof(double));
                Array.Reverse(toConvert);
                return BitConverter.ToDouble(toConvert, 0);
            }
            else
            {
                return BitConverter.ToDouble(value, startIndex);
            }
        }

19 View Source File : FdbListTuple.cs
License : MIT License
Project Creator : abdullin

public FdbListTuple Append<T>(T value)
		{
			var list = new object[m_count + 1];
			Array.Copy(m_items, m_offset, list, 0, m_count);
			list[m_count] = value;
			return new FdbListTuple(list, 0, list.Length);
		}

19 View Source File : FdbListTuple.cs
License : MIT License
Project Creator : abdullin

public FdbListTuple AppendRange(object[] items)
		{
			if (items == null) throw new ArgumentNullException("items");

			if (items.Length == 0) return this;

			var list = new object[m_count + items.Length];
			Array.Copy(m_items, m_offset, list, 0, m_count);
			Array.Copy(items, 0, list, m_count, items.Length);
			return new FdbListTuple(list, 0, list.Length);
		}

19 View Source File : FdbListTuple.cs
License : MIT License
Project Creator : abdullin

public FdbListTuple Concat(FdbListTuple tuple)
		{
			if (tuple == null) throw new ArgumentNullException("tuple");

			if (tuple.m_count == 0) return this;
			if (m_count == 0) return tuple;

			var list = new object[m_count + tuple.m_count];
			Array.Copy(m_items, m_offset, list, 0, m_count);
			Array.Copy(tuple.m_items, tuple.m_offset, list, m_count, tuple.m_count);
			return new FdbListTuple(list, 0, list.Length);
		}

19 View Source File : FdbListTuple.cs
License : MIT License
Project Creator : abdullin

public FdbListTuple Concat(IFdbTuple tuple)
		{
			var _ = tuple as FdbListTuple;
			if (_ != null) return Concat(_);

			int count = tuple.Count;
			if (count == 0) return this;

			var list = new object[m_count + count];
			Array.Copy(m_items, m_offset, list, 0, m_count);
			tuple.CopyTo(list, m_count);
			return new FdbListTuple(list, 0, list.Length);
		}

19 View Source File : FdbListTuple.cs
License : MIT License
Project Creator : abdullin

public void CopyTo(object[] array, int offset)
		{
			Array.Copy(m_items, m_offset, array, offset, m_count);
		}

19 View Source File : BufferedAudioStream.cs
License : MIT License
Project Creator : absurd-joy

public void AddData(float[] samples) {
    int remainingWriteLength = samples.Length;

    if(writePos > audioBuffer.Length) {
      throw new Exception();
    }

    do {
      int writeLength = remainingWriteLength;
      int remainingSpace = audioBuffer.Length - writePos;

      if(writeLength > remainingSpace) {
        writeLength = remainingSpace;
      }

      Array.Copy(samples, 0, audioBuffer, writePos, writeLength);

      remainingWriteLength -= writeLength;
      writePos += writeLength;
      if(writePos > audioBuffer.Length) {
        throw new Exception();
      }
      if(writePos == audioBuffer.Length) {
        writePos = 0;
      }
    } while(remainingWriteLength > 0);

#if VERBOSE_LOGGING
    float prev = remainingBufferTime;
#endif
    remainingBufferTime += (float)samples.Length / sampleRate;
#if VERBOSE_LOGGING
    Debug.Log(string.Format("previous remaining: {0}, new remaining: {1}, added {2} samples", prev, remainingBufferTime, samples.Length));
#endif
    audio.clip.SetData(audioBuffer, 0);
  }

19 View Source File : OVRNetwork.cs
License : MIT License
Project Creator : absurd-joy

void OnReadDataCallback(IAsyncResult ar)
		{
			NetworkStream stream = ar.AsyncState as NetworkStream;
			try
			{
				int numBytes = stream.EndRead(ar);
				receivedBufferDataSize += numBytes;

				while (receivedBufferDataSize >= FrameHeader.StructSize)
				{
					FrameHeader header = FrameHeader.FromBytes(receivedBuffers[receivedBufferIndex]);
					if (header.protocolIdentifier != OVRNetwork.FrameHeaderMagicIdentifier)
					{
						Debug.LogWarning("[OVRNetworkTcpClient] header mismatch");
						Disconnect();
						return;
					}

					if (header.payloadLength < 0 || header.payloadLength > OVRNetwork.MaxPayloadLength)
					{
						Debug.LogWarningFormat("[OVRNetworkTcpClient] Sanity check failed. PayloadLength %d", header.payloadLength);
						Disconnect();
						return;
					}

					if (receivedBufferDataSize >= FrameHeader.StructSize + header.payloadLength)
					{
						if (payloadReceivedCallback != null)
						{
							payloadReceivedCallback(header.payloadType, receivedBuffers[receivedBufferIndex], FrameHeader.StructSize, header.payloadLength);
						}

						// swap receive buffer
						int newBufferIndex = 1 - receivedBufferIndex;
						int newBufferDataSize = receivedBufferDataSize - (FrameHeader.StructSize + header.payloadLength);
						if (newBufferDataSize > 0)
						{
							Array.Copy(receivedBuffers[receivedBufferIndex], (FrameHeader.StructSize + header.payloadLength), receivedBuffers[newBufferIndex], 0, newBufferDataSize);
						}
						receivedBufferIndex = newBufferIndex;
						receivedBufferDataSize = newBufferDataSize;
					}
				}
				readyReceiveDataEvent.Set();
			}
			catch (SocketException e)
			{
				Debug.LogErrorFormat("[OVRNetworkTcpClient] OnReadDataCallback: socket error: {0}", e.Message);
				Disconnect();
			}
		}

19 View Source File : AudioDataAnalyzer.cs
License : MIT License
Project Creator : ABTSoftware

private void ProcessData(double[] input)
        {
            var offset = input.Length - _fftWindowSize;
            for (int i = 0; i < _fftWindowSize; i++)
            {
                Complex c = new Complex();
                c.X = (float)(input[offset + i] * FastFourierTransform.BlackmannHarrisWindow(i, _fftWindowSize));
                c.Y = 0;
                _fftInput[i] = c;
            }

            FastFourierTransform.FFT(true, _log2, _fftInput);

            ComputeDbValues(_fftInput, DbValues);

            Array.Copy(SpectrogramBuffer, FftDataPoints, SpectrogramBuffer, 0, (SpectrogramFrameCount - 1) * FftDataPoints);
            for (var i = 0; i < FftDataPoints; i++)
            {
                SpectrogramBuffer[SpectrogramFrameCount - 1, i] = DbValues[i];
            }

            Update?.Invoke(this, EventArgs.Empty);
        }

19 View Source File : SampleReader.cs
License : MIT License
Project Creator : ABTSoftware

public void ReadSamples(byte[] data, int dataCount, double[] dest)
        {
            var size = dest.Length;
            var sampleCount = NumSamples(dataCount);
            sampleCount = Math.Min(size, sampleCount);

            var offset = size - sampleCount;

            Array.Copy(dest, sampleCount, dest, 0, offset);

            for (int i = 0; i < sampleCount; i++)
            {
                dest[offset + i] = ReadSample(data, i);
            }
        }

19 View Source File : CommandManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void ParseCommand(string commandLine, out string command, out string[] parameters)
        {
            if (commandLine == "/" || commandLine == "")
            {
                command = null;
                parameters = null;
                return;
            }
            var commandSplit = commandLine.Split(' ',StringSplitOptions.RemoveEmptyEntries);
            command = commandSplit[0];

            // remove leading '/' or '@' if erroneously entered in console
            if(command.StartsWith("/") || command.StartsWith("@"))
                command = command.Substring(1);

            parameters = new string[commandSplit.Length - 1];

            Array.Copy(commandSplit, 1, parameters, 0, commandSplit.Length - 1);

            if (commandLine.Contains("\""))
            {
                var listParameters = new List<string>();

                for (int start = 0; start < parameters.Length; start++)
                {
                    if (!parameters[start].StartsWith("\"") || parameters[start].EndsWith("\"")) // Make sure we catch parameters like: "someParam"
                        listParameters.Add(parameters[start].Replace("\"", ""));
                    else
                    {
                        listParameters.Add(parameters[start].Replace("\"", ""));
                        for (int end = start + 1; end < parameters.Length; end++)
                        {
                            if (!parameters[end].EndsWith("\""))
                                listParameters[listParameters.Count - 1] += " " + parameters[end];
                            else
                            {
                                listParameters[listParameters.Count - 1] += " " + parameters[end].Replace("\"", "");
                                start = end;
                                break;
                            }
                        }
                    }
                }
                Array.Resize(ref parameters, listParameters.Count);
                parameters = listParameters.ToArray();
            }
        }

19 View Source File : ValueEncoders.cs
License : MIT License
Project Creator : actions

private static string Base64StringEscapeShift(String value, int shift)
        {
            var bytes = Encoding.UTF8.GetBytes(value);
            if (bytes.Length > shift)
            {
                var shiftArray = new byte[bytes.Length - shift];
                Array.Copy(bytes, shift, shiftArray, 0, bytes.Length - shift);
                return Convert.ToBase64String(shiftArray);
            }
            else
            {
                return Convert.ToBase64String(bytes);
            }
        }

See More Examples