/[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 240 - (hide annotations) (download)
Sun Jun 3 12:54:18 2012 UTC (8 years, 10 months ago) by william
File size: 7805 byte(s)
+ implement GenericMemoryProvider : NOTE: config is null

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

  ViewVC Help
Powered by ViewVC 1.1.22