Skip to content

Commit

Permalink
Add --launch= command line argument to start game executables
Browse files Browse the repository at this point in the history
`--launch=` option accepts both executable paths and URIs for launcher
compatibility.

Some games like Sackboy or Telltale Expanse Series on Epic
will fail to launch correctly if .exe path is used directly. Instead they
require proper launcher URI.

This change will allow UEVR fronted to act as a launcher for games.

Example. Creating shortcut to:
```
UEVRInjector.exe "--launch=com.epicgames.launcher://apps/da36711940d4460da57d8d6ad67236a4%3Aa1afcdb1d2344232954be97d4b86b9a8%3Acfbbc006f3ee4ba0bfff3ffa46942f90?action=launch&silent=true" --attach=CosmicShake-Win64-Shipping
```

Will allow to automatically launch and inject Sponge Bob: Cosmic Shake on EGS
  • Loading branch information
keton committed Jan 15, 2024
1 parent 4221f08 commit f58ccf6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public partial class MainWindow : Window {

private ExecutableFilter m_executableFilter = new ExecutableFilter();
private string? m_commandLineAttachExe = null;
private string? m_commandLineLaunchExe = null;
private bool m_ignoreFutureVDWarnings = false;

[System.Runtime.InteropServices.DllImport("user32.dll")]
Expand All @@ -187,6 +188,11 @@ 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;
}
}
}
Expand Down Expand Up @@ -251,6 +257,7 @@ private void RestartAsAdminButton_Click(object sender, RoutedEventArgs e) {
}

private DateTime m_lastAutoInjectTime = DateTime.MinValue;
private bool m_launchExeDone = false;

private void Update_InjectStatus() {
if (m_connected) {
Expand All @@ -261,6 +268,21 @@ 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
});

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";
Expand Down

0 comments on commit f58ccf6

Please sign in to comment.