W343-4/Patch

From NetHackWiki
Jump to navigation Jump to search

This post to rec.games.roguelike.nethack describes a patch for NetHack 3.4.3 to fix bug W343-4, so that doors unlock correctly when nhraykey.dll is in use.

The complete thread can be found in the Wayback Machine's archive of Google Groups. Google Groups itself only sporadically allows reading of direct links to posts. This post contains a patch, and Google Groups' mangling of whitespace is a problem. The text below is recovered from the Internet Archive.

As recovered, the post has tabs converted to spaces. These are converted back to tabs, to give a patch that applies cleanly.

Path: intern1.nntp.aus1.giganews.com!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!tdsnet-transit!newspeer.tds.net!sn-xit-02!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
From: Ray Chason <long-defunct email address redacted>
Newsgroups: rec.games.roguelike.nethack
Subject: [PATCH] Fix for door-locking bug in nhraykey.dll
Date: Sat, 14 Feb 2004 18:53:46 -0500
Organization: Not Bloody Likely
Message-ID: <102td85k8jf1nf3@corp.supernews.com>
User-Agent: KNode/0.7.1
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
X-Windows-95: Where do you want to go today?
X-Windows-XP: All your base are belong to us.
X-Complaints-To: abuse@supernews.com
Lines: 63
Xref: intern1.nntp.aus1.giganews.com rec.games.roguelike.nethack:249583

This patch fixes a bug in nhraykey.c in which the keyboard stops responding 
after locking or unlocking a door.

--cut here--cut here--cut here--cut here--cut here--cut here--cut here--
*** nethack-3.4.3/sys/winnt/nhraykey.c.old	Sat Feb 14 18:39:20 2004
--- nethack-3.4.3/sys/winnt/nhraykey.c	Sat Feb 14 18:41:23 2004
***************
*** 537,554 ****
  			scan  = ir->Event.KeyEvent.wVirtualScanCode;
  			shiftstate = ir->Event.KeyEvent.dwControlKeyState;
  			vk = ir->Event.KeyEvent.wVirtualKeyCode;
! 			keycode = MapVirtualKey(vk, 2);
! 			if (is_altseq(shiftstate)) {
! 				if  (ch || inmap(keycode,vk)) altseq = 1;
! 				else altseq = -1;	/* invalid altseq */
! 			}
! 			if (ch || iskeypad(scan) || altseq) {
! 				done = 1;	    /* Stop looking         */
! 				retval = 1;         /* Found what we sought */
! 			} else {
! 				/* Strange Key event; let's purge it to avoid trouble */
  				ReadConsoleInput(hConIn,ir,1,&count);
  			}
  
  		}
  		else if ((ir->EventType == MOUSE_EVENT &&
--- 537,560 ----
  			scan  = ir->Event.KeyEvent.wVirtualScanCode;
  			shiftstate = ir->Event.KeyEvent.dwControlKeyState;
  			vk = ir->Event.KeyEvent.wVirtualKeyCode;
! 			if (scan == 0 && vk == 0) {
! 				/* It's the bogus_key.  Discard it */
  				ReadConsoleInput(hConIn,ir,1,&count);
  			}
+ 			else {
+ 				keycode = MapVirtualKey(vk, 2);
+ 				if (is_altseq(shiftstate)) {
+ 					if  (ch || inmap(keycode,vk)) altseq = 1;
+ 					else altseq = -1;	/* invalid altseq */
+ 				}
+ 				if (ch || iskeypad(scan) || altseq) {
+ 					done = 1;	    /* Stop looking         */
+ 					retval = 1;         /* Found what we sought */
+ 				} else {
+ 					/* Strange Key event; let's purge it to avoid trouble */
+ 					ReadConsoleInput(hConIn,ir,1,&count);
+ 				}
+ 			}
  
  		}
  		else if ((ir->EventType == MOUSE_EVENT &&
--cut here--cut here--cut here--cut here--cut here--cut here--cut here--

The problem occurs because NHkbhit() falsely returns true when the bogus_key 
is the next event to be read; the main code at allmain.c line 326 then 
calls Getchar() with no key waiting.  The patch changes NHkbhit to 
recognize the bogus_key (which has scan code and virtual key both set to 
zero) and discard it.

-- 
 --------------===============<[ Ray Chason ]>===============--------------
    This message was stage-managed by IBM.  So say Darl McBride and SCO.
                    Delendae sunt RIAA, MPAA et Windoze