Commit Graph

92 Commits

Author SHA1 Message Date
Dean Luick
8143d55d76 Create and use a snprintf wrapper in the core code
Use a wrapper around snprintf to consilidate all use, add
error checking, and remove gcc 9 warnings about not checking
the result.

Replace the prevous use of snprintf added to weapon.c with the
new scheme.

Update a second spot that has a gcc sprintf warning.  While
there, simplify the code.
2021-01-15 11:33:47 -06:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
Pasi Kallinen
43d331c4eb Nerf unicorn horn
Unicorn horns are just too good. Nerf it in similar way several
other variants have done: don't let it restore attribute loss.

This makes potion of restore ability more valuable, and the
int loss from the (nerfed) mind flayers matter more.
2020-04-15 22:45:47 +03:00
Pasi Kallinen
712f545119 Move, rename, and comment out unused function 2020-03-16 11:46:08 +02:00
Pasi Kallinen
88aa0793dc Allow flipping levels horizontally or vertically
When a special level is created, there's a chance it gets flipped
horizontally and/or vertically.

Add new level flags "noflip", "noflipx", and "noflipy" to prevent
flipping the level. Add a wiz-mode command #wizlevelflip to test
the flipping on current level - although this doesn't flip everything,
as level flipping is meant to happen during level creation.
2020-02-21 18:16:14 +02:00
nhmall
d6bc9f0bb3 fix inaccuracies in comment 2020-01-04 07:35:53 -05:00
PatR
730b67b838 add some bullet-proofing to tabexpand()
Include some bounds checking for tabexpand, but it assumes caller
passes a BUFSZ buffer rather than having that caller pass the actual
size.
2020-01-04 03:33:57 -08:00
nhmall
2a187c47c7 more warnings 2019-11-24 18:01:48 -05:00
nhmall
bcb627100b Merge branch 'paxed-lua-merged3' into paxed-lua-v2-merged 2019-11-06 12:56:21 -05:00
Pasi Kallinen
fd55d9118e Use lua for special level files
Game is playable, and should compile on linux and Windows.
Assumes you have a lua 5.3 library available.

Removes level compiler and associated files.
Replaces special level des-files with lua scripts.
Exposes some NetHack internals to lua:
 - des-table with commands to create special levels
 - nh-table with NetHack core commands
 - nhc-table with some constants
 - u-table with some player-specific data (u-struct)
 - selection userdata

Adds some rudimentary tests.

Adds new extended command #wizloadlua to run a specific script,
and #wizloaddes to run a specific level-creation script.

nhlib.lua is loaded for every lua script.

Download and untar lua:
  mkdir lib
  cd lib
  curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
  tar zxf lua-5.3.5.tar.gz

Then make nethack normally.
2019-11-06 18:43:20 +02:00
Bart House
97ca83fd02 Merge branch 'master' into NetHack-3.7
# Conflicts:
#	src/pline.c
#	sys/winnt/windmain.c
#	win/tty/topl.c
#	win/win32/scripts/fuzzer/longtest.bat
#	win/win32/scripts/fuzzer/restore.bat
#	win/win32/scripts/fuzzer/runtill.bat
2019-07-14 23:50:54 -07:00
Bart House
cd1b650fb7 Merge branch 'NetHack-3.6'
# Conflicts:
#	DEVEL/Developer.txt
#	include/config.h
#	include/decl.h
#	include/display.h
#	include/extern.h
#	include/global.h
#	include/hack.h
#	include/patchlevel.h
#	src/display.c
#	src/dothrow.c
#	src/makemon.c
#	src/monst.c
#	src/objnam.c
#	src/sp_lev.c
#	src/wield.c
#	src/zap.c
#	sys/share/pmatchregex.c
#	sys/winnt/Makefile.msc
2019-07-14 23:36:56 -07:00
Bart House
a607ea2b7f Revert "When fuzzing, use the number of moves as a proxy for the hour."
This reverts commit f75deae0bc.
2019-07-14 21:29:41 -07:00
Bart House
f7c956c35a Revert "Adding ptr_array data structure."
This reverts commit e665d3b850.
2019-07-14 21:12:59 -07:00
Bart House
4c1c247028 Revert "Fuzzer improvements."
This reverts commit 435f1c4626.
2019-07-14 21:10:39 -07:00
nhmall
0d34f43830 remove STATIC_DCL, STATIC_OVL, STATIC_VAR, STATIC_PTR from core 2019-07-14 17:24:58 -04:00
nhmall
ec1b77ff80 Merge branch 'NetHack-3.6' 2019-07-14 09:39:24 -04:00
Bart House
435f1c4626 Fuzzer improvements.
phase_of_moon and friday_13th determined using rn2() instead of local
time if fuzzing.  Don't reseed using init_random() if fuzzing.  Allow
set_random to be called outside of hacklib.  rn2_on_display_rng uses
rn2 if fuzzing so that we have a single source of random that we can
ensure is reproducible.  Implement rul() that returns a random unsigned
long.  Fix bug in fuzzer handling of ntposkey which would cause us to use
unitialized values for x and y.  Added command line arguments to allow
auto starting and stopping of fuzzer.  Add a logging facility for the
fuzzer to use to record activity.  Added some scripts used to automate
fuzzer testing on windows.
2019-07-14 00:20:09 -07:00
Bart House
e665d3b850 Adding ptr_array data structure. 2019-07-13 16:08:08 -07:00
nhmall
2e7655af40 Merge branch 'NetHack-3.6' part 2 2019-07-04 23:29:26 -04:00
nhmall
4fbfbb07b1 Merge branch 'NetHack-3.6' 2019-07-04 22:53:06 -04:00
Bart House
f75deae0bc When fuzzing, use the number of moves as a proxy for the hour.
Every 1000 moves simulates one hour.
2019-07-04 18:06:56 -07:00
nhmall
d52ab63f33 Merge branch 'NetHack-3.6.2' 2019-03-15 20:57:59 -04:00
PatR
ed55fa23f6 hacklib.c tidbit
Describe 'trimspaces()' more accurately.
2019-03-15 01:45:10 -07:00
nhmall
d36eaf8f99 Merge branch 'NetHack-3.6.2' 2019-01-30 23:12:15 -05:00
PatR
409343e8eb another warning fix
Only appeared when ISAAC64 was disabled.
2019-01-30 16:25:31 -08:00
nhmall
fd410148c5 Merge branch 'NetHack-3.6.2' 2019-01-29 07:27:56 -05:00
nhmall
457e4b68aa merge Alex's dual rng proposal with the isaac64 rng code and adjust
This is branched from Alex's hallu-rng-stability branch,
with two build corrections (detect.c, zap.c), and merged
with  the isaac64 branch that we have ready to go.

Alex's dual rng is supported by setting up the array
of multiple isaac64 contexts.

I stuck with Alex's approach of passing the rng function
name around as the parameter (rng or rn2_on_display_rng)
for the new additional parameter needed for
set_random(), init_random(), reseed_random(),
and init_isaac64().
2019-01-28 19:43:55 -05:00
nhmall
0aa4d62a2c detect rng seed strength at runtime based on algorithm not compile time based on platform features 2019-01-28 10:32:57 +01:00
nhmall
0a430cab11 every platform provides sys_random_seed() and SYS_RANDOM_SEED goes away 2019-01-28 10:32:57 +01:00
nhmall
6c114640f5 some system-specific adjustments for RNG routines
move some system-specific seed-related stuff from hacklib.c to
a system-specific source file and #define SYS_RANDOM_SEED to
utilize it during build.

Windows changes for random seed generation using
crypto next gen (CNG) api routines.

Corresponding vms changes due to disentangling of VMS and
unix when the unix seed bits got moved (untested).
2019-01-28 10:02:08 +01:00
Patric Mueller
f9433b2a87 integrate isaac64 into nethack
Also removed the float code from isaac64 as they are not used in
NetHack.
2019-01-28 10:02:08 +01:00
Patric Mueller
52d4b1a1aa reseed during level change to prevent deduction of rng state
For platforms that read from the system's random number generator,
reseed during level change, before the map of a new level is created and
after level creation has finished.
2019-01-28 10:02:00 +01:00
Patric Mueller
86d694c61b read rng seed from random number source device
Linux and BSD system have random number source devices that can be used
as source for a unguessable seed source.

Other platforms fall back to generate the seed with gettime().
2019-01-28 10:01:45 +01:00
Bart House
912886a73f First set of changes to move globals to instance_globals. 2018-12-19 20:00:35 -08:00
keni
d8c49ec9d1 Add updated copyright lines, part 1. 2018-04-25 15:00:13 -04:00
PatR
48af4fa259 static analyzer bit
I can't find the original message at the moment, but one of the things
that an analyzer complained about was the *s='\0' possibly assigning
to a Null pointer.  The superfluous test of 's' in the while condition
has fooled it into thinking that's possible when it's not.

if (s) {
  while (s && ...) {
    *s++ = ...
  }
  *s = '\0';
}
2018-02-17 18:54:52 -08:00
PatR
0bdbfaa580 strbuf cleanup
The expression '*cp-- = cp[-count]' is not valid C.  There's no sequence
point between the two references to 'cp', and the decrement side-effect
could occur before or after cp[-count] is resolved.

The functions were also using ANSI-style argument definitions.  The rest
is just reformatting.

It seems to me that the strbuf structure ought to have an allocation
size field in addition to the current length field.  Otherwise a string
which gets shortened will forget about the extra length available for
later expansion, potentially resulting in unnecessary reallocation.
2017-10-25 19:13:21 -07:00
Bart House
a588541a27 Win32GUI: Gather raw_print text and display it all in single dialog
Defined strbuf_t and related routines to support dynamically sized
strings. Modified strip_newline() to strip the last newline in a string
instead of the first.

Simplified splash window code using new strbuf_t.

Prior to exiting game, re-enable getreturn and call wait_synch() in
case there is buffered raw prints that must be displayed to user.
2017-10-25 10:34:27 +03:00
Pasi Kallinen
69f7a78dba Hilite Status: Improved
Allow defining multiple stops per field. Add hitpointbar.
2017-09-26 10:04:25 +03:00
PatR
964fd0fdbd dynamic format strings vulnerable to user input
This adds new utility routine strNsubst(), a more versatile version
of the existing strsubst(), that can replace the Nth occurrence of
a substring rather than just the first, and replaces all occurrences
if N is 0.

When working on vampire shape-shifting messages a few days ago I
noticed that a constructed pline/sprintf format was vulnerable to
the player giving the vampire a name with '%' in it and included
a fix for that.  This fixes two other instances of the same
vulnerability:  a monster with reflection triggering a floating
eye's gaze and the hero using a silver weapon against a silver-
hating monster.

I didn't do a lot of experimenting with the failure, just assigned
the name "foo%s" to the floating eye or the weapon.  The resulting
feedback for the relevant messages was garbled due to parameters
being substituted in the wrong place.  When that caused there to be
too few arguments to satisfy the format, the final message included
"null" for the missing one rather than triggering a crash while
trying to format something arbitrary from the stack.

I don't think these bugs provided sufficient user control to be
vulnerable to stack manipulation that does something naughty.

I found the dynamic format strings by searching for "%%".  There
may be others scattered around the code which don't have that as
an indicator....
2017-06-07 11:39:24 -07:00
Pasi Kallinen
680c8a542c Add key rebinding
This is a modified version of Jason Dorje Short's key rebinding
patch, and allows also binding special keys, such as the ones
used in getloc and getpos.

One of the ways to play NetHack on nethack.alt.org is via a HTML
terminal in browser. Unfortunately this means several ctrl-key
combinations cannot be entered, because the browser intercepts
those. Similar thing applies to some international keyboard layouts
on Windows. With this patch, the user can just rebind the command
to a key that works best for them.

I've tested this on Linux TTY, X11, and Windows TTY and GUI.
2016-10-05 20:04:56 +03:00
PatR
6fc21bfaa0 fix #H4492 - ing_suffix("throw") gave "throwwing"
The bug report assumed "you mime throwwing something" feedback
from 't-' was a typo, but 'throwwing' gets generated from 'throw'.
Change ing_suffix() not to double final 'w'.  Presumeably 'w' and 'y'
are exceptions because they're sometimes used as vowels.

Change 'strrchr()' to 'rindex()' like the rest of nethack.  Someday
those will need to be switched the other way around.

Add some missing bounds checking, although since ing_suffix() isn't
used for user-supplied strings, that's probably superfluous.
2016-08-23 19:37:42 -07:00
PatR
c4a9d6a45c newline handling
In light of the recent 'bad options' feedback issue where \r messed
up message display, try to to make newline handling be more consistent.
I'm sure there are lots of places that still handle \n manually, but
it's a start.
2015-12-25 21:54:01 -08:00
PatR
3ec592e3f1 fix bz60 and bz61 - meta char feedback
60: getpos() doesn't report the offending keystroke accurately when
rejecting M-something as a movement keystroke while moving the cursor;
61: typing M-N as a command keystroke produces
 |Unknown command 'M-
 |                 '.
where the '.' on the second line clobbers the top line of the map.

I can't reproduce the first one without extending the altmeta hack
[a run-time option to treat two char sequence ESC c as M-c] to getpos()
and nh_poskey(), which I've done for testing but am not including here.

I can't reproduce the second as it's described, but M-^J produces
 |Unknown command 'M-
 |'.--More--
and this fixes that, with a general fix that applies to any meta char.

The diffs include some cleanup/groundwork for maybe extending altmeta.
2015-12-15 03:22:39 -08:00
Pasi Kallinen
d195052796 Remove trailing whitespaces 2015-11-09 13:06:19 +02:00
PatR
68cb45c9fd str_end_is()
Move this small utility routine to hacklib.c where other such things
live and where it's feasible to find them if you need the functionality
elsewhere.
2015-10-31 17:13:26 -07:00
PatR
ad3af4efb2 hacklib.c formatting
hacklib.c took a beating in the reformatting, so clean it up.
A tweak to the anti-predictability hack in setrandom() is the only
change in the actual code.
2015-05-27 03:49:09 -07:00
Sean Hunt
1c081b1647 Remove stale version control lines. 2015-05-25 09:21:31 +09:00
Sean Hunt
97d6fade74 Reformat all C files.
I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
2015-05-09 13:43:16 -04:00