A Weird Imagination

Emulating Xbox controllers using GameCube controllers

The problem

I previously wrote about making different controllers act like Xbox 360 controllers. While it's a useful general-purpose solution, it's can be a bit clunky to have to explicitly set the mappings for each controller. More importantly, the remapping leaves the original controller entries in /dev/input/, although they don't do anything, and some games1 assume that the four players are controlled by the first four controllers. This is no longer true if js0 is the real first controller and js1 is the copy made by xboxdrv to look like an Xbox 360 controller. Or, worse, if js0-js3 are the four real controllers and js4-js7 are the ones we want the game to actually use.

The specific reason I'm remapping the controllers, is that the gamepads I'm actually using are GameCube controllers connected via the Nintendo GameCube controller Adapter for Wii U, which connects up to four GameCube controllers to a USB port. wii-u-gc-adapter makes them usable as controllers, but they appear different enough from Xbox 360 controllers that remapping them is necessary for most games.

The solution

Just build and use the version of wii-u-gc-adapter in my feature/mimic-xpad branch and your GameCube controllers will show up as Xbox controllers.

The details

Read more…

Encrypted files in Vim

Posted in

The problem

There's a handy Vim plugin openssl.vim that allows you to easily edit encrypted files with Vim simply by giving the file an extension like .aes. Then Vim will ask for a password upon loading and saving the file in order to decrypt and encrypt it with openssl.

Unfortunately, the plugin was last updated in 2008 and makes some assumptions about openssl's defaults which are no longer valid. The most pressing issue is that the plugin now outputs a warning message when encrypting. By itself, that's worrisome, but, worse, that warning message gets output into the file along with the ciphertext. Needless to say, the resulting file cannot be decrypted without manually removing the warning text.

The solution

Simply fixing the options the script passes to openssl is a good start, but I also wanted to make sure any files encrypted with the old settings could be decrypted. My updated openssl.vim1 does both in addition to fixing some other annoyances.

The details

Read more…

Timezones and scheduling tasks with at

The problem

My system for automatically posting future-dated blog posts mysteriously stopped working recently. The posts would appear if I manually published the blog, but not with the automatic scheduling mechanism.

The solution

In schedule_publish.sh, I changed the line

echo "$0" | at -q g $time


if [ "$(date -d "$time PST" +'%s')" -ge "$now" ]
    echo "$0" | at -q g -t "$(date +'%Y%m%d%H%M' -d "$time PST")"

(where "PST" is the timezone of this blog; adjust as appropriate for your blog). $now is initialized with

now="$(date +'%s')"

before the call to make publish to avoid a race condition.

The details

Read more…

Nvidia GLX not working

The problem

I recently replaced my old Nvidia graphics card with a newer one. Upon booting up, I ran glxgears to test that 3D graphics were working properly and got an error like

X Error of failed request:  BadWindow (invalid Window parameter)
 Major opcode of failed request:  155 (NV-GLX)
 Minor opcode of failed request:  4 ()
 Resource id in failed request:  0x1200003
 Serial number of failed request:  34
 Current serial number in output stream:  34

The solution

Either delete /etc/X11/xorg.conf or edit it and remove (or comment out) the "Files" section; that is, the lines

Section "Files"

Read more…

Emotional error messages

Posted in

Cowardly tar

$ tar c
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.

That's what the GNU implementation of tar says. For comparison, Debian includes FreeBSD's implementation of tar in the bsdtar package as the bsdtar command:

$ bsdtar c
bsdtar: no files or directories specified

Clingy lynx

In the text-only web browser lynx (not to be confused with links), if you press q to quit, it asks

Are you sure you want to quit? (y)

Most keys quit the program, but if you decide not to quit and press n for no, lynx shows the message


which goes away after a couple seconds allowing you to continue browsing.

Emulating Xbox controllers on Linux

Posted in

The problem

The Xbox 360 controller has become the defacto standard controller in PC gaming in recent years, likely due to both the popularity of the Xbox and the fact that the controller can easily be used with a computer. One downside of this is that some games assume you have one. If the game supports it and is running through Steam, then Steam's controller settings will let you use any controller, but that doesn't work for all games, and you might not be using Steam. The game that prompted this blog post actually does have Steam controller support promised in the future, but it's in early access and they are busy developing other parts of the game.1


The solution is xboxdrv, the userspace Xbox controller driver. In addition to supporting actual Xbox controllers, it can also simulate Xbox controllers based on inputs from other devices like a PlayStation controller or some less common controller.

Read more…

Read-only filesystem errors

Linux has a tendency to give very unhelpful error messages when it is unable to create a file. I previously blogged about a few different reasons Linux might report a disk is full, but all of the reasons included the disk actually not having space for more files. Yet another reason to get similar errors is if the partition is mounted readonly (ro):

$ mount | grep -F /usr
/dev/sdc2 on /usr type ext4 (ro,nodev,noatime,data=ordered)

mount without any options lists all of the mounted partitions along with their mount options.

Many programs will show a helpful error message:

$ touch test
touch: cannot touch ‘test’: Read-only file system

But some others won't:

rtorrent: Could not lock session directory: "./session/", held by "<error>".

That error is normally caused by ./session/rtorrent.lock not being writable due to being held by another process, but in this case it's not writable due to the filesystem being readonly. rtorrent doesn't distinguish the two.

For that reason, when running into weird behavior from a program on Linux, it's a good idea to check that the directories the program might try to write to are actually writable.

How not to fix USB HID errors

The error

I was having trouble with a USB joystick adapter (an EMS Playstation controller adapter, to be specific). When I plugged it in, it wouldn't work and checking dmesg showed the same error getting generated over and over again (at least once per second):

$ dmesg
[81700.968873] usbhid 6-1:1.0: can't add hid device: -71
[81700.968885] usbhid: probe of 6-1:1.0 failed with error -71
[81700.968986] usb usb6-port1: disabled by hub (EMI?), re-enabling...
[81700.968991] usb 6-1: USB disconnect, device number 53
[81701.208025] usb 6-1: new low-speed USB device number 54 using uhci_hcd
[81701.384866] usb 6-1: string descriptor 0 read error: -32

The wrong fix

I decided the sensible thing to do was to reload the driver:

$ sudo modprobe -r usbhid  # Bad idea, don't run this

Read more…

Fixing broken alternatives

The problem

Trying to install the python-numpy package in Debian Unstable ("Sid") I got the following error on the liblapack3 package (seen also in this bug):

$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 36 not upgraded.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up liblapack3 (3.5.0-4) ...
update-alternatives: error: alternative liblapack.so.3gf can't be slave of liblapack.so.3: it is a master alternative
dpkg: error processing package liblapack3 (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of python-numpy:
 python-numpy depends on liblapack3 | liblapack.so.3; however:
  Package liblapack3 is not configured yet.
  Package liblapack.so.3 is not installed.
  Package lapack3 which provides liblapack.so.3 is not installed.
  Package atlas3-base which provides liblapack.so.3 is not installed.
  Package liblapack3 which provides liblapack.so.3 is not configured yet.
  Package libatlas3-base which provides liblapack.so.3 is not installed.

The solution

Run the following command to fix the error:

$ sudo update-alternatives --remove-all liblapack.so.3gf

And then rerun the install:

$ sudo apt-get install -f

Read more…

Listing files into a file

Posted in

The problem

$ ls > file

doesn't do what you expect:

$ touch foo
$ touch bar
$ ls > filelist
$ cat filelist

You probably didn't expect, or want, filelist to be listed in filelist.

The solution

$ filelist=$(ls); echo "$filelist" >filelist

Read more…