Skip to content

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

Open
LordMidas wants to merge 21 commits intodevelopmentfrom
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 21 commits intodevelopmentfrom
feat-allow-mods-to-affect-loading-campaign-save-compatibility

Conversation

@LordMidas
Copy link
Copy Markdown
Member

@LordMidas LordMidas commented Apr 17, 2026

  • 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.require("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

@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
{
local info = split(mod, this.ModInfoSeparator);
local mod = ::Hooks.SQClass.Mod(info[0], info[2], info[1], this.EmptyTable);
if (info[3] != "x")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3 should be a static class variable with a name. Especially since you later use a [3] magic number a second time where it is not clear if both of those values mean the same thing

mod.require(this.__getCompatString(req));
}
}
if (info[4] != "x")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 should be a static class variable

@LordMidas LordMidas force-pushed the feat-allow-mods-to-affect-loading-campaign-save-compatibility branch from 796dc9d to dd52355 Compare April 18, 2026 02:36
@LordMidas LordMidas force-pushed the feat-allow-mods-to-affect-loading-campaign-save-compatibility branch from 6c1be3b to 87c2a36 Compare April 18, 2026 03:28
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.
@Darxo
Copy link
Copy Markdown
Contributor

Darxo commented Apr 19, 2026

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

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