Skip to content

Commit 97337a5

Browse files
committed
Fixed server init hanging
1 parent c6c318a commit 97337a5

File tree

3 files changed

+105
-17
lines changed

3 files changed

+105
-17
lines changed

plugin_OpenVR/Assets/Strings/en.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@
229229
{
230230
"id": "/InputActions/Code/Test",
231231
"translation": "The output from code testing will appear here..."
232+
},
233+
{
234+
"id": "/ServerStatuses/-110/Title",
235+
"translation": "The registered OpenVR driver does not support emulation."
236+
},
237+
{
238+
"id": "/ServerStatuses/-111/Title",
239+
"translation": "The registered OpenVR driver has device and input emulation enabled."
240+
},
241+
{
242+
"id": "/ServerStatuses/-110/Content",
243+
"translation": "Please re-register the driver entry from SteamVR service settings within Amethyst."
244+
},
245+
{
246+
"id": "/ServerStatuses/-111/Content",
247+
"translation": "Please re-register the driver entry from SteamVR service settings within Amethyst."
232248
}
233249
]
234250
}

plugin_OpenVR/OpenVR.cs

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.ComponentModel;
44
using System.ComponentModel.Composition;
55
using System.Diagnostics;
6+
using System.IO;
67
using System.Linq;
78
using System.Numerics;
89
using System.Runtime.InteropServices;
@@ -47,6 +48,7 @@ public class SteamVR : IServiceEndpoint
4748
private uint _vrNotificationId;
4849
private ulong _vrOverlayHandle = OpenVR.k_ulOverlayHandleInvalid;
4950
private bool _isEmulationEnabledLast;
51+
private int _serviceStatus;
5052

5153
public SteamVR()
5254
{
@@ -180,7 +182,25 @@ Host is not null &&
180182

181183
public object SettingsInterfaceRoot => InterfaceRoot;
182184

183-
public int ServiceStatus { get; private set; }
185+
public int ServiceStatus
186+
{
187+
get => _serviceStatus;
188+
private set
189+
{
190+
_serviceStatus = value;
191+
Host.GetType().GetMethod("SetRelayInfoBarOverride")!.Invoke(Host, [
192+
ServiceStatus is -110 or -111
193+
? new InfoBarData
194+
{
195+
Title = Host?.RequestLocalizedString($"/ServerStatuses/{_serviceStatus}/Title"),
196+
Content = Host?.RequestLocalizedString($"/ServerStatuses/{_serviceStatus}/Content"),
197+
IsOpen = true,
198+
Closable = false
199+
}.AsPackedData
200+
: null
201+
]);
202+
}
203+
}
184204

185205
[DefaultValue("Not Defined\nE_NOT_DEFINED\nStatus message not defined!")]
186206
public string ServiceStatusString => PluginLoaded
@@ -207,8 +227,8 @@ 1 when VrHelper.IsCurrentProcessElevated() =>
207227
.Replace("{0}", ServiceStatus.ToString()),
208228

209229
-10 => Host.RequestLocalizedString("/ServerStatuses/Exception")
210-
.Replace("{0}", ServiceStatus.ToString()
211-
.Replace("{1}", ServerDriverException.Message)),
230+
.Replace("{0}", ServiceStatus.ToString())
231+
.Replace("{1}", ServerDriverException.Message),
212232

213233
-2 => Host.RequestLocalizedString("/ServerStatuses/RPCChannelFailure")
214234
.Replace("{0}", ServiceStatus.ToString()),
@@ -344,7 +364,7 @@ public void OnLoad()
344364
VrInputStatic = VrInput;
345365
HostStatic = Host;
346366

347-
Settings ??= new SettingsPage { DataParent = this, Host = Host };
367+
Settings = new SettingsPage { DataParent = this, Host = Host };
348368
InterfaceRoot = new Page
349369
{
350370
Content = Settings
@@ -480,7 +500,7 @@ public void DisplayToast((string Title, string Text) message)
480500
get
481501
{
482502
if (!Initialized || OpenVR.System is null) return (Vector3.Zero, Quaternion.Identity); // Sanity check
483-
if (IsHeadsetEmulationEnabled) return null; // Sanity check don't inbreed calibration poses
503+
// if (IsHeadsetEmulationEnabled) return null; // Sanity check don't inbreed calibration poses
484504

485505
// Capture RAW HMD pose
486506
var devicePose = new TrackedDevicePose_t[1]; // HMD only
@@ -501,6 +521,37 @@ public void DisplayToast((string Title, string Text) message)
501521
}
502522
}
503523

524+
public List<TrackerBase> GetTrackerPoses()
525+
{
526+
if (!Initialized || OpenVR.System is null) return null; // Sanity check
527+
528+
string GetDeviceName(uint index)
529+
{
530+
StringBuilder serialStringBuilder = new(1024);
531+
var serialError = ETrackedPropertyError.TrackedProp_Success;
532+
OpenVR.System.GetStringTrackedDeviceProperty(index, ETrackedDeviceProperty.Prop_SerialNumber_String,
533+
serialStringBuilder, (uint)serialStringBuilder.Capacity, ref serialError);
534+
535+
return serialStringBuilder.ToString();
536+
}
537+
538+
var devicePose = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
539+
OpenVR.System.GetDeviceToAbsoluteTrackingPose(
540+
ETrackingUniverseOrigin.TrackingUniverseStanding, 0, devicePose);
541+
542+
// Get pos & rot
543+
return devicePose.Select((x, i) => new TrackerBase
544+
{
545+
Serial = GetDeviceName((uint)i),
546+
Position = Vector3.Transform(x
547+
.mDeviceToAbsoluteTracking.GetPosition() - VrPlayspaceTranslation,
548+
Quaternion.Inverse(VrPlayspaceOrientationQuaternion)),
549+
550+
Orientation = Quaternion.Inverse(VrPlayspaceOrientationQuaternion) *
551+
x.mDeviceToAbsoluteTracking.GetOrientation()
552+
}).ToList();
553+
}
554+
504555
public TrackerBase GetTrackerPose(string contains, bool canBeFromAmethyst = true)
505556
{
506557
if (!Initialized || OpenVR.System is null) return null; // Sanity check
@@ -725,12 +776,14 @@ private async Task<int> InitAmethystServerAsync(string target)
725776
Host?.Log(e.ToString(), LogSeverity.Error);
726777
ServerDriverException = e;
727778

779+
Host?.Log(Path.Join(ApplicationData.Current.LocalFolder.Path, "Amethyst"));
780+
728781
return IsEmulationEnabled switch
729782
{
730-
true when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
731-
.CreateFolderAsync("Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -110,
732-
false when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
733-
.CreateFolderAsync("00Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -111,
783+
true when OpenVrPaths.TryRead()?.external_drivers.Contains(
784+
Path.Join(ApplicationData.Current.LocalFolder.Path, "Amethyst")) ?? false => -110,
785+
false when OpenVrPaths.TryRead()?.external_drivers.Contains(
786+
Path.Join(ApplicationData.Current.LocalFolder.Path, "00Amethyst")) ?? false => -111,
734787
_ => -1
735788
};
736789
}
@@ -741,10 +794,10 @@ false when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationDa
741794

742795
return IsEmulationEnabled switch
743796
{
744-
true when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
745-
.CreateFolderAsync("Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -110,
746-
false when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
747-
.CreateFolderAsync("00Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -111,
797+
true when OpenVrPaths.TryRead()?.external_drivers.Contains(
798+
Path.Join(ApplicationData.Current.LocalFolder.Path, "Amethyst")) ?? false => -110,
799+
false when OpenVrPaths.TryRead()?.external_drivers.Contains(
800+
Path.Join(ApplicationData.Current.LocalFolder.Path, "00Amethyst")) ?? false => -111,
748801
_ => -1
749802
};
750803
}
@@ -804,10 +857,10 @@ private async Task<int> CheckK2ServerStatusAsync()
804857

805858
return IsEmulationEnabled switch
806859
{
807-
true when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
808-
.CreateFolderAsync("Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -110,
809-
false when OpenVrPaths.TryRead()?.external_drivers.Contains((await ApplicationData.Current.LocalFolder
810-
.CreateFolderAsync("00Amethyst", CreationCollisionOption.OpenIfExists)).Path) ?? false => -111,
860+
true when OpenVrPaths.TryRead()?.external_drivers.Contains(
861+
Path.Join(ApplicationData.Current.LocalFolder.Path, "Amethyst")) ?? false => -110,
862+
false when OpenVrPaths.TryRead()?.external_drivers.Contains(
863+
Path.Join(ApplicationData.Current.LocalFolder.Path, "00Amethyst")) ?? false => -111,
811864
_ => -1
812865
};
813866
}

plugin_OpenVR/Utils/PackageUtils.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Net;
45
using Windows.ApplicationModel;
56
using Windows.Management.Deployment;
67
using Windows.Storage;
@@ -47,4 +48,22 @@ public static void CopyToFolder(this DirectoryInfo source, string destination, b
4748
foreach (var newPath in source.GetFiles("*.*", SearchOption.AllDirectories))
4849
newPath.CopyTo(newPath.FullName.Replace(source.FullName, destination), true);
4950
}
51+
}
52+
53+
public class InfoBarData
54+
{
55+
public string Title { get; set; }
56+
public string Content { get; set; }
57+
public string Button { get; set; }
58+
public Action Click { get; set; }
59+
public bool Closable { get; set; }
60+
public bool IsOpen { get; set; }
61+
62+
public (string Title, string Content, string Button, Action Click, bool Closable)? AsPackedData =>
63+
IsOpen ? (Title, Content, Button, Click, Closable) : null;
64+
65+
public void ClickAction(object sender, object args)
66+
{
67+
Click();
68+
}
5069
}

0 commit comments

Comments
 (0)