fix #K4189 - dorecover() bug

Restoring was hiding unhidden mimics and if that chose an object
other than boulder of gold pieces, it called mkobj() before an
array used by that routine was initialized.  The result was warning
"rnd(0) attempted" when NH_DEVEL_STATUS wasn't set to 'released' or
divide by 0 crash if it was set to that.

Restore should not be catching up for lost time when unpacking a
save file into individual level files, and if it hadn't done that
it wouldn't hide mimics who aren't currently hidden.

In addition to avoiding that, this also moves the initialization of
the offending mkobj array sooner.

[3.6 didn't use that array so wasn't susceptible to this.  It is
hiding unhidden mimics during what should be a strictly bookkeeping
operation though.]
This commit is contained in:
PatR
2024-06-08 13:34:12 -07:00
parent d02028fe66
commit d7008f8fe5
3 changed files with 19 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1442 $ $NHDT-Date: 1717570484 2024/06/05 06:54:44 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1443 $ $NHDT-Date: 1717878584 2024/06/08 20:29:44 $
General Fixes and Modified Features
-----------------------------------
@@ -1954,6 +1954,8 @@ on medusa-4, Medusa and the downstairs were located in different chambers
on medusa-3 and medusa-4, Perseus's statue was located in a different chamber
from Medusa
omit "a" from "drowned in a limitless water" when drowning on Plane of Water
restoring a save file could trigger impossible "rnd(0) attempted" if it tried
to make an unhidden mimic hide an an object
Fixes to 3.7.0-x Platform and/or Interface Problems Exposed Via git Repository

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 hack.h $NHDT-Date: 1713334806 2024/04/17 06:20:06 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.253 $ */
/* NetHack 3.7 hack.h $NHDT-Date: 1717878594 2024/06/08 20:29:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.257 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2017. */
/* NetHack may be freely redistributed. See license for details. */
@@ -727,8 +727,9 @@ struct restore_info {
};
enum restore_stages {
REST_GSTATE = 1, /* restoring current level and game state */
REST_LEVELS = 2, /* restoring remainder of dungeon */
REST_GSTATE = 1, /* restoring game state + first pass of current level */
REST_LEVELS = 2, /* restoring remainder of dungeon */
REST_CURRENT_LEVEL = 3, /* final pass of restoring current level */
};
struct rogueroom {

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 restore.c $NHDT-Date: 1686726258 2023/06/14 07:04:18 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.211 $ */
/* NetHack 3.7 restore.c $NHDT-Date: 1717878585 2024/06/08 20:29:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.228 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -709,6 +709,8 @@ restlevelstate(void)
return;
}
/* after getlev(), put current level into a level/lock file;
essential when splitting a save file into individual level files */
/*ARGSUSED*/
staticfn int
restlevelfile(xint8 ltmp)
@@ -718,8 +720,8 @@ restlevelfile(xint8 ltmp)
nhfp = create_levelfile(ltmp, whynot);
if (!nhfp) {
/* BUG: should suppress any attempt to write a panic
save file if file creation is now failing... */
/* failed to create a new file; don't attempt to make a panic save */
gp.program_state.something_worth_saving = 0;
panic("restlevelfile: %s", whynot);
}
bufon(nhfp->fd);
@@ -756,6 +758,9 @@ dorecover(NHFILE *nhfp)
gp.program_state.restoring = 0;
return 0;
}
/* after restgamestate() -> restnames() so that 'bases[]' is populated */
init_oclass_probs(); /* recompute go.oclass_prob_totals[] */
restlevelstate();
#ifdef INSURANCE
savestateinlock();
@@ -825,6 +830,9 @@ dorecover(NHFILE *nhfp)
(void) validate(nhfp, (char *) 0, FALSE);
get_plname_from_file(nhfp, gp.plname);
/* not 0 nor REST_GSTATE nor REST_LEVELS */
gp.program_state.restoring = REST_CURRENT_LEVEL;
getlev(nhfp, 0, (xint8) 0);
close_nhfile(nhfp);
restlevelstate();
@@ -836,7 +844,6 @@ dorecover(NHFILE *nhfp)
assign_graphics(ROGUESET);
reset_glyphmap(gm_levelchange);
max_rank_sz(); /* to recompute gm.mrank_sz (botl.c) */
init_oclass_probs(); /* recompute go.oclass_prob_totals[] */
if ((uball && !uchain) || (uchain && !uball)) {
impossible("restgamestate: lost ball & chain");
@@ -1133,7 +1140,7 @@ getlev(NHFILE *nhfp, int pid, xint8 lev)
}
/* regenerate monsters while on another level */
if (!u.uz.dlevel)
if (!u.uz.dlevel || gp.program_state.restoring == REST_LEVELS)
continue;
if (ghostly) {
/* reset peaceful/malign relative to new character;