ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Main.cs
Revision: 196
Committed: Thu May 31 05:52:41 2012 UTC (11 years, 6 months ago) by william
File size: 10119 byte(s)
Log Message:
+ add some event code
+ add memeory view  dialog (wip)

File Contents

# Content
1 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Windows.Forms;
11 using RomCheater.Logging;
12 using RomCheater.Properties;
13 using RomCheater.UserSettingsSupport;
14 using RomCheater.PluginFramework.Core;
15 using System.Diagnostics;
16 using RomCheater.PluginFramework.Interfaces;
17 using WeifenLuo.WinFormsUI.Docking;
18 using RomCheater.Docking;
19 using System.IO;
20 using Sojaner.MemoryScanner;
21 using RomCheater.PluginFramework.Events;
22
23 namespace RomCheater
24 {
25 public partial class Main : Form
26 {
27 private bool m_bSaveLayout = true;
28 private Process SelectedProcess = null;
29 private DeserializeDockContent m_deserializeDockContent;
30 private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
32 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
33 private PIDSelector m_PIDSelector = new PIDSelector();
34 private FloatingMemoryView m_memoryview = new FloatingMemoryView();
35 //private bool log_window_expanded = false;
36 //private double log_window_splitter_default_position = 1.4045;
37 PluginLoader loader = null;
38 IConfigPlugin ConfigPlugin = null;
39 IInputPlugin InputPlugin = null;
40 IWindowPlugin WindowPlugin = null;
41 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
42 private const string t = "RomCheater";
43 #region LogWriterSupport
44 static LogWriter _LoggerInstance;
45 static LogWriter LoggerInstance
46 {
47 get { return _LoggerInstance; }
48 set { _LoggerInstance = value; }
49 }
50 #endregion
51
52
53 private void OnProcessChanged(ProcessChangedEventArgs e)
54 {
55 SelectedProcess = Process.GetProcessById(e.ProcessID);
56 m_RamDump.AcceptedProcess = SelectedProcess;
57 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
58
59 m_memoryview.AcceptedProcess = SelectedProcess;
60 m_memoryview.AcceptedPlugin = this.ConfigPlugin;
61 }
62
63 #region Dock Support
64 private IDockContent GetContentFromPersistString(string persistString)
65 {
66 if (persistString == typeof(FloatingLogWindow).ToString())
67 {
68 return m_LogWindow;
69 }
70 //if (persistString == typeof(FloatingAboutBox).ToString())
71 //{
72 // return m_AboutBox;
73 //}
74 if (persistString == typeof(FloatingRamDumperDialog).ToString())
75 {
76 return m_RamDump;
77 }
78 if (persistString == typeof(PIDSelector).ToString())
79 {
80 return m_PIDSelector;
81 }
82 if (persistString == typeof(FloatingMemoryView).ToString())
83 {
84 return m_memoryview;
85 }
86 else
87 {
88 // not sure if this is appropriate
89 return null;
90 }
91 }
92 public void SetupDocks()
93 {
94 m_LogWindow = new FloatingLogWindow();
95 m_AboutBox = new FloatingAboutBox();
96 m_RamDump = new FloatingRamDumperDialog();
97 m_PIDSelector = new PIDSelector();
98 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
99 m_memoryview = new FloatingMemoryView();
100 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
101 }
102 public void ShowDocks()
103 {
104 ShowLogWindow();
105 //ShowAboutBox();
106 ShowRamDump();
107 ShowMemoryView();
108 ShowPidSelector();
109 }
110 public void ShowLogWindow()
111 {
112 m_LogWindow.Show(dockPanel, DockState.DockBottom);
113 }
114 public void ShowAboutBox()
115 {
116 m_AboutBox.ShowDialog();
117 }
118 public void ShowRamDump()
119 {
120 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
121 m_RamDump.Show(dockPanel);
122 }
123 public void ShowMemoryView()
124 {
125 m_memoryview = new FloatingMemoryView(ConfigPlugin);
126 m_memoryview.Show(dockPanel);
127 }
128 public void ShowPidSelector()
129 {
130 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
131 m_PIDSelector = new PIDSelector(ConfigPlugin);
132 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
133 m_PIDSelector.Show(dockPanel);
134 }
135 #endregion
136
137
138 public Main() : this(false) { }
139 public Main(bool no_console_redirect)
140 {
141 InitializeComponent();
142 #if SHOW_DEBUG_MENU
143 mnuDebug.Visible = true;
144 #else
145 mnuDebug.Visible = false;
146 #endif
147 load_loggerflags();
148 SetupDocks();
149 LoggerInstance = m_LogWindow.Logwriter;
150 LoggerInstance.CreateNewLog(false);
151 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
152 load_plugins();
153 if (no_console_redirect)
154 LoggerInstance.RedirectConsoleOutput = false;
155
156
157
158 }
159 private void load_loggerflags()
160 {
161 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
162 #if FORCE_ALL_LOGGING_FLAGS
163 logger.SetLoggingFlags(loggerflags.ALL);
164 #endif
165 }
166 private void load_plugins()
167 {
168 loader = new PluginLoader();
169 loader.LoadPlugins();
170
171 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
172 if (ConfigPlugin != null)
173 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
174 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
175 if (InputPlugin != null)
176 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
177 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
178 if (WindowPlugin != null)
179 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
180
181 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
182 m_RamDump.AcceptedPlugin = ConfigPlugin;
183 if (this.SelectedProcess != null)
184 m_RamDump.AcceptedProcess = SelectedProcess;
185
186 }
187
188 private void mnuItemExit_Click(object sender, EventArgs e)
189 {
190 this.Close();
191 }
192
193 private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
194 {
195
196 }
197
198 private void Main_Load(object sender, EventArgs e)
199 {
200
201 }
202
203 private void mnuItemConfig_Click(object sender, EventArgs e)
204 {
205 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
206 dlg.ShowDialog();
207 // reload plugins
208 load_plugins();
209 }
210
211 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
212 {
213 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
214 //PIDSelector selector = new PIDSelector(ConfigPlugin);
215 //selector.ShowDialog();
216 }
217
218 private void Main_Shown(object sender, EventArgs e)
219 {
220 //dockPanel.SuspendLayout(true);
221 //ShowDocks();
222 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
223 if (File.Exists(configFile))
224 {
225 try
226 {
227 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
228 }
229 catch (Exception)
230 {
231 this.Controls.Remove(dockPanel);
232 dockPanel = new DockPanel();
233 dockPanel.Dock = DockStyle.Fill;
234 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
235 this.Controls.Add(dockPanel);
236 ShowDocks();
237 }
238 }
239 else
240 {
241 ShowDocks();
242 }
243
244 //dockPanel.ResumeLayout(true, true);
245 }
246
247 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
248 {
249 ShowLogWindow();
250 }
251
252 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
253 {
254 ShowAboutBox();
255 }
256
257 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
258 {
259 ShowRamDump();
260 }
261
262 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
263 {
264 ShowPidSelector();
265 }
266
267 private void Main_FormClosing(object sender, FormClosingEventArgs e)
268 {
269 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
270 if (m_bSaveLayout)
271 dockPanel.SaveAsXml(configFile);
272 else if (File.Exists(configFile))
273 File.Delete(configFile);
274 }
275
276 private void mnuTestExeParse_Click(object sender, EventArgs e)
277 {
278 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
279 }
280 }
281 }