diff --git a/NTRDebuggerTool/NTRDebuggerTool.csproj b/NTRDebuggerTool/NTRDebuggerTool.csproj index 16a3956..a4005c6 100644 --- a/NTRDebuggerTool/NTRDebuggerTool.csproj +++ b/NTRDebuggerTool/NTRDebuggerTool.csproj @@ -29,7 +29,7 @@ true - AnyCPU + x86 true full false @@ -39,7 +39,7 @@ 4 - AnyCPU + x86 pdbonly true bin\Release\ diff --git a/NTRDebuggerTool/Program.cs b/NTRDebuggerTool/Program.cs index ac4d1d5..91d334a 100644 --- a/NTRDebuggerTool/Program.cs +++ b/NTRDebuggerTool/Program.cs @@ -78,6 +78,7 @@ static void Main(string[] args) { log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType).Error(null, ex); MessageBox.Show("An exception has occurred. Check the log file at " + System.IO.Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + "NTRDebuggerTool-Log.txt"); + Application.Exit(); } } } diff --git a/NTRDebuggerTool/Properties/AssemblyInfo.cs b/NTRDebuggerTool/Properties/AssemblyInfo.cs index e9d0458..9d488f5 100644 --- a/NTRDebuggerTool/Properties/AssemblyInfo.cs +++ b/NTRDebuggerTool/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("290cd39f-c191-4212-9985-0584c9200acc")] -[assembly: AssemblyVersion("0.8.6.1")] -[assembly: AssemblyFileVersion("0.8.6.1")] +[assembly: AssemblyVersion("0.8.6.2")] +[assembly: AssemblyFileVersion("0.8.6.2")] diff --git a/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs index 9313f16..728b67d 100644 --- a/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs +++ b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs @@ -1,7 +1,6 @@ using NTRDebuggerTool.Forms.FormEnums; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using System.Threading; using System.Xml; @@ -322,25 +321,26 @@ private bool CheckCriteria(uint RealAddress, byte[] RemoteValue) { return false; } + return IsIncreasedBy(RealAddress, RemoteValue); return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) == BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0); case SearchTypeBase.DecreasedBy: if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress)) { return false; } - return GetValueFromByteArray(RemoteValue).CompareTo(GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress])) == BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0); + return IsDecreasedBy(RealAddress, RemoteValue); case SearchTypeBase.Increased: if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress)) { return false; } - return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) > 0; + return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) < 0; case SearchTypeBase.Decreased: if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress)) { return false; } - return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) < 0; + return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) > 0; case SearchTypeBase.Same: if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress)) { @@ -358,8 +358,6 @@ private bool CheckCriteria(uint RealAddress, byte[] RemoteValue) default: throw new InvalidOperationException("Invalid search type " + NTRConnection.SearchCriteria[0].SearchType.ToString() + " passed to NTRPacketReceiverThread.CheckCriteria"); } - - } private IComparable GetValueFromByteArray(byte[] Value) @@ -383,6 +381,99 @@ private IComparable GetValueFromByteArray(byte[] Value) } } + private bool IsIncreasedBy(uint RealAddress, byte[] RemoteValue) + { + checked + { + switch (NTRConnection.SearchCriteria[0].DataType) + { + case DataTypeExact.Bytes1: + return NTRConnection.SearchCriteria[0].AddressesFound[RealAddress][0] == + RemoteValue[0] - NTRConnection.SearchCriteria[0].SearchValue[0]; + case DataTypeExact.Bytes2: + return BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt16(RemoteValue, 0) - BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Bytes4: + return BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt32(RemoteValue, 0) - BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Bytes8: + return BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt64(RemoteValue, 0) - BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Float: + return IsLessThan(BitConverter.ToSingle(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0), + BitConverter.ToSingle(RemoteValue, 0) + BitConverter.ToSingle(NTRConnection.SearchCriteria[0].SearchValue, 0)); + case DataTypeExact.Double: + return IsLessThan(BitConverter.ToDouble(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0), + BitConverter.ToDouble(RemoteValue, 0) + BitConverter.ToDouble(NTRConnection.SearchCriteria[0].SearchValue, 0)); + default: + throw new InvalidOperationException("Invalid data type " + NTRConnection.SearchCriteria[0].DataType.ToString() + " passed to NTRPacketReceiverThread.GetValueFromByteArray"); + } + } + } + + private bool IsDecreasedBy(uint RealAddress, byte[] RemoteValue) + { + checked + { + switch (NTRConnection.SearchCriteria[0].DataType) + { + case DataTypeExact.Bytes1: + return NTRConnection.SearchCriteria[0].AddressesFound[RealAddress][0] == + RemoteValue[0] + NTRConnection.SearchCriteria[0].SearchValue[0]; + case DataTypeExact.Bytes2: + return BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt16(RemoteValue, 0) + BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Bytes4: + return BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt32(RemoteValue, 0) + BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Bytes8: + return BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) == + BitConverter.ToUInt64(RemoteValue, 0) + BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].SearchValue, 0); + case DataTypeExact.Float: + return IsGreaterThan(BitConverter.ToSingle(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0), + BitConverter.ToSingle(RemoteValue, 0) + BitConverter.ToSingle(NTRConnection.SearchCriteria[0].SearchValue, 0)); + case DataTypeExact.Double: + return IsGreaterThan(BitConverter.ToDouble(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0), + BitConverter.ToDouble(RemoteValue, 0) + BitConverter.ToDouble(NTRConnection.SearchCriteria[0].SearchValue, 0)); + default: + throw new InvalidOperationException("Invalid data type " + NTRConnection.SearchCriteria[0].DataType.ToString() + " passed to NTRPacketReceiverThread.GetValueFromByteArray"); + } + } + } + + #endregion + + #region Handle comparison of precision numbers (float, double) + + private bool IsLessThan(float Left, float Right) + { + checked + { + return Left < Right + float.Epsilon; + } + } + private bool IsGreaterThan(float Left, float Right) + { + checked + { + return Left + float.Epsilon > Right; + } + } + private bool IsLessThan(double Left, double Right) + { + checked + { + return Left < Right + double.Epsilon; + } + } + private bool IsGreaterThan(double Left, double Right) + { + checked + { + return Left + double.Epsilon > Right; + } + } + #endregion } }