Mods / SimpleModconfigPatch

Tags:
Library
Author:
zulacecek
Side:
Both
Created:
Apr 28th at 10:03 AM
Last modified:
Apr 28th at 10:04 AM
Downloads:
39
Latest release (for Vintage Story 1.22.0, potentially outdated):
simplemodconfigpatch_1.0.0.zip  1-click install

Simple modconfig patch

Allows any dependant mod to easily json patch your mod config. They don't need to depend on this mod. Neither do you if you copy and paste a little bit of code. But it can still be used as a normal dependency as well.

You can copy this to your solution and just call it after you load your modconfig. 

NEEDS TO BE CALLED IN AssetsLoaded(ICoreApi api) in your ModSystem.

 

public static T PatchModConfig<T>(ICoreAPI api, T originalModConfig, string modConfigPatchFilePath)
{
    var modInfoPatchAsset = new AssetLocation(modConfigPatchFilePath);
    if (originalModConfig is null || modInfoPatchAsset is null)
    {
        return originalModConfig;
    }

    IAsset asset = api.Assets.TryGet(modInfoPatchAsset);
    if (asset is null)
    {
        return originalModConfig;
    }

    var modInfoPatch = asset.ToText();
    if (modInfoPatch is null)
    {
        return originalModConfig;
    }

    JsonConvert.PopulateObject(modInfoPatch, originalModConfig);

    return originalModConfig;
}

 

Then call like this:

try
{
    var fileName = $"{nameof(ModConfig)}.json";
    var loadedConfig = api.LoadModConfig<ModConfig>(fileName) ?? new ModConfig();
    loadedConfig = ModConfigPatcher.PatchModConfig(api, loadedConfig, "yourmodid:config/override/config.json");
    Config = loadedConfig;

    api.StoreModConfig(Config, fileName);
}
catch (Exception e)
{
    Mod.Logger.Error(e);
}

Mod Version Mod IdentifierFor Game version Downloads Released Changelog Download 1-click mod install*
1.0.0 simplemodconfigpatch 39 Apr 28th at 10:04 AM simplemodconfigpatch_1.0.0.zip 1-click install

Intial release

Disclaimer

By downloading a mod you consent to our Terms of Use.

We tell you this specifically because we want to make sure you are aware that we cannot validate every mod, and you are responsible for any damages you might incur by installing or loading mods.

This prompt will not be shown to you again (for the current browser session) if you proceed.


0 Comments (oldest first | newest first) (threaded | flat)