Author Topic: Running the Touhou games in Wine: using a separate Wine prefix  (Read 4265 times)

Running the Touhou games in Wine: using a separate Wine prefix
« on: September 27, 2017, 05:57:15 PM »
Click here=>https://www.shrinemaiden.org/forum/index.php/topic,5902.0.html or here => http://en.touhouwiki.net/wiki/Running_in_Linux_and_MacOS_X for more general information about Touhou on Linux.

I am using a German keyboard, which have the Z any Y keys swapped. This means, that when I launch the games with my default keyboard layout, I have to use the Z key, which is in a very inconvenient position on German keyboards. However installing dinput8 using winetricks (winetricks dinput8) breaks compatibility with my controller. That's why I came up with this script:

Code: [Select]
#!/bin/sh
export WINEPREFIX=$(sh -c 'cd ../.wine/prefix && pwd')
WINEARCH=win64 wine .\\thcrap\\thcrap_loader.exe thcrap\\en.js th*.exe

The first line tells Linux, which shell to use.

The second one sets the location of the wineprefix.
It works like that: The export command is to set shell variables. A shell variable is something which when called, gets replaced by the thing it stands for. For example: We have the shell variable is THDIR, which equals /home/thsys/Games/Touhou 8 - Imperishable Night/. If we now type `echo $THDIR`, $THDIR gets replaced by /home/thsys/Games/Touhou 8 - Imperishable Night/. Understand that?
WINEPREFIX is the shell variable we want to set. To do that, in this case we use a $ sign with brackets next to them `$()`. Inside the brackets we put a command. The $ sign, the brackets and what is inside the brackets will get turned into the output of the command inside those brackets. Example: the command `echo hello` outputs `hello`. If we type `echo $(echo hello)` `$(echo hello)` will turn into the output of the command `echo hello` which is `hello`. That way `echo $(echo hello)` gets turned into `echo hello`. This is obviously a pointless example, but it makes more sense in my script.
The command we launch in the brackets is `sh -c 'cd ../.wine/prefix && pwd`. `sh -c` launches a secondary shell. That shell doesn't affect the main shell, this script runs in at all, but can output text. In this secondary shell we run `cd`, which changes the folder in which the shell is working in. `..` means the folder above (if you are in the folder /home/thsys/Documents and run `cd ..` you get to the folder /home/thsys). The `/.wine/prefix` part means, that the shell should go to the folder `.wine` after going in the folder above and then going into the folder `prefix`. `&&` means, that if the command before ran successfully, the command next to `&&` should get ran too. That command is `pwd` which outputs the folder the shell is currently in.
All of that allows us to work with relative paths, but get a pull path as our shell variable.

The next command then launches thcrap, which then launches our Touhou game. The reason I need 2 backslashes is because the backslash is put in front of a special character, in order to include it in a command, but not treat it like a special character.
The `WINEARCH=win64` is to force wine to run in 64 bit mode and not run at all on 32 bit computers, because thcrap doesn't work with 32 bit wine prefixes.


SIDENOTE: this script is universal for all games, if you are using a thcrap English patch. If you are using a static patch, change `th*.exe` in the third command to `th*e.exe` and remove `.\\thcrap\\thcrap_loader.exe`

SIDENOTE2: this script assumes, that you have a configured thcrap installation in a folder called `thcrap` inside your game's folder and a `.wine` folder in the same folder, as your game's folder, which contains a `prefix` folder.

SIDENOTE3: You install `dinput8` in your Wine prefix, by opening a terminal and using `cd` to navigate to your game's folder, running `export WINEPREFIX=$(sh -c 'cd ../.wine/prefix && pwd')` and then running `winetricks dinput8` (also make sure, you have winetricks installed on your computer`

SIDENOTE4: You can use download and use `shc` in order to make a binary of the script, which you can then double click in your file manager.
« Last Edit: September 28, 2017, 12:33:20 PM by 32th System »
Not that a signature matters.