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
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
/* various code that was replicated in *main.c */
|
||||
|
||||
#include "hack.h"
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -378,11 +379,7 @@ boolean resuming;
|
||||
if (g.multi >= 0 && g.occupation) {
|
||||
#if defined(MICRO) || defined(WIN32)
|
||||
abort_lev = 0;
|
||||
#ifdef NEW_KEYBOARD_HIT
|
||||
if (keyboard_hit()) {
|
||||
#else
|
||||
if (kbhit()) {
|
||||
#endif
|
||||
if ((ch = pgetchar()) == ABORT)
|
||||
abort_lev++;
|
||||
else
|
||||
@@ -440,8 +437,6 @@ boolean resuming;
|
||||
#ifdef MAIL
|
||||
ckmailstatus();
|
||||
#endif
|
||||
fuzzer_check();
|
||||
|
||||
rhack((char *) 0);
|
||||
}
|
||||
if (u.utotype) /* change dungeon level */
|
||||
@@ -589,8 +584,6 @@ newgame()
|
||||
{
|
||||
int i;
|
||||
|
||||
fuzzer_auto_start();
|
||||
|
||||
#ifdef MFLOPPY
|
||||
gameDiskPrompt();
|
||||
#endif
|
||||
@@ -930,78 +923,4 @@ const char *opts;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* fuzzer_toggle() toggles fuzzer state */
|
||||
void
|
||||
fuzzer_toggle()
|
||||
{
|
||||
if (iflags.debug_fuzzer)
|
||||
fuzzer_stop();
|
||||
else
|
||||
fuzzer_start();
|
||||
}
|
||||
|
||||
/* fuzzer_check() is called prior to rhack(0) to allow the fuzzer to
|
||||
* check if it should stop and to allow it to reseed the game.
|
||||
*/
|
||||
void
|
||||
fuzzer_check()
|
||||
{
|
||||
if (iflags.debug_fuzzer)
|
||||
{
|
||||
unsigned long seed;
|
||||
if (g.moves >= iflags.fuzzer_stop_and_save) {
|
||||
iflags.fuzzer_saving = TRUE;
|
||||
dosave0();
|
||||
exit_nhwindows("Goodbye from the fuzzer...");
|
||||
fuzzer_stop();
|
||||
nh_terminate(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
seed = rul();
|
||||
set_random(seed, rn2);
|
||||
fuzzer_log(LOG_MINIMAL, "SEED:%ld:%lu\n", g.moves, seed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* fuzzer_auto_start is called when creating a new game to allow
|
||||
* the fuzzer to start itself.
|
||||
*/
|
||||
void
|
||||
fuzzer_auto_start()
|
||||
{
|
||||
if (iflags.fuzzer_auto_start) {
|
||||
unsigned long seed;
|
||||
nhassert(!iflags.debug_fuzzer);
|
||||
fuzzer_start();
|
||||
seed = rul();
|
||||
set_random(seed, rn2);
|
||||
fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", g.moves, seed);
|
||||
}
|
||||
}
|
||||
|
||||
/* fuzzer_msg_history is called during save file recovery to allow
|
||||
* the fuzzer to snoop the messages being recovered. The fuzzer
|
||||
* saves a seed as a message in save files and this is the mechanism
|
||||
* used to recover that seed if the fuzzer is being auto started.
|
||||
*/
|
||||
boolean
|
||||
fuzzer_msg_history(msg)
|
||||
const char * msg;
|
||||
{
|
||||
long saved_moves;
|
||||
unsigned long saved_seed;
|
||||
if (sscanf(msg, "SEED:%ld:%lu", &saved_moves, &saved_seed) == 2) {
|
||||
nhassert(saved_moves == g.moves);
|
||||
if (iflags.fuzzer_auto_start) {
|
||||
fuzzer_start();
|
||||
set_random(saved_seed, rn2);
|
||||
fuzzer_log(LOG_MINIMAL, "START:%ld:%lu\n", g.moves, saved_seed);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
/*allmain.c*/
|
||||
|
||||
@@ -2516,8 +2516,7 @@ recalc_mapseen()
|
||||
struct cemetery *bp, **bonesaddr;
|
||||
struct trap *t;
|
||||
unsigned i, ridx;
|
||||
int x, y, ltyp, count;
|
||||
unsigned int atmp;
|
||||
int x, y, ltyp, count, atmp;
|
||||
|
||||
/* Should not happen in general, but possible if in the process
|
||||
* of being booted from the quest. The mapseen object gets
|
||||
|
||||
@@ -854,7 +854,7 @@ static struct tm *NDECL(getlt);
|
||||
/* Sets the seed for the random number generator */
|
||||
#ifdef USE_ISAAC64
|
||||
|
||||
void
|
||||
static void
|
||||
set_random(seed, fn)
|
||||
unsigned long seed;
|
||||
int FDECL((*fn), (int));
|
||||
@@ -865,7 +865,7 @@ int FDECL((*fn), (int));
|
||||
#else /* USE_ISAAC64 */
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
static void
|
||||
set_random(seed, fn)
|
||||
unsigned long seed;
|
||||
int FDECL((*fn), (int)) UNUSED;
|
||||
@@ -917,7 +917,7 @@ int FDECL((*fn), (int));
|
||||
{
|
||||
/* only reseed if we are certain that the seed generation is unguessable
|
||||
* by the players. */
|
||||
if (has_strong_rngseed && !iflags.debug_fuzzer)
|
||||
if (has_strong_rngseed)
|
||||
init_random(fn);
|
||||
}
|
||||
|
||||
@@ -1108,9 +1108,6 @@ phase_of_the_moon() /* 0-7, with 0: new, 4: full */
|
||||
register struct tm *lt = getlt();
|
||||
register int epact, diy, goldn;
|
||||
|
||||
if(iflags.debug_fuzzer)
|
||||
return rn2(8);
|
||||
|
||||
diy = lt->tm_yday;
|
||||
goldn = (lt->tm_year % 19) + 1;
|
||||
epact = (11 * goldn + 18) % 30;
|
||||
@@ -1125,9 +1122,6 @@ friday_13th()
|
||||
{
|
||||
register struct tm *lt = getlt();
|
||||
|
||||
if(iflags.debug_fuzzer)
|
||||
return rn2(30);
|
||||
|
||||
/* tm_wday (day of week; 0==Sunday) == 5 => Friday */
|
||||
return (boolean) (lt->tm_wday == 5 && lt->tm_mday == 13);
|
||||
}
|
||||
@@ -1135,8 +1129,7 @@ friday_13th()
|
||||
int
|
||||
night()
|
||||
{
|
||||
register int hour = (iflags.debug_fuzzer ? (g.moves / 1000) % 24 :
|
||||
getlt()->tm_hour);
|
||||
register int hour = getlt()->tm_hour;
|
||||
|
||||
return (hour < 6 || hour > 21);
|
||||
}
|
||||
@@ -1144,10 +1137,7 @@ night()
|
||||
int
|
||||
midnight()
|
||||
{
|
||||
register int hour = (iflags.debug_fuzzer ? (g.moves / 1000) % 24 :
|
||||
getlt()->tm_hour);
|
||||
|
||||
return (hour == 0);
|
||||
return (getlt()->tm_hour == 0);
|
||||
}
|
||||
|
||||
/* strbuf_init() initializes strbuf state for use */
|
||||
@@ -1229,38 +1219,4 @@ strbuf_t *strbuf;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_array_t *
|
||||
ptr_array_new(max_length)
|
||||
size_t max_length;
|
||||
{
|
||||
size_t esize = max_length * sizeof(void *);
|
||||
ptr_array_t * a = (ptr_array_t *) malloc(sizeof(ptr_array_t) + esize);
|
||||
a->elements = (void **)(a + 1);
|
||||
a->length = 0;
|
||||
a->max_length = max_length;
|
||||
memset(a->elements, 0, esize);
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
ptr_array_free(a)
|
||||
ptr_array_t * a;
|
||||
{
|
||||
size_t i;
|
||||
|
||||
nhassert(a->length <= a->max_length);
|
||||
|
||||
for(i = 0; i < a->length; i++)
|
||||
if(a->elements[i])
|
||||
free(a->elements[i]);
|
||||
|
||||
for (i = a->length; i < a->max_length; i++) {
|
||||
nhassert(a->elements[i] == NULL);
|
||||
if(a->elements[i])
|
||||
free(a->elements[i]);
|
||||
}
|
||||
|
||||
free(a);
|
||||
}
|
||||
|
||||
/*hacklib.c*/
|
||||
|
||||
74
src/pline.c
74
src/pline.c
@@ -572,78 +572,4 @@ VA_DECL(const char *, str)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* nhassert_failed is called when an nhassert's condition is false */
|
||||
void
|
||||
nhassert_failed(filepath, line)
|
||||
const char * filepath;
|
||||
int line;
|
||||
{
|
||||
const char * filename;
|
||||
|
||||
/* attempt to get filename from path. TODO: we really need a port provided
|
||||
* function to return a filename from a path */
|
||||
filename = strrchr(filepath, '/');
|
||||
filename = (filename == NULL ? strrchr(filepath, '\\') : filename);
|
||||
filename = (filename == NULL ? filepath : filename + 1);
|
||||
|
||||
impossible("nhassert failed in file '%s' at line %d", filename, line);
|
||||
}
|
||||
|
||||
static FILE * g_fuzzer_log_file = NULL;
|
||||
static int g_fuzzer_log_level = LOG_MINIMAL;
|
||||
|
||||
/* fuzzer_start() starts the fuzzer opening the fuzzer log file */
|
||||
void
|
||||
fuzzer_start()
|
||||
{
|
||||
if (!iflags.debug_fuzzer) {
|
||||
const char * fq_replay;
|
||||
|
||||
iflags.debug_fuzzer = TRUE;
|
||||
iflags.fuzzer_auto_start = FALSE;
|
||||
|
||||
nhassert(g_fuzzer_log_file == NULL);
|
||||
fq_replay = fqname("fuzzer.log", SAVEPREFIX, 0);
|
||||
|
||||
g_fuzzer_log_file = fopen(fq_replay, "w");
|
||||
}
|
||||
}
|
||||
|
||||
/* fuzzer_stop() stops the fuzzer and close the fuzzer log file */
|
||||
void
|
||||
fuzzer_stop()
|
||||
{
|
||||
if (iflags.debug_fuzzer) {
|
||||
if(g_fuzzer_log_file != NULL) {
|
||||
fclose(g_fuzzer_log_file);
|
||||
g_fuzzer_log_file = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fuzzer_log() is used to place messages in the file 'fuzzer.log'. This
|
||||
* log is the primary tool for monitoring fuzzer activity and tracking down
|
||||
* issues that the fuzzer is able to reproduce.
|
||||
*/
|
||||
void
|
||||
fuzzer_log
|
||||
VA_DECL2(int, lvl, const char *, str)
|
||||
{
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
|
||||
if (!g_fuzzer_log_file)
|
||||
return;
|
||||
|
||||
if (iflags.verbose_logging_start != 0 &&
|
||||
g.moves >= iflags.verbose_logging_start)
|
||||
g_fuzzer_log_level = LOG_VERBOSE;
|
||||
|
||||
if (lvl <= g_fuzzer_log_level)
|
||||
Vfprintf(g_fuzzer_log_file, str, VA_ARGS);
|
||||
|
||||
VA_END();
|
||||
}
|
||||
|
||||
|
||||
/*pline.c*/
|
||||
|
||||
@@ -1509,8 +1509,6 @@ NHFILE *nhfp;
|
||||
if (nhfp->fieldlevel)
|
||||
sfi_str(nhfp, msg, "msghistory", "msg", msgsize);
|
||||
msg[msgsize] = '\0';
|
||||
if(fuzzer_msg_history(msg))
|
||||
continue;
|
||||
putmsghistory(msg, TRUE);
|
||||
++msgcount;
|
||||
}
|
||||
|
||||
29
src/rnd.c
29
src/rnd.c
@@ -56,21 +56,10 @@ int FDECL((*fn), (int));
|
||||
(int) sizeof seed);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
rul()
|
||||
{
|
||||
unsigned long value;
|
||||
|
||||
value = (unsigned long) isaac64_next_uint64(&rnglist[CORE].rng_state);
|
||||
fuzzer_log(LOG_VERBOSE, "RANDOM:%lu\n", value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static int
|
||||
RND(int x)
|
||||
{
|
||||
return (rul() % x);
|
||||
return (isaac64_next_uint64(&rnglist[CORE].rng_state) % x);
|
||||
}
|
||||
|
||||
/* 0 <= rn2(x) < x, but on a different sequence from the "main" rn2;
|
||||
@@ -80,8 +69,6 @@ int
|
||||
rn2_on_display_rng(x)
|
||||
register int x;
|
||||
{
|
||||
if (iflags.debug_fuzzer)
|
||||
return rn2(x);
|
||||
return (isaac64_next_uint64(&rnglist[DISP].rng_state) % x);
|
||||
}
|
||||
|
||||
@@ -107,20 +94,6 @@ register int x;
|
||||
seed *= 2739110765;
|
||||
return (int)((seed >> 16) % (unsigned)x);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
rul()
|
||||
{
|
||||
#if defined(LINT) && defined(UNIX)
|
||||
return (unsigned long) rand();
|
||||
#else /* LINT */
|
||||
#if defined(UNIX) || defined(RANDOM)
|
||||
return (unsigned long) Rand();
|
||||
#else
|
||||
return (unsigned long) (Rand() >> 3);
|
||||
#endif /* defined(UNIX) || defined(RANDOM) */
|
||||
#endif /* LINT */
|
||||
}
|
||||
#endif /* USE_ISAAC64 */
|
||||
|
||||
/* 0 <= rn2(x) < x */
|
||||
|
||||
21
src/save.c
21
src/save.c
@@ -132,7 +132,7 @@ dosave0()
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
HUP if (!iflags.debug_fuzzer && iflags.window_inited) {
|
||||
HUP if (iflags.window_inited) {
|
||||
nh_uncompress(fq_save);
|
||||
nhfp = open_savefile();
|
||||
if (nhfp) {
|
||||
@@ -1225,25 +1225,6 @@ NHFILE *nhfp;
|
||||
}
|
||||
++msgcount;
|
||||
}
|
||||
/* If the fuzzer is stopping and saving, save a seed as a message.
|
||||
In 3.7, we will modify the save file format and save the seed
|
||||
directly in the saved game state. */
|
||||
if (iflags.fuzzer_saving) {
|
||||
char message[BUFSIZ];
|
||||
unsigned long seed = rul();
|
||||
|
||||
sprintf(message, "SEED:%ld:%lu", g.moves, seed);
|
||||
fuzzer_log(LOG_MINIMAL, "STOP:%ld:%lu\n", g.moves, seed);
|
||||
msglen = strlen(message);
|
||||
if (nhfp->structlevel) {
|
||||
bwrite(nhfp->fd, (genericptr_t) &msglen, sizeof msglen);
|
||||
bwrite(nhfp->fd, (genericptr_t) message, msglen);
|
||||
}
|
||||
if (nhfp->fieldlevel) {
|
||||
sfo_int(nhfp, &msglen, "msghistory", "msghistory_length", 1);
|
||||
sfo_str(nhfp, message, "msghistory", "msg", msglen);
|
||||
}
|
||||
}
|
||||
if (nhfp->structlevel)
|
||||
bwrite(nhfp->fd, (genericptr_t) &minusone, sizeof (int));
|
||||
if (nhfp->fieldlevel)
|
||||
|
||||
@@ -3762,7 +3762,7 @@ struct opvar *mc;
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
if (levl[x][y].lit == (unsigned int) lit)
|
||||
if (levl[x][y].lit == lit)
|
||||
selection_setpoint(x, y, ret, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1140,10 +1140,10 @@ struct monst *mtmp;
|
||||
sent out of his room (caller might resort to goodpos() if
|
||||
we report failure here, so this isn't full prevention) */
|
||||
if (mtmp->isshk && inhishop(mtmp)) {
|
||||
if (levl[x][y].roomno != (unsigned char) ESHK(mtmp)->shoproom)
|
||||
if (levl[x][y].roomno != ESHK(mtmp)->shoproom)
|
||||
return FALSE;
|
||||
} else if (mtmp->ispriest && inhistemple(mtmp)) {
|
||||
if (levl[x][y].roomno != (unsigned char) EPRI(mtmp)->shroom)
|
||||
if (levl[x][y].roomno != EPRI(mtmp)->shroom)
|
||||
return FALSE;
|
||||
}
|
||||
/* current location is <xx,yy> */
|
||||
|
||||
@@ -521,9 +521,6 @@ static void NDECL(hup_void_ndecl);
|
||||
static void FDECL(hup_void_fdecl_int, (int));
|
||||
static void FDECL(hup_void_fdecl_winid, (winid));
|
||||
static void FDECL(hup_void_fdecl_constchar_p, (const char *));
|
||||
#ifdef NEW_KEYBOARD_HIT
|
||||
static boolean NDECL(hup_keyboard_hit);
|
||||
#endif
|
||||
|
||||
static struct window_procs hup_procs = {
|
||||
"hup", 0L, 0L, hup_init_nhwindows,
|
||||
@@ -571,9 +568,6 @@ static struct window_procs hup_procs = {
|
||||
hup_void_ndecl, /* status_finish */
|
||||
genl_status_enablefield, hup_status_update,
|
||||
genl_can_suspend_no,
|
||||
#ifdef NEW_KEYBOARD_HIT
|
||||
hup_keyboard_hit
|
||||
#endif
|
||||
};
|
||||
|
||||
static void FDECL((*previnterface_exit_nhwindows), (const char *)) = 0;
|
||||
@@ -628,14 +622,6 @@ hup_nhgetch(VOID_ARGS)
|
||||
return '\033'; /* ESC */
|
||||
}
|
||||
|
||||
#ifdef NEW_KEYBOARD_HIT
|
||||
static boolean
|
||||
hup_keyboard_hit(VOID_ARGS)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*ARGSUSED*/
|
||||
static char
|
||||
hup_yn_function(prompt, resp, deflt)
|
||||
|
||||
Reference in New Issue
Block a user