Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Launcher/Configurator #94

Open
pchome opened this issue Dec 5, 2019 · 3 comments
Open

POC: Launcher/Configurator #94

pchome opened this issue Dec 5, 2019 · 3 comments

Comments

@pchome
Copy link
Contributor

pchome commented Dec 5, 2019

The idea is simple: hold Left Ctrl key during game launch to spawn an program where one can add/modify PF options.

I hacked this as two parts: a simple keypress detector, to avoid additional dependencies (except it depends on X11), and a patch.

is_ctrl_key.c

#include <X11/Xlib.h>
#include <X11/keysym.h>

int main() {
  char keys_return[32];

  Display *dpy    = XOpenDisplay(NULL);
  KeyCode keycode = XKeysymToKeycode(dpy, XK_Control_L);

  XQueryKeymap(dpy, keys_return);
  XCloseDisplay(dpy);

  return !!(keys_return[keycode >> 3] & (1 << (keycode & 7))) ? 0 : -1;
}

patch

diff --git a/protonfixes/fix.py b/protonfixes/fix.py
index b026a31..16bacec 100755
--- a/protonfixes/fix.py
+++ b/protonfixes/fix.py
@@ -5,6 +5,7 @@ from __future__ import print_function
 import io
 import os
 import re
+import subprocess
 import sys
 from importlib import import_module
 from protonfixes.splash import splash
@@ -133,6 +134,28 @@ def main():

     log.info('Running protonfixes')

+    try:
+        # Check if Left Ctrl key pressed
+        subprocess.run(os.path.expanduser('~/.local/bin/is_ctrl_key'), shell=True, check=True)
+
+        lpf_file = os.path.expanduser('~/.config/protonfixes/localfixes/' + game_id() + '.py')
+
+        # Create local gamefix file
+        if not os.path.isfile(lpf_file):
+            lpf_template = ''
+            lpf_template += 'from protonfixes import util' + "\n\n"
+            lpf_template += 'def main():' + "\n"
+            lpf_template += '    """ game: ' + game_name() + "\n"
+            lpf_template += '    """' + "\n"
+            lpf_template += '    #util.set_environment("PROTON_USE_WINED3D11", "1")' + "\n"
+            lpf_template += '    '
+            subprocess.run('echo \''+ lpf_template +'\' >> ' + lpf_file, shell=True, check=True)
+
+        #subprocess.run('xdg-open ' + lpf_file, shell=True, check=True)
+        subprocess.run('kate ' + lpf_file, shell=True, check=True)
+    except subprocess.CalledProcessError:
+        pass
+
     if config.enable_splash:
         with splash():
             run_fix(game_id())

When LCtrl pressed, PF will check for existing local gamefix or will create a new one from template. Then (in this example) will open it with the text editor (kate). After closing editor session PF will continue it's work and should load modified gamefix as usual.

Could be changed to an GUI program with most common proton switches to select, if any do/will exist.

@simons-public
Copy link
Owner

I like this idea, and would love a pull request. The only thing I would say is that i think it would make the most sense to use xdg-open like you have commented out in the example, since there's no way of knowing what text editor would be available.

@pchome
Copy link
Contributor Author

pchome commented Dec 19, 2019

The problem with xdg-open is that it do not wait for process to exit, so the text editor running in parallel with the game. I should figure out is there other XDG utility to determine available program.

Also I'm not sure how binaries should be distributed or built in python packages. Maybe template should be the file too, then it could be more complex and contain some examples.

So, before I eventually will figure this out, any hints are welcomed. I'll do the PR then.

@pchome
Copy link
Contributor Author

pchome commented Feb 5, 2020

While I thought about custom launcher for protonfixes, and maybe some kind of gamefix parser, I remembered the winetricks GUI which I almost never used before, but which can be a good start.

Here is my attempt to combine everything together: pf-launcher-draft-v3.patch.gz

It's very basic, and I'm still unsure about some things, but if this patch is acceptable, you can use git apply /path/to/pf-launcher-draft-v3.patch and close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants