Page 1 of 1

[Fixed][0.17.79] Desync using Mods in Multiplayer (Endless Resources)

Posted: Mon Feb 03, 2020 10:56 am
by MarshMeloz
We started this world a couple of days ago and played the first few hours without any problems. All of a sudden we started having desync issues. There was no specific thing that caused the desync and it happened at random times, sometimes on connection, other times not for 10 or 20 minutes.

We have tried going through disabling mods and have been unable to figure out which mod is causing the issue, if a mod is causing the issue.

I have attached our mod list and a link to the desync report.
mod-list.json
(3.02 KiB) Downloaded 147 times
https://drive.google.com/file/d/1oOk8v_ ... sp=sharing

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Tue Feb 04, 2020 6:51 pm
by boskid
Thanks for the report.

In desync report, primary differences are around crude-oil resourceAmount and secondary differences are around fluid amounts. I managed to narrow this desync down to one mod: "Endless resources". This mod is flawed as it has variable "tick_counter" that is stored outside of "global" variable so will not be saved, client will start with different(default) value and so it will desync.

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Tue Feb 04, 2020 9:22 pm
by Philuminati
Thanks for the notification. I am the author of the mod and first of all, I don't know much about Lua or the specs of Factorio's API. I was using this counter to make the mod UPS friendly but I understand the problem with it. Could you please explain to me how the global tick counter works and how I access it via Lua, so I can fix this issue.

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Tue Feb 04, 2020 9:38 pm
by boskid
Philuminati wrote:
Tue Feb 04, 2020 9:22 pm
Thanks for the notification. I am the author of the mod and first of all, I don't know much about Lua or the specs of Factorio's API. I was using this counter to make the mod UPS friendly but I understand the problem with it. Could you please explain to me how the global tick counter works and how I access it via Lua, so I can fix this issue.
In control.lua, line 1 you have:

Code: Select all

tick_counter = 17700
This places this variable in lua global scope. Lua context cannot be stored entirely inside save file so only part of its state is stored, for example variable called "global" is serialised using serpent.dump and when loading, is recreated inside new lua state. Shortly speaking: line 1 will be executed inside client's game instance after load and so tick_counter will be different. You have "global.generator" that will be properly handled during save/load since generator is inside "global" variable.

You may want to set initial value of "global.tick_counter" inside callback for script.on_init and then use it inside script.on_event.

Btw, for performance it is better to use script.on_nth_tick rather than catching every tick and counting ticks by yourself.

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Wed Feb 05, 2020 2:54 am
by MarshMeloz
Thank you so much for the reply, really appreciate the help!!

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Wed Feb 05, 2020 1:16 pm
by Philuminati
I changed the script to use the "on_nth_tick"-method you mentioned. Please tell me if it works without desyncs now. The new version is for 0.18 at the moment so tell me also if you need a version compatible with older savegames.

Re: [0.17.79] Desync using Mods in Multiplayer

Posted: Sun May 17, 2020 7:05 pm
by MagSun
Hello Philuminati,

I've just learned that you've created a fix for 0.18. A friend and I are playing multiplayer on 0.17.79 (current steam version) and suffer from desyncs, where I guess (from the desync-report diff) that the endless resources mod may be one of the troublemakers.

Could you be so kind and provide a 0.17 update as well?

Thanks a lot!

Cheers,
MagSun

Re: [Fixed][0.17.79] Desync using Mods in Multiplayer (Endless Resources)

Posted: Tue Jul 28, 2020 12:49 pm
by Philuminati
Sorry for the late answer, I didn't get a notification for your message... :? You can easily modify my latest version to work for 0.17 by editing the "info.json" file in the mods folder. Just edit the part:

Code: Select all

"factorio_version": "0.18",
"dependencies": ["base >= 0.18.0"]
to:

Code: Select all

"factorio_version": "0.17",
"dependencies": ["base >= 0.17.0"]
The mod doesn't use script mechanics that didn't exist in 0.17, so it shouldn't be a problem. If it is though, feel free to write me in the discussion section of the mod... :D

Have fun,

Phil