- Fixed: Reading the RNG states from a savegame calculated the amounts of

RNGs in the savegame wrong.


SVN r1508 (trunk)
This commit is contained in:
Christoph Oelckers 2009-03-27 22:07:16 +00:00
parent 7371c4a516
commit 26420a9c60
2 changed files with 9 additions and 2 deletions

View file

@ -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 - Changed random seed initialization so that it uses the system's
cryptographically secure random number generator, if available, instead cryptographically secure random number generator, if available, instead
of the current time. of the current time.

View file

@ -269,6 +269,7 @@ void FRandom::StaticWriteRNGState (FILE *file)
// Only write those RNGs that have names // Only write those RNGs that have names
if (rng->NameCRC != 0) if (rng->NameCRC != 0)
{ {
Printf("Writing RNG %s\n", rng->Name);
arc << rng->NameCRC << rng->idx; arc << rng->NameCRC << rng->idx;
for (int i = 0; i < SFMT::N32; ++i) for (int i = 0; i < SFMT::N32; ++i)
{ {
@ -295,7 +296,8 @@ void FRandom::StaticReadRNGState (PNGHandle *png)
if (len != 0) 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; int i;
DWORD crc; DWORD crc;
@ -311,6 +313,7 @@ void FRandom::StaticReadRNGState (PNGHandle *png)
{ {
if (rng->NameCRC == crc) if (rng->NameCRC == crc)
{ {
Printf("Reading RNG %s\n", rng->Name);
arc << rng->idx; arc << rng->idx;
for (int i = 0; i < SFMT::N32; ++i) for (int i = 0; i < SFMT::N32; ++i)
{ {