#define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using RomCheater.Logging; using RomCheater.Properties; using RomCheater.UserSettingsSupport; using RomCheater.PluginFramework.Core; using System.Diagnostics; using RomCheater.PluginFramework.Interfaces; using WeifenLuo.WinFormsUI.Docking; using RomCheater.Docking; using System.IO; using Sojaner.MemoryScanner; using RomCheater.PluginFramework.Events; namespace RomCheater { public partial class Main : Form { private bool m_bSaveLayout = true; private Process SelectedProcess = null; private DeserializeDockContent m_deserializeDockContent; private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); private FloatingAboutBox m_AboutBox = new FloatingAboutBox(); private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog(); private PIDSelector m_PIDSelector = new PIDSelector(); private FloatingMemoryView m_memoryview = new FloatingMemoryView(); //private bool log_window_expanded = false; //private double log_window_splitter_default_position = 1.4045; PluginLoader loader = null; IConfigPlugin ConfigPlugin = null; IInputPlugin InputPlugin = null; IWindowPlugin WindowPlugin = null; static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); } private const string t = "RomCheater"; #region LogWriterSupport static LogWriter _LoggerInstance; static LogWriter LoggerInstance { get { return _LoggerInstance; } set { _LoggerInstance = value; } } #endregion private void OnProcessChanged(ProcessChangedEventArgs e) { SelectedProcess = Process.GetProcessById(e.ProcessID); m_RamDump.AcceptedProcess = SelectedProcess; m_RamDump.AcceptedPlugin = this.ConfigPlugin; m_memoryview.AcceptedProcess = SelectedProcess; m_memoryview.AcceptedPlugin = this.ConfigPlugin; } #region Dock Support private IDockContent GetContentFromPersistString(string persistString) { if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; } //if (persistString == typeof(FloatingAboutBox).ToString()) //{ // return m_AboutBox; //} if (persistString == typeof(FloatingRamDumperDialog).ToString()) { return m_RamDump; } if (persistString == typeof(PIDSelector).ToString()) { return m_PIDSelector; } if (persistString == typeof(FloatingMemoryView).ToString()) { return m_memoryview; } else { // not sure if this is appropriate return null; } } public void SetupDocks() { m_LogWindow = new FloatingLogWindow(); m_AboutBox = new FloatingAboutBox(); m_RamDump = new FloatingRamDumperDialog(); m_PIDSelector = new PIDSelector(); m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler(OnProcessChanged); m_memoryview = new FloatingMemoryView(); m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString); } public void ShowDocks() { ShowLogWindow(); //ShowAboutBox(); ShowRamDump(); ShowMemoryView(); ShowPidSelector(); } public void ShowLogWindow() { m_LogWindow.Show(dockPanel, DockState.DockBottom); } public void ShowAboutBox() { m_AboutBox.ShowDialog(); } public void ShowRamDump() { m_RamDump = new FloatingRamDumperDialog(ConfigPlugin); m_RamDump.AcceptedProcess = SelectedProcess; m_RamDump.Show(dockPanel); } public void ShowMemoryView() { m_memoryview = new FloatingMemoryView(ConfigPlugin); m_memoryview.AcceptedProcess = SelectedProcess; m_memoryview.Show(dockPanel); } public void ShowPidSelector() { //List procs = ConfigPlugin.ValidProcessesForPlugin; m_PIDSelector = new PIDSelector(ConfigPlugin); m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler(OnProcessChanged); m_PIDSelector.Show(dockPanel); } #endregion public Main() : this(false) { } public Main(bool no_console_redirect) { InitializeComponent(); #if SHOW_DEBUG_MENU mnuDebug.Visible = true; #else mnuDebug.Visible = false; #endif load_loggerflags(); SetupDocks(); LoggerInstance = m_LogWindow.Logwriter; LoggerInstance.CreateNewLog(false); logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name); load_plugins(); if (no_console_redirect) LoggerInstance.RedirectConsoleOutput = false; } private void load_loggerflags() { logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags); #if FORCE_ALL_LOGGING_FLAGS logger.SetLoggingFlags(loggerflags.ALL); #endif } private void load_plugins() { loader = new PluginLoader(); loader.LoadPlugins(); ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin); if (ConfigPlugin != null) logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString()); InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin); if (InputPlugin != null) logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString()); WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin); if (WindowPlugin != null) logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString()); m_PIDSelector.AcceptedPlugin = ConfigPlugin; m_RamDump.AcceptedPlugin = ConfigPlugin; if (this.SelectedProcess != null) m_RamDump.AcceptedProcess = SelectedProcess; } private void mnuItemExit_Click(object sender, EventArgs e) { this.Close(); } private void btnCopyLogToClipboard_Click(object sender, EventArgs e) { } private void Main_Load(object sender, EventArgs e) { } private void mnuItemConfig_Click(object sender, EventArgs e) { RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader); dlg.ShowDialog(); // reload plugins load_plugins(); } private void mnuItemOpenProcess_Click(object sender, EventArgs e) { ////List procs = ConfigPlugin.ValidProcessesForPlugin; //PIDSelector selector = new PIDSelector(ConfigPlugin); //selector.ShowDialog(); } private void Main_Shown(object sender, EventArgs e) { //dockPanel.SuspendLayout(true); //ShowDocks(); string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config"); if (File.Exists(configFile)) { try { dockPanel.LoadFromXml(configFile, m_deserializeDockContent); } catch (Exception) { this.Controls.Remove(dockPanel); dockPanel = new DockPanel(); dockPanel.Dock = DockStyle.Fill; dockPanel.DocumentStyle = DocumentStyle.DockingWindow; this.Controls.Add(dockPanel); ShowDocks(); } } else { ShowDocks(); } //dockPanel.ResumeLayout(true, true); } private void mnuItemShowLogWindow_Click(object sender, EventArgs e) { ShowLogWindow(); } private void mnuItemHelpAbout_Click(object sender, EventArgs e) { ShowAboutBox(); } private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e) { ShowRamDump(); } private void mnuItemShowPIDSelector_Click(object sender, EventArgs e) { ShowPidSelector(); } private void mnuItemShowMemoryView_Click(object sender, EventArgs e) { ShowMemoryView(); } private void Main_FormClosing(object sender, FormClosingEventArgs e) { string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config"); if (m_bSaveLayout) dockPanel.SaveAsXml(configFile); else if (File.Exists(configFile)) File.Delete(configFile); } private void mnuTestExeParse_Click(object sender, EventArgs e) { PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe"); } private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e) { //uint start = 0xf0000000; uint end = uint.MaxValue; //for (uint i = start; i < end; i++) //{ ulong value = Convert.ToUInt64(end.ToString(), 16); //} } } }