Repository: lutris/lutris

Issue:
Lutris shell script generation leaves out overrides based on DLL selection for the runner
### Bug description

Executing `lutris -b /some/path.sh lutris:write-script/<some game>` generates environment variables and templates them into a shell script that is supposed to be suitable for starting the game. Because of the order that the environment is built in this method, the runner doesn't undergo its `prelaunch` and properly populate environment variables, so `get_launch_parameters` doesn't return the proper WINEDLLOVERRIDES and the generated script is incomplete, not taking advantage of DXVK and other important DLLs that should be used.

### How to Reproduce

Steps to reproduce the behavior:
1. Install a game
2. Configure DXVK or some other runner option that's enabled via WINEDLLOVERRIDE
3. At a terminal run `lutris -b /tmp/game.sh lutris:write-script/1` or swap the `1` for the game ID of the game you installed.
4. `grep WINEDLLOVERRIDES /tmp/game.sh` and note the lack of overrides for the things configured in step 2


### Expected behavior

I expect the generated script to be able to adequately launch the game without Lutris, using the options I'd configured in Lutris. For example, when launching a copy of the same game from lutris, I see the following:

```
$ xargs -0 -n 1 echo < /proc/396196/environ | grep WINEDLLOVERRIDES
WINEDLLOVERRIDES=d3d10core,d3d11,d3d12,d3d9,d3dcompiler_42,d3dcompiler_43,d3dcompiler_46,d3dcompiler_47,d3dx10,d3dx10_33,d3dx10_34,d3dx10_35,d3dx10_36,d3dx10_37,d3dx10_38,d3dx10_39,d3dx10_40,d3dx10_41,d3dx10_42,d3dx10_43,d3dx11_42,d3dx11_43,d3dx9_24,d3dx9_25,d3dx9_26,d3dx9_27,d3dx9_28,d3dx9_29,d3dx9_30,d3dx9_31,d3dx9_32,d3dx9_33,d3dx9_34,d3dx9_35,d3dx9_36,d3dx9_37,d3dx9_38,d3dx9_39,d3dx9_40,d3dx9_41,d3dx9_42,d3dx9_43,dxgi=n;winemenubuilder=
```

### Log output

```shell
$ lutris -b /tmp/gw2.sh lutris:write-script/1
2022-01-30 13:42:52,767: Magic not available. Unable to automatically find game executables. Please install python-magic
2022-01-30 13:42:52,792: Starting Lutris 0.5.9.1
2022-01-30 13:42:52,806: No cores found
2022-01-30 13:42:53,813: Failed to read content length on response from https://api.github.com/repos/lutris/dxvk-nvapi/releases
2022-01-30 13:42:54,141: Startup complete
2022-01-30 13:42:54,142: Running AMD Mesa driver 21.3.4 on AMD Radeon RX 5700 XT (NAVI10, DRM 3.42.0, 5.15.16-200.fc35.x86_64, LLVM 13.0.0) (0x731f)
2022-01-30 13:42:54,142: GPU: 1002:731F 1DA2:E410 (amdgpu drivers)
2022-01-30 13:42:54,212: Shutting down Lutris
$ grep WINEDLLOVERRIDES /tmp/gw2.sh
export WINEDLLOVERRIDES="winemenubuilder="
```
```


### System Information

```shell
[System]
OS:              Fedora Linux 35 
Arch:            x86_64
Kernel:          5.15.16-200.fc35.x86_64
Desktop:         Not found
Display Server:  wayland

[CPU]
Vendor:          AuthenticAMD
Model:           AMD Ryzen 9 5950X 16-Core Processor
Physical cores:  16
Logical cores:   32

[Memory]
RAM:             62.8 GB
Swap:            8.0 GB

[Graphics]
Vendor:          AMD
OpenGL Renderer: AMD Radeon RX 5700 XT (NAVI10, DRM 3.42.0, 5.15.16-200.fc35.x86_64, LLVM 13.0.0)
OpenGL Version:  4.6 (Compatibility Profile) Mesa 21.3.4
OpenGL Core:     4.6 (Core Profile) Mesa 21.3.4
OpenGL ES:       OpenGL ES 3.2 Mesa 21.3.4
Vulkan:          Supported
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:

Resolving patch:
diff --git a/lutris/runner_interpreter.py b/lutris/runner_interpreter.py
--- a/lutris/runner_interpreter.py
+++ b/lutris/runner_interpreter.py
@@ -127,6 +127,8 @@ def get_gamescope_args(launch_arguments, system_config):
 
 def export_bash_script(runner, gameplay_info, script_path):
     """Convert runner configuration into a bash script"""
+    if getattr(runner, 'prelaunch', None) is not None:
+        runner.prelaunch()
     command, env = get_launch_parameters(runner, gameplay_info)
     # Override TERM otherwise the script might not run
     env["TERM"] = "xterm"


Test patch: