Commit 6aa3ba4
Changed files (1)
modules
game
modules/game/hoyo-games.nix
@@ -44,7 +44,8 @@
# See https://github.com/an-anime-team/an-anime-game-launcher/issues/572#issuecomment-3476345318
my_wrapper = pkgs.writeShellScriptBin prev.pname ''
# --- Configuration ---
- STRACE_CMD="${pkgs.strace}/bin/strace -f -e trace=process -o /dev/null ${prev.passthru.wrapper}/bin/${prev.passthru.wrapper.name} "$@""
+ ORIGINAL_WRAPPER="${prev.passthru.wrapper}/bin/${prev.passthru.wrapper.name}"
+ STRACE_CMD="${pkgs.strace}/bin/strace -f -e trace=process -o /dev/null $ORIGINAL_WRAPPER "$@""
ESCORT_DURATION=120
GAME_PROCESS_NAME="YuanShen.exe"
LAUNCHER_PROCESS_NAME="${prev.passthru.wrapper.name}"
@@ -75,36 +76,41 @@
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 -x $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) &
+ while true; do
+ IS_GAME_RUNNING=false
+ if pgrep -f "$GAME_PROCESS_NAME" > /dev/null; then
+ IS_GAME_RUNNING=true
+ fi
+
+ IS_STRACE_RUNNING=false
+ if [ ! -z "$STRACE_PID" ] && ps -p "$STRACE_PID" > /dev/null; then
+ IS_STRACE_RUNNING=true
+ fi
+
+ if [ "$IS_STRACE_RUNNING" = false ] && [ "$IS_GAME_RUNNING" = false ]; then
+ echo "[Fix Script] Neither Launcher nor Game is running. Exiting wrapper."
+ break
+ fi
+
+ if [ "$IS_GAME_RUNNING" = true ]; then
+ if [ -z "$KILLER_PID" ] && [ "$IS_STRACE_RUNNING" = true ]; then
+ echo "[Fix Script] Game process detected! Starting $ESCORT_DURATION-second countown to kill strace..."
+ (sleep $ESCORT_DURATION && echo "[Fix Script] Time up! Killing strace..." && 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..."
+ echo "[Fix Script] Game exited but Launcher is open. 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"
-
+ echo "[Fix Script] Finished."
exit 0
'';
in {