33using System . ComponentModel ;
44using System . ComponentModel . Composition ;
55using System . Diagnostics ;
6+ using System . IO ;
67using System . Linq ;
78using System . Numerics ;
89using 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\n E_NOT_DEFINED\n Status 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 }
0 commit comments