Script Help

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
mooseranger
Level 1
Level 1
Posts: 6
Joined: Fri May 29, 2009 3:53 pm

Script Help

Post by mooseranger »

Hello,

When running Battle for Middle Earth 2, my screen resolution needs to be set at 1024x768 before I run the program or it crashes when I start a game. (It does switch automatically to 1024x768 but if I didn't set it myself beforehand it will crash once I start a game). Normally I have my resolution set at 1440x900.

I wrote a script to do a few things:

Code: Select all

sed 's/"UseGLSL"="enabled"/"UseGLSL"="disabled"/' -i /home/david/.wine/user.reg
xrandr -s 1024x768
sleep 2
env WINEPREFIX="/home/david/.wine" 
wine "C:\Program Files\Electronic Arts\The Battle for Middle-earth (tm) II\lotrbfme2.exe"
sed 's/"UseGLSL"="disabled"/"UseGLSL"="enabled"/' -i /home/david/.wine/user.reg
xrandr -s 1440x900
The sed stuff is in there because LOTRBFME2 requires UseGLSL disabled but for other things I need it enabled.

That said, whenever I run this script it crashes when I try to load a game just the same as it does if my resolution were 1440x900 before I launched it. If I take out the xrandr -s 1024x768 line, manually change the resolution in the nvidia x server settings, then run the script, it works fine (but isn't as convenient).

Does nvidia x server settings do something xrandr doesn't, or is there something else I am supposed to do?

(of course, if anyone knew how to get battle for middle earth to run fine from 1440x900, that would be great as well).

Thank you very much!
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: Script Help

Post by vitamin »

mooseranger wrote:sed 's/"UseGLSL"="enabled"/"UseGLSL"="disabled"/' -i /home/david/.wine/user.reg
Don't do this, you will corrupt Wine registry. Or this change will have no affect if wineserver is running.

Add this setting for your app only. In winecfg, add your game exe (Add application) and select it in the list. Go to graphics tab, un-check pixel shader, hit apply, check it back, apply, exit.

Start regedit, got to this key: [HKEY_CURRENT_USER\Software\Wine\AppDefaults\lotrbfme2.exe\Direct3D] and add "UseGLSL"="disabled".
mooseranger wrote:Does nvidia x server settings do something xrandr doesn't, or is there something else I am supposed to do?
Does running xrandr manually from the terminal, waiting 5 sec and starting your game has the same problem as script?
mooseranger
Level 1
Level 1
Posts: 6
Joined: Fri May 29, 2009 3:53 pm

Re: Script Help

Post by mooseranger »

vitamin wrote:
mooseranger wrote:sed 's/"UseGLSL"="enabled"/"UseGLSL"="disabled"/' -i /home/david/.wine/user.reg
Don't do this, you will corrupt Wine registry. Or this change will have no affect if wineserver is running.

Add this setting for your app only. In winecfg, add your game exe (Add application) and select it in the list. Go to graphics tab, un-check pixel shader, hit apply, check it back, apply, exit.

Start regedit, got to this key: [HKEY_CURRENT_USER\Software\Wine\AppDefaults\lotrbfme2.exe\Direct3D] and add "UseGLSL"="disabled".
Hmm... I tried this and it didn't seem to work...
vitamin wrote:
mooseranger wrote:Does nvidia x server settings do something xrandr doesn't, or is there something else I am supposed to do?
Does running xrandr manually from the terminal, waiting 5 sec and starting your game has the same problem as script?
Running xrandr from the terminal did not seem to have the same problem as the script; running it manually from the terminal worked fine...odd...

I tried making the script just sleep longer; that didn't help. The script is called LOTRBFME2.sh and I ran it with 'sh LOTRBFME2.sh' - is there a different way I should run the script that would make it as if I manually ran it? (I'm new to this).

Thanks!
Martin Gregorie

Script Help

Post by Martin Gregorie »

On Sun, 2009-05-31 at 12:47 -0500, mooseranger wrote:
I tried making the script just sleep longer; that didn't help. The
script is called LOTRBFME2.sh and I ran it with 'sh LOTRBFME2.sh' - is
there a different way I should run the script that would make it as if
I manually ran it? (I'm new to this).
Does the script just run xrandr or does it run xrandr, wait 5 seconds
and then start LOTR? If it does the first things may be confused by you
using several shells:

- first is the shell that put up your command prompt
- using "sh LOTRBFME2.sh" starts a new shell to run your script
- if your script starts with "#!/bin/sh" that will start a third shell
- the third shell will run the script and exit, then the second shell
will exit to leave you in the original shell, but any shell variables
the 2nd and 3rd shells set up will be lost

The second shell is always redundant: all scripts should start with
"#!/bin/shell" to make sure the right 'shell' is run. This way you never
need to write "sh script" to run a script from the command line. So, fix
that and then try one of the following:

- run a script (WITHOUT the #! line) as ". script" to run it in your
original shell and follow it with "wine blahblah" to run LOTR

- write and run a script looks something like:

#!/bin/bash
xrandr [optionds and arguments] #run xrandr
sleep 5 #wait 5 secs
wine blahblah #start LOTR
exit

not forgetting to make it executable "chmod u+x scriptname"
before running it.

Martin
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: Script Help

Post by vitamin »

mooseranger wrote:Hmm... I tried this and it didn't seem to work...
Then you might need to do this for a different executable. Some programs, especially games, use a launcher. You want to use the actual game executable instead. You should be able to find it running 'ps -ef' and looking for the actual game process name.
Martin Gregorie wrote:- first is the shell that put up your command prompt
- using "sh LOTRBFME2.sh" starts a new shell to run your script
- if your script starts with "#!/bin/sh" that will start a third shell
- the third shell will run the script and exit, then the second shell
will exit to leave you in the original shell, but any shell variables
the 2nd and 3rd shells set up will be lost
This is all irrelevant.

He doesn't background any of the processes. Which shell they run doesn't matter. 'xrandr' changes X-display settings which have nothing to do with shell "setup".

The only possible reason why it works when manually run and doesn't work from the script - is timing. 5 seconds might not be enough.
mooseranger
Level 1
Level 1
Posts: 6
Joined: Fri May 29, 2009 3:53 pm

Post by mooseranger »

Martin Gregorie:
run a script (WITHOUT the #! line) as ". script" to run it in your
original shell
I tried these suggestions and the first time I ran the .script file, it worked! Then I tried reducing the time from 7 seconds to see if it would still work; it did not. However, when I changed it back to 7 seconds, it no longer worked and would not work again no matter what I did. Does anyone have any idea why?

vitamin:
The only possible reason why it works when manually run and doesn't work from the script - is timing. 5 seconds might not be enough.
I tried it with sleep 20 (much more than enough time) and that still didn't work in the script file, but it works in the terminal.
Then you might need to do this for a different executable. Some programs, especially games, use a launcher. You want to use the actual game executable instead. You should be able to find it running 'ps -ef' and looking for the actual game process name.
The game starts up with lotrbfem2.exe (what I set the options for before). After that, it goes to a process "game.dat" - how would I set the options for that?

Thank you guys so much for your help!
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

mooseranger wrote:Does anyone have any idea why?
No clue, could be something else and not xrandr. Wine bight still be running when you tested and it worked/didn't work.
mooseranger wrote:The game starts up with lotrbfem2.exe (what I set the options for before). After that, it goes to a process "game.dat" - how would I set the options for that?
Just rename the "lotrbfem2.exe" registry key to "game.dat" ex:

Code: Select all

[HKEY_CURRENT_USER\Software\Wine\AppDefaults\game.dat\Direct3D]
mooseranger
Level 1
Level 1
Posts: 6
Joined: Fri May 29, 2009 3:53 pm

Post by mooseranger »

Ok, well something got messed up because the game stopped working at all. I uninstalled wine, deleted the .wine folder, reinstalled wine, and reinstalled the game.

The registry stuff you suggested works when I change the key to game.dat; thanks much!

Then I just made a script that toggles the resolution between 1440x900 and 1024x768, so I have a shortcut to that script in my panel and a shortcut to BFME2. It works pretty well just clicking the toggle resolution shortcut then the game launcher, then the toggle after I'm done.

Thanks all!
Locked