Starcraft on VirtualBox (and Hamachi)

Rationale

Starcraft on Wine is horribly slow due to the missing DIB engine.

Handling DIBs is a crucial component when it comes to fast 2D drawing. Other games like Age of Empires and even applications like Adobe Photoshop are affected by this weakness in Wine.

Work on this has started last year as a Summer of Code program, but progress has slowed down recently.

All in all I guess we won’t get a usable implementation within the next few years except if another dedicated effort is spent on it.

Enter VirtualBox

Luckily another solution has come up recently: Sun’s VirtualBox virtualization product is free (as in beer and freedom), easy to use and works well enough with Starcraft.

Here’s my basic setup: VirtualBox 3.0.0 (in beta state right now but so far it hasn’t crashed on me) with guest additions, Windows XP and Starcraft Brood War 1.16.1.

I have enabled DirectDraw acceleration and bridging as network mode in VirtualBox. Both are simple point-and-click settings; you need to make sure the vboxnetflt module is loaded, though.

All of Starcraft is usable and very importantly fast.

Resolution issues

Update: You can just use VBoxSDL to start your VM in proper fullscreen mode without jumping through the hoops below. Makes it much more convenient and reliable.

VirtualBox does not have a real full-screen mode. With the guest additions you’re able to get a Desktop that resizes automatically to fit, but fixed resolutions (Starcraft uses 640×480) will not be scaled up to fill the VirtualBox window or the whole screen.

I have tried XRandR but it just made the viewport smaller which is worse than useless.

The kludge here is to copy over your X config, remove all resolutions except for 640×480 and start a new X server. I cannot go into the full detail here but it boils down to this:

xinit /home/sky/scripts/xinitrc.2 -display :1 \
  -- :1 -ac -config xorg.conf.lowres

Put in some lightweight window manager or VirtualBox itself at the end of xinitrc.2.

After that just use VirtualBox as you have before and switch to full screen.

You should be ready to get the full experience of playing Starcraft now!

Bonus: Hamachi integration

Hamachi is a proprietary cross-platform VPN solution that is also beginner-friendly and gratis. It works well with my VirtualBox setup, too.

However the latest version (1.0.3.0) does seem to have some problems with UDP networking.

Downgrading to 1.0.1.4 helped, and I was even able to play Starcraft via a VPN. Don’t forget to turn off the helpful Windows firewall least it might interfere with your network.

Did this post help you?

If yes, then I’d like to know about it. Please also tell me about other games that work or don’t work with this setup.

If you’re really happy about it you may also send me a gift.

Partial MP3 decoder in Haskell

Here’s a partially conforming MP3 decoder in Haskell.

It looks pretty clean even to me, not being a Haskell programmer.

Who’s up for it in Common Lisp? :)

Hard Disk Sentinel

HDSentinel is an utility that interprets the SMART information of your hard disk drives. Their flagship product is an extensive GUI tool for Win32, but they also have a small command-line application for GNU/Linux.

It was recently uploaded to ArchLinux AUR and I gave it a whirl.

Its output for one of my disks claimed it to be close to failure:

HDD Device  2: /dev/sda
HDD Model ID : ST3160023A
HDD Serial No: 5JS2NX0R
HDD Revision : 3.06
HDD Size     : 152628 MB
Interface    : IDE/ATA
Temperature  : 42 °C
Health       : 13 %
Performance  : 100 %
Power on time: 658 days, 7 hours
Est. lifetime: 19 days

The theory behind HDSentinel seems sound, so I’m looking forward to see whether the prediction will hold.

Using Finance::Quote to watch exchange rates

Since I’m often receiving payments in USD I need to keep track of the USD/EUR exchange rates.

I don’t want to run any GUI apps for that though or visit web sites, so I just slightly adapted the Finance::Quote Perl module’s simple example to do what I need:

#!/usr/bin/perl
 
use Finance::Quote;
 
$q = Finance::Quote->new;
$q->timeout(60);
 
print $q->currency("USD","EUR")."\n";

A functional interface for trivial queries like that would be nice in any case. Finance::Quote has one but it’s deprecated; maybe the authors are Java zealots.

Trimming silence at the beginning and end of an audio file

Here’s a simple shell script that uses the amazing Ecasound to remove any silence from the beginning and end of an audio file:

#!/bin/sh
#
# from http://osdir.com/ml/audio.ecasound.general/2005-08/msg00002.html
#
# description: removes silence from the beginning and the end
#              of a file
# version: 20050807-1
# usage: ecatrimsilence.sh <inputfile>
 
tmp=ecatrimsilence-tmp.wav
 
if test -e "$tmp" ; then
  echo "error: temp file $tmp exists, unable to continue..."
  exit 1
fi
 
if test ! -e "$1" ; then
  echo "error: input file $1 does not exist, unable to continue..."
  exit 2
fi
 
format=`ecalength -sf "$1"`
 
echo "Trimming file ${1}."
echo "Removing silence at the end..."
ecasound -q -f:${format} -i reverse,"${1}" -o "${tmp}" -ge:1,0,0 -b:256
rm -f "${1}"
echo "Removing silence at the beginning..."
ecasound -q -f:${format} -i reverse,"${tmp}" -o "${1}" -ge:1,0,0 -b:256
rm -f "${tmp}"
echo "Done."
</inputfile>

I know some GUI programs that offer this functionality (Audacity, for example), but no other command-line tool.

Do you?

Unicode nickname support in UnrealIRCd

A recent release of UnrealIRCd has brought us support for some latin codepages and even mulitbyte encodings. Unicode, however, is not included, so that it looks a bit like a kludge.

But there’s a comprehensive discussion along with patches for better codepage support in the project’s bug tracker. Unfortunately, some of the patches are not done right, and the rest of them are a bit, uh, stale.

This procedure worked for me:

  1. Get UnrealIRCd 3.2.5 (3.2.x might work, too)
  2. Patch with unreal3.2.5.cvs.codepages-2.diff (allowed fuzz of five or so)
  3. Edit src/modules/Makefile.in manually (the patch was rejected here for me), adding m_names.so m_codepage.so to R_MODULES and COMMANDS.
  4. To allow full UTF8 nick names, change the conditional in src/modules/m_nick.c around line 150 to read:
            /* For a local clients, do proper nickname checking via do_nick_name()
             * and reject the nick if it returns false.
             * For remote clients, do a quick check by using do_remote_nick_name(),
             * if this returned false then reject and kill it. -- Syzop
             */
     
            if (!do_remote_nick_name(nick)) /* just do some basic checking */
            {

    That way you still won’t have

    \xA0!+%@&~#$:'\"?*,.

    but I guess this is a limitation of the IRC protocol.

    After that you should be ready to run ./Config && make, and set up your unrealircd.conf. It’s best to also enabled UTF-8 as the default in codepage.conf.

    Happy hacking!

Poor man’s ALSA sound server

I’m currently visiting my family, and an inevitable part of it is playing some good old games with my brothers. The hardware situation here is a bit peculiar, though; I need to play on two different machines, and only one of them has speakers.

Those speakers are built-in, too, so I can’t change them easily.
No problem, there’s ESD, right? Well. The Enlightened Sound Daemon might have deserved its name when it was released, but since then a bunch of years have passed and it didn’t show acceptable quality when I tried it here.

PulseAudio to the rescue! This modern solution runs even on Microsoft Windows (although not on the 9x series, it seems), has dead simple GUI tools and is the best thing since sliced bread. A real sports car.
Except, for some unknown reason, I couldn’t get it to work on one of the machines in question. No sliced bread for me, I guess.

But then I came across a real slick solution in the ALSA wiki: a sound server using Netcat and the out-of-the-box ALSA utilities aplay and arecord.

Setup is as simple as:

# on the server:
nc -u -l -p 9999 | aplay
 
# on the client
arecord -t wav -f cd | nc -u SERVER 9999

Now just set your recording source via alsamixer -Vc to “Mix” and adjust the output volume levels on client, server and speaker.

Made me slap my head ’cause I didn’t think of it myself.

A minimalistic web site compiler

The setup of small non-dynamic web sites is an often recurring task. Unfortunately, there’s a lot of repeated content, most of it in the header of the sites that doesn’t change except for the title.

SSI doesn’t really help because its syntax is clumsy and the files are compiled again on each request. It also needs to be enabled on the target host.

A solution that compiles standard HTML from templates is best for performance and portability. It’s possible to use on of the many HTML template toolkits out there, but why bother? All I want is a standardized header and footer and a page title varying with each HTML file.

So let’s do just that:

#!/bin/bash
set -e
 
OUTDIR=./build
 
mkdir -p "$OUTDIR"
 
# wrap header and footer, set <title> from first line of body
for f in {page1,page2,page3}.html; do
  TITLE=$(echo $(head -n1 $f) | perl -p -e 's/^TITLE: *(.*?)$/$1/')
 
  (sed "s|TITLE|$TITLE|" header.html ;
   sed '1d' $f;
   cat footer.html) > "$OUTDIR/$f"
done
 
# auxiliary files
for f in logo.png default.css; do
  cp $f "$OUTDIR/$f"
done
</title>

The files that get wrapped into header and footer need to set their title on the first line:

TITLE: my page title
<p>So this is it...</p>

If you don’t like Perl, you can also whip up a sed or awk script in its place.

Classical hack: Apache httpd as CMS

In search of a light-weight content management system, I came across this KISS solution.

It’s obviously not really a CMS that one would install for a customer, but it’s a nice thing
for your typical software projects: a flock of small pages gathering around the most important thing,
namely the downloads.

Well done!