Page 1 of 1
Mod-settings.dat file editor (in C#)
Posted: Wed Apr 25, 2018 7:05 pm
by Rseding91
For anyone looking to build their own editor for the mod-settings.dat file I made this quick-and-dirty C# editor example:
https://www.dropbox.com/sh/uscmj9y3cjfw ... 7fxga?dl=0
Re: Mod-settings.dat file editor (in C#)
Posted: Wed Apr 25, 2018 7:38 pm
by steinio
why not include it in the build?
Doesn't need to look fancy.
Re: Mod-settings.dat file editor (in C#)
Posted: Wed Apr 25, 2018 7:47 pm
by Rseding91
steinio wrote:why not include it in the build?
Doesn't need to look fancy.
Because the game already comes with a built in settings editor: itself.
Re: Mod-settings.dat file editor (in C#)
Posted: Wed Apr 25, 2018 7:50 pm
by eradicator
Rseding91 wrote:steinio wrote:why not include it in the build?
Doesn't need to look fancy.
Because the game already comes with a built in settings editor: itself.
I thought the whole point of having an external settings editor was to fix cases where borked settings prevent the game from starting up in the first place (i.e. because a setting triggers an if-clause that leads to bugged code).
Re: Mod-settings.dat file editor (in C#)
Posted: Thu Apr 26, 2018 8:02 am
by bobingabout
eradicator wrote:Rseding91 wrote:steinio wrote:why not include it in the build?
Doesn't need to look fancy.
Because the game already comes with a built in settings editor: itself.
I thought the whole point of having an external settings editor was to fix cases where borked settings prevent the game from starting up in the first place (i.e. because a setting triggers an if-clause that leads to bugged code).
Yeah, I was actually going to write a setting that could have very easilly induced this state, instead I sat down and thought about it, and changed the setting to something else that performs a similar job, but can't induce this state.
Before changing the .json to a .dat, I would have used that previous possibly dangerous setting.
Re: Mod-settings.dat file editor (in C#)
Posted: Tue May 01, 2018 7:36 am
by usafphoenix
i keep one or two backup copies of the modsettings.dat file in a folder or zip file now that the devs made it unfriendly to text editors.
Re: Mod-settings.dat file editor (in C#)
Posted: Tue May 07, 2019 7:25 am
by sparr
Rseding91 wrote: ↑Wed Apr 25, 2018 7:47 pm
Because the game already comes with a built in settings editor: itself.
The built-in settings editor isn't accessible when a startup setting is causing the game to not load. Being able to edit the settings outside of the game avoids the need to relaunch the game yet another unnecessary time.
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Jul 08, 2019 3:15 am
by invisus
sparr wrote: ↑Tue May 07, 2019 7:25 am
The built-in settings editor isn't accessible when a startup setting is causing the game to not load.
Guess who just learned this lesson the hard way...
*cough*
Spoiler: Me
I'm pretty shocked by the lack of recourse here. Is there no way to trigger defaulting the settings for ONE mod? We're stuck nuking everything or writing our own external editor?
I'm not mad Wube... I'm just... disappointed.
Would be great if you could create an empty file with the mod name or something to cause the game to default/reset a specific mod's settings and consume the file. This all-or-nothing approach to mod settings is something a AAA studio would do
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Jul 08, 2019 9:05 am
by eradicator
invisus wrote: ↑Mon Jul 08, 2019 3:15 am
Is there no way to trigger defaulting the settings for ONE mod?
Not even the in-game settings menu can do that. Something i've wanted for a long time...
Re: Mod-settings.dat file editor (in C#)
Posted: Sun Jul 21, 2019 10:09 pm
by kevok
FYI I've updated the tool for 17.0, looks like another byte was added after the version blob causing the deserializer to get confused. I've also noticed that reserialized options are not binary equivalent, looks like there was a blob of 0x010100 (3B) that was converted to 0x00000000 (4B), not sure why.
Also, I added command line options so that you can reuse the code for compiling/decompiling the .dat file without having to recompile the code as well.
Also, for some reason the zip file has two different cases for the main code directory (breaks on case sensitive filesystems, but minor fix)
With Rseding's permission I can upload all of this to github.
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Oct 28, 2019 3:04 pm
by CobaltEcho
kevok wrote: ↑Sun Jul 21, 2019 10:09 pm
FYI I've updated the tool for 17.0, looks like another byte was added after the version blob causing the deserializer to get confused. I've also noticed that reserialized options are not binary equivalent, looks like there was a blob of 0x010100 (3B) that was converted to 0x00000000 (4B), not sure why.
Also, I added command line options so that you can reuse the code for compiling/decompiling the .dat file without having to recompile the code as well.
Also, for some reason the zip file has two different cases for the main code directory (breaks on case sensitive filesystems, but minor fix)
With Rseding's permission I can upload all of this to github.
Did you ever upload this?
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Oct 28, 2019 3:46 pm
by Rseding91
I don't mind if someone else wants to take over the code/do what ever with it.
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Jan 20, 2020 7:52 am
by credomane
So I rewrote this app as a
nodejs module (Still needs work). I noticed that in your code (and the wiki docs) is that reading and writing strings is handled differently from how Factorio actually does it. Perhaps this is just differences between Factorio versions 0.16 (that your app was originally written for ) and 0.17? Kinda like the extra always false boolean value added in 0.17 after the map version?
First Issue:
Code: Select all
//FileName: JsonUtil.cs
private static void WritePropertyTree(Serialiser output, JToken token)
{
PropertyTreeType type = ParseTokenType(token.Type);
// Type
output.Write((byte)type);
// Any-type flag
output.Write(type == PropertyTreeType.String);
You are suppose to write TRUE for the any-type flag when the property type is a string. In practice the any-type flag is always written as false by Factorio. So I am following suit with Factorio and always writing false.
Second Issue is much the same
Code: Select all
//FileName: Serialiser.cs
public void Write(string value)
{
Write(value.Length == 0);
if (value.Length == 0)
return;
When writing strings you write a boolean for if the string length is 0 or not and then skip writing the rest of the string value data out when it is zero. What I actually discovered is that is factorio always writes false then writes the rest of the string value even for a zero byte string. This one really tripped me up for a several hours.
Once I did both of these "corrections" my nodejs script saves mod-settings.dat bit-for-bit identical to the original mod-settings.dat
[edit]
Is is possible to partially parse the game save? Just enough to determine the mods installed, mod versions and mod settings?
Haven't taken a crack at it but an initial look-see is promising as level.dat seems to operate much like mod-settings.dat at least before the actual level data appears.
Would it also be possible to get future factorio versions to report the startup modsettings to the matchmaking API? Would be nice to swap mods to match the server and the mod-settings all in one go instead of having to restart twice.
Re: Mod-settings.dat file editor (in C#)
Posted: Mon Jan 20, 2020 1:57 pm
by BlueTemplar
For some use-cases, it might be easier to just uncompress the mods, change their default settings to what you want -
(bonus : with a script you could check what settings you have changed compared to default -
which can NOT be seen in game !)
- and then just delete mod-list.json and mod-settings.dat whenever you have a mod/settings caused crash.
Re: Mod-settings.dat file editor (in C#)
Posted: Tue Jan 21, 2020 10:41 am
by eradicator
BlueTemplar wrote: ↑Mon Jan 20, 2020 1:57 pm
For some use-cases, it might be easier to just uncompress the mods, change their default settings to what you want -
Changing the default values for a setting inside a mod does not affect the value of that setting if the mod has ever been loaded before. Pre-existing values in mod-settings.dat are (logically) always preferred.
Edit: Oh, you said "and then delete mod-settings.dat". But that would a) reset settings for all mods and b) imply that the mod crashes with default settings, in which case you should post a bug report so everyone gets the fix.
Re: Mod-settings.dat file editor (in C#)
Posted: Tue Jan 21, 2020 11:08 am
by BlueTemplar
I'm using the "default" settings in the extracted folder as custom ones.
EDIT : Some context, with one use-case : random seeds :
viewtopic.php?p=474162#p474162
Re: Mod-settings.dat file editor (in C#)
Posted: Thu Jul 15, 2021 1:42 pm
by mattyro96@gmail.com
Hi Rseding91
I've your project to support Factorio 1.1 with option to select mod-settings.json or mod-setting.dat
Here the project:
https://github.com/MatrixDJ96/Mod-Settings-Converter