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