Valheim
warning Scheduled Downtime - On 3 August 2021 starting from 09:30 (GMT+1) until approximately 13:30 (GMT+1) our site and forums will be undergoing maintenance.
0 of 0

File information

Last updated

Original upload

Created by

Pfhoenix

Uploaded by

Pfhoenix0

Virus scan

Safe to use

About this mod

Mod Config Enforcer is a utility mod for mod authors. It allows them to support servers setting configs and then enforcing those settings onto connecting clients using their mod.

IF YOU ARE A USER, ALL YOU NEED TO DO IS INSTALL THIS MOD. THAT'S IT.

Version 2.0 and later is a breaking change from the previous versions.

Requirements
Permissions and credits
Changelogs
Donations
UPDATE: Version 2.0 is a major version change due to breaking backwards compatibility with version 1. If you are a user, do not update MCE unless a mod you are using that uses it tells you to. Yes, this will be painful for a little bit, but the benefits to mod authors is why I did this.

Mod Config Enforcer is a utility mod for mod authors. It allows them to support servers setting configs and then enforcing those settings onto connecting clients using their mod. The mod allows mod authors to define config variables that can be local only (no server enforcement) as well as server enforced.

Installation : If you aren't using Vortex, you will need to download and setup the BepInEx Valheim mod off of Thunderstore.io, and then download and copy the ModConfigEnforcer.dll to your Valheim\Bepinex\plugins folder.

If you are downloading MCE because it is a dependency for another mod, you're done!

Mod authors: once downloaded and setup, in your mod project, add a reference to the ModConfigEnforcer.dll file. Your C# plugin class file should at minimum look like the following :

using System.Reflection;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using ModConfigEnforcer;

namespace YourMod
{
    [BepInPlugin("you.yourmod", ModName, Plugin.Version)]
    public class Plugin : BaseUnityPlugin
    {
        public const string Version = "1.0";
        public const string ModName = "Your Mod";
        Harmony _Harmony;

        public static ConfigVariable<bool> TestVariable;

        private void Awake()
        {
            ConfigManager.RegisterMod(ModName, Config);
            TestVariable = ConfigManager.RegisterModConfigVariable<bool>(ModName, "Test Variable", true, "General", "Just a test variable, doesn't do anything.", false);
            _Harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), null);
        }

        private void OnDestroy()
        {
            if (_Harmony != null) _Harmony.UnpatchSelf();
        }
    }
}


The ConfigVariable<bool> type comes from MCE. It is what manages the config value for your mod, based on whether it should be set by the server or not. It's uses a C# generic type - any of the following types are currently supported (the limitation is due to what data types the ZPackage class will read and write from its data stream) :
  • int
  • uint
  • bool
  • byte
  • byte[]
  • char
  • sbyte
  • long
  • ulong
  • float
  • double
  • string
  • ZPackage
  • List<string>
  • Vector3
  • Quaternion
  • ZDOID
  • HitData

In order to use your configuration variable in your code, simply call (using the example above) Plugin.TestVariable.Value

If you want to use custom configuration methods, that's also supported.

If you have any questions or need help, find me on the Valheim Modding discord server.

If you want to look at the code to see how ModConfigEnforcer works, I've made the GitHub repo public.

If you'd like to donate, head to my buymeacoffee account.