Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement launcher integration #9

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Loading