Skip to content

Commit e611be5

Browse files
committed
Match other comparer logic.
1 parent 64b9479 commit e611be5

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

ReClass.NET/MemoryScanner/Comparer/DoubleMemoryComparer.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ private bool CheckRoundedEquality(double value) =>
4242

4343
public bool Compare(byte[] data, int index, out ScanResult result)
4444
{
45-
result = null;
46-
47-
var value = BitConverter.ToDouble(data, index);
48-
49-
bool IsMatch() =>
50-
CompareType switch
45+
return CompareInternal(
46+
data,
47+
index,
48+
value => CompareType switch
5149
{
5250
ScanCompareType.Equal => CheckRoundedEquality(value),
5351
ScanCompareType.NotEqual => !CheckRoundedEquality(value),
@@ -59,18 +57,11 @@ bool IsMatch() =>
5957
ScanCompareType.BetweenOrEqual => Value1 <= value && value <= Value2,
6058
ScanCompareType.Unknown => true,
6159
_ => throw new InvalidCompareTypeException(CompareType)
62-
};
63-
64-
if (!IsMatch())
65-
{
66-
return false;
60+
},
61+
out result
62+
);
6763
}
6864

69-
result = new DoubleScanResult(value);
70-
71-
return true;
72-
}
73-
7465
public bool Compare(byte[] data, int index, ScanResult previous, out ScanResult result)
7566
{
7667
#if DEBUG
@@ -82,12 +73,10 @@ public bool Compare(byte[] data, int index, ScanResult previous, out ScanResult
8273

8374
public bool Compare(byte[] data, int index, DoubleScanResult previous, out ScanResult result)
8475
{
85-
result = null;
86-
87-
var value = BitConverter.ToDouble(data, index);
88-
89-
bool IsMatch() =>
90-
CompareType switch
76+
return CompareInternal(
77+
data,
78+
index,
79+
value => CompareType switch
9180
{
9281
ScanCompareType.Equal => CheckRoundedEquality(value),
9382
ScanCompareType.NotEqual => !CheckRoundedEquality(value),
@@ -104,9 +93,18 @@ bool IsMatch() =>
10493
ScanCompareType.Between => Value1 < value && value < Value2,
10594
ScanCompareType.BetweenOrEqual => Value1 <= value && value <= Value2,
10695
_ => throw new InvalidCompareTypeException(CompareType)
107-
};
96+
},
97+
out result
98+
);
99+
}
100+
101+
private static bool CompareInternal(byte[] data, int index, Func<double, bool> matcher, out ScanResult result)
102+
{
103+
result = null;
104+
105+
var value = BitConverter.ToDouble(data, index);
108106

109-
if (!IsMatch())
107+
if (!matcher(value))
110108
{
111109
return false;
112110
}

ReClass.NET/MemoryScanner/Comparer/FloatMemoryComparer.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ private bool CheckRoundedEquality(float value) =>
4242

4343
public bool Compare(byte[] data, int index, out ScanResult result)
4444
{
45-
result = null;
46-
47-
var value = BitConverter.ToSingle(data, index);
48-
49-
bool IsMatch() =>
50-
CompareType switch
45+
return CompareInternal(
46+
data,
47+
index,
48+
value => CompareType switch
5149
{
5250
ScanCompareType.Equal => CheckRoundedEquality(value),
5351
ScanCompareType.NotEqual => !CheckRoundedEquality(value),
@@ -59,18 +57,11 @@ bool IsMatch() =>
5957
ScanCompareType.BetweenOrEqual => Value1 <= value && value <= Value2,
6058
ScanCompareType.Unknown => true,
6159
_ => throw new InvalidCompareTypeException(CompareType)
62-
};
63-
64-
if (!IsMatch())
65-
{
66-
return false;
60+
},
61+
out result
62+
);
6763
}
6864

69-
result = new FloatScanResult(value);
70-
71-
return true;
72-
}
73-
7465
public bool Compare(byte[] data, int index, ScanResult previous, out ScanResult result)
7566
{
7667
#if DEBUG
@@ -82,12 +73,10 @@ public bool Compare(byte[] data, int index, ScanResult previous, out ScanResult
8273

8374
public bool Compare(byte[] data, int index, FloatScanResult previous, out ScanResult result)
8475
{
85-
result = null;
86-
87-
var value = BitConverter.ToSingle(data, index);
88-
89-
bool IsMatch() =>
90-
CompareType switch
76+
return CompareInternal(
77+
data,
78+
index,
79+
value => CompareType switch
9180
{
9281
ScanCompareType.Equal => CheckRoundedEquality(value),
9382
ScanCompareType.NotEqual => !CheckRoundedEquality(value),
@@ -104,9 +93,18 @@ bool IsMatch() =>
10493
ScanCompareType.Between => Value1 < value && value < Value2,
10594
ScanCompareType.BetweenOrEqual => Value1 <= value && value <= Value2,
10695
_ => throw new InvalidCompareTypeException(CompareType)
107-
};
96+
},
97+
out result
98+
);
99+
}
100+
101+
private static bool CompareInternal(byte[] data, int index, Func<float, bool> matcher, out ScanResult result)
102+
{
103+
result = null;
104+
105+
var value = BitConverter.ToSingle(data, index);
108106

109-
if (!IsMatch())
107+
if (!matcher(value))
110108
{
111109
return false;
112110
}

0 commit comments

Comments
 (0)