/[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 507 - (show annotations) (download)
Tue Jun 4 20:33:40 2013 UTC (8 years, 7 months ago) by william
File size: 13557 byte(s)
LogSearchOptions():
* when logging the datatype bit size, alos include the size of the type (1/2/4/8 bytes)

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, ProgressBarWithPercentageLabel _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, ProgressBarWithPercentageLabel _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, ProgressBarWithPercentageLabel _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, ProgressBarWithPercentageLabel _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, ProgressBarWithPercentageLabel _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 ProgressBarWithPercentageLabel _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 ProgressBarWithPercentageLabel ProgressLogger { get { return _ProgressLogger; } set { if (value != null) value.ShowPercentageLabel = true; _ProgressLogger = value; } }
133
134 public bool IsFirstSearch { get { return _IsFirstSearch; } set { _IsFirstSearch = value; } }
135
136 //public List<ResultType<object>> Results { get { return _Results; } set { _Results = value; } }
137
138 public void LogSearchOptions()
139 {
140
141 //StringBuilder builder = new StringBuilder();
142
143 logger.Info.WriteLine("Current Search Options:");
144 int size = 0;
145 BitTools.SizeOf(this.DataType, out size);
146 // write Data type
147 if (size == 1)
148 {
149 logger.Info.WriteLine("Data Type: {0} [{1} byte]", Enum.GetName(typeof(SearchDataTypes), this.DataType), size);
150 }
151 else
152 logger.Info.WriteLine("Data Type: {0} [{1} bytes]", Enum.GetName(typeof(SearchDataTypes), this.DataType), size);
153 {
154 }
155 // write Signed/Unsigned
156 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Signed/Unsigned: {0}", "Unsigned"); }
157 else { logger.Info.WriteLine("Signed/Unsigned: {0}", "Signed"); }
158 // Write Compare Type
159 logger.Info.WriteLine("Comparison Type: {0}", Enum.GetName(typeof(SearchCompareTypes), this.CompareType));
160 // Write Compare Value Tupe
161 logger.Info.WriteLine("Comparison Value Type: {0}", Enum.GetName(typeof(CompareValueTypes), this.CompareValueType));
162 // Write Value
163 if (this.CompareType != SearchCompareTypes.Between && this.CompareType != SearchCompareTypes.NotBetween)
164 {
165 #region Non-Ranged Comparison Value(s)
166 if (this.CompareValueType == CompareValueTypes.SpecificValue)
167 {
168 switch (this.DataType)
169 {
170 case SearchDataTypes._8bits:
171 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToByte(this.CompareStartValue).ToString("x2")); }
172 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToSByte(this.CompareStartValue).ToString("x2")); }
173 break;
174 case SearchDataTypes._16bits:
175 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt16(this.CompareStartValue).ToString("x4")); }
176 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt16(this.CompareStartValue).ToString("x4")); }
177 break;
178 case SearchDataTypes._32bits:
179 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt32(this.CompareStartValue).ToString("x8")); }
180 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt32(this.CompareStartValue).ToString("x8")); }
181 break;
182 case SearchDataTypes._64bits:
183 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt64(this.CompareStartValue).ToString("x16")); }
184 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt64(this.CompareStartValue).ToString("x16")); }
185 break;
186 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
187 }
188 }
189 else
190 {
191 logger.Info.WriteLine("Comparison Value: {0}\n", "ignored");
192 }
193 #endregion
194 }
195 else
196 {
197 #region Ranged Comparison Value(s)
198 switch (this.DataType)
199 {
200 case SearchDataTypes._8bits:
201 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToByte(this.CompareStartValue), Convert.ToByte(this.CompareEndValue)); }
202 else { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToSByte(this.CompareStartValue), Convert.ToSByte(this.CompareEndValue)); }
203 break;
204 case SearchDataTypes._16bits:
205 if (this.IsUnsignedDataType) { logger.Info.WriteLine("CComparison Range: 0x{0:x2} to 0x{1:x4}", Convert.ToUInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
206 else { logger.Info.WriteLine("Comparison Range: 0x{0:x4} to 0x{1:x4}", Convert.ToInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
207 break;
208 case SearchDataTypes._32bits:
209 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToUInt32(this.CompareStartValue), Convert.ToUInt32(this.CompareEndValue)); }
210 else { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToInt32(this.CompareStartValue), Convert.ToInt32(this.CompareEndValue)); }
211 break;
212 case SearchDataTypes._64bits:
213 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToUInt64(this.CompareStartValue), Convert.ToUInt64(this.CompareEndValue)); }
214 else { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToInt64(this.CompareStartValue), Convert.ToInt64(this.CompareEndValue)); }
215 break;
216 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
217 }
218 #endregion
219 }
220
221 //logger.Info.WriteLine(builder.ToString());
222 }
223 #endregion
224
225 //#region ISerializable Members
226
227 //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
228 //{
229 // throw new NotImplementedException();
230 //}
231
232 //#endregion
233 }
234 }

  ViewVC Help
Powered by ViewVC 1.1.22