Thursday, January 28, 2010

Breakneck / N.I.C.E.2 / Excessive Speed on Linux (PART 2)

. . .Part 2. The Technical Stuff

Ok, first of all to get this game running under Linux you'll need to install Wine. Wine is a Windows compatibility layer for Linux. Most Linux distributions have it in their repositories, and that's really the best way to install it. It can be difficult to compile from source or install manually. So, ok, go do that. I'll wait.

MAKE AN IMAGE

Ah! You're back so soon? Cool. You'll need your Breakneck CD-ROM to install the game. But we're not going to actually use the disc. First of all, it's a pain in the ass to swap CDs in and out. That's so last century! I've also noticed that the game tends to remember which CD/DVD drive it was installed from, because on my system with multiple optical drives the game will only run with the CD in the drive from which I originally installed it. So, what we want to do is make an IMAGE of the CD. This is a really good idea with an old game like this that is out of production - if you damage the CD you're out of luck (unless you find one on eBay I suppose). Here's what to do:
1. Insert the BreakNeck CD in your CD/DVD drive.
2. If it "auto mounts" you need to unmount it! If you see its icon on the desktop just right+click and "unmount" it. If your system isn't set up to show mounted drives on the desktop you need to open a terminal and type "mount" at the prompt. Look for the CD in the list (probably /dev/cdrom). If it's there type (without the quotes) "umount /dev/cdrom" or "umount /media/cdrom" or "umount /mnt/cdrom" depending on what you saw in the list.
3. Create CD-ROM ISO image with dd command (assuming CD is at /dev/cdrom and $ is the prompt):

$ dd if=/dev/cdrom of=/tmp/BreakNeck.iso

That will create the ISO file in your temporary files "/tmp" directory. Just navigate to it and move it where-ever you plan to store CD-ROM images. For example, I put mine in a folder I created in my Home directory: "~/Games/Windows/CDs/"

You can put the original BreakNeck CD-ROM away for safe-keeping.

CREATE A FAKE DRIVE

You'll need to mount the ISO file every time you want to play the game. You'll need your trusty terminal again. Type the following commands (we'll be working as root so you'll need administrative access. "$" represents the prompt):

$ sudo su

$ mkdir /media/iso

$ gedit /etc/fstab

(on that last one if you're using Gnome that works. Or instead of "gedit" put in whatever text editor you prefer to use)

on a new line at the bottom of that file enter this:

/tmp/isolink /media/iso udf,iso9660 ro,user,loop,noauto 0 0

Save the file. That line now creates a link between a temporary file and the media/iso folder we created above.

That's it! Well, almost. We still need the "/tmp/isolink" but we'll create that in the next step.

INSTALL THE GAME

Open up a terminal and type the following:

$ ln -sf ~/Games/Windows/CDs/BreakNeck.iso /tmp/isolink

$ mount /media/iso

Your ISO file is now mounted as if it were the original CD-ROM! You should be able to run the installer just as you would on a Windows machine. You can skip the DirectX install because Wine already has a nearly complete implementation of DirectX 6 built into it. I didn't try any of the DX Media stuff because the running commentary from "Eddie" is hyper annoying.

At this point you should be able to run the "Setup" utility. You can select whatever graphics card you want, it doesn't matter, because we'll HAVE to use the Software Engine. You can either select it in the first drop-down box OR you can just check the "Software Engine" checkbox. Don't bother playing with any of the other options, except make sure "SoundFX" is checked. Force Feedback won't work, so you can ignore the radio buttons at the bottom. Click "Benchmark" to make sure the settings work, and to see if the frame rate is high enough. If it isn't, you'll need to either dial down the resolution (lower the smoother) and/or the bit-depth (32 to 16). If all goes well you can then test play the game.

UPDATE: Ubuntu 10.04 Lucid Lynx / Linux Mint 9

With the latest versions of Ubuntu (and derivatives) there is now a "ExecutableBit" security policy in place by default that blocks .EXE files on CD-ROMs, DVDs, and mounted ISO images from being marked as executable/trusted, so you can no longer just double click on such files and have them run in Wine. :(

In order to install BreakNeck from the CD-ROM (or the mounted ISO image of it) you will need to either press ALT+F2 to get a "run" window or open a Terminal and type:

$ wine /media/iso/setup.exe

Once the program is installed, however, the EXE file being executed is installed to the Wine "C:" drive as a trusted executable, so if you want to play the game directly (without XBMC being involved) you'll need to run the game from the Main Menu entry or you'll need to execute the launch script explained in the next section, which will be treated the same as typing the commands in a terminal.

CREATE A LAUNCH SCRIPT

Normally you won't be able to just click on the game icon on your desktop or in your main menu and play the game because it is going to want your CD in the drive! So, let's create a script that will "insert" the virtual CD in the fake drive and then launch the game for us!

Open up a text editor and type in the following (replace "username" with your login name):

umount /media/iso
rm -r /tmp/isolink
ln -sf ~/Games/Windows/CDs/BreakNeck.iso /tmp/isolink
mount /media/iso
env WINEPREFIX="/home/username/.wine" wine "C:\Program Files\SouthPeak Interactive\BreakNeck\breakneck.exe"

Explanation:
Line 1 makes sure no other ISO files are mounted.
Line 2 removes the "isolink" file because the next line can't always overwrite it properly.
Line 3 creates the "isolink" file pointing to the desired ISO file.
Line 4 mounts the ISO file to our fake drive
Line 5 launches BreakNeck in Wine.

Save the file with whatever name you want (something like "BreakNeck" is good) and then right+click on it and under the Permissions make sure it is "executable."

Here's the cool part: Copy that file and edit it to mount different ISO files and launch other programs and the scripts will do the virtual CD-swapping for you - always making sure the correct CD image is in the virtual drive.

I should note that this method only works with games that require a single CD be in the drive. I haven't tackled games that want you to swap out CDs during the game.

CONFIGURE WHEEL

Odds are you don't want to drive your car with the arrow keys on the keyboard. You probably also don't want to drive with a joystick (but you can if that's all you've got), but I'm going to talk about setting up a wheel. Specifically a Thrustmaster wheel since I have two different ones I tried.

1. Do not, I repeat NOT, install the drivers/utilities for your game controllers in Wine. They simply will not work because Wine gets the game controller configurations from Linux.

2. Plug your controller into a USB port. If you have an old "game port" controller you're probably SOL - I couldn't get the one I had to work. I would highly recommend you only plug ONE controller in - the one you want to use - for best results.

3. Open up a terminal and type:

$ sudo apt-get update

$ sudo apt-get install joystick

$ jstest --normal /dev/input/js0

(on that line you may have to try js0, js1, js2, etc. to find your controller - and if you plug and unplug devices in different orders they'll get different assignments)

Once you've located where your desired controller is mounting, we need to calibrate it! In the terminal again (example is if your controller mounted as /dev/input/js2):

$ jscal -c /dev/input/js2

The terminal will prompt you to do stuff with the controller. Do it and your controller will be calibrated. This calibration will carry over into BreakNeck running in Wine. Or at least is should.

2. Download joysticktester.exe to test your controller within Wine. You may discover that an axis is reversed, or that the buttons have enumerated differently than they're labeled. Make note of anything goofy and if it's an axis issue you should be able to just calibrate it in reverse by running the "jcal -c" command again and switching what you told it was the "maximum" and "minimum" limits.

3. If you're seeing your controller in Joysticktester within Wine. You're ready for the next step! If not, you may need to change the permissions for the /dev/input/js* files. Since those files are automatically created changing permissions on the files themselves won't stick - you need to add your main user to the "plugdev" group to automatically get read-write access to any js files the operating system makes. You normally shouldn't need access to the /dev/input/event* files and if you do change the permissions it will screw up the controller names in Wine (for example if I change permissions on /dev/input/event4 - which is linked to /dev/input/js0 - then in BreakNeck it will stop reporting my controller as "Thrustmaster Pro Digital" and call it "/dev/input/event4" in the "Controls" setup. It will still WORK, mind you, but it shouldn't be necessary to do that.

4. Run your launch script and go to the "Controls" entry on the main menu in the game. You should see your controller, by name, listed under the options. Tell it the correct TYPE of controller (keyboard, wheel, joystick, etc.). You may notice the X,Y,Z axis settings are BLANK! Whatever you do, do NOT try to assign them within BreakNeck. Not only will it NOT work, it will disable the axis settings and you'll have to do a registry hack to fix it. You CAN, however, change button assignments without worry. Some buttons, though, may be dead - but if you did the Joysticktester.exe test you already knew that.

5. AXIS FIX - if for some reason you still can't steer and or your gas/brake doesn't work or if you accidentally tried to assign an axis in the game controls settings you'll need to fix it manually. You'll also may need a working copy of the game running on a Windows system to do it! Ok, the simple fix is navigate to: ~/.wine/Windows/regedit.exe then navigate to:

HKEY_LOCAL_MACHINE\SOFTWARE\SYNETIC\HAND\V2\Input

If the "Input" folder doesn't exist, just create it. If you're lucky it's already there.

A. If the "Input" folder is already there you should have an entry for your controller by name. The "value" string will be a long sequence of binary number data. For a Wheel controller the first two sets should be "02 01" so if they are "00 00" just edit them and your controller should now work.

B. If the "Input" folder is missing, or has no entries in it, you'll need the data from a working Windows machine. Using Regedit get the string data. You can just "export" the Input key and then "import" it to your Wine registry and that should fix it.

LAUNCH FROM XBMC (optional)

I'm setting this up on my Home Theater PC so I want to be able to launch the game from inside my media center interface. I installed the "Launcher" programs plugin from the SVN repository and created a launcher pointing to my custom script. Works beautifully!

Happy Racing!

No comments: