diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index b8edd14..181a008 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -172,6 +172,9 @@ public partial class MainWindow : Window { private ExecutableFilter m_executableFilter = new ExecutableFilter(); private string? m_commandLineAttachExe = null; + private string? m_commandLineLaunchExe = null; + private string? m_commandLineLaunchArgs = null; + private int m_commandLineDelayInjection = 0; private bool m_ignoreFutureVDWarnings = false; [System.Runtime.InteropServices.DllImport("user32.dll")] @@ -187,6 +190,25 @@ public MainWindow() { foreach (string arg in args) { if (arg.StartsWith("--attach=")) { m_commandLineAttachExe = arg.Split('=')[1]; + continue; + } + if (arg.StartsWith("--launch=")) { + m_commandLineLaunchExe = arg.Substring(arg.IndexOf('=') + 1); // game exe URI may contain any characters including '=' + continue; + } + if (arg.StartsWith("--launch_args=")) { + m_commandLineLaunchArgs = arg.Substring(arg.IndexOf('=') + 1); // space separated list of game exe arguments + continue; + } + if (arg.StartsWith("--delay=")) { + try { + m_commandLineDelayInjection = int.Parse(arg.Split('=')[1]); + } + catch { + m_commandLineDelayInjection = 0; + } + + continue; } } } @@ -251,6 +273,8 @@ private void RestartAsAdminButton_Click(object sender, RoutedEventArgs e) { } private DateTime m_lastAutoInjectTime = DateTime.MinValue; + private bool m_launchExeDone = false; + private int? m_delayInjectionTimer = null; private void Update_InjectStatus() { if (m_connected) { @@ -261,6 +285,22 @@ private void Update_InjectStatus() { DateTime now = DateTime.Now; TimeSpan oneSecond = TimeSpan.FromSeconds(1); + if (m_commandLineLaunchExe != null && !m_launchExeDone) { + try { + Process.Start(new ProcessStartInfo { + FileName = m_commandLineLaunchExe, + UseShellExecute = true, // for launcher compatiblity, executable might be an URI + Arguments = m_commandLineLaunchArgs + }); + + m_launchExeDone = true; + } + catch (Exception) { + MessageBox.Show("Failed to launch: " + m_commandLineLaunchExe, "Launch error", MessageBoxButton.OK, MessageBoxImage.Error); + Application.Current.Dispatcher.Invoke(new Action(() => { Application.Current.Shutdown(1); })); + } + } + if (m_commandLineAttachExe == null) { if (m_lastSelectedProcessId == 0) { m_injectButton.Content = "Inject"; @@ -313,6 +353,16 @@ private void Update_InjectStatus() { return; } + if (m_commandLineDelayInjection > 0) { + if (m_delayInjectionTimer == null) { + m_delayInjectionTimer = m_commandLineDelayInjection; + } + + m_injectButton.Content = m_commandLineAttachExe.ToLower() + " found. Delaying " + m_delayInjectionTimer + "s"; + m_delayInjectionTimer--; + if (m_delayInjectionTimer > 0) return; + } + if (now - m_lastAutoInjectTime > oneSecond) { if (m_nullifyVRPluginsCheckbox.IsChecked == true) { IntPtr nullifierBase; @@ -355,6 +405,8 @@ private void Update_InjectStatus() { m_lastAutoInjectTime = now; m_commandLineAttachExe = null; // no need anymore. + m_delayInjectionTimer = null; + m_commandLineDelayInjection = 0; FillProcessList(); if (m_focusGameOnInjectionCheckbox.IsChecked == true) {