It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I made a PKGBUILD file for Baldur's Gate for Arch Linux. My issue is now how to get saving to work. The game is installed /opt/gog/. Hence the user can't write to that directory. I know I can change persmissions but that seems messy. I'm trying to use unionfs to move the save directory.
Here is the shell script I’ve written to launch Baldur’s Gate, maybe you can find some inspiration from it:
#!/bin/sh
ID=baldurs-gate
WRITABLE='*.ini *.key *.tlk'
EXE=bgmain2.exe
USERDIR=$HOME/.local/share/games/$ID
export WINEPREFIX=$USERDIR/.wine
export WINEDEBUG=-all

if ! [ -d $USERDIR ]
then
__ INSTALLDIR=/usr/local/share/games/$ID
__ mkdir -p $(dirname $USERDIR)
__ cp -as $INSTALLDIR $USERDIR
__ WINEARCH=win32 wineboot -i
__ rm $WINEPREFIX/dosdevices/"z:"
__ ln -s $USERDIR $WINEPREFIX/drive_c
__ cd $USERDIR
__ for file in $WRITABLE
__ do
____ cp -a --remove-destination $INSTALLDIR/$file $file
__ done
fi

cd $WINEPREFIX/drive_c/$ID
wine $EXE
If you’d like explanations for some parts of it, feel free to ask ;)

PS: I put underscores representing tabs, I hope it will make the code easier to read.
Post edited October 30, 2014 by vv221
I can see that you have installed the game under /usr/local/share/games/ but I am not quite sure I understand the next part. How vdo you solve the save game issue?
GOG forums eating my tabulations doesn’t help reading a code that might not be crystal clear to begin with, I’ll explain it part by part.

ID=baldurs-gate
WRITABLE='*.ini *.key *.tlk'
EXE=bgmain2.exe
USERDIR=$HOME/.local/share/games/$ID
export WINEPREFIX=$USERDIR/.wine
export WINEDEBUG=-all
Here I define some variables: $WRITABLE is the list of files the user might need to modify, $USERDIR is a directory in the user’s $HOME, where a fake tree is created (more on this later), $WINEPREFIX is a WINE prefix specific to the game (the system-wide WINE is used, not an embedded one).

if ! [ -d $USERDIR ]
then
__ INSTALLDIR=/usr/local/share/games/$ID
__ mkdir -p $(dirname $USERDIR)
__ cp -as $INSTALLDIR $USERDIR
__ WINEARCH=win32 wineboot -i
__ rm $WINEPREFIX/dosdevices/"z:"
__ ln -s $USERDIR $WINEPREFIX/drive_c
__ cd $USERDIR
__ for file in $WRITABLE
__ do
____ cp -a --remove-destination $INSTALLDIR/$file $file
__ done
fi
This part is executed only at the first launch, and it is the one containing the saves management. A fake tree is created in the user’s $HOME, replicating the real tree under /use/local by recreating the directory tree and putting symlinks to the files contained in it ("cp -as" command). Thanks to this, the game launched by the user will be able to create new files (including saves) without the need to have write access to the original files.
Except that there is some files the user may need to modify to. Here come the "for" loop, copying the said files in $USERDIR instead of the symlinks already in place.

cd $WINEPREFIX/drive_c/$ID
wine $EXE
I guess this part is quite self-explanatory, it simply launch the game.

-----

I hope it is easier to understand now, don’t hesitate to ask if you need more precisions.

I actually thought of unionfs at the beginning, but finally found this method (fake tree with symlinks) and kept it to use as little dependencies as possible.

PS: I put underscores representing tabs, I hope it will make the code easier to read.
Post edited October 30, 2014 by vv221
Thanks for the clarification. If you launch the game via the startup.sh you get three options to run the game: fullscreen, windowed and then the config menu. Would it be possible to use that in thew last two lines or would that overwrite your wine settings?
Post edited October 30, 2014 by fettouhi
avatar
fettouhi: Thanks for the clarification. If you launch the game via the startup.sh you get three options to run the game: fullscreen, windowed and then the config menu. Would it be possible to use that in thew last two lines or would that overwrite your wine settings?
To launch the config menu, just copy the script and change the EXE value to config.exe (that’s how I do it in my Debian packages, with two separate scripts for the game and the config menu).
And for windowed/fullscreen, just use 'Alt'+'Enter' ;)
Can't get the script working on my Arch Linux box. Wine won't run the game.
avatar
fettouhi: Can't get the script working on my Arch Linux box. Wine won't run the game.
Never tried it on an Arch box before, but it should work.
Do you have any error reported in the console?

Could you post you own version of it (the one you use)?
I guess you had to do some slight modifications to get it to (not) run with your game installed under /opt.

PS: A lot of variables in my version are not quoted, because I use paths without spaces.
You might need to quote $USERDIR, $INSTALLDIR and $WINEPREFIX if there are spaces in the path to the game files.
Post edited October 31, 2014 by vv221
[code]
#!/usr/bin/bash
ID=baldurs-gate
WRITABLE='*.ini *.key *.tlk'
EXE=BGMain.exe
USERDIR=$HOME/.gog/$ID
export WINEPREFIX=$USERDIR/.wine
export WINEDEBUG=-all

if ! [ -d $USERDIR ]
then
INSTALLDIR=/opt/gog/$ID
mkdir -p $(dirname $USERDIR)
cp -as $INSTALLDIR $USERDIR
WINEARCH=win32 wineboot -i
rm $WINEPREFIX/dosdevices/"z:"
ln -s $USERDIR $WINEPREFIX/drive_c
cd $USERDIR
for file in $WRITABLE
do
cp -a --remove-destination $INSTALLDIR/$file $file
done
fi

cd $WINEPREFIX/drive_c/$ID/prefix/drive_c/GOG\ Games/Baldur's\ Gate/
wine $EXE
[/code]
/!\ My thinking process sometimes following strange ways, you should directly jump to the end of my post to find a (probably) working script ;)
avatar
fettouhi: #!/usr/bin/bash
ID=baldurs-gate
WRITABLE='*.ini *.key *.tlk'
EXE=BGMain.exe
USERDIR=$HOME/.gog/$ID
export WINEPREFIX=$USERDIR/.wine
export WINEDEBUG=-all
This part is OK.
I can’t remember why I use bgmain2.exe instead of bgmain.exe… Maybe the latter is from the original game while the former is the one added by th expansion? Anyway, shouldn’t matter if the game can be launched from BGMain.exe on your system.
avatar
fettouhi: if ! [ -d $USERDIR ]
then
INSTALLDIR=/opt/gog/$ID
mkdir -p $(dirname $USERDIR)
cp -as $INSTALLDIR $USERDIR
WINEARCH=win32 wineboot -i
rm $WINEPREFIX/dosdevices/"z:"
ln -s $USERDIR $WINEPREFIX/drive_c
cd $USERDIR
for file in $WRITABLE
do
cp -a --remove-destination $INSTALLDIR/$file $file
done
fi
This part is OK if the file BGMain.exe can be found under /opt/gog/baldurs-gate/BGMain.exe, is that the case? Otherwise, what is the absolute path to this file?
EDIT: I can see from the end of the script that $INSTALLDIR does not point directly to the directory containing BGMain.exe, see below for more comments on this.
avatar
fettouhi: cd $WINEPREFIX/drive_c/$ID/prefix/drive_c/GOG\ Games/Baldur's\ Gate/
wine $EXE
[/code]
I can see here you kept the files in the same file tree that GOG provides, which this script is not meant to use (it could, but it might need more tweaking to do so).
You should put everything found under whatever/prefix/drive_c/GOG\ Games/Baldur's\ Gate/ in a directory, and define $INSTALLDIR to its path. Everything else from the GOG archive can be trashed.

Here is how I do it (incomplete script, only relevant parts):

#!/bin/sh

ID=baldurs-gate
VERSION=1.3.5521
REVISION=gog1.0.0.8
ARCH=all
ARCHIVE=gog_baldurs_gate_1.0.0.8.tar.gz

PKGNAME="$ID"_"$VERSION"-"$REVISION"_"$ARCH"
mkdir -p $PKGNAME/usr/local/share/doc/$ID $PKGNAME/usr/local/share/games/$ID

TMPDIR=$ID.$(date +%s)
mkdir $TMPDIR
tar xvf "$ARCHIVE" -C $TMPDIR
mv $TMPDIR/*/docs/* $PKGNAME/usr/local/share/doc/$ID
mv $TMPDIR/*/prefix/drive_c/"GOG Games"/*/* $PKGNAME/usr/local/share/games/$ID
rm -r $TMPDIR
sed -i s/'HD0:=.\+'/'HD0:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD1:=.\+'/'CD1:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD2:=.\+'/'CD2:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD3:=.\+'/'CD3:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD4:=.\+'/'CD4:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD5:=.\+'/'CD5:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
sed -i s/'CD6:=.\+'/'CD6:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/baldur.ini
$PKGNAME is the folder in which I create the Debian package, it probably can’t be used as is with Archlinux system.
The command 'date +%s' is used to add an unique identifier to $TMPDIR, allowing parallel builds of the package. You can omit it if you don’t need to allow building several packages for the same game in parallel (you probably don’t).
The several sed commands are for editing the baldur.ini file, which you have to do if you don’t keep the GOG files organization, or the game will complain about missing files and won’t launch.

-----

A maybe simpler alternative if you want to keep GOG files organization (this way you don’t need to change anything in baldur.ini), assuming BGMain.exe can be found at "/opt/gog/Baldurs Gate/prefix/drive_c/GOG Games/Baldur's Gate/BGMain.exe"

#!/usr/bin/bash
WRITABLE='*.ini *.key *.tlk'
EXE=BGMain.exe
USERDIR="$HOME/.gog/Baldurs Gate"
export WINEPREFIX="$USERDIR/prefix"
export WINEDEBUG=-all

if ! [ -d $USERDIR ]; then
INSTALLDIR="/opt/gog/Baldurs Gate"
mkdir -p $(dirname $USERDIR)
cp -as $INSTALLDIR $USERDIR
WINEARCH=win32 wineboot
cd "$USERDIR/prefix/drive_c/GOG Games/Baldur's Gate"
for file in $WRITABLE; do
cp -a --remove-destination "$INSTALLDIR/prefix/drive_c/GOG Games/Baldur's Gate"/$file $file
done
fi

cd "$WINEPREFIX/drive_c/GOG Games/Baldur's Gate"
wine $EXE
/!\ If it exists, you should remove directory "$HOME/.gog/Baldurs Gate" before running the script to be sure it is initialized properly.

Run it from a console and give me any eventual error message if it still doesn’t work for you.

PS: Script written with no possibility to test it yet, double-check it for eventual typos ;)
Post edited November 01, 2014 by vv221
Here is the output

[af@andre ~]$ gog-baldurs-gate
wine: created the configuration directory '/home/af/.gog/baldurs-gate/.wine'
wine: configuration in '/home/af/.gog/baldurs-gate/.wine' has been updated.
cp: kan ikke udføre stat() på '/opt/gog/baldurs-gate/*.ini': Ingen sådan fil eller filkatalog
cp: kan ikke udføre stat() på '/opt/gog/baldurs-gate/*.key': Ingen sådan fil eller filkatalog
cp: kan ikke udføre stat() på '/opt/gog/baldurs-gate/*.tlk': Ingen sådan fil eller filkatalog
wine: cannot find L"C:\\windows\\system32\\BGMain.exe"
Woops, sorry for the late answer, I missed your last post.

avatar
fettouhi: cp: kan ikke udføre stat() på '/opt/gog/baldurs-gate/*.ini': Ingen sådan fil eller filkatalog
Looks like INSTALLDIR doesn’t point to the right path.
What does the following commands tell you?
ls /opt/gog/baldurs-gate
ls ~/.gog/baldurs-gate
avatar
vv221: Woops, sorry for the late answer, I missed your last post.

avatar
fettouhi: cp: kan ikke udføre stat() på '/opt/gog/baldurs-gate/*.ini': Ingen sådan fil eller filkatalog
avatar
vv221: Looks like INSTALLDIR doesn’t point to the right path.
What does the following commands tell you?

ls /opt/gog/baldurs-gate
ls ~/.gog/baldurs-gate
avatar
vv221:
Here is the output

[af@andre test]$ ls /opt/gog/baldurs-gate
Baldur.exe Characters dialog.tlk movies Save
Baldur.ini Chitin.key Keymap.ini MPSave scripts
BGMain2.exe Config.exe luaAuto.cfg Music Sounds
BGMain.exe data MConvert.exe Override temp
[af@andre test]$ ls ~/.gog/baldurs-gate
Baldur.exe Characters dialog.tlk movies Save
Baldur.ini Chitin.key Keymap.ini MPSave scripts
BGMain2.exe Config.exe luaAuto.cfg Music Sounds
BGMain.exe data MConvert.exe Override temp

So now the Config.exe runs but when I run BGMain.exe I get a popup window saying

An Assertion failed in D:\Dev\chitin\ChDimm.cpp at linu number 581
Programmer says: Unable to Open BIF:data\SFXSound.bif
Got it working now. I had forgotten to add the

sed -i s/'HD0:=.\+'/'HD0:=C:\\baldurs-gate\\'/ $PKGNAME/usr/local/share/games/$ID/Baldur.ini

lines. Hence the crash. Many many thanks for your help.
avatar
fettouhi: Got it working now.
Glad it finally worked!