public WeakReference <T>[] MakeInterfaces <T>() where T : class { var modifications = _loader.Manager.GetModifications(); var interfaces = new List <WeakReference <T> >(); foreach (var mod in modifications) { var defaultAssembly = mod.Context?.LoadDefaultAssembly(); var entryPoints = defaultAssembly?.GetTypes().Where(t => typeof(T).IsAssignableFrom(t) && !t.IsAbstract); if (entryPoints == null) { continue; } foreach (var entryPoint in entryPoints) { var instance = (T)Activator.CreateInstance(entryPoint); interfaces.Add(new WeakReference <T>(instance)); // Store strong reference in mod loader only. _interfaceModMapping[typeof(T)] = new ModGenericTuple <object>(mod.Mod, instance); } } return(interfaces.ToArray()); }
/* Functions */ public ModGenericTuple <IModConfigV1>[] GetActiveMods() { var modifications = _loader.Manager.GetModifications(); var activeMods = new ModGenericTuple <IModConfigV1> [modifications.Count]; using (var enumerator = modifications.GetEnumerator()) { for (int x = 0; x < modifications.Count; x++) { enumerator.MoveNext(); var current = enumerator.Current; activeMods[x] = new ModGenericTuple <IModConfigV1>(current.Mod, current.ModConfig); } } return(activeMods); }
public void AddOrReplaceController <T>(IModV1 owner, T instance) { _controllerModMapping[typeof(T)] = new ModGenericTuple <object>(owner, instance); }