[0.18.1722] First, not newest dll loaded if multiple copies are present

Started by Nightinggale, December 02, 2017, 07:50:52 AM

Previous topic - Next topic

Nightinggale

When loading mods, if the same DLL file exist in multiple mods, the one from the first mod in the loaded mod list will be used. This is a problem for tools, which are distributed as a DLL file to add to the mod itself (ModCheck, Harmony etc) because if a new version is released, mods can't use the new features because then it will fail, possibly even crash if a user happens to to load a mod, which didn't update the DLL. The solution would be to not include the mod in multiple mods, but then the game crash if the user doesn't include the DLL mod, or include it in the wrong order.

The problem can be avoided if all mods always update to include the newest DLL. However why should a mod update if it doesn't use the newly added feature? This mean the mod creator who has to do the work will not be the one making the DLL or the one whose mod breaks due to lack of update.

Obviously this is a big problem for any DLL designed to be included in multiple mods.

The problem appears to be in Verse.LoadedModManager.LoadAllActiveMods().

foreach (Type type in typeof(Mod).InstantiableDescendantsAndSelf())
{
if (!LoadedModManager.runningModClasses.ContainsKey(type))
{
ModContentPack modContentPack2 = (from modpack in LoadedModManager.runningMods
where modpack.assemblies.loadedAssemblies.Contains(type.Assembly)
select modpack).FirstOrDefault<ModContentPack>();
LoadedModManager.runningModClasses[type] = (Mod)Activator.CreateInstance(type, new object[]
{
modContentPack2
});
}
}

If FirstOrDefault is replaced with a method call, which will return the ModContentPack where type comes from a DLL with the highest AssemblyFileVersion, then it should be the newest DLL, which is loaded, regardless of load order.

Unlike most other vanilla issues, this is near impossible to fix for modders because the most obvious solution would require using Harmony before 0Harmony.dll is loaded.
ModCheck - boost your patch loading times and include patchmods in your main mod.