Skip to content

feat: validate mods compatibility when trying to load saved games#490

Open
LordMidas wants to merge 24 commits into
developmentfrom
feat-allow-mods-to-affect-loading-campaign-save-compatibility
Open

feat: validate mods compatibility when trying to load saved games#490
LordMidas wants to merge 24 commits into
developmentfrom
feat-allow-mods-to-affect-loading-campaign-save-compatibility

Conversation

@LordMidas

@LordMidas LordMidas commented Apr 17, 2026

Copy link
Copy Markdown
Member
  • We save the mod compatibility data for registered mods using the same technology that is available in Modern Hooks.
  • We then validate the saved mods just like Modern Hooks validates installed mods.
  • We allow mods to adjust the saved mods' compatibility data during validation in case they want to act as a compatibility patch or fork.

Usage

This system is meant to seamlessly blend with Modern Hooks. Use Modern Hooks and declare your requirements/conflicts as normal. This info will be saved to the save file and will be automatically used to validate compatibility.

Declaring your mod as unsafe to add to existing saves

Use Modern Hooks and require your own mod i.e.

HooksMod.require("my_own_mod_id");

Declaring your mod incompatible with older versions of itself

Use Modern Hooks and require a version of your mod:

HooksMod.conflictWith("my_own_mod_id < 0.5.5");

Applying a compatibility patch to remove declared incompatibilities

During savegame compatibility validation, you can adjust the CompatibilityData stored in the save file. For this, you need to use the MSU Serialization system. This can be useful when creating compatibility patches or creating forks of mods with different ids and declaring yourself compatible with save games that require the original mod.

// Let's say the save file has `mod_a` which requires `mod_b` version 1.8.0 or greater.
// You made a compatibility patch mod which can drop this requirement, or reduce the requirement to 1.5.0.
MyMSUMod.Serialization.onValidateSavedMods( _modsInfo )
{
  if (_modsInfo.hasMod("mod_a")
  {
    // First clear the compatibility data e.g. requirement/conflict stored for `mod_xyz` about `mod_asdf`.
     _modsInfo.clearCompatibilityData("mod_a", "mod_b");
   // Then you can add new requirement/conflict e.g.
    _modsInfo.getMod("mod_a").require("mod_b >= 1.5.0");
  }
image image

@LordMidas LordMidas requested a review from TaroEld April 17, 2026 18:48
@LordMidas LordMidas force-pushed the feat-allow-mods-to-affect-loading-campaign-save-compatibility branch from fc326c8 to 531f3f8 Compare April 17, 2026 18:59
Comment thread msu/systems/serialization/saved_mods_info.nut Outdated
Comment thread msu/systems/serialization/saved_mods_info.nut Outdated
@LordMidas LordMidas force-pushed the feat-allow-mods-to-affect-loading-campaign-save-compatibility branch 2 times, most recently from 6c1be3b to 87c2a36 Compare April 18, 2026 03:28
@Darxo

Darxo commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Perhaps it's possible to adjust the vanilla warning message that's displayed on those incompatible savegames.
Make it include "Mods" too.
- Incompatible Version or DLC/Mods Missing -

image

LordMidas added 23 commits June 23, 2026 00:37
This will hopefully avoid any pitfalls if metadata has a limit on the length of strings. Also makes it probably more readable when the data is printed out.
Different from native squirrel split which considers every character in the `_delimiter` string to be a delimiter rather than the entire `_delimiter` string as the delimiter.
Because for required mods you already have them installed otherwise modern hooks won't let you get to main menu without error. We should not validate requirements for installed mods in savegames because it will make it impossible to continue your older save if a mod updates a dependency requirement e.g. requires MSU 1.8.0 will make it impossible to load saves made with MSU 1.7.0. If you really don't want an older save to be loadable you should declare conflict with that version.
@LordMidas LordMidas force-pushed the feat-allow-mods-to-affect-loading-campaign-save-compatibility branch from 7335475 to cc5e31d Compare June 23, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQUEST] A system for mods that warns about/prevents loading saves when a added/removed mod would cause issues

2 participants