From 82bf7a5daadd3715bddd7759f0b6a53fcec60e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lower?= Date: Sun, 14 Jan 2024 12:51:27 +0100 Subject: [PATCH] Add `--delay` option to wait before injection Some games don't respond well to be injected directly on boot. Intro movies, menus, loading screens can appear broken or as a black screen. This commit augments `--attach` mode with `--delay` parameter allowing UEVR injector to wait upon detecting target application. This gives user time to get into the game without needing to go back to the injector UI and pressing inject manually. Example: `UEVRInjector.exe --attach=CosmicShake-Win64-Shipping --delay=30` will wait for SpongeBob Cosmic Shake process to spawn, then wait 30s on top and inject. --- UEVR/MainWindow.xaml.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index 3016f86..be0a779 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -195,6 +195,7 @@ public partial class MainWindow : Window private ExecutableFilter m_executableFilter = new ExecutableFilter(); private string? m_commandLineAttachExe = null; private string? m_commandLineLaunchExe = null; + private int m_commandLineDelayInjection = 0; private bool m_ignoreFutureVDWarnings = false; [System.Runtime.InteropServices.DllImport("user32.dll")] @@ -220,6 +221,19 @@ public MainWindow() m_commandLineLaunchExe = arg.Substring(arg.IndexOf('=') + 1); // game exe URI may contain any characters including '=' continue; } + if (arg.StartsWith("--delay=")) + { + try + { + m_commandLineDelayInjection = int.Parse(arg.Split('=')[1]); + } + catch + { + m_commandLineDelayInjection = 0; + } + + continue; + } } } @@ -295,6 +309,7 @@ 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() { @@ -394,6 +409,18 @@ 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) @@ -453,6 +480,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) {