ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Main.cs
Revision: 218
Committed: Sat Jun 2 11:02:38 2012 UTC (11 years, 3 months ago) by william
File size: 11770 byte(s)
Log Message:

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 FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter();
36 //private bool log_window_expanded = false;
37 //private double log_window_splitter_default_position = 1.4045;
38 PluginLoader loader = null;
39 IConfigPlugin ConfigPlugin = null;
40 IInputPlugin InputPlugin = null;
41 IWindowPlugin WindowPlugin = null;
42 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
43 private const string t = "RomCheater";
44 #region LogWriterSupport
45 static LogWriter _LoggerInstance;
46 static LogWriter LoggerInstance
47 {
48 get { return _LoggerInstance; }
49 set { _LoggerInstance = value; }
50 }
51 #endregion
52
53
54 private void OnProcessChanged(ProcessChangedEventArgs e)
55 {
56 SelectedProcess = Process.GetProcessById(e.ProcessID);
57 m_RamDump.AcceptedProcess = SelectedProcess;
58 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
59
60 m_memoryview.AcceptedProcess = SelectedProcess;
61 m_memoryview.AcceptedPlugin = this.ConfigPlugin;
62 }
63
64 #region Dock Support
65 private IDockContent GetContentFromPersistString(string persistString)
66 {
67 if (persistString == typeof(FloatingLogWindow).ToString())
68 {
69 return m_LogWindow;
70 }
71 //if (persistString == typeof(FloatingAboutBox).ToString())
72 //{
73 // return m_AboutBox;
74 //}
75 if (persistString == typeof(FloatingRamDumperDialog).ToString())
76 {
77 return m_RamDump;
78 }
79 if (persistString == typeof(PIDSelector).ToString())
80 {
81 return m_PIDSelector;
82 }
83 if (persistString == typeof(FloatingMemoryView).ToString())
84 {
85 return m_memoryview;
86 }
87 if (persistString == typeof(FloatingDataTypeConverter).ToString())
88 {
89 return m_typeconverter;
90 }
91 else
92 {
93 // not sure if this is appropriate
94 return null;
95 }
96 }
97 public void SetupDocks()
98 {
99 m_LogWindow = new FloatingLogWindow();
100 m_AboutBox = new FloatingAboutBox();
101 m_RamDump = new FloatingRamDumperDialog();
102 m_PIDSelector = new PIDSelector();
103 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
104 m_memoryview = new FloatingMemoryView();
105 m_typeconverter = new FloatingDataTypeConverter();
106 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
107 }
108 public void ShowDocks()
109 {
110 ShowLogWindow();
111 //ShowAboutBox();
112 ShowRamDump();
113 ShowMemoryView();
114 ShowPidSelector();
115 ShowDataTypeConverter();
116 }
117 public void ShowLogWindow()
118 {
119 if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
120 m_LogWindow.Show(dockPanel, DockState.DockBottom);
121 }
122 public void ShowAboutBox()
123 {
124 if (m_AboutBox == null || m_AboutBox.IsDisposed) { m_AboutBox = new FloatingAboutBox(); }
125 m_AboutBox.ShowDialog();
126 }
127 public void ShowRamDump()
128 {
129 load_plugins();
130 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
131 m_RamDump.AcceptedProcess = SelectedProcess;
132 m_RamDump.Show(dockPanel);
133 }
134 public void ShowMemoryView()
135 {
136 load_plugins();
137 m_memoryview = new FloatingMemoryView(ConfigPlugin);
138 m_memoryview.AcceptedProcess = SelectedProcess;
139 m_memoryview.Show(dockPanel);
140 }
141 public void ShowPidSelector()
142 {
143 load_plugins();
144 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
145 m_PIDSelector = new PIDSelector(ConfigPlugin);
146 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
147 m_PIDSelector.Show(dockPanel);
148 }
149 public void ShowDataTypeConverter()
150 {
151 if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); }
152 m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide);
153 }
154 #endregion
155
156
157 public Main() : this(false) { }
158 public Main(bool no_console_redirect)
159 {
160 InitializeComponent();
161 #if SHOW_DEBUG_MENU
162 mnuDebug.Visible = true;
163 #else
164 mnuDebug.Visible = false;
165 #endif
166 load_loggerflags();
167 SetupDocks();
168 LoggerInstance = m_LogWindow.Logwriter;
169 LoggerInstance.CreateNewLog(false);
170 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
171 load_plugins();
172 if (no_console_redirect)
173 LoggerInstance.RedirectConsoleOutput = false;
174
175
176
177 }
178 private void load_loggerflags()
179 {
180 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
181 #if FORCE_ALL_LOGGING_FLAGS
182 logger.SetLoggingFlags(loggerflags.ALL);
183 #endif
184 }
185 private void load_plugins()
186 {
187 loader = new PluginLoader();
188 loader.LoadPlugins();
189
190 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
191 if (ConfigPlugin != null)
192 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
193 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
194 if (InputPlugin != null)
195 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
196 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
197 if (WindowPlugin != null)
198 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
199
200 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
201 m_RamDump.AcceptedPlugin = ConfigPlugin;
202 if (this.SelectedProcess != null)
203 m_RamDump.AcceptedProcess = SelectedProcess;
204
205 }
206
207 private void mnuItemExit_Click(object sender, EventArgs e)
208 {
209 this.Close();
210 }
211
212 private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
213 {
214
215 }
216
217 private void Main_Load(object sender, EventArgs e)
218 {
219
220 }
221
222 private void mnuItemConfig_Click(object sender, EventArgs e)
223 {
224 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
225 dlg.ShowDialog();
226 // reload plugins
227 load_plugins();
228 }
229
230 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
231 {
232 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
233 //PIDSelector selector = new PIDSelector(ConfigPlugin);
234 //selector.ShowDialog();
235 }
236
237 private void Main_Shown(object sender, EventArgs e)
238 {
239 //dockPanel.SuspendLayout(true);
240 //ShowDocks();
241 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
242 if (File.Exists(configFile))
243 {
244 try
245 {
246 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
247 }
248 catch (Exception)
249 {
250 this.Controls.Remove(dockPanel);
251 dockPanel = new DockPanel();
252 dockPanel.Dock = DockStyle.Fill;
253 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
254 this.Controls.Add(dockPanel);
255 ShowDocks();
256 }
257 }
258 else
259 {
260 ShowDocks();
261 }
262
263 //dockPanel.ResumeLayout(true, true);
264 }
265
266 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
267 {
268 ShowLogWindow();
269 }
270
271 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
272 {
273 ShowAboutBox();
274 }
275
276 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
277 {
278 ShowRamDump();
279 }
280
281 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
282 {
283 ShowPidSelector();
284 }
285 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
286 {
287 ShowMemoryView();
288 }
289 private void Main_FormClosing(object sender, FormClosingEventArgs e)
290 {
291 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
292 if (m_bSaveLayout)
293 dockPanel.SaveAsXml(configFile);
294 else if (File.Exists(configFile))
295 File.Delete(configFile);
296 }
297
298 private void mnuTestExeParse_Click(object sender, EventArgs e)
299 {
300 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
301 }
302
303 private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e)
304 {
305
306 //uint start = 0xf0000000;
307 uint end = uint.MaxValue;
308 //for (uint i = start; i < end; i++)
309 //{
310 ulong value = Convert.ToUInt64(end.ToString(), 16);
311 //}
312 }
313
314 private void mnuItemShowDataTypeConverter_Click(object sender, EventArgs e)
315 {
316 ShowDataTypeConverter();
317 }
318
319 }
320 }