Merge branch 'master' into NetHack-3.7

This commit is contained in:
nhmall
2019-07-14 09:57:32 -04:00
18 changed files with 517 additions and 40 deletions

View File

@@ -4,7 +4,7 @@
/* NetHack may be freely redistributed. See license for details. */
/* various code that was replicated in *main.c */
#define NEED_VARARGS
#include "hack.h"
#include <ctype.h>
@@ -441,6 +441,8 @@ boolean resuming;
#ifdef MAIL
ckmailstatus();
#endif
fuzzer_check();
rhack((char *) 0);
}
if (u.utotype) /* change dungeon level */
@@ -588,6 +590,8 @@ newgame()
{
int i;
fuzzer_auto_start();
#ifdef MFLOPPY
gameDiskPrompt();
#endif
@@ -927,4 +931,131 @@ const char *opts;
#endif
return;
}
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_toggle() toggles fuzzer state */
void
fuzzer_toggle()
{
if (iflags.debug_fuzzer)
fuzzer_stop();
else
fuzzer_start();
}
/* 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, level, 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 (level <= g_fuzzer_log_level)
Vfprintf(g_fuzzer_log_file, str, VA_ARGS);
VA_END();
}
/* 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)
{
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);
}
unsigned long 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) {
nhassert(!iflags.debug_fuzzer);
fuzzer_start();
unsigned long 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*/