/[RomCheater]/trunk/RomCheater/Main.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 218 - (hide annotations) (download)
Sat Jun 2 11:02:38 2012 UTC (9 years, 3 months ago) by william
File size: 11770 byte(s)

1 william 99 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 william 158 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 william 99 using System;
4 william 5 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 william 17 using RomCheater.Logging;
12 william 34 using RomCheater.Properties;
13     using RomCheater.UserSettingsSupport;
14 william 83 using RomCheater.PluginFramework.Core;
15 william 86 using System.Diagnostics;
16 william 87 using RomCheater.PluginFramework.Interfaces;
17 william 144 using WeifenLuo.WinFormsUI.Docking;
18 william 146 using RomCheater.Docking;
19 william 152 using System.IO;
20 william 159 using Sojaner.MemoryScanner;
21 william 196 using RomCheater.PluginFramework.Events;
22 william 5
23     namespace RomCheater
24     {
25 william 13 public partial class Main : Form
26 william 5 {
27 william 152 private bool m_bSaveLayout = true;
28 william 196 private Process SelectedProcess = null;
29 william 144 private DeserializeDockContent m_deserializeDockContent;
30     private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 william 147 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
32 william 148 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
33     private PIDSelector m_PIDSelector = new PIDSelector();
34 william 196 private FloatingMemoryView m_memoryview = new FloatingMemoryView();
35 william 218 private FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter();
36 william 144 //private bool log_window_expanded = false;
37     //private double log_window_splitter_default_position = 1.4045;
38 william 86 PluginLoader loader = null;
39 william 87 IConfigPlugin ConfigPlugin = null;
40     IInputPlugin InputPlugin = null;
41     IWindowPlugin WindowPlugin = null;
42 william 146 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
43 william 20 private const string t = "RomCheater";
44 william 17 #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 william 196 private void OnProcessChanged(ProcessChangedEventArgs e)
55 william 151 {
56 william 153 SelectedProcess = Process.GetProcessById(e.ProcessID);
57     m_RamDump.AcceptedProcess = SelectedProcess;
58 william 196 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
59    
60     m_memoryview.AcceptedProcess = SelectedProcess;
61     m_memoryview.AcceptedPlugin = this.ConfigPlugin;
62 william 151 }
63    
64 william 144 #region Dock Support
65     private IDockContent GetContentFromPersistString(string persistString)
66     {
67     if (persistString == typeof(FloatingLogWindow).ToString())
68     {
69     return m_LogWindow;
70     }
71 william 152 //if (persistString == typeof(FloatingAboutBox).ToString())
72     //{
73     // return m_AboutBox;
74     //}
75 william 148 if (persistString == typeof(FloatingRamDumperDialog).ToString())
76     {
77     return m_RamDump;
78     }
79 william 152 if (persistString == typeof(PIDSelector).ToString())
80     {
81     return m_PIDSelector;
82     }
83 william 196 if (persistString == typeof(FloatingMemoryView).ToString())
84     {
85     return m_memoryview;
86     }
87 william 218 if (persistString == typeof(FloatingDataTypeConverter).ToString())
88     {
89     return m_typeconverter;
90     }
91 william 144 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 william 147 m_AboutBox = new FloatingAboutBox();
101 william 148 m_RamDump = new FloatingRamDumperDialog();
102     m_PIDSelector = new PIDSelector();
103 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
104     m_memoryview = new FloatingMemoryView();
105 william 218 m_typeconverter = new FloatingDataTypeConverter();
106 william 144 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
107     }
108     public void ShowDocks()
109     {
110     ShowLogWindow();
111 william 152 //ShowAboutBox();
112 william 148 ShowRamDump();
113 william 196 ShowMemoryView();
114 william 148 ShowPidSelector();
115 william 218 ShowDataTypeConverter();
116 william 144 }
117     public void ShowLogWindow()
118 william 218 {
119     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
120 william 152 m_LogWindow.Show(dockPanel, DockState.DockBottom);
121 william 144 }
122 william 147 public void ShowAboutBox()
123     {
124 william 218 if (m_AboutBox == null || m_AboutBox.IsDisposed) { m_AboutBox = new FloatingAboutBox(); }
125 william 148 m_AboutBox.ShowDialog();
126 william 147 }
127 william 148 public void ShowRamDump()
128     {
129 william 218 load_plugins();
130 william 153 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
131 william 201 m_RamDump.AcceptedProcess = SelectedProcess;
132 william 196 m_RamDump.Show(dockPanel);
133 william 148 }
134 william 196 public void ShowMemoryView()
135     {
136 william 218 load_plugins();
137 william 196 m_memoryview = new FloatingMemoryView(ConfigPlugin);
138 william 201 m_memoryview.AcceptedProcess = SelectedProcess;
139 william 196 m_memoryview.Show(dockPanel);
140     }
141 william 148 public void ShowPidSelector()
142     {
143 william 218 load_plugins();
144 william 148 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
145     m_PIDSelector = new PIDSelector(ConfigPlugin);
146 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
147 william 148 m_PIDSelector.Show(dockPanel);
148     }
149 william 218 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 william 144 #endregion
155    
156    
157 william 117 public Main() : this(false) { }
158     public Main(bool no_console_redirect)
159 william 5 {
160     InitializeComponent();
161 william 158 #if SHOW_DEBUG_MENU
162     mnuDebug.Visible = true;
163     #else
164     mnuDebug.Visible = false;
165     #endif
166 william 83 load_loggerflags();
167 william 144 SetupDocks();
168     LoggerInstance = m_LogWindow.Logwriter;
169 william 23 LoggerInstance.CreateNewLog(false);
170 william 112 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
171 william 87 load_plugins();
172 william 117 if (no_console_redirect)
173     LoggerInstance.RedirectConsoleOutput = false;
174 william 158
175    
176 william 144
177 william 5 }
178 william 83 private void load_loggerflags()
179     {
180 william 111 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
181 william 99 #if FORCE_ALL_LOGGING_FLAGS
182     logger.SetLoggingFlags(loggerflags.ALL);
183     #endif
184 william 83 }
185 william 87 private void load_plugins()
186     {
187     loader = new PluginLoader();
188     loader.LoadPlugins();
189 william 83
190 william 87 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 william 153 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
201     m_RamDump.AcceptedPlugin = ConfigPlugin;
202     if (this.SelectedProcess != null)
203     m_RamDump.AcceptedProcess = SelectedProcess;
204 william 152
205 william 87 }
206    
207 william 14 private void mnuItemExit_Click(object sender, EventArgs e)
208     {
209     this.Close();
210     }
211 william 16
212     private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
213     {
214    
215     }
216 william 17
217     private void Main_Load(object sender, EventArgs e)
218 william 144 {
219 william 152
220 william 17 }
221 william 63
222     private void mnuItemConfig_Click(object sender, EventArgs e)
223     {
224 william 86 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
225 william 63 dlg.ShowDialog();
226 william 92 // reload plugins
227     load_plugins();
228 william 63 }
229 william 69
230     private void mnuItemOpenProcess_Click(object sender, EventArgs e)
231     {
232 william 148 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
233     //PIDSelector selector = new PIDSelector(ConfigPlugin);
234     //selector.ShowDialog();
235 william 69 }
236 william 104
237 william 144 private void Main_Shown(object sender, EventArgs e)
238 william 104 {
239 william 152 //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 william 177 catch (Exception)
249 william 152 {
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 william 104 }
265 william 144
266     private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
267     {
268     ShowLogWindow();
269     }
270 william 147
271     private void mnuItemHelpAbout_Click(object sender, EventArgs e)
272     {
273     ShowAboutBox();
274     }
275 william 148
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 william 201 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
286     {
287     ShowMemoryView();
288     }
289 william 152 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 william 158
298     private void mnuTestExeParse_Click(object sender, EventArgs e)
299     {
300 william 159 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
301 william 158 }
302 william 201
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 william 218
314     private void mnuItemShowDataTypeConverter_Click(object sender, EventArgs e)
315     {
316     ShowDataTypeConverter();
317     }
318 william 201
319 william 5 }
320     }

  ViewVC Help
Powered by ViewVC 1.1.22