/[RomCheater]/trunk/RomCheater/Docking/MemorySearch/SearchType.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/MemorySearch/SearchType.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 526 - (show annotations) (download)
Wed Jun 5 08:03:28 2013 UTC (7 years, 3 months ago) by william
File size: 13595 byte(s)

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3
4 #region Enabled logging levels
5 #define LOGGING_ENABLE_INFO
6 #define LOGGING_ENABLE_WARN
7 #define LOGGING_ENABLE_DEBUG
8 #define LOGGING_ENABLE_VERBOSEDEBUG
9 #define LOGGING_ENABLE_ERROR
10 #define LOGGING_ENABLE_VERBOSEERROR
11 #define LOGGING_ENABLE_PROFILER
12 #endregion
13 #endregion
14 using System;
15 using System.Collections.Generic;
16 using System.Linq;
17 using System.Text;
18 using Utilities.TransparentControls;
19 using RomCheater.Logging;
20 using RomCheater.Core;
21
22 namespace RomCheater.Docking.MemorySearch
23 {
24 public class SearchType : ISearchType//, ISerializable
25 {
26 #region Implicit Concersion
27 public static implicit operator SearchType(OnlySearchType search)
28 {
29 SearchType _search_type = new SearchType(search.DataType, search.IsUnsignedDataType, search.CompareType, search.CompareValueType, search.CompareStartValue, search.CompareEndValue, null);
30 _search_type.IsFirstSearch = search.IsFirstSearch;
31 //_search_type.Results = search.Results;
32 return _search_type;
33 }
34 #endregion
35 //const SearchDataTypes Default_DataType = SearchDataTypes._8bits;
36 const bool Default_UnsignedState = true;
37 const SearchDataTypes Default_SarechType = SearchDataTypes._32bits;
38 const SearchCompareTypes Default_CompareType = SearchCompareTypes.Equal;
39 const CompareValueTypes Default_CompareValueType = CompareValueTypes.OldValue;
40 const byte Default_CompareValue = 0;
41
42 #region default constructors
43 public SearchType() : this(Default_SarechType, Default_UnsignedState, Default_CompareType, Default_CompareValueType, Default_CompareValue) { }
44 public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object value)
45 : this(_data_type, _is_unsigned, _compare_type, _compare_value_type, value, null, null)
46 {
47 }
48 public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object start_value, object end_value, CustomProgressBar _progress_logger)
49 {
50 this.DataType = _data_type;
51 this.IsUnsignedDataType = _is_unsigned;
52 this.CompareType = _compare_type;
53 this.CompareValueType = _compare_value_type;
54 this.CompareStartValue = start_value;
55 this.CompareEndValue = end_value;
56 this.ProgressLogger = _progress_logger;
57 }
58 #endregion
59
60 #region 8bit specific constructors
61 public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
62 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
63 {
64 }
65 public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, CustomProgressBar _progress_logger)
66 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
67 {
68 this.DataType = SearchDataTypes._8bits;
69 }
70 #endregion
71
72 #region 16bit specific constructors
73 public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
74 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
75 {
76 }
77 public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, CustomProgressBar _progress_logger)
78 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
79 {
80 this.DataType = SearchDataTypes._16bits;
81 }
82 #endregion
83
84 #region 32bit specific constructors
85 public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
86 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
87 {
88 }
89 public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, CustomProgressBar _progress_logger)
90 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
91 {
92 this.DataType = SearchDataTypes._32bits;
93 }
94 #endregion
95
96 #region 64bit specific constructors
97 public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
98 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
99 {
100 }
101 public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, CustomProgressBar _progress_logger)
102 {
103 this.DataType = SearchDataTypes._64bits;
104 this.IsUnsignedDataType = _is_unsigned;
105 this.CompareType = _compare_type;
106 this.CompareValueType = _compare_value_type;
107 this.CompareStartValue = start_value;
108 this.CompareEndValue = end_value;
109 this.ProgressLogger = null;
110 }
111 #endregion
112 #region ISearchType Members
113
114 private SearchDataTypes _DataType;
115 private bool _IsUnsignedDataType;
116 private SearchCompareTypes _CompareType;
117 private CompareValueTypes _CompareValueType;
118 private object _CompareStartValue;
119 private object _CompareEndValue;
120 private CustomProgressBar _ProgressLogger;
121
122 private bool _IsFirstSearch;
123 //private List<ResultType<object>> _Results = new List<ResultType<object>>();
124
125 public SearchDataTypes DataType { get { return _DataType; } set { _DataType = value; } }
126 public bool IsUnsignedDataType { get { return _IsUnsignedDataType; } set { _IsUnsignedDataType = value; } }
127 public SearchCompareTypes CompareType { get { return _CompareType; } set { _CompareType = value; } }
128 public CompareValueTypes CompareValueType { get { return _CompareValueType; } set { _CompareValueType = value; } }
129
130 public object CompareStartValue { get { return _CompareStartValue; } set { _CompareStartValue = value; } }
131 public object CompareEndValue { get { return _CompareEndValue; } set { _CompareEndValue = value; } }
132
133 public CustomProgressBar ProgressLogger
134 {
135 get { return _ProgressLogger; }
136 set
137 {
138 if (value != null) value.ShowPercentageLabel = true;
139 _ProgressLogger = value;
140 }
141 }
142
143 public bool IsFirstSearch { get { return _IsFirstSearch; } set { _IsFirstSearch = value; } }
144
145 //public List<ResultType<object>> Results { get { return _Results; } set { _Results = value; } }
146
147 public void LogSearchOptions()
148 {
149
150 //StringBuilder builder = new StringBuilder();
151
152 logger.Info.WriteLine("Current Search Options:");
153 int size = 0;
154 BitTools.SizeOf(this.DataType, out size);
155 // write Data type
156 if (size == 1)
157 {
158 logger.Info.WriteLine("Data Type: {0} [{1} byte]", Enum.GetName(typeof(SearchDataTypes), this.DataType), size);
159 }
160 else
161 logger.Info.WriteLine("Data Type: {0} [{1} bytes]", Enum.GetName(typeof(SearchDataTypes), this.DataType), size);
162 {
163 }
164 // write Signed/Unsigned
165 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Signed/Unsigned: {0}", "Unsigned"); }
166 else { logger.Info.WriteLine("Signed/Unsigned: {0}", "Signed"); }
167 // Write Compare Type
168 logger.Info.WriteLine("Comparison Type: {0}", Enum.GetName(typeof(SearchCompareTypes), this.CompareType));
169 // Write Compare Value Tupe
170 logger.Info.WriteLine("Comparison Value Type: {0}", Enum.GetName(typeof(CompareValueTypes), this.CompareValueType));
171 // Write Value
172 if (this.CompareType != SearchCompareTypes.Between && this.CompareType != SearchCompareTypes.NotBetween)
173 {
174 #region Non-Ranged Comparison Value(s)
175 if (this.CompareValueType == CompareValueTypes.SpecificValue)
176 {
177 switch (this.DataType)
178 {
179 case SearchDataTypes._8bits:
180 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToByte(this.CompareStartValue).ToString("x2")); }
181 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToSByte(this.CompareStartValue).ToString("x2")); }
182 break;
183 case SearchDataTypes._16bits:
184 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt16(this.CompareStartValue).ToString("x4")); }
185 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt16(this.CompareStartValue).ToString("x4")); }
186 break;
187 case SearchDataTypes._32bits:
188 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt32(this.CompareStartValue).ToString("x8")); }
189 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt32(this.CompareStartValue).ToString("x8")); }
190 break;
191 case SearchDataTypes._64bits:
192 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt64(this.CompareStartValue).ToString("x16")); }
193 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt64(this.CompareStartValue).ToString("x16")); }
194 break;
195 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
196 }
197 }
198 else
199 {
200 logger.Info.WriteLine("Comparison Value: {0}\n", "ignored");
201 }
202 #endregion
203 }
204 else
205 {
206 #region Ranged Comparison Value(s)
207 switch (this.DataType)
208 {
209 case SearchDataTypes._8bits:
210 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToByte(this.CompareStartValue), Convert.ToByte(this.CompareEndValue)); }
211 else { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToSByte(this.CompareStartValue), Convert.ToSByte(this.CompareEndValue)); }
212 break;
213 case SearchDataTypes._16bits:
214 if (this.IsUnsignedDataType) { logger.Info.WriteLine("CComparison Range: 0x{0:x2} to 0x{1:x4}", Convert.ToUInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
215 else { logger.Info.WriteLine("Comparison Range: 0x{0:x4} to 0x{1:x4}", Convert.ToInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
216 break;
217 case SearchDataTypes._32bits:
218 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToUInt32(this.CompareStartValue), Convert.ToUInt32(this.CompareEndValue)); }
219 else { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToInt32(this.CompareStartValue), Convert.ToInt32(this.CompareEndValue)); }
220 break;
221 case SearchDataTypes._64bits:
222 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToUInt64(this.CompareStartValue), Convert.ToUInt64(this.CompareEndValue)); }
223 else { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToInt64(this.CompareStartValue), Convert.ToInt64(this.CompareEndValue)); }
224 break;
225 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
226 }
227 #endregion
228 }
229
230 //logger.Info.WriteLine(builder.ToString());
231 }
232 #endregion
233
234 //#region ISerializable Members
235
236 //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
237 //{
238 // throw new NotImplementedException();
239 //}
240
241 //#endregion
242 }
243 }

  ViewVC Help
Powered by ViewVC 1.1.22