diff --git a/Makefile b/Makefile deleted file mode 100644 index f02f5a6..0000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -.PHONY: all build clean - -all: build - -clean: - rm envload - -build: envload - -%: %.c - tcc -o $@ $< diff --git a/README.md b/README.md index 0d65f63..b41d7a6 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,57 @@ # protonhax + Tool to help running other programs (i.e. Cheat Engine) inside Steam's proton. ## Usage -In Steam set the launch options for the desired game to `protonhax init %COMMAND%` +Set the steam game launch options to `protonhax init %COMMAND%` + +On your Steam Library: +- Right-click the game > Properties > General. +- Set Launch Options as `protonhax init %COMMAND%`. -To list all running appids use\ +Now, you can use your terminal to run the following commands: + +- To list all running appids use\ `protonhax ls` -To run a program with proton use\ +- To run a program with proton use\ `protonhax run [args...]`\ NOTE: The PATH variable is ignored -To run cmd.exe use\ +- To run cmd.exe use\ `protonhax cmd ` -To run a program natively with the environment variables that were used to launch the game originally use\ +- To run a program natively with the environment variables that were used to launch the game originally use\ `protonhax exec [args...]`\ NOTE: The PATH variable is ignored ## Installing -For it to work, you need to be able to access both `protonhax` and `envload` from the terminal. You can use one of the available packages or build it yourself. - -### Build it yourself +**protonhax** is currently a single bash script, you just need to add it to your $PATH. -*Current Makefile uses `tcc`, you can update it to use any c compiler you have (e.g. gcc)* - -1. Clone our repo `https://github.com/jcnils/protonhax.git`, or download the source from our [release page](https://github.com/jcnils/protonhax/releases) -2. Open the directory in a terminal. -3. Run `make`. It will build the `envload.c` using the `Makefile` into a file called `envload`. -4. Copy both `envload` and `protonhax` files to where you want to call them from and give proper permissions, Example `/usr/bin/protonhax` and `usr/bin/envload` with permission `755`. - -Try to call `envload` and `protonhax` if a usage guide appears, it means they are working. +1. Either clone our repo `https://github.com/jcnils/protonhax.git`, or download the source from our [release page](https://github.com/jcnils/protonhax/releases) +2. Copy the **protonhax** file to where you preffer and give it permission to execute: + - Example of locations `$HOME/.local/bin/protonhax`, `/usr/bin/protonhax`. They need to be on your $PATH + - Permission `chmod 755 protonhax`. ### Arch Linux - https://aur.archlinux.org/packages/protonhax - https://aur.archlinux.org/packages/protonhax-git/ +## Debugging + +Open the `protonhax` file and add to the second line +```sh +set -x +exec >/tmp/protonhax.$$.log 2>&1 +``` +It will save protonhax debug log into `/tmp/protonhax.*.log` + ## Contributing Contributions are always welcome! Especially if they are packages for other distributions. ## TODO - [ ] Flatpak version for Steam Flatpak +- [ ] Nix Packages - [ ] Packages for other Linux distributions. diff --git a/envload.c b/envload.c deleted file mode 100644 index 141e4f1..0000000 --- a/envload.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include - -int main(int argc, char **argv) { - if (argc < 3) { - fprintf(stderr, "%s [args...]\n", argv[0]); - return 1; - } - - FILE *fd = fopen(argv[1], "rb"); - - fseek(fd, 0, SEEK_END); - long int env_len = ftell(fd); - fseek(fd, 0, SEEK_SET); - - char* env = (char*)malloc(env_len); - fread(env, sizeof(char), env_len, fd); - fclose(fd); - - unsigned int envp_count = 0; - for (char* ev = env; ev < env + env_len; ev++) { - envp_count++; - ev += strlen(ev); - } - - char** envp = (char**)malloc((envp_count + 1) * sizeof(char*)); - char* ev = env; - for (unsigned int i = 0; i < envp_count; i++) { - envp[i] = ev; - ev += strlen(ev) + 1; - } - envp[envp_count] = (char*)NULL; - - int eargc = argc - 2; - char** eargv = (char**)malloc((eargc + 1) * sizeof(char*)); - for (int i = 0; i < eargc; i++) - eargv[i] = argv[i + 2]; - eargv[eargc] = (char*)NULL; - - execve(argv[2], eargv, envp); - - int e = errno; - fprintf(stderr, "Failed to exec!\n"); - fprintf(stderr, "%d %s\n", e, strerror(e)); - return e; -} diff --git a/protonhax b/protonhax index afe6de7..581248d 100755 --- a/protonhax +++ b/protonhax @@ -28,7 +28,7 @@ if [[ "$c" == "init" ]]; then mkdir -p $phd/$SteamAppId printf "%s\n" "${@}" | grep -m 1 "/proton" > $phd/$SteamAppId/exe printf "%s" "$STEAM_COMPAT_DATA_PATH/pfx" > $phd/$SteamAppId/pfx - env -0 > $phd/$SteamAppId/env + declare -px > $phd/$SteamAppId/env "$@" ec=$? rm -r $phd/$SteamAppId @@ -53,20 +53,22 @@ elif [[ "$c" == "run" ]] || [[ "$c" == "cmd" ]] || [[ "$c" == "exec" ]]; then SteamAppId=$1 shift + source $phd/$SteamAppId/env + if [[ "$c" == "run" ]]; then if [[ $# -lt 1 ]]; then usage exit 1 fi - $(dirname $0)/envload $phd/$SteamAppId/env "$(cat $phd/$SteamAppId/exe)" run "$@" + exec "$(cat $phd/$SteamAppId/exe)" run "$@" elif [[ "$c" == "cmd" ]]; then - $(dirname $0)/envload $phd/$SteamAppId/env "$(cat $phd/$SteamAppId/exe)" run "$(cat $phd/$SteamAppId/pfx)/drive_c/windows/system32/cmd.exe" + exec "$(cat $phd/$SteamAppId/exe)" run "$(cat $phd/$SteamAppId/pfx)/drive_c/windows/system32/cmd.exe" elif [[ "$c" == "exec" ]]; then if [[ $# -lt 1 ]]; then usage exit 1 fi - $(dirname $0)/envload $phd/$SteamAppId/env "$@" + exec "$@" fi else printf "Unknown command %s\n" "$c"