diff --git a/Reloaded.Memory.SigScan.Tests/ScannerTests.cs b/Reloaded.Memory.SigScan.Tests/ScannerTests.cs index a2f5c71..b4b3bc9 100644 --- a/Reloaded.Memory.SigScan.Tests/ScannerTests.cs +++ b/Reloaded.Memory.SigScan.Tests/ScannerTests.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using Reloaded.Memory.Sigscan; +using Reloaded.Memory.Sigscan.Definitions.Structs; using Xunit; namespace Reloaded.Memory.SigScan.Tests @@ -148,5 +149,31 @@ public void PatternNotFound() Assert.False(resultCompiled.Found); Assert.Equal(-1, resultCompiled.Offset); } + + [Fact] + public void FindAtOffset() + { + var scanner = new Scanner(_data); + var expectedOffsets = new int[] + { + 2, + 254 + }; + + var numFound = 0; + var lastOffset = -1; + + while (true) + { + + lastOffset = scanner.FindPattern("7A", lastOffset + 1).Offset; + if (lastOffset == -1) + break; + + Assert.Equal(expectedOffsets[numFound++], lastOffset); + } + + Assert.Equal(2, numFound); + } } } diff --git a/Reloaded.Memory.Sigscan/Scanner.cs b/Reloaded.Memory.Sigscan/Scanner.cs index 397ece9..407b5f1 100644 --- a/Reloaded.Memory.Sigscan/Scanner.cs +++ b/Reloaded.Memory.Sigscan/Scanner.cs @@ -124,13 +124,13 @@ public PatternScanResult FindPattern(string pattern, int offset) { #if SIMD_INTRINSICS if (Avx2.IsSupported) - return FindPatternAvx2(_dataPtr + offset, _dataLength - offset, pattern); + return FindPatternAvx2(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset); if (Sse2.IsSupported) - return FindPatternSse2(_dataPtr + offset, _dataLength - offset, pattern); + return FindPatternSse2(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset); #endif - return FindPatternCompiled(_dataPtr + offset, _dataLength - offset, pattern); + return FindPatternCompiled(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset); } ///