This commit is contained in:
edschuy95 2026-01-22 20:11:47 -05:00
parent d5ac6e68ec
commit f111ffa1dc

View file

@ -23,7 +23,7 @@ import pygame
shutdown_event = threading.Event()
# ========================= CONFIG =========================
DEBUG = False # Set True to enable debug overrides
DEBUG = True # Set True to enable debug overrides
# Default paths (used if not in debug mode)
DEFAULT_WIN_GAME_EXE = r"./qgame.dll"
@ -644,58 +644,50 @@ def game_launch(gameargs):
creationflags=subprocess.CREATE_NO_WINDOW
)
master_fd = None
# Start monitoring in background thread
monitor_thread = threading.Thread(target=monitor_game, args=(pty_proc,))
monitor_thread.start()
else:
master_fd, slave_fd = pty.openpty()
# Close all file descriptors except the pty
# This prevents inheritance of file manager's stdin/stdout
max_fd = 1024 # Reasonable upper limit
for fd in range(3, max_fd):
try:
os.close(fd)
except OSError:
pass
pty_proc = subprocess.Popen(
[game_exe, "+set", "ttycon", "1"] + gameargs,
stdin=slave_fd,
stdout=slave_fd,
stderr=slave_fd,
close_fds=True,
# Don't let the child process be affected by parent's terminal
preexec_fn=os.setsid if hasattr(os, 'setsid') else None
close_fds=True
)
os.close(slave_fd)
# Start monitoring in background thread
monitor_thread = threading.Thread(target=monitor_game_pty, args=(master_fd,))
monitor_thread.start()
# Monitor the game output
try:
if os.name == "nt":
monitor_game(pty_proc)
else:
monitor_game_pty(master_fd)
while True:
# Check if the game process is still running
if pty_proc.poll() is not None:
# Process has ended
break
# Small sleep to prevent busy waiting
time.sleep(0.1)
# if os.name == "nt":
# monitor_game(pty_proc)
# else:
# monitor_game_pty(master_fd)
except KeyboardInterrupt:
print("Exiting...")
finally:
stop_flag.set()
stop_playback()
if pty_proc:
try:
pty_proc.stdin.close()
except:
pass
try:
pty_proc.stdout.close()
except:
pass
try:
pty_proc.terminate()
except:
pass
try:
pty_proc.wait(timeout=5)
except:
pass