From 150e49039869a03a1788e8c005a9b6abccd4b8f3 Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Tue, 5 Jan 2010 00:28:18 -0800 Subject: Fix marshalling of beholders and unrandarts (#338) Beholders were getting saved as signed bytes, so any mermaid with a monster index higher than 127 would come out as a negative number, crashes ensuing. Only the first 50 unrandart existance entries were getting saved, allowing roughly 1/3 of the unrandarts to be created multiple times. --- crawl-ref/source/tags.cc | 23 ++++++++++++++++------- crawl-ref/source/tags.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 8309c17566..816edcf061 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -1113,9 +1113,9 @@ static void tag_construct_you(writer &th) // be recalculated on game start. // List of currently beholding monsters (usually empty). - marshallByte(th, you.beholders.size()); + marshallShort(th, you.beholders.size()); for (unsigned int k = 0; k < you.beholders.size(); k++) - marshallByte(th, you.beholders[k]); + marshallShort(th, you.beholders[k]); marshallByte(th, you.piety_hysteresis); @@ -1165,8 +1165,8 @@ static void tag_construct_you_items(writer &th) marshallByte(th, static_cast(identy[i][j])); // how many unique items? - marshallByte(th, 50); - for (j = 0; j < 50; ++j) + marshallByte(th, MAX_UNRANDARTS); + for (j = 0; j < MAX_UNRANDARTS; ++j) marshallByte(th,you.unique_items[j]); marshallByte(th, NUM_FIXED_BOOKS); @@ -1547,9 +1547,18 @@ static void tag_read_you(reader &th, char minorVersion) you.water_in_sight = -1; // List of currently beholding monsters (usually empty). - count_c = unmarshallByte(th); - for (i = 0; i < count_c; i++) - you.beholders.push_back(unmarshallByte(th)); + if (minorVersion >= TAG_MINOR_BEHELD16) + { + count_c = unmarshallShort(th); + for (i = 0; i < count_c; i++) + you.beholders.push_back(unmarshallShort(th)); + } + else + { + count_c = unmarshallByte(th); + for (i = 0; i < count_c; i++) + you.beholders.push_back(unmarshallByte(th)); + } you.piety_hysteresis = unmarshallByte(th); diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index dd04e1df0e..d694e14aae 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -47,6 +47,7 @@ enum tag_major_version enum tag_minor_version { TAG_MINOR_RESET = 0, // Minor tags were reset + TAG_MINOR_BEHELD16 = 1, // Use correct type sizes for beholders TAG_MINOR_VERSION = 1 // Current version. (Keep equal to max.) }; -- cgit v1.2.3-54-g00ecf