Skip to content

Instantly share code, notes, and snippets.

@hradec
Created October 10, 2020 20:27
Show Gist options
  • Select an option

  • Save hradec/4b373184f97072fbcbc4e06cb18064cc to your computer and use it in GitHub Desktop.

Select an option

Save hradec/4b373184f97072fbcbc4e06cb18064cc to your computer and use it in GitHub Desktop.
A Python Script to automatically prioritize process for Oculus Link! (it also uses OculusDebugToolCli to setup ASW off for beatsaber)
import os, sys
import psutil
import time
vr=[
'vrserver.exe',
'vrcompositor.exe',
# 'steamvr.exe',
# 'vrmonitor',
# 'vrdash',
# 'vrwebhel',
# 'alvr',
# 'parsec',
'OVRServer',
]
games=[
'hlvr.exe',
'Beat Saber.exe',
'VRParadise',
'stbc',
'elite',
'Elite',
]
asw={
'Beat Saber.exe' : 'server:asw.off',
}
def cleanup():
file='c:/temp/cleanup.vr'
asw_cmd='server:asw.Clock45'
f=open(file, 'w+')
f.write('%s\nexit\n' % asw_cmd)
f.close()
cmd='"C:\\Program Files\\Oculus\\Support\\oculus-diagnostics\\OculusDebugToolCLI.exe" -f '+file
print cmd
os.system(cmd)
for game in games+['cleanup']:
file='c:/temp/%s.vr' % game.replace(' ','_')
if os.path.exists(file):
print file
os.remove(file)
def setpriority(pid=None,priority=-1):
""" Set The Priority of a Windows Process. Priority is a value between 0-5 where
2 is normal priority. Default sets the priority of the current
python process but can take any valid process ID. """
import win32api,win32process,win32con
priorityclasses = [win32process.IDLE_PRIORITY_CLASS,
win32process.BELOW_NORMAL_PRIORITY_CLASS,
win32process.NORMAL_PRIORITY_CLASS,
win32process.ABOVE_NORMAL_PRIORITY_CLASS,
win32process.HIGH_PRIORITY_CLASS,
win32process.REALTIME_PRIORITY_CLASS]
if pid == None:
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, priorityclasses[priority])
def findProcessIdByName(processName):
'''
Get a list of all the PIDs of a all the running process whose name contains
the given string processName
'''
listOfProcessObjects = []
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
# Check if process name contains the given name string.
if processName.lower() in pinfo['name'].lower() :
listOfProcessObjects.append(pinfo)
except (psutil.NoSuchProcess, psutil.AccessDenied , psutil.ZombieProcess) :
pass
return listOfProcessObjects;
for process in findProcessIdByName('python.exe'):
setpriority(process['pid'], 0)
print ".."
counter=-11
frozen=True
cleanup()
while True:
freeze=False
nothing=True
for game in vr:
for process in findProcessIdByName(game):
print game, process
setpriority(process['pid'], -1)
nothing=False
time.sleep(0.5)
for game in games:
for process in findProcessIdByName(game):
if counter<0:
counter=0
print game, process
setpriority(process['pid'], -2)
freeze=True
nothing=False
if counter < 5:
frozen=0
# set asw if needed
file='c:/temp/%s.vr' % game.replace(' ','_')
asw_cmd='server:asw.off'
if game in asw:
asw_cmd=asw[game]
if not os.path.exists(file):
f=open(file, 'w+')
f.write('%s\nexit\n' % asw_cmd)
f.close()
cmd='"C:\\Program Files\\Oculus\\Support\\oculus-diagnostics\\OculusDebugToolCLI.exe" -f '+file
print cmd
os.system(cmd)
time.sleep(0.5)
print "frozen: %s - freeze: %s - count: %s" % (str(frozen), str(freeze), str(counter)),
if nothing and not frozen:
print "- nothings to see... ",
counter=0
else:
if freeze:
counter=counter+1
else:
counter=counter-1
if counter>5:
counter=5
if not frozen:
cmd="ssh [email protected] freeze.sh"
print cmd,
os.system(cmd)
frozen=True
if counter<-10:
counter=0
if frozen:
cmd="ssh [email protected] unfreeze.sh"
print cmd,
os.system(cmd)
frozen=False
cleanup()
time.sleep(10)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment