/[RomCheater]/trunk/RomCheater/Docking/MemorySearch/ResultItemState.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Docking/MemorySearch/ResultItemState.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (hide annotations) (download)
Sun Jun 3 16:09:05 2012 UTC (8 years, 10 months ago) by william
File size: 6845 byte(s)
change address from uint to int

1 william 229 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Windows.Forms;
6     using System.IO;
7     using System.Diagnostics;
8     using RomCheater.Logging;
9 william 240 using Sojaner.MemoryScanner.MemoryProviers;
10 william 245 using RomCheater.PluginFramework.Interfaces;
11 william 229
12     namespace RomCheater.Docking.MemorySearch
13     {
14     [Serializable]
15 william 245 public class ResultItemState :
16     IAcceptsPlugin<IConfigPlugin>,
17     IAcceptsProcess<Process>,
18     IAcceptsProcessAndConfig
19 william 229 {
20     #region Implicit Conversion
21     public static implicit operator ResultDataType(ResultItemState state)
22     {
23     ResultDataType _result = null;
24     bool frozen = false;
25     switch (state.Frozen.ToLower())
26     {
27     case "true": frozen = true; break;
28     case "false": frozen = false; break;
29     }
30    
31 william 249 int Address = Convert.ToInt32(state.Address, 16);
32 william 229 switch (state.ValueType)
33     {
34     case SearchDataTypes._8bits:
35     if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToByte(state.Value, 16)); }
36     else { _result = new ResultDataType(Address, frozen, Convert.ToSByte(state.Value)); }
37     break;
38     case SearchDataTypes._16bits:
39     if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt16(state.Value, 16)); }
40     else { _result = new ResultDataType(Address, frozen, Convert.ToInt16(state.Value, 16)); }
41     break;
42     case SearchDataTypes._32bits:
43     if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt32(state.Value, 16)); }
44     else { _result = new ResultDataType(Address, frozen, Convert.ToInt32(state.Value, 16)); }
45     break;
46     case SearchDataTypes._64bits:
47     if (state.IsUnsigned) { _result = new ResultDataType(Address, frozen, Convert.ToUInt64(state.Value, 16)); }
48     else { _result = new ResultDataType(Address, frozen, Convert.ToInt64(state.Value, 16)); }
49     break;
50     }
51     return _result;
52     }
53     #endregion
54 william 245 #region IAcceptsProcess<Process> Members
55     public Process AcceptedProcess { get; set; }
56     #endregion
57     #region IAcceptsPlugin<IConfigPlugin> Members
58     public IConfigPlugin AcceptedPlugin { get; set; }
59     #endregion
60     public ResultItemState() : this(null) { }
61     public ResultItemState(IAcceptsProcessAndConfig pconfig)
62 william 229 {
63     this.IconKey = "";
64     this.Address = (0).ToString("x8");
65     this.Value = (0).ToString("x8");
66     this.Frozen = false.ToString();
67     this.ValueType = SearchDataTypes._32bits;
68     this.IsUnsigned = true;
69 william 245
70     this.AcceptedPlugin = pconfig.AcceptedPlugin;
71     this.AcceptedProcess = pconfig.AcceptedProcess;
72 william 229 }
73 william 245 public ResultItemState(string address, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig)
74     : this(AVPIconKeys.NOTFROZEN, address, "", false.ToString(), bitsize, IsUnsigned, pconfig)
75 william 229 {
76 william 249 int Address = 0;
77     Address = Convert.ToInt32(this.Address, 16);
78 william 245 GenericMemoryProvider provider = new GenericMemoryProvider(pconfig);
79     provider.OpenProvider();
80 william 229 int bytesReadSize;
81     byte[] data;
82     uint bytesToRead=0;
83     switch (bitsize)
84     {
85     case SearchDataTypes._8bits:
86     bytesToRead = 1;
87     break;
88     case SearchDataTypes._16bits:
89     bytesToRead = 2;
90     break;
91     case SearchDataTypes._32bits:
92     bytesToRead = 4;
93     break;
94     case SearchDataTypes._64bits:
95     bytesToRead = 8;
96     break;
97     }
98    
99 william 240 provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
100 william 229 MemoryStream ms = new MemoryStream(data);
101     BinaryReader r_ms = new BinaryReader(ms);
102    
103     //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
104     //int val = 0;
105     switch (bitsize)
106     {
107     case SearchDataTypes._8bits:
108     if (IsUnsigned) { this.Value = string.Format("0x{0:x2}", r_ms.ReadByte()); }
109     else { this.Value = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
110     break;
111     case SearchDataTypes._16bits:
112     if (IsUnsigned) { this.Value = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
113     else { this.Value = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
114     break;
115     case SearchDataTypes._32bits:
116     if (IsUnsigned) { this.Value = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
117     else { this.Value = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
118     break;
119     case SearchDataTypes._64bits:
120     if (IsUnsigned) { this.Value = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
121     else { this.Value = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
122     break;
123     }
124 william 245 provider.CloseProvider();
125 william 229 }
126 william 245 public ResultItemState(string IconKey, string address, string value, string frozen, SearchDataTypes bitsize, bool IsUnsigned, IAcceptsProcessAndConfig pconfig)
127     : this(pconfig)
128 william 229 {
129     this.IconKey = IconKey;
130     this.Address = address;
131     this.Value = value;
132     this.Frozen = frozen;
133     this.ValueType = bitsize;
134     this.IsUnsigned = IsUnsigned;
135     }
136    
137    
138     private string _IconKey;
139     private string _Address;
140     private string _Value;
141     private string _Frozen;
142    
143     public string IconKey { get { return _IconKey; } set { _IconKey = value; } }
144     public string Address { get { return _Address; } set { _Address = value; } }
145     public string Value { get { return _Value; } set { _Value = value; } }
146     public string Frozen { get { return _Frozen; } set { _Frozen = value; } }
147    
148    
149     private bool _IsUnsigned;
150     public bool IsUnsigned { get { return _IsUnsigned; } set { _IsUnsigned = value; } }
151     private SearchDataTypes _ValueType;
152     public SearchDataTypes ValueType { get { return _ValueType; } set { _ValueType = value; } }
153     }
154     }

  ViewVC Help
Powered by ViewVC 1.1.22