[2.0.x] broken save files and migrating things with illegal names for 2.0.x (e.g. items, entities etc.)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 95
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.0.x] broken save files and migrating things with illegal names for 2.0.x (e.g. items, entities etc.)

Post by hgschmie »

The 2.0.7 release notes contain this line: Restricted prototype names to only contain alphanumeric characters, dashes and underscores.

That is a bummer because I have a bunch of mods where, for 1.x, I used a prefix to differentiate its assets (items, entities, recipes, technology etc.) from other mods.

With the 2.0 release, the prefix became "illegal" (it had a colon ":" in it). I changed the prefix to be compatible for 2.0.

Now, if you try to load an old 1.1 game, all of the entities are gone ("invalid entity") even though there is an upgraded version of the mod available. This is sad because I have a few pretty massive saves that now lose all of those entities and items.

I can not see a way around this currently short of patching the save files (and I don't have a tool that can do that so it is challenging). Does such a tool exist.

The way I see it, there are three ways to deal with this:

- release a tool that you can run on a save file to replace the names of things in he save file to match new prototypes. This seems cumbersome and error prone.
- loosen up the name restrictions again a bit (at least allow the ":" back, then I will go away ;-) )
- make the game migrate these things:

Add an attribute in the data phase to the prototypes like "legacy_name". This accepts all names that the "old" 1.1 game accepted (not the new, restricted name rules like 2.0). Anything encountered when loading a game that matches that "legacy_name" will have its name changed from the "legacy_name" to the "name" value of a prototype.

This is clearly a hacky way to do that ("what if two entities declare the same legacy name? "behave the same way as when two entities declare the same name") but the game does read all game files and should be able to construct an in-memory model of the game that can migrate old content.

Thanks for considering.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3516
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.x] broken save files and migrating things with illegal names for 2.0.x (e.g. items, entities etc.)

Post by boskid »

I think json migration allows all characters in the "from" side of migration.

As for ":" character, it is one of those characters that we wanted the most to get rid of. There is a dump command that creates icons in files named after prototypes and ":" on windows falls into alternate data streams feature. 106734
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 95
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: [2.0.x] broken save files and migrating things with illegal names for 2.0.x (e.g. items, entities etc.)

Post by hgschmie »

Hi,

Thanks for the quick answer! I did not think about json migration! I will try this out. I assumed that ":" was one of the culprits. It is literally what divides the Windows and the *ix world (that and the backslash. ;-) )
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 95
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: [2.0.x] broken save files and migrating things with illegal names for 2.0.x (e.g. items, entities etc.)

Post by hgschmie »

boskid wrote: Mon Dec 09, 2024 10:25 pm I think json migration allows all characters in the "from" side of migration.

As for ":" character, it is one of those characters that we wanted the most to get rid of. There is a dump command that creates icons in files named after prototypes and ":" on windows falls into alternate data streams feature. 106734
json migrations worked like a charm! Thank you for pointing this out.

minor nit: The sentence "All JSON migrations are applied before any Lua migrations" should be much closer to "The sequence in which migrations are executed is sorted by mod order first, migration file name second (using lexicographical comparison)." as it is really relevant to the entities being valid (updated) even though the actual migration number is lower (in this case, JSON migration 3.3.0 ran before lua migration 3.2.0 which makes total sense based on the last sentence but was confusing after reading only the first.
Post Reply

Return to “Modding interface requests”