Skip to content

Commit 9e66a2e

Browse files
authored
Allow to specify custom ATS/ETS2 launch options (truckersmp-cli#167)
1 parent 7f6541d commit 9e66a2e

File tree

5 files changed

+73
-40
lines changed

5 files changed

+73
-40
lines changed

Diff for: .github/workflows/build_and_upload_inject_program.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Build truckersmp-cli.exe
3030
# we need "make clean" because we already have truckersmp-cli.exe
3131
# and "make" does nothing even when truckersmp-cli.c is changed
32-
run: make clean && make
32+
run: make clean && make truckersmp_cli/truckersmp-cli.exe
3333
- name: Strip truckersmp-cli.exe
3434
run: x86_64-w64-mingw32-strip truckersmp_cli/truckersmp-cli.exe
3535
- uses: actions/upload-artifact@v1

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Short option|Long option|Description
104104
(Not available)|`--check-windows-steam`|Check for the Windows Steam version on updating when using Proton
105105
(Not available)|`--disable-proton-overlay`|Disable Steam Overlay when using Proton
106106
(Not available)|`--downgrade`|**DEPRECATED** Downgrade to the latest version that is supported by TruckersMP. Note: This option implies "--update" option and is ignored if "--beta" ("-b") option is specified
107+
(Not available)|`--game-options OPTIONS`|Specify ATS/ETS2 options Note: If specifying one option, use `--game-options=-option` format [Default: `-nointro -64bit`]
107108
(Not available)|`--native-steam-dir`|Choose native Steam installation, useful only if your Steam directory is not detected automatically [Default: `auto`]
108109
(Not available)|`--self-update`|Update files to the latest release and quit
109110
(Not available)|`--singleplayer`|**DEPRECATED** Start singleplayer game, useful for save editing, using/testing DXVK in singleplayer, etc.

Diff for: truckersmp-cli.c

+22-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <stdio.h>
13+
#include <string.h>
1314
#include <windows.h>
1415
#include <unistd.h>
1516

@@ -29,13 +30,13 @@ int
2930
main(int argc, char **argv)
3031
{
3132
int i, len;
32-
const char opts[] = "-nointro -64bit";
33+
char opts[BUF_SIZE] = {0};
3334
char cmd[BUF_SIZE];
3435
char dll[BUF_SIZE];
3536
char *exepath, *dllpath, *steamid;
3637

3738
if (argc < 3)
38-
die("Usage: truckersmp-cli GAMEDIR MODDIR\n");
39+
die("Usage: truckersmp-cli GAMEDIR MODDIR GAME_OPTIONS...\n");
3940

4041
for (i = 1; i < 3; i++) { /* '\' and '/' can be mixed in windows type pathes */
4142
len = strlen(argv[i]);
@@ -59,7 +60,25 @@ main(int argc, char **argv)
5960
}
6061
}
6162

62-
snprintf(cmd, sizeof(cmd), "%s%s %s", argv[1], exepath, opts);
63+
if (argc == 3) {
64+
/* if game options are not given, use default options for compatibility */
65+
strcpy(opts, " -nointro -64bit");
66+
} else {
67+
/* build game options string */
68+
len = strlen(argv[1]) + strlen(exepath) + 1; /* game exe path + "\0" */
69+
for (i = 3; i < argc; i++) {
70+
/* check whether a space and the option can be added to the buffer */
71+
len += 1 + strlen(argv[i]); /* 1 = strlen(" ") */
72+
if (len <= BUF_SIZE) {
73+
strcat(opts, " ");
74+
strcat(opts, argv[i]);
75+
} else {
76+
die("Game options are too long.");
77+
}
78+
}
79+
}
80+
81+
snprintf(cmd, sizeof(cmd), "%s%s%s", argv[1], exepath, opts);
6382
snprintf(dll, sizeof(dll), "%s%s", argv[2], dllpath);
6483

6584
SetEnvironmentVariable("SteamGameId", steamid);

Diff for: truckersmp_cli/args.py

+7
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ def create_arg_parser():
306306
Note: This option implies "--update" option and
307307
is ignored if "--beta" ("-b") option is specified""",
308308
action="store_true"))
309+
store_actions.append(parser.add_argument(
310+
"--game-options", metavar="OPTIONS", type=str,
311+
default="-nointro -64bit",
312+
help="""specify ATS/ETS2 options
313+
Note: If specifying one option, use "--game-options=-option" format
314+
[Default: "-nointro -64bit"]""",
315+
action="store_true"))
309316
store_actions.append(parser.add_argument(
310317
"--native-steam-dir", metavar="DIR", type=str,
311318
default="auto",

Diff for: truckersmp_cli/main.py

+42-36
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def setup_logging():
176176

177177
def start_with_proton():
178178
"""Start game with Proton."""
179-
# pylint: disable=consider-using-with,too-many-branches,too-many-statements
179+
# pylint: disable=consider-using-with,too-many-branches
180+
# pylint: disable=too-many-locals,too-many-statements
180181
steamdir = wait_for_steam(use_proton=True, loginvdf_paths=File.loginusers_paths)
181182
logging.info("Steam installation directory: %s", steamdir)
182183

@@ -216,15 +217,12 @@ def start_with_proton():
216217
env["PROTON_USE_WINED3D"] = "1" if Args.use_wined3d else "0"
217218
env["PROTON_NO_D3D11"] = "1" if not Args.enable_d3d11 else "0"
218219
# enable Steam Overlay unless "--disable-proton-overlay" is specified
219-
if Args.disable_proton_overlay:
220-
ld_preload = ""
221-
else:
220+
if not Args.disable_proton_overlay:
222221
overlayrenderer = os.path.join(steamdir, File.overlayrenderer_inner)
223222
if "LD_PRELOAD" in env:
224223
env["LD_PRELOAD"] += ":" + overlayrenderer
225224
else:
226225
env["LD_PRELOAD"] = overlayrenderer
227-
ld_preload = "LD_PRELOAD={}\n ".format(env["LD_PRELOAD"])
228226

229227
# start wine-discord-ipc-bridge for multiplayer
230228
# unless "--without-wine-discord-ipc-bridge" is specified
@@ -240,29 +238,35 @@ def start_with_proton():
240238
if Args.singleplayer:
241239
exename = "eurotrucks2.exe" if Args.ets2 else "amtrucks.exe"
242240
gamepath = os.path.join(Args.gamedir, "bin/win_x64", exename)
243-
argv += gamepath, "-nointro", "-64bit"
241+
argv.append(gamepath)
244242
else:
245243
argv += File.inject_exe, Args.gamedir, Args.moddir
246244

245+
# game options
246+
for opt in Args.game_options.split(" "):
247+
if opt != "":
248+
argv.append(opt)
249+
247250
env["SteamGameId"] = Args.steamid
248251
env["SteamAppId"] = Args.steamid
249-
logging.info(
250-
"""Startup command:
251-
SteamGameId=%s
252-
SteamAppId=%s
253-
STEAM_COMPAT_DATA_PATH=%s
254-
STEAM_COMPAT_CLIENT_INSTALL_PATH=%s
255-
PROTON_USE_WINED3D=%s
256-
PROTON_NO_D3D11=%s
257-
%s%s %s
258-
run
259-
%s %s %s""",
260-
env["SteamGameId"], env["SteamAppId"],
261-
env["STEAM_COMPAT_DATA_PATH"], env["STEAM_COMPAT_CLIENT_INSTALL_PATH"],
262-
env["PROTON_USE_WINED3D"],
263-
env["PROTON_NO_D3D11"],
264-
ld_preload,
265-
sys.executable, proton, argv[-3], argv[-2], argv[-1])
252+
env_print = ["SteamAppId", "SteamGameId"]
253+
if "LD_PRELOAD" in env:
254+
env_print.append("LD_PRELOAD")
255+
env_print += [
256+
"PROTON_NO_D3D11",
257+
"PROTON_USE_WINED3D",
258+
"STEAM_COMPAT_CLIENT_INSTALL_PATH",
259+
"STEAM_COMPAT_DATA_PATH",
260+
]
261+
262+
env_str = ""
263+
cmd_str = ""
264+
name_value_pairs = []
265+
for name in env_print:
266+
name_value_pairs.append("{}={}".format(name, env[name]))
267+
env_str += "\n ".join(name_value_pairs) + "\n "
268+
cmd_str += "\n ".join(argv)
269+
logging.info("Running Proton:\n %s%s", env_str, cmd_str)
266270
try:
267271
output = subproc.check_output(argv, env=env, stderr=subproc.STDOUT)
268272
logging.info("Proton output:\n%s", output.decode("utf-8"))
@@ -282,7 +286,7 @@ def start_with_proton():
282286

283287
def start_with_wine():
284288
"""Start game with Wine."""
285-
# pylint: disable=consider-using-with
289+
# pylint: disable=consider-using-with,too-many-branches
286290
wine = os.environ["WINE"] if "WINE" in os.environ else "wine"
287291
if Args.activate_native_d3dcompiler_47:
288292
activate_native_d3dcompiler_47(Args.prefixdir, wine)
@@ -314,25 +318,27 @@ def start_with_wine():
314318
if not Args.enable_d3d11:
315319
env["WINEDLLOVERRIDES"] += ";d3d11=;dxgi="
316320

317-
desktop_args = ""
318321
if Args.wine_desktop:
319322
argv += "explorer", "/desktop=TruckersMP,{}".format(Args.wine_desktop)
320-
desktop_args += argv[1] + " " + argv[2] + " "
321323
if Args.singleplayer:
322324
exename = "eurotrucks2.exe" if Args.ets2 else "amtrucks.exe"
323325
gamepath = os.path.join(Args.gamedir, "bin/win_x64", exename)
324-
argv += gamepath, "-nointro", "-64bit"
326+
argv.append(gamepath)
325327
else:
326328
argv += File.inject_exe, Args.gamedir, Args.moddir
327-
logging.info(
328-
"""Startup command:
329-
WINEDEBUG=-all
330-
WINEARCH=win64
331-
WINEPREFIX=%s
332-
WINEDLLOVERRIDES="%s"
333-
%s %s%s %s %s""",
334-
env["WINEPREFIX"], env["WINEDLLOVERRIDES"],
335-
wine, desktop_args, argv[-3], argv[-2], argv[-1])
329+
330+
for opt in Args.game_options.split(" "):
331+
if opt != "":
332+
argv.append(opt)
333+
334+
env_str = ""
335+
cmd_str = ""
336+
name_value_pairs = []
337+
for name in ("WINEARCH", "WINEDEBUG", "WINEDLLOVERRIDES", "WINEPREFIX"):
338+
name_value_pairs.append("{}={}".format(name, env[name]))
339+
env_str += "\n ".join(name_value_pairs) + "\n "
340+
cmd_str += "\n ".join(argv)
341+
logging.info("Running Wine:\n %s%s", env_str, cmd_str)
336342
try:
337343
output = subproc.check_output(argv, env=env, stderr=subproc.STDOUT)
338344
logging.info("Wine output:\n%s", output.decode("utf-8"))

0 commit comments

Comments
 (0)