Skip to content

Commit 4bc3d72

Browse files
committed
Added ScanResult.ValueSize.
1 parent 8b091bb commit 4bc3d72

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

ReClass.NET/MemoryScanner/ScanResult.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ public abstract class ScanResult
1111

1212
public IntPtr Address { get; set; }
1313

14+
public abstract int ValueSize { get; }
15+
1416
public abstract ScanResult Clone();
1517
}
1618

1719
public class ByteScanResult : ScanResult, IEquatable<ByteScanResult>
1820
{
1921
public override ScanValueType ValueType => ScanValueType.Byte;
2022

23+
public override int ValueSize => sizeof(byte);
24+
2125
public byte Value { get; }
2226

2327
public ByteScanResult(byte value)
@@ -50,6 +54,8 @@ public class ShortScanResult : ScanResult, IEquatable<ShortScanResult>
5054
{
5155
public override ScanValueType ValueType => ScanValueType.Short;
5256

57+
public override int ValueSize => sizeof(short);
58+
5359
public short Value { get; }
5460

5561
public ShortScanResult(short value)
@@ -82,6 +88,8 @@ public class IntegerScanResult : ScanResult, IEquatable<IntegerScanResult>
8288
{
8389
public override ScanValueType ValueType => ScanValueType.Integer;
8490

91+
public override int ValueSize => sizeof(int);
92+
8593
public int Value { get; }
8694

8795
public IntegerScanResult(int value)
@@ -114,6 +122,8 @@ public class LongScanResult : ScanResult, IEquatable<LongScanResult>
114122
{
115123
public override ScanValueType ValueType => ScanValueType.Long;
116124

125+
public override int ValueSize => sizeof(long);
126+
117127
public long Value { get; }
118128

119129
public LongScanResult(long value)
@@ -146,6 +156,8 @@ public class FloatScanResult : ScanResult, IEquatable<FloatScanResult>
146156
{
147157
public override ScanValueType ValueType => ScanValueType.Float;
148158

159+
public override int ValueSize => sizeof(float);
160+
149161
public float Value { get; }
150162

151163
public FloatScanResult(float value)
@@ -178,6 +190,8 @@ public class DoubleScanResult : ScanResult, IEquatable<DoubleScanResult>
178190
{
179191
public override ScanValueType ValueType => ScanValueType.Double;
180192

193+
public override int ValueSize => sizeof(double);
194+
181195
public double Value { get; }
182196

183197
public DoubleScanResult(double value)
@@ -210,6 +224,8 @@ public class ArrayOfBytesScanResult : ScanResult, IEquatable<ArrayOfBytesScanRes
210224
{
211225
public override ScanValueType ValueType => ScanValueType.ArrayOfBytes;
212226

227+
public override int ValueSize => Value.Length;
228+
213229
public byte[] Value { get; }
214230

215231
public ArrayOfBytesScanResult(byte[] value)
@@ -244,6 +260,8 @@ public class StringScanResult : ScanResult, IEquatable<StringScanResult>
244260
{
245261
public override ScanValueType ValueType => ScanValueType.String;
246262

263+
public override int ValueSize => Value.Length;
264+
247265
public string Value { get; }
248266

249267
public Encoding Encoding { get; }

ReClass.NET/MemoryScanner/Scanner.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private Task<bool> FirstScan(IScanComparer comparer, IProgress<int> progress, Ca
244244
.ToList();
245245
if (results.Count > 0)
246246
{
247-
var block = CreateResultBlock(results, start, comparer.ValueSize);
247+
var block = CreateResultBlock(results, start);
248248
store.AddBlock(block); // Store the result block.
249249
}
250250
}
@@ -309,7 +309,7 @@ private Task<bool> NextScan(IScanComparer comparer, IProgress<int> progress, Can
309309
.ToList();
310310
if (results.Count > 0)
311311
{
312-
var block = CreateResultBlock(results, b.Start, comparer.ValueSize);
312+
var block = CreateResultBlock(results, b.Start);
313313
store.AddBlock(block);
314314
}
315315
}
@@ -375,16 +375,18 @@ private static List<ConsolidatedMemoryRegion> ConsolidateSections(IList<Section>
375375
/// </summary>
376376
/// <param name="results">The results in this block.</param>
377377
/// <param name="previousStartAddress">The start address of the previous block or section.</param>
378-
/// <param name="valueSize">The size of the value type.</param>
379378
/// <returns>The new result block.</returns>
380-
private static ScanResultBlock CreateResultBlock(IReadOnlyList<ScanResult> results, IntPtr previousStartAddress, int valueSize)
379+
private static ScanResultBlock CreateResultBlock(IReadOnlyList<ScanResult> results, IntPtr previousStartAddress)
381380
{
381+
var firstResult = results.First();
382+
var lastResult = results.Last();
383+
382384
// Calculate start and end address
383-
var startAddress = results.First().Address.Add(previousStartAddress);
384-
var endAddress = results.Last().Address.Add(previousStartAddress) + valueSize;
385+
var startAddress = firstResult.Address.Add(previousStartAddress);
386+
var endAddress = lastResult.Address.Add(previousStartAddress) + lastResult.ValueSize;
385387

386388
// Adjust the offsets of the results
387-
var firstOffset = results.First().Address;
389+
var firstOffset = firstResult.Address;
388390
foreach (var result in results)
389391
{
390392
result.Address = result.Address.Sub(firstOffset);

0 commit comments

Comments
 (0)