Skip to content

Commit

Permalink
Launch game with OpenVR flag if VR is required (#124)
Browse files Browse the repository at this point in the history
* Launch game with openvr flag if VR is enabled
  • Loading branch information
Raicuparta authored Jun 29, 2020
1 parent ea7ca89 commit 0df8464
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class App
private readonly OWPatcher _owPatcher;
private readonly VRPatcher _vrPatcher;

private const string VrArgument = " -vrmode openvr";

public App(IOwmlConfig owmlConfig, IModManifest owmlManifest, IModConsole writer, IModFinder modFinder,
OutputListener listener, PathFinder pathFinder, OWPatcher owPatcher, VRPatcher vrPatcher)
{
Expand Down Expand Up @@ -55,9 +57,10 @@ public void Run(string[] args)

ShowModList(mods);

PatchGame(mods);
var hasVrMod = HasVrMod(mods);
PatchGame(hasVrMod);

StartGame(args);
StartGame(args, hasVrMod);

if (hasPortArgument)
{
Expand Down Expand Up @@ -142,13 +145,18 @@ private void OnOutput(string s)
}
}

private void PatchGame(IList<IModData> mods)
private bool HasVrMod(IList<IModData> mods)
{
_owPatcher.PatchGame();

var vrMod = mods.FirstOrDefault(x => x.Config.RequireVR && x.Config.Enabled);
var enableVR = vrMod != null;
_writer.WriteLine(enableVR ? $"{vrMod.Manifest.UniqueName} requires VR." : "No mods require VR.");
var hasVrMod = vrMod != null;
_writer.WriteLine(hasVrMod ? $"{vrMod.Manifest.UniqueName} requires VR." : "No mods require VR.");
return hasVrMod;
}

private void PatchGame(bool enableVR)
{
_owPatcher.PatchGame();
_vrPatcher.PatchVR(enableVR);
try
{
_vrPatcher.PatchVR(enableVR);
Expand All @@ -159,12 +167,17 @@ private void PatchGame(IList<IModData> mods)
}
}

private void StartGame(string[] args)
private void StartGame(string[] args, bool enableVR)
{
_writer.WriteLine("Starting game...");
try
{
Process.Start($"{_owmlConfig.GamePath}/OuterWilds.exe", string.Join(" ", args));
var gameArgs = string.Join(" ", args);
if (enableVR)
{
gameArgs += VrArgument;
}
Process.Start($"{_owmlConfig.GamePath}/OuterWilds.exe", gameArgs);
}
catch (Exception ex)
{
Expand Down

0 comments on commit 0df8464

Please sign in to comment.