From 335d5972f980d23413aa0473553d34b300c9d1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lower?= Date: Sun, 14 Jan 2024 13:34:16 +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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index 4e78402..c1bd226 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -173,6 +173,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")] @@ -194,6 +195,16 @@ 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; + } } } @@ -258,6 +269,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() { if (m_connected) { @@ -337,6 +349,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; @@ -379,6 +401,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) {