Win32 locales fix
Author Ray Chason
Download link
Bilious PatchDB 313

W343-4 designates a bug that affects the Microsoft Windows version of NetHack 3.4.3. It occurs when the keyboard handler nhraykey.dll is loaded and causes minor problems with the keyboard when performing certain acts, such as locking a door.

A patch is available to fix this bug at the Bilious Patch Database, here; it also fixes W343-3. The DevTeam lists this bug as fixed in the next release.

Nature of the bug Edit

Bug W343-4 affects all users of NetHack on Windows who use the text mode user interface and the keyboard handler nhraykey.dll.

After performing any act that takes multiple turns and can be interrupted, such as locking a door, the game seems to stop responding. It is necessary to press a key to get it to continue.

This bug is an annoyance rather than a showstopper, but has perhaps slowed the acceptance of nhraykey.dll, despite its improved handling of non-USA (and especially non-English) keyboards.

Cause of the bug Edit

Nhraykey.dll seeks to read both keyboard and mouse input, while translating the keystrokes according to the user's configured localization settings. The Win32 API does not make this task easy: ReadConsole translates the keystrokes, but ignores the mouse, while ReadConsoleInput reads the mouse, but does not translate the keystrokes. Nhraykey.dll solves this problem by calling PeekConsoleInput first, and then calling ReadConsole to retrieve any keystrokes and ReadConsoleInput to clear out anything else.

The complication is that there can be a keystroke, but the call to ReadConsole may still block, keeping the mouse from responding, because the key was a dead key. Nhraykey.dll prevents the blocking by pushing a bogus key event on the queue before calling ReadConsole; if nothing else, the ReadConsole call will return the bogus key.

The bogus key is supposed to be ignored when it is read. The bug is that one particular function, NHkbhit(), doesn't do this. It returns a true status, indicating that a real key is available, and allmain.c then calls Getchar() to retrieve this nonexistent key. The user must eventually provide a real key for Getchar() to return.

Versions affected Edit

The only versions affected are NetHack 3.4.2 and NetHack 3.4.3.

Patch Edit

A patch is available to fix this bug, as this post to No binaries or variants other than Spanish NetHack are known to incorporate it.

The fix is to add a check for the bogus key in NHkbhit(). If found, the bogus key is discarded and the queue is queried again.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.