using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace RomCheater.Docking.MemorySearch { public interface IResultDataType { int Address { get; set; } bool IsFrozen { get; set; } bool IsUnsigned { get; set; } object Value { get; set; } SearchDataTypes ValueType { get; set; } } public class ResultDataType : IResultDataType { public ResultDataType(int address) { this.Address = address; } public ResultDataType(int address, bool isfrozen) : this(address) { this.IsFrozen = isfrozen; } public ResultDataType(int address, bool isfrozen, object value, SearchDataTypes ValueType) : this(address, isfrozen, value) { this.ValueType = ValueType; } public ResultDataType(int address, bool isfrozen, object value) : this(address, isfrozen) { this.Value = value; this.ValueType = SearchDataTypes._8bits; if (value.GetType() == typeof(sbyte) || value.GetType() == typeof(byte)) { this.ValueType = SearchDataTypes._8bits; } else if (value.GetType() == typeof(short) || value.GetType() == typeof(ushort)) { this.ValueType = SearchDataTypes._16bits; } else if (value.GetType() == typeof(int) || value.GetType() == typeof(uint)) { this.ValueType = SearchDataTypes._32bits; } else if (value.GetType() == typeof(long) || value.GetType() == typeof(ulong)) { this.ValueType = SearchDataTypes._64bits; } else { this.ValueType = SearchDataTypes._8bits; } this.IsUnsigned = true; } public ResultDataType(int address, bool isfrozen, byte value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._8bits; this.IsUnsigned = true; } public ResultDataType(int address, bool isfrozen, sbyte value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._8bits; } public ResultDataType(int address, bool isfrozen, ushort value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._16bits; this.IsUnsigned = true; } public ResultDataType(int address, bool isfrozen, short value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._16bits; } public ResultDataType(int address, bool isfrozen, uint value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._32bits; this.IsUnsigned = true; } public ResultDataType(int address, bool isfrozen, int value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._32bits; } public ResultDataType(int address, bool isfrozen, ulong value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._64bits; this.IsUnsigned = true; } public ResultDataType(int address, bool isfrozen, long value) : this(address, isfrozen) { this.Value = (object)value; this.ValueType = SearchDataTypes._64bits; } #region IResultDataType Members private int _address; private bool _isfrozen; private object _value; private SearchDataTypes _valuetype; private bool _IsUnsigned = false; public int Address { get { return _address; } set { _address = value; } } public bool IsFrozen { get { return _isfrozen; } set { _isfrozen = value; } } public object Value { get { return _value; } set { _value = value; } } public SearchDataTypes ValueType { get { return _valuetype; } set { _valuetype = value; } } public bool IsUnsigned { get { return _IsUnsigned; } set { _IsUnsigned = value; } } #endregion public override string ToString() { string value_out = ""; switch (this.ValueType) { case SearchDataTypes._8bits: value_out = string.Format("0x{0:x2}", this.Value); break; case SearchDataTypes._16bits: value_out = string.Format("0x{0:x4}", this.Value); break; case SearchDataTypes._32bits: value_out = string.Format("0x{0:x8}", this.Value); break; case SearchDataTypes._64bits: value_out = string.Format("0x{0:x16}", this.Value); break; } StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.AppendFormat("0x{0:x8},{1},{2}", this.Address, value_out, this.IsFrozen); builder.Append("}"); return builder.ToString(); } } }