private void btnLaunch_Click(object sender, EventArgs ea) { if (this.InjectorThread.ThreadState == System.Threading.ThreadState.Stopped) { // Need to remake the thread CreateInjectorThread(); } SetupRegistry(); string gamePath = txtGamePath.Text; if (!File.Exists(gamePath)) { MessageBox.Show("Invalid path - could not find Borderlands 2.exe", "Failed to Launch", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(gamePath)).Length > 0) { MessageBox.Show("Borderlands 2 is already running. Please close it before trying again.", "Failed to Launch", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.GamePath = gamePath; string gameDir = Path.GetDirectoryName(gamePath); Win32.STARTUPINFO lpStartupInfo = new Win32.STARTUPINFO(); Environment.SetEnvironmentVariable("SteamGameId", "49520"); Environment.SetEnvironmentVariable("SteamAppId", "49520"); Win32.PROCESS_INFORMATION lpProcessInformation; bool result = Win32.CreateProcess( gamePath, "-nolauncher", IntPtr.Zero, IntPtr.Zero, false, Win32.CreateProcessFlags.CreateSuspended, IntPtr.Zero, gameDir, ref lpStartupInfo, out lpProcessInformation); if (result) { btnLaunch.Enabled = false; btnLaunch.Text = "Waiting to attach debugger..."; MessageBox.Show("Attach your debugger now"); btnLaunch.Text = "Injecting into Borderlands 2..."; this.InjectorThread.Start(); Win32.CloseHandle(lpProcessInformation.hProcess); Win32.CloseHandle(lpProcessInformation.hThread); } else { MessageBox.Show("Failed to launch Borderlands 2. Error Code = " + Marshal.GetLastWin32Error(), "Failed to Launch", MessageBoxButtons.OK, MessageBoxIcon.Error); } }