Skip to content

Commit

Permalink
Add --delay option to wait before injection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keton committed Jan 15, 2024
1 parent f58ccf6 commit 4f32ad6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -335,6 +347,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;
Expand Down Expand Up @@ -377,6 +399,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)
{
Expand Down

0 comments on commit 4f32ad6

Please sign in to comment.