/[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 415 - (show annotations) (download)
Fri Jun 22 08:33:51 2012 UTC (7 years, 7 months ago) by william
File size: 13218 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, 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 // write Data type
145 logger.Info.WriteLine("Data Type: {0}", Enum.GetName(typeof(SearchDataTypes), this.DataType));
146 // write Signed/Unsigned
147 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Signed/Unsigned: {0}", "Unsigned"); }
148 else { logger.Info.WriteLine("Signed/Unsigned: {0}", "Signed"); }
149 // Write Compare Type
150 logger.Info.WriteLine("Comparison Type: {0}", Enum.GetName(typeof(SearchCompareTypes), this.CompareType));
151 // Write Compare Value Tupe
152 logger.Info.WriteLine("Comparison Value Type: {0}", Enum.GetName(typeof(CompareValueTypes), this.CompareValueType));
153 // Write Value
154 if (this.CompareType != SearchCompareTypes.Between && this.CompareType != SearchCompareTypes.NotBetween)
155 {
156 #region Non-Ranged Comparison Value(s)
157 if (this.CompareValueType == CompareValueTypes.SpecificValue)
158 {
159 switch (this.DataType)
160 {
161 case SearchDataTypes._8bits:
162 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToByte(this.CompareStartValue).ToString("x2")); }
163 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToSByte(this.CompareStartValue).ToString("x2")); }
164 break;
165 case SearchDataTypes._16bits:
166 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt16(this.CompareStartValue).ToString("x4")); }
167 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt16(this.CompareStartValue).ToString("x4")); }
168 break;
169 case SearchDataTypes._32bits:
170 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt32(this.CompareStartValue).ToString("x8")); }
171 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt32(this.CompareStartValue).ToString("x8")); }
172 break;
173 case SearchDataTypes._64bits:
174 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt64(this.CompareStartValue).ToString("x16")); }
175 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt64(this.CompareStartValue).ToString("x16")); }
176 break;
177 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
178 }
179 }
180 else
181 {
182 logger.Info.WriteLine("Comparison Value: {0}\n", "ignored");
183 }
184 #endregion
185 }
186 else
187 {
188 #region Ranged Comparison Value(s)
189 switch (this.DataType)
190 {
191 case SearchDataTypes._8bits:
192 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToByte(this.CompareStartValue), Convert.ToByte(this.CompareEndValue)); }
193 else { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToSByte(this.CompareStartValue), Convert.ToSByte(this.CompareEndValue)); }
194 break;
195 case SearchDataTypes._16bits:
196 if (this.IsUnsignedDataType) { logger.Info.WriteLine("CComparison Range: 0x{0:x2} to 0x{1:x4}", Convert.ToUInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
197 else { logger.Info.WriteLine("Comparison Range: 0x{0:x4} to 0x{1:x4}", Convert.ToInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
198 break;
199 case SearchDataTypes._32bits:
200 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToUInt32(this.CompareStartValue), Convert.ToUInt32(this.CompareEndValue)); }
201 else { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToInt32(this.CompareStartValue), Convert.ToInt32(this.CompareEndValue)); }
202 break;
203 case SearchDataTypes._64bits:
204 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToUInt64(this.CompareStartValue), Convert.ToUInt64(this.CompareEndValue)); }
205 else { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToInt64(this.CompareStartValue), Convert.ToInt64(this.CompareEndValue)); }
206 break;
207 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
208 }
209 #endregion
210 }
211
212 //logger.Info.WriteLine(builder.ToString());
213 }
214 #endregion
215
216 //#region ISerializable Members
217
218 //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
219 //{
220 // throw new NotImplementedException();
221 //}
222
223 //#endregion
224 }
225 }

  ViewVC Help
Powered by ViewVC 1.1.22