Skip to content

Commit

Permalink
Offer option to automatically remove unwanted plugins on launch
Browse files Browse the repository at this point in the history
This commit allows option to automatically delete unwanted VR plugins.
All user needs to do is to click 'yes'.

Additionally game is checked before launch for being UE title and
warning is issued if it's not.

This requires `--attach=` parameter to be full path to game executable.
If only process name is passed old behavior is used instead.
  • Loading branch information
keton committed Jan 16, 2024
1 parent 1f1b0f3 commit 9eedc83
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using static UEVR.SharedMemory;
using System.Threading.Channels;
using System.Security.Principal;
using Path = System.IO.Path;

namespace UEVR {
class GameSettingEntry : INotifyPropertyChanged {
Expand Down Expand Up @@ -172,6 +173,7 @@ public partial class MainWindow : Window {

private ExecutableFilter m_executableFilter = new ExecutableFilter();
private string? m_commandLineAttachExe = null;
private string? m_commandLineAttachExePath = null;
private string? m_commandLineLaunchExe = null;
private string? m_commandLineLaunchArgs = null;
private int m_commandLineDelayInjection = 0;
Expand All @@ -190,6 +192,11 @@ public MainWindow() {
foreach (string arg in args) {
if (arg.StartsWith("--attach=")) {
m_commandLineAttachExe = arg.Split('=')[1];

if(m_commandLineAttachExe.EndsWith(".exe")) {
m_commandLineAttachExePath = Path.GetDirectoryName(m_commandLineAttachExe);
m_commandLineAttachExe = Path.GetFileNameWithoutExtension(m_commandLineAttachExe);
}
continue;
}
if (arg.StartsWith("--launch=")) {
Expand Down Expand Up @@ -286,6 +293,39 @@ private void Update_InjectStatus() {
TimeSpan oneSecond = TimeSpan.FromSeconds(1);

if (m_commandLineLaunchExe != null && !m_launchExeDone) {
if(m_commandLineAttachExePath != null && m_commandLineAttachExe != null) {
if(!IsUnrealEngineGame(m_commandLineAttachExePath, m_commandLineAttachExe)) {
var result = MessageBox.Show(m_lastSelectedProcessName + " does not appear to be an Unreal Engine title.\n" +
"Do you want to proceed?",
"Non UE game",
MessageBoxButton.YesNo, MessageBoxImage.Warning);
switch (result) {
case MessageBoxResult.Yes:
break;
case MessageBoxResult.No:
Application.Current.Dispatcher.Invoke(new Action(() => { Application.Current.Shutdown(1); }));
break;
};
}

var pluginsDir = AreVRPluginsPresent(m_commandLineAttachExePath);
if(pluginsDir != null) {
var result = MessageBox.Show("VR plugins have been detected in game directory.\n" +
"Do you want to automatically remove them?\n" +
"NOTE: for a handful of games deleting VR plugins will lead to game crashes",
"VR Plugins detected",
MessageBoxButton.YesNo, MessageBoxImage.Question);

switch (result) {
case MessageBoxResult.Yes:
RemoveVRPlugins(pluginsDir);
break;
case MessageBoxResult.No:
break;
};
}
}

try {
Process.Start(new ProcessStartInfo {
FileName = m_commandLineLaunchExe,
Expand Down Expand Up @@ -689,6 +729,22 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent
return null;
}

private void RemoveVRPlugins(string? pluginsPath) {
if(pluginsPath == null) return;

foreach (string discouragedPlugin in m_discouragedPlugins) {
string pluginPath = pluginsPath + "\\" + discouragedPlugin;

if (Directory.Exists(pluginPath)) {
try {
Directory.Delete(pluginPath, true);
} catch (Exception) {
MessageBox.Show("Failed to delete:" + pluginPath);
}
}
}
}

private bool IsUnrealEngineGame(string gameDirectory, string targetName) {
try {
if (targetName.ToLower().EndsWith("-win64-shipping")) {
Expand Down

0 comments on commit 9eedc83

Please sign in to comment.