Пример #1
0
    private static MemoryOperations memory; //avoid gc

    static void Main(string[] args)
    {
        RPCAbleMethods.Load();

        NetPeerConfiguration config = new NetPeerConfiguration("of_masterserver")
        {
            Port = PORT,
            MaximumConnections        = (2 ^ 32 - 1),
            AcceptIncomingConnections = true,
        };

        peer = new NetServer(config);
        peer.Start();

        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine("> Server started, server version: " + VERSION);
        Console.ForegroundColor = ConsoleColor.White;

        memory = new MemoryOperations();
        ServerLoop.StartServerLoop(peer);

        while (ServerLoop.EnabledLooping)
        {
            Thread.Sleep(1000);
        }
    }
Пример #2
0
            protected static byte *Write(byte *dest, params byte[] data)
            {
                int size = data.Length;

                fixed(byte *src = data)
                MemoryOperations.BlockCopy(src, dest, size);

                return(dest + size);
            }
            static unsafe bool _EqualsUnsafeCore(byte[] x, byte[] y)
            {
                var n = x.Length;

                if (n == 0)
                {
                    return(true);

                    fixed(byte *px = x, py = y)
                    return(MemoryOperations.BlockEquals(px, py, n));
            }
Пример #4
0
        public static uint[] Cpuid(uint req_no)
        {
            uint[] buf = new uint[4];

            unsafe
            {
                _Cpuid(req_no, (uint *)MemoryOperations.GetInternalArray(buf));
            }

            return(buf);
        }
Пример #5
0
        /// <summary>
        /// Overwrites a channel of a sample of the buffer.
        /// </summary>
        /// <param name="sample">A pointer to the first byte of the channel value to read from.</param>
        /// <param name="index">The index of the target sample to write to.</param>
        /// <param name="channel">The index of the channel to write to.</param>
        public unsafe void WriteChannel(byte *sample, int index, int channel)
        {
            if (mode != OperationMode.Convert)
            {
                int sampleStart = index * target.Format.Size + channel * target.Format.ChannelSize;

                fixed(byte *destPtr = target.RawData)
                {
                    MemoryOperations.Copy(destPtr + sampleStart, sample, target.Format.ChannelSize);
                }
            }
            else
            {
                // Read the sample to the buffer
                for (int j = 0; j < writeFormat.ChannelSize; j++)
                {
                    buffer[j] = sample[j];
                }

                fixed(byte *bufferPtr = buffer, destPtr = target.RawData)
                {
                    // Pass 1: Change the bit-depth
                    if (writeFormat.BitDepth != target.Format.BitDepth)
                    {
                        ChangeBitDepth(
                            bufferPtr,
                            1, // one channel
                            writeFormat.BitDepth,
                            target.Format.BitDepth
                            );
                    }

                    // Pass 2: Change the sign
                    if (shouldChangeSign)
                    {
                        if (shouldMakeSigned)
                        {
                            MakeSigned(bufferPtr, target.Format);
                        }
                        else
                        {
                            MakeUnsigned(bufferPtr, target.Format);
                        }
                    }

                    int sampleStart = index * target.Format.Size + channel * target.Format.ChannelSize;

                    MemoryOperations.Copy(destPtr + sampleStart, bufferPtr, target.Format.ChannelSize);
                }
            }
        }
Пример #6
0
    public static void ReloadBalanceData(NetIncomingMessage message)
    {
        string AdminLogin    = message.ReadString();
        string AdminPassword = message.ReadString();
        string BanNickname   = message.ReadString();

        try
        {
            PlayerInfo request = MemoryOperations.PlayersData.Keys.FirstOrDefault(x => x.Nickname == AdminLogin);
            if (request.Password == AdminPassword && request.AccessLevel >= 16)
            {
                MemoryOperations.LoadGameBalance(Program.PATH_BALANCE_FILE);
                Commands.BroadcastBalanceData();
            }
        }
        catch { }
    }
Пример #7
0
    private static void Shutdown(NetIncomingMessage message)
    {
        string AdminLogin    = message.ReadString();
        string AdminPassword = message.ReadString();

        Console.WriteLine("Shutdown");
        try
        {
            PlayerInfo request = MemoryOperations.PlayersData.Keys.FirstOrDefault(x => x.Nickname == AdminLogin);
            if (request.Password == AdminPassword && request.AccessLevel >= 16)
            {
                MemoryOperations.RefreshPlayersAccountsInMemory(0);
                ServerLoop.CloseLooping();
            }
        }
        catch { Environment.Exit(0); }
    }
Пример #8
0
        private void TestByteArrayCopy(int size)
        {
            byte[] src = new byte[size];
            byte[] dst = new byte[size];

            mDebugger.Send($"Start Copy of {size} bytes");

            MemoryOperations.Fill(src, 42);

            mDebugger.Send("Copy Start");
            MemoryOperations.Copy(dst, src);
            mDebugger.Send("Copy End");

            Assert.AreEqual(src, dst, $"Copy failed Array src and dst with size {size} are not equals");

            mDebugger.Send("End");
        }
Пример #9
0
        private void TestIntArrayCopy(int size)
        {
            int[] src = new int[size];
            int[] dst = new int[size];

            mDebugger.Send($"Start Copy of {size} integers");

            MemoryOperations.Fill(src, 42);

            mDebugger.Send("Copy Start");
            MemoryOperations.Copy(dst, src);
            mDebugger.Send("Copy End");

            Assert.IsTrue(AreArrayEquals(src, dst), $"Copy failed Array src and dst with size {size} are not equals");

            mDebugger.Send("End");
        }
Пример #10
0
        private void HandleInterrupt(ref INTs.IRQContext aContext)
        {
            ushort sr = pTransferStatus.Word;

            if ((sr & IRQ_LVBCI) > 0)
            {
                // Last Valid Buffer interrupt
                pTransferStatus.Word = IRQ_LVBCI;
            }
            else if ((sr & IRQ_BCIS) > 0)
            {
                // Load a buffer ahead
                int next = lastValidIdx + 1;
                if (next >= BUFFER_COUNT)
                {
                    next -= BUFFER_COUNT;
                }

                BufferProvider.RequestBuffer(transferBuffer);

                fixed(byte *mainBufPtr = transferBuffer.RawData)
                {
                    MemoryOperations.Copy(
                        dest: bufferDescriptorList[next].pointer,
                        src: mainBufPtr,
                        size: bufferSizeBytes
                        );
                }

                // Set the index to the current one
                lastValidIdx++;
                if (lastValidIdx == BUFFER_COUNT)
                {
                    lastValidIdx = 0;
                }

                pLastValidEntry.Byte = lastValidIdx;
                pTransferStatus.Word = IRQ_BCIS;
            }
            else if ((sr & IRQ_FIFO_ERROR) > 0)
            {
                pTransferStatus.Word = IRQ_FIFO_ERROR;
            }
        }
        public unsafe void Execute(string parameter = null)
        {
            if (parameter == null || !int.TryParse(parameter, out var length))
            {
                length = 64000;
            }
            var array  = new int[length];
            var points = new[]
            {
                4, 2, 3
            };

            fixed(int *dest = array)
            {
                MemoryOperations.Fill(dest, 42, length);
            }

            Console.WriteLine($"Voilà super rapide les {length} éléments ptdr *transition Leclerc*");
            var smallerLength = length / 4;
            var array2        = new int[smallerLength];
            var array3        = new int[smallerLength];
            var timeStamp     = CStopwatch.GetTimestamp();

            Console.WriteLine($"Test: {smallerLength} elements");
            // no pointer
            for (int i = 0; i < smallerLength; i++)
            {
                array2[i] = i + i * i;
            }
            Console.WriteLine($"Completed with no pointers in {CStopwatch.GetTimestamp() - timeStamp} units");
            timeStamp = CStopwatch.GetTimestamp();
            fixed(int *array3P = array3)
            {
                for (int i = 0; i < smallerLength; i++)
                {
                    *(array3P + i) = i + i * i;
                }
            }

            Console.WriteLine($"Completed with a pointy pointer in {CStopwatch.GetTimestamp() - timeStamp} units");
        }
Пример #12
0
        public bool Authenticate(
            ReadOnlySpan <byte> clientPublicKey,
            ReadOnlySpan <byte> clientProof)
        {
            _A  = BigIntFromByteArray(clientPublicKey.ToArray());
            _M1 = BigIntFromByteArray(clientProof.ToArray());

            if (_A.IsZero || (_A % _N).IsZero)
            {
                return(false);
            }

            var u = BigIntFromByteArray(HashArrays(
                                            BigIntToByteArray(_A),
                                            BigIntToByteArray(_B)
                                            ));
            var S = BigInteger.ModPow(
                _A * BigInteger.ModPow(_v, u, _N),
                _b,
                _N);

            _K = ComputeSessionKey(S);

            Span <byte>         ngHash = HashArrays(BigIntToByteArray(_N));
            ReadOnlySpan <byte> gHash  = HashArrays(BigIntToByteArray(_g));

            MemoryOperations.InPlaceXor(ngHash, gHash);

            var iHash = HashArrays(Encoding.UTF8.GetBytes(_I));

            var clientProofCheck = HashArrays(
                ngHash.ToArray(), iHash,
                BigIntToByteArray(_s),
                BigIntToByteArray(_A),
                BigIntToByteArray(_B),
                BigIntToByteArray(_K)
                );

            return(clientProof.SequenceEqual(clientProofCheck));
        }
Пример #13
0
        /// <summary>
        /// Writes a sample to the buffer.
        /// </summary>
        /// <param name="sample">A pointer to the first byte of the sample write.</param>
        /// <param name="index">The index of the target sample to overwrite.</param>
        public unsafe void Write(byte *sample, int index)
        {
            if (mode == OperationMode.DirectCopy)
            {
                int sampleStart = index * target.Format.Size;

                fixed(byte *destPtr = target.RawData)
                {
                    MemoryOperations.Copy(destPtr + sampleStart, sample, target.Format.Size);
                }
            }
            else
            {
                // Read the sample to the buffer
                for (int j = 0; j < writeFormat.Size; j++)
                {
                    buffer[j] = sample[j];
                }

                // Pass 1: Upmix/downmix channels
                if (writeFormat.Channels < target.Format.Channels)
                {
                    UpmixChannels(
                        buffer,
                        writeFormat.Channels,
                        target.Format.Channels,
                        writeFormat
                        );
                }

                fixed(byte *bufferPtr = buffer, destPtr = target.RawData)
                {
                    // Pass 2: Change the bit-depth
                    if (writeFormat.BitDepth != target.Format.BitDepth)
                    {
                        ChangeBitDepth(
                            bufferPtr,
                            target.Format.Channels,
                            writeFormat.BitDepth,
                            target.Format.BitDepth
                            );
                    }

                    // Pass 3: Change the sign
                    if (shouldChangeSign)
                    {
                        if (shouldMakeSigned)
                        {
                            MakeSigned(bufferPtr, target.Format);
                        }
                        else
                        {
                            MakeUnsigned(bufferPtr, target.Format);
                        }
                    }

                    int sampleStart = index * target.Format.Size;

                    MemoryOperations.Copy(destPtr + sampleStart, bufferPtr, target.Format.Size);
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Converts the specified samples to the specified target format.
        /// The specified buffer pointer must be large enough to hold both
        /// the input samples, and the converted output samples.
        /// </summary>
        protected static unsafe void ChangeBitDepth(byte *bufferPtr, byte channels, AudioBitDepth inputBitDepth, AudioBitDepth outputBitDepth)
        {
            // Convert the bit-depth
            //     We have to re-normalize the samples; from the source data type's min and max value,
            //     to the target data type's min and max values - this operation can be represented by
            //     the following formula:
            //        (value / max source data type value) * max target data type value
            //     For example, to convert a 16-bit sample 0x0E to a 32-bit sample:
            //        (14 / 32767) * 2147483647
            //     However, this approach, while the most obvious from a mathematical standpoint,
            //     uses floating-point math. This can be much slower than direct bit-manipulation.
            //     The code below will do the equivalent to the provided formula by using
            //     bit-manipulation operators, making the method much more performant.
            //
            //     By using bit-shifting, we do not have to change the sign of the samples
            //     which is useful for us as we convert the samples in several different passes.

            switch (inputBitDepth)
            {
            case AudioBitDepth.Bits8: {
                // 8 bit -> target bit depth
                byte[] samples = new byte[channels];

                fixed(byte *samplesPtr = samples)
                {
                    MemoryOperations.Copy(samplesPtr, bufferPtr, channels);
                    ChangeBitDepth(bufferPtr, outputBitDepth, channels, samplesPtr);
                }

                break;
            }

            case AudioBitDepth.Bits16: {
                // 16 bit -> target bit depth
                short[] samples = new short[channels];

                fixed(short *samplesPtr = samples)
                {
                    MemoryOperations.Copy((byte *)samplesPtr, bufferPtr, channels * sizeof(short));
                    ChangeBitDepth(bufferPtr, outputBitDepth, channels, samplesPtr);
                }

                break;
            }

            case AudioBitDepth.Bits24: {
                // 24 bit -> target bit depth
                int[] samples = new int[channels];

                for (int j = 0; j < channels; j++)
                {
                    samples[j] = ToInt24(bufferPtr, j * 3);
                }

                fixed(int *samplesPtr = samples)
                {
                    ChangeBitDepth24(bufferPtr, outputBitDepth, channels, samplesPtr);
                }

                break;
            }

            case AudioBitDepth.Bits32: {
                // 32 bit -> target bit depth
                int[] samples = new int[channels];

                fixed(int *samplesPtr = samples)
                {
                    MemoryOperations.Copy((byte *)samplesPtr, bufferPtr, channels * sizeof(int));
                    ChangeBitDepth(bufferPtr, outputBitDepth, channels, samplesPtr);
                }

                break;
            }
            }
        }
Пример #15
0
        static unsafe void *InternalInvoke(void *maddr, int pcnt, void **parameters, void **types, void *ret_vtbl, uint flags)
        {
            /* Modify the types array to contain the call locations of each parameter
             *
             * 0 - INTEGER (pass as-is)
             * 1 - INTEGER (unbox in asm)
             * 2 - SSE (unbox in asm)
             * 3 - MEMORY (upper 24 bits give length of object)
             * 4 - INTEGER (unbox low 32 bits in asm)
             * 5 - INTEGER (unbox to byref in asm)
             */

            for (int i = 0; i < pcnt; i++)
            {
                // handle this pointer
                if (i == 0 && ((flags & TysosMethod.invoke_flag_instance) != 0))
                {
                    if ((flags & TysosMethod.invoke_flag_vt) != 0)
                    {
                        // we need to unbox the this pointer to a managed pointer
                        types[i] = (void *)5;
                    }
                    else
                    {
                        types[i] = (void *)0;
                    }
                }
                else
                {
                    // the type we need is encoded in the vtable
                    var vtbl      = types[i];
                    var cur_class = *((byte *)vtbl + 0x1 + ClassOperations.GetVtblTargetFieldsOffset());
                    types[i] = (void *)cur_class;
                }
            }

            var ret = asm_invoke(maddr, pcnt, parameters, types);

            // See if we have to box the return type
            if (ret_vtbl != null && ((flags & TysosMethod.invoke_flag_vt_ret) != 0))
            {
                // Get the size of the return type
                var tsize = *(int *)((byte *)ret_vtbl + ClassOperations.GetVtblTypeSizeOffset())
                            - ClassOperations.GetBoxedTypeDataOffset();

                /* TODO: handle VTypes that don't fit in a register */
                if (tsize > 8)
                {
                    throw new NotImplementedException("InternalInvoke: return type not supported (size " +
                                                      tsize.ToString() + ")");
                }

                // Build a new boxed version of the type
                var obj = (void **)MemoryOperations.GcMalloc(tsize + ClassOperations.GetBoxedTypeDataOffset());
                *   obj = ret_vtbl;
                *(int *)((byte *)obj + ClassOperations.GetMutexLockOffset()) = 0;

                System.Diagnostics.Debugger.Log(0, "libsupcs", "x86_64_invoke: returning boxed type of size " + tsize.ToString());

                if (tsize > 4)
                {
                    *(long *)((byte *)obj + ClassOperations.GetBoxedTypeDataOffset()) = (long)ret;
                }
                else
                {
                    *(int *)((byte *)obj + ClassOperations.GetBoxedTypeDataOffset()) = (int)((long)ret & 0xffffffff);
                }

                return(obj);
            }
            else if (ret_vtbl == null)
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "x86_64_invoke: returning void");
                return(ret);
            }
            else
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "x86_64_invoke: returning object");
                return(ret);
            }
        }