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

  ViewVC Help
Powered by ViewVC 1.1.22