Exemple #1
0
        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());
        }
Exemple #2
0
        /* 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);
        }
Exemple #3
0
 public void AddOrReplaceController <T>(IModV1 owner, T instance)
 {
     _controllerModMapping[typeof(T)] = new ModGenericTuple <object>(owner, instance);
 }