Hacky, but it’s the only solution that worked.
def make_config(self, **options: str) -> Optional[Path]:
new_cfg: Optional[Path] = None
try:
with self.__main_config.open("r", encoding = "UTF-8") as cfg:
with NamedTemporaryFile("w", encoding = "UTF-8", delete = False) as tmp_cfg:
new_cfg = Path(tmp_cfg.name)
key: str
value: str
for line in cfg:
key, value = line.split('=', 1)
# Skip pre-defined keys.
if key.strip().casefold() not in options:
tmp_cfg.write(line)
tmp_cfg.writelines(f'{key} = "{value}"\n' for (key, value) in options.items())
except (OSError, ValueError):
# Make sure to delete the temporary file on error.
if new_cfg is not None:
try:
new_cfg.unlink()
except OSError:
pass
new_cfg = None
return new_cfg
...
ra_config: Optional[Path] = cast(RetroArch, config.retroarch).make_config(
netplay_ip_address = join_room.address,
netplay_ip_port = str(join_room.port),
config_save_on_exit = "false"
)
if ra_config is None:
Console.error("Failed to create temporary RetroArch configuration.")
try:
cast(RetroArch, config.retroarch).launch(
cast(Path, cast(Platform, join_room.platform).game(cast(str, join_room.game), cast(str, join_room.game), join_room.crc)),
cast(str, cast(Platform, join_room.platform).core),
"--config", str(ra_config),
"--connect", join_room.address
)
finally:
# Wait a little bit before deleting as to allow RetroArch to read it.
time.sleep(3)
try:
ra_config.unlink()
except OSError:
pass
Launching it from the lobby viewer on a random room:
[INFO] [Config]: Loading config from: "E:\Users\Admin\AppData\Local\Temp\tmp6xx4kozu".
[INFO] [Netplay]: Connecting to netplay host
[WARN] WARNING: A netplay peer is running a different version of RetroArch. If problems occur, use the same version.
[WARN] WARNING: A netplay peer is running a different version of the core. If problems occur, use the same version.
[INFO] Connected to: "Tiago"
[INFO] [netplay] You have joined as player 2
–appendconfig worked for me, but only if I don’t start RetroArch with content loaded.
Both things might be worth looking into.
I couldn’t find why --appendconfig wouldn’t work for netplay_ip_address when launching via --libretro. Everything in the source code indicated that it would be loaded right after retroarch.cfg, appending its content into the config object; I even got the “config appended” log without the failed one.
-C/–connect should be refactored into storing its argument separately from netplay_ip_address, with its format changed from “address” to either “address:port” or “address|port” to avoid conflict with netplay_ip_port aswell (–port option should be used for -H/–host only).