From 26420a9c60b7cad5dec5adba6fea4e735909c9e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 27 Mar 2009 22:07:16 +0000 Subject: [PATCH] - Fixed: Reading the RNG states from a savegame calculated the amounts of RNGs in the savegame wrong. SVN r1508 (trunk) --- docs/rh-log.txt | 6 +++++- src/m_random.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 0918d1f08f..8bcfec0952 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,8 @@ -March 26, 2009 +March 27, 2009 (Changes by Graf Zahl) +- Fixed: Reading the RNG states from a savegame calculated the amounts of + RNGs in the savegame wrong. + +March 26, 2009 - Changed random seed initialization so that it uses the system's cryptographically secure random number generator, if available, instead of the current time. diff --git a/src/m_random.cpp b/src/m_random.cpp index 3cc977ce5f..02bb8880a6 100644 --- a/src/m_random.cpp +++ b/src/m_random.cpp @@ -269,6 +269,7 @@ void FRandom::StaticWriteRNGState (FILE *file) // Only write those RNGs that have names if (rng->NameCRC != 0) { + Printf("Writing RNG %s\n", rng->Name); arc << rng->NameCRC << rng->idx; for (int i = 0; i < SFMT::N32; ++i) { @@ -295,7 +296,8 @@ void FRandom::StaticReadRNGState (PNGHandle *png) if (len != 0) { - const int rngcount = (int)((len-4) / 8); + const size_t sizeof_rng = sizeof(rng->NameCRC) + sizeof(rng->idx) + sizeof(rng->sfmt.u); + const int rngcount = (int)((len-4) / sizeof_rng); int i; DWORD crc; @@ -311,6 +313,7 @@ void FRandom::StaticReadRNGState (PNGHandle *png) { if (rng->NameCRC == crc) { + Printf("Reading RNG %s\n", rng->Name); arc << rng->idx; for (int i = 0; i < SFMT::N32; ++i) {