 _          _    _    ____                            _
| |    ___ | | _(_)  / ___|___  _ __ ___  _ __   __ _| |_
| |   / _ \| |/ / | | |   / _ \| '_ ` _ \| '_ \ / _` | __|
| |__| (_) |   <| | | |__| (_) | | | | | | |_) | (_| | |_
|_____\___/|_|\_\_|  \____\___/|_| |_| |_| .__/ \__,_|\__|
                                         |_|
Libraries for running old Loki games.
Alan Swanson <swanson@ukfsn.org>
3 Oct 2009
Release 1.4


THE PROBLEM
===========

Unknown changes in glibc 2.3 (and newer) cause problems for these old games
resulting in a segmentation fault when trying to run them, the suspects are
threading and C++ ABI incompatibility. Using the static binaries can be
problematic as the libraries compiled into them are old and have bugs such
as SDL using a low screen refresh rate with XFree 4.3 or newer [1].

Workarounds such as using LD_ASSUME_KERNEL and/or pre-loading a smpeg
library compiled with an old GCC version only sometimes work and the movies
may be blank or have to be disabled. In the future for glibc 2.4,
LinuxThreads and the LD_ASSUME_KERNEL workaround are going away [2].


THE SOLUTION
============

The solution is to use an old version of glibc such as 2.2.5. However all
the other libraries linked by the game must also be compiled against an
equally old (or older) version of glibc.

The libraries used by the Loki games have been compiled and provided by me
for others to run their old games too. Other than glibc and zlib which were
the last (security) releases from Debian, all the libraries included in the
tar are based on the current Gentoo ebuilds available at the time. Further
details on library versions at bottom.

To use the old glibc libraries set the LD_LIBRARY_PATH environment variable
to the directory these libraries are located. Additionally prepend the game
binary to run the game with the old ld-linux.so.2 dynamic linker/loader
(as the one with glibc 2.3 does not include the GLIBC_2.2, GLIBC_2.2.1 or
GLIBC_2.2.3 profiles used with glibc 2.2.5 for some reason).


THE GAMES
=========

Assuming the games are patched to the latest available patches (and there
are never going to be newer patches) then to run them use the following
instructions. The dynamic binaries are used where available.

CIVILSATION: CALL TO POWER
Requires an old glibc so to run use the following command;
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/CivCTP/civctp.dynamic

DESCENT 3
Compatible with new glibc using smpeg library created with old compiler but
needs an uppercased symbolic link for one file to be created;
  $ cd /path/Descent3
  $ ln -s ppics.hog PPics.Hog
Then to run use the following command;
  $ LD_PRELOAD=/path/Loki_Compat/libstdc++-3-libc6.2-2-2.10.0.so:/path/Loki_Compat/libsmpeg-0.4.so.0.1.3 /path/Descent3/descent3

HEAVY METAL: FAKK2
Compatible with newer glibc but requires old zlib version. It is also
recommended to use the pak4.pk3 file provided at
http://icculus.org/~chunky/fakk2/ to fix a crashing problem during the game.
  $ cp pak4.pk3 /path/FAKK2/fakk/
Then to run use the following command;
  $ LD_PRELOAD=/path/Loki_Compat/libz.so.1.1.4 /path/FAKK2/fakk2

HERETIC II
No workarounds are required as it is compatible with newer glibc.

HEROES OF MIGHT AND MAGIC 3
Requires an old glibc so to run use the following command;
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/Heroes3/heroes3.dynamic

KOHAN: IMMORTAL SOVEREIGNS
Requires an old glibc so to run use the following command;
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/Kohan/kohan.dynamic

MINDROVER
No workarounds are required as it is compatible with newer glibc.

MYTH 2: SOULBLIGHTER
Compatible with new glibc but need meminfo compatibility fix.
  $ LD_PRELOAD=/path/Loki_Compat/meminfo-compat.so /path/Myth2/myth2_x11.dynamic
Previous instructions to disable movies can be reverted;
  $ cd /patch/Myth2
  $ mv cutscenes.disabled cutscenes

SHOGO: MOBILE ARMOR DIVISION
No workarounds are required as it is compatible with newer glibc. However it
may run too fast on modern computers. Add the following parameter to the
autoexec.cfg configuration file located under ~/.hyperion/Shogo/.
  "MaxFPS" "30"

SID MEIER'S ALPHA CENTAURI
Requires an old glibc so to run use the following command (note the smacpack
command only runs the static binaries);
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/AlphaCentauri/smac.dynamic
To run the Alien Crossfire expansion use the following command;
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/AlphaCentauri/smacx.dynamic

SIMCITY 3000
Requires an old glibc so to run use the following command;
  $ LD_LIBRARY_PATH=/path/Loki_Compat/ /path/Loki_Compat/ld-linux.so.2 /path/SimCity3000/sc3u.dynamic

SIN
Compatible with newer glibc using smpeg library created with old compiler but
needs an old SDL library name in system. Create a symbolic link in the system
from the old name to the new name;
  $ cd /usr/lib
  $ ln -s libSDL-1.2.so libSDL-1.1.so
Then change to your SiN install directory and run using the following
commands;
  $ cd /path/SiN
  $ LD_PRELOAD=/path/Loki_Compat/libstdc++-3-libc6.2-2-2.10.0.so:/path/Loki_Compat/libsmpeg-0.4.so.0.1.3 ./sin.exe

SOLDIER OF FORTUNE
No workarounds are required as it is compatible with newer glibc.

UNREAL TOURNAMENT
No workarounds are required as it is compatible with newer glibc. However
do ensure it uses the newer system SDL library. First either rename or
delete the old library installed with the game;
  $ cd /path/UnrealTournament/System
  $ mv libSDL-1.1.so.0 libSDL-1.1.so.0.orig
Then create a symbolic link in the system from the old name to the new name;
  $ cd /usr/lib
  $ ln -s libSDL-1.2.so.0 libSDL-1.1.so.0


FURTHER PROBLEMS
================

If any game exits with an error similar to the following;
  X Error of failed request: BadMatch (invalid parameter attributes)
  for Major opcode of failed request: 142 (XVideo)
Then disable hardware YUV acceleration by prepending the following to the
command that runs the game;
  SDL_VIDEO_YUV_HWACCEL=0


THE LIBRARIES
=============

The libraries included were built in a chrooted Debian 3.0 Woody using
GCC 2.95.4 with CFLAGS "-O2 -march=i686" as upgrading from Gentoo 1.2, which
has glibc 2.2.5 and gcc 2.95.3, to the current portage is decidedly
non-trivial.

GLIBC 2.2.5
  From the last Debian Woody 3.0 glibc (security) release which was
  libc6_2.2.5-11.8_i386.deb. Only the files in the /lib directory are
  are required.

ZLIB 1.1.4 (libz.so.1.1.4)
  From the last Debian Woody 3.0 zlib release which was
  zlib1g_1.1.4-1.0woody0_i386.deb.

XORG 6.8.2 (libX11.so.6.2 libXext.so.6.4 libGL.so.1.2 libXrandr.so.2.0
            libXrender.so.1.2.2 libXfixes.so.3.0 libXcursor.so.1.0.2)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo xorg-x11-6.8.2-r4 ebuild and patches.

ALSA 1.0.21a (libasound.so.2.0.0)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo alsa-lib-1.0.21a ebuild.

SDL 1.2.13 (libSDL-1.2.so.0.11.3)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo libsdl-1.2.13-r1 ebuild with CVS dated 2008-10-03 to
  fix screensaver not being renabled on exit and patches but without esd or
  arts support.

SMPEG 0.4.4 (libsmpeg-0.4.so.0.1.3)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo smpeg-0.4.4-r7 ebuild and patches.

SMJPEG 0.2.1 (libsmjpeg-0.2.so.0.0.1)
 Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
 based on the Gentoo smjpeg-0.2.1-r2 ebuild.

SDL-MIXER 1.2.8 (libSDL_mixer-1.2.so.0.2.6)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo sdl-mixer-1.2.8 ebuild.

SDL-TTF 2.0.9 (libSDL_ttf-2.0.so.0.6.3)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo sdl-ttf-2.0.9 ebuild.

LIBOGG 1.1.4 (libogg.so.0.6.0)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo libogg-1.1.4 ebuild.

LIBVORBIS 1.2.3 (libvorbis.so.0.4.3 libvorbisfile.so.3.3.2)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -mcpu=i686" and
  based on the Gentoo libvorbis-1.2.3 ebuild.

FREETYPE 1.3.1 (libttf.so.2.2.0)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo freetype-1.3.1-r4 ebuild.

FREETYPE 2.1.10 (libfreetype.so.6.3.8)
  Built on Debian 3.0 using GCC 2.95.4 with CFLAGS "-O2 -march=i686" and
  based on the Gentoo freetype-2.1.10-r2 ebuild and patches but without
  the security patches as they caused text to disappear with SMAC.

OPENAL 0.0 (libopenal-0.0.so)
  Taken from Unreal Tournament patched to 436. Although the OpenAL CVS was
  tagged for 0.0 I do not know the status of it. The libopenal-0.0.so
  included with patch 1.06a for Soldier Of Fortune may possibly be newer with
  a fix for small wav files but the Unreal Tournament one works for my games.


CHANGELOG
=========
1.4 Add meminfo compatibility [3], libogg, and libvorbis. Updated libsdl,
    sdl-mixer and sdl-ttf.
1.3 Add libXcursor, libXfixes and libXrender libraries. Updated libsdl.


REFERENCES
==========

[1] http://www.devolution.com/pipermail/sdl/2003-April/053836.html
[2] http://www.redhat.com/archives/fedora-test-list/2005-July/msg00095.html
[3] http://tobias.rautenkranz.ch/myth_memfix.html
