如果我的游戏正在加载,我该如何检测并终止协同作用?

如果我的游戏正在加载,我该如何检测并终止协同作用?

所以我在玩 Battle.Net 的几款游戏(尤其是星际争霸)时被打败了,因为它讨厌协同作用。原因很明显,因为它是一款非常依赖鼠标的游戏,当你启动它时,它会控制一切。我有启动和停止协同作用的别名,但问题是我总是忘记在开始游戏之前使用它们,而之后我已经投入了。这真的让我很恼火。

游戏是使用 PlayOnLinux 安装的。我要编辑什么脚本才能插入一些会破坏协同作用的内容?PlayOnLinux 是否有放置用户脚本的标准位置,或者是否有一些标准化的方法来执行此类操作?

新信息 - 发现:

/usr/share/playonlinux/playonlinux --run "Battle.Net" %F

这里合适吗或者有更好的地方吗?

答案1

我没有编辑别人的脚本,而是编写了一个包装器。这个脚本可以很好地处理 pulseaudio 和 synergy,但 playonlinux 命令本身存在问题,因为它会返回,我必须想办法让我的脚本等待……或者也许我不会。我可以编写它来轮询游戏是否正在运行。

...好的,我重写了它以包含轮询循环。我还有最后一个担忧,那就是如果它不从快捷方式运行。

...好的,从快捷方式运行时出现了问题,但在 playonlinux 命令末尾添加“&”似乎可以解决问题。

#!/bin/bash

#The idea is to use this script to replace the command in the shortcut.
#
# Architectural & contextual notes: This is a desktop ( my wargamer's box called
# Warmachine ) which has a synergy server running on it and also a laptop that
# runs a synergy client. Synergy & pulseaudio must die in order for the game to
# play correctly. Synergy must die on both machines but pulseaudio is an issue
# local to the desktop. The Synergy client running remotely must die because it
# freaks out when it can't find the server. The most annoying effect of this is
# a shrieking laptop fan while you are trying to conentrate when it isn't even
# supposed to be doing anything. I have aliases for all these functions and I'm
# really just putting them into a wrapper script form because I keep forgetting
# to use them.
#
# In order for the sudo commands to work in a non-interactive fashion
# i.e., without a password, you need the following entry in your sudoers file:
# [username goes here] ALL=(root) NOPASSWD: /usr/sbin/service avahi-daemon restart, /usr/bin/killall synergys
# ...and this one on the laptop:
# [username goes here] ALL=(root) NOPASSWD: /usr/bin/killall synergyc, /home/jim/scripts/restartSynergy.sh
# I use a special script to restart synergy on the laptop as it includes a
# screen resizing background process that fixes the synergy screen size
# when it swtches from the laptops display to the 42" TV I use for a regular
# game display.

#kpa - Kill Pulse Audio alias
#We are killing pulseaudio because WINE hates it.

echo "autospawn = no" > ~/.config/pulse/client.conf &
pulseaudio --kill

#Now we need to kill our synergy server and also stop the client in my laptop.

ssh -t -t bl sudo /usr/bin/killall synergyc &
sudo /usr/bin/killall synergys

sleep 1

# This is the command to start the game. This is what the script is wrapping.
# Unfortunately this command returns as soon as it is called regardless, so I
# need to come up with something to deal with that. Perhaps a polling system?
# The apparently extraneous '&' below fixes an issue.
/usr/share/playonlinux/playonlinux --run "Battle.Net" %F &

sleep 1

#This is our polling loop.
EXIT=0
while [ ${EXIT} -eq 0 ]; do
  sleep 5

  ps aux | grep -v grep | grep Battle\.Net
  EXIT=$?
  if [[ ${EXIT} != 0 ]]; then

    #spa - Start Pulse Audio alias
    rm -f ~/.config/pulse/client.conf
    pulseaudio --start

    # Reload the audio devices in the GUI
    sudo /usr/sbin/service avahi-daemon restart &

    /usr/bin/synergys -a 127.0.0.1 -c /etc/synergy.conf
    sleep 1
    #Restart synergy client on laptop.
    ssh -t -t bl /home/jim/scripts/restartSynergy.sh

  fi

done

相关内容