public static void AttachAndShowUI() { // This form finds the process for re2.exe (assigned to gameProc) or waits until it is found. using (AttachUI attachUI = new AttachUI()) using (ApplicationContext mainContext = new ApplicationContext(attachUI)) { Application.Run(mainContext); } // If we exited the attach UI without finding a PID, bail out completely. Debug.WriteLine("Checking PID for -1..."); if (gamePID == -1) { return; } // Attach to the re2.exe process now that we've found it and show the UI. Debug.WriteLine("Showing MainUI..."); using (gameMem = new GameMemory(gamePID)) using (MainUI mainUI = new MainUI()) using (ApplicationContext mainContext = new ApplicationContext(mainUI)) { Application.Run(mainContext); } }
public MainUI() { InitializeComponent(); // Set titlebar. this.Text += string.Format(" {0}", Program.srtVersion); this.ContextMenu = Program.contextMenu; this.playerHealthStatus.ContextMenu = Program.contextMenu; this.statisticsPanel.ContextMenu = Program.contextMenu; this.inventoryPanel.ContextMenu = Program.contextMenu; //GDI+ this.playerHealthStatus.Paint += this.playerHealthStatus_Paint; this.statisticsPanel.Paint += this.statisticsPanel_Paint; this.inventoryPanel.Paint += this.inventoryPanel_Paint; // DirectX if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.DirectXOverlay)) { overlay = new DXOverlay(Program.gameWindowHandle); overlay.Initialize((GameOverlay.Windows.OverlayWindow w, GameOverlay.Drawing.Graphics g) => { font = g.CreateFont("Consolas", 8, true); redBrush = g.CreateSolidBrush(255, 0, 0); whiteBrush = g.CreateSolidBrush(255, 255, 255); greyBrush = g.CreateSolidBrush(150, 150, 150); blackBrush = g.CreateSolidBrush(0, 0, 0); backBrushDirectX = g.CreateSolidBrush(60, 60, 60); foreBrushDirectX = g.CreateSolidBrush(100, 0, 0); }); overlay.Run(statisticsPanelDirectX_Paint, CancellationToken.None); } if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.NoTitleBar)) { this.FormBorderStyle = FormBorderStyle.None; } if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.Transparent)) { this.TransparencyKey = Color.Black; } // Only run the following code if we're rendering inventory. if (!Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.NoInventory)) { GameMemory.GenerateImages(); // Create a black slot image for when side-pack is not equipped. inventoryError = new Bitmap(Program.INV_SLOT_WIDTH, Program.INV_SLOT_HEIGHT, PixelFormat.Format32bppPArgb); using (Graphics grp = Graphics.FromImage(inventoryError)) { grp.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), 0, 0, inventoryError.Width, inventoryError.Height); grp.DrawLine(new Pen(Color.FromArgb(150, 255, 0, 0), 3), 0, 0, inventoryError.Width, inventoryError.Height); grp.DrawLine(new Pen(Color.FromArgb(150, 255, 0, 0), 3), inventoryError.Width, 0, 0, inventoryError.Height); } // Set the width and height of the inventory display so it matches the maximum items and the scaling size of those items. this.inventoryPanel.Width = Program.INV_SLOT_WIDTH * 4; this.inventoryPanel.Height = Program.INV_SLOT_HEIGHT * 5; // Adjust main form width as well. this.Width = this.statisticsPanel.Width + 24 + this.inventoryPanel.Width; // Only adjust form height if its greater than 461. We don't want it to go below this size. if (41 + this.inventoryPanel.Height > 461) { this.Height = 41 + this.inventoryPanel.Height; } } else { // Disable rendering of the inventory panel. this.inventoryPanel.Visible = false; // Adjust main form width as well. this.Width = this.statisticsPanel.Width + 2; } lastPtrUpdate = DateTime.UtcNow.Ticks; lastFullUIDraw = DateTime.UtcNow.Ticks; }
public static void Main(string[] args) { // Handle command-line parameters. programSpecialOptions = new Options(); programSpecialOptions.GetOptions(); foreach (string arg in args) { if (arg.Equals("--Help", StringComparison.InvariantCultureIgnoreCase)) { StringBuilder message = new StringBuilder("Command-line arguments:\r\n\r\n"); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Skip-Checksum", "Skip the checksum file validation step."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--No-Titlebar", "Hide the titlebar and window frame."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Always-On-Top", "Always appear on top of other windows."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Transparent", "Make the background transparent."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--ScalingFactor=n", "Set the inventory slot scaling factor on a scale of 0.0 to 1.0. Default: 0.75 (75%)"); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--NoInventory", "Disables the inventory display."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Debug", "Debug mode."); MessageBox.Show(null, message.ToString().Trim(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); Environment.Exit(0); } if (arg.Equals("--Skip-Checksum", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.SkipChecksumCheck; } if (arg.Equals("--No-Titlebar", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.NoTitleBar; } if (arg.Equals("--Always-On-Top", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.AlwaysOnTop; } if (arg.Equals("--Transparent", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.Transparent; } if (arg.Equals("--NoInventory", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.NoInventory; } if (arg.StartsWith("--ScalingFactor=", StringComparison.InvariantCultureIgnoreCase)) { if (!double.TryParse(arg.Split(new char[1] { '=' }, 2, StringSplitOptions.None)[1], out programSpecialOptions.ScalingFactor)) { programSpecialOptions.ScalingFactor = 0.75d; // Default scaling factor for the inventory images. If we fail to process the user input, ensure this gets set to the default value just in case. } } if (arg.Equals("--Debug", StringComparison.InvariantCultureIgnoreCase)) { programSpecialOptions.Flags |= ProgramFlags.Debug; } } // Context menu. contextMenu = new ContextMenu(); contextMenu.MenuItems.Add("Options", (object sender, EventArgs e) => { using (OptionsUI optionsForm = new OptionsUI()) optionsForm.ShowDialog(); }); contextMenu.MenuItems.Add("-", (object sender, EventArgs e) => { }); contextMenu.MenuItems.Add("Exit", (object sender, EventArgs e) => { Environment.Exit(0); }); // Set item slot sizes after scaling is determined. INV_SLOT_WIDTH = (int)Math.Round(112d * programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero); // Individual inventory slot width. INV_SLOT_HEIGHT = (int)Math.Round(112d * programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero); // Individual inventory slot height. // Standard WinForms stuff. Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // This form finds the process for re2.exe (assigned to gameProc) or waits until it is found. using (mainContext = new ApplicationContext(new AttachUI())) Application.Run(mainContext); // Attach to the re2.exe process now that we've found it and show the UI. using (gameMem = new GameMemory(gameProc)) using (mainContext = new ApplicationContext(new MainUI())) Application.Run(mainContext); }