Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
HyrumGG committed Jun 4, 2022
1 parent 2724be9 commit 8131793
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 142 deletions.
39 changes: 0 additions & 39 deletions OculusKiller/Oculus.cs

This file was deleted.

2 changes: 0 additions & 2 deletions OculusKiller/OculusKiller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Oculus.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteamVR.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
104 changes: 79 additions & 25 deletions OculusKiller/Program.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace OculusKiller
{
public class Program
{
static Oculus oculus = new Oculus();
static SteamVR steamVR = new SteamVR();

static bool UpdateVars()
{
return oculus.Update() && steamVR.Update();
}

static void Main()
{
try
{
// Try to update our variables, We don't have to worry about error messages!
// The update functions should also verify that everything is correct!
if (!UpdateVars()) return;

// Start and find the VR Server, then wait for it to exit!
Process.Start(steamVR.startupPath).WaitForExit();
string oculusPath = GetOculusPath();
var result = GetSteamPaths();
if (result == null || String.IsNullOrEmpty(oculusPath))
{
return;
}
string startupPath = result.Item1;
string vrServerPath = result.Item2;

Process.Start(startupPath).WaitForExit();

long loopStartTime = DateTimeOffset.Now.ToUnixTimeSeconds();
while (true) {
// Make sure this doesn't go infinitely... Let's give it, 10 seconds!
if (DateTimeOffset.Now.ToUnixTimeSeconds() - loopStartTime >= 10)
Stopwatch sw = Stopwatch.StartNew();
while (true)
{
if (sw.ElapsedMilliseconds >= 10000)
{
MessageBox.Show("SteamVR VR server not found... (Did SteamVR crash?)");
MessageBox.Show("SteamVR vrserver not found... (Did SteamVR crash?)");
return;
}

// Don't give the user an error if the process isn't found, it happens often...
Process vrServerProcess = Array.Find(Process.GetProcessesByName("vrserver"), steamVR.IsServer);
if (vrServerProcess == null) continue;
Process vrServerProcess = Array.Find(Process.GetProcessesByName("vrserver"), process => process.MainModule.FileName == vrServerPath);
if (vrServerProcess == null)
continue;
vrServerProcess.WaitForExit();

// Find the OVR Server (So we can kill it)
// No-one would ever use the name "OVRServer_x64" but let's just be safe...
Process ovrServerProcess = Array.Find(Process.GetProcessesByName("OVRServer_x64"), oculus.IsServer);
Process ovrServerProcess = Array.Find(Process.GetProcessesByName("OVRServer_x64"), process => process.MainModule.FileName == oculusPath);
if (ovrServerProcess == null)
{
MessageBox.Show("Oculus runtime not found...");
return;
}

// Kill it in order to stop Link, it doesn't even give the user an error, nice!
ovrServerProcess.Kill();
ovrServerProcess.WaitForExit();
break;
Expand All @@ -60,5 +56,63 @@ static void Main()
MessageBox.Show($"An exception occured while attempting to find/start SteamVR...\n\nMessage: {e}");
}
}

static string GetOculusPath()
{
string oculusPath = Environment.GetEnvironmentVariable("OculusBase");
if (string.IsNullOrEmpty(oculusPath))
{
MessageBox.Show("Oculus installation environment not found...");
return null;
}

oculusPath = Path.Combine(oculusPath, @"Support\oculus-runtime\OVRServer_x64.exe");
if (!File.Exists(oculusPath))
{
MessageBox.Show("Oculus server executable not found...");
return null;
}

return oculusPath;
}

public static Tuple<string, string> GetSteamPaths()
{
string openVrPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"openvr\openvrpaths.vrpath");
if (!File.Exists(openVrPath))
{
MessageBox.Show("OpenVR Paths file not found... (Has SteamVR been run once?)");
return null;
}

try
{
JavaScriptSerializer jss = new JavaScriptSerializer();
string openvrJsonString = File.ReadAllText(openVrPath);
dynamic openvrPaths = jss.DeserializeObject(openvrJsonString);

string location = openvrPaths["runtime"][0].ToString();
string startupPath = Path.Combine(location, @"bin\win64\vrstartup.exe");
string serverPath = Path.Combine(location, @"bin\win64\vrserver.exe");

if (!File.Exists(startupPath))
{
MessageBox.Show("SteamVR startup executable does not exist... (Has SteamVR been run once?)");
return null;
}
if (!File.Exists(serverPath))
{
MessageBox.Show("SteamVR server executable does not exist... (Has SteamVR been run once?)");
return null;
}

return new Tuple<string, string>(startupPath, serverPath);
}
catch (Exception e)
{
MessageBox.Show($"Corrupt OpenVR Paths file found... (Has SteamVR been run once?)\n\nMessage: {e}");
}
return null;
}
}
}
76 changes: 0 additions & 76 deletions OculusKiller/SteamVR.cs

This file was deleted.

0 comments on commit 8131793

Please sign in to comment.