コード例 #1
0
        public unsafe static T Read <T>(IMemoryManager memory, long position) where T : struct
        {
            long size = Marshal.SizeOf <T>();

            byte[] data = memory.ReadBytes(position, size);

            fixed(byte *ptr = data)
            {
                return(Marshal.PtrToStructure <T>((IntPtr)ptr));
            }
        }
コード例 #2
0
ファイル: MemoryPattern.cs プロジェクト: casualshammy/FMemory
        /// <summary>
        ///     Actually finds memory block for pattern
        /// </summary>
        /// <param name="bm">Instance of <see cref="MemoryManager"/> to use for search</param>
        /// <returns>Enumerable of <see cref="IntPtr"/> with found addresses</returns>
        private IEnumerable <IntPtr> FindMaskAddress(IMemoryManager bm)
        {
            System.Diagnostics.ProcessModule mainModule = bm.Process.MainModule;
            IntPtr mainModuleBaseAddress = mainModule.BaseAddress;
            long   mainModuleSize        = mainModule.ModuleMemorySize;
            long   patternLength         = p_bytes.LongLength;

            for (long offset = 0; offset < mainModuleSize - patternLength; offset += p_cacheSize - patternLength)
            {
                byte[] cacheBytes = bm.ReadBytes(mainModuleBaseAddress + (int)offset, (int)(p_cacheSize > mainModuleSize - offset ? mainModuleSize - offset : p_cacheSize));
                for (uint offsetInCacheBytes = 0; offsetInCacheBytes < cacheBytes.Length - patternLength; offsetInCacheBytes++)
                {
                    if (DataCompare(cacheBytes, offsetInCacheBytes))
                    {
                        yield return(mainModuleBaseAddress + (int)(offset + offsetInCacheBytes));
                    }
                }
            }
        }
コード例 #3
0
ファイル: VoiceContext.cs プロジェクト: VioletteLam/Ryujinx
        private void UpdateBuffer(IMemoryManager memory)
        {
            // TODO: Implement conversion for formats other
            // than interleaved stereo (2 channels).
            // As of now, it assumes that HostChannelsCount == 2.
            WaveBuffer wb = WaveBuffers[_bufferIndex];

            if (wb.Position == 0)
            {
                _samples = new int[0];

                return;
            }

            if (SampleFormat == SampleFormat.PcmInt16)
            {
                int samplesCount = (int)(wb.Size / (sizeof(short) * ChannelsCount));

                _samples = new int[samplesCount * AudioRendererConsts.HostChannelsCount];

                if (ChannelsCount == 1)
                {
                    for (int index = 0; index < samplesCount; index++)
                    {
                        short sample = memory.ReadInt16(wb.Position + index * 2);

                        _samples[index * 2 + 0] = sample;
                        _samples[index * 2 + 1] = sample;
                    }
                }
                else
                {
                    for (int index = 0; index < samplesCount * 2; index++)
                    {
                        _samples[index] = memory.ReadInt16(wb.Position + index * 2);
                    }
                }
            }
            else if (SampleFormat == SampleFormat.Adpcm)
            {
                byte[] buffer = memory.ReadBytes(wb.Position, wb.Size);

                _samples = AdpcmDecoder.Decode(buffer, AdpcmCtx);
            }
            else
            {
                throw new InvalidOperationException();
            }

            if (SampleRate != AudioRendererConsts.HostSampleRate)
            {
                // TODO: We should keep the frames being discarded (see the 4 below)
                // on a buffer and include it on the next samples buffer, to allow
                // the resampler to do seamless interpolation between wave buffers.
                int samplesCount = _samples.Length / AudioRendererConsts.HostChannelsCount;

                samplesCount = Math.Max(samplesCount - 4, 0);

                _samples = Resampler.Resample2Ch(
                    _samples,
                    SampleRate,
                    AudioRendererConsts.HostSampleRate,
                    samplesCount,
                    ref _resamplerFracPart);
            }
        }