Skip to content

Commit

Permalink
Use OpenVR to find SteamVR to find it's manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ybalrid committed May 10, 2021
1 parent 5f80f5f commit 59fc76f
Show file tree
Hide file tree
Showing 6 changed files with 8,275 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third-party/openvr"]
path = third-party/openvr
url = https://github.com/ValveSoftware/openvr
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="openvr_api.cs" />
<Compile Include="Runtime.cs" />
<Compile Include="RuntimeManager.cs" />
<Compile Include="Version.cs" />
Expand Down Expand Up @@ -158,5 +159,16 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="openvr_api.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy $(ProjectDir)openvr_api.dll $(TargetDir)</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>copy $(ProjectDir)..\..\third-party\openvr\bin\win64\openvr_api.dll ${ProjectDir)
copy $(ProjectDir)..\..\third-party\openvr\headers\openvr_api.cs ${ProjectDir)
</PreBuildEvent>
</PropertyGroup>
</Project>
41 changes: 39 additions & 2 deletions OpenXR-Runtime-Manager/OpenXR-Runtime-Manager/RuntimeManager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using Microsoft.Win32;
using Newtonsoft.Json;
using Valve.VR;

namespace OpenXR_Runtime_Manager
{
class RuntimeManager
{
//TODO make a database of paths to manifest for known OpenXR runtimes that are compatible with MS Windows
readonly string[] WellKnwonOpenXRRuntimeManifestPaths =
List<string> WellKnwonOpenXRRuntimeManifestPaths = new List<string>()
{
"%ProgramFiles(x86)%\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json",
"%ProgramFiles%\\Oculus\\Support\\oculus-runtime\\oculus_openxr_32.json",
"%ProgramFiles%\\Oculus\\Support\\oculus-runtime\\oculus_openxr_64.json",
"%windir%\\system32\\MixedRealityRuntime.json",
Expand Down Expand Up @@ -148,9 +150,44 @@ private static string GetKhronosOpenXRVersionRegistryKeyPath(int OpenXRVersion =
return $@"SOFTWARE\Khronos\OpenXR\{OpenXRVersion}";
}

/// <summary>
/// Uses OpenVR to query the installation path of SteamVR, to then build the path to the OpenXR manifest file
/// </summary>
/// <returns>True upon success. </returns>
private bool ProbeForSteamVRInstallationPath()
{
StringBuilder pathBuilder = new StringBuilder(256);
uint bufferSize = (uint)pathBuilder.Length;
try
{
if (OpenVRInterop.GetRuntimePath(pathBuilder, bufferSize, ref bufferSize))
{
string pathToSteamVR = pathBuilder.ToString();
Debug.Print($"Found a SteamVR installation at {pathToSteamVR}");
string pathToSteamVRManifest = Path.Combine(pathBuilder.ToString(), "steamxr_win64.json");
WellKnwonOpenXRRuntimeManifestPaths.Add(pathToSteamVRManifest);
return true;
}
return false;
}
catch(DllNotFoundException e)
{
Debug.Print("Missing openvr_api.dll?!");
Debug.Print(e.Message);
return false;
}
}

public RuntimeManager()
{
GetActiveRuntimeFromRegistry();

if(!ProbeForSteamVRInstallationPath())
{
Debug.Print("This system seems to not have SteamVR installed, or we cannot call OpenVR for some other reasons. Will probe in default installation folder instead");
WellKnwonOpenXRRuntimeManifestPaths.Add("%ProgramFiles(x86)%\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json");
}

ProbeForAdditionalRuntimes();

foreach (KeyValuePair<string, Runtime> availableRuntime in _availableRuntimes)
Expand Down
Loading

0 comments on commit 59fc76f

Please sign in to comment.