# --- Cleanup Function --- cleanup() { echo"[Fix Script] Exit signal received, cleaning up..." if [ ! -z "$KILLER_PID" ] && ps -p $KILLER_PID >/dev/null; then kill -9 $KILLER_PID fi if [ ! -z "$STRACE_PID" ] && ps -p $STRACE_PID >/dev/null; then kill -9 $STRACE_PID fi pkill -9 -f "$LAUNCHER_PROCESS_NAME" echo"[Fix Script] Cleanup complete." } trap cleanup EXIT SIGINT SIGTERM
# 1. Start the escort and the launcher echo"[Fix Script] Escort enabled..." $STRACE_CMD & STRACE_PID=$! echo"[Fix Script] Escort process PID: $STRACE_PID"
# 2. Main monitoring loop echo"[Fix Script] Waiting for you to start the game from the launcher..."
while ps -p $STRACE_PID >/dev/null; do if pgrep -f $GAME_PROCESS_NAME >/dev/null; then # State: In-Game if [ -z "$KILLER_PID" ]; then echo"[Fix Script] Game process detected! Starting $ESCORT_DURATION-second separation countdown..." # Start a "timed killer" in the background, its only job is to kill strace (sleep$ESCORT_DURATION && kill -9 $STRACE_PID) & KILLER_PID=$! echo"[Fix Script] Detach program deployed, PID: $KILLER_PID" fi else # State: In-Launcher (or game not started) if [ ! -z "$KILLER_PID" ]; then echo"[Fix Script] Game has been exited. Revoking detach program..." if ps -p $KILLER_PID >/dev/null; then kill -9 $KILLER_PID fi KILLER_PID="" echo"[Fix Script] Reset. Ready to relaunch the game." fi fi sleep$POLLING_INTERVAL done
# When the strace process ends (either killed or the user closed the launcher), the script will arrive here. # We perform a final, failsafe cleanup here. echo"[Fix Script] Escort task finished. Performing final cleanup." pkill -9 -f "$LAUNCHER_PROCESS_NAME"