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