Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/monstermac77/vr into main
Browse files Browse the repository at this point in the history
  • Loading branch information
monstermac77 committed Feb 9, 2021
2 parents bb93dfa + cb80e9a commit 869c051
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 31 deletions.
12 changes: 12 additions & 0 deletions bin/mixedvr-manager-startup-wrapper.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off

:: NOTE: If you want to launch MixedVR-Manager manually in a terminal window, please run "mixedvr-manager.bat" as admin
:: this file should only be run by the scheduled task in elevated permissions
:: Another note: have confirmed that we still need to launch through vbs to make the program run headlessly

:: file path for MixedVR-Manager from argument passed in by scheduled task
:: using %* to collate all arguments to catch where filepath has spaces (and therefore passed as multiple parameters)
set FilePath=%*

:: call vbs script and pass file path as argument
"%FilePath%\bin\mixedvr-manager-startup.vbs" "%FilePath%"
19 changes: 19 additions & 0 deletions bin/mixedvr-manager-startup.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'Thank you: https://superuser.com/a/140077/699131
'This is how you can determine what process this is in task manager: https://superuser.com/a/362167/699131

Dim FilePath

'Check if active filepath is provided as argument, otherwise default to current working directory
If WScript.Arguments.Count > 0 Then
FilePath = WScript.Arguments(0) & ""
Else
FilePath = ""
End if

'Call runtime bat via absolute path - again admin rights appears to cause issues with relative paths
'with VBS it seems to run from C:\Windows\System32\
'additional escaped quotes to allow for filepaths with spaces
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c """ & FilePath & "\bin\mixedvr-manager.bat"""
oShell.Run strArgs, 0, false
53 changes: 34 additions & 19 deletions mixedvr-manager.bat → bin/mixedvr-manager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ setlocal EnableDelayedExpansion
:: This script was created for users of MixedVR (see the /r/MixedVR subreddit) by monstermac77
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: TODO: allow users to specify what kind of headset, right now this script only supports WMR
:: TODO: figure out how to tuck this bat file in a "source" folder so that users only see the vbs and config file
:: TODO: allow users to specify what kind of headset, right now this script only supports WMR (note: will need to modify the uninstall script too)
:: TODO: minimize WMR immediately
:: TODO: Tetracyclic should make it so that lighthouse-keeper has its own config file that it automatically populates with the MAC addresses; it automatically runs "discover" on first run, and populates this, so the user doesn't have to do this setup
:: TODO: Tetracyclic, in addition to above, should detect what version of lighthouses they have
:: TODO: submit our files to Microsoft for approval: https://www.microsoft.com/en-us/wdsi/filesubmission
:: TODO: make a note in the readme that sometimes steam decides to create multiple chaperone universes, it's best to delete all but one and save that one
:: TODO: add logging

:: Notes for debugging:
:: * Prevent the script from starting on startup (or kill it) and then run the .bat file so you can see the output (never click in the window, just do command+tab)
:: * When debugging syntax errors, comment the line at the top of the file
:: * To debug the script crashing, comment the "@echo off" at the top, then run the `.bat` this way so you can see what line it's crashing on: `cmd /k "cd c:\myfolder & mixedvr-manager.bat"`
:: * The most common case for crashing seems to be adding parens inside comments that are inside for/if statements...

:::::::: release process ::::::::
:: `git tag v1.x`
Expand All @@ -34,11 +34,16 @@ setlocal EnableDelayedExpansion

title MixedVR Manager

:: running .bat files with admin rights appears to prevent calls to external scripts (e.g. lighthouse-keeper, USBDeview) using relative paths
:: so this gets the working directory so we can use absolute paths, i.e. "%mixedVRManagerDirectory%[application]", as you can see below
set mixedVRManagerDirectory=%~dp0

:: goto marker (start of loop)
:whileTrueLoop
:whileTrueLoop

:: calling config here, which allows hotswapping of configurations
call config.bat
:: note the ..\ as we are in \bin and config is up a folder (in the root)
call "%mixedVRManagerDirectory%..\config.bat"

:: check to see if steamvr is running (thank you https://stackoverflow.com/a/1329790/2611730)
tasklist /FI "IMAGENAME eq vrserver.exe" 2>NUL | find /I /N "vrserver.exe">NUL
Expand Down Expand Up @@ -96,7 +101,7 @@ if "%steamvrStatus%" == "running" (set desiredHMDUSBAction=enable) else (set des
if "%allowHMDManagement%" == "true" (
:: toggle state of the USB that the headset is plugged into
echo MixedVR-Manager is changing state of USB device, the HMD, to /!desiredHMDUSBAction!...
bin\USBDeview.exe /RunAsAdmin /!desiredHMDUSBAction! "HoloLens Sensors"
"%mixedVRManagerDirectory%USBDeview.exe" /RunAsAdmin /!desiredHMDUSBAction! "HoloLens Sensors"
) else (
echo MixedVR-Manager is skipping changing state of the HMD to %desiredHMDUSBAction%, per user's configuration
)
Expand All @@ -107,10 +112,10 @@ if "%steamvrStatus%" == "running" (set desiredLighthouseState=on) else (set desi
if "%allowLighthouseManagement%" == "true" (
echo MixedVR-Manager is turning lighthouses v%lighthouseVersion% %desiredLighthouseState%...
if "%lighthouseVersion%" == "2.0" (
bin\lighthouse-keeper.exe 2 %desiredLighthouseState% %lighthouseMACAddressList%
"%mixedVRManagerDirectory%lighthouse-keeper.exe" 2 %desiredLighthouseState% %lighthouseMACAddressList%
)
if "%lighthouseVersion%" == "1.0" (
bin\lighthouse-keeper.exe 1 %desiredLighthouseState% %lighthouseMACAddressList%
"%mixedVRManagerDirectory%lighthouse-keeper.exe" 1 %desiredLighthouseState% %lighthouseMACAddressList%
)
) else (
echo MixedVR-Manager is skipping changing state of the lighthouses to %desiredLighthouseState%, per user's configuration
Expand All @@ -119,42 +124,44 @@ if "%allowLighthouseManagement%" == "true" (
:: otherwise we try killing it before it has started, which ends up with us having never
:: restarted it. The symptom for this is SteamVR is unable to detect the HMD even though it's enabled.
:: TODO: could improve this by doing the same waiting method we do for room setup, since it might take longer than
:: 15 seconds for SteamVR to start up on some people's machines
:: x seconds for SteamVR to start up on some people's machines. If we do this method, we should take it out of this
:: if statement and just apply it to all users, not just those not using lighthouses
echo Waiting %maxLaunchTimeForSteamVR% seconds for SteamVR to launch...
timeout %maxLaunchTimeForSteamVR% >NUL
)
)


:: restore SteamVR home state (if the user has added SAVE files)
if exist userdata\SAVE\save_game_steamvr_home.sav (
if exist "%mixedVRManagerDirectory%..\userdata\SAVE\save_game_steamvr_home.sav" (
echo MixedVR-Manager is overwriting the existing SteamVR Home layout with the user specified SteamVR Home...
for %%f in (userdata\SAVE\*) do (
:: TODO bug: now that we're absolute pathing, this just straight up isn't working when there's a space in the name
:: need to figure it out, originally this was just: for %%f in userdata\SAVE\* do
for %%f in (%mixedVRManagerDirectory%..\userdata\SAVE\*) do (
xcopy /y %%f "%steamVRPath%\tools\steamvr_environments\game\steamtours\SAVE"
)
)

:: restore SteamVR chaperone bounds state (if the user has added chaperone_info.vrchap)
if exist userdata\chaperone_info.vrchap (
if exist "%mixedVRManagerDirectory%..\userdata\chaperone_info.vrchap" (
echo MixedVR-Manager is overwriting the existing SteamVR chaperone bounds with the user specified chaperone bounds...
xcopy /y userdata\chaperone_info.vrchap "%steamPath%\config"
xcopy /y "%mixedVRManagerDirectory%..\userdata\chaperone_info.vrchap" "%steamPath%\config"
)

:: if we're switching to the running state, then we also need to restart SteamVR now that
:: the headset has been enabled, this is because sadly SteamVR requires the headset to be connected when SteamVR is opened
:: note, we need to kill room setup if it's running because otherwise it may still be open when we
:: start relying on it being quit when blocking on the next loop
if "%steamvrStatus%" == "running" (
echo MixedVR-Manager is restarting SteamVR so it SteamVR can detect the now powered on lighthouses and HMD.
echo MixedVR-Manager is restarting SteamVR so SteamVR can detect the now powered on lighthouses and HMD.
taskkill /f /im "steamvr_room_setup.exe" 2>NUL
taskkill /f /im "vrmonitor.exe"
taskkill /f /im "vrserver.exe"
taskkill /f /im "OpenVR-SpaceCalibrator.exe" 2>NUL
start steam://launch/250820/VR

:: wait until SteamVR Room Setup starts, then kill it. if it doesn't start after
:: maxWaitTimeForRoomSetup seconds, assume it's never going to start, and just
:: continue with the script's execution.
:: 90 seconds, assume it's never going to start, and just continue with the script's execution.
:: this is only applicable to MixedVR users who are forcing the SteamVR chaperone bounds
:: note: this "delayed expansion" business really got me; apparently variables are
:: evaluated before execution time unless you do this and then use ! instead of %. Craziness.
echo Waiting for SteamVR to start back up and to close Room Setup, will wait up to 90 seconds...
Expand All @@ -168,12 +175,20 @@ if "%steamvrStatus%" == "running" (
timeout 1 >NUL
)

:: also allow this loop to be exited earlier if SteamVR has become quit
:: although not likely during real use sessions, it's possible that SteamVR is quit or crashes
:: before SteamVR Room setup is launched, or for non-MixedVR users, room setup will never launch
:: therefore we allow an early exit from this 90 second loop if we detect that SteamVR has actually
:: been quit already, allowing us to do the setup procedure now, rather than after 90 seconds, which is
:: a huge difference. Note that we have to wait for SteamVR to actually launch first
:: TODO we could do this better, by checking to see if it has opened and then closed, but instead
:: we're just going to wait x seconds no matter what. This could end up being an issue soon, if a lot of
:: people have machines that can't launch SteamVR in that sensible default. In that cause, we should detect
:: when it opens and then closes
if %%i geq %maxLaunchTimeForSteamVR% (
tasklist /FI "IMAGENAME eq vrserver.exe" 2>NUL | find /I /N "vrserver.exe">NUL
if "!ERRORLEVEL!"=="0" (set steamvrWaitingStatus=running) else (set steamvrWaitingStatus=quit)
if "!steamvrWaitingStatus!" == "quit" (
echo SteamVR was exited or crashed almost immediately after start of play session. User is likely testing script or serious issue is occuring.
echo SteamVR was exited or crashed almost immediately after start of play session. User is likely testing script, has slow computer, or serious issue is occuring.
goto roomSetupQuitComplete
)
)
Expand Down
11 changes: 6 additions & 5 deletions config.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

:: NOTE: when you change something in this file and save, the changes take effect immediately. No reboot required!

:: specify whether you want MixedVR Manager to turn on/off your lighthouses
:: specify whether you want MixedVR Manager to turn on/off your lighthouses (a.k.a basestations)
:: if you don't have lighthouses, you NEED to set this to false
set allowLighthouseManagement=true

Expand All @@ -15,17 +15,18 @@ set allowHMDManagement=true
:: specify the MAC addresses of your lighthouses (a.k.a basestations) here, separated by a space
:: To find the MAC addresses you can:
:: 1. Open up "Command Prompt"
:: 2. Navigate to the directory this config file is in, e.g. `cd C:\Users\Joe\Dropbox\big-bro-peep\vr\bin\`
:: 2. Navigate to the bin directory in this folder, e.g. `cd C:\Users\Joe\Dropbox\big-bro-peep\vr\bin\`
:: 3. Run `lighthouse-keeper.exe 2 discover` (change the 2 to a 1 if you have 1.0 lighthouses)
:: NOTE: you may have to run the discover command several times before you get both MAC addresses
set lighthouseMACAddressList=FE:D0:49:F5:78:D6 E2:81:7F:AC:2B:ED

:: specify what version of lighthouses (a.k.a basestations) you're using, 2.0 or 1.0
:: specify what version of lighthouses you're using, 2.0 or 1.0
set lighthouseVersion=2.0

:: maxLaunchTimeForSteamVR is how long (in seconds) you ever would expect it to take for SteamVR to launch.
:: if you have a slow machine and MixedVR Manager isn't working, increase this value.
set maxLaunchTimeForSteamVR=15
:: if you have a slow machine and MixedVR Manager isn't working, increase this value. Likewise, if you have a fast machine
:: and you want to reduce your VR launch/exit time, you can try lowering this value (with caution).
set maxLaunchTimeForSteamVR=20

:: steamPath is the directory where you have Steam installed; it's only used for the restoring SteamVR home state and for restoring the chaperone bounds
:: state, both of which are optional features which are disabled by default, so don't be concerned if this path is wrong if you're not using those features
Expand Down
41 changes: 41 additions & 0 deletions install-mixedvr-manager.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off

:: NOTE: If you want to launch MixedVR-Manager manually in a terminal window, please run "mixedvr-manager.bat" as admin

:: NOTE: This installer must be run as administrator (ty: https://stackoverflow.com/a/11995662/2611730)
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed. Proceeding with install...
) else (
echo Failure: Current permissions inadequate. Please right click on file and select "Run as Administrator"
timeout 10 >NUL
exit
)

:: find location of Mixed VR Manager
set MixedVRManagerFolder=%~dp0

:: remove trailing slash from folder path to avoid escape issues with argument
set MixedVRManagerFolder=%MixedVRManagerFolder:~0,-1%

:: create scheduled task
:: /SC ONLOGON - run on user logon
:: /RL HIGHEST - run as administrator
SCHTASKS /CREATE /SC ONLOGON /TN "VR\Mixed VR Manager" /RL HIGHEST /TR "'%MixedVRManagerFolder%\bin\mixedvr-manager-startup-wrapper.bat' %MixedVRManagerFolder%"

:: run the scheduled task (this just makes it so they don't have to reboot)
SCHTASKS /RUN /TN "VR\Mixed VR Manager"

echo *******************************************************************
echo *****PLEASE READ***********PLEASE READ**********PLEASE READ********
echo *******************************************************************
echo MixedVR Manager has been installed and is now running.
echo Please turn on an Index Controller (or start SteamVR directly), count to 30, and then put on your headset.
echo After launching SteamVR you don't have to touch the mouse/keyboard/controller; MixedVR Manager handles all setup.
echo (Note: you will see SteamVR exit and then restart several seconds later. This is normal. It's not crashing).
echo When you're done, open the SteamVR dashboard and select 'Exit VR'. MixedVR Manager will shut down everything automatically.
echo *******************************************************************
echo *****PLEASE READ***********PLEASE READ**********PLEASE READ********
echo *******************************************************************
timeout 60 >NUL
7 changes: 0 additions & 7 deletions mixedvr-manager-launcher.vbs

This file was deleted.

41 changes: 41 additions & 0 deletions uninstall-mixedvr-manager.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off

:: NOTE: This installer must be run as administrator (ty: https://stackoverflow.com/a/11995662/2611730)
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed. Proceeding with uninstall...
) else (
echo Failure: Current permissions inadequate. Please right click on file and select "Run as Administrator"
timeout 10 >NUL
exit
)

:: find location of Mixed VR Manager
set MixedVRManagerFolder=%~dp0

:: kill mixedvr-manager if currently running
taskkill /f /t /fi "Windowtitle eq Administrator: MixedVR Manager"
taskkill /f /t /fi "Windowtitle eq MixedVR Manager"

:: delete scheduled task
schtasks /Delete /TN "VR\Mixed VR Manager" /F

:: undo any processes here that people would expect to be undone, like re-enable the HMD
echo MixedVR-Manager is changing state of USB device, the HMD, to /enable just in case it was off...
"%MixedVRManagerFolder%bin\USBDeview.exe" /RunAsAdmin /enable "HoloLens Sensors"

echo *******************************************************************
echo *****PLEASE READ***********PLEASE READ**********PLEASE READ********
echo *******************************************************************
echo MixedVR-Manager uninstalled.
echo If MixedVR manager wasn't working correctly for you, try the following:
echo * Double clicking on mixedvr-manager.bat inside the bin/ folder
echo * Opening SteamVR
echo * Send a screenshot of the output to /u/monstermac77 on Reddit, or post it on the Github
echo *******************************************************************
echo *****PLEASE READ***********PLEASE READ**********PLEASE READ********
echo *******************************************************************

timeout 60 >NUL

0 comments on commit 869c051

Please sign in to comment.