Skip to content

Commit

Permalink
Fix for ModInstantiator generics when passed IMod
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Jan 5, 2025
1 parent 9351753 commit 57d4794
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions Mutagen.Bethesda.Core/Plugins/Records/ModInstantiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public static class ModInstantiator<TMod>
/// Function to call to import a new Mod of type T
/// </summary>
public static readonly ImporterDelegate Importer;
//
// /// <summary>
// /// Function to call to import a new Mod of type T
// /// </summary>
// public static readonly Func<ModPath, GameRelease, IFileSystem?, TMod> FileSystemImporter;

static ModInstantiator()
{
Expand All @@ -99,29 +94,49 @@ static ModInstantiator()
createActivator = false;
}

if (type == null || !LoquiRegistration.TryGetRegister(type, out var regis))
if (type == null)
{
throw new ArgumentException();
}

if (createActivator)
if (type == typeof(IModGetter) || type == typeof(IMod))
{
Activator = ModInstantiatorReflection.GetActivator<TMod>(regis);
}
else
{
Activator = (Key, Release, Version, Ranges) =>
Activator = (modKey, release, headerVersion, forceUseLowerFormIDRanges) => (TMod)ModInstantiator.Activator(modKey, release, headerVersion, forceUseLowerFormIDRanges);
if (type == typeof(IModGetter))
{
throw new ArgumentException($"Cannot create a new mod of type {type}");
};
}
if (typeof(TMod).InheritsFrom(typeof(IMod)))
{
Importer = ModInstantiatorReflection.GetImporter<TMod>(regis);
Importer = (path, release, param) => (TMod)ModInstantiator.ImportGetter(path, release, param);
}
else
{
Importer = (path, release, param) => (TMod)ModInstantiator.ImportSetter(path, release, param);
}
}
else
{
Importer = ModInstantiatorReflection.GetOverlay<TMod>(regis);
if (!LoquiRegistration.TryGetRegister(type, out var regis))
{
throw new ArgumentException();
}

if (createActivator)
{
Activator = ModInstantiatorReflection.GetActivator<TMod>(regis);
}
else
{
Activator = (Key, Release, Version, Ranges) =>
{
throw new ArgumentException($"Cannot create a new mod of type {type}");
};
}
if (typeof(TMod).InheritsFrom(typeof(IMod)))
{
Importer = ModInstantiatorReflection.GetImporter<TMod>(regis);
}
else
{
Importer = ModInstantiatorReflection.GetOverlay<TMod>(regis);
}
}
}
}
Expand Down

0 comments on commit 57d4794

Please sign in to comment.