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) {