Mod-settings.dat file editor (in C#)

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Rseding91
Factorio Staff
Factorio Staff
Posts: 13174
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Mod-settings.dat file editor (in C#)

Post 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
If you want to get ahold of me I'm almost always on Discord.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2632
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post by steinio »

why not include it in the build?

Doesn't need to look fancy.
Image

Transport Belt Repair Man

View unread Posts

Rseding91
Factorio Staff
Factorio Staff
Posts: 13174
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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).

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.
Last edited by bobingabout on Tue May 01, 2018 8:16 am, edited 2 times in total.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

usafphoenix
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Sun Aug 06, 2017 9:42 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.

User avatar
invisus
Filter Inserter
Filter Inserter
Posts: 284
Joined: Fri Sep 21, 2018 5:33 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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 :P

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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...
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

kevok
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Oct 11, 2016 12:48 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.

User avatar
CobaltEcho
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sun Mar 05, 2017 4:16 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13174
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post by Rseding91 »

I don't mind if someone else wants to take over the code/do what ever with it.
If you want to get ahold of me I'm almost always on Discord.

credomane
Filter Inserter
Filter Inserter
Posts: 278
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.
BobDiggity (mod-scenario-pack)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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
BobDiggity (mod-scenario-pack)

mattyro96@gmail.com
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Jul 15, 2021 1:39 pm
Contact:

Re: Mod-settings.dat file editor (in C#)

Post 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
Last edited by mattyro96@gmail.com on Thu Jul 15, 2021 1:43 pm, edited 1 time in total.

Post Reply

Return to “Modding discussion”