savefile changes - part 1
This is the first of several savefile-related changes to follow later. This one is groundwork for those later changes. Remove internal compression schemes (RLECOMP and ZEROCOMP) and discard the savefile_info struct that was primarily used to convey which internal compression schemes had been in use. Relocate some struct definitions into appropriate header files for use by code to come in later changes. Remove the two struct size-related fields from version_info and from the nmakedefs_s. Instead, include a series of bytes near the beginning of the savefile, representing the size of each struct or base data type that impacts the historical savefile content. Those are referred to as the "critical bytes". (Related note: the "you" struct required two bytes, low and high, due to its size). Compare those critical bytes in a savefile against the NetHack build that is reading the savefile. This allows mismatch detection early in the savefile-reading process, and a clean exit, rather than proceeding to read nonsensical values from the file. Include some feedback on what the first mismatch was when encountering one. For arrays stored in the savefile, use loop-logic in the core to write/read the array elements one at a time, rather than in a single blob. This will be required for changes to follow later. (impacts artiexist[], artidisco[], svd.dungeons[], svl.level_info[], svl.level.locations[][], msrooms[] field of mapseen, svb.bases[], svb.disco[] objects[], svm.mvitals[], svs.spl_book[], svd.doors[], go.oracle_loc[], utrack[], wgrowtime[]) This also adds data model to the long version information. This invalidates existing save and bones files due to the changes in the information at the start of the file.
This commit is contained in:
17
src/files.c
17
src/files.c
@@ -4258,7 +4258,6 @@ recover_savefile(void)
|
||||
struct version_info version_data;
|
||||
int processed[256];
|
||||
char savename[SAVESIZE], errbuf[BUFSZ], indicator;
|
||||
struct savefile_info sfi;
|
||||
char tmpplbuf[PL_NSIZ_PLUS];
|
||||
const char *savewrite_failure = (const char *) 0;
|
||||
|
||||
@@ -4269,7 +4268,6 @@ recover_savefile(void)
|
||||
* pid of creating process (ignored here)
|
||||
* level number for current level of save file
|
||||
* name of save file nethack would have created
|
||||
* savefile info
|
||||
* player name
|
||||
* and game state
|
||||
*/
|
||||
@@ -4304,7 +4302,6 @@ recover_savefile(void)
|
||||
!= sizeof filecmc)
|
||||
|| (read(gnhfp->fd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data)
|
||||
|| (read(gnhfp->fd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi)
|
||||
|| (read(gnhfp->fd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
|
||||
!= sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ_PLUS)
|
||||
|| (read(gnhfp->fd, (genericptr_t) &tmpplbuf, pltmpsiz)
|
||||
@@ -4317,8 +4314,8 @@ recover_savefile(void)
|
||||
/* save file should contain:
|
||||
* format indicator and cmc
|
||||
* version info
|
||||
* savefile info
|
||||
* player name
|
||||
* plnametmp = player name size (int, 2 bytes)
|
||||
* player name (PL_NSIZ_PLUS)
|
||||
* current level (including pets)
|
||||
* (non-level-based) game state
|
||||
* other levels
|
||||
@@ -4347,17 +4344,7 @@ recover_savefile(void)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Our savefile output format might _not_ be structlevel.
|
||||
* We have to check and use the correct output routine here.
|
||||
*/
|
||||
/*store_formatindicator(snhfp); */
|
||||
store_version(snhfp);
|
||||
|
||||
if (snhfp->structlevel) {
|
||||
if (write(snhfp->fd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi)
|
||||
savewrite_failure = "savefileinfo";
|
||||
}
|
||||
if (savewrite_failure)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user