using System; using System.Collections.Generic; using System.Linq; using System.Text; using Utilities.TransparentControls; using RomCheater.Logging; namespace RomCheater.Docking.MemorySearch { public class SearchType : ISearchType//, ISerializable { #region Implicit Concersion public static implicit operator SearchType(OnlySearchType search) { SearchType _search_type = new SearchType(search.DataType, search.IsUnsignedDataType, search.CompareType, search.CompareValueType, search.CompareStartValue, search.CompareEndValue, null); _search_type.IsFirstSearch = search.IsFirstSearch; _search_type.Results = search.Results; return _search_type; } #endregion //const SearchDataTypes Default_DataType = SearchDataTypes._8bits; const bool Default_UnsignedState = true; const SearchDataTypes Default_SarechType = SearchDataTypes._32bits; const SearchCompareTypes Default_CompareType = SearchCompareTypes.Equal; const CompareValueTypes Default_CompareValueType = CompareValueTypes.OldValue; const byte Default_CompareValue = 0; #region default constructors public SearchType() : this(Default_SarechType, Default_UnsignedState, Default_CompareType, Default_CompareValueType, Default_CompareValue) { } public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object value) : this(_data_type, _is_unsigned, _compare_type, _compare_value_type, value, null, null) { } public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object start_value, object end_value, ProgressBarWithPercentageLabel _progress_logger) { this.DataType = _data_type; this.IsUnsignedDataType = _is_unsigned; this.CompareType = _compare_type; this.CompareValueType = _compare_value_type; this.CompareStartValue = start_value; this.CompareEndValue = end_value; this.ProgressLogger = _progress_logger; } #endregion #region 8bit specific constructors public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type) : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null) { } public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger) : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger) { this.DataType = SearchDataTypes._8bits; } #endregion #region 16bit specific constructors public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type) : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null) { } public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger) : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger) { this.DataType = SearchDataTypes._16bits; } #endregion #region 32bit specific constructors public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type) : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null) { } public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger) : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger) { this.DataType = SearchDataTypes._32bits; } #endregion #region 64bit specific constructors public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type) : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null) { } public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger) { this.DataType = SearchDataTypes._64bits; this.IsUnsignedDataType = _is_unsigned; this.CompareType = _compare_type; this.CompareValueType = _compare_value_type; this.CompareStartValue = start_value; this.CompareEndValue = end_value; this.ProgressLogger = null; } #endregion #region ISearchType Members private SearchDataTypes _DataType; private bool _IsUnsignedDataType; private SearchCompareTypes _CompareType; private CompareValueTypes _CompareValueType; private object _CompareStartValue; private object _CompareEndValue; private ProgressBarWithPercentageLabel _ProgressLogger; private bool _IsFirstSearch; private List> _Results = new List>(); public SearchDataTypes DataType { get { return _DataType; } set { _DataType = value; } } public bool IsUnsignedDataType { get { return _IsUnsignedDataType; } set { _IsUnsignedDataType = value; } } public SearchCompareTypes CompareType { get { return _CompareType; } set { _CompareType = value; } } public CompareValueTypes CompareValueType { get { return _CompareValueType; } set { _CompareValueType = value; } } public object CompareStartValue { get { return _CompareStartValue; } set { _CompareStartValue = value; } } public object CompareEndValue { get { return _CompareEndValue; } set { _CompareEndValue = value; } } public ProgressBarWithPercentageLabel ProgressLogger { get { return _ProgressLogger; } set { if (value != null) value.ShowPercentageLabel = true; _ProgressLogger = value; } } public bool IsFirstSearch { get { return _IsFirstSearch; } set { _IsFirstSearch = value; } } public List> Results { get { return _Results; } set { _Results = value; } } public void LogSearchOptions() { StringBuilder builder = new StringBuilder(); builder.AppendLine("Current Search Options:"); // write Data type builder.AppendFormat("Data Type: {0}\n", Enum.GetName(typeof(SearchDataTypes), this.DataType)); // write Signed/Unsigned if (this.IsUnsignedDataType) { builder.AppendFormat("Signed/Unsigned: {0}\n", "Unsigned"); } else { builder.AppendFormat("Signed/Unsigned: {0}\n", "Signed"); } // Write Compare Type builder.AppendFormat("Comparison Type: {0}\n", Enum.GetName(typeof(SearchCompareTypes), this.CompareType)); // Write Compare Value Tupe builder.AppendFormat("Comparison Value Type: {0}\n", Enum.GetName(typeof(CompareValueTypes), this.CompareValueType)); // Write Value if (this.CompareType != SearchCompareTypes.Between && this.CompareType != SearchCompareTypes.NotBetween) { #region Non-Ranged Comparison Value(s) if (this.CompareValueType == CompareValueTypes.SpecificValue) { switch (this.DataType) { case SearchDataTypes._8bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToByte(this.CompareStartValue).ToString("x2")); } else { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToSByte(this.CompareStartValue).ToString("x2")); } break; case SearchDataTypes._16bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToUInt16(this.CompareStartValue).ToString("x4")); } else { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToInt16(this.CompareStartValue).ToString("x4")); } break; case SearchDataTypes._32bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToUInt32(this.CompareStartValue).ToString("x8")); } else { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToInt32(this.CompareStartValue).ToString("x8")); } break; case SearchDataTypes._64bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToUInt64(this.CompareStartValue).ToString("x16")); } else { builder.AppendFormat("Comparison Value: 0x{0}\n", Convert.ToInt64(this.CompareStartValue).ToString("x16")); } break; default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type."); } } else { builder.AppendFormat("Comparison Value: {0}\n", "ignored"); } #endregion } else { #region Ranged Comparison Value(s) switch (this.DataType) { case SearchDataTypes._8bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Range: 0x{0:x2} to 0x{1:x2}\n", Convert.ToByte(this.CompareStartValue), Convert.ToByte(this.CompareEndValue)); } else { builder.AppendFormat("Comparison Range: 0x{0:x2} to 0x{1:x2}\n", Convert.ToSByte(this.CompareStartValue), Convert.ToSByte(this.CompareEndValue)); } break; case SearchDataTypes._16bits: if (this.IsUnsignedDataType) { builder.AppendFormat("CComparison Range: 0x{0:x2} to 0x{1:x4}\n", Convert.ToUInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); } else { builder.AppendFormat("Comparison Range: 0x{0:x4} to 0x{1:x4}\n", Convert.ToInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); } break; case SearchDataTypes._32bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Range: 0x{0:x8} to 0x{1:x8}\n", Convert.ToUInt32(this.CompareStartValue), Convert.ToUInt32(this.CompareEndValue)); } else { builder.AppendFormat("Comparison Range: 0x{0:x8} to 0x{1:x8}\n", Convert.ToInt32(this.CompareStartValue), Convert.ToInt32(this.CompareEndValue)); } break; case SearchDataTypes._64bits: if (this.IsUnsignedDataType) { builder.AppendFormat("Comparison Range: 0x{0:x16} to 0x{1:x16}\n", Convert.ToUInt64(this.CompareStartValue), Convert.ToUInt64(this.CompareEndValue)); } else { builder.AppendFormat("Comparison Range: 0x{0:x16} to 0x{1:x16}\n", Convert.ToInt64(this.CompareStartValue), Convert.ToInt64(this.CompareEndValue)); } break; default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type."); } #endregion } logger.Info.WriteLine(builder.ToString()); } #endregion //#region ISerializable Members //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) //{ // throw new NotImplementedException(); //} //#endregion } }