public unsafe void IndexOf()
        {
            // Pull random elements <Count> times and verify that IndexOf returns correct value.
            Random randomNumberGenerator = new Random();

            // Fill in byte array with ascending numbers.
            int    upperBound = 1000;
            IntPtr ptr        = _currentProcess.Allocate(upperBound * sizeof(int));
            var    arrayPtr   = new FixedArrayPtr <int>((ulong)ptr, upperBound);

            for (int x = 0; x < upperBound; x++)
            {
                arrayPtr.Set(ref x, x);
            }

            // Test IndexOf
            for (int x = 0; x < arrayPtr.Count; x++)
            {
                int randomIndex = randomNumberGenerator.Next(0, arrayPtr.Count);
                arrayPtr.Get(out var value, randomIndex);
                Assert.Equal(randomIndex, arrayPtr.IndexOf(value));
            }

            // Test nonexisting item.
            int notInArray = upperBound + 1;

            Assert.Equal(-1, arrayPtr.IndexOf(notInArray));

            // Cleanup
            _currentProcess.Free(ptr);
        }
示例#2
0
        public void FromToPtr()
        {
            // Build array of random integer structs.
            int randomStructNumber = 1000;

            RandomIntStruct[] randomIntegers = new RandomIntStruct[randomStructNumber];

            for (int x = 0; x < randomStructNumber; x++)
            {
                randomIntegers[x] = RandomIntStruct.BuildRandomStruct();
            }

            // Allocate memory for these structs.
            IntPtr memoryPtr = _currentProcess.Allocate(Reloaded.Memory.StructArray.GetSize <RandomIntStruct>(randomStructNumber));

            // Write random int struct array to pointer.
            Reloaded.Memory.StructArray.ToPtr(memoryPtr, randomIntegers);

            // Read back struct array from pointer.
            Reloaded.Memory.StructArray.FromPtr <RandomIntStruct>(memoryPtr, out var randomIntegersCopy, randomStructNumber);

            // Now compare old and new array.
            Assert.Equal(randomIntegers, randomIntegersCopy);

            // Cleanup
            _currentProcess.Free(memoryPtr);
        }
        /// <summary>
        /// Set up this function by copying over an array of Sonic Adventure physics.
        /// </summary>
        public FixedArrayPtr()
        {
            // Read in the Sonic Adventure physics array from file, then copy over to self-allocated memory.
            byte[] bytes = File.ReadAllBytes("phys.bin");

            _currentProcess        = new Reloaded.Memory.Sources.Memory();
            _adventurePhysicsArray = _currentProcess.Allocate(bytes.Length);
            _currentProcess.WriteRaw(_adventurePhysicsArray, bytes);
            _fixedArrayPtr = new FixedArrayPtr <AdventurePhysics>((ulong)_adventurePhysicsArray, PhysicsArrayLength);
        }
示例#4
0
        /// <summary>
        /// Set up this function by copying over an array of Sonic Adventure physics.
        /// </summary>
        public IArrayPtrGenerator()
        {
            // Read in the Sonic Adventure physics array from file, then copy over to self-allocated memory.
            byte[] bytes = File.ReadAllBytes("phys.bin");

            AdventurePhysicsArray = CurrentProcess.Allocate(bytes.Length);
            CurrentProcess.WriteRaw(AdventurePhysicsArray, bytes);

            _data = new List <object[]>
            {
                new object[] { new Reloaded.Memory.Pointers.ArrayPtr <AdventurePhysics>((ulong)AdventurePhysicsArray, false, CurrentProcess) },
                new object[] { new Reloaded.Memory.Pointers.FixedArrayPtr <AdventurePhysics>((ulong)AdventurePhysicsArray, 10, false, CurrentProcess) }
            };
        }