Example #1
0
/*
 * Actually read the savefile
 */
static int rd_savefile_new_aux(void)
{
	u32b n_x_check, n_v_check;
	u32b o_x_check, o_v_check;

	/* Mention the savefile version */
	note(format("Loading a %d.%d.%d savefile...",
	            sf_major, sf_minor, sf_patch));

	/* Strip the version bytes */
	strip_bytes(4);

	/* Hack -- decrypt */
	xor_byte = sf_extra;


	/* Clear the checksums */
	v_check = 0L;
	x_check = 0L;


	/* Strip old data */
	strip_bytes(20);


	if (!get_check("If you import this savefile, object memory will be lost.  Is that OK? [y/n]"))
		return -1;



        if (rd_randomizer()) return -1;
        if (rd_options()) return -1;
        if (rd_messages()) return -1;
        if (rd_monster_memory()) return -1;
        if (rd_object_memory()) return -1;
        if (rd_quests()) return -1;
        if (rd_artifacts()) return -1;

        if (rd_player()) return -1;
        if (rd_squelch()) return -1;
        if (rd_misc()) return -1;       
        if (rd_player_hp()) return -1;
        if (rd_player_spells()) return -1;

        if (rd_randarts()) return -1;
        if (rd_inventory()) return -1;
        if (rd_stores()) return -1;
        
        if (rd_dungeon()) return -1;
        if (rd_objects()) return -1;
        if (rd_monsters()) return -1;
        if (rd_ghost()) return -1;

        if (rd_history()) return -1;


	/* Save the checksum */
	n_v_check = v_check;

	/* Read the old checksum */
	rd_u32b(&o_v_check);

	/* Verify */
	if (o_v_check != n_v_check)
	{
		note("Invalid checksum");
		return (-1);
	}

	/* Save the encoded checksum */
	n_x_check = x_check;

	/* Read the checksum */
	rd_u32b(&o_x_check);

	/* Verify */
	if (o_x_check != n_x_check)
	{
		note("Invalid encoded checksum");
		return (-1);
	}


	/* Hack -- no ghosts */
	r_info[z_info->r_max-1].max_num = 0;


	/* Success */
	return (0);
}
Example #2
0
/*
 * Actually read the savefile
 */
static errr rd_savefile_new_aux(void)
{
	int i;

	byte tmp8u;
	u16b tmp16u;
	u32b tmp32u;

	u32b n_x_check, n_v_check;
	u32b o_x_check, o_v_check;

	/* Mention the savefile version */
	note(format("Loading a %d.%d.%d savefile...",
	            sf_major, sf_minor, sf_patch));

	/* Strip the version bytes, and the game_mode byte */
	strip_bytes(5);

	/* Hack -- decrypt */
	xor_byte = sf_extra;

	/* Clear the checksums */
	v_check = 0L;
	x_check = 0L;

	/* Operating system info */
	rd_u32b(&sf_xtra);

	/* Time of savefile creation */
	rd_u32b(&sf_when);

	/* Number of resurrections */
	rd_u16b(&sf_lives);

	/* Number of times played */
	rd_u16b(&sf_saves);


	/* Later use (always zero) */
	rd_u32b(&tmp32u);

	/* Later use (always zero) */
	rd_u32b(&tmp32u);


	/* Read RNG state */
	rd_randomizer();
	if (arg_fiddle) note("Loaded Randomizer Info");


	/* Then the options */
	rd_options();
	if (arg_fiddle) note("Loaded Option Flags");

	/* Then the "messages" */
	rd_messages();
	if (arg_fiddle) note("Loaded Messages");

	/* Monster Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->r_max)
	{
		note(format("Too many (%u) monster races!", tmp16u));
		return (-1);
	}

	/* Read the available records */
	for (i = 0; i < tmp16u; i++)
	{
		/* Read the lore */
		rd_monster_lore(i);
	}
	if (arg_fiddle) note("Loaded Monster Memory");


	/* Object Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->k_max)
	{
		note(format("Too many (%u) object kinds!", tmp16u));
		return (-1);
	}

	/* Read the object memory */
	for (i = 0; i < tmp16u; i++)
	{
		byte tmp8u;

		object_kind *k_ptr = &k_info[i];

		rd_byte(&tmp8u);

		k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
		k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
		k_ptr->everseen = (tmp8u & 0x08) ? TRUE: FALSE;

		rd_byte(&k_ptr->squelch);

		/* Hack - Repair the savefile */
		if (!k_ptr->everseen) k_ptr->squelch = SQUELCH_NEVER;

	}
	if (arg_fiddle) note("Loaded Object Memory");

	/* Load the Quests */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->q_max)
	{
		note(format("Too many (%u) quests!", tmp16u));
		return (23);
	}

	/* Load the Quests */
	for (i = 0; i < tmp16u; i++)
	{
		quest_type *q_ptr = &q_info[i];

		rd_byte(&q_ptr->q_type);
		/* Only limited info for permanent quests.  The rest is detailed in quest.txt */
		if (q_ptr->q_type == QUEST_PERMANENT)
		{
			rd_byte(&q_ptr->q_flags);
			rd_s16b(&q_ptr->q_num_killed);
			continue;
		}

		rd_u16b(&q_ptr->q_reward);
		rd_u16b(&q_ptr->q_fame_inc);
		rd_byte(&q_ptr->base_level);
		rd_byte(&q_ptr->q_theme);
		rd_s16b(&q_ptr->mon_idx);
		rd_s32b(&q_ptr->turn_counter);
		rd_s16b(&q_ptr->q_num_killed);
		rd_s16b(&q_ptr->q_max_num);
		rd_byte(&q_ptr->q_flags);
	}

	if (arg_fiddle) note("Loaded Quests");

	/* Load the Artifacts */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->art_max)
	{
		note(format("Too many (%u) artifacts!", tmp16u));
		return (-1);
	}

	/* Read the artifact flags */
	for (i = 0; i < tmp16u; i++)
	{
		rd_byte(&tmp8u);
		a_info[i].a_cur_num = tmp8u;
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
	}
	if (arg_fiddle) note("Loaded Artifacts");


	/* Read the extra stuff */
	if (rd_extra()) return (-1);
	if (arg_fiddle) note("Loaded extra information");

	if (rd_randarts()) return (-1);
	if (arg_fiddle) note("Loaded Random Artifacts");

	if (rd_notes()) return (-1);
	if (arg_fiddle) note("Loaded Notes");

	if (rd_extensions()) return (-1);
	if (arg_fiddle) note("Loaded Extensions");

	/* Important -- Initialize the sex */
	sp_ptr = &sex_info[p_ptr->psex];

	/* Important -- Initialize the race/class */
	rp_ptr = &p_info[p_ptr->prace];
	cp_ptr = &c_info[p_ptr->pclass];

	/* Important -- Initialize the magic */
	mp_ptr = &cp_ptr->spells;

	/* Hack - In NPP 050, we moved a spell out of ironman book.*/
	if (cp_ptr->spell_book == TV_MAGIC_BOOK)  p_ptr->spell_flags[SPELL_FLIGHT] &= ~(PY_SPELL_IRONMAN);

	/* Read the inventory */
	if (rd_inventory())
	{
		note("Unable to read inventory");
		return (-1);
	}

	/* Read the stores */
	rd_u16b(&tmp16u);
	for (i = 0; i < tmp16u; i++)
	{
		if (rd_store(i)) return (-1);
	}


	/* Read the stored number of terrain features */
	rd_u16b(&tmp16u);

	/* Check bounds */
	if (tmp16u > z_info->f_max)
	{
		note(format("Too many (%u) terrain features!", tmp16u));
		return (-1);
	}

	/* Read terrain lore */
	for (i = 0; i < tmp16u; i++)
	{
		if (rd_feature_lore(i)) return (-1);
	}

	/* Artifact lore */
	/* Read the stored number of artifacts (normal + special) */
	rd_u16b(&tmp16u);

	/* Check bounds */
	if (tmp16u > z_info->art_norm_max)
	{
		note(format("Too many (%u) artifacts!", tmp16u));
		return (-1);
	}

	/* Read artifact lore */
	for (i = 0; i < tmp16u; i++)
	{
		if (rd_artifact_lore(i)) return (-1);
	}

	/* I'm not dead yet... */
	if (!p_ptr->is_dead)
	{
		/* Dead players have no dungeon */
		note("Restoring Dungeon...");
		if (rd_dungeon())
		{
			note("Error reading dungeon data");
			return (-1);
		}

	}

	/* Save the checksum */
	n_v_check = v_check;

	/* Read the old checksum */
	rd_u32b(&o_v_check);

	/* Verify */
	if (o_v_check != n_v_check)
	{
		note("Invalid checksum");
		return (-1);
	}

	/* Save the encoded checksum */
	n_x_check = x_check;

	/* Read the checksum */
	rd_u32b(&o_x_check);

	/* Verify */
	if (o_x_check != n_x_check)
	{
		note("Invalid encoded checksum");
		return (-1);
	}

	/* Success */
	return (0);
}
Example #3
0
/*
 * Actually read the savefile
 */
static errr rd_savefile_new_aux(void)
{
	int i;

	byte tmp8u;
	u16b tmp16u;
	u32b tmp32u;

	int a_max;

	artifact_type *a_info_new;
	object_lore *a_list_new;

#ifdef VERIFY_CHECKSUMS
	u32b n_x_check, n_v_check;
	u32b o_x_check, o_v_check;
#endif


	/* Mention the savefile version */
	note(format("Loading a %d.%d.%d savefile...",
	    sf_major, sf_minor, sf_patch));

	/* Strip the version bytes */
	strip_bytes(4);

	/* Hack -- decrypt */
	xor_byte = sf_extra;


	/* Clear the checksums */
	v_check = 0L;
	x_check = 0L;


	/* Operating system info */
	rd_u32b(&sf_xtra);

	/* Time of savefile creation */
	rd_u32b(&sf_when);

	/* Number of resurrections */
	rd_u16b(&sf_lives);

	/* Number of times played */
	rd_u16b(&sf_saves);


	/* Later use (always zero) */
	rd_u32b(&tmp32u);

	/* Later use (always zero) */
	rd_u32b(&tmp32u);


	/* Read RNG state */
	rd_randomizer();
	if (arg_fiddle) note("Loaded Randomizer Info");


	/* Then the options */
	rd_options();
	if (arg_fiddle) note("Loaded Option Flags");


	/* Then the "messages" */
	rd_messages();
	if (arg_fiddle) note("Loaded Messages");


	/* Monster Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->r_max)
	{
		note(format("Too many (%u) monster races!", tmp16u));
		return (-1);
	}

	/* Read the available records */
	for (i = 0; i < tmp16u; i++)
	{
		/* Read the lore */
		rd_lore(i);
	}
	if (arg_fiddle) note("Loaded Monster Memory");


	/* Object Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->k_max)
	{
		note(format("Too many (%u) object kinds!", tmp16u));
		return (-1);
	}

	/* Read the object memory */
	for (i = 0; i < tmp16u; i++)
	{
		byte tmp8u;

		object_kind *k_ptr = &k_info[i];
		rd_byte(&tmp8u);

		k_ptr->aware = (tmp8u == 1) ? TRUE: FALSE;
		k_ptr->tried = (tmp8u >= 2) ? TRUE: FALSE;

		if ((variant_guess_id) && (tmp8u > 2)) k_ptr->guess = (tmp8u - 2);

		/* Activations */
		if ((variant_usage_id) && !(older_than(2,9,6))) rd_s16b(&k_ptr->used);

	}
	if (arg_fiddle) note("Loaded Object Memory");


	/* Load the Quests */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > MAX_Q_IDX)
	{
		note(format("Too many (%u) quests!", tmp16u));
		return (-1);
	}

	/* Load the Quests */
	for (i = 0; i < tmp16u; i++)
	{
		rd_byte(&tmp8u);
		q_list[i].level = tmp8u;
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
	}
	if (arg_fiddle) note("Loaded Quests");


	/* Load the Artifacts */
	rd_u16b(&tmp16u);	

	a_max = tmp16u;

	/* Incompatible save files */
	if (a_max > 256)
	{
		note(format("Too many (%u) artifacts!", tmp16u));
		return (-1);
	}

	/* Allocate the new artifact range */
	C_MAKE(a_info_new, a_max, artifact_type);

	/* Allocate the new artifact range */
	C_MAKE(a_list_new, a_max, object_lore);

	/* Read the artifact flags */
	for (i = 0; i < a_max; i++)
	{
		object_lore *n_ptr = &a_list_new[i];

		rd_byte(&tmp8u);
		a_info_new[i].cur_num = (tmp8u != 0);
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);

		if (variant_learn_id)
		{
			/* Knowledge */
			rd_u32b(&n_ptr->can_flags1);
			rd_u32b(&n_ptr->can_flags2);
			rd_u32b(&n_ptr->can_flags3);

			rd_u32b(&n_ptr->not_flags1);
			rd_u32b(&n_ptr->not_flags2);
			rd_u32b(&n_ptr->not_flags3);

		}

		/* Activations */
		if (variant_usage_id) rd_s16b(&a_info_new[i].activated);

		/* Oops */
		if (variant_learn_id) rd_byte(&tmp8u);
		if (variant_learn_id) rd_byte(&tmp8u);
	}

	if (arg_fiddle) note("Loaded Artifacts");

	if (variant_learn_id || variant_usage_id)
	{
		/* Load the Ego items */
		rd_u16b(&tmp16u);

		/* Incompatible save files */
		if (tmp16u > z_info->e_max)
		{
			note(format("Too many (%u) ego items!", tmp16u));
			return (24);
		}

		/* Read the ego item flags */
		for (i = 0; i < tmp16u; i++)
		{
			object_lore *n_ptr = &e_list[i];

			/* Knowledge */
			if (variant_learn_id)
			{
				rd_u32b(&n_ptr->can_flags1);
				rd_u32b(&n_ptr->can_flags2);
				rd_u32b(&n_ptr->can_flags3);

				rd_u32b(&n_ptr->may_flags1);
				rd_u32b(&n_ptr->may_flags2);
				rd_u32b(&n_ptr->may_flags3);

				rd_u32b(&n_ptr->not_flags1);
				rd_u32b(&n_ptr->not_flags2);
				rd_u32b(&n_ptr->not_flags3);
			}

			/* Oops */
			if (variant_usage_id) rd_byte(&e_info[i].aware);
			if (variant_usage_id) rd_byte(&tmp8u);

			/* Oops */
			if (variant_learn_id) rd_byte(&tmp8u);
			if (variant_learn_id) rd_byte(&tmp8u);
		}

	}

	if (arg_fiddle) note("Loaded Ego Items");


	/* Read the extra stuff */
	if (rd_extra()) return (-1);
	if (arg_fiddle) note("Loaded extra information");


	/* Read random artifacts */
	if ((adult_rand_artifacts) || (a_max == 256))
	{
		if (rd_randarts()) return (-1);
		if (arg_fiddle) note("Loaded Random Artifacts");
	}

	/* Only restore fixed arts if dead */
	if (a_max > z_info->a_max) a_max = z_info->a_max;

	/* Don't restore fixed art knowledge if all random */
	else if (p_ptr->is_dead) a_max = 0;

	/* Copy over the artifact flags */
	for (i = 0; i < a_max; i++)
	{
		object_lore *n_ptr = &a_list[i];
		object_lore *n2_ptr = &a_list_new[i];

		a_info[i].cur_num = a_info_new[i].cur_num;

		if (variant_learn_id)
		{
			/* Knowledge */
			n_ptr->can_flags1 = n2_ptr->can_flags1;
			n_ptr->can_flags2 = n2_ptr->can_flags2;
			n_ptr->can_flags3 = n2_ptr->can_flags3;

			n_ptr->not_flags1 = n2_ptr->not_flags1;
			n_ptr->not_flags2 = n2_ptr->not_flags2;
			n_ptr->not_flags3 = n2_ptr->not_flags3;
		}

		/* Activations */
		if (variant_usage_id) a_info[i].activated = a_info_new[i].activated;
	}

	FREE(a_info_new);
	FREE(a_list_new);

	/* Important -- Initialize the sex */
	sp_ptr = &sex_info[p_ptr->psex];

	/* Important -- Initialize the race/class */
	rp_ptr = &p_info[p_ptr->prace];
	cp_ptr = &c_info[p_ptr->pclass];

	/* Read the inventory */
	if (rd_inventory())
	{
		note("Unable to read inventory");
		return (-1);
	}


	/* Read the stores */
	rd_u16b(&tmp16u);
	for (i = 0; i < tmp16u; i++)
	{
		if (rd_store(i)) return (-1);
	}


	/* I'm not dead yet... */
	if (!p_ptr->is_dead)
	{
		/* Dead players have no dungeon */
		note("Restoring Dungeon...");
		if (rd_dungeon())
		{
			note("Error reading dungeon data");
			return (-1);
		}

		/* Read the ghost info */
		rd_ghost();
	}


#ifdef VERIFY_CHECKSUMS

	/* Save the checksum */
	n_v_check = v_check;

	/* Read the old checksum */
	rd_u32b(&o_v_check);

	/* Verify */
	if (o_v_check != n_v_check)
	{
		note("Invalid checksum");
		return (-1);
	}

	/* Save the encoded checksum */
	n_x_check = x_check;

	/* Read the checksum */
	rd_u32b(&o_x_check);

	/* Verify */
	if (o_x_check != n_x_check)
	{
		note("Invalid encoded checksum");
		return (-1);
	}

#endif


	/* Hack -- no ghosts */
	r_info[z_info->r_max-1].max_num = 0;

        /* Set important Save-File Option */
        variant_save_feats = TRUE;


	/* Success */
	return (0);
}
Example #4
0
/*
 * Actually read the savefile
 */
static errr rd_savefile_new_aux(void)
{
	int i;

	byte tmp8u;
	u16b tmp16u;

	u32b n_x_check, n_v_check;
	u32b o_x_check, o_v_check;

	/* Mention the savefile version */
	note(format("Loading a %d.%d.%d savefile...",
	            sf_major, sf_minor, sf_patch));

	/* Strip the version bytes */
	strip_bytes(4);

	/* Hack -- decrypt */
	xor_byte = sf_extra;

	/* Clear the checksums */
	v_check = 0L;
	x_check = 0L;

	/* Operating system info */
	rd_u32b(&sf_xtra);

	/* Time of savefile creation */
	rd_u32b(&sf_when);

	/* Number of resurrections */
	rd_u16b(&sf_lives);

	/* Number of times played */
	rd_u16b(&sf_saves);

	// 8 spare bytes
	strip_bytes(8);

	/* Read RNG state */
	rd_randomizer();
	if (arg_fiddle) note("Loaded Randomizer Info");

	/* Then the options */
	rd_options();
	if (arg_fiddle) note("Loaded Option Flags");

	/* Then the "messages" */
	rd_messages();
	if (arg_fiddle) note("Loaded Messages");

	/* Monster Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->r_max)
	{
		note(format("Too many (%u) monster races!", tmp16u));
		return (-1);
	}

	/* Read the available records */
	for (i = 0; i < tmp16u; i++)
	{
		/* Read the lore */
		rd_lore(i);
	}
	if (arg_fiddle) note("Loaded Monster Memory");


	/* Object Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->k_max)
	{
		note(format("Too many (%u) object kinds!", tmp16u));
		return (-1);
	}

	/* Read the object memory */
	for (i = 0; i < tmp16u; i++)
	{
		byte tmp8u;

		object_kind *k_ptr = &k_info[i];

		rd_byte(&tmp8u);

		k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
		k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
		k_ptr->everseen = (tmp8u & 0x08) ? TRUE: FALSE;

		rd_byte(&k_ptr->squelch);
	}
	if (arg_fiddle) note("Loaded Object Memory");

	/* Load the Artefacts */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > z_info->art_max)
	{
		note(format("Too many (%u) artefacts!", tmp16u));
		return (-1);
	}

	/* Read the artefact flags */
	for (i = 0; i < tmp16u; i++)
	{
		rd_byte(&tmp8u);
		a_info[i].cur_num = tmp8u;
		rd_byte(&tmp8u);
		a_info[i].found_num = tmp8u;
	}
	if (arg_fiddle) note("Loaded Artefacts");


	/* Read the extra stuff */
	if (rd_extra()) return (-1);
	if (arg_fiddle) note("Loaded extra information");

	if (rd_randarts()) return (-1);
	if (arg_fiddle) note("Loaded Random Artefacts");

	if (rd_notes()) return (-1);
	if (arg_fiddle) note("Loaded Notes");

	/* Important -- Initialize the sex */
	sp_ptr = &sex_info[p_ptr->psex];

	/* Important -- Initialize the race/house */
	rp_ptr = &p_info[p_ptr->prace];
	hp_ptr = &c_info[p_ptr->phouse];

	/* Read the inventory */
	if (rd_inventory())
	{
		note("Unable to read inventory");
		return (-1);
	}

	/* I'm not dead yet... */
	if (!p_ptr->is_dead)
	{
		/* Dead players have no dungeon */
		note("Restoring Dungeon...");
		if (rd_dungeon())
		{
			note("Error reading dungeon data");
			return (-1);
		}

	}

	/* Save the checksum */
	n_v_check = v_check;

	/* Read the old checksum */
	rd_u32b(&o_v_check);

	/* Verify */
	if (o_v_check != n_v_check)
	{
		note("Invalid checksum");
		return (-1);
	}

	/* Save the encoded checksum */
	n_x_check = x_check;

	/* Read the checksum */
	rd_u32b(&o_x_check);

	/* Verify */
	if (o_x_check != n_x_check)
	{
		note("Invalid encoded checksum");
		return (-1);
	}

	/* Success */
	return (0);
}