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() shutdown_event = threading.Event()
# ========================= CONFIG ========================= # ========================= 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 paths (used if not in debug mode)
DEFAULT_WIN_GAME_EXE = r"./qgame.dll" DEFAULT_WIN_GAME_EXE = r"./qgame.dll"
@ -644,58 +644,50 @@ def game_launch(gameargs):
creationflags=subprocess.CREATE_NO_WINDOW creationflags=subprocess.CREATE_NO_WINDOW
) )
master_fd = None master_fd = None
# Start monitoring in background thread
monitor_thread = threading.Thread(target=monitor_game, args=(pty_proc,))
monitor_thread.start()
else: else:
master_fd, slave_fd = pty.openpty() 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( pty_proc = subprocess.Popen(
[game_exe, "+set", "ttycon", "1"] + gameargs, [game_exe, "+set", "ttycon", "1"] + gameargs,
stdin=slave_fd, stdin=slave_fd,
stdout=slave_fd, stdout=slave_fd,
stderr=slave_fd, stderr=slave_fd,
close_fds=True, 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
) )
os.close(slave_fd) 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 # Monitor the game output
try: try:
if os.name == "nt": while True:
monitor_game(pty_proc) # Check if the game process is still running
else: if pty_proc.poll() is not None:
monitor_game_pty(master_fd) # 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: except KeyboardInterrupt:
print("Exiting...") print("Exiting...")
finally: finally:
stop_flag.set() stop_flag.set()
stop_playback() stop_playback()
if pty_proc: if pty_proc:
try:
pty_proc.stdin.close()
except:
pass
try:
pty_proc.stdout.close()
except:
pass
try: try:
pty_proc.terminate() pty_proc.terminate()
except:
pass
try:
pty_proc.wait(timeout=5) pty_proc.wait(timeout=5)
except: except:
pass pass