proton_run.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. """Runs a program the way Steam's `proton run` does, minus steam.exe: the prefix setup and the per-run environment
  3. (DXVK/vkd3d-proton dll overrides, fonts, protonfixes) all come from Proton's own `run` path, only its last step,
  4. starting the program through steam.exe, becomes `wine <args>`. `runinprefix` is no substitute, it skips the setup
  5. and with it the d3d11/dxgi=n overrides, so WE ends up on wined3d. Valve's steam.exe also asserts without a running
  6. Steam client (GE's only warns), the dialog blocks the run.
  7. proton_run.py <proton script> <program> [args...] with STEAM_COMPAT_DATA_PATH etc. set like for proton
  8. """
  9. import os, sys, textwrap
  10. path = sys.argv[1]
  11. args = sys.argv[2:]
  12. src = open(path).read()
  13. head, sep, body = src.partition('\nif __name__ == "__main__":\n')
  14. if not sep:
  15. sys.exit('%s: no main block' % path)
  16. # the script imports filelock, protonfixes etc. from its own folder
  17. sys.path.insert(0, os.path.dirname(os.path.abspath(path)))
  18. g = {'__name__': 'proton', '__file__': path}
  19. sys.argv = [path, 'run'] + args
  20. exec(compile(head, path, 'exec'), g)
  21. def run(self):
  22. return self.run_proc([g['g_proton'].wine_bin] + args)
  23. g['Session'].run = run
  24. # the block ends at the first unindented line (the file ends with pylint/vim comments)
  25. lines = []
  26. for line in body.splitlines(True):
  27. if line.strip() and not line[0].isspace():
  28. break
  29. lines.append(line)
  30. exec(compile(textwrap.dedent(''.join(lines)), path, 'exec'), g)