[1.0]Hash collisions caused by adding new Defs into existing saves

Started by Ataman, March 20, 2019, 05:56:25 AM

Previous topic - Next topic

Ataman

After trying to install a new mod into an existing save (which I know, is not supported) I ran into a strange bug and started investigating the cause. After thinking about it for a few days this bug turns out to be rather concerning.
Post this is based on: https://ludeon.com/forums/index.php?topic=48267.0 (Also includes a way of reproduction)

What's the problem?
The hash collisions caused by ShortHashGiver.GiveShortHash() are not an issue as long as the game keeps its state. However, updating ANY mod (which includes Core) is another matter as every new Def risks breaking existing saves (Meat_Squirrel comes to mind).
Modders unaware of this bug could be updating their mods right now and break tons of saves without warning to the user.

One solution I thought of would be to save the currently used hash database together with the save game and then load it back. That way new Defs wouldn't risk overwriting existing Hashes used by the save. Removed Defs would also need to be checked and nulled so that they can be reused after the next save.

I'm no software developer though and don't know the code well at all. Thus I can't say if that's even a practical solution in the first place. I'm sure Tynan does however.