Page MenuHomeWildfire Games

Set m_RNG in Ai Deserialisation as last
Needs ReviewPublic

Authored by Angen on Fri, Feb 7, 7:49 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

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

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

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

Linter detected issues:
Executing section Source...

source/simulation2/components/CCmpAIManager.cpp
|   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: https://jenkins.wildfiregames.com/job/docker-differential/1723/display/redirect

bb added a subscriber: bb.Tue, Feb 11, 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
   AIManager:
     num ais: 1
-    rng: "247049416601596"
+    rng: "259292060214002"
     turn: 0
     useSharedScript: true
     sharedData: {
source/simulation2/components/CCmpAIManager.cpp
822–823

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.