Page MenuHomeWildfire Games

Set m_RNG in Ai Deserialisation as last

Authored by Silier on Feb 7 2020, 7:49 PM.



When player rejoins and any function using random number generation is called during deserialization, states of players will not match because rng number of aimanagers will be different. That also causes problem with every other generation of random number and as that will not be the same as the host generates, ai will enter different gamestate.

Reverting random pickup of phase technology in ai.gamestate (rP20750) because that init function is called on rejoin and gamestate is not serialised from aimanager. Most likely it would be better for the future if ai could pick that phase technology at runtime so it would be possibly different pick for multiple ais.

Test Plan

Without patch:
Run multiplayer match with ai.
Connect with another client.
Rejoin in early game.
Almost immediately oos.

With patch:
Run multiplayer match with ai.
Connect with another client.
Rejoin in early game.
No oos because of random calls.

Event Timeline

Silier created this revision.Feb 7 2020, 7:49 PM
Owners added a subscriber: Restricted Owners Package.Feb 7 2020, 7:49 PM
Vulcan added a comment.Feb 7 2020, 8:07 PM

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"
Executing section JS...
Executing section cli...

Link to build:

bb added a subscriber: bb.Feb 11 2020, 9:43 PM

Performing the test plan yields an oos:

--- oos_dump1.txt	2020-02-11 21:35:38.942198026 +0100
+++ oos_dump.txt	2020-02-11 21:35:38.988197402 +0100
@@ -1550,7 +1550,7 @@
     value: 154
     num ais: 1
-    rng: "247049416601596"
+    rng: "259292060214002"
     turn: 0
     useSharedScript: true
     sharedData: {

It seems this would allow calling random functions on deserialize (wouldn't harm, but doing it would be 100% stupid anyway).

hmm, this was supposed to solve the issue, m_RNG is set as last action in deserialisation, there is no way it should be affected by that, unless, that javascript code is call async, in that case we are doomed with previous approach.

Silier abandoned this revision.Apr 20 2023, 4:47 PM