ModLib
ModLib copied to clipboard
Issues with ModLib.dll in 3rd party mods
Requiring Harmony API might be a turn off for some mod developers.
Each 3rd party module must contain 0Harmony.dll or the loading screen hangs.
ModLib's Harmony patches will also be applied multiple times as Bannerlord runs all compatible dll's in the module's folder ModLib.ModLibSubModule.OnSubModuleLoad()
. See Taleworlds.MountAndBlade.Module.LoadSubModules()
I wrote a great big answer and then realised I hadn't understood what you were saying.
When ModLib is released, it will be its own mod and ModLib.dll will not be bundled with a 3rd party module. Mods will use ModLib as a dependancy by adding <DependedModule Id="ModLib" />
to their dependancies list inside their SubModule.xml file.
ModLib will load first, then mods that use it will load. ModLib.dll will only be loaded into memory once, from within the ModLib module.
You're going to have to reconsider how mods set up their settings, then. Without containing ModLib.dll in the 3rd party mods, they cannot execute the code for registering settings because it does not exist. If the 3rd party mods have not loaded yet, then ModLib will not find them and cannot setup their settings on its own.
All that is needed to maintain the current structure is to have a switch in the ModLibSubModule.OnSubModuleLoad()
to load as client mode, which allows 3rd party mods to use the ModLib utilities but will leave the settings menu to the real ModLib module. This has the side effect of making the GUI settings menu optional (users won't need ModLib) while maintaining configurable 3rd party mods.
Totally chiming in here: Harmony can never be a turn off ;)
If you want to change runtime functionality and don't want things to end up in Detours-last-guy-wins-hell you'll need some governor who makes everybody play nice with each other.
As far as I know Harmony is the only library that offers this in a centralized, stable way. Personally I also happen to think it does this quite well, but I'll admit the underlying concepts may be somewhat hard to grasp especially for new modders.
On the ModLib design: If things get split into two parts I'd suggest
- A
ModLib.Abstractions
(or whatever name you fancy) assembly only downloadable here on github (or luxury variant: as a nuget package) that contains just the datastructures & interfaces you want 3rd party mods declaring. - The actual
ModLib
mod which does all the work (and of course itself also depends on the abstractions package). Distributed via Nexus (possibly later steam workshop if it should become available).
Also, I would strongly suggest going an MIT license for the redistributable/embedable Abstractions
package. Because a reasonable argument can be made that people linking their stuff against your modlib let alone distributing it with modlib embedded may force them to release under GPL as well. That may be a deal-breaker for quite a lot of people.
So from a non-fragmenting mod config libraries point of view: If you can make your library as unencumbered as possible it'll get picked up more. And if you actually just stuff interfaces in there someone is not going to run off with it.
These are some good suggestions. I'll split the definitions into a separate dll to make things more compatible, and the point about versioning differences is a nice bonus. With how it is set up now it runs as long as ModLib is loaded before any other mod that uses it. It doesn't look for anyone using the library, it lets them register to use it, so as other mods load up they register. This will change when I've separated out the definitions and it'll search for settings classes automatically to make it quicker to implement. Also, I've switched the licencing to MIT as it causes less problems. I just don't want it to get split off into a million different versions.
I really appreciate the input here!
Also you can look here at how I isolate the ModLib settings and references from the rest of my module. I don't include modlib.dll in my mod, and if it's not loaded, that's ok, the code that references it never called. https://github.com/brandonm4/BannerlordMods/tree/master/TournamentsXPanded.Settings
By putting all ModLib references in a separate class, if that class is never referenced by running code, and the using modlib is never hit, then you will not get an error even if modlib.dll is nowhere to be found.